You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
<?php
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 Illuminate\Http\Request;
/** * 批量审核产品 * Class BatchAuditProduct * @package App\Admin\Actions\Grid */class BatchAuditProduct extends BatchAction{ /** * @return string */ protected $action; private ?string $title_text; private $type = 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) { $this->action = $action; $this->type = $type;
$this->title_text = $action == 1 ? '审核通过' : '审核拒绝'; $this->title = '<i class="fa '.($action == 1 ? 'fa-check-square' : 'fa-times-circle') . '"></i> ' . $this->title_text;
parent::__construct($title); }
/** * Handle the action request. * * @param Request $request * * @return Response */ public function handle(Request $request) { $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(); }
/** * @return string|array|void */ public function confirm() { return "确定要批量{$this->title_text}吗?"; }
/** * @return array */ protected function parameters() { return [ 'action' => $this->action, 'type' => $this->type, ]; }}
|