作者 lyh

gx

... ... @@ -86,22 +86,6 @@ class Common
}
/**
* @remark :识别用户输入语言
* @name :detectLanguage
* @author :lyh
* @method :post
* @time :2023/8/15 9:25
*/
public static function detectLanguage($param) {
if (preg_match('/[\x{4e00}-\x{9fa5}]/u', $param)) {
return '中文';
} elseif (preg_match('/[a-zA-Z]/', $param)) {
return '英文';
} else {
return '英文';
}
}
/**
* @name :获取缓存
* @return void
* @author :liyuhang
... ...
... ... @@ -104,4 +104,23 @@ class ProductController extends BaseController
$rs = $logic->setCopyProduct();
$this->response('success',Code::SUCCESS,$rs);
}
/**
* @remark :批量设置产品分类及状态
* @name :batchSetCategory
* @author :lyh
* @method :post
* @time :2023/8/15 17:51
*/
public function batchSetCategory(ProductLogic $logic){
$this->request->validate([
'id'=>'required',
'category_id'=>'required'
],[
'id.required' => '产品ID不能为空',
'category_id' => '分类ID不能为空'
]);
$logic->batchSetCategory();
$this->response('success');
}
}
... ...
... ... @@ -274,4 +274,38 @@ class ProductLogic extends BaseLogic
}
return $rs;
}
/**
* @remark :批量设置产品分类及状态
* @name :batchSetCategory
* @author :lyh
* @method :post
* @time :2023/8/15 17:53
*/
public function batchSetCategory(){
DB::beginTransaction();
try {
//删除分类关联表记录
$categoryRelatedModel = new CategoryRelated();
$categoryRelatedModel->del(['product_id'=>['in',$this->param['id']]]);
//批量
$param = [
'category_id'=>Arr::arrToSet($this->param['category_id']),
'status'=>$this->param['status']
];
$this->model->edit($param,['id'=>['in',$this->param['id']]]);
//新增关联分类
foreach ($this->param['id'] as $v1){
foreach ($this->param['category_id'] as $v2){
CategoryRelated::saveRelated($v1,$v2);
}
}
DB::commit();
//对应添加关联表
}catch (\Exception $e){
DB::rollBack();
$this->fail('error');
}
return $this->success();
}
}
... ...