UserExtractController.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <?php
  2. namespace app\api\controller\user;
  3. use app\admin\model\system\SystemConfig;
  4. use app\admin\model\user\UserExtract as UserExtractModel;
  5. use app\models\activity\ActivityJoin;
  6. use app\models\store\StoreOrder;
  7. use app\models\user\UserBill;
  8. use app\models\user\UserExtract;
  9. use app\models\user\UserMoney;
  10. use app\Request;
  11. use crmeb\services\UtilService;
  12. /**
  13. * 提现类
  14. * Class UserExtractController
  15. * @package app\api\controller\user
  16. */
  17. class UserExtractController
  18. {
  19. /**
  20. * 提现银行
  21. * @param Request $request
  22. * @return mixed
  23. */
  24. public function bank(Request $request)
  25. {
  26. $user = $request->user();
  27. $broken_time = intval(sys_config('extract_time'));
  28. $search_time = time() - 86400 * $broken_time;
  29. //可提现佣金
  30. //返佣 +
  31. $brokerage_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  32. ->where('add_time', '>', $search_time)
  33. ->where('pm', 1)
  34. ->where('status', 1)
  35. ->sum('number');
  36. //退款退的佣金 -
  37. $refund_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  38. ->where('add_time', '>', $search_time)
  39. ->where('pm', 0)
  40. ->where('status', 1)
  41. ->sum('number');
  42. $data['broken_commission'] = bcsub($brokerage_commission, $refund_commission, 2);
  43. if ($data['broken_commission'] < 0)
  44. $data['broken_commission'] = 0;
  45. // return $data;
  46. $data['brokerage_price'] = $user['brokerage_price'];
  47. //可提现佣金
  48. $data['commissionCount'] = $data['brokerage_price'] - $data['broken_commission'];
  49. $extractBank = sys_config('user_extract_bank') ?? []; //提现银行
  50. $extractBank = str_replace("\r\n", "\n", $extractBank);//防止不兼容
  51. $data['extractBank'] = explode("\n", is_array($extractBank) ? (isset($extractBank[0]) ? $extractBank[0] : $extractBank) : $extractBank);
  52. $data['minPrice'] = sys_config('user_extract_min_price');//提现最低金额
  53. return app('json')->successful($data);
  54. }
  55. /**
  56. * 提现申请
  57. * @param Request $request
  58. * @return mixed
  59. */
  60. public function cashold(Request $request)
  61. {
  62. $extractInfo = UtilService::postMore([
  63. ['alipay_code', ''],
  64. ['extract_type', ''],
  65. ['money', 0],
  66. ['name', ''],
  67. ['bankname', ''],
  68. ['cardnum', ''],
  69. ['weixin', ''],
  70. ], $request);
  71. if (!$request->user()['is_real']) return app('json')->fail('提币请先进行实名认证');
  72. if (!preg_match('/^(([1-9]\d*)|0)(\.\d{1-2})?$/', $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. if (UserExtract::userExtract($request->user(), $extractInfo))
  100. return app('json')->successful('申请提现成功!');
  101. else
  102. return app('json')->fail(UserExtract::getErrorInfo('提现失败'));
  103. }
  104. public function cash_calculator(Request $request)
  105. {
  106. $extractInfo = UtilService::postMore([
  107. ['money', 0],
  108. ['money_type', ''],
  109. ], $request);
  110. // if (!preg_match('/^(([1-9]\d*)|0)(\.\d{1-8})?$/', $extractInfo['money'])) return app('json')->fail('提现金额输入有误');
  111. $user = $request->user();
  112. $money_type = sys_data('money_type');
  113. foreach ($money_type as $v) {
  114. if ($v['code'] == $extractInfo['money_type']) {
  115. if (!$v['can_cash']) {
  116. return app('json')->fail('该币种不可提币');
  117. }
  118. if ($v['cash_commission_count_type'] == 1) {
  119. $service = bcmul(bcdiv($v['cash_commission_ratio'], 100, 8), $extractInfo['money'], 8);
  120. } else {
  121. $service = $v['cash_commission_ratio'];
  122. }
  123. $service_type = $v['cash_commission_type'];
  124. if ($service >= $extractInfo['money']) {
  125. return app('json')->fail('提币量太少');
  126. }
  127. }
  128. }
  129. if (!isset($service_type)) {
  130. return app('json')->fail('该币种不可提币');
  131. }
  132. $extractInfo = array_merge($extractInfo, compact('service', 'service_type'));
  133. if ($extractInfo['money_type'] != $extractInfo['service_type']) {
  134. $extractInfo['extract_price'] = $extractInfo['money'];
  135. } else {
  136. $extractInfo['extract_price'] = bcsub($extractInfo['money'], $extractInfo['service'], 8);
  137. }
  138. $extractInfo['_money_type'] = init_money_type()[$extractInfo['money_type']];
  139. $extractInfo['_service_type'] = init_money_type()[$extractInfo['service_type']];
  140. return app('json')->success('ok', $extractInfo);
  141. }
  142. /**
  143. * 提现申请
  144. * @param Request $request
  145. * @return mixed
  146. */
  147. public function cash(Request $request)
  148. {
  149. $extractInfo = UtilService::postMore([
  150. ['alipay_code', ''],
  151. ['extract_type', ''],
  152. ['money', 0],
  153. ['name', ''],
  154. ['bankname', ''],
  155. ['cardnum', ''],
  156. ['weixin', ''],
  157. ['money_type', ''],
  158. ['address', ''],
  159. ], $request);
  160. // if (!preg_match('/^(([1-9]\d*)|0)(\.\d{1-8})?$/', $extractInfo['money'])) return app('json')->fail('提现金额输入有误');
  161. $user = $request->user();
  162. // if (!$user['is_real']) return app('json')->fail('提币请先进行实名认证');
  163. if ($extractInfo['money_type'] == 'brokerage') {
  164. $broken_time = intval(sys_config('extract_time'));
  165. $search_time = time() - 86400 * $broken_time;
  166. //可提现佣金
  167. //返佣 +
  168. $brokerage_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  169. ->where('add_time', '>', $search_time)
  170. ->where('pm', 1)
  171. ->where('status', 1)
  172. ->sum('number');
  173. //退款退的佣金 -
  174. $refund_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  175. ->where('add_time', '>', $search_time)
  176. ->where('pm', 0)
  177. ->where('status', 1)
  178. ->sum('number');
  179. $data['broken_commission'] = bcsub($brokerage_commission, $refund_commission, 2);
  180. if ($data['broken_commission'] < 0)
  181. $data['broken_commission'] = 0;
  182. $data['brokerage_price'] = $user['brokerage_price'];
  183. //可提现佣金
  184. $commissionCount = $data['brokerage_price'] - $data['broken_commission'];
  185. if ($extractInfo['money'] > $commissionCount) return app('json')->fail('可提现佣金不足');
  186. if (!$extractInfo['cardnum'] == '')
  187. if (!preg_match('/^([1-9]{1})(\d{14}|\d{18})$/', $extractInfo['cardnum']))
  188. return app('json')->fail('银行卡号输入有误');
  189. $res = UserExtract::userExtract($user, $extractInfo);
  190. if ($res) {
  191. return app('json')->successful('申请提币成功!', ['data' => $res]);
  192. } else
  193. return app('json')->fail(UserExtract::getErrorInfo('提币失败'));
  194. }
  195. $money_type = sys_data('money_type');
  196. foreach ($money_type as $v) {
  197. if ($v['code'] == $extractInfo['money_type']) {
  198. if (!$v['can_cash']) {
  199. return app('json')->fail('该币种不可提币');
  200. }
  201. if ($v['less'] > $extractInfo['money']) {
  202. return app('json')->fail('该币种' . $v['less'] . '个起提');
  203. }
  204. if ($v['cash_commission_count_type'] == 1) {
  205. $service = bcmul(bcdiv($v['cash_commission_ratio'], 100, 8), $extractInfo['money'], 8);
  206. } else {
  207. $service = $v['cash_commission_ratio'];
  208. }
  209. if ($service >= $extractInfo['money']) {
  210. return app('json')->fail('提币量太少');
  211. }
  212. $service_type = $v['cash_commission_type'];
  213. }
  214. }
  215. if (!isset($service_type)) {
  216. return app('json')->fail('该币种不可提币');
  217. }
  218. $extractInfo = array_merge($extractInfo, compact('service', 'service_type'));
  219. if ($extractInfo['money_type'] == 'GYJF') {
  220. if ($extractInfo['money'] > ActivityJoin::where('uid', $request->uid())->count() * 100000) {
  221. return app('json')->fail('每次参加互助最多可提100000拼团积分');
  222. }
  223. }
  224. $money = UserMoney::initialUserMoney($request->uid(), $extractInfo['money_type']);
  225. $money2 = UserMoney::initialUserMoney($request->uid(), $service_type);
  226. if ($extractInfo['money_type'] != $service_type) {
  227. if ($extractInfo['money'] > $money['money']) return app('json')->fail('可提现佣金不足');
  228. if ($service > $money2['money']) return app('json')->fail('用于支付手续费的' . init_money_type()[$service_type] . '不足');
  229. } else {
  230. if ($extractInfo['money'] > $money['money']) return app('json')->fail('可提现佣金不足');
  231. // if (bcadd($extractInfo['money'], $service, 8) > $money['money']) return app('json')->fail('可提现佣金不足');
  232. }
  233. // if ($extractInfo['address'] == '') return app('json')->fail('钱包地址错误');
  234. if (!$extractInfo['cardnum'] == '')
  235. if (!preg_match('/^([1-9]{1})(\d{14}|\d{18})$/', $extractInfo['cardnum']))
  236. return app('json')->fail('银行卡号输入有误');
  237. $res = UserExtract::userExtract($user, $extractInfo);
  238. if ($res) {
  239. return app('json')->successful('申请提币成功!', ['data' => $res]);
  240. } else
  241. return app('json')->fail(UserExtract::getErrorInfo('提币失败'));
  242. }
  243. public function lst(Request $request)
  244. {
  245. $where = UtilService::getMore([
  246. ['limit', 10],
  247. ['page', 1],
  248. ], $request);
  249. $model = new UserExtractModel();
  250. $model = $model->where('a.uid', $request->uid());
  251. $model = $model->alias('a');
  252. $model = $model->field('a.*,b.nickname');
  253. $model = $model->join('user b', 'b.uid=a.uid', 'LEFT');
  254. $model = $model->order('a.id desc');
  255. $list = $model->page($where['page'], $where['limit'])->select();
  256. return app('json')->successful('ok!', ['data' => $list]);
  257. }
  258. }