Browse Source

套包卡券

gorden 4 months ago
parent
commit
7147d10cd5
1 changed files with 41 additions and 5 deletions
  1. 41 5
      app/admin/service/goods/GoodsService.php

+ 41 - 5
app/admin/service/goods/GoodsService.php

@@ -567,7 +567,7 @@ class GoodsService
         $categorys = [];
         if (!empty($categoryIds)) {
             $categorys = SysCategory::whereIn('category_id', $categoryIds)
-                ->whereIn('category_status', ['ACTIVED','UNSHOW'])
+                ->whereIn('category_status', ['ACTIVED', 'UNSHOW'])
                 ->select('category_id as id', 'category_name as name', 'category_super_id as pid', 'category_super_path')
                 ->orderBy('category_sort', 'DESC')
                 ->get()
@@ -575,7 +575,7 @@ class GoodsService
             $data = array_merge($data, $categorys);
         } else if (!empty($categorySuperId)) {
             $categorys = SysCategory::where('category_super_id', $categorySuperId)
-                ->whereIn('category_status', ['ACTIVED','UNSHOW'])
+                ->whereIn('category_status', ['ACTIVED', 'UNSHOW'])
                 ->select('category_id as id', 'category_name as name', 'category_super_id as pid', 'category_super_path')
                 ->orderBy('category_sort', 'DESC')
                 ->get()
@@ -588,7 +588,7 @@ class GoodsService
             $category['category_super_path'] = '#' . $category['id'] . '#';
             // }
             $subCategory = SysCategory::where('category_super_path', 'like', '%' . $category['category_super_path'] . '%')
-                ->whereIn('category_status', ['ACTIVED','UNSHOW'])
+                ->whereIn('category_status', ['ACTIVED', 'UNSHOW'])
                 ->select('category_id as id', 'category_name as name', 'category_super_id as pid', 'category_super_path')
                 ->orderBy('category_sort', 'DESC')
                 ->get()
@@ -1318,8 +1318,20 @@ class GoodsService
                     $data['goods_premisses'] = $goodsAttributeJson['premisses'];
                     $data['goods_premisses_str'] = SysDept::whereIn('dept_id', $goodsAttributeJson['premisses'])->pluck('dept_name');
                 }
+//                if (!empty($goodsAttributeJson['coupon'])) {
+//                    $data['coupon_list'] = $goodsAttributeJson['coupon'];
+//                }
+                $data['couponContentList'] = [];
+                $data['coupon_id'] = [];
                 if (!empty($goodsAttributeJson['coupon'])) {
-                    $data['coupon_list'] = $goodsAttributeJson['coupon'];
+                    foreach ($goodsAttributeJson['coupon'] as $key => $coupon) {
+                        $data['coupon_id'][] = $key;
+                        $data['couponContentList'][] = [
+                            'coupon_id' => $key,
+                            'coupon_name' => $coupon['name'],
+                            'nbr' => $coupon['num']
+                        ];
+                    }
                 }
             }
 
@@ -1491,7 +1503,7 @@ class GoodsService
                 $redis->sAdd(Goods::LISTING_KEY_PREFIX . $key, $params['goods_id']);
             }
             Db::commit();
-        }  catch (BusinessException $e) {
+        } catch (BusinessException $e) {
             Db::rollBack();
             dump($e->getMessage());
             return json_fail($e->getMessage());
@@ -1933,6 +1945,17 @@ class GoodsService
                 $attributeJson['time'] = $attributeJsonTime;
                 $model->goods_attribute_json = json_encode($attributeJson);
             }
+            if (!empty($params['couponContentList'])) {
+                $couponList = [];
+                foreach ($params['couponContentList'] as $coupon) {
+                    $couponList[$coupon['coupon_id']] = [
+                        'num' => $coupon['nbr'],
+                        'name' => $coupon['coupon_name']
+                    ];
+                }
+                $attributeJson['coupon'] = $couponList;
+                $model->goods_attribute_json = json_encode($attributeJson, JSON_UNESCAPED_UNICODE);
+            }
             if (!empty($params['coupon_id']) && !empty($params['coupon_nbr'])) {
                 if (!empty($model->goods_attribute_json) && !is_array($model->goods_attribute_json)) {
                     $attributeJson = json_decode($model->goods_attribute_json, true);
@@ -2310,6 +2333,19 @@ class GoodsService
                 $attributeJson['month'] = $months;
                 $data['goods_attribute_json'] = json_encode($attributeJson, JSON_UNESCAPED_UNICODE);
             }
+
+            if (!empty($params['couponContentList'])) {
+                $couponList = [];
+                foreach ($params['couponContentList'] as $coupon) {
+                    $couponList[$coupon['coupon_id']] = [
+                        'num' => $coupon['nbr'],
+                        'name' => $coupon['coupon_name']
+                    ];
+                }
+                $attributeJson['coupon'] = $couponList;
+                $model->goods_attribute_json = json_encode($attributeJson, JSON_UNESCAPED_UNICODE);
+            }
+
             if (!empty($params['coupon_id']) && !empty($params['coupon_nbr'])) {
                 $attributeJson = [];
                 if (!empty($row->goods_attribute_json)) {