From 09b24182815f07a4a6ed7cb6722a0421aa7ac2f8 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Fri, 30 Oct 2020 17:33:49 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=B4=BB=E5=8A=A8=E5=95=86=E5=93=81--?= =?UTF-8?q?=E6=89=B9=E9=87=8F=E4=B8=8A=E4=B8=8B=E6=9E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v3/GoodsActivityController.php | 12 +++- .../Extensions/Tools/GoodsActivityOnSale.php | 59 +++++++++++++++++++ 2 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 app/Admin/Extensions/Tools/GoodsActivityOnSale.php diff --git a/app/Admin/Controllers/v3/GoodsActivityController.php b/app/Admin/Controllers/v3/GoodsActivityController.php index 2a4e77b..4c288a2 100644 --- a/app/Admin/Controllers/v3/GoodsActivityController.php +++ b/app/Admin/Controllers/v3/GoodsActivityController.php @@ -16,6 +16,7 @@ use App\Models\v3\GoodsActivity as GoodsActivityModel; use Dcat\Admin\Form\NestedForm; use App\Models\v3\GoodsCategory as GoodsCategoryModel; use App\Admin\Common\Auth; +use App\Admin\Extensions\Tools\GoodsActivityOnSale; use App\Admin\Forms\v3\GoodsActivitySettingForm; use Dcat\Admin\Admin; use Dcat\Admin\Layout\Content; @@ -92,10 +93,17 @@ class GoodsActivityController extends AdminController $filter->equal('price'); $filter->equal('goods_unit'); }); - // 每页10条 - $grid->paginate(10); + $grid->actions([new GoodsActivityCopy()]); $grid->tools([new GoodsActivitySetting()]); + $grid->batchActions([ + new GoodsActivityOnSale('上架', 1), + new GoodsActivityOnSale('下架', 0), + ]); + + // 每页10条 + $grid->paginate(10); + $grid->disableBatchDelete(); }); } diff --git a/app/Admin/Extensions/Tools/GoodsActivityOnSale.php b/app/Admin/Extensions/Tools/GoodsActivityOnSale.php new file mode 100644 index 0000000..e7a125a --- /dev/null +++ b/app/Admin/Extensions/Tools/GoodsActivityOnSale.php @@ -0,0 +1,59 @@ +title = $title; + $this->action = $action; + } + + // 确认弹窗信息 + public function confirm() + { + return '您确定要'.$this->title.'已选中的商品吗?'; + } + + // 处理请求 + public function handle(Request $request) + { + // 获取选中的文章ID数组 + $keys = $this->getKey(); + if(empty($keys) || !is_array($keys)){ + return $this->response()->error('请选择商品!'); + } + // 获取请求参数 + $action = $request->get('action'); + $title = $request->get('title'); + $actionWhere = $action == 1 ? 0 : 1 ; + $title = $this->title ? $this->title : $title; + + // 下架处理 + $res = GoodsActivityModel::whereIn('id',$keys)->where('on_sale',$actionWhere)->update(['on_sale'=>$action]); + if($res){ + return $this->response()->success($title.'成功')->refresh(); + }else{ + return $this->response()->error($title.'失败或已'.$title.'!'); + } + } + + // 设置请求参数 + public function parameters() + { + return [ + 'action' => $this->action, + 'title' => $this->title, + ]; + } +} \ No newline at end of file From 2450bfde729afd8623e0849a6e7aac437d6b1dd1 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Fri, 30 Oct 2020 17:50:14 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=95=86=E5=93=81--=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=95=86=E5=93=81=E7=B1=BB=E7=9B=AE=E5=BF=AB=E6=8D=B7=E7=BC=96?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Controllers/v3/GoodsActivityController.php | 12 ++++-------- app/Admin/Controllers/v3/GoodsController.php | 7 +++---- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/app/Admin/Controllers/v3/GoodsActivityController.php b/app/Admin/Controllers/v3/GoodsActivityController.php index 4c288a2..3c62395 100644 --- a/app/Admin/Controllers/v3/GoodsActivityController.php +++ b/app/Admin/Controllers/v3/GoodsActivityController.php @@ -34,18 +34,14 @@ class GoodsActivityController extends AdminController $marketId = Auth::getMarket(); $build = new \App\Models\v3\GoodsActivity(); if ($marketId){ - //$build = new \App\Models\v3\Goods(); $build = $build::where('market_id',$marketId); $storeList = StoreModel::getStoreArray([['market_id','=',$marketId]]); }else{ - //$build = new GoodsActivity(); $storeList = StoreModel::getStoreArray([['market_id','=',$marketId]]); } return Grid::make($build, function (Grid $grid) use($storeList){ // 二级分类 $categoryList = CategoryModel::getArray([['parent_id','>',0]],['选择分类'=>0]); - // 店铺 - // $storeList = StoreModel::getStoreArray(); // 商品类目 $goodsCategoryList = GoodsCategoryModel::getArray([],['选择类目'=>0]); //市场 @@ -71,10 +67,10 @@ class GoodsActivityController extends AdminController $item = CategoryModel::getInfo($categoryId,'title'); return empty($item) ? '' : $item->title; }); - // $grid->goods_category_id->display(function ($goodsCategoryId){ - // $item = GoodsCategoryModel::getInfo($goodsCategoryId,'title'); - // return empty($item) ? '' : $item->title; - // }); + $grid->goods_category_id->display(function ($goodsCategoryId){ + $item = GoodsCategoryModel::getInfo($goodsCategoryId,'title'); + return empty($item) ? '' : $item->title; + }); $grid->column('expire_time_text'); $grid->column('sales'); $grid->column('on_sale')->switch(); diff --git a/app/Admin/Controllers/v3/GoodsController.php b/app/Admin/Controllers/v3/GoodsController.php index d14d9ce..349505c 100644 --- a/app/Admin/Controllers/v3/GoodsController.php +++ b/app/Admin/Controllers/v3/GoodsController.php @@ -41,8 +41,6 @@ class GoodsController extends AdminController return Grid::make($build, function (Grid $grid) use($storeList){ // 二级分类 $categoryList = CategoryModel::getArray([['parent_id','>',0]],['选择分类'=>0]); - // 店铺 - // $storeList = StoreModel::getStoreArray(); // 商品类目 $goodsCategoryList = GoodsCategoryModel::getArray([],['选择类目'=>0]); @@ -55,7 +53,7 @@ class GoodsController extends AdminController $id = $this->id; $banners = GoodsBannersModel::getArray([['goods_id','=',$id],['type','=',1]]); return $banners; - })->image('', 50); + })->image('', 50)->width('5%'); $grid->name->editable(); $grid->price->editable(); $grid->original_price->editable(); @@ -81,12 +79,13 @@ class GoodsController extends AdminController // $grid->category_id->display(function ($categoryId) use($categoryList){ // return isset($categoryList[$categoryId]) ? $categoryList[$categoryId] : ''; // }); + $grid->goods_category_id->select($goodsCategoryList); // $grid->goods_category_id->display(function ($goodsCategoryId) use($goodsCategoryList){ // return isset($goodsCategoryList[$goodsCategoryId]) ? $goodsCategoryList[$goodsCategoryId] : ''; // }); // 简介 - $grid->content->width(200); + $grid->content->width(150); $grid->on_sale->switch(); From 9713691e442738b28c862529b9f4600c23f5f3ca Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Fri, 30 Oct 2020 17:55:00 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=95=86=E5=93=81--=E7=B1=BB=E7=9B=AE?= =?UTF-8?q?=E5=8A=A0help=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Controllers/v3/GoodsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Admin/Controllers/v3/GoodsController.php b/app/Admin/Controllers/v3/GoodsController.php index 349505c..9b11b19 100644 --- a/app/Admin/Controllers/v3/GoodsController.php +++ b/app/Admin/Controllers/v3/GoodsController.php @@ -79,7 +79,7 @@ class GoodsController extends AdminController // $grid->category_id->display(function ($categoryId) use($categoryList){ // return isset($categoryList[$categoryId]) ? $categoryList[$categoryId] : ''; // }); - $grid->goods_category_id->select($goodsCategoryList); + $grid->goods_category_id->select($goodsCategoryList)->help('注意商品类目所属的分类!!!'); // $grid->goods_category_id->display(function ($goodsCategoryId) use($goodsCategoryList){ // return isset($goodsCategoryList[$goodsCategoryId]) ? $goodsCategoryList[$goodsCategoryId] : ''; // });