type ?? 'day'; $date = $request->date ?? Carbon::now()->format('Y-m-d'); $time = Carbon::parse($date); switch ($type) { case 'month': $timeBetween = [ $time->startOfMonth()->toDateTimeString(), $time->endOfMonth()->toDateTimeString(), ]; break; case 'year': $timeBetween = [ $time->startOfYear()->toDateTimeString(), $time->endOfYear()->toDateTimeString(), ]; break; case 'day': default: $timeBetween = [ $time->startOfDay()->toDateTimeString(), $time->endOfDay()->toDateTimeString(), ]; break; } $lists = $user->withdraws() ->whereBetween('created_at', $timeBetween) ->latest() ->paginate(); $is_chain = config('withdraw.is_chain', false); if ($is_chain) { $all = floatval($user->getStoneFormatBalance()); } else { $account = config('withdraw.account', 'coins'); $all = $user->account->{$account}; } $data = [ 'all' => $all, 'lists' => new WithdrawCollection($lists), ]; return $this->success($data); } /** * Notes: 提现前置 * * @Author: 玄尘 * @Date : 2021/1/21 14:21 */ public function create(Request $request): JsonResponse { $user = Api::user(); $is_chain = config('withdraw.is_chain', false); $bank_account_id = $request->bank_account_id; $alipay_account_id = $request->alipay_account_id; if ($bank_account_id) { $bank_account = $user->bankAccounts()->where('id', $bank_account_id)->first(); } else { $bank_account = $user->bankAccounts()->first(); } if ($alipay_account_id) { $alipay_account = $user->alipayAccounts()->where('id', $alipay_account_id)->first(); } else { $alipay_account = $user->alipayAccounts()->first(); } $data = [ 'tax' => Config::getValue('tax', 0), 'bank_account' => $bank_account ? new UserBankAccountResource($bank_account) : '', 'alipay_account' => $alipay_account ? new UserAlipayAccountResource($alipay_account) : '', 'bank_accounts' => UserBankAccountResource::collection($user->bankAccounts), 'alipay_accounts' => UserAlipayAccountResource::collection($user->alipayAccounts), 'is_chain' => config('withdraw.is_chain'), 'certification' => (bool) $user->certification, 'types' => Withdraw::TYPES, ]; if ($is_chain) { $data = array_merge($data, [ 'balance' => floatval($user->getStoneFormatBalance()),//账户余额 'cost' => (new DayDataChain())->getStoneValue(),//现金价值 ]); } else { $account = config('withdraw.account'); $data = array_merge($data, [ 'balance' => $user->account->{$account},//账户余额 'cost' => 1, ]); } return $this->success($data); } /** * Notes: 提现 * * @Author: 玄尘 * @Date : 2021/1/21 14:27 * @param WithdrawRequest $request * @return JsonResponse|mixed */ public function store(WithdrawRequest $request) { $user = Api::user(); try { // if (! $user->certification) { // throw new \Exception('未进行个人认证不可提现'); // } Withdraw::createInfo($user, $request); return $this->success('申请提现成功,等待管理员审核'); } catch (\Exception $e) { return $this->failed($e->getmessage()); } } }