can('dcat.admin.dealers.edit_lvl'); } /** * Handle the form request. * * @param array $input * * @return mixed */ public function handle(array $input) { $id = $this->payload['id'] ?? 0; $dealer = Dealer::findOrFail($id); if ($dealer?->lvl->value >= $input['lvl']) { throw new BizException('请选择大于当前的等级'); } try { DB::beginTransaction(); //执行自己升级 $dealer->update([ 'lvl'=>$input['lvl'], ]); 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() { // dd(UserInfo::$agentLevelTexts); $this->select('lvl', '经销商级别')->options(DealerLvl::texts()) ->help('请选择大于当前的身份') ->required(); } public function default() { $id = $this->payload['id'] ?? 0; $dealer = Dealer::findOrFail($id); return [ 'lvl' => $dealer->lvl->value, ]; } }