WithdrawBusiness.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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. throw new \Exception('提现功能暂未开放!');
  20. if (empty($system->is_money)) {
  21. throw new \Exception('提现功能暂未开放!');
  22. }
  23. if ($system->min_money > $param['money']) {
  24. throw new \Exception('最小提现金额:' . $system->min_money . '元');
  25. }
  26. } elseif ($param['mold'] == 2) {
  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. } elseif ($param['mold'] == 5) {
  35. } elseif ($param['mold'] == 6) {
  36. // if (empty($system->is_money_one)) {
  37. // throw new \Exception('兑换功能暂未开放!');
  38. // }
  39. if (10 > $param['money']) {
  40. throw new \Exception('最小提现金额:10USD');
  41. }
  42. } elseif ($param['mold'] == 10) {
  43. } elseif ($param['mold'] == 7) {
  44. if (empty($system->is_money_seven)) {
  45. throw new \Exception('提现功能暂未开放!');
  46. }
  47. if ($system->min_money_seven > $param['money']) {
  48. throw new \Exception('最小提现金额:' . $system->min_money_seven . '元');
  49. }
  50. } elseif ($param['mold'] == 8) {
  51. if (empty($system->is_money_eight)) {
  52. throw new \Exception('提现功能暂未开放!');
  53. }
  54. if ($system->min_money_eight > $param['money']) {
  55. throw new \Exception('最小提现金额:' . $system->min_money_eight . '元');
  56. }
  57. } elseif ($param['mold'] == 9) {
  58. if (empty($system->is_money_nine)) {
  59. throw new \Exception('提现功能暂未开放!');
  60. }
  61. if ($system->min_money_nine > $param['money']) {
  62. throw new \Exception('最小提现金额:' . $system->min_money_nine . '元');
  63. }
  64. } elseif ($param['mold'] == 11) {
  65. if (10 > $param['money']) {
  66. throw new \Exception('最小提现金额:10元');
  67. }
  68. } elseif ($param['mold'] == 12) {
  69. if (10 > $param['money']) {
  70. throw new \Exception('最小提现金额:10元');
  71. }
  72. } elseif ($param['mold'] == 55) {
  73. } elseif ($param['mold'] == 15) {
  74. if (10 > $param['money']) {
  75. throw new \Exception('最小提现金额:10元');
  76. }
  77. } elseif ($param['mold'] == 16) {
  78. if (10 > $param['money']) {
  79. throw new \Exception('最小提现金额:10元');
  80. }
  81. } elseif ($param['mold'] == 17) {
  82. if (10 > $param['money']) {
  83. throw new \Exception('最小提现金额:10元');
  84. }
  85. } elseif ($param['mold'] == 19) {
  86. if (10 > $param['money']) {
  87. throw new \Exception('最小提现金额:10元');
  88. }
  89. } else {
  90. throw new \Exception('提现功能暂未开放!');
  91. }
  92. $remarks = '';
  93. if ($param['mold'] == 2) {
  94. $status = 3;
  95. $affiliated_bank = '';
  96. $account_holder = '';
  97. $card_number = '';
  98. } elseif ($param['mold'] == 5) {
  99. $status = 3;
  100. $affiliated_bank = '';
  101. $account_holder = '';
  102. $card_number = '';
  103. } elseif ($param['mold'] == 6) {
  104. $status = 1;
  105. $affiliated_bank = '';
  106. $account_holder = '';
  107. $card_number = '';
  108. } elseif ($param['mold'] == 10) {
  109. $status = 3;
  110. $affiliated_bank = '';
  111. $account_holder = '';
  112. $card_number = '';
  113. $remarks = '全球通金卡提现申请通过,已打款';
  114. }elseif ($param['mold'] == 17) {
  115. $status = 3;
  116. $affiliated_bank = '';
  117. $account_holder = '';
  118. $card_number = '';
  119. } elseif ($param['mold'] == 1) {
  120. $status = 3;
  121. $affiliated_bank = '';
  122. $account_holder = '';
  123. $card_number = '';
  124. $userdata = Db::table('wa_users')->where('id', $param['user_data']['id'])->first();
  125. if ($userdata->money_fourteen < $param['money']) {
  126. throw new \Exception('今日提现额度不足!');
  127. }
  128. if ($userdata->money_four < $param['money']) {
  129. throw new \Exception('银行卡基础额度不足!');
  130. }
  131. } elseif ($param['mold'] == 55) {
  132. $status = 3;
  133. $affiliated_bank = '';
  134. $account_holder = '';
  135. $card_number = '';
  136. $userdata = Db::table('wa_users')->where('id', $param['user_data']['id'])->first();
  137. $money_five_value = bcmul($param['money'], $system->coin_value, 2);
  138. if ($userdata->money_thirteen < $money_five_value) {
  139. throw new \Exception('今日提现额度不足!');
  140. }
  141. if ($userdata->money_four < $money_five_value) {
  142. throw new \Exception('银行卡基础额度不足!');
  143. }
  144. } elseif ($param['mold'] == 17) {
  145. $status = 3;
  146. $affiliated_bank = '';
  147. $account_holder = '';
  148. $card_number = '';
  149. $remarks = '提现成功';
  150. } else {
  151. /** @var $bankCard 银行卡 */
  152. $bankCard = Db::table('wa_bank_card')->where('uid', $param['user_data']['id'])->first();
  153. if (empty($bankCard)) {
  154. throw new \Exception('请绑定银行卡!');
  155. }
  156. /** @var $userIdentity 实名信息 */
  157. $userIdentity = Db::table('wa_user_identity')->where('uid', $param['user_data']['id'])->first();
  158. if (empty($userIdentity)) {
  159. throw new \Exception('请实名后,在提现!');
  160. }
  161. $hasWithdraw = Db::table('wa_withdraw')
  162. ->where('type', $param['mold'])
  163. ->where('user_id', $param['user_data']['id'])
  164. ->whereBetween('created_at', [date('Y-m-d') . ' 00:00:00', date('Y-m-d') . ' 23:59:59'])->exists();
  165. if ($hasWithdraw) {
  166. throw new \Exception('今日已提现,请次日在来提现!');
  167. }
  168. $status = 1;
  169. $affiliated_bank = $bankCard->affiliated_bank;
  170. $account_holder = $bankCard->account_holder;
  171. $card_number = $bankCard->card_number;
  172. }
  173. $withdrawId = Db::table('wa_withdraw')->insertGetId([
  174. 'order_no' => date('YmdHis') . mt_rand(10000, 99999),
  175. 'user_id' => $param['user_data']['id'],
  176. 'money' => $param['money'],
  177. 'type' => $param['mold'],
  178. 'affiliated_bank' => $affiliated_bank,
  179. 'account_holder' => $account_holder,
  180. 'card_number' => $card_number,
  181. 'name' => Arr::get($param, 'name', ''),
  182. 'identity' => Arr::get($param, 'identity', ''),
  183. 'img' => !empty(Arr::get($param, 'img', '')) ? implode(',', Arr::get($param, 'img', '')) : '',
  184. 'created_at' => date('Y-m-d H:i:s'),
  185. 'updated_at' => date('Y-m-d H:i:s'),
  186. 'status' => $status,
  187. 'remarks' => $remarks
  188. ]);
  189. if ($param['mold'] == 2) {
  190. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType14, $param['mold'], moldTypefild($param['mold']), $withdrawId);
  191. StreamBusiness::addStream($param['user_data']['id'], $param['money'], streamType14, moldType3, moldTypefild3, $withdrawId);
  192. } elseif ($param['mold'] == 5) {
  193. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType24, $param['mold'], moldTypefild($param['mold']), $withdrawId);
  194. StreamBusiness::delStream($param['user_data']['id'], 100, streamType22, moldType5, moldTypefild5, $withdrawId);
  195. StreamBusiness::addStream($param['user_data']['id'], bcmul($param['money'], $system->coin_value, 2), streamType24, moldType10, moldTypefild10, $withdrawId);
  196. } elseif ($param['mold'] == 10) {
  197. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType4, $param['mold'], moldTypefild($param['mold']), $withdrawId);
  198. // Db::table('wa_system')->where('id',1)->increment('completion_progress',10);
  199. Db::table('wa_users')->where('id', $param['user_data']['id'])->increment('bank_money', $param['money']);
  200. StreamBusiness::addStream($param['user_data']['id'],$param['money'], streamType4, moldType3, moldTypefild3,$withdrawId);
  201. } elseif ($param['mold'] == 17) {
  202. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType4, $param['mold'], moldTypefild($param['mold']), $withdrawId);
  203. StreamBusiness::addStream($param['user_data']['id'], $param['money'], streamType4, moldType3, moldTypefild3, $withdrawId);
  204. } elseif ($param['mold'] == 1) {
  205. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType4, $param['mold'], moldTypefild($param['mold']), $withdrawId);
  206. StreamBusiness::addStream($param['user_data']['id'], $param['money'], streamType4, moldType10, moldTypefild10, $withdrawId);
  207. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType4, moldType4, moldTypefild4, $withdrawId);
  208. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType4, moldType14, moldTypefild14, $withdrawId);
  209. } elseif ($param['mold'] == 55) {
  210. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType4, moldType5, moldTypefild5, $withdrawId);
  211. StreamBusiness::addStream($param['user_data']['id'], bcmul($param['money'], $system->coin_value, 2), streamType4, moldType10, moldTypefild10, $withdrawId);
  212. StreamBusiness::delStream($param['user_data']['id'], bcmul($param['money'], $system->coin_value, 2), streamType4, moldType4, moldTypefild4, $withdrawId);
  213. StreamBusiness::delStream($param['user_data']['id'], bcmul($param['money'], $system->coin_value, 2), streamType4, moldType13, moldTypefild13, $withdrawId);
  214. } else {
  215. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType4, $param['mold'], moldTypefild($param['mold']), $withdrawId);
  216. }
  217. } catch (\Throwable $exception) {
  218. throw new \Exception($exception->getMessage());
  219. }
  220. return true;
  221. }
  222. /** 提现流水
  223. * @param array $param
  224. * @return void
  225. */
  226. static public function stream(array $param)
  227. {
  228. try {
  229. $data = Db::table('wa_withdraw')
  230. ->where(function ($query) use ($param) {
  231. if (!empty(Arr::get($param, 'mold'))) {
  232. if($param['mold']==111){
  233. $query->whereIn('type', [10, 16, 17, 18]);
  234. }else{
  235. $query->where('type', $param['mold']);
  236. }
  237. }
  238. })
  239. ->where('user_id', $param['user_data']['id'])
  240. ->orderByDesc('id')
  241. ->paginate(Arr::get($param, 'limit', 10), ['*'], 'page', Arr::get($param, 'page'))
  242. ->toArray();
  243. foreach ($data['data'] as $k => $v) {
  244. $is_buy_tuikuianll = Db::table('wa_payorder')
  245. ->where('user_id', $param['user_data']['id'])
  246. ->where('is_pay', 2)
  247. ->where('goods_type', 15)
  248. ->exists();
  249. $jieshutime = strtotime(date('Y-m-23',time()));
  250. if(!$is_buy_tuikuianll && $jieshutime<time()){
  251. $data['data'][$k]->new_state = 3;
  252. }
  253. $data['data'][$k]->mold_name = moldType($v->type);
  254. }
  255. } catch (\Throwable $exception) {
  256. throw new \Exception($exception->getMessage());
  257. }
  258. return $data;
  259. }
  260. /** 转账至五行银行卡
  261. * @param array $param
  262. * @return void
  263. */
  264. static public function transfer_accounts(array $param)
  265. {
  266. try {
  267. $system = Db::table('wa_system')->first();
  268. if ($param['mold'] != 2) {
  269. throw new \Exception('转账至五行银行卡暂未开放!');
  270. }
  271. $param['mold'] = 5;
  272. /** @var $bankCard 银行卡 */
  273. $bankCard = Db::table('wa_user_social_cark')->where('user_id', $param['user_data']['id'])->first();
  274. if (empty($bankCard)) {
  275. throw new \Exception('请先领取五行银行卡!');
  276. }
  277. /** @var $userIdentity 实名信息 */
  278. $userIdentity = Db::table('wa_user_identity')->where('uid', $param['user_data']['id'])->first();
  279. if (empty($userIdentity)) {
  280. throw new \Exception('请实名后,在转入!');
  281. }
  282. if (empty($system->conversion_value_cost)) {
  283. throw new \Exception('暂时不能转入!');
  284. }
  285. //五行银行卡余额变更
  286. $money = bcmul($param['money'], $system->conversion_value_cost, 2);
  287. Db::table('wa_user_social_cark')->where('user_id', $param['user_data']['id'])->increment('money', $money);
  288. //转账到五行银行卡余额
  289. StreamBusiness::addStream($param['user_data']['id'], $money, streamType14, moldType4, moldTypefild4);
  290. //减少股票账户
  291. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType14, $param['mold'], moldTypefild($param['mold']), $param['user_data']['id']);
  292. } catch (\Throwable $exception) {
  293. throw new \Exception($exception->getMessage());
  294. }
  295. return true;
  296. }
  297. }