WithdrawBusiness.php 12 KB

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