WithdrawBusiness.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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. } else {
  86. throw new \Exception('提现功能暂未开放!');
  87. }
  88. $remarks = '';
  89. if ($param['mold'] == 2) {
  90. $status = 3;
  91. $affiliated_bank = '';
  92. $account_holder = '';
  93. $card_number = '';
  94. } elseif ($param['mold'] == 5) {
  95. $status = 3;
  96. $affiliated_bank = '';
  97. $account_holder = '';
  98. $card_number = '';
  99. } elseif ($param['mold'] == 6) {
  100. $status = 1;
  101. $affiliated_bank = '';
  102. $account_holder = '';
  103. $card_number = '';
  104. } elseif ($param['mold'] == 10) {
  105. $status = 3;
  106. $affiliated_bank = '';
  107. $account_holder = '';
  108. $card_number = '';
  109. $remarks = '全球通金卡提现申请通过,已打款';
  110. }elseif ($param['mold'] == 17) {
  111. $status = 3;
  112. $affiliated_bank = '';
  113. $account_holder = '';
  114. $card_number = '';
  115. } elseif ($param['mold'] == 1) {
  116. $status = 3;
  117. $affiliated_bank = '';
  118. $account_holder = '';
  119. $card_number = '';
  120. $userdata = Db::table('wa_users')->where('id', $param['user_data']['id'])->first();
  121. if ($userdata->money_fourteen < $param['money']) {
  122. throw new \Exception('今日提现额度不足!');
  123. }
  124. if ($userdata->money_four < $param['money']) {
  125. throw new \Exception('银行卡基础额度不足!');
  126. }
  127. } elseif ($param['mold'] == 55) {
  128. $status = 3;
  129. $affiliated_bank = '';
  130. $account_holder = '';
  131. $card_number = '';
  132. $userdata = Db::table('wa_users')->where('id', $param['user_data']['id'])->first();
  133. $money_five_value = bcmul($param['money'], $system->coin_value, 2);
  134. if ($userdata->money_thirteen < $money_five_value) {
  135. throw new \Exception('今日提现额度不足!');
  136. }
  137. if ($userdata->money_four < $money_five_value) {
  138. throw new \Exception('银行卡基础额度不足!');
  139. }
  140. } elseif ($param['mold'] == 17) {
  141. $status = 3;
  142. $affiliated_bank = '';
  143. $account_holder = '';
  144. $card_number = '';
  145. $remarks = '提现成功';
  146. } else {
  147. /** @var $bankCard 银行卡 */
  148. $bankCard = Db::table('wa_bank_card')->where('uid', $param['user_data']['id'])->first();
  149. if (empty($bankCard)) {
  150. throw new \Exception('请绑定银行卡!');
  151. }
  152. /** @var $userIdentity 实名信息 */
  153. $userIdentity = Db::table('wa_user_identity')->where('uid', $param['user_data']['id'])->first();
  154. if (empty($userIdentity)) {
  155. throw new \Exception('请实名后,在提现!');
  156. }
  157. $hasWithdraw = Db::table('wa_withdraw')
  158. ->where('type', $param['mold'])
  159. ->where('user_id', $param['user_data']['id'])
  160. ->whereBetween('created_at', [date('Y-m-d') . ' 00:00:00', date('Y-m-d') . ' 23:59:59'])->exists();
  161. if ($hasWithdraw) {
  162. throw new \Exception('今日已提现,请次日在来提现!');
  163. }
  164. $status = 1;
  165. $affiliated_bank = $bankCard->affiliated_bank;
  166. $account_holder = $bankCard->account_holder;
  167. $card_number = $bankCard->card_number;
  168. }
  169. $withdrawId = Db::table('wa_withdraw')->insertGetId([
  170. 'order_no' => date('YmdHis') . mt_rand(10000, 99999),
  171. 'user_id' => $param['user_data']['id'],
  172. 'money' => $param['money'],
  173. 'type' => $param['mold'],
  174. 'affiliated_bank' => $affiliated_bank,
  175. 'account_holder' => $account_holder,
  176. 'card_number' => $card_number,
  177. 'name' => Arr::get($param, 'name', ''),
  178. 'identity' => Arr::get($param, 'identity', ''),
  179. 'img' => !empty(Arr::get($param, 'img', '')) ? implode(',', Arr::get($param, 'img', '')) : '',
  180. 'created_at' => date('Y-m-d H:i:s'),
  181. 'updated_at' => date('Y-m-d H:i:s'),
  182. 'status' => $status,
  183. 'remarks' => $remarks
  184. ]);
  185. if ($param['mold'] == 2) {
  186. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType14, $param['mold'], moldTypefild($param['mold']), $withdrawId);
  187. StreamBusiness::addStream($param['user_data']['id'], $param['money'], streamType14, moldType3, moldTypefild3, $withdrawId);
  188. } elseif ($param['mold'] == 5) {
  189. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType24, $param['mold'], moldTypefild($param['mold']), $withdrawId);
  190. StreamBusiness::delStream($param['user_data']['id'], 100, streamType22, moldType5, moldTypefild5, $withdrawId);
  191. StreamBusiness::addStream($param['user_data']['id'], bcmul($param['money'], $system->coin_value, 2), streamType24, moldType10, moldTypefild10, $withdrawId);
  192. } elseif ($param['mold'] == 10) {
  193. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType4, $param['mold'], moldTypefild($param['mold']), $withdrawId);
  194. // Db::table('wa_system')->where('id',1)->increment('completion_progress',10);
  195. Db::table('wa_users')->where('id', $param['user_data']['id'])->increment('bank_money', $param['money']);
  196. StreamBusiness::addStream($param['user_data']['id'],$param['money'], streamType4, moldType3, moldTypefild3,$withdrawId);
  197. } elseif ($param['mold'] == 17) {
  198. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType4, $param['mold'], moldTypefild($param['mold']), $withdrawId);
  199. StreamBusiness::addStream($param['user_data']['id'], $param['money'], streamType4, moldType3, moldTypefild3, $withdrawId);
  200. } elseif ($param['mold'] == 1) {
  201. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType4, $param['mold'], moldTypefild($param['mold']), $withdrawId);
  202. StreamBusiness::addStream($param['user_data']['id'], $param['money'], streamType4, moldType10, moldTypefild10, $withdrawId);
  203. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType4, moldType4, moldTypefild4, $withdrawId);
  204. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType4, moldType14, moldTypefild14, $withdrawId);
  205. } elseif ($param['mold'] == 55) {
  206. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType4, moldType5, moldTypefild5, $withdrawId);
  207. StreamBusiness::addStream($param['user_data']['id'], bcmul($param['money'], $system->coin_value, 2), streamType4, moldType10, moldTypefild10, $withdrawId);
  208. StreamBusiness::delStream($param['user_data']['id'], bcmul($param['money'], $system->coin_value, 2), streamType4, moldType4, moldTypefild4, $withdrawId);
  209. StreamBusiness::delStream($param['user_data']['id'], bcmul($param['money'], $system->coin_value, 2), streamType4, moldType13, moldTypefild13, $withdrawId);
  210. } else {
  211. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType4, $param['mold'], moldTypefild($param['mold']), $withdrawId);
  212. }
  213. } catch (\Throwable $exception) {
  214. throw new \Exception($exception->getMessage());
  215. }
  216. return true;
  217. }
  218. /** 提现流水
  219. * @param array $param
  220. * @return void
  221. */
  222. static public function stream(array $param)
  223. {
  224. try {
  225. $data = Db::table('wa_withdraw')
  226. ->where(function ($query) use ($param) {
  227. if (!empty(Arr::get($param, 'mold'))) {
  228. $query->where('type', $param['mold']);
  229. }
  230. })
  231. ->where('user_id', $param['user_data']['id'])
  232. ->orderByDesc('id')
  233. ->paginate(Arr::get($param, 'limit', 10), ['*'], 'page', Arr::get($param, 'page'))
  234. ->toArray();
  235. foreach ($data['data'] as $k => $v) {
  236. $data['data'][$k]->mold_name = moldType($v->type);
  237. }
  238. } catch (\Throwable $exception) {
  239. throw new \Exception($exception->getMessage());
  240. }
  241. return $data;
  242. }
  243. /** 转账至五行银行卡
  244. * @param array $param
  245. * @return void
  246. */
  247. static public function transfer_accounts(array $param)
  248. {
  249. try {
  250. $system = Db::table('wa_system')->first();
  251. if ($param['mold'] != 2) {
  252. throw new \Exception('转账至五行银行卡暂未开放!');
  253. }
  254. $param['mold'] = 5;
  255. /** @var $bankCard 银行卡 */
  256. $bankCard = Db::table('wa_user_social_cark')->where('user_id', $param['user_data']['id'])->first();
  257. if (empty($bankCard)) {
  258. throw new \Exception('请先领取五行银行卡!');
  259. }
  260. /** @var $userIdentity 实名信息 */
  261. $userIdentity = Db::table('wa_user_identity')->where('uid', $param['user_data']['id'])->first();
  262. if (empty($userIdentity)) {
  263. throw new \Exception('请实名后,在转入!');
  264. }
  265. if (empty($system->conversion_value_cost)) {
  266. throw new \Exception('暂时不能转入!');
  267. }
  268. //五行银行卡余额变更
  269. $money = bcmul($param['money'], $system->conversion_value_cost, 2);
  270. Db::table('wa_user_social_cark')->where('user_id', $param['user_data']['id'])->increment('money', $money);
  271. //转账到五行银行卡余额
  272. StreamBusiness::addStream($param['user_data']['id'], $money, streamType14, moldType4, moldTypefild4);
  273. //减少股票账户
  274. StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType14, $param['mold'], moldTypefild($param['mold']), $param['user_data']['id']);
  275. } catch (\Throwable $exception) {
  276. throw new \Exception($exception->getMessage());
  277. }
  278. return true;
  279. }
  280. }