UserExtractController.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. $user_type = $request->post('user_type', 0);
  57. $extract_fee = 0;
  58. if ($user_type == 0) {
  59. $max = PHP_INT_MAX;
  60. foreach ($fees as $k => $v) {
  61. if ($sum_money > $max) {
  62. break;
  63. }
  64. $max = $k;
  65. if ($sum_money + $money > $k) {
  66. $extract_fee = bcadd((string)$extract_fee, bcmul((string)($sum_money + $money - ($sum_money > $k ? $sum_money : $k)), bcdiv($v, '100', 4), 2));
  67. $money = $money - ($sum_money + $money - $k);
  68. }
  69. }
  70. }
  71. return app('json')->success('ok', ['fee' => $extract_fee]);
  72. }
  73. /**
  74. * 提现申请
  75. * @param Request $request
  76. * @return mixed
  77. */
  78. public function cash(Request $request)
  79. {
  80. $extractInfo = $request->postMore([
  81. ['alipay_code', ''],
  82. ['extract_type', 'bank'],
  83. ['money', 0],
  84. ['image', 0],
  85. ['name', ''],
  86. ['bankname', ''],
  87. ['cardnum', ''],
  88. ['weixin', ''],
  89. ['qrcode_url', ''],
  90. ['user_type', 0],
  91. ]);
  92. $extractType = Config::get('pay.extractType', []);
  93. if (!in_array($extractInfo['extract_type'], $extractType))
  94. return app('json')->fail('提现方式不存在');
  95. if (!preg_match('/^[0-9]+(.[0-9]{1,2})?$/', (float)$extractInfo['money'])) return app('json')->fail('提现金额输入有误');
  96. if (!$extractInfo['cardnum'] == '')
  97. if (!preg_match('/^([1-9]{1})(\d{15}|\d{16}|\d{18})$/', $extractInfo['cardnum']))
  98. return app('json')->fail('银行卡号输入有误');
  99. if (!$extractInfo['image'])
  100. return app('json')->fail('请上传发票凭证');
  101. if ($extractInfo['extract_type'] == 'alipay') {
  102. if (!$extractInfo['alipay_code']) return app('json')->fail('请输入支付宝账号');
  103. } else if ($extractInfo['extract_type'] == 'bank') {
  104. if (!$extractInfo['cardnum']) return app('json')->fail('请输入银行卡账号');
  105. if (!$extractInfo['bankname']) return app('json')->fail('请输入开户行信息');
  106. // $bank_info = WithdrawService::init()::contractInfo($user['enterprise_professional_facilitator_id']);
  107. // if ($bank_info['is_contract']) {
  108. // return app('json')->fail('签约已完成');
  109. // }
  110. } else if ($extractInfo['extract_type'] == 'weixin' && sys_config('brokerage_type') == 0) {
  111. if (!$extractInfo['weixin']) return app('json')->fail('请输入微信账号');
  112. }
  113. $uid = (int)$request->uid();
  114. if ($this->services->cash($uid, $extractInfo))
  115. return app('json')->successful('申请提现成功!');
  116. else
  117. return app('json')->fail('提现失败');
  118. }
  119. }