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.
72 lines
1.5 KiB
72 lines
1.5 KiB
<?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;
|
|
|
|
/**
|
|
* BatchAuditProduct constructor.
|
|
* @param null $title
|
|
* @param int $action 1:通过;2:拒绝
|
|
*/
|
|
public function __construct($title = null, $action = 1)
|
|
{
|
|
$this->action = $action;
|
|
|
|
$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;
|
|
Product::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,
|
|
];
|
|
}
|
|
}
|