WithdrawBusiness.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. namespace app\business;
  3. use Illuminate\Support\Arr;
  4. use Respect\Validation\Validator;
  5. use support\Db;
  6. use support\Log;
  7. use support\Redis;
  8. class WithdrawBusiness
  9. {
  10. /** 提现
  11. * @param array $param
  12. * @return void
  13. */
  14. static public function applyfor(array $param)
  15. {
  16. try {
  17. $system = Db::table('wa_system')->first();
  18. if ($param['mold'] == 1) {
  19. if (empty($system->is_money)) {
  20. throw new \Exception('提现功能暂未开放!');
  21. }
  22. if ($system->min_money > $param['money']) {
  23. throw new \Exception('最小提现金额:' . $system->min_money . '元');
  24. }
  25. } elseif ($param['mold'] == 2) {
  26. throw new \Exception('提现失败!');
  27. if (empty($system->is_money_one)) {
  28. throw new \Exception('提现功能暂未开放!');
  29. }
  30. if ($system->min_money_one > $param['money']) {
  31. throw new \Exception('最小提现金额:' . $system->min_money_one . '元');
  32. }
  33. } elseif ($param['mold'] == 3) {
  34. if (empty($system->is_money_two)) {
  35. throw new \Exception('提现功能暂未开放!');
  36. }
  37. if ($system->min_money_two > $param['money']) {
  38. throw new \Exception('最小提现金额:' . $system->min_money_two . '元');
  39. }
  40. } else {
  41. throw new \Exception('提现功能暂未开放!');
  42. }
  43. /** @var $bankCard 银行卡 */
  44. $bankCard = Db::table('wa_bank_card')->where('uid', $param['user_data']['id'])->first();
  45. if (empty($bankCard)) {
  46. throw new \Exception('请绑定银行卡!');
  47. }
  48. /** @var $userIdentity 实名信息 */
  49. $userIdentity = Db::table('wa_user_identity')->where('uid', $param['user_data']['id'])->first();
  50. if (empty($userIdentity)) {
  51. throw new \Exception('请实名后,在提现!');
  52. }
  53. $hasWithdraw = Db::table('wa_withdraw')
  54. ->where('type', $param['mold'])
  55. ->where('user_id', $param['user_data']['id'])
  56. ->whereBetween('created_at', [date('Y-m-d') . ' 00:00:00', date('Y-m-d') . ' 23:59:59'])->exists();
  57. if ($hasWithdraw) {
  58. throw new \Exception('今日已提现,请次日在来提现!');
  59. }
  60. if ($param['mold'] == 2){
  61. $status = 3;
  62. }else{
  63. $status = 1;
  64. }
  65. $withdrawId = Db::table('wa_withdraw')->insertGetId([
  66. 'order_no' => date('YmdHis') . mt_rand(10000, 99999),
  67. 'user_id' => $param['user_data']['id'],
  68. 'money' => $param['money'],
  69. 'type' => $param['mold'],
  70. 'affiliated_bank' => $bankCard->affiliated_bank,
  71. 'account_holder' => $bankCard->account_holder,
  72. 'card_number' => $bankCard->card_number,
  73. 'name' => Arr::get($param, 'name', ''),
  74. 'identity' => Arr::get($param, 'identity', ''),
  75. 'img' => !empty(Arr::get($param, 'img', '')) ? implode(',', Arr::get($param, 'img', '')) : '',
  76. 'created_at' => date('Y-m-d H:i:s'),
  77. 'updated_at' => date('Y-m-d H:i:s'),
  78. 'status' => $status
  79. ]);
  80. if ($param['mold'] == 2){
  81. StreamBusiness::addStream($param['user_data']['id'], $param['money'], streamType4, moldType5, moldTypefild5, $withdrawId);
  82. }
  83. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType4, $param['mold'], moldTypefild($param['mold']), $withdrawId);
  84. } catch (\Throwable $exception) {
  85. throw new \Exception($exception->getMessage());
  86. }
  87. return true;
  88. }
  89. /** 提现流水
  90. * @param array $param
  91. * @return void
  92. */
  93. static public function stream(array $param)
  94. {
  95. try {
  96. $data = Db::table('wa_withdraw')
  97. ->where(function ($query) use ($param) {
  98. if (!empty(Arr::get($param, 'mold'))) {
  99. $query->where('type', $param['mold']);
  100. }
  101. })
  102. ->where('user_id', $param['user_data']['id'])
  103. ->orderByDesc('id')
  104. ->paginate(Arr::get($param, 'limit', 10), ['*'], 'page', Arr::get($param, 'page'))
  105. ->toArray();
  106. foreach ($data['data'] as $k => $v) {
  107. $data['data'][$k]->mold_name = moldType($v->type);
  108. }
  109. } catch (\Throwable $exception) {
  110. throw new \Exception($exception->getMessage());
  111. }
  112. return $data;
  113. }
  114. /** 转账至五行银行卡
  115. * @param array $param
  116. * @return void
  117. */
  118. static public function transfer_accounts(array $param)
  119. {
  120. try {
  121. $system = Db::table('wa_system')->first();
  122. if ($param['mold'] != 2) {
  123. throw new \Exception('转账至五行银行卡暂未开放!');
  124. }
  125. $param['mold'] = 5;
  126. /** @var $bankCard 银行卡 */
  127. $bankCard = Db::table('wa_user_social_cark')->where('user_id', $param['user_data']['id'])->first();
  128. if (empty($bankCard)) {
  129. throw new \Exception('请先领取五行银行卡!');
  130. }
  131. /** @var $userIdentity 实名信息 */
  132. $userIdentity = Db::table('wa_user_identity')->where('uid', $param['user_data']['id'])->first();
  133. if (empty($userIdentity)) {
  134. throw new \Exception('请实名后,在转入!');
  135. }
  136. if (empty($system->conversion_value_cost)) {
  137. throw new \Exception('暂时不能转入!');
  138. }
  139. //五行银行卡余额变更
  140. $money = bcmul($param['money'], $system->conversion_value_cost, 2);
  141. Db::table('wa_user_social_cark')->where('user_id', $param['user_data']['id'])->increment('money', $money);
  142. //转账到五行银行卡余额
  143. StreamBusiness::addStream($param['user_data']['id'], $money, streamType14, moldType4, moldTypefild4);
  144. //减少股票账户
  145. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType14, $param['mold'], moldTypefild($param['mold']), $param['user_data']['id']);
  146. } catch (\Throwable $exception) {
  147. throw new \Exception($exception->getMessage());
  148. }
  149. return true;
  150. }
  151. }