with('pay') ->where([ 'user_id' => Admin::user()->id, 'user_type' => DemandTraits::$col[0], 'status' => WithdrawalTraits::$state[3], 'pay_type' => WithdrawalTraits::$userType[1], ]) ->orderByDesc('updated_at') ->first(); $form->display('id'); $form->decimal('price','提现金额')->required()->maxLength(50)->default($auto->price ?? 0); $form->text('name')->required()->maxLength(50)->default($auto->pay->name ?? ''); $form->text('card_number')->required()->maxLength(50)->type('number')->default($auto->pay->card_number ?? ''); $form->text('account_name')->required()->maxLength(50)->default($auto->pay->account_name ?? ''); $form->text('branch')->required()->maxLength(100)->default($auto->pay->branch ?? ''); $form->hidden('withdrawal_id'); $form->saving(function (Form $form) { $user = Agent::query()->where('id', Admin::user()->id)->lockForUpdate()->first(); if ($form->price > $user->balance) { return $form->response()->error('余额不足,当前可用余额为'.$user->balance); } $user->balance = bcsub($user->balance,$form->price,6); $user->save(); $withdrawal = new Withdrawal(); $withdrawal->user_id = Admin::user()->id; $withdrawal->user_type = DemandTraits::$col[0]; $withdrawal->price = request('price',0); //$withdrawal->pay_id = $form->getKey(); $withdrawal->pay_type = WithdrawalTraits::$userType[1]; $withdrawal->save(); $form->withdrawal_id = $withdrawal->id; $form->deleteInput('price'); }); $form->saved(function (Form $form) { $withdrawal = Withdrawal::find($form->withdrawal_id); $withdrawal->pay_id = $form->getKey(); $withdrawal->save(); }); }); } }