WithdrawBusiness.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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. } elseif ($param['mold'] == 20) {
  90. if (10 > $param['money']) {
  91. throw new \Exception('最小提现金额:10元');
  92. }
  93. } elseif ($param['mold'] == 21) {
  94. if (10 > $param['money']) {
  95. throw new \Exception('最小提现金额:10元');
  96. }
  97. }elseif ($param['mold'] == 22) {
  98. if (10 > $param['money']) {
  99. throw new \Exception('最小提现金额:10元');
  100. }
  101. }elseif ($param['mold'] == 23) {
  102. // if($param['user_data']['new_is_num']<3){
  103. // throw new \Exception('邀请三人即可提现');
  104. // }
  105. if (10 > $param['money']) {
  106. throw new \Exception('最小提现金额:10元');
  107. }
  108. }elseif ($param['mold'] == 24) {
  109. if (10 > $param['money']) {
  110. throw new \Exception('最小提现金额:10元');
  111. }
  112. }elseif ($param['mold'] == 25) {
  113. if (100 > $param['money']) {
  114. throw new \Exception('最小提现金额:100元');
  115. }
  116. } else {
  117. throw new \Exception('提现功能暂未开放!');
  118. }
  119. $remarks = '';
  120. if ($param['mold'] == 2) {
  121. $status = 3;
  122. $affiliated_bank = '';
  123. $account_holder = '';
  124. $card_number = '';
  125. } elseif ($param['mold'] == 5) {
  126. $status = 3;
  127. $affiliated_bank = '';
  128. $account_holder = '';
  129. $card_number = '';
  130. } elseif ($param['mold'] == 6) {
  131. $status = 1;
  132. $affiliated_bank = '';
  133. $account_holder = '';
  134. $card_number = '';
  135. } elseif ($param['mold'] == 10) {
  136. $status = 1;
  137. $affiliated_bank = '';
  138. $account_holder = '';
  139. $card_number = '';
  140. $remarks = '全球通金卡提现申请通过,已打款';
  141. }elseif ($param['mold'] == 17) {
  142. $status = 3;
  143. $affiliated_bank = '';
  144. $account_holder = '';
  145. $card_number = '';
  146. } elseif ($param['mold'] == 1) {
  147. $status = 3;
  148. $affiliated_bank = '';
  149. $account_holder = '';
  150. $card_number = '';
  151. $userdata = Db::table('wa_users')->where('id', $param['user_data']['id'])->first();
  152. if ($userdata->money_fourteen < $param['money']) {
  153. throw new \Exception('今日提现额度不足!');
  154. }
  155. if ($userdata->money_four < $param['money']) {
  156. throw new \Exception('银行卡基础额度不足!');
  157. }
  158. } elseif ($param['mold'] == 55) {
  159. $status = 3;
  160. $affiliated_bank = '';
  161. $account_holder = '';
  162. $card_number = '';
  163. $userdata = Db::table('wa_users')->where('id', $param['user_data']['id'])->first();
  164. $money_five_value = bcmul($param['money'], $system->coin_value, 2);
  165. if ($userdata->money_thirteen < $money_five_value) {
  166. throw new \Exception('今日提现额度不足!');
  167. }
  168. if ($userdata->money_four < $money_five_value) {
  169. throw new \Exception('银行卡基础额度不足!');
  170. }
  171. } elseif ($param['mold'] == 17) {
  172. $status = 3;
  173. $affiliated_bank = '';
  174. $account_holder = '';
  175. $card_number = '';
  176. $remarks = '提现成功';
  177. }elseif ($param['mold'] == 23) {
  178. /** @var $bankCard 银行卡 */
  179. $bankCard = Db::table('wa_bank_card')->where('uid', $param['user_data']['id'])->first();
  180. if (empty($bankCard)) {
  181. throw new \Exception('请绑定银行卡!');
  182. }
  183. /** @var $userIdentity 实名信息 */
  184. $userIdentity = Db::table('wa_user_identity')->where('uid', $param['user_data']['id'])->first();
  185. if (empty($userIdentity)) {
  186. throw new \Exception('请实名后,在提现!');
  187. }
  188. $status = 1;
  189. $affiliated_bank = $bankCard->affiliated_bank;
  190. $account_holder = $bankCard->account_holder;
  191. $card_number = $bankCard->card_number;
  192. }elseif ($param['mold'] == 22) {
  193. /** @var $bankCard 银行卡 */
  194. $bankCard = Db::table('wa_bank_card')->where('uid', $param['user_data']['id'])->first();
  195. if (empty($bankCard)) {
  196. throw new \Exception('请绑定银行卡!');
  197. }
  198. /** @var $userIdentity 实名信息 */
  199. $userIdentity = Db::table('wa_user_identity')->where('uid', $param['user_data']['id'])->first();
  200. if (empty($userIdentity)) {
  201. throw new \Exception('请实名后,在提现!');
  202. }
  203. $status = 1;
  204. $affiliated_bank = $bankCard->affiliated_bank;
  205. $account_holder = $bankCard->account_holder;
  206. $card_number = $bankCard->card_number;
  207. } else {
  208. /** @var $bankCard 银行卡 */
  209. $bankCard = Db::table('wa_bank_card')->where('uid', $param['user_data']['id'])->first();
  210. if (empty($bankCard)) {
  211. throw new \Exception('请绑定银行卡!');
  212. }
  213. /** @var $userIdentity 实名信息 */
  214. $userIdentity = Db::table('wa_user_identity')->where('uid', $param['user_data']['id'])->first();
  215. if (empty($userIdentity)) {
  216. throw new \Exception('请实名后,在提现!');
  217. }
  218. $hasWithdraw = Db::table('wa_withdraw')
  219. ->where('type', $param['mold'])
  220. ->where('user_id', $param['user_data']['id'])
  221. ->whereBetween('created_at', [date('Y-m-d') . ' 00:00:00', date('Y-m-d') . ' 23:59:59'])->exists();
  222. if ($hasWithdraw) {
  223. throw new \Exception('今日已提现,请次日在来提现!');
  224. }
  225. $status = 1;
  226. $affiliated_bank = $bankCard->affiliated_bank;
  227. $account_holder = $bankCard->account_holder;
  228. $card_number = $bankCard->card_number;
  229. }
  230. $withdrawId = Db::table('wa_withdraw')->insertGetId([
  231. 'order_no' => date('YmdHis') . mt_rand(10000, 99999),
  232. 'user_id' => $param['user_data']['id'],
  233. 'money' => $param['money'],
  234. 'type' => $param['mold'],
  235. 'affiliated_bank' => $affiliated_bank,
  236. 'account_holder' => $account_holder,
  237. 'card_number' => $card_number,
  238. 'name' => Arr::get($param, 'name', ''),
  239. 'identity' => Arr::get($param, 'identity', ''),
  240. 'img' => !empty(Arr::get($param, 'img', '')) ? implode(',', Arr::get($param, 'img', '')) : '',
  241. 'created_at' => date('Y-m-d H:i:s'),
  242. 'updated_at' => date('Y-m-d H:i:s'),
  243. 'status' => $status,
  244. 'remarks' => $remarks
  245. ]);
  246. if ($param['mold'] == 2) {
  247. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType14, $param['mold'], moldTypefild($param['mold']), $withdrawId);
  248. StreamBusiness::addStream($param['user_data']['id'], $param['money'], streamType14, moldType3, moldTypefild3, $withdrawId);
  249. } elseif ($param['mold'] == 5) {
  250. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType24, $param['mold'], moldTypefild($param['mold']), $withdrawId);
  251. StreamBusiness::delStream($param['user_data']['id'], 100, streamType22, moldType5, moldTypefild5, $withdrawId);
  252. StreamBusiness::addStream($param['user_data']['id'], bcmul($param['money'], $system->coin_value, 2), streamType24, moldType10, moldTypefild10, $withdrawId);
  253. } elseif ($param['mold'] == 10) {
  254. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType4, $param['mold'], moldTypefild($param['mold']), $withdrawId);
  255. // Db::table('wa_system')->where('id',1)->increment('completion_progress',10);
  256. // Db::table('wa_users')->where('id', $param['user_data']['id'])->increment('bank_money', $param['money']);
  257. // StreamBusiness::addStream($param['user_data']['id'],$param['money'], streamType4, moldType3, moldTypefild3,$withdrawId);
  258. } elseif ($param['mold'] == 17) {
  259. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType4, $param['mold'], moldTypefild($param['mold']), $withdrawId);
  260. StreamBusiness::addStream($param['user_data']['id'], $param['money'], streamType4, moldType3, moldTypefild3, $withdrawId);
  261. } elseif ($param['mold'] == 1) {
  262. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType4, $param['mold'], moldTypefild($param['mold']), $withdrawId);
  263. StreamBusiness::addStream($param['user_data']['id'], $param['money'], streamType4, moldType10, moldTypefild10, $withdrawId);
  264. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType4, moldType4, moldTypefild4, $withdrawId);
  265. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType4, moldType14, moldTypefild14, $withdrawId);
  266. } elseif ($param['mold'] == 55) {
  267. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType4, moldType5, moldTypefild5, $withdrawId);
  268. StreamBusiness::addStream($param['user_data']['id'], bcmul($param['money'], $system->coin_value, 2), streamType4, moldType10, moldTypefild10, $withdrawId);
  269. StreamBusiness::delStream($param['user_data']['id'], bcmul($param['money'], $system->coin_value, 2), streamType4, moldType4, moldTypefild4, $withdrawId);
  270. StreamBusiness::delStream($param['user_data']['id'], bcmul($param['money'], $system->coin_value, 2), streamType4, moldType13, moldTypefild13, $withdrawId);
  271. } else {
  272. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType4, $param['mold'], moldTypefild($param['mold']), $withdrawId);
  273. }
  274. } catch (\Throwable $exception) {
  275. throw new \Exception($exception->getMessage());
  276. }
  277. return true;
  278. }
  279. /** 提现流水
  280. * @param array $param
  281. * @return void
  282. */
  283. static public function stream(array $param)
  284. {
  285. try {
  286. $data = Db::table('wa_withdraw')
  287. ->where(function ($query) use ($param) {
  288. if (!empty(Arr::get($param, 'mold'))) {
  289. if($param['mold']==111){
  290. $query->whereIn('type', [10, 16, 17, 18]);
  291. }elseif ($param['mold']==222){
  292. $query->whereIn('type', [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 19, 55,24,25]);
  293. }else{
  294. $query->where('type', $param['mold']);
  295. }
  296. }
  297. })->where('money','>',0)
  298. ->where('user_id', $param['user_data']['id'])
  299. ->orderByDesc('id')
  300. ->paginate(Arr::get($param, 'limit', 10), ['*'], 'page', Arr::get($param, 'page'))
  301. ->toArray();
  302. foreach ($data['data'] as $k => $v) {
  303. $is_buy_tuikuianll = Db::table('wa_payorder')
  304. ->where('user_id', $param['user_data']['id'])
  305. ->where('is_pay', 2)
  306. ->where('goods_type', 15)
  307. ->exists();
  308. $jieshutime = strtotime(date('Y-m-23',time()));
  309. if(!$is_buy_tuikuianll && $jieshutime<time()){
  310. $data['data'][$k]->new_state = 3;
  311. }
  312. $is_buy_xinc_daoz = Db::table('wa_payorder')
  313. ->where('user_id', $param['user_data']['id'])
  314. ->where('is_pay', 2)
  315. ->where('goods_type', 21)
  316. ->exists();
  317. if($is_buy_xinc_daoz && $v->type==22){
  318. $data['data'][$k]->status = 3;
  319. }
  320. $is_buy_jinka_daoz = Db::table('wa_payorder')
  321. ->where('user_id', $param['user_data']['id'])
  322. ->where('is_pay', 2)
  323. ->where('goods_type', 10)
  324. ->exists();
  325. if($is_buy_jinka_daoz && $v->type==10){
  326. $data['data'][$k]->status = 3;
  327. }
  328. $is_buy_zongzc_daoz = Db::table('wa_payorder')
  329. ->where('user_id', $param['user_data']['id'])
  330. ->where('is_pay', 2)
  331. ->where('goods_type', 23)
  332. ->exists();
  333. if($is_buy_zongzc_daoz && $v->type==23){
  334. $data['data'][$k]->status = 3;
  335. }
  336. $data['data'][$k]->mold_name = moldType($v->type);
  337. }
  338. } catch (\Throwable $exception) {
  339. throw new \Exception($exception->getMessage());
  340. }
  341. return $data;
  342. }
  343. /** 转账至五行银行卡
  344. * @param array $param
  345. * @return void
  346. */
  347. static public function transfer_accounts(array $param)
  348. {
  349. try {
  350. $system = Db::table('wa_system')->first();
  351. if ($param['mold'] != 2) {
  352. throw new \Exception('转账至五行银行卡暂未开放!');
  353. }
  354. $param['mold'] = 5;
  355. /** @var $bankCard 银行卡 */
  356. $bankCard = Db::table('wa_user_social_cark')->where('user_id', $param['user_data']['id'])->first();
  357. if (empty($bankCard)) {
  358. throw new \Exception('请先领取五行银行卡!');
  359. }
  360. /** @var $userIdentity 实名信息 */
  361. $userIdentity = Db::table('wa_user_identity')->where('uid', $param['user_data']['id'])->first();
  362. if (empty($userIdentity)) {
  363. throw new \Exception('请实名后,在转入!');
  364. }
  365. if (empty($system->conversion_value_cost)) {
  366. throw new \Exception('暂时不能转入!');
  367. }
  368. //五行银行卡余额变更
  369. $money = bcmul($param['money'], $system->conversion_value_cost, 2);
  370. Db::table('wa_user_social_cark')->where('user_id', $param['user_data']['id'])->increment('money', $money);
  371. //转账到五行银行卡余额
  372. StreamBusiness::addStream($param['user_data']['id'], $money, streamType14, moldType4, moldTypefild4);
  373. //减少股票账户
  374. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType14, $param['mold'], moldTypefild($param['mold']), $param['user_data']['id']);
  375. } catch (\Throwable $exception) {
  376. throw new \Exception($exception->getMessage());
  377. }
  378. return true;
  379. }
  380. }