|  | @@ -129,6 +129,110 @@ class DiscountService
 | 
	
		
			
				|  |  |          
 | 
	
		
			
				|  |  |          return array_values($processedData);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 限时查询一个当前活动的信息和商品信息 活动信息直接加一个商品数组字段
 | 
	
		
			
				|  |  | +     * @param mixed $activityId
 | 
	
		
			
				|  |  | +     * @return array|bool|Model|string|\PDOStatement|null
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    public static function getActivityWithGoods()
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        $currentTime = time();
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  | +        // 查询活动信息
 | 
	
		
			
				|  |  | +        $activity = Db::table('shop_activity')
 | 
	
		
			
				|  |  | +            // ->where('id', $activityId)
 | 
	
		
			
				|  |  | +            ->where('start_time', '<=', $currentTime)
 | 
	
		
			
				|  |  | +            ->where('end_time', '>=', $currentTime)
 | 
	
		
			
				|  |  | +            ->where('activity_status', ActivityEnum::ACTIVITY_STATUS_ONGOING)
 | 
	
		
			
				|  |  | +            ->where('status', StatusEnum::ENABLED)
 | 
	
		
			
				|  |  | +            ->find();
 | 
	
		
			
				|  |  | +            
 | 
	
		
			
				|  |  | +        if (!$activity) {
 | 
	
		
			
				|  |  | +            return null;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  | +        // 查询该活动下的商品信息
 | 
	
		
			
				|  |  | +        $goods = Db::table('shop_activity_sku')
 | 
	
		
			
				|  |  | +            ->alias('sku')
 | 
	
		
			
				|  |  | +            ->join('shop_goods goods', 'sku.goods_id = goods.id')
 | 
	
		
			
				|  |  | +            ->join('shop_goods_sku spec', 'sku.sku_id = spec.id', 'left')
 | 
	
		
			
				|  |  | +            ->where('sku.activity_id', $activity->id)
 | 
	
		
			
				|  |  | +            ->where('goods.status', GoodsEnum::STATUS_ON_SALE)
 | 
	
		
			
				|  |  | +            ->where('sku.stocks', '>', 0)
 | 
	
		
			
				|  |  | +            ->field([
 | 
	
		
			
				|  |  | +                'goods.id as goods_id',
 | 
	
		
			
				|  |  | +                'goods.title',
 | 
	
		
			
				|  |  | +                'goods.sub_title',
 | 
	
		
			
				|  |  | +                'goods.image',
 | 
	
		
			
				|  |  | +                'goods.price as original_price',
 | 
	
		
			
				|  |  | +                'goods.market_price',
 | 
	
		
			
				|  |  | +                'goods.stocks as goods_stocks',
 | 
	
		
			
				|  |  | +                'goods.sales',
 | 
	
		
			
				|  |  | +                'goods.spec_type',
 | 
	
		
			
				|  |  | +                'sku.id as activity_sku_id',
 | 
	
		
			
				|  |  | +                'sku.sku_id',
 | 
	
		
			
				|  |  | +                'sku.discount',
 | 
	
		
			
				|  |  | +                'sku.discount_price',
 | 
	
		
			
				|  |  | +                'sku.stocks as discount_stocks',
 | 
	
		
			
				|  |  | +                'sku.sale_quantity',
 | 
	
		
			
				|  |  | +                'spec.price as sku_price',
 | 
	
		
			
				|  |  | +                'spec.image as sku_image'
 | 
	
		
			
				|  |  | +            ])
 | 
	
		
			
				|  |  | +            ->order('sku.discount', 'asc')
 | 
	
		
			
				|  |  | +            ->select();
 | 
	
		
			
				|  |  | +            
 | 
	
		
			
				|  |  | +        // 处理商品数据
 | 
	
		
			
				|  |  | +        $processedGoods = [];
 | 
	
		
			
				|  |  | +        foreach ($goods as $item) {
 | 
	
		
			
				|  |  | +            $goodsId = $item['goods_id'];
 | 
	
		
			
				|  |  | +            
 | 
	
		
			
				|  |  | +            if (!isset($processedGoods[$goodsId])) {
 | 
	
		
			
				|  |  | +                $processedGoods[$goodsId] = [
 | 
	
		
			
				|  |  | +                    'goods_id' => $goodsId,
 | 
	
		
			
				|  |  | +                    'title' => $item['title'],
 | 
	
		
			
				|  |  | +                    'sub_title' => $item['sub_title'],
 | 
	
		
			
				|  |  | +                    'image' => $item['image'],
 | 
	
		
			
				|  |  | +                    'original_price' => $item['original_price'],
 | 
	
		
			
				|  |  | +                    'market_price' => $item['market_price'],
 | 
	
		
			
				|  |  | +                    'goods_stocks' => $item['goods_stocks'],
 | 
	
		
			
				|  |  | +                    'sales' => $item['sales'],
 | 
	
		
			
				|  |  | +                    'spec_type' => $item['spec_type'],
 | 
	
		
			
				|  |  | +                    'discount_info' => []
 | 
	
		
			
				|  |  | +                ];
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            
 | 
	
		
			
				|  |  | +            $discountInfo = [
 | 
	
		
			
				|  |  | +                'activity_sku_id' => $item['activity_sku_id'],
 | 
	
		
			
				|  |  | +                'sku_id' => $item['sku_id'],
 | 
	
		
			
				|  |  | +                'discount' => $item['discount'],
 | 
	
		
			
				|  |  | +                'discount_price' => $item['discount_price'],
 | 
	
		
			
				|  |  | +                'discount_stocks' => $item['discount_stocks'],
 | 
	
		
			
				|  |  | +                'sale_quantity' => $item['sale_quantity']
 | 
	
		
			
				|  |  | +            ];
 | 
	
		
			
				|  |  | +            
 | 
	
		
			
				|  |  | +            if ($item['sku_id'] > 0) {
 | 
	
		
			
				|  |  | +                $discountInfo['sku_price'] = $item['sku_price'];
 | 
	
		
			
				|  |  | +                $discountInfo['sku_image'] = $item['sku_image'];
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            
 | 
	
		
			
				|  |  | +            $processedGoods[$goodsId]['discount_info'][] = $discountInfo;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  | +        // 在活动信息中添加商品数组字段
 | 
	
		
			
				|  |  | +        $activity['goods'] = array_values($processedGoods);
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  | +        return $activity;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    // 限时zhe'kou一个当前活动的信息和商品信息 活动信息直接加一个商品数组字段
 | 
	
		
			
				|  |  | +    public static function getCurrentActivityInfoAndPrize($activityId)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        $activity = Db::table('shop_activity')->where('id', $activityId)->find();
 | 
	
		
			
				|  |  | +        $prize = Db::table('shop_activity_sku_prize')->where('activity_id', $activityId)->find();
 | 
	
		
			
				|  |  | +        return ['activity' => $activity, 'prize' => $prize];
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |      
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  |       * 根据商品ID和SKU ID获取折扣信息
 |