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\Extensions\Tools;
use Dcat\Admin\Grid\BatchAction;use Illuminate\Http\Request;use App\Models\v3\GoodsActivity as GoodsActivityModel;
class GoodsActivityOnSale extends BatchAction{ protected $action; /** * 批量上下架活动商品 */ // 注意action的构造方法参数一定要给默认值
public function __construct($title = null, $action = 1) { $this->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, ]; }}
|