UserExtractController.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace app\api\controller\user;
  3. use app\admin\model\system\SystemConfig;
  4. use app\models\store\StoreOrder;
  5. use app\models\user\UserBill;
  6. use app\models\user\UserExtract;
  7. use app\Request;
  8. use crmeb\services\UtilService;
  9. use crmeb\services\CacheService;
  10. /**
  11. * 提现类
  12. * Class UserExtractController
  13. * @package app\api\controller\user
  14. */
  15. class UserExtractController
  16. {
  17. /**
  18. * 提现银行
  19. * @param Request $request
  20. * @return mixed
  21. */
  22. public function bank(Request $request)
  23. {
  24. $user = $request->user();
  25. $broken_time = intval(sys_config('extract_time'));
  26. $search_time = time() - 86400 * $broken_time;
  27. //可提现佣金
  28. //返佣 +
  29. $brokerage_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  30. ->where('add_time', '>', $search_time)
  31. ->where('pm', 1)
  32. ->sum('number');
  33. //退款退的佣金 -
  34. $refund_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  35. ->where('add_time', '>', $search_time)
  36. ->where('pm', 0)
  37. ->sum('number');
  38. $data['broken_commission'] = bcsub($brokerage_commission, $refund_commission, 2);
  39. if ($data['broken_commission'] < 0)
  40. $data['broken_commission'] = 0;
  41. // return $data;
  42. $data['brokerage_price'] = $user['brokerage_price'];
  43. //可提现佣金
  44. $data['commissionCount'] = $data['brokerage_price'] - $data['broken_commission'];
  45. $extractBank = sys_config('user_extract_bank') ?? []; //提现银行
  46. $extractBank = str_replace("\r\n", "\n", $extractBank);//防止不兼容
  47. $data['extractBank'] = explode("\n", is_array($extractBank) ? (isset($extractBank[0]) ? $extractBank[0] : $extractBank) : $extractBank);
  48. $data['minPrice'] = sys_config('user_extract_min_price');//提现最低金额
  49. return app('json')->successful($data);
  50. }
  51. /**
  52. * 提现申请
  53. * @param Request $request
  54. * @return mixed
  55. */
  56. public function cash(Request $request)
  57. {
  58. $extractInfo = UtilService::postMore([
  59. ['type'],
  60. ['alipay_code', ''],
  61. ['extract_type', ''],
  62. ['money', 0],
  63. ['name', ''],
  64. ['bankname', ''],
  65. ['cardnum', ''],
  66. ['weixin', ''],
  67. ], $request);
  68. if ($extractInfo['money'] < 50) return app('json')->fail('最少提现50');
  69. $extract = UserExtract::where('uid', $request->uid())->where('status', '<', 0)->whereBetweenTime('add_time', strtotime('today'), strtotime('tomorrow'))->count();
  70. if ($extract >= 3) return app('json')->fail('今天提现错误3次,请明天再提现');
  71. if (cache($request->uid())) return app('json')->fail('请勿频繁点击');
  72. if (!preg_match('/^\\d+(\\.\\d+)?$/', $extractInfo['money'])) return app('json')->fail('提现金额输入有误');
  73. $user = $request->user();
  74. $broken_time = intval(sys_config('extract_time'));
  75. $search_time = time() - 86400 * $broken_time;
  76. //可提现佣金
  77. //返佣 +
  78. $brokerage_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  79. ->where('add_time', '>', $search_time)
  80. ->where('pm', 1)
  81. ->where('status', 1)
  82. ->sum('number');
  83. //退款退的佣金 -
  84. $refund_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  85. ->where('add_time', '>', $search_time)
  86. ->where('pm', 0)
  87. ->where('status', 1)
  88. ->sum('number');
  89. $data['broken_commission'] = bcsub($brokerage_commission, $refund_commission, 2);
  90. if ($data['broken_commission'] < 0)
  91. $data['broken_commission'] = 0;
  92. $data['brokerage_price'] = $user['brokerage_price'];
  93. //可提现佣金
  94. // $commissionCount = $data['brokerage_price'] - $data['broken_commission'];
  95. // if ($extractInfo['money'] > $commissionCount) return app('json')->fail('可提现佣金不足');
  96. if (!$extractInfo['cardnum'] == '')
  97. if (!preg_match('/^([1-9]{1})(\d{14}|\d{18})$/', $extractInfo['cardnum']))
  98. return app('json')->fail('银行卡号输入有误');
  99. cache($request->uid(), 1, 5);
  100. if (UserExtract::userExtract($request->user(), $extractInfo))
  101. return app('json')->successful('申请提现成功!');
  102. else
  103. return app('json')->fail(UserExtract::getErrorInfo('提现失败'));
  104. }
  105. }