作者 lyh

gx

@@ -298,6 +298,21 @@ class ProductController extends BaseController @@ -298,6 +298,21 @@ class ProductController extends BaseController
298 $v['values'] = ''; 298 $v['values'] = '';
299 } 299 }
300 }else{ 300 }else{
  301 + $v = $this->setTypValues($v,$info);
  302 + }
  303 + $list[$k] = $v;
  304 + }
  305 + return $list;
  306 + }
  307 +
  308 + /**
  309 + * @remark :扩展字段根据type返回类型
  310 + * @name :setTypValues
  311 + * @author :lyh
  312 + * @method :post
  313 + * @time :2023/12/6 14:43
  314 + */
  315 + public function setTypValues($v,$info){
301 if($v['type'] == 3){ 316 if($v['type'] == 3){
302 $arr = json_decode($info['values']); 317 $arr = json_decode($info['values']);
303 foreach ($arr as $k1=>$v1){ 318 foreach ($arr as $k1=>$v1){
@@ -316,10 +331,7 @@ class ProductController extends BaseController @@ -316,10 +331,7 @@ class ProductController extends BaseController
316 }else{ 331 }else{
317 $v['values'] = $info['values']; 332 $v['values'] = $info['values'];
318 } 333 }
319 - }  
320 - $list[$k] = $v;  
321 - }  
322 - return $list; 334 + return $this->success($v);
323 } 335 }
324 336
325 /** 337 /**
@@ -38,21 +38,12 @@ class ProductLogic extends BaseLogic @@ -38,21 +38,12 @@ class ProductLogic extends BaseLogic
38 * @time :2023/8/21 18:35 38 * @time :2023/8/21 18:35
39 */ 39 */
40 public function productSave(){ 40 public function productSave(){
41 - //扩展字段  
42 - $extend = [];  
43 - if(!empty($this->param['extend'])){  
44 - $extend = $this->param['extend'];  
45 - unset($this->param['extend']);  
46 - }  
47 - $this->param = $this->handleSaveParam($this->param); 41 + //处理扩展字段
  42 + $extend = $this->handleExtent();
48 //单独处理分类 43 //单独处理分类
49 - $category_ids = [];  
50 - if(isset($this->param['category_id']) && !empty($this->param['category_id'])) {  
51 - $category_ids = $this->getLastCategoryArr($this->param['category_id']);  
52 - $this->param['category_id'] = ','.implode(',',$category_ids).',';  
53 - }else{  
54 - $this->param['category_id'] = '';  
55 - } 44 + $category_ids = $this->handleCategory();
  45 + //处理其他字段
  46 + $this->param = $this->handleSaveParam($this->param);
56 DB::connection('custom_mysql')->beginTransaction(); 47 DB::connection('custom_mysql')->beginTransaction();
57 try { 48 try {
58 if(isset($this->param['id']) && !empty($this->param['id'])){ 49 if(isset($this->param['id']) && !empty($this->param['id'])){
@@ -81,6 +72,40 @@ class ProductLogic extends BaseLogic @@ -81,6 +72,40 @@ class ProductLogic extends BaseLogic
81 } 72 }
82 73
83 /** 74 /**
  75 + * @remark :处理扩展字段
  76 + * @name :handleExtent
  77 + * @author :lyh
  78 + * @method :post
  79 + * @time :2023/12/6 15:06
  80 + */
  81 + public function handleExtent(){
  82 + //扩展字段
  83 + $extend = [];
  84 + if(!empty($this->param['extend'])){
  85 + $extend = $this->param['extend'];
  86 + unset($this->param['extend']);
  87 + }
  88 + return $extend;
  89 + }
  90 +
  91 + /**
  92 + * @remark :处理分类数据
  93 + * @name :handleCategory
  94 + * @author :lyh
  95 + * @method :post
  96 + * @time :2023/12/6 15:01
  97 + */
  98 + public function handleCategory(){
  99 + $category_ids = [];
  100 + if(isset($this->param['category_id']) && !empty($this->param['category_id'])) {
  101 + $category_ids = $this->getLastCategoryArr($this->param['category_id']);
  102 + $this->param['category_id'] = ','.implode(',',$category_ids).',';
  103 + }else{
  104 + $this->param['category_id'] = '';
  105 + }
  106 + return $category_ids;
  107 + }
  108 + /**
84 * @remark :新增时处理字段 109 * @remark :新增时处理字段
85 * @name :addHandleParam 110 * @name :addHandleParam
86 * @author :lyh 111 * @author :lyh
@@ -112,6 +137,20 @@ class ProductLogic extends BaseLogic @@ -112,6 +137,20 @@ class ProductLogic extends BaseLogic
112 if(empty($v['values'])){ 137 if(empty($v['values'])){
113 continue; 138 continue;
114 } 139 }
  140 + $v = $this->saveHandleExtend($v,$product_id);
  141 + $extendInfoModel->add($v);
  142 + }
  143 + return $this->success();
  144 + }
  145 +
  146 + /**
  147 + * @remark :保存扩展字段时处理数据
  148 + * @name :saveHandleExtend
  149 + * @author :lyh
  150 + * @method :post
  151 + * @time :2023/12/6 15:11
  152 + */
  153 + public function saveHandleExtend(&$v,$product_id){
115 unset($v['title']); 154 unset($v['title']);
116 if($v['type'] == 3){ 155 if($v['type'] == 3){
117 foreach ($v['values'] as $k1=>$v1){ 156 foreach ($v['values'] as $k1=>$v1){
@@ -128,11 +167,8 @@ class ProductLogic extends BaseLogic @@ -128,11 +167,8 @@ class ProductLogic extends BaseLogic
128 } 167 }
129 $v['project_id'] = $this->user['project_id']; 168 $v['project_id'] = $this->user['project_id'];
130 $v['product_id'] = $product_id; 169 $v['product_id'] = $product_id;
131 - $extendInfoModel->add($v); 170 + return $this->success($v);
132 } 171 }
133 - return $this->success();  
134 - }  
135 -  
136 172
137 /** 173 /**
138 * @remark :编辑列表数据 174 * @remark :编辑列表数据
@@ -38,7 +38,9 @@ class CategoryRelated extends Base @@ -38,7 +38,9 @@ class CategoryRelated extends Base
38 foreach ($cate_ids as $cate_id){ 38 foreach ($cate_ids as $cate_id){
39 $data[] = [ 39 $data[] = [
40 'product_id' => $product_id, 40 'product_id' => $product_id,
41 - 'cate_id' => $cate_id 41 + 'cate_id' => $cate_id,
  42 + 'created_at'=>date('Y-m-d H:i:s'),
  43 + 'updated_at'=>date('Y-m-d H:i:s')
42 ]; 44 ];
43 } 45 }
44 self::insert($data); 46 self::insert($data);