作者 lyh

gx

@@ -298,24 +298,7 @@ class ProductController extends BaseController @@ -298,24 +298,7 @@ class ProductController extends BaseController
298 $v['values'] = ''; 298 $v['values'] = '';
299 } 299 }
300 }else{ 300 }else{
301 - if($v['type'] == 3){  
302 - $arr = json_decode($info['values']);  
303 - foreach ($arr as $k1=>$v1){  
304 - $v1 = (array)$v1;  
305 - $v1['url'] = getImageUrl($v1['url']);  
306 - $arr[$k1] = $v1;  
307 - }  
308 - $v['values'] = $arr;  
309 - }elseif($v['type'] == 4){  
310 - $arr1 = json_decode($info['values']);  
311 - foreach ($arr1 as $k1=>$v1){  
312 - $v1 = getFileUrl($v1);  
313 - $arr1[$k1] = $v1;  
314 - }  
315 - $v['values'] = $arr1;  
316 - }else{  
317 - $v['values'] = $info['values'];  
318 - } 301 + $v = $this->setTypValues($v,$info);
319 } 302 }
320 $list[$k] = $v; 303 $list[$k] = $v;
321 } 304 }
@@ -323,6 +306,35 @@ class ProductController extends BaseController @@ -323,6 +306,35 @@ class ProductController extends BaseController
323 } 306 }
324 307
325 /** 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){
  316 + if($v['type'] == 3){
  317 + $arr = json_decode($info['values']);
  318 + foreach ($arr as $k1=>$v1){
  319 + $v1 = (array)$v1;
  320 + $v1['url'] = getImageUrl($v1['url']);
  321 + $arr[$k1] = $v1;
  322 + }
  323 + $v['values'] = $arr;
  324 + }elseif($v['type'] == 4){
  325 + $arr1 = json_decode($info['values']);
  326 + foreach ($arr1 as $k1=>$v1){
  327 + $v1 = getFileUrl($v1);
  328 + $arr1[$k1] = $v1;
  329 + }
  330 + $v['values'] = $arr1;
  331 + }else{
  332 + $v['values'] = $info['values'];
  333 + }
  334 + return $this->success($v);
  335 + }
  336 +
  337 + /**
326 * @remark :保存产品数据 338 * @remark :保存产品数据
327 * @name :save 339 * @name :save
328 * @author :lyh 340 * @author :lyh
@@ -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,27 +137,38 @@ class ProductLogic extends BaseLogic @@ -112,27 +137,38 @@ class ProductLogic extends BaseLogic
112 if(empty($v['values'])){ 137 if(empty($v['values'])){
113 continue; 138 continue;
114 } 139 }
115 - unset($v['title']);  
116 - if($v['type'] == 3){  
117 - foreach ($v['values'] as $k1=>$v1){  
118 - $v1['url'] = str_replace_url($v1['url']);  
119 - $v['values'][$k1] = $v1;  
120 - }  
121 - $v['values'] = json_encode($v['values']);  
122 - }elseif ($v['type'] == 4){  
123 - foreach ($v['values'] as $k1=>$v1){  
124 - $v1 = str_replace_url($v1);  
125 - $v['values'][$k1] = $v1;  
126 - }  
127 - $v['values'] = json_encode($v['values']);  
128 - }  
129 - $v['project_id'] = $this->user['project_id'];  
130 - $v['product_id'] = $product_id; 140 + $v = $this->saveHandleExtend($v,$product_id);
131 $extendInfoModel->add($v); 141 $extendInfoModel->add($v);
132 } 142 }
133 return $this->success(); 143 return $this->success();
134 } 144 }
135 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){
  154 + unset($v['title']);
  155 + if($v['type'] == 3){
  156 + foreach ($v['values'] as $k1=>$v1){
  157 + $v1['url'] = str_replace_url($v1['url']);
  158 + $v['values'][$k1] = $v1;
  159 + }
  160 + $v['values'] = json_encode($v['values']);
  161 + }elseif ($v['type'] == 4){
  162 + foreach ($v['values'] as $k1=>$v1){
  163 + $v1 = str_replace_url($v1);
  164 + $v['values'][$k1] = $v1;
  165 + }
  166 + $v['values'] = json_encode($v['values']);
  167 + }
  168 + $v['project_id'] = $this->user['project_id'];
  169 + $v['product_id'] = $product_id;
  170 + return $this->success($v);
  171 + }
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);