UserExtractController.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 (!preg_match('/^(([1-9]\d*)|0)(\.\d{1-2})?$/', $extractInfo['money'])) return app('json')->fail('提现金额输入有误');
  70. $user = $request->user();
  71. $broken_time = intval(sys_config('extract_time'));
  72. $search_time = time() - 86400 * $broken_time;
  73. //可提现佣金
  74. //返佣 +
  75. $brokerage_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  76. ->where('add_time', '>', $search_time)
  77. ->where('pm', 1)
  78. ->where('status', 1)
  79. ->sum('number');
  80. //退款退的佣金 -
  81. $refund_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  82. ->where('add_time', '>', $search_time)
  83. ->where('pm', 0)
  84. ->where('status', 1)
  85. ->sum('number');
  86. $data['broken_commission'] = bcsub($brokerage_commission, $refund_commission, 2);
  87. if ($data['broken_commission'] < 0)
  88. $data['broken_commission'] = 0;
  89. $data['brokerage_price'] = $user['brokerage_price'];
  90. //可提现佣金
  91. $commissionCount = $data['brokerage_price'] - $data['broken_commission'];
  92. if ($extractInfo['money'] > $commissionCount) return app('json')->fail('可提现佣金不足');
  93. if (!$extractInfo['cardnum'] == '')
  94. if (!preg_match('/^([1-9]{1})(\d{14}|\d{18})$/', $extractInfo['cardnum']))
  95. return app('json')->fail('银行卡号输入有误');
  96. if (UserExtract::userExtract($request->user(), $extractInfo))
  97. return app('json')->successful('申请提现成功!');
  98. else
  99. return app('json')->fail(UserExtract::getErrorInfo('提现失败'));
  100. }
  101. }