UserExtractController.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\api\v1\user;
  12. use app\model\user\UserExtract;
  13. use app\Request;
  14. use app\services\user\UserExtractServices;
  15. use crmeb\services\WithdrawService;
  16. use think\facade\Config;
  17. /**
  18. * 提现类
  19. * Class UserExtractController
  20. * @package app\controller\api\user
  21. */
  22. class UserExtractController
  23. {
  24. protected $services = NUll;
  25. /**
  26. * UserExtractController constructor.
  27. * @param UserExtractServices $services
  28. */
  29. public function __construct(UserExtractServices $services)
  30. {
  31. $this->services = $services;
  32. }
  33. /**
  34. * 提现银行
  35. * @param Request $request
  36. * @return mixed
  37. */
  38. public function bank(Request $request)
  39. {
  40. $uid = (int)$request->uid();
  41. return app('json')->successful($this->services->bank($uid));
  42. }
  43. public function cash_calculator(Request $request)
  44. {
  45. $fee = sys_data('withdraw_fee');
  46. $fees = [];
  47. foreach ($fee as $v) {
  48. $fees[$v['month_number']] = (string)$v['fee'];
  49. }
  50. krsort($fees, SORT_DESC);
  51. $sum_money = UserExtract::where('uid', $request->uid())
  52. ->whereTime('add_time', 'month')
  53. ->where('extract_type', '<>', 'balance')
  54. ->where('status', 1)->sum('extract_price');
  55. $money = $request->post('money');
  56. $extract_fee = 0;
  57. $max = PHP_INT_MAX;
  58. foreach ($fees as $k => $v) {
  59. if ($sum_money > $max) {
  60. break;
  61. }
  62. $max = $k;
  63. if ($sum_money + $money > $k) {
  64. $extract_fee = bcadd((string)$extract_fee, bcmul((string)($sum_money + $money - ($sum_money > $k ? $sum_money : $k)), bcdiv($v, '100', 4), 2));
  65. $money = $money - ($sum_money + $money - $k);
  66. }
  67. }
  68. return app('json')->success('ok', ['fee' => $extract_fee]);
  69. }
  70. /**
  71. * 提现申请
  72. * @param Request $request
  73. * @return mixed
  74. */
  75. public function cash(Request $request)
  76. {
  77. $extractInfo = $request->postMore([
  78. ['alipay_code', ''],
  79. ['extract_type', 'bank'],
  80. ['money', 0],
  81. ['image', 0],
  82. ['name', ''],
  83. ['bankname', ''],
  84. ['cardnum', ''],
  85. ['weixin', ''],
  86. ['qrcode_url', ''],
  87. ]);
  88. $extractType = Config::get('pay.extractType', []);
  89. if (!in_array($extractInfo['extract_type'], $extractType))
  90. return app('json')->fail('提现方式不存在');
  91. if (!preg_match('/^[0-9]+(.[0-9]{1,2})?$/', (float)$extractInfo['money'])) return app('json')->fail('提现金额输入有误');
  92. if (!$extractInfo['cardnum'] == '')
  93. if (!preg_match('/^([1-9]{1})(\d{15}|\d{16}|\d{18})$/', $extractInfo['cardnum']))
  94. return app('json')->fail('银行卡号输入有误');
  95. if (!$extractInfo['image'])
  96. return app('json')->fail('请上传发票凭证');
  97. if ($extractInfo['extract_type'] == 'alipay') {
  98. if (!$extractInfo['alipay_code']) return app('json')->fail('请输入支付宝账号');
  99. } else if ($extractInfo['extract_type'] == 'bank') {
  100. if (!$extractInfo['cardnum']) return app('json')->fail('请输入银行卡账号');
  101. if (!$extractInfo['bankname']) return app('json')->fail('请输入开户行信息');
  102. // $bank_info = WithdrawService::init()::contractInfo($user['enterprise_professional_facilitator_id']);
  103. // if ($bank_info['is_contract']) {
  104. // return app('json')->fail('签约已完成');
  105. // }
  106. } else if ($extractInfo['extract_type'] == 'weixin' && sys_config('brokerage_type') == 0) {
  107. if (!$extractInfo['weixin']) return app('json')->fail('请输入微信账号');
  108. }
  109. $uid = (int)$request->uid();
  110. if ($this->services->cash($uid, $extractInfo))
  111. return app('json')->successful('申请提现成功!');
  112. else
  113. return app('json')->fail('提现失败');
  114. }
  115. }