UserExtractController.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. ['alipay_code', ''],
  60. ['extract_type', ''],
  61. ['money', 0],
  62. ['name', ''],
  63. ['bankname', ''],
  64. ['cardnum', ''],
  65. ['weixin', ''],
  66. ], $request);
  67. // if (time() - CacheService::get('UserExtract_' . $request->uid(), time()) < 10) return app('json')->fail('请勿连续多次提交');
  68. // else CacheService::set('UserExtract_' . $request->uid(), time());
  69. if (cache($request->uid())) return app('json')->fail('请勿频繁点击');
  70. if (!preg_match('/^(([1-9]\d*)|0)(\.\d{1-2})?$/', $extractInfo['money'])) return app('json')->fail('提现金额输入有误');
  71. $user = $request->user();
  72. $broken_time = intval(sys_config('extract_time'));
  73. $search_time = time() - 86400 * $broken_time;
  74. //可提现佣金
  75. //返佣 +
  76. $brokerage_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  77. ->where('add_time', '>', $search_time)
  78. ->where('pm', 1)
  79. ->where('status', 1)
  80. ->sum('number');
  81. //退款退的佣金 -
  82. $refund_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  83. ->where('add_time', '>', $search_time)
  84. ->where('pm', 0)
  85. ->where('status', 1)
  86. ->sum('number');
  87. $data['broken_commission'] = bcsub($brokerage_commission, $refund_commission, 2);
  88. if ($data['broken_commission'] < 0)
  89. $data['broken_commission'] = 0;
  90. $data['brokerage_price'] = $user['brokerage_price'];
  91. //可提现佣金
  92. // $commissionCount = $data['brokerage_price'] - $data['broken_commission'];
  93. // if ($extractInfo['money'] > $commissionCount) return app('json')->fail('可提现佣金不足');
  94. if (!$extractInfo['cardnum'] == '')
  95. if (!preg_match('/^([1-9]{1})(\d{14}|\d{18})$/', $extractInfo['cardnum']))
  96. return app('json')->fail('银行卡号输入有误');
  97. cache($request->uid(), 1, 5);
  98. if (UserExtract::userExtract($request->user(), $extractInfo))
  99. return app('json')->successful('申请提现成功!');
  100. else
  101. return app('json')->fail(UserExtract::getErrorInfo('提现失败'));
  102. }
  103. }