作者 lyh

gx

@@ -86,22 +86,6 @@ class Common @@ -86,22 +86,6 @@ class Common
86 } 86 }
87 87
88 /** 88 /**
89 - * @remark :识别用户输入语言  
90 - * @name :detectLanguage  
91 - * @author :lyh  
92 - * @method :post  
93 - * @time :2023/8/15 9:25  
94 - */  
95 - public static function detectLanguage($param) {  
96 - if (preg_match('/[\x{4e00}-\x{9fa5}]/u', $param)) {  
97 - return '中文';  
98 - } elseif (preg_match('/[a-zA-Z]/', $param)) {  
99 - return '英文';  
100 - } else {  
101 - return '英文';  
102 - }  
103 - }  
104 - /**  
105 * @name :获取缓存 89 * @name :获取缓存
106 * @return void 90 * @return void
107 * @author :liyuhang 91 * @author :liyuhang
@@ -104,4 +104,23 @@ class ProductController extends BaseController @@ -104,4 +104,23 @@ class ProductController extends BaseController
104 $rs = $logic->setCopyProduct(); 104 $rs = $logic->setCopyProduct();
105 $this->response('success',Code::SUCCESS,$rs); 105 $this->response('success',Code::SUCCESS,$rs);
106 } 106 }
  107 +
  108 + /**
  109 + * @remark :批量设置产品分类及状态
  110 + * @name :batchSetCategory
  111 + * @author :lyh
  112 + * @method :post
  113 + * @time :2023/8/15 17:51
  114 + */
  115 + public function batchSetCategory(ProductLogic $logic){
  116 + $this->request->validate([
  117 + 'id'=>'required',
  118 + 'category_id'=>'required'
  119 + ],[
  120 + 'id.required' => '产品ID不能为空',
  121 + 'category_id' => '分类ID不能为空'
  122 + ]);
  123 + $logic->batchSetCategory();
  124 + $this->response('success');
  125 + }
107 } 126 }
@@ -274,4 +274,38 @@ class ProductLogic extends BaseLogic @@ -274,4 +274,38 @@ class ProductLogic extends BaseLogic
274 } 274 }
275 return $rs; 275 return $rs;
276 } 276 }
  277 +
  278 + /**
  279 + * @remark :批量设置产品分类及状态
  280 + * @name :batchSetCategory
  281 + * @author :lyh
  282 + * @method :post
  283 + * @time :2023/8/15 17:53
  284 + */
  285 + public function batchSetCategory(){
  286 + DB::beginTransaction();
  287 + try {
  288 + //删除分类关联表记录
  289 + $categoryRelatedModel = new CategoryRelated();
  290 + $categoryRelatedModel->del(['product_id'=>['in',$this->param['id']]]);
  291 + //批量
  292 + $param = [
  293 + 'category_id'=>Arr::arrToSet($this->param['category_id']),
  294 + 'status'=>$this->param['status']
  295 + ];
  296 + $this->model->edit($param,['id'=>['in',$this->param['id']]]);
  297 + //新增关联分类
  298 + foreach ($this->param['id'] as $v1){
  299 + foreach ($this->param['category_id'] as $v2){
  300 + CategoryRelated::saveRelated($v1,$v2);
  301 + }
  302 + }
  303 + DB::commit();
  304 + //对应添加关联表
  305 + }catch (\Exception $e){
  306 + DB::rollBack();
  307 + $this->fail('error');
  308 + }
  309 + return $this->success();
  310 + }
277 } 311 }