WithdrawBusiness.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. if (empty($system->is_money_one)) {
  27. throw new \Exception('提现功能暂未开放!');
  28. }
  29. if ($system->min_money_one > $param['money']) {
  30. throw new \Exception('最小提现金额:' . $system->min_money_one . '元');
  31. }
  32. } elseif ($param['mold'] == 5) {
  33. if (empty($system->is_money_five)) {
  34. throw new \Exception('提现功能暂未开放!');
  35. }
  36. if ($system->min_money_five > $param['money']) {
  37. throw new \Exception('最小提现金额:' . $system->min_money_five . '元');
  38. }
  39. } else {
  40. throw new \Exception('提现功能暂未开放!');
  41. }
  42. /** @var $bankCard 银行卡 */
  43. $bankCard = Db::table('wa_bank_card')->where('uid', $param['user_data']['id'])->first();
  44. if (empty($bankCard)) {
  45. throw new \Exception('请绑定银行卡!');
  46. }
  47. /** @var $userIdentity 实名信息 */
  48. $userIdentity = Db::table('wa_user_identity')->where('uid', $param['user_data']['id'])->first();
  49. if (empty($userIdentity)) {
  50. throw new \Exception('请实名后,在提现!');
  51. }
  52. if ($param['mold'] == 1) {
  53. $hasWithdraw = Db::table('wa_withdraw')
  54. ->where('type', $param['mold'])
  55. ->where('binding_type', $param['binding_type'])
  56. ->where('user_id', $param['user_data']['id'])
  57. ->whereBetween('created_at', [date('Y-m-d') . ' 00:00:00', date('Y-m-d') . ' 23:59:59'])->exists();
  58. if ($hasWithdraw) {
  59. throw new \Exception('今日已提现,请次日在来提现!');
  60. }
  61. }else{
  62. $hasWithdraw = Db::table('wa_withdraw')->where('type', $param['mold'])->where('user_id', $param['user_data']['id'])
  63. ->whereBetween('created_at', [date('Y-m-d') . ' 00:00:00', date('Y-m-d') . ' 23:59:59'])->exists();
  64. if ($hasWithdraw) {
  65. throw new \Exception('今日已提现,请次日在来提现!');
  66. }
  67. }
  68. $withdrawId = Db::table('wa_withdraw')->insertGetId([
  69. 'order_no' => date('YmdHis') . mt_rand(10000, 99999),
  70. 'user_id' => $param['user_data']['id'],
  71. 'money' => $param['money'],
  72. 'type' => $param['mold'],
  73. 'affiliated_bank' => $bankCard->affiliated_bank,
  74. 'account_holder' => $bankCard->account_holder,
  75. 'card_number' => $bankCard->card_number,
  76. 'name' => Arr::get($param, 'name', ''),
  77. 'identity' => Arr::get($param, 'identity', ''),
  78. 'binding_type' => Arr::get($param, 'binding_type', 0),
  79. 'img' => !empty(Arr::get($param, 'img', '')) ? implode(',', Arr::get($param, 'img', '')) : '',
  80. 'created_at' => date('Y-m-d H:i:s'),
  81. 'updated_at' => date('Y-m-d H:i:s'),
  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. if (!empty(Arr::get($param, 'type'))) {
  102. if($param['type']==1){
  103. $query->where('type', 1);
  104. }elseif ($param['type']==2){
  105. $query->where('type', 1);
  106. $query->where('binding_type', 1);
  107. }elseif ($param['type']==3){
  108. $query->where('type', 1);
  109. $query->where('binding_type', 2);
  110. }elseif ($param['type']==4){
  111. $query->whereIn('type', [2,5]);
  112. }
  113. }
  114. })
  115. ->where('user_id', $param['user_data']['id'])
  116. ->orderByDesc('id')
  117. ->paginate(Arr::get($param, 'limit', 10), ['*'], 'page', Arr::get($param, 'page'))
  118. ->toArray();
  119. foreach ($data['data'] as $k => $v) {
  120. $data['data'][$k]->mold_name = moldType($v->type);
  121. }
  122. } catch (\Throwable $exception) {
  123. throw new \Exception($exception->getMessage());
  124. }
  125. return $data;
  126. }
  127. /** 转账至五行银行卡
  128. * @param array $param
  129. * @return void
  130. */
  131. static public function transfer_accounts(array $param)
  132. {
  133. try {
  134. $system = Db::table('wa_system')->first();
  135. if ($param['mold'] != 2) {
  136. throw new \Exception('转账至五行银行卡暂未开放!');
  137. }
  138. $param['mold'] = 5;
  139. /** @var $bankCard 银行卡 */
  140. $bankCard = Db::table('wa_user_social_cark')->where('user_id', $param['user_data']['id'])->first();
  141. if (empty($bankCard)) {
  142. throw new \Exception('请先领取五行银行卡!');
  143. }
  144. /** @var $userIdentity 实名信息 */
  145. $userIdentity = Db::table('wa_user_identity')->where('uid', $param['user_data']['id'])->first();
  146. if (empty($userIdentity)) {
  147. throw new \Exception('请实名后,在转入!');
  148. }
  149. if (empty($system->conversion_value_cost)) {
  150. throw new \Exception('暂时不能转入!');
  151. }
  152. //五行银行卡余额变更
  153. $money = bcmul($param['money'], $system->conversion_value_cost, 2);
  154. Db::table('wa_user_social_cark')->where('user_id', $param['user_data']['id'])->increment('money', $money);
  155. //转账到五行银行卡余额
  156. StreamBusiness::addStream($param['user_data']['id'], $money, streamType14, moldType4, moldTypefild4);
  157. //减少股票账户
  158. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType14, $param['mold'], moldTypefild($param['mold']), $param['user_data']['id']);
  159. } catch (\Throwable $exception) {
  160. throw new \Exception($exception->getMessage());
  161. }
  162. return true;
  163. }
  164. }