accountInfo = $this->getCurrentAgent(); }*/ /** * 代理提现方式列表 * * @param AgentBankInfoRepository $bankRepo * @return WithdrawBankInfoResponse */ public function bankInfo(AgentBankInfoRepository $bankRepo) { $this->accountInfo = $this->getCurrentAgent(); $bankInfo = $bankRepo->agentBankList($this->accountInfo['uid']); /** * @var ConfigRepoistory $confRepo */ $confRepo = app(ConfigRepoistory::class); $serviceLink = $confRepo->get('servicese_link', 'sys'); return new WithdrawBankInfoResponse($bankInfo, $serviceLink); } /** * 新增提现方式 * * @return \Illuminate\Http\JsonResponse|ConfigSuccessResponse */ public function bankCreate() { $inputData = $this->getJsonData(); $rules = [ 'bank_card' => 'nullable|string', 'bank_account' => 'nullable|string', 'bank_mark' => 'nullable|string', 'type' => 'required|in:1,2,3', 'ustd_network' => 'nullable|string', 'ustd_account' => 'nullable|string', 'alipay_account' => 'nullable|string', 'alipay_username' => 'nullable|string', ]; $validator = Validator::make($inputData, $rules); if ($validator->fails()) { // 如果有错误(可能是多个信息),这里只取第一个错误信息返回. return json_fail($validator->errors()->first()); } $this->accountInfo = $this->getCurrentAgent(); /** * @var AgentBankInfoRepository $bankRepo */ $bankRepo = app(AgentBankInfoRepository::class); $findBank = $bankRepo->findWhere(['type' => $inputData['type'], 'agent_uid' => $this->accountInfo['uid']], ['id']); if ($findBank->isNotEmpty()) { return json_fail('请勿重复添加同一种提现方式!'); } $setarr['type'] = $inputData['type']; $setarr['agent_uid'] = $this->accountInfo['uid']; if (!empty($inputData['alipay_account'])) { $setarr['alipay_account'] = $inputData['alipay_account']; } if (!empty($inputData['alipay_username'])) { $setarr['alipay_username'] = $inputData['alipay_username']; } if (!empty($inputData['bank_card'])) { $setarr['bank_card'] = $inputData['bank_card']; } if (!empty($inputData['bank_account'])) { $setarr['bank_account'] = $inputData['bank_account']; } if (!empty($inputData['bank_mark'])) { $setarr['bank_mark'] = $inputData['bank_mark']; } if (!empty($inputData['ustd_network'])) { $setarr['ustd_network'] = $inputData['ustd_network']; } if (!empty($inputData['ustd_account'])) { $setarr['ustd_account'] = $inputData['ustd_account']; } $result = $bankRepo->create($setarr); if (!$result) { return json_fail('新增提现方式失败'); } else { $logSubject = '新增一个提现银行卡,:' . $result->uid; $logSvalue = $result->uid; $logDbData = [ 'after_items' => [ $setarr, ], 'before_items' => [ ], ]; $this->log($logSubject, $logSvalue, $logDbData); return new ConfigSuccessResponse(); } } /** * 提现列表 * * @return \Illuminate\Http\JsonResponse|WithdrawLogResponse */ public function lists() { $inputData = $this->getJsonData(); $rules = [ 'page' => 'nullable|integer', 'page_size' => 'nullable|integer', 'start_date' => 'nullable|string', 'end_date' => 'nullable|string', ]; $validator = Validator::make($inputData, $rules); if ($validator->fails()) { // 如果有错误(可能是多个信息),这里只取第一个错误信息返回. return json_fail($validator->errors()->first()); } $this->accountInfo = $this->getCurrentAgent(); // 针对layui table自动分页请求参数,优先GET值. $queryPage = request()->has('page') ? request()->input('page', 1) : null; $queryPageSize = request()->has('page_size') ? request()->input('page_size', 10) : null; if (!is_null($queryPage)) { $inputData['page'] = $queryPage; } if (!is_null($queryPageSize)) { $inputData['page_size'] = $queryPageSize; } $orders = [ ['created_at', 'DESC'] ]; if (!isset($inputData['page_size']) || $inputData['page_size'] > 500) { $pageSize = CommonConstant::PAGE_SIZE; } else { $pageSize = $inputData['page_size']; } $page = format_page($inputData['page'] ?? 0); /** * @var WithDrawalLogRepository $witRepo */ $witRepo = app(WithDrawalLogRepository::class); $inputData['agent_uid'] = $this->accountInfo['uid']; $field = ['created_at', 'paid_at', 'status', 'uid', 'type', 'amount', 'usdt_rate']; $res = $witRepo->pushCriteria(new FinanceWithdrawCriteria($inputData))->pushCriteria(new OrderLimitCriteria($orders))->paginate($pageSize, $field, $page); /** * @var AgentRepository $agentRepo */ $agentRepo = app(AgentRepository::class); $accountInfo = $agentRepo->findBy('uid', $this->accountInfo['uid'], ['frozen', 'balance']); /** * @var AnnounceRepository $annRespo */ $annRespo = app(AnnounceRepository::class); $annData = $annRespo->findWhere(['status' => 1, 'type' => 2], ['content', 'title']); return new WithdrawLogResponse($res, $accountInfo, $annData); } /** * 提现账户详情 * * @return mixed */ public function accountInfo() { $this->accountInfo = $this->getCurrentAgent(); /** * @var AgentRepository $agentRepo */ $agentRepo = app(AgentRepository::class); $accountInfo = $agentRepo->findBy('uid', $this->accountInfo['uid'], ['balance']); /** * @var AgentBankInfoRepository $bankList */ $bankRepo = app(AgentBankInfoRepository::class); $bankList = $bankRepo->agentBankList($this->accountInfo['uid'], ['type', 'bank_account', 'ustd_account', 'alipay_account', 'uid']); /** * @var ConfigRepoistory $confRepo */ $confRepo = app(ConfigRepoistory::class); $usdtRate = $confRepo->get('usdt_rate', 'sys'); if ($this->accountInfo['withdraw_usdt']) { $minUsdt = $this->accountInfo['withdraw_usdt']; } else { $minUsdt = $confRepo->get('withdraw_min_usdt', 'sys'); } if ($this->accountInfo['withdraw_amount']) { $minMoney = $this->accountInfo['withdraw_amount']; } else { $minMoney = $confRepo->get('withdraw_min_money', 'sys'); } $res['balance'] = $accountInfo->balance; $res['usdt_rate'] = $usdtRate; $res['bank_list'] = $bankList; $res['withdraw_min_usdt'] = $minUsdt; $res['withdraw_min_money'] = $minMoney; return json_success($res); } /** * 提现申请 * * @return \Illuminate\Http\JsonResponse|ConfigSuccessResponse * @throws \Psr\SimpleCache\InvalidArgumentException */ public function apply() { $inputData = $this->getJsonData(); $rules = [ 'bank_uid' => 'required|string', 'type' => 'required|in:1,2,3', 'amount' => 'required|integer', 'withdraw_pwd' => 'required', ]; $validator = Validator::make($inputData, $rules); if ($validator->fails()) { // 如果有错误(可能是多个信息),这里只取第一个错误信息返回. return json_fail($validator->errors()->first()); } $this->accountInfo = $this->getCurrentAgent(); /** * @var ConfigRepoistory $confRepo */ $confRepo = app(ConfigRepoistory::class); $rate = 0; if ($inputData['type'] == 2) { $rate = $confRepo->get('usdt_rate', 'sys'); $amount = intval($inputData['amount'] * $rate); } else { $amount = $inputData['amount']; } /** * @var AgentRepository $agentRepo */ $agentRepo = app(AgentRepository::class); $accountInfo = $agentRepo->findBy('uid', $this->accountInfo['uid']); $oldAccountInfo = clone $accountInfo; //最低提现金额 if ($inputData['type'] == 2) { if ($accountInfo['withdraw_usdt']) { $minUsdt = $accountInfo['withdraw_usdt']; } else { $minUsdt = $confRepo->get('withdraw_min_usdt', 'sys'); } if ($minUsdt > $amount) { return json_fail('最低提现为' . $minUsdt . 'U'); } } else { if ($accountInfo['withdraw_amount']) { $minMoney = $accountInfo['withdraw_amount']; } else { $minMoney = $confRepo->get('withdraw_min_money', 'sys'); } if ($minMoney > $amount) { return json_fail('最低提现金额为' . $minMoney . '元'); } } if ($accountInfo->balance < $amount) { return json_fail('提现余额不足,请重新申请!'); } if ($accountInfo->withdraw_pwd != $inputData['withdraw_pwd']) { return json_fail('提现密码错误!'); } /** * @var BalanceLogRepository $bLogRepo */ $bLogRepo = app(BalanceLogRepository::class); /** * @var WithDrawalLogRepository $witRepo */ $witRepo = app(WithDrawalLogRepository::class); /** * @var AgentBankInfoRepository $bankList */ $bankRepo = app(AgentBankInfoRepository::class); $bankInfo = $bankRepo->findByWhere(['uid' => $inputData['bank_uid']]); if (!$bankInfo) { return json_fail('提现账户异常,请联系客服!'); } DB::beginTransaction(); try { //帐变操作 $accountInfo->balance -= $amount; $accountInfo->frozen += $amount; $res1 = $accountInfo->save(); if (!$res1) { DB::rollBack(); return json_fail('提现申请失败!'); } //写入提现记录 $instData = [ 'status' => 2, 'agent_uid' => $this->accountInfo['uid'], 'amount' => $amount, 'type' => $inputData['type'], 'before_amount' => $oldAccountInfo->balance, 'after_amount' => $oldAccountInfo->balance - $amount, 'bank_account' => $bankInfo->bank_account, 'bank_card' => $bankInfo->bank_card, 'bank_mark' => $bankInfo->bank_mark, 'ustd_network' => $bankInfo->ustd_network, 'ustd_account' => $bankInfo->ustd_account, 'alipay_account' => $bankInfo->alipay_account, 'alipay_username' => $bankInfo->alipay_username, 'usdt_rate' => $rate, ]; $res2 = $witRepo->create($instData); if (!$res2) { DB::rollBack(); return json_fail('提现异常!'); } $res3 = $bLogRepo->record($accountInfo, $oldAccountInfo); if (!$res3) { DB::rollBack(); return json_fail('提现失败!'); } DB::commit(); } catch (\Throwable $e) { var_dump($e->getMessage()); DB::rollBack(); return json_fail('提现异常,请联系客服!'); } $this->dispatch(new SendTgWithdrawMegJob( $this->accountInfo['uid'], $this->accountInfo['username'], $inputData['type'], $inputData['amount'], Carbon::now()->toDateTimeString() )); return new ConfigSuccessResponse(); } public function usdtNetWork() { $this->accountInfo = $this->getCurrentAgent(); $confRepo = app(ConfigRepoistory::class); $usdtAddress = $confRepo->get('usdt_address', 'sys'); return json_success(explode(',', $usdtAddress)); } }