WithdrawBusiness.php 12 KB

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