can('dcat.admin.dealers.wallet_change'); } /** * Handle the form request. * * @param array $input * * @return mixed */ public function handle(array $input) { if (bccomp($input['change_balance'], '0', 2) <= 0) { return $this->response()->error('金额必须大于0'); } $dealer = Dealer::findOrFail($this->payload['id']); $action = DealerWalletAction::from($input['action']); try { DB::beginTransaction(); (new WalletService())->changeBalance( $dealer->user, match ($action) { DealerWalletAction::Recharge => bcmul($input['change_balance'], '1', 2), DealerWalletAction::Deduct => bcmul($input['change_balance'], '-1', 2), }, $action, $input['remarks'], Admin::user() ); DB::commit(); } catch (Throwable $th) { DB::rollBack(); report($th); return $this->response()->error('操作失败:'.$th->getMessage()); } return $this->response() ->success(__('admin.update_succeeded')) ->refresh(); } /** * Build a form here. */ public function form() { $this->radio('action', '操作') ->options([ DealerWalletAction::Recharge->value => '充值', DealerWalletAction::Deduct->value => '扣除', ]) ->default(DealerWalletAction::Recharge->value) ->required(); $this->currency('change_balance', '金额')->symbol('¥')->required(); $this->textarea('remarks', '备注')->required(); $this->confirm('是否确认充值?', '提交后该动作无法逆转'); } }