diff --git a/app/Admin/Actions/Grid/BatchAuditProduct.php b/app/Admin/Actions/Grid/BatchAuditProduct.php
index 14f165c..57eb93b 100644
--- a/app/Admin/Actions/Grid/BatchAuditProduct.php
+++ b/app/Admin/Actions/Grid/BatchAuditProduct.php
@@ -2,11 +2,11 @@
namespace App\Admin\Actions\Grid;
+use App\Common\ProductStatus;
+use App\Models\IndustryProduct;
+use App\Models\Product;
use Dcat\Admin\Actions\Response;
use Dcat\Admin\Grid\BatchAction;
-use Dcat\Admin\Traits\HasPermissions;
-use Illuminate\Contracts\Auth\Authenticatable;
-use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
/**
@@ -19,23 +19,25 @@ class BatchAuditProduct extends BatchAction
/**
* @return string
*/
- protected $title = '批量审核';
+ protected $action;
+ private ?string $title_text;
+ private $type = null;
- public function __construct($title = null)
+ /**
+ * BatchAuditProduct constructor.
+ * @param null $title
+ * @param int $action 1:通过;2:拒绝
+ * @param int $type 1:普通产品Product;2:行业产品IndustryProduct;
+ */
+ public function __construct($title = null, $action = 1, $type = 1)
{
- parent::__construct($title);
- }
+ $this->action = $action;
+ $this->type = $type;
- public function render()
- {
- $redirect = request()->fullUrl();
+ $this->title_text = $action == 1 ? '审核通过' : '审核拒绝';
+ $this->title = ' ' . $this->title_text;
- return << {$this->title}
-HTML;//拒绝图标:fa-times-circle
+ parent::__construct($title);
}
/**
@@ -47,9 +49,15 @@ HTML;//拒绝图标:fa-times-circle
*/
public function handle(Request $request)
{
- return $this->response()
- ->success('Processed successfully: '.json_encode($this->getKey()))
- ->redirect('/');
+ $status = $request->action == 1 ? ProductStatus::ON_SALE : ProductStatus::REFUSE;
+
+ if ($request->type == 1) {
+ Product::whereIn('id', $this->getKey())->update(['status' => $status]);
+ } else {
+ IndustryProduct::whereIn('id', $this->getKey())->update(['status' => $status]);
+ }
+
+ return $this->response()->success('操作成功!')->refresh();
}
/**
@@ -57,24 +65,17 @@ HTML;//拒绝图标:fa-times-circle
*/
public function confirm()
{
- // return ['Confirm?', 'contents'];
+ return "确定要批量{$this->title_text}吗?";
}
- /**
- * @param Model|Authenticatable|HasPermissions|null $user
- *
- * @return bool
- */
- protected function authorize($user): bool
- {
- return true;
- }
-
/**
* @return array
*/
protected function parameters()
{
- return [];
+ return [
+ 'action' => $this->action,
+ 'type' => $this->type,
+ ];
}
}
diff --git a/app/Admin/Controllers/IndustryProductController.php b/app/Admin/Controllers/IndustryProductController.php
index b9520e7..aa75f58 100644
--- a/app/Admin/Controllers/IndustryProductController.php
+++ b/app/Admin/Controllers/IndustryProductController.php
@@ -2,6 +2,7 @@
namespace App\Admin\Controllers;
+use App\Admin\Actions\Grid\BatchAuditProduct;
use App\Admin\Extensions\Grid\AuditIndustryProduct;
use App\Admin\Repositories\IndustryProduct;
use App\Common\ProductStatus;
@@ -25,6 +26,11 @@ class IndustryProductController extends AdminController
$grid->disableCreateButton();
$grid->disableDeleteButton();
+ $grid->batchActions([
+ new BatchAuditProduct(null, 1, 2),
+ new BatchAuditProduct(null, 2, 2),
+ ]);
+
//如果是审核页面,多加where条件判断
if (strpos(Route::current()->uri, 'audit')) {
$grid->model()->where('status', UserStatus::UNAUDITED);
diff --git a/app/Admin/Controllers/ProductController.php b/app/Admin/Controllers/ProductController.php
index 3631a7c..40023e7 100644
--- a/app/Admin/Controllers/ProductController.php
+++ b/app/Admin/Controllers/ProductController.php
@@ -32,8 +32,10 @@ class ProductController extends AdminController
$grid->model()->where('status', ProductStatus::UNAUDITED);
}
-// $grid->batchActions(new BatchAuditProduct);
-// $grid->batchActions(new BatchAuditProduct);
+ $grid->batchActions([
+ new BatchAuditProduct(null, 1, 1),
+ new BatchAuditProduct(null, 2, 1),
+ ]);
$grid->column('id')->sortable();
$grid->column('category.name', '分类');