作者 lyh

gx

@@ -213,16 +213,7 @@ class ProductController extends BaseController @@ -213,16 +213,7 @@ class ProductController extends BaseController
213 * @time :2023/8/17 9:15 213 * @time :2023/8/17 9:15
214 */ 214 */
215 public function handleParam($v){ 215 public function handleParam($v){
216 - $v['category_id_text'] = '';  
217 $v['keyword_id_text'] = ''; 216 $v['keyword_id_text'] = '';
218 - if(!empty($v['category_id'])){  
219 - $categoryModel = new Category();  
220 - $category_data = $categoryModel->list(['id'=>['in',$v['category_id']]],'id',['title']);  
221 - foreach ($category_data as $v1){  
222 - $v['category_id_text'] .= $v1['title'].',';  
223 - }  
224 - $v['category_id_text'] = trim($v['category_id_text'],',');  
225 - }  
226 if(!empty($v['keyword_id'])){ 217 if(!empty($v['keyword_id'])){
227 $keywordModel = new Keyword(); 218 $keywordModel = new Keyword();
228 $keyword_data = $keywordModel->list(['id'=>['in',$v['keyword_id']]]); 219 $keyword_data = $keywordModel->list(['id'=>['in',$v['keyword_id']]]);
@@ -102,12 +102,12 @@ class BlogLogic extends BaseLogic @@ -102,12 +102,12 @@ class BlogLogic extends BaseLogic
102 if($info === false){ 102 if($info === false){
103 $this->fail('error'); 103 $this->fail('error');
104 } 104 }
105 - $category = explode(',',trim($info['category_id'],','));  
106 - $str = [];  
107 - foreach ($category as $v){  
108 - $this->getAllFather($v,$str);  
109 - }  
110 - $info['category_id'] = array_values(array_unique($str)); 105 + $info['category_id'] = explode(',',trim($info['category_id'],','));
  106 +// $str = [];
  107 +// foreach ($category as $v){
  108 +// $this->getAllFather($v,$str);
  109 +// }
  110 +// $info['category_id'] = array_values(array_unique($str));
111 //获取标签名称 111 //获取标签名称
112 $blogLabelLogic = new BlogLabelLogic(); 112 $blogLabelLogic = new BlogLabelLogic();
113 $info['label_name'] = $blogLabelLogic->getLabelName($info['label_id']); 113 $info['label_name'] = $blogLabelLogic->getLabelName($info['label_id']);
@@ -115,21 +115,21 @@ class BlogLogic extends BaseLogic @@ -115,21 +115,21 @@ class BlogLogic extends BaseLogic
115 return $this->success($info); 115 return $this->success($info);
116 } 116 }
117 117
118 - /**  
119 - * @remark :获取分类的所有上级  
120 - * @name :getAllFather  
121 - * @author :lyh  
122 - * @method :post  
123 - * @time :2023/10/20 9:08  
124 - */  
125 - public function getAllFather($id,&$str = []){  
126 - $cateModel = new BlogCategoryModel();  
127 - $info = $cateModel->read(['id'=>$id],['id','pid']);  
128 - if($info !== false){  
129 - $str[] = (int)$id;  
130 - $this->getAllFather($info['pid'],$str);  
131 - }  
132 - } 118 +// /**
  119 +// * @remark :获取分类的所有上级
  120 +// * @name :getAllFather
  121 +// * @author :lyh
  122 +// * @method :post
  123 +// * @time :2023/10/20 9:08
  124 +// */
  125 +// public function getAllFather($id,&$str = []){
  126 +// $cateModel = new BlogCategoryModel();
  127 +// $info = $cateModel->read(['id'=>$id],['id','pid']);
  128 +// if($info !== false){
  129 +// $str[] = (int)$id;
  130 +// $this->getAllFather($info['pid'],$str);
  131 +// }
  132 +// }
133 133
134 /** 134 /**
135 * @name :修改状态 135 * @name :修改状态
@@ -152,12 +152,12 @@ class NewsLogic extends BaseLogic @@ -152,12 +152,12 @@ class NewsLogic extends BaseLogic
152 if($info === false){ 152 if($info === false){
153 $this->fail('error'); 153 $this->fail('error');
154 } 154 }
155 - $category = explode(',',trim($info['category_id'],','));  
156 - $str = [];  
157 - foreach ($category as $v){  
158 - $this->getAllFather($v,$str);  
159 - }  
160 - $info['category_id'] = array_values(array_unique($str)); 155 + $info['category_id'] = explode(',',trim($info['category_id'],','));
  156 +// $str = [];
  157 +// foreach ($category as $v){
  158 +// $this->getAllFather($v,$str);
  159 +// }
  160 +// $info['category_id'] = array_values(array_unique($str));
161 $info['image_link'] = getImageUrl($info['image']); 161 $info['image_link'] = getImageUrl($info['image']);
162 return $this->success($info); 162 return $this->success($info);
163 } 163 }
@@ -4,6 +4,7 @@ namespace App\Http\Logic\Bside\Product; @@ -4,6 +4,7 @@ namespace App\Http\Logic\Bside\Product;
4 4
5 use App\Helper\Arr; 5 use App\Helper\Arr;
6 use App\Http\Logic\Bside\BaseLogic; 6 use App\Http\Logic\Bside\BaseLogic;
  7 +use App\Models\Product\Category;
7 use App\Models\Product\CategoryRelated; 8 use App\Models\Product\CategoryRelated;
8 use App\Models\Product\Product; 9 use App\Models\Product\Product;
9 use App\Models\RouteMap\RouteMap; 10 use App\Models\RouteMap\RouteMap;
@@ -26,9 +27,6 @@ class ProductLogic extends BaseLogic @@ -26,9 +27,6 @@ class ProductLogic extends BaseLogic
26 $this->model = new Product(); 27 $this->model = new Product();
27 } 28 }
28 29
29 -  
30 -  
31 -  
32 /** 30 /**
33 * @remark :保存产品 31 * @remark :保存产品
34 * @name :productSave 32 * @name :productSave
@@ -37,7 +35,7 @@ class ProductLogic extends BaseLogic @@ -37,7 +35,7 @@ class ProductLogic extends BaseLogic
37 * @time :2023/8/21 18:35 35 * @time :2023/8/21 18:35
38 */ 36 */
39 public function productSave(){ 37 public function productSave(){
40 - $category_ids = $this->param['category_id'] ?? []; 38 +// $category_ids = $this->param['category_id'] ?? [];
41 //参数处理 39 //参数处理
42 $this->param = $this->handleSaveParam($this->param); 40 $this->param = $this->handleSaveParam($this->param);
43 DB::connection('custom_mysql')->beginTransaction(); 41 DB::connection('custom_mysql')->beginTransaction();
@@ -56,8 +54,7 @@ class ProductLogic extends BaseLogic @@ -56,8 +54,7 @@ class ProductLogic extends BaseLogic
56 $route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT, $id, $this->user['project_id']); 54 $route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT, $id, $this->user['project_id']);
57 $this->model->edit(['route'=>$route],['id'=>$id]); 55 $this->model->edit(['route'=>$route],['id'=>$id]);
58 //产品分类关联 56 //产品分类关联
59 - CategoryRelated::saveRelated($id, $category_ids);  
60 - 57 +// CategoryRelated::saveRelated($id, $category_ids);
61 DB::connection('custom_mysql')->commit(); 58 DB::connection('custom_mysql')->commit();
62 }catch (\Exception $e){ 59 }catch (\Exception $e){
63 DB::connection('custom_mysql')->rollBack(); 60 DB::connection('custom_mysql')->rollBack();
@@ -88,7 +85,7 @@ class ProductLogic extends BaseLogic @@ -88,7 +85,7 @@ class ProductLogic extends BaseLogic
88 $param['attrs'] = Arr::a2s($param['attrs'] ?? ''); 85 $param['attrs'] = Arr::a2s($param['attrs'] ?? '');
89 $param['attr_id'] = Arr::arrToSet($param['attr_id'] ?? ''); 86 $param['attr_id'] = Arr::arrToSet($param['attr_id'] ?? '');
90 if(isset($param['category_id']) && !empty($param['category_id'])){ 87 if(isset($param['category_id']) && !empty($param['category_id'])){
91 - $param['category_id'] = ','.Arr::arrToSet($param['category_id']).','; 88 + $param['category_id'] = $this->getLastCategory($param['category_id']);
92 } 89 }
93 if(isset($param['keyword_id']) && !empty($param['keyword_id'])){ 90 if(isset($param['keyword_id']) && !empty($param['keyword_id'])){
94 $param['keyword_id'] = ','.Arr::arrToSet($param['keyword_id']).','; 91 $param['keyword_id'] = ','.Arr::arrToSet($param['keyword_id']).',';
@@ -108,6 +105,25 @@ class ProductLogic extends BaseLogic @@ -108,6 +105,25 @@ class ProductLogic extends BaseLogic
108 } 105 }
109 106
110 /** 107 /**
  108 + * @remark :获取最后一级分类id
  109 + * @name :getLastCategory
  110 + * @author :lyh
  111 + * @method :post
  112 + * @time :2023/10/20 9:02
  113 + */
  114 + public function getLastCategory($category){
  115 + $str = '';
  116 + $cateModel = new Category();
  117 + foreach ($category as $v){
  118 + $info = $cateModel->read(['pid'=>$v]);
  119 + if($info === false){
  120 + $str .= $v.',';
  121 + }
  122 + }
  123 + return ','.$str;
  124 + }
  125 +
  126 + /**
111 * @remark :编辑产品 127 * @remark :编辑产品
112 * @name :editProduct 128 * @name :editProduct
113 * @author :lyh 129 * @author :lyh