瀏覽代碼

add - 活动商品、优惠券改动

liugc 1 年之前
父節點
當前提交
fb1fe70664

+ 6 - 1
app/adminapi/lists/coupon/CouponRulesLists.php

@@ -40,7 +40,7 @@ class CouponRulesLists extends BaseAdminDataLists implements ListsSearchInterfac
     public function setSearch(): array
     {
         return [
-            '=' => ['amount',  'amount_require',  'max_deductible_price', 'mold_type', 'server_category_name', 'coupon_type','voucher_status','property_activity_id'],
+            '=' => ['amount',  'amount_require',  'max_deductible_price', 'mold_type', 'server_category_name', 'coupon_type','voucher_status'],
             '%like%' => ['event_name','code'],
         ];
     }
@@ -83,6 +83,11 @@ class CouponRulesLists extends BaseAdminDataLists implements ListsSearchInterfac
             }
             $where[] = ['id','IN',$ids];
         }
+        if (isset($this->params['property_activity_id']) && !empty($this->params['property_activity_id'])) {
+            // 筛选已选过的
+
+            $where[] = ['id','>' ,0];//100000
+        }
         return $where;
     }
     /**

+ 6 - 1
app/adminapi/lists/goods/GoodsLists.php

@@ -41,7 +41,7 @@ class GoodsLists extends BaseAdminDataLists implements ListsSearchInterface
     public function setSearch(): array
     {
         return [
-            '=' => ['goods_status','is_agent','property_activity_id'],
+            '=' => ['goods_status','is_agent'],
             '%like%' => ['goods_name','goods_brand'],
             'between' => ['service_total', 'service_fee'],
         ];
@@ -63,6 +63,11 @@ class GoodsLists extends BaseAdminDataLists implements ListsSearchInterface
         } else {
             $where[] = ['user_id','=' ,$this->params['user_id']];
         }
+        if (isset($this->params['property_activity_id']) && !empty($this->params['property_activity_id'])) {
+            // 筛选已选过的
+
+            $where[] = ['property_activity_id','>' ,0];//100000
+        }
         return $where;
     }
 

+ 1 - 1
app/adminapi/lists/property/PropertyActivityLists.php

@@ -57,7 +57,7 @@ class PropertyActivityLists extends BaseAdminDataLists implements ListsSearchInt
     {
         return PropertyActivity::with(['propertyHeadInfo'])
         ->where($this->searchWhere)
-            ->field(['id', 'property_head_id', 'activity_name', 'activity_start_time', 'activity_end_time','block_data','url_page','page_type','images'])
+            ->field(['id', 'property_head_id', 'activity_name', 'activity_start_time', 'activity_end_time','block_data','coupon_data','url_page','page_type','images'])
             ->limit($this->limitOffset, $this->limitLength)
             ->order(['id' => 'desc'])
             ->select()

+ 35 - 4
app/adminapi/logic/property/PropertyActivityLogic.php

@@ -46,8 +46,10 @@ class PropertyActivityLogic extends BaseLogic
             PropertyActivity::create([
                 'property_head_id' => $params['property_head_id'],
                 'activity_name' => $params['activity_name'],
-                'activity_start_time' => $params['activity_start_time'],
-                'activity_end_time' => $params['activity_end_time'],
+                'activity_start_time' => $params['activity_start_time']?strtotime($params['activity_start_time']):0,
+                'activity_end_time' => $params['activity_end_time']?strtotime($params['activity_end_time']):0,
+                'block_data' => self::configureReservedField($params['block_data']??[], 'block_data'),
+                'coupon_data' => self::configureReservedField($params['coupon_data']??[], 'coupon_data'),
                 'url_page' => $params['url_page']??'',
                 'page_type' => $params['page_type']??0,
                 'images' => $params['images']??[],
@@ -79,7 +81,8 @@ class PropertyActivityLogic extends BaseLogic
                 'activity_name' => $params['activity_name'],
                 'activity_start_time' => $params['activity_start_time']?strtotime($params['activity_start_time']):0,
                 'activity_end_time' => $params['activity_end_time']?strtotime($params['activity_end_time']):0,
-                'block_data' => json_encode($params['block_data']??[]),
+                'block_data' => json_encode(self::configureReservedField($params['block_data']??[], 'block_data')),
+                'coupon_data' => json_encode(self::configureReservedField($params['coupon_data']??[], 'coupon_data')),
                 'url_page' => $params['url_page']??'',
                 'page_type' => $params['page_type']??0,
                 'images' => json_encode($params['images']??[]),
@@ -93,7 +96,34 @@ class PropertyActivityLogic extends BaseLogic
             return false;
         }
     }
-
+    public static function configureReservedField($data, $reserved_type,$reserved_field = []): array
+    {
+        if($reserved_type === 'block_data'){
+            $reserved_field = ['id','recommend_weight','goods_name'];
+            foreach ($data as &$item) {
+                foreach ($item['goods'] as &$good) {
+                    foreach ($good as $k=>$v) {
+                        if(!in_array($k,$reserved_field)){
+                            unset($good[$k]);
+                        }
+                    }
+                }
+            }
+        }
+        if($reserved_type === 'coupon_data'){
+            $reserved_field = ['id','voucher_count','voucher_status','server_category_name','event_name','couponWithCategory','expire_time',
+                    'amount_require','amount','max_deductible_price','discount_ratio','mold_type','coupon_type','code','remaining_count'
+                ];
+            foreach ($data as &$item) {
+                foreach ($item as $k=>$v) {
+                    if(!in_array($k,$reserved_field)){
+                        unset($item[$k]);
+                    }
+                }
+            }
+        }
+        return $data??[];
+    }
 
     /**
      * @notes 删除
@@ -153,4 +183,5 @@ class PropertyActivityLogic extends BaseLogic
     }
 
 
+
 }

+ 83 - 24
app/api/logic/ActivityLogic.php

@@ -59,24 +59,25 @@ class ActivityLogic extends BaseLogic
                     }
                     $v['goods'] = self::groupArrays($v['goods']);
                 }
+                $res['coupons'] = CouponRules::with(['couponCategoryOne'])->where('property_activity_id',$params['property_activity_id'])
+                    ->select()
+                    ->toArray();
+                foreach ($res['coupons'] as &$coupon) {
+                    $coupon['goods_category_id'] = $coupon['couponCategoryOne']['goods_category_id'];
+                }
+                $res['goods'] =  Goods::where('property_activity_id',$params['property_activity_id'])
+                    ->where('is_agent',1)
+                    ->visible(['id','goods_name','goods_image','base_service_fee','service_total','service_fee','goods_type'])
+                    ->order('is_recommend desc')
+                    ->select()
+                    ->toArray();
+                // 临时添加
+                foreach ($res['goods'] as &$good){
+                    $good['service_fee'] = $good['base_service_fee'];
+                }
             }else{
                 $res['block_data_structure'] = self::blockDataStructure($res['activity_info']['url_page'],$res['activity_info']['block_data']);
-            }
-            $res['coupons'] = CouponRules::with(['couponCategoryOne'])->where('property_activity_id',$params['property_activity_id'])
-                ->select()
-                ->toArray();
-            foreach ($res['coupons'] as &$coupon) {
-                $coupon['goods_category_id'] = $coupon['couponCategoryOne']['goods_category_id'];
-            }
-            $res['goods'] =  Goods::where('property_activity_id',$params['property_activity_id'])
-                ->where('is_agent',1)
-                ->visible(['id','goods_name','goods_image','base_service_fee','service_total','service_fee','goods_type'])
-                ->order('is_recommend desc')
-                ->select()
-                ->toArray();
-            // 临时添加
-            foreach ($res['goods'] as &$good){
-                $good['service_fee'] = $good['base_service_fee'];
+                $res['coupons'] = self::couponDataStructure($params['property_activity_id']);
             }
             return $res;
         }catch(\Exception $e){
@@ -88,9 +89,11 @@ class ActivityLogic extends BaseLogic
         array_multisort(array_column($data, 'sort'), SORT_DESC, $data);
         foreach ($data as &$v){
             array_multisort(array_column($v['goods'], 'recommend_weight'), SORT_DESC, $v['goods']);
-            // 临时改价 11-28
             if(!empty($v['goods'])){
                 foreach ($v['goods'] as &$item){
+                    $item = Goods::findOrEmpty($item['id'])->toArray();
+
+                    // 临时改价 11-28
                     $item['service_fee'] = $item['base_service_fee'];
                 }
             }
@@ -105,6 +108,17 @@ class ActivityLogic extends BaseLogic
         }
         return $data;
     }
+    public static function couponDataStructure(int $property_activity_id): array {
+        $couponIds = self::getDataIdsByType($property_activity_id, 'coupon_data');
+        $coupons = CouponRules::with(['couponCategoryOne'])
+            ->where('id','in',$couponIds)
+            ->select()
+            ->toArray();
+        foreach ($coupons as &$coupon) {
+            $coupon['goods_category_id'] = $coupon['couponCategoryOne']['goods_category_id'];
+        }
+        return $coupons;
+    }
     public static function groupArrays($array) {
         $result = []; $groupSize = 2;
         $totalElements = count($array);
@@ -116,13 +130,9 @@ class ActivityLogic extends BaseLogic
     }
     public static function createPropertyOrder($params,$serviceOrder){
         try{
-            // 判断商品是否为 代理活动商品
-            $goods = Goods::findOrEmpty($params['goods_id']);
-            if($goods->isEmpty()){
-                throw new \Exception('产品不存在!');
-            }
-            if($goods->property_activity_id > 0){
-                $propertyActivity = PropertyActivity::findOrEmpty($goods->property_activity_id);
+            // 代理活动
+            if(isset($params['property_activity_id']) && !empty($params['property_activity_id'])){
+                $propertyActivity = PropertyActivity::findOrEmpty($params['property_activity_id']);
                 if($propertyActivity->isEmpty()){
                     throw new \Exception('活动不存在');
                 }
@@ -146,11 +156,60 @@ class ActivityLogic extends BaseLogic
                 if($result === false){
                     throw new \Exception('生成代理单失败');
                 }
+            }elseif (isset($params['goods_id']) && !empty($params['goods_id'])) {
+                // 判断商品是否为 代理活动商品
+                $goods = Goods::findOrEmpty($params['goods_id']);
+                if ($goods->isEmpty()) {
+                    throw new \Exception('产品不存在!');
+                }
+                if ($goods->property_activity_id > 0) {
+                    $propertyActivity = PropertyActivity::findOrEmpty($goods->property_activity_id);
+                    if ($propertyActivity->isEmpty()) {
+                        throw new \Exception('活动不存在');
+                    }
+                    if (!empty($propertyActivity->getData('activity_start_time')) && $propertyActivity->getData('activity_start_time') > time()) {
+                        throw new \Exception('活动未开始');
+                    }
+                    if (!empty($propertyActivity->getData('activity_end_time')) && $propertyActivity->getData('activity_end_time') < time()) {
+                        throw new \Exception('活动已结束');
+                    }
+                    // 生成代理单 user_info
+                    // remark address  property_head_id  householder_name householder_mobile
+                    $result = PropertyOrderLogic::add(array_merge($params, [
+                        'property_head_id' => $propertyActivity['property_head_id'],
+                        'householder_mobile' => $params['user_info']['mobile'],
+                        'householder_name' => $params['user_info']['real_name'],
+                        'address' => $params['address'],
+                        'remark' => '',
+                        'order_status' => 1,
+                        'work_id' => $serviceOrder['work_id'],
+                    ]));
+                    if ($result === false) {
+                        throw new \Exception('生成代理单失败');
+                    }
+                }
             }
             return true;
         }catch(\Exception $e){
             throw new \Exception($e->getMessage());
         }
     }
+    public static function getDataIdsByType($property_activity_id, $type): array
+    {
+        $ids = [];
+        $activityInfo = PropertyActivity::where('property_activity_id',$property_activity_id)->findOrEmpty();
+        if(!$activityInfo->isEmpty()){
+            $activityInfo = $activityInfo->toArray();
+            if($type === 'block_data'){
+                foreach ($activityInfo['block_data'] as &$item) {
+                    $ids = array_merge($ids,array_column($item['goods'], 'id'));
+                }
+            }
+            if($type === 'coupon_data'){
+                $ids = array_merge($ids,array_column($activityInfo['coupon_data'], 'id'));
+            }
+        }
+        return $ids??[0];
+    }
 
 }

+ 5 - 2
app/api/logic/UserCouponLogic.php

@@ -173,10 +173,13 @@ class UserCouponLogic extends BaseLogic
 
             $coupon_ids = CouponCategory::where('goods_category_id',$params['goods_category_id'])->whereIn('coupon_id',$coupon_all_ids)->column('coupon_id');
 
-            // 商品Id - 代理Id - 代理券
+            // 去除代理券
             $remove_coupon_ids = [0];
             Log::info('remove_coupon_ids:'.json_encode([$params,$remove_coupon_ids]));
-            if(isset($params['goods_id']) && !empty($params['goods_id'])){
+            if(isset($params['property_activity_id']) && !empty($params['property_activity_id'])){
+                $remove_coupon_ids = ActivityLogic::getDataIdsByType($params['property_activity_id'], 'coupon_data');
+                Log::info('remove_coupon_ids-1001:'.json_encode([$params['property_activity_id'],$remove_coupon_ids]));
+            }elseif (isset($params['goods_id']) && !empty($params['goods_id'])){
                 $property_activity_id = Goods::where('id',$params['goods_id'])->value('property_activity_id');
                 $property_activity_id && $remove_coupon_ids = CouponRules::where('property_activity_id',$property_activity_id)->column('id')?:[0];
                 Log::info('remove_coupon_ids-1001:'.json_encode([$property_activity_id,$remove_coupon_ids]));

+ 1 - 0
app/common/model/property/PropertyActivity.php

@@ -30,6 +30,7 @@ class PropertyActivity extends BaseModel
     protected $name = 'property_activity';
     protected $type = [
         'block_data' => 'array',
+        'coupon_data' => 'array',
         'images' => 'array',
     ];