From b17591ee1160adb3ef277c19376f6d5c739735d6 Mon Sep 17 00:00:00 2001 From: liapples Date: Thu, 16 Dec 2021 00:25:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E6=9E=B6=E6=89=80=E6=9C=89=E4=BE=9B?= =?UTF-8?q?=E5=BA=94=E5=95=86=E4=BA=A7=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Actions/Grid/ShelveAllSupplierProduct.php | 85 +++++++++++++++++++ .../Controllers/AgentProductController.php | 5 ++ 2 files changed, 90 insertions(+) create mode 100644 app/AdminAgent/Actions/Grid/ShelveAllSupplierProduct.php diff --git a/app/AdminAgent/Actions/Grid/ShelveAllSupplierProduct.php b/app/AdminAgent/Actions/Grid/ShelveAllSupplierProduct.php new file mode 100644 index 0000000..29a93da --- /dev/null +++ b/app/AdminAgent/Actions/Grid/ShelveAllSupplierProduct.php @@ -0,0 +1,85 @@ +appendHtmlAttribute('class', 'btn btn-primary btn-outline'); + + return <<formatHtmlAttributes()}>{$this->title()} +HTML; + } + + /** + * Handle the action request. + * + * @param Request $request + * + * @return Response + */ + public function handle(Request $request) + { + Product::select(['id'])->where([ + ['status', '=', ProductStatus::ON_SALE], + ['stock', '>', 0] + ])->chunk(200, function ($products) { + foreach ($products as $product) { + AgentProductShelve::dispatch(Admin::user()->id, $product->id); + } + }); + return $this->response()->success('操作成功,此操作可能需要几分钟,请耐心等待')->refresh(); + } + + /** + * @return string|void + */ + protected function href() + { + // return admin_url('auth/users'); + } + + /** + * @return string|array|void + */ + public function confirm() + { + return ['确定要上架所有供应商的全部产品吗?']; + } + + /** + * @param Model|Authenticatable|HasPermissions|null $user + * + * @return bool + */ + protected function authorize($user): bool + { + return true; + } + + /** + * @return array + */ + protected function parameters() + { + return []; + } +} diff --git a/app/AdminAgent/Controllers/AgentProductController.php b/app/AdminAgent/Controllers/AgentProductController.php index 4726dd5..646f6e5 100644 --- a/app/AdminAgent/Controllers/AgentProductController.php +++ b/app/AdminAgent/Controllers/AgentProductController.php @@ -2,6 +2,7 @@ namespace App\AdminAgent\Controllers; +use App\AdminAgent\Actions\Grid\ShelveAllSupplierProduct; use App\AdminAgent\Forms\LoadSupplierSpec; use App\AdminAgent\Renderable\SelectGuide; use App\AdminAgent\Renderable\SelectProduct; @@ -35,6 +36,7 @@ class AgentProductController extends AdminController return Grid::make(new AgentProduct(['product.supplier:id,company_name', 'category:id,name']), function (Grid $grid) { $agent_id = Admin::user()->id; $grid->model()->where('agent_id', $agent_id); + if ($source = request()->input('source')) { if ($source == 1) { $grid->model()->where('product_id', 0); @@ -43,6 +45,9 @@ class AgentProductController extends AdminController } } + # 上架所有供应商产品 + $grid->tools(new ShelveAllSupplierProduct); + $grid->column('id')->sortable(); $grid->column('product.supplier.company_name')->limit(8); $grid->column('picture', '产品图片')->image('', 60, 60);