WithdrawBusiness.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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'] == 3) {
  33. }elseif ($param['mold'] == 5) {
  34. }elseif ($param['mold'] == 6) {
  35. // if (empty($system->is_money_one)) {
  36. // throw new \Exception('兑换功能暂未开放!');
  37. // }
  38. if (10 > $param['money']) {
  39. throw new \Exception('最小提现金额:10USD');
  40. }
  41. }elseif ($param['mold'] == 10) {
  42. }elseif ($param['mold'] == 7) {
  43. if (empty($system->is_money_seven)) {
  44. throw new \Exception('提现功能暂未开放!');
  45. }
  46. if ($system->min_money_seven > $param['money']) {
  47. throw new \Exception('最小提现金额:' . $system->min_money_seven . '元');
  48. }
  49. }elseif ($param['mold'] == 8) {
  50. if (empty($system->is_money_eight)) {
  51. throw new \Exception('提现功能暂未开放!');
  52. }
  53. if ($system->min_money_eight > $param['money']) {
  54. throw new \Exception('最小提现金额:' . $system->min_money_eight . '元');
  55. }
  56. }elseif ($param['mold'] == 9) {
  57. if (empty($system->is_money_nine)) {
  58. throw new \Exception('提现功能暂未开放!');
  59. }
  60. if ($system->min_money_nine > $param['money']) {
  61. throw new \Exception('最小提现金额:' . $system->min_money_nine . '元');
  62. }
  63. }elseif ($param['mold'] == 11) {
  64. if (10 > $param['money']) {
  65. throw new \Exception('最小提现金额:10元');
  66. }
  67. } else {
  68. throw new \Exception('提现功能暂未开放!');
  69. }
  70. if ($param['mold'] == 2) {
  71. $status = 3;
  72. $affiliated_bank = '';
  73. $account_holder = '';
  74. $card_number = '';
  75. }elseif ($param['mold'] == 5){
  76. $status = 3;
  77. $affiliated_bank = '';
  78. $account_holder = '';
  79. $card_number = '';
  80. }elseif ($param['mold'] == 6){
  81. $status = 1;
  82. $affiliated_bank = '';
  83. $account_holder = '';
  84. $card_number = '';
  85. }elseif ($param['mold'] == 10){
  86. $status = 1;
  87. $affiliated_bank = '';
  88. $account_holder = '';
  89. $card_number = '';
  90. } else {
  91. /** @var $bankCard 银行卡 */
  92. $bankCard = Db::table('wa_bank_card')->where('uid', $param['user_data']['id'])->first();
  93. if (empty($bankCard)) {
  94. throw new \Exception('请绑定银行卡!');
  95. }
  96. /** @var $userIdentity 实名信息 */
  97. $userIdentity = Db::table('wa_user_identity')->where('uid', $param['user_data']['id'])->first();
  98. if (empty($userIdentity)) {
  99. throw new \Exception('请实名后,在提现!');
  100. }
  101. $hasWithdraw = Db::table('wa_withdraw')
  102. ->where('type', $param['mold'])
  103. ->where('user_id', $param['user_data']['id'])
  104. ->whereBetween('created_at', [date('Y-m-d') . ' 00:00:00', date('Y-m-d') . ' 23:59:59'])->exists();
  105. if ($hasWithdraw) {
  106. throw new \Exception('今日已提现,请次日在来提现!');
  107. }
  108. $status = 1;
  109. $affiliated_bank = $bankCard->affiliated_bank;
  110. $account_holder = $bankCard->account_holder;
  111. $card_number = $bankCard->card_number;
  112. }
  113. $withdrawId = Db::table('wa_withdraw')->insertGetId([
  114. 'order_no' => date('YmdHis') . mt_rand(10000, 99999),
  115. 'user_id' => $param['user_data']['id'],
  116. 'money' => $param['money'],
  117. 'type' => $param['mold'],
  118. 'affiliated_bank' => $affiliated_bank,
  119. 'account_holder' => $account_holder,
  120. 'card_number' => $card_number,
  121. 'name' => Arr::get($param, 'name', ''),
  122. 'identity' => Arr::get($param, 'identity', ''),
  123. 'img' => !empty(Arr::get($param, 'img', '')) ? implode(',', Arr::get($param, 'img', '')) : '',
  124. 'created_at' => date('Y-m-d H:i:s'),
  125. 'updated_at' => date('Y-m-d H:i:s'),
  126. 'status' => $status
  127. ]);
  128. if ($param['mold'] == 2) {
  129. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType14, $param['mold'], moldTypefild($param['mold']), $withdrawId);
  130. StreamBusiness::addStream($param['user_data']['id'], $param['money'], streamType14, moldType3, moldTypefild3, $withdrawId);
  131. }elseif ($param['mold'] == 5){
  132. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType24, $param['mold'], moldTypefild($param['mold']), $withdrawId);
  133. StreamBusiness::delStream($param['user_data']['id'], 100, streamType22, moldType5,moldTypefild5, $withdrawId);
  134. StreamBusiness::addStream($param['user_data']['id'], bcmul($param['money'],$system->coin_value,2), streamType24, moldType3, moldTypefild3, $withdrawId);
  135. }elseif ($param['mold'] == 10){
  136. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType23, $param['mold'], moldTypefild($param['mold']), $withdrawId);
  137. Db::table('wa_system')->where('id',1)->increment('completion_progress',10);
  138. } else {
  139. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType4, $param['mold'], moldTypefild($param['mold']), $withdrawId);
  140. }
  141. } catch (\Throwable $exception) {
  142. throw new \Exception($exception->getMessage());
  143. }
  144. return true;
  145. }
  146. /** 提现流水
  147. * @param array $param
  148. * @return void
  149. */
  150. static public function stream(array $param)
  151. {
  152. try {
  153. $data = Db::table('wa_withdraw')
  154. ->where(function ($query) use ($param) {
  155. if (!empty(Arr::get($param, 'mold'))) {
  156. $query->where('type', $param['mold']);
  157. }
  158. })
  159. ->where('user_id', $param['user_data']['id'])
  160. ->orderByDesc('id')
  161. ->paginate(Arr::get($param, 'limit', 10), ['*'], 'page', Arr::get($param, 'page'))
  162. ->toArray();
  163. foreach ($data['data'] as $k => $v) {
  164. $data['data'][$k]->mold_name = moldType($v->type);
  165. }
  166. } catch (\Throwable $exception) {
  167. throw new \Exception($exception->getMessage());
  168. }
  169. return $data;
  170. }
  171. /** 转账至五行银行卡
  172. * @param array $param
  173. * @return void
  174. */
  175. static public function transfer_accounts(array $param)
  176. {
  177. try {
  178. $system = Db::table('wa_system')->first();
  179. if ($param['mold'] != 2) {
  180. throw new \Exception('转账至五行银行卡暂未开放!');
  181. }
  182. $param['mold'] = 5;
  183. /** @var $bankCard 银行卡 */
  184. $bankCard = Db::table('wa_user_social_cark')->where('user_id', $param['user_data']['id'])->first();
  185. if (empty($bankCard)) {
  186. throw new \Exception('请先领取五行银行卡!');
  187. }
  188. /** @var $userIdentity 实名信息 */
  189. $userIdentity = Db::table('wa_user_identity')->where('uid', $param['user_data']['id'])->first();
  190. if (empty($userIdentity)) {
  191. throw new \Exception('请实名后,在转入!');
  192. }
  193. if (empty($system->conversion_value_cost)) {
  194. throw new \Exception('暂时不能转入!');
  195. }
  196. //五行银行卡余额变更
  197. $money = bcmul($param['money'], $system->conversion_value_cost, 2);
  198. Db::table('wa_user_social_cark')->where('user_id', $param['user_data']['id'])->increment('money', $money);
  199. //转账到五行银行卡余额
  200. StreamBusiness::addStream($param['user_data']['id'], $money, streamType14, moldType4, moldTypefild4);
  201. //减少股票账户
  202. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType14, $param['mold'], moldTypefild($param['mold']), $param['user_data']['id']);
  203. } catch (\Throwable $exception) {
  204. throw new \Exception($exception->getMessage());
  205. }
  206. return true;
  207. }
  208. }