From 48534cd57abcff8418d89be2b47843258aa49ac6 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Thu, 5 Nov 2020 16:57:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=97=E9=93=BA=E6=9B=B4=E6=8D=A2=E5=B8=82?= =?UTF-8?q?=E5=9C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Actions/Grid/v3/StoreChangeMarket.php | 40 ++++++++++ app/Admin/Controllers/v3/StoreController.php | 18 ++++- app/Admin/Forms/v3/StoreChangeMarketForm.php | 76 +++++++++++++++++++ 3 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 app/Admin/Actions/Grid/v3/StoreChangeMarket.php create mode 100644 app/Admin/Forms/v3/StoreChangeMarketForm.php diff --git a/app/Admin/Actions/Grid/v3/StoreChangeMarket.php b/app/Admin/Actions/Grid/v3/StoreChangeMarket.php new file mode 100644 index 0000000..6c20205 --- /dev/null +++ b/app/Admin/Actions/Grid/v3/StoreChangeMarket.php @@ -0,0 +1,40 @@ +getKey(); + + $modal = Modal::make() + ->xl() + ->title($this->title) + ->body(StoreChangeMarketForm::make()->setKey($id)->payload([ + 'id'=>$this->row->id, + 'name'=>$this->row->name, + 'market_id'=>$this->row->market_id + ])) + ->button($this->title); + + return $modal; + } + + public function parameters() + { + + return [ + + ]; + } +} diff --git a/app/Admin/Controllers/v3/StoreController.php b/app/Admin/Controllers/v3/StoreController.php index de95853..cf6eb29 100644 --- a/app/Admin/Controllers/v3/StoreController.php +++ b/app/Admin/Controllers/v3/StoreController.php @@ -2,6 +2,7 @@ namespace App\Admin\Controllers\v3; +use App\Admin\Actions\Grid\v3\StoreChangeMarket; use App\Admin\Common\Auth; use App\Admin\Repositories\v3\Store; use App\Models\LanzuMmInfo; @@ -97,7 +98,13 @@ class StoreController extends AdminController $grid->is_operation->switch(); $grid->is_open->switch(); - $grid->actions([new StoreSetTime()]); + $actions = [ + new StoreSetTime() + ]; + if($this->storeChangeMarketCan()){ + $actions[] = new StoreChangeMarket(); + } + $grid->actions($actions); // 搜索 $grid->filter(function (Grid\Filter $filter) use($marketList){ $filter->equal('id'); @@ -422,4 +429,13 @@ class StoreController extends AdminController $user = Admin::user(); return $user->can('store_balance'); } + + /** + * @return bool + */ + protected function storeChangeMarketCan(): bool + { + $user = Admin::user(); + return $user->can('store_change_market'); + } } diff --git a/app/Admin/Forms/v3/StoreChangeMarketForm.php b/app/Admin/Forms/v3/StoreChangeMarketForm.php new file mode 100644 index 0000000..cfa1ad5 --- /dev/null +++ b/app/Admin/Forms/v3/StoreChangeMarketForm.php @@ -0,0 +1,76 @@ +error('店铺不存在!'); + } + + $goods = GoodsModel::select('id')->where('store_id',$id)->first(); + if($goods){ + return $this->error('店铺存在商品,不可更换市场!'); + } + if(!empty($marketId)){ + $store->market_id = $marketId; + } + if($store->save()){ + return $this->success('修改成功!'); + } + + return $this->error('未做任何修改或者修改失败!'); + } + + /** + * Build a form here. + */ + public function form() + { + $id = $this->payload['id'] ?? 0; + $name = $this->payload['name'] ?? ''; + $marketId = $this->payload['market_id'] ?? 0; + + $marketList = MarketModel::getMarketArray(); + unset($marketList[$marketId]); + + $this->hidden('id')->value($id); + $this->display('name','店铺')->value($name); + + $this->select('market_id','所属市场')->options($marketList)->required(); + } + + /** + * The data of the form. + * + * @return array + */ + public function default() + { + return []; + } + +}