getOldUserAssets($user_id,$account_type); } return $this->toData(0, 'Request successful.', $result); } protected function getOldUserAssets(int $user_id, int $account_type){ switch ($account_type) { case 1: $result = [ 'digital' => $this->getUserDigital([ 'user_id' => $user_id, 'account_type' => $account_type ]) ]; break; case 2: $result = [ 'contract' => $this->getUserContract([ 'user_id' => $user_id, 'account_type' => $account_type ]) ]; break; // 美股 case 3: $result = [ 'contract' => $this->getUserUsStock([ 'user_id' => $user_id, 'account_type' => $account_type ]) ]; break; // 印尼股票 case 4: $result = [ 'contract' => $this->getUserIdnStock([ 'user_id' => $user_id, 'account_type' => $account_type ]) ]; break; // 马来西亚股票 case 5: $result = [ 'contract' => $this->getUserMysStock([ 'user_id' => $user_id, 'account_type' => $account_type ]) ]; break; // 泰股股票 case 6: $result = [ 'contract' => $this->getUserThaStock([ 'user_id' => $user_id, 'account_type' => $account_type ]) ]; break; case 7: $result = [ 'contract' => $this->getUserInStock([ 'user_id' => $user_id, 'account_type' => $account_type ]) ]; break; // 秒合约 case 8: $result = [ 'contract' => $this->getUserContractSec([ 'user_id' => $user_id, 'account_type' => $account_type ]) ]; break; //新加坡 case 9: $result = [ 'contract' => $this->getUserSgdStock([ 'user_id' => $user_id, 'account_type' => $account_type ]) ]; break; //基金 case 10: $result = [ 'contract' => $this->getUserFundStock([ 'user_id' => $user_id, 'account_type' => $account_type ]) ]; break; //印度期权 case 11: $result = [ 'contract' => $this->getUserInOption([ 'user_id' => $user_id, 'account_type' => $account_type ]) ]; break; //港股 case 12: $result = [ 'contract' => $this->getUserHkStock([ 'user_id' => $user_id, 'account_type' => $account_type ]) ]; break; case 14: $result = [ 'contract' => $this->getUserUkStock([ 'user_id' => $user_id, 'account_type' => $account_type ]) ]; break; case 15: $result = [ 'contract' => $this->getUserFurStock([ 'user_id' => $user_id, 'account_type' => $account_type ]) ]; break; case 16: $result = [ 'contract' => $this->getUserEurStock([ 'user_id' => $user_id, 'account_type' => $account_type ]) ]; break; case 17: $result = [ 'contract' => $this->getUserBrlStock([ 'user_id' => $user_id, 'account_type' => $account_type ]) ]; break; case 18: $result = [ 'contract' => $this->getUserJpStock([ 'user_id' => $user_id, 'account_type' => $account_type ]) ]; break; case 19: $result = [ 'contract' => $this->getUserForex([ 'user_id' => $user_id, 'account_type' => $account_type ]) ]; break; default: $result = [ 'digital' => $this->getUserDigital([ 'user_id' => $user_id, 'account_type' => $account_type ]), 'contract' => $this->getUserContract([ 'user_id' => $user_id, 'account_type' => $account_type ]), 'forex' => $this->getUserForex([ 'user_id' => $user_id, 'account_type' => $account_type ]), 'contract_sec' => $this->getUserContractSec([ 'user_id' => $user_id, 'account_type' => $account_type ]), 'us_stock' => $this->getUserUsStock([ 'user_id' => $user_id, 'account_type' => $account_type ]), 'idn_stock' => $this->getUserIdnStock([ 'user_id' => $user_id, 'account_type' => $account_type ]), 'mys_stock' => $this->getUserMysStock([ 'user_id' => $user_id, 'account_type' => $account_type ]), 'tha_stock' => $this->getUserThaStock([ 'user_id' => $user_id, 'account_type' => $account_type ]), 'in_stock' => $this->getUserInStock([ 'user_id' => $user_id, 'account_type' => $account_type ]), 'sgd_stock' => $this->getUserSgdStock([ 'user_id' => $user_id, 'account_type' => $account_type ]), 'fund_stock' => $this->getUserFundStock([ 'user_id' => $user_id, 'account_type' => $account_type ]), 'option_in_stock' => $this->getUserInOption([ 'user_id' => $user_id, 'account_type' => $account_type ]), 'hk_stock' => $this->getUserHkStock([ 'user_id' => $user_id, 'account_type' => $account_type ]), 'uk_stock' => $this->getUserUkStock([ 'user_id' => $user_id, 'account_type' => $account_type ]), 'fur_stock' => $this->getUserFurStock([ 'user_id' => $user_id, 'account_type' => $account_type ]), 'eur_stock' => $this->getUserEurStock([ 'user_id' => $user_id, 'account_type' => $account_type ]), 'brl_stock' => $this->getUserBrlStock([ 'user_id' => $user_id, 'account_type' => $account_type ]), 'jp_stock' => $this->getUserJpStock([ 'user_id' => $user_id, 'account_type' => $account_type ]), ]; break; } return $result; } protected function getNewUserAssets(int $user_id){ $res=UserMoneyModel::where('user_id',$user_id)->field('usable_num,frozen_num,stock_id as name')->select(); $result=[]; if(!empty($res)){ $result=$res->toArray(); } return $result; } /** * 获取用户现货资产 * @param $user_id * @param int $type 0全部资产,1只获取usdt资产 * @return array */ private function getUserDigital(array $data, int $type = 0): array { try { validate(WalletValidate::class)->scene('getUserBalance')->check($data); if ($type == 0) { return UserDigitalModel::getUserDigitalList($data['user_id']); } else { return UserDigitalModel::getUserDigitalByUserId($data); } } catch (ValidateException $validateException) { $message = $validateException->getMessage(); return $this->toData('1', $message, []); } catch (\Exception $exception) { return $this->toData('100500', 'The system is busy. Please try again later.', [$exception->getMessage(), $exception->getTrace()]); } } /** * 获取用户合约资产 * @param $data * @return array */ private function getUserContract($data, int $type = 0): array { try { validate(WalletValidate::class)->scene('getUserBalance')->check($data); if ($type == 0) { return UserContractModel::getUserContractList($data['user_id']); } else { return UserContractModel::getUserContractByUserId($data); } } catch (ValidateException $validateException) { $message = $validateException->getMessage(); return $this->toData('1', $message, []); } catch (\Exception $exception) { return $this->toData('100500', 'The system is busy. Please try again later.', [$exception->getMessage(), $exception->getTrace()]); } } /** * 获取用户外汇资产 * @param $data * @return array */ private function getUserForex($data, int $type = 0): array { try { validate(WalletValidate::class)->scene('getUserBalance')->check($data); if ($type == 0) { return UserForexModel::getUserForexList($data['user_id']); } else { return UserForexModel::getUserForexByUserId($data); } } catch (ValidateException $validateException) { $message = $validateException->getMessage(); return $this->toData('1', $message, []); } catch (\Exception $exception) { return $this->toData('100500', 'The system is busy. Please try again later.', [$exception->getMessage(), $exception->getTrace()]); } } /** * 获取用户秒合约资产 * @param $data * @return array */ private function getUserContractSec($data, int $type = 0): array { try { validate(WalletValidate::class)->scene('getUserBalance')->check($data); if ($type == 0) { return UserContractSecModel::getUserContractList($data['user_id']); } else { return UserContractSecModel::getUserContractByUserId($data); } } catch (ValidateException $validateException) { $message = $validateException->getMessage(); return $this->toData('1', $message, []); } catch (\Exception $exception) { return $this->toData('100500', 'The system is busy. Please try again later.', [$exception->getMessage(), $exception->getTrace()]); } } /** * 获取用户美股资产 * @param $user_id * @return array */ private function getUserStock($data, int $type = 0): array { try { validate(WalletValidate::class)->scene('getUserBalance')->check($data); if ($type == 0) { return UserStockModel::getUserStockList($data['user_id']); } else { return UserStockModel::getUserStockByUserId($data); } } catch (ValidateException $validateException) { $message = $validateException->getMessage(); return $this->toData('1', $message, []); } catch (\Exception $exception) { return $this->toData('100500', 'The system is busy. Please try again later.', [$exception->getMessage(), $exception->getTrace()]); } } /** * 获取用户美股资产 * @param $user_id * @return array */ private function getUserUsStock($data, int $type = 0): array { try { validate(WalletValidate::class)->scene('getUserBalance')->check($data); if ($type == 0) { return UserStockModel::getUserStockList($data['user_id']); } else { return UserStockModel::getUserStockByUserId($data); } } catch (ValidateException $validateException) { $message = $validateException->getMessage(); return $this->toData('1', $message, []); } catch (\Exception $exception) { return $this->toData('100500', 'The system is busy. Please try again later.', [$exception->getMessage(), $exception->getTrace()]); } } /** * 获取用户印尼股票 资产 * @param $user_id * @return array */ private function getUserIdnStock($data, int $type = 0): array { try { validate(WalletValidate::class)->scene('getUserBalance')->check($data); if ($type == 0) { return UserStockIdnModel::getUserStockList($data['user_id']); } else { return UserStockIdnModel::getUserStockByUserId($data); } } catch (ValidateException $validateException) { $message = $validateException->getMessage(); return $this->toData('1', $message, []); } catch (\Exception $exception) { return $this->toData('100500', 'The system is busy. Please try again later.', [$exception->getMessage(), $exception->getTrace()]); } } private function getUserSgdStock($data, int $type = 0): array { try { validate(WalletValidate::class)->scene('getUserBalance')->check($data); if ($type == 0) { return UserStockSgdModel::getUserStockList($data['user_id']); } else { return UserStockSgdModel::getUserStockByUserId($data); } } catch (ValidateException $validateException) { $message = $validateException->getMessage(); return $this->toData('1', $message, []); } catch (\Exception $exception) { return $this->toData('100500', 'The system is busy. Please try again later.', [$exception->getMessage(), $exception->getTrace()]); } } private function getUserFundStock($data, int $type = 0): array { try { validate(WalletValidate::class)->scene('getUserBalance')->check($data); if ($type == 0) { return UserStockFundModel::getUserStockList($data['user_id']); } else { return UserStockFundModel::getUserStockByUserId($data); } } catch (ValidateException $validateException) { $message = $validateException->getMessage(); return $this->toData('1', $message, []); } catch (\Exception $exception) { return $this->toData('100500', 'The system is busy. Please try again later.', [$exception->getMessage(), $exception->getTrace()]); } } /** * 获取用户马来西亚股票 资产 * @param $user_id * @return array */ private function getUserMysStock($data, int $type = 0): array { try { validate(WalletValidate::class)->scene('getUserBalance')->check($data); if ($type == 0) { return UserStockMysModel::getUserStockList($data['user_id']); } else { return UserStockMysModel::getUserStockByUserId($data); } } catch (ValidateException $validateException) { $message = $validateException->getMessage(); return $this->toData('1', $message, []); } catch (\Exception $exception) { return $this->toData('100500', 'The system is busy. Please try again later.', [$exception->getMessage(), $exception->getTrace()]); } } /** * 获取用户马股股票 资产 * @param $user_id * @return array */ private function getUserThaStock($data, int $type = 0): array { try { validate(WalletValidate::class)->scene('getUserBalance')->check($data); if ($type == 0) { return UserStockThaModel::getUserStockList($data['user_id']); } else { return UserStockThaModel::getUserStockByUserId($data); } } catch (ValidateException $validateException) { $message = $validateException->getMessage(); return $this->toData('1', $message, []); } catch (\Exception $exception) { return $this->toData('100500', 'The system is busy. Please try again later.', [$exception->getMessage(), $exception->getTrace()]); } } /** * 获取用户印度股票 资产 * @param $user_id * @return array */ private function getUserInStock($data, int $type = 0): array { try { validate(WalletValidate::class)->scene('getUserBalance')->check($data); if ($type == 0) { return UserStockInModel::getUserStockList($data['user_id']); } else { return UserStockInModel::getUserStockByUserId($data); } } catch (ValidateException $validateException) { $message = $validateException->getMessage(); return $this->toData('1', $message, []); } catch (\Exception $exception) { return $this->toData('100500', 'The system is busy. Please try again later.', [$exception->getMessage(), $exception->getTrace()]); } } /** * 获取用户印度股票 资产 * @param $user_id * @return array */ private function getUserHkStock($data, int $type = 0): array { try { validate(WalletValidate::class)->scene('getUserBalance')->check($data); if ($type == 0) { return UserStockHkdModel::getUserStockList($data['user_id']); } else { return UserStockHkdModel::getUserStockByUserId($data); } } catch (ValidateException $validateException) { $message = $validateException->getMessage(); return $this->toData('1', $message, []); } catch (\Exception $exception) { return $this->toData('100500', 'The system is busy. Please try again later.', [$exception->getMessage(), $exception->getTrace()]); } } /** * 获取用户印度股票 资产 * @param $user_id * @return array */ private function getUserUkStock($data, int $type = 0): array { try { validate(WalletValidate::class)->scene('getUserBalance')->check($data); if ($type == 0) { return UserStockGBXModel::getUserStockList($data['user_id']); } else { return UserStockGBXModel::getUserStockByUserId($data); } } catch (ValidateException $validateException) { $message = $validateException->getMessage(); return $this->toData('1', $message, []); } catch (\Exception $exception) { return $this->toData('100500', 'The system is busy. Please try again later.', [$exception->getMessage(), $exception->getTrace()]); } } private function getUserFurStock($data, int $type = 0): array { try { validate(WalletValidate::class)->scene('getUserBalance')->check($data); if ($type == 0) { return UserStockFurModel::getUserStockList($data['user_id']); } else { return UserStockFurModel::getUserStockByUserId($data); } } catch (ValidateException $validateException) { $message = $validateException->getMessage(); return $this->toData('1', $message, []); } catch (\Exception $exception) { return $this->toData('100500', 'The system is busy. Please try again later.', [$exception->getMessage(), $exception->getTrace()]); } } private function getUserEurStock($data, int $type = 0): array { try { validate(WalletValidate::class)->scene('getUserBalance')->check($data); if ($type == 0) { return UserStockEurModel::getUserStockList($data['user_id']); } else { return UserStockEurModel::getUserStockByUserId($data); } } catch (ValidateException $validateException) { $message = $validateException->getMessage(); return $this->toData('1', $message, []); } catch (\Exception $exception) { return $this->toData('100500', 'The system is busy. Please try again later.', [$exception->getMessage(), $exception->getTrace()]); } } private function getUserBrlStock($data, int $type = 0): array { try { validate(WalletValidate::class)->scene('getUserBalance')->check($data); if ($type == 0) { return UserStockBrlModel::getUserStockList($data['user_id']); } else { return UserStockBrlModel::getUserStockByUserId($data); } } catch (ValidateException $validateException) { $message = $validateException->getMessage(); return $this->toData('1', $message, []); } catch (\Exception $exception) { return $this->toData('100500', 'The system is busy. Please try again later.', [$exception->getMessage(), $exception->getTrace()]); } } private function getUserJpStock($data, int $type = 0): array { try { validate(WalletValidate::class)->scene('getUserBalance')->check($data); if ($type == 0) { return UserStockJpModel::getUserStockList($data['user_id']); } else { return UserStockJpModel::getUserStockByUserId($data); } } catch (ValidateException $validateException) { $message = $validateException->getMessage(); return $this->toData('1', $message, []); } catch (\Exception $exception) { return $this->toData('100500', 'The system is busy. Please try again later.', [$exception->getMessage(), $exception->getTrace()]); } } /** * 获取用户印度期权资产 * @param $user_id * @return array */ private function getUserInOption($data, int $type = 0): array { try { validate(WalletValidate::class)->scene('getUserBalance')->check($data); if ($type == 0) { return UserStockOptionInrModel::getUserStockList($data['user_id']); } else { return UserStockOptionInrModel::getUserStockByUserId($data); } } catch (ValidateException $validateException) { $message = $validateException->getMessage(); return $this->toData('1', $message, []); } catch (\Exception $exception) { return $this->toData('100500', 'The system is busy. Please try again later.', [$exception->getMessage(), $exception->getTrace()]); } } /** * 获取用户充值列表 * @param array $data * @return array */ public function getUserRechargeList(array $data): array { try { validate(WalletValidate::class)->scene('getDrawalList')->check($data); $list = RechargeApplyModel::getUserRecharge($data); return $this->toData(0, 'Request successful.', $list); } catch (ValidateException $validateException) { $message = $validateException->getMessage(); return $this->toData('1', $message, []); } catch (\Exception $exception) { return $this->toData('100500', 'The system is busy. Please try again later.', [$exception->getMessage(), $exception->getTrace()]); } } public function getUserRechargeWallet(array $data): array { $list = WalletListModel::getUserWalletList([ 'wallet_type' => $data['wallet_type'] ]); return $this->toData(0, 'Request successful.', $list); } /** * 用户添加钱包地址 * @param array $data * @return array */ public function insertWalletAdress(array $data): array { try { validate(BankValidate::class)->scene('setWalletAddress')->check($data); UserWalletaddressModel::InsertUserWallet($data); return $this->toData(0, 'Request successful.'); } catch (ValidateException $validateException) { $message = $validateException->getMessage(); return $this->toData('1', $message, []); } catch (\Exception $exception) { return $this->toData('100500', 'The system is busy. Please try again later.', [$exception->getMessage(), $exception->getTrace()]); } } /** * 获取用户钱包地址列表 * @param array $data * @return array */ public function getUserWalletAddress(array $data): array { try { validate(BankValidate::class)->scene('getWalletAddressList')->check($data); $address_list = UserWalletaddressModel::getUserWalletList($data); return $this->toData(0, 'Request successful.', $address_list); } catch (ValidateException $validateException) { $message = $validateException->getMessage(); return $this->toData('1', $message, []); } catch (\Exception $exception) { return $this->toData('100500', 'The system is busy. Please try again later.', [$exception->getMessage(), $exception->getTrace()]); } } /** * 获取用户钱包地址详情 * @param array $data * @param int $type * @return array * */ public function getUserWalletAddressInfo(array $data, int $type = 0): array { try { validate(BankValidate::class)->scene('getWalletAddressInfo')->check($data); $address_info = UserWalletaddressModel::getUserWalletInfoById($data); if ($type) { return $address_info; } else { return $this->toData(0, 'Request successful.', $address_info); } } catch (ValidateException $validateException) { $message = $validateException->getMessage(); return $this->toData('1', $message, []); } catch (\Exception $exception) { return $this->toData('100500', 'The system is busy. Please try again later.', [$exception->getMessage(), $exception->getTrace()]); } } /** * 删除用户钱包地址 * @param array $data * @return array */ public function delUserWalletAddress(array $data): array { try { validate(BankValidate::class)->scene('getWalletAddressInfo')->check($data); UserWalletaddressModel::delUserWalletById($data); return $this->toData(0, 'Request successful.'); } catch (ValidateException $validateException) { $message = $validateException->getMessage(); return $this->toData('1', $message, []); } catch (\Exception $exception) { return $this->toData('100500', 'The system is busy. Please try again later.', [$exception->getMessage(), $exception->getTrace()]); } } /** * 添加编辑银行卡 * @param array $data * @return array */ public function insertUserBank(array $data): array { try { validate(BankValidate::class)->scene('setBank')->check($data); UserBankModel::InsertUserBank($data); return $this->toData(0, 'Request successful.'); } catch (ValidateException $validateException) { $message = $validateException->getMessage(); return $this->toData('1', $message, []); } catch (\Exception $exception) { return $this->toData('100500', 'The system is busy. Please try again later.', [$exception->getMessage(), $exception->getTrace()]); } } /** * 获取银行卡列表 * @param array $data * @return array */ public function getUserBank(array $data): array { try { validate(BankValidate::class)->scene('getBankList')->check($data); $bank_list = UserBankModel::getUserBankList($data); return $this->toData(0, 'Request successful.', $bank_list); } catch (ValidateException $validateException) { $message = $validateException->getMessage(); return $this->toData('1', $message, []); } catch (\Exception $exception) { return $this->toData('100500', 'The system is busy. Please try again later.', [$exception->getMessage(), $exception->getTrace()]); } } /** * 获取银行卡详情 * @param array $data * @return array */ public function getUserBankInfo(array $data, int $type = 0): array { try { validate(BankValidate::class)->scene('getBankInfo')->check($data); $bank_info = UserBankModel::getUserBankInfoById($data); if ($type) { return $bank_info; } else { return $this->toData(0, 'Request successful.', $bank_info); } } catch (ValidateException $validateException) { $message = $validateException->getMessage(); return $this->toData('1', $message, []); } catch (\Exception $exception) { return $this->toData('100500', 'The system is busy. Please try again later.', [$exception->getMessage(), $exception->getTrace()]); } } /** * 删除银行卡 * @param array $data * @return array */ public function delUserBank(array $data): array { try { validate(BankValidate::class)->scene('getBankInfo')->check($data); UserBankModel::delUserBankById($data); return $this->toData(0, 'Request successful.'); } catch (ValidateException $validateException) { $message = $validateException->getMessage(); return $this->toData('1', $message, []); } catch (\Exception $exception) { return $this->toData('100500', 'The system is busy. Please try again later.', [$exception->getMessage(), $exception->getTrace()]); } } /** * 获取用户账户可用余额 * @param array $data * @return array */ public function getUserBalance(array $data): array { if(env('ACCOUT_TYPE.ALL_IN_ONE')==1){ $usdt_info = UserMoneyModel::getUserUSDByUserId($data); }else{ //账户类型:1现货,2合约,3美股 4 印尼股票 5 马来西呀 6 泰股 7印度股 8秒合约 9新加坡股 10基金 11印度期权 12港股 switch ($data['account_type']) { case 2: $usdt_info = $this->getUserContract($data, 1); break; case 3: $usdt_info = $this->getUserUsStock($data, 1); break; case 4: $usdt_info = $this->getUserIdnStock($data, 1); break; case 5: $usdt_info = $this->getUserMysStock($data, 1); break; case 6: $usdt_info = $this->getUserThaStock($data, 1); break; case 7: $usdt_info = $this->getUserInStock($data, 1); break; case 8: $usdt_info = $this->getUserContractSec($data, 1); break; case 9: $usdt_info = $this->getUserSgdStock($data, 1); break; case 10: $usdt_info = $this->getUserFundStock($data, 1); break; case 11: $usdt_info = $this->getUserInOption($data, 1); break; case 12: $usdt_info = $this->getUserHkStock($data, 1); break; case 14: $usdt_info = $this->getUserUkStock($data, 1); break; case 15: $usdt_info = $this->getUserFurStock($data, 1); break; case 16: $usdt_info = $this->getUserEurStock($data, 1); break; case 17: $usdt_info = $this->getUserBrlStock($data, 1); break; case 18: $usdt_info = $this->getUserJpStock($data, 1); break; case 19: $usdt_info = $this->getUserForex($data, 1); break; default: $usdt_info = $this->getUserDigital($data, 1); break; } } return $this->toData(0, "ok", $usdt_info); } /** * 获取手续费用 * @return array */ public function getDrawalFee(int $account_type = 0): array { $fee_info = DrawalSettingModel::getDrawalFee(); $info = FeeSettingModel::where('market_type', $account_type)->field('min_withdrawal_num,min_recharge_num')->find(); if(!empty($info)){ $info =$info->toArray(); $fee_info['min_drawal']=$info['min_withdrawal_num']>0 ? $info['min_withdrawal_num']: $fee_info['min_drawal']; $fee_info['min_recharge']=$info['min_recharge_num']>0 ? $info['min_recharge_num']: $fee_info['min_recharge']; } return $this->toData(0, "ok",$fee_info); } /** * 处理提款;处理流程: 1.提交提款申请 ->检查余额->将可用余额扣除提款金额及手续费,转入冻结余额 * @param array $data * @return array */ public function dealDrawalApply(array $data): array { //校验交易密码 $salt = env('ENCRYPT.SALT'); $name = env('WALLET.NAME'); $user_info = UserModel::getFieldsByUserId('trade_password,is_real', $data['user_id']); if (empty($user_info['trade_password'])) { return $this->toData(3, "Please set a transaction password first."); } if ($user_info['is_real'] == 0 && $name == 'STOCK') { return $this->toData('20150', 'Please authenticate with real name first', []); } $check_pwd = (new UnqId())->checkPassword($data['trade_pwd'], $user_info['trade_password'], $salt); if (!$check_pwd) { return $this->toData(2, "Transaction password is incorrect."); } $flag = $this->checkOnlyOneNotEmpty($data['bank_id'], $data['address_id'], $data['wallet_address']); if ($flag) { //手续费 $fee = $this->getUserDrawalFee($data['apply_num'], $data['drawal_type']); $pay_info = []; if ($data['bank_id'] > 0) { $pay_info = $this->getUserBankInfo(['user_id' => $data['user_id'], 'id' => $data['bank_id']], 1); } if ($data['address_id'] > 0) { $pay_info = $this->getUserWalletAddressInfo(['user_id' => $data['user_id'], 'adr_id' => $data['address_id']], 1); } if (!empty($data['wallet_address'])) { $pay_info['wallet_address'] = $data['wallet_address']; } if (empty($pay_info)) { return $this->toData(1, 'The withdrawal information is incorrect.'); } if ($data['account_type'] > 2 && ($data['account_type'] != 8)) { $market_rate = (new StockMarketModel())->getRate($data['account_type']); } else { $market_rate = 1; } //提现金额 $apply_num = ($data['apply_num'] - $fee); $apply_usd_num = round($apply_num / $market_rate, 4); //印尼通道 $currency_rate = (new StockMarketModel())->getRate(4); //扣手续费 $total_amount = round($apply_usd_num * $currency_rate, 4); //事务开启, 查询用户资金 Db::startTrans(); try { //查询提现资金账户信息 $from_account = $this->lockUserBalance($data['account_type'], $data['user_id']); if (empty($from_account)) Db::rollback(); //换算汇率 //$change_num=$apply_num*$market_rate; $change_num = $apply_num; $cha_num = bcsub($from_account['usable_num'], $data['apply_num'], 18); //$from_account['usable_num']-$data['apply_num']; if ($cha_num < 0) { Db::rollback(); return $this->toData(1, 'Insufficient balance.'); } //插入提款记录表 $drawal_data['user_id'] = $data['user_id']; $drawal_data['order_no'] = $this->generateOrderNumber(20); $drawal_data['account_type'] = $data['account_type']; $drawal_data['apply_type'] = $data['apply_type']; $drawal_data['apply_num'] = $apply_usd_num; $drawal_data['service_fee'] = $fee; $drawal_data['currency_rate'] = $currency_rate; $drawal_data['pay_info'] = json_encode($pay_info); $drawal_data['status'] = 0; $drawal_data['country'] = $data['country']; $drawal_data['drawal_type'] = $data['drawal_type']; $drawal_data['market_amount'] = $data['apply_num']; $drawal_data['total_amount'] = $apply_num; UserWithdrawalModel::InsertUserDrawalLog($drawal_data); //扣除用户资金 $from_update['usable_num'] = $cha_num;//round($cha_num,4); $from_update['frozen_num'] = bcadd($from_account['frozen_num'], $data['apply_num'], 18);// round(($from_account['frozen_num']+$data['apply_num']),4); $res = $this->updateUserBalance($data['account_type'], $from_update, $data['user_id']); if (empty($res)) Db::rollback(); $log_data['user_id'] = $data['user_id']; $log_data['change_type'] = 5; //冻结 $log_data['change_num'] = -$data['apply_num']; $log_data['before_num'] = $from_account['usable_num']; $log_data['order_id'] = $drawal_data['order_no']; $res = $this->addUserBalanceLog($data['account_type'], $log_data); if (empty($res)) Db::rollback(); Db::commit(); return $this->toData(0, 'Request successful.'); } catch (\Exception $exception) { // 回滚事务 Db::rollback(); return $this->toData('100500', 'The system is busy. Please try again later.', [$exception->getMessage(), $exception->getTrace()]); } } else { return $this->toData(1, "Please fill in the parameters according to the requirements."); } } public function canncelDrawalApply(array $data): array { $order_info = UserWithdrawalModel::getUserDrawalInfo($data); if ($order_info['status'] == 0) { $obj = new AdminBaseService(); if(env('ACCOUT_TYPE.ALL_IN_ONE')==1){ $updateStatus = $obj->updateUserAssetNew($order_info['user_id'], 6, $order_info['market_amount'], -$order_info['market_amount'], $order_info['order_no']); }else{ $updateStatus = $obj->updateUserAsset($order_info['user_id'], $order_info['account_type'], 6, $order_info['market_amount'], -$order_info['market_amount'], $order_info['order_no']); } if (!empty($updateStatus) && $updateStatus['status'] == 200) { UserWithdrawalModel::where($data)->update([ 'status' => 5, 'update_time' => date('Y-m-d H:i:s') ]); return $this->toData(0, 'Request successful.'); }else{ return $this->toData(500, "System error."); } } else { return $this->toData(300, "Withdrawal orders cannot be cancelled."); } } private function checkOnlyOneNotEmpty($value1, $value2, $value3): bool { $count = 0; // 用于计数非空值的个数 if (!empty($value1)) { $count++; } if (!empty($value2)) { $count++; } if (!empty($value3)) { $count++; } // 如果非空值的个数等于1,则返回 true,否则返回 false return $count == 1; } public function getDrawalList(array $data): array { try { validate(WalletValidate::class)->scene('getDrawalList')->check($data); $list = UserWithdrawalModel::getUserDrawalList($data); return $this->toData(0, 'Request successful.', $list); } catch (ValidateException $validateException) { $message = $validateException->getMessage(); return $this->toData('1', $message, []); } catch (\Exception $exception) { return $this->toData('100500', 'The system is busy. Please try again later.', [$exception->getMessage(), $exception->getTrace()]); } } /** * 计算用户提现手续费用 * @param $money * @param $type 1数字币,2银行卡 * @return float|int|mixed */ private function getUserDrawalFee($money, $type = 0) { $fee_info = DrawalSettingModel::getDrawalFee(); if ($type == 2) { return $fee_info['bank_drawal_fee'] * $money; } else { return $fee_info['digital_drawal_fee']; } } public function getUserBalanceRecord(array $data): array { $record_list = []; if(env('ACCOUT_TYPE.ALL_IN_ONE')==1){ $record_list=UserMoneyLogModel::getUserBalanceLog($data); }else{ //账户类型:1现货,2合约,3美股 switch ($data['account_type']) { case 1: $record_list = UserDigitalLogModel::getUserBalanceLog($data); break; case 2: $record_list = UserContractLogModel::getUserBalanceLog($data); break; case 3: $record_list = UserStockLogModel::getUserBalanceLog($data); break; case 4: // 印尼股票 $record_list = UserStockIdnLogModel::getUserBalanceLog($data); break; case 5: // 马来股票 $record_list = UserStockMysLogModel::getUserBalanceLog($data); break; case 6: // 泰国股票 $record_list = UserStockThaLogModel::getUserBalanceLog($data); break; case 7: // 印度股票 $record_list = UserStockInLogModel::getUserBalanceLog($data); break; case 8: // 秒合约 $record_list = UserContractSecLogModel::getUserBalanceLog($data); break; case 9: // 新加坡 $record_list = UserStockSgdLogModel::getUserBalanceLog($data); break; case 10: // 基金 $record_list = UserStockFundLogModel::getUserBalanceLog($data); break; case 11: // 印度期权 $record_list = UserStockOptionInrLogModel::getUserBalanceLog($data); break; case 12: // 香港 $record_list = UserStockHkdLogModel::getUserBalanceLog($data); break; case 14: // 德国 $record_list = UserStockGBXLogModel::getUserBalanceLog($data); break; case 15: // 法国 $record_list = UserStockFurLogModel::getUserBalanceLog($data); break; case 16: // 英国 $record_list = UserStockEurLogModel::getUserBalanceLog($data); break; case 17: // 巴西 $record_list = UserStockBrlLogModel::getUserBalanceLog($data); break; case 18: // 巴西 $record_list = UserStockJpLogModel::getUserBalanceLog($data); break; case 19: // 巴西 $record_list =UserForexLogModel::getUserBalanceLog($data); break; default: return $this->toData(1, "Please fill in the parameters according to the requirements."); break; } } return $this->toData(0, "ok", $record_list); } /** * 处理用户各资金账户相互划转 * @param array $data * @return array */ public function doUserTransfer(array $data): array { try { validate(WalletValidate::class)->scene('transfer')->check($data); if ($data['from_account'] == $data['to_account']) { return $this->toData('2', 'The transfer out and transfer in accounts cannot be the same account.'); } //事务开启, 查询用户资金 Db::startTrans(); try { //查询划转资金账户信息 $from_account = $this->lockUserBalance($data['from_account'], $data['user_id']); if (empty($from_account)) { Db::rollback(); return $this->toData('2', 'error'); } //print_r($from_account); $cha_num = $from_account['usable_num'] - $data['change_num']; if ($cha_num < 0) { Db::rollback(); return $this->toData(1, 'Insufficient balance.'); } $to_num = $this->getRateToTransfer([ 'from_account' => $data['from_account'], 'to_account' => $data['to_account'], 'change_num' => $data['change_num'] ]); $to_num_data = $to_num['data']; if (!isset($to_num_data['to_change_num']) || !is_numeric($to_num_data['to_change_num']) || $to_num_data['to_change_num'] <= 0) { return $to_num; } //查询转入资金账户信息 $to_account = $this->lockUserBalance($data['to_account'], $data['user_id']); if (empty($to_account)) { Db::rollback(); return $this->toData('2', 'error to_account '); } //插入账户资金划转表 $transfer_data['user_id'] = $data['user_id']; $transfer_data['from_account'] = $data['from_account']; $transfer_data['to_account'] = $data['to_account']; $transfer_data['from_num'] = $data['change_num']; // 转出数量 $transfer_data['to_num'] = $to_num_data['to_change_num']; // 转入数量 $transfer_data['from_account_rate'] = $to_num_data['from_usd']; // 转出费率 $transfer_data['to_account_rate'] = $to_num_data['usd_to']; // 转入费率 $transfer_data['status'] = 1; $transfer_data['order_sn'] = $this->generateOrderNumber(20); UserTransferModel::InsertUserStock($transfer_data); //更新划转资金账户余额 $from_update['usable_num'] = $cha_num; $res = $this->updateUserBalance($data['from_account'], $from_update, $data['user_id']); if (empty($res)) { Db::rollback(); return $this->toData('2', 'error from_account transfer'); } // 新增转入 $to_update['usable_num'] = $to_account['usable_num'] + $to_num_data['to_change_num']; $res = $this->updateUserBalance($data['to_account'], $to_update, $data['user_id']); if (empty($res)) { Db::rollback(); return $this->toData('2', 'error to_account transfer '); } //变动类型:1-充值,2-提现,3-买入,4-卖出,5-冻结,6-解冻,7账户转出,8账户转入 //插入资金变动日志 $from_log['user_id'] = $data['user_id']; $from_log['change_type'] = 7; $from_log['change_num'] = -$data['change_num']; $from_log['before_num'] = $from_account['usable_num']; $from_log['order_id'] = $transfer_data['order_sn']; $res = $this->addUserBalanceLog($data['from_account'], $from_log); if (empty($res)) { Db::rollback(); return $this->toData('2', 'error from_log transfer'); } $to_log['user_id'] = $data['user_id']; $to_log['change_type'] = 8; $to_log['change_num'] = $to_num_data['to_change_num']; $to_log['before_num'] = $to_account['usable_num']; $to_log['order_id'] = $transfer_data['order_sn']; $res = $this->addUserBalanceLog($data['to_account'], $to_log); if (empty($res)) { Db::rollback(); return $this->toData('2', 'error to_log transfer'); } Db::commit(); return $this->toData(0, 'Request successful.'); } catch (\Exception $exception) { // 回滚事务 Db::rollback(); return $this->toData('100500', 'The system is busy. Please try again later.', [$exception->getMessage(), $exception->getTrace()]); } } catch (ValidateException $validateException) { $message = $validateException->getMessage(); return $this->toData('1', $message, []); } catch (\Exception $exception) { return $this->toData('100500', 'The system is busy. Please try again later.', [$exception->getMessage(), $exception->getTrace()]); } } public function lockUserBalance(int $account_type, int $user_id): array { if(env('ACCOUT_TYPE.ALL_IN_ONE')==1){ return UserMoneyModel::getUserUSDLock($user_id); }else{ switch ($account_type) { case 1: return UserDigitalModel::getUserDigitalLock($user_id); break; case 2: return UserContractModel::getUserContractLock($user_id); break; case 3: // 美股 return UserStockModel::getUserStockLock($user_id); break; case 4: // 印尼 股 return UserStockIdnModel::getUserStockLock($user_id); break; case 5: // 马来西亚 股 return UserStockMysModel::getUserStockLock($user_id); break; case 6: // 泰 股 return UserStockThaModel::getUserStockLock($user_id); break; case 7: // 印度 股 return UserStockInModel::getUserStockLock($user_id); break; case 8: // 秒合约 return UserContractSecModel::getUserContractLock($user_id); break; case 9: // 新加坡 return UserStockSgdModel::getUserStockLock($user_id); break; case 10: // 基金 return UserStockFundModel::getUserStockLock($user_id); break; case 11: // 印度期权 return UserStockOptionInrModel::getUserStockLock($user_id); break; case 12: // 香港 return UserStockHkdModel::getUserStockLock($user_id); break; case 14: // 英国 return UserStockGBXModel::getUserStockLock($user_id); break; case 15: // 英国 return UserStockFurModel::getUserStockLock($user_id); break; case 16: // 英国 return UserStockEurModel::getUserStockLock($user_id); break; case 17: // 巴西 return UserStockBrlModel::getUserStockLock($user_id); break; case 18: // 巴西 return UserStockJpModel::getUserStockLock($user_id); break; case 19: // 巴西 return UserForexModel::getUserForexLock($user_id); break; default: return []; break; } } } public function updateUserBalance(int $account_type, array $update_data, int $user_id): bool { if(env('ACCOUT_TYPE.ALL_IN_ONE')==1){ return UserMoneyModel::updateUserUSD($update_data,[ 'user_id' => $user_id, 'stock_id' => 'USD' ]); }else{ switch ($account_type) { case 1: return UserDigitalModel::updateUserDigital($update_data, [ 'user_id' => $user_id, 'digital_id' => 'USDT' ]); break; case 2: return UserContractModel::updateUserContract($update_data, [ 'user_id' => $user_id, 'contract_id' => 'USDT' ]); break; case 3: return UserStockModel::updateUserStock($update_data, [ 'user_id' => $user_id, 'stock_id' => 'USD' ]); break; case 4: return UserStockIdnModel::updateUserStock($update_data, [ 'user_id' => $user_id, 'stock_id' => 'IDR' ]); break; case 5: return UserStockMysModel::updateUserStock($update_data, [ 'user_id' => $user_id, 'stock_id' => 'MYR' ]); break; case 6: return UserStockThaModel::updateUserStock($update_data, [ 'user_id' => $user_id, 'stock_id' => 'THB' ]); break; case 7: return UserStockInModel::updateUserStock($update_data, [ 'user_id' => $user_id, 'stock_id' => 'INR' ]); break; case 8: return UserContractSecModel::updateUserContract($update_data, [ 'user_id' => $user_id, 'contract_id' => 'USDT' ]); break; case 9: return UserStockSgdModel::updateUserStock($update_data, [ 'user_id' => $user_id, 'stock_id' => 'SGD' ]); break; case 10: return UserStockFundModel::updateUserStock($update_data, [ 'user_id' => $user_id, 'stock_id' => 'USD' ]); break; case 11: return UserStockOptionInrModel::updateUserStock($update_data, [ 'user_id' => $user_id, 'stock_id' => 'INR' ]); break; case 12: return UserStockHkdModel::updateUserStock($update_data, [ 'user_id' => $user_id, 'stock_id' => 'HKD' ]); break; case 14: return UserStockGBXModel::updateUserStock($update_data, [ 'user_id' => $user_id, 'stock_id' => 'GBX' ]); break; case 15: return UserStockFurModel::updateUserStock($update_data, [ 'user_id' => $user_id, 'stock_id' => 'EUR' ]); break; case 16: return UserStockEurModel::updateUserStock($update_data, [ 'user_id' => $user_id, 'stock_id' => 'EUR' ]); break; case 17: return UserStockBrlModel::updateUserStock($update_data, [ 'user_id' => $user_id, 'stock_id' => 'BRL' ]); break; case 18: return UserStockJpModel::updateUserStock($update_data, [ 'user_id' => $user_id, 'stock_id' => 'JPY' ]); break; case 19: return UserForexModel::updateUserForex($update_data, [ 'user_id' => $user_id, 'contract_id' => 'USD' ]); break; default: return false; break; } } } public function addUserBalanceLog(int $account_type, array $log_data): bool { if(env('ACCOUT_TYPE.ALL_IN_ONE')==1){ $log_data['stock_id'] = 'USD'; return UserMoneyLogModel::InsertUserBalanceLog($log_data); }else{ switch ($account_type) { case 1: $log_data['digital_id'] = 'USDT'; return UserDigitalLogModel::InsertUserBalanceLog($log_data); break; case 2: $log_data['contract_id'] = 'USDT'; return UserContractLogModel::InsertUserBalanceLog($log_data); break; case 3: $log_data['stock_id'] = 'USD'; return UserStockLogModel::InsertUserBalanceLog($log_data); break; case 4: $log_data['stock_id'] = 'IDR'; return UserStockIdnLogModel::InsertUserBalanceLog($log_data); break; case 5: $log_data['stock_id'] = 'MYR'; return UserStockMysLogModel::InsertUserBalanceLog($log_data); break; case 6: $log_data['stock_id'] = 'THB'; return UserStockThaLogModel::InsertUserBalanceLog($log_data); break; case 7: $log_data['stock_id'] = 'INR'; return UserStockInLogModel::InsertUserBalanceLog($log_data); break; case 8: $log_data['contract_id'] = 'USDT'; return UserContractSecLogModel::InsertUserBalanceLog($log_data); break; case 9: $log_data['stock_id'] = 'SGD'; return UserStockSgdLogModel::InsertUserBalanceLog($log_data); break; case 10: $log_data['stock_id'] = 'USD'; return UserStockFundLogModel::InsertUserBalanceLog($log_data); break; case 11: $log_data['stock_id'] = 'INR'; return UserStockOptionInrLogModel::InsertUserBalanceLog($log_data); break; case 12: $log_data['stock_id'] = 'HKD'; return UserStockHkdLogModel::InsertUserBalanceLog($log_data); break; case 14: $log_data['stock_id'] = 'GBX'; return UserStockGBXLogModel::InsertUserBalanceLog($log_data); break; case 15: $log_data['stock_id'] = 'EUR'; return UserStockFurLogModel::InsertUserBalanceLog($log_data); break; case 16: $log_data['stock_id'] = 'EUR'; return UserStockEurLogModel::InsertUserBalanceLog($log_data); break; case 17: $log_data['stock_id'] = 'BRL'; return UserStockBrlLogModel::InsertUserBalanceLog($log_data); break; case 18: $log_data['stock_id'] = 'JPY'; return UserStockJpLogModel::InsertUserBalanceLog($log_data); break; case 19: $log_data['contract_id'] = 'USD'; return UserForexLogModel::InsertUserBalanceLog($log_data); break; default: return false; break; } } } /** * 获取用户资金划转明细 * @param array $data * @return array */ public function getUserTransfer(array $data): array { try { validate(WalletValidate::class)->scene('getRechargeList')->check($data); $list = UserTransferModel::getUserTransferList($data); return $this->toData(0, 'Request successful.', $list); } catch (ValidateException $validateException) { $message = $validateException->getMessage(); return $this->toData('1', $message, []); } catch (\Exception $exception) { return $this->toData('100500', 'The system is busy. Please try again later.', [$exception->getMessage(), $exception->getTrace()]); } } public function userHasNotPay(array $data):array { if (!empty($data['market_type'])) { $table_obj = (new \app\admin\service\setting\IPOService())->getStockModel($data['market_type']); if (empty($table_obj)) { return $this->toData(1, 'system error.'); } $list = UserArrearsModel::where('user_id', $data['user_id'])->where('status', 0)->where('account_type', $data['market_type'])->select(); } else { $list = UserArrearsModel::where('user_id', $data['user_id'])->where('status', 0)->select(); } if (empty($list)) { $list = []; } else { $list = $list->toArray(); foreach ($list as $key => $val) { $table_obj = (new \app\admin\service\setting\IPOService())->getStockModel($val['account_type']); $order = Db::table($table_obj['order_table'])->where('order_no', $val['order_no'])->find(); if ($order) { $list[$key]['get_num'] = $order['get_num']; $list[$key]['get_amount'] = $order['get_amount']; $list[$key]['get_fee'] = $order['get_fee']; $list[$key]['stock_code'] = Db::table($table_obj['stock_table'])->where('id', $order['pre_stock_id'])->value('stock_code'); } } } return $this->toData(0, 'Request successful.', $list); } public function dealUnPayIPO(array $data):array { if(env('ACCOUT_TYPE.ALL_IN_ONE')==1){ $this->dealUnPayIPOByNew($data); }else{ $this->dealUnPayIPOByOld($data); } return $this->toData(0, 'Request successful.',[]); } public function dealUnPayIPOByOld($data){ $total=UserArrearsModel::where('user_id',$data['user_id'])->where('account_type',$data['market_type'])->where('status',0)->sum('num'); $table_obj=(new \app\admin\service\setting\IPOService())->getStockModel($data['market_type']); $res=Db::table($table_obj['user_table'])->where('user_id',$data['user_id'])->where('stock_id',$table_obj['stock_id']) ->where('usable_num','>=',$total)->find(); if(empty($res)){ return $this->toData(1, 'The balance is not enough.'); } $order_list=UserArrearsModel::where('user_id',$data['user_id'])->where('account_type',$data['market_type'])->select(); $nowDate=date('Y-m-d H:i:s'); Db::startTrans(); //扣钱 $update_bool = Db::table($table_obj['user_table'])->where('stock_id', $table_obj['stock_id'])->where('user_id', $data['user_id']) ->dec('usable_num', $total) ->update(['update_time' => $nowDate]); if(!$update_bool){ Db::rollback(); return $this->toData('1', 'system error0', []); } foreach ($order_list as $order){ //生成支付流水 $insertStockLogArr = [ 'user_id' => $order['user_id'], 'change_type' => 15, // 新股申购扣减费用 'stock_id' => $table_obj['stock_id'], 'before_num' => 0, 'change_num' => '-' . Db::table($table_obj['order_table'])->where('order_no',$order['order_no'])->value('get_amount'), 'order_id' => $order['order_no'], 'create_time' => $nowDate, 'update_time' => $nowDate ]; $log_bool = Db::table($table_obj['log_table'])->insert($insertStockLogArr); if(!$log_bool){ Db::rollback(); return $this->toData('1', 'system error1', []); } // 生成扣手续流水 $insertStockLogArrFee = [ 'user_id' => $order['user_id'], 'change_type' => 16, // 新股申购扣减费用 'stock_id' => $table_obj['stock_id'], 'before_num' => 0, 'change_num' => '-' . Db::table($table_obj['order_table'])->where('order_no',$order['order_no'])->value('get_fee'), 'order_id' => $order['order_no'], 'create_time' => $nowDate, 'update_time' => $nowDate ]; $fee_bool = Db::table($table_obj['log_table'])->insert($insertStockLogArrFee); if (!$fee_bool) { Db::rollback(); return $this->toData('1', 'system error2', []); } //更新状态 $status_bool=UserArrearsModel::where('user_id',$order['user_id'])->where('order_no',$order['order_no'])->update([ 'status'=>1, 'update_time'=>$nowDate ]); if (!$status_bool) { Db::rollback(); return $this->toData('1', 'system error2', []); } //更新订单状态 if(env('USER_ARREARS.HAS_USER_ARREARS')==3){ $sign_status=Db::table($table_obj['stock_table'])->where('id',$order['pre_stock_id'])->value('sign_status'); $order_bool=Db::table($table_obj['order_table'])->where('order_no',$order['order_no'])->where('user_id',$order['user_id']) ->update([ 'status'=> $sign_status==1 ? 2:3, 'update_time'=>$nowDate ]); if (!$order_bool) { Db::rollback(); return $this->toData('1', 'system error3'.Db::table($table_obj['order_table'])->getLastSql(), []); } } //删除缓存订单 $key="USER:ARREAR:ORDER:".$order['order_no']; Cache::store('redis')->delete($key); } Db::commit(); } public function dealUnPayIPOByNew($data){ $total=UserArrearsModel::where('user_id',$data['user_id'])->where('account_type',$data['market_type'])->where('status',0)->sum('num'); $table_obj=(new \app\admin\service\setting\IPOService())->getStockModel($data['market_type']); $usd_total=0; $rate = (new StockMarketModel())->getRate($data['market_type']); $usd_total=$total/$rate; $res=UserMoneyModel::where('user_id',$data['user_id'])->where('stock_id','USD') ->where('usable_num','>=',$usd_total)->find(); if(empty($res)){ return $this->toData(1, 'The balance is not enough.'); } $order_list=UserArrearsModel::where('user_id',$data['user_id'])->where('account_type',$data['market_type'])->select(); $nowDate=date('Y-m-d H:i:s'); Db::startTrans(); //扣钱 $update_bool = UserMoneyModel::where('stock_id', 'USD')->where('user_id', $data['user_id']) ->dec('usable_num', $usd_total) ->update(['update_time' => $nowDate]); if(!$update_bool){ Db::rollback(); return $this->toData('1', 'system error0', []); } foreach ($order_list as $order){ //生成支付流水 $amount= Db::table($table_obj['order_table'])->where('order_no',$order['order_no'])->value('get_amount'); $usd_amount=$amount/$rate; $insertStockLogArr = [ 'user_id' => $order['user_id'], 'change_type' => 15, // 新股申购扣减费用 'stock_id' => $table_obj['stock_id'], 'before_num' => 0, 'change_num' => '-' .$usd_amount, 'order_id' => $order['order_no'], 'create_time' => $nowDate, 'update_time' => $nowDate, 'market_type' => $data['market_type'] ]; $log_bool = UserMoneyLogModel::InsertUserBalanceLog($insertStockLogArr); if(!$log_bool){ Db::rollback(); return $this->toData('1', 'system error1', []); } // 生成扣手续流水 $fee=Db::table($table_obj['order_table'])->where('order_no',$order['order_no'])->value('get_fee'); $usd_fee= $fee/$rate; $insertStockLogArrFee = [ 'user_id' => $order['user_id'], 'change_type' => 16, // 新股申购扣减费用 'stock_id' => $table_obj['stock_id'], 'before_num' => 0, 'change_num' => '-' . $usd_fee, 'order_id' => $order['order_no'], 'create_time' => $nowDate, 'update_time' => $nowDate, 'market_type' => $data['market_type'] ]; $fee_bool =UserMoneyLogModel::InsertUserBalanceLog($insertStockLogArrFee); if (!$fee_bool) { Db::rollback(); return $this->toData('1', 'system error2', []); } //更新状态 $status_bool=UserArrearsModel::where('user_id',$order['user_id'])->where('order_no',$order['order_no'])->update([ 'status'=>1, 'update_time'=>$nowDate ]); if (!$status_bool) { Db::rollback(); return $this->toData('1', 'system error2', []); } //更新订单状态 if(env('USER_ARREARS.HAS_USER_ARREARS')==3){ $sign_status=Db::table($table_obj['stock_table'])->where('id',$order['pre_stock_id'])->value('sign_status'); $order_bool=Db::table($table_obj['order_table'])->where('order_no',$order['order_no'])->where('user_id',$order['user_id']) ->update([ 'status'=> $sign_status==1 ? 2:3, 'update_time'=>$nowDate ]); if (!$order_bool) { Db::rollback(); return $this->toData('1', 'system error3'.Db::table($table_obj['order_table'])->getLastSql(), []); } } //删除缓存订单 $key="USER:ARREAR:ORDER:".$order['order_no']; Cache::store('redis')->delete($key); } Db::commit(); } // 获取账户之间划转手续费 public function getRateToTransfer($data) { try { // 1 现货 2 合约 3 美股 4 印尼股 5 马股 6 泰股 7 印度 $fromAccount = $data['from_account']; $toAccount = $data['to_account']; if($fromAccount <1 || $fromAccount > 20){ return $this->toData('2', 'Transfer out account type is incorrect.'); } if($toAccount <1 || $toAccount > 20){ return $this->toData('2', 'Transfer out account type is incorrect.'); } if ($fromAccount == $toAccount) { return $this->toData('2', 'The transfer out and transfer in accounts cannot be the same account.'); } // 转出地址对美元的汇率 $fromRate = (new StockMarketModel())->getRate($fromAccount); $toRate = (new StockMarketModel())->getRate($toAccount); if ($fromRate <= 0) { return $this->toData('2', 'Transfer out account type is incorrect.'); } if ($toRate <= 0) { return $this->toData('2', 'Transfer in account type is incorrect.'); } // 是否传递转账数量 $toChangeNum = '-'; if (!empty($data['change_num']) && is_numeric($data['change_num']) && $data['change_num'] > 0) { // 转出数量计算 change_num / from_rate * to_rate $toChangeNum = bcmul(bcdiv($data['change_num'], $fromRate, 6), $toRate, 6); } return $this->toData('0', 'SUCCESS', [ 'from_usd' => $fromRate, 'usd_to' => $toRate, 'to_change_num' => $toChangeNum ]); } catch (\Exception $exception) { return $this->toData('100500', 'The system is busy. Please try again later.', [$exception->getMessage(), $exception->getTrace()]); } } }