|
@@ -335,22 +335,6 @@ class ProductLogic extends BaseLogic |
|
@@ -335,22 +335,6 @@ class ProductLogic extends BaseLogic |
|
335
|
return !empty(trim($str,',')) ? ','.$str.',' : '';
|
335
|
return !empty(trim($str,',')) ? ','.$str.',' : '';
|
|
336
|
}
|
336
|
}
|
|
337
|
|
337
|
|
|
338
|
- /**
|
|
|
|
339
|
- * @remark :获取最后一级分类id(数组)
|
|
|
|
340
|
- * @name :getLastCategory
|
|
|
|
341
|
- * @author :lyh
|
|
|
|
342
|
- * @method :post
|
|
|
|
343
|
- * @time :2023/10/20 9:02
|
|
|
|
344
|
- */
|
|
|
|
345
|
- public function getLastCategoryArr($category){
|
|
|
|
346
|
- $arr = [];
|
|
|
|
347
|
- if(isset($category) && !empty($category)){
|
|
|
|
348
|
- foreach ($category as $v){
|
|
|
|
349
|
- $arr[] = $v;
|
|
|
|
350
|
- }
|
|
|
|
351
|
- }
|
|
|
|
352
|
- return $arr;
|
|
|
|
353
|
- }
|
|
|
|
354
|
|
338
|
|
|
355
|
/**
|
339
|
/**
|
|
356
|
* @remark :编辑产品
|
340
|
* @remark :编辑产品
|
|
@@ -575,27 +559,29 @@ class ProductLogic extends BaseLogic |
|
@@ -575,27 +559,29 @@ class ProductLogic extends BaseLogic |
|
575
|
* @time :2023/8/15 17:53
|
559
|
* @time :2023/8/15 17:53
|
|
576
|
*/
|
560
|
*/
|
|
577
|
public function batchSetCategory(){
|
561
|
public function batchSetCategory(){
|
|
578
|
- if(isset($this->param['category_id']) && !empty($this->param['category_id'])) {
|
|
|
|
579
|
- DB::connection('custom_mysql')->beginTransaction();
|
|
|
|
580
|
- $category_ids = $this->getLastCategoryArr($this->param['category_id']);
|
|
|
|
581
|
- $this->param['category_id'] = ','.implode(',',$category_ids).',';
|
562
|
+ if(!isset($this->param['category_id']) || empty($this->param['category_id'])){
|
|
|
|
563
|
+ $this->fail('请选择分类');
|
|
|
|
564
|
+ }
|
|
582
|
try {
|
565
|
try {
|
|
583
|
- //批量
|
|
|
|
584
|
- $param = [
|
|
|
|
585
|
- 'category_id'=>$this->param['category_id'],
|
|
|
|
586
|
- 'status'=>$this->param['status']
|
|
|
|
587
|
- ];
|
|
|
|
588
|
- $this->model->edit($param,['id'=>['in',$this->param['id']]]);
|
566
|
+ if(!isset($this->param['is_cover']) || ($this->param['is_cover'] == 1)){
|
|
|
|
567
|
+ $category_ids = ','.implode(',',$this->param['category_id']).',';
|
|
|
|
568
|
+ $this->model->edit(['category_id'=>$category_ids],['id'=>['in',$this->param['id']]]);
|
|
589
|
//分类关联
|
569
|
//分类关联
|
|
590
|
foreach ($this->param['id'] as $id){
|
570
|
foreach ($this->param['id'] as $id){
|
|
591
|
- CategoryRelated::saveRelated($id, $category_ids);
|
571
|
+ CategoryRelated::saveRelated($id, $this->param['category_id']);
|
|
|
|
572
|
+ }
|
|
|
|
573
|
+ }else{
|
|
|
|
574
|
+ foreach ($this->param['id'] as $id){
|
|
|
|
575
|
+ //获取当前产品的分类
|
|
|
|
576
|
+ $productInfo = $this->model->read(['id'=>$id],['id','category_id']);
|
|
|
|
577
|
+ $category_ids_arr = array_values(array_unique(array_merge($productInfo['category_id'],$this->param['category_id'])));
|
|
|
|
578
|
+ $category_ids = ','.implode(',',$category_ids_arr).',';
|
|
|
|
579
|
+ $this->model->edit(['category_id'=>$category_ids],['id'=>$id]);
|
|
|
|
580
|
+ CategoryRelated::saveRelated($id, $category_ids_arr);
|
|
592
|
}
|
581
|
}
|
|
593
|
- DB::connection('custom_mysql')->commit();
|
|
|
|
594
|
- //对应添加关联表
|
|
|
|
595
|
- }catch (\Exception $e){
|
|
|
|
596
|
- DB::connection('custom_mysql')->rollBack();
|
|
|
|
597
|
- $this->fail('系统错误,请联系管理员');
|
|
|
|
598
|
}
|
582
|
}
|
|
|
|
583
|
+ }catch (\Exception $e){
|
|
|
|
584
|
+ $this->fail('设置分类失败,请联系管理员');
|
|
599
|
}
|
585
|
}
|
|
600
|
return $this->success();
|
586
|
return $this->success();
|
|
601
|
}
|
587
|
}
|