Browse Source

fix:首页状态判断

super-yimizi 1 month ago
parent
commit
c37d79f500
2 changed files with 107 additions and 43 deletions
  1. 3 43
      application/api/controller/Common.php
  2. 104 0
      application/common/Service/DiscountService.php

+ 3 - 43
application/api/controller/Common.php

@@ -43,47 +43,7 @@ class Common extends Api
         parent::_initialize();
     }
 
-    /**
-     * 加载初始化
-     *
-     * @ApiParams (name="version", type="string", required=true, description="版本号")
-     * @ApiParams (name="lng", type="string", required=true, description="经度")
-     * @ApiParams (name="lat", type="string", required=true, description="纬度")
-     */
-    // public function init()
-    // {
-    //     if ($version = $this->request->request('version')) {
-    //         $lng = $this->request->request('lng');
-    //         $lat = $this->request->request('lat');
-
-    //         //配置信息
-    //         $upload = Config::get('upload');
-    //         //如果非服务端中转模式需要修改为中转
-    //         if ($upload['storage'] != 'local' && isset($upload['uploadmode']) && $upload['uploadmode'] != 'server') {
-    //             //临时修改上传模式为服务端中转
-    //             set_addon_config($upload['storage'], ["uploadmode" => "server"], false);
-
-    //             $upload = \app\common\model\Config::upload();
-    //             // 上传信息配置后
-    //             Hook::listen("upload_config_init", $upload);
-
-    //             $upload = Config::set('upload', array_merge(Config::get('upload'), $upload));
-    //         }
-
-    //         $upload['cdnurl'] = $upload['cdnurl'] ? $upload['cdnurl'] : cdnurl('', true);
-    //         $upload['uploadurl'] = preg_match("/^((?:[a-z]+:)?\/\/)(.*)/i", $upload['uploadurl']) ? $upload['uploadurl'] : url($upload['storage'] == 'local' ? '/api/common/upload' : $upload['uploadurl'], '', false, true);
-
-    //         $content = [
-    //             'citydata'    => Area::getCityFromLngLat($lng, $lat),
-    //             'versiondata' => Version::check($version),
-    //             'uploaddata'  => $upload,
-    //             'coverdata'   => Config::get("cover"),
-    //         ];
-    //         $this->success('', $content);
-    //     } else {
-    //         $this->error(__('Invalid parameters'));
-    //     }
-    // }
+   
 
     /**
      * 初始化
@@ -253,14 +213,14 @@ class Common extends Api
         $newList['measure'] = $measureList;
         // todo  查询活动商品
         //  首页推荐的分类
-        $indexCategoryList = Category::where('status', StatusEnum::NORMAL)
+        $indexCategoryList = Category::where('status', StatusEnum::ENABLED)
         ->field('id,name,image')
         ->where('is_recommend',StatusEnum::YES)
         ->order('weigh desc')
         ->limit(8)
         ->select();
         //热门分类
-        $indexHotCategoryList = Category::where('status', StatusEnum::NORMAL)
+        $indexHotCategoryList = Category::where('status', StatusEnum::ENABLED)
         ->field('id,name,image')
         ->where('is_hot',StatusEnum::YES)
         ->order('weigh desc')

+ 104 - 0
application/common/Service/DiscountService.php

@@ -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获取折扣信息