WithdrawBusiness.php 13 KB

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