瀏覽代碼

一些功能

Kirin 3 年之前
父節點
當前提交
2cd34f5f30

+ 4 - 4
app/api/controller/PublicController.php

@@ -94,12 +94,12 @@ class PublicController
         $firstNumber = sys_config('first_number', 0);//TODO 首发新品个数
         $firstNumber = sys_config('first_number', 0);//TODO 首发新品个数
         $promotionNumber = sys_config('promotion_number', 0);//TODO 首发新品个数
         $promotionNumber = sys_config('promotion_number', 0);//TODO 首发新品个数
         $info['fastList'] = StoreCategory::byIndexList((int)$fastNumber, false);//TODO 快速选择分类个数
         $info['fastList'] = StoreCategory::byIndexList((int)$fastNumber, false);//TODO 快速选择分类个数
-        $info['bastList'] = StoreProduct::getBestProduct('id,image,store_name,cate_id,price,ot_price,IFNULL(sales,0) + IFNULL(ficti,0) as sales,unit_name', (int)$bastNumber, $request->uid(), false);//TODO 精品推荐个数
+        $info['bastList'] = StoreProduct::getBestProduct('id,image,store_name,cate_id,price,ot_price,IFNULL(sales,0) + IFNULL(ficti,0) as sales,unit_name', (int)$bastNumber, $request->uid(), false, $request->store_id());//TODO 精品推荐个数
-        $info['firstList'] = StoreProduct::getNewProduct('id,image,store_name,cate_id,price,unit_name,IFNULL(sales,0) + IFNULL(ficti,0) as sales', (int)$firstNumber, $request->uid(), false);//TODO 首发新品个数
+        $info['firstList'] = StoreProduct::getNewProduct('id,image,store_name,cate_id,price,unit_name,IFNULL(sales,0) + IFNULL(ficti,0) as sales', (int)$firstNumber, $request->uid(), false, $request->store_id());//TODO 首发新品个数
         $info['bastBanner'] = sys_data('routine_home_bast_banner') ?? [];//TODO 首页精品推荐图片
         $info['bastBanner'] = sys_data('routine_home_bast_banner') ?? [];//TODO 首页精品推荐图片
-        $benefit = StoreProduct::getBenefitProduct('id,image,store_name,cate_id,price,ot_price,stock,unit_name', $promotionNumber);//TODO 首页促销单品
+        $benefit = StoreProduct::getBenefitProduct('id,image,store_name,cate_id,price,ot_price,stock,unit_name', $promotionNumber, $request->store_id());//TODO 首页促销单品
         $lovely = sys_data('routine_home_new_banner') ?: [];//TODO 首发新品顶部图
         $lovely = sys_data('routine_home_new_banner') ?: [];//TODO 首发新品顶部图
-        $likeInfo = StoreProduct::getHotProduct('id,image,store_name,cate_id,price,ot_price,unit_name', 3);//TODO 热门榜单 猜你喜欢
+        $likeInfo = StoreProduct::getHotProduct('id,image,store_name,cate_id,price,ot_price,unit_name', 3, $request->uid(), $request->store_id());//TODO 热门榜单 猜你喜欢
         $couponList = StoreCouponIssue::getIssueCouponList($request->uid(), 3);
         $couponList = StoreCouponIssue::getIssueCouponList($request->uid(), 3);
         if ($request->uid()) {
         if ($request->uid()) {
             $subscribe = WechatUser::where('uid', $request->uid())->value('subscribe') ? true : false;
             $subscribe = WechatUser::where('uid', $request->uid())->value('subscribe') ? true : false;

+ 9 - 4
app/api/controller/store/StoreProductController.php

@@ -4,6 +4,7 @@ namespace app\api\controller\store;
 
 
 use app\admin\model\store\StoreDescription;
 use app\admin\model\store\StoreDescription;
 use app\admin\model\system\SystemAttachment;
 use app\admin\model\system\SystemAttachment;
+use app\admin\model\system\SystemStoreProductStock;
 use app\models\routine\RoutineCode;
 use app\models\routine\RoutineCode;
 use app\models\store\StoreOrder;
 use app\models\store\StoreOrder;
 use app\models\store\StoreVisit;
 use app\models\store\StoreVisit;
@@ -199,6 +200,10 @@ class StoreProductController
         $productHot = StoreProduct::getHotProductLoading('id,image,store_name,cate_id,price,unit_name,ot_price', (int)$page, (int)$limit);
         $productHot = StoreProduct::getHotProductLoading('id,image,store_name,cate_id,price,unit_name,ot_price', (int)$page, (int)$limit);
         if (!empty($productHot)) {
         if (!empty($productHot)) {
             foreach ($productHot as $k => $v) {
             foreach ($productHot as $k => $v) {
+                if ($request->store_id()) {
+                    $stockinfo = SystemStoreProductStock::where('product_id', $productHot[$k]['id'])->where('store_id', $request->store_id())->find();
+                    $productHot['price'] = $stockinfo ? SystemStoreProductStock::where('product_id', $productHot[$k]['id'])->where('store_id', $request->store_id())->min('price') : $productHot[$k]['price'];
+                }
                 $productHot[$k]['activity'] = StoreProduct::activity($v['id']);
                 $productHot[$k]['activity'] = StoreProduct::activity($v['id']);
             }
             }
         }
         }
@@ -220,16 +225,16 @@ class StoreProductController
         $info['list'] = [];
         $info['list'] = [];
         if ($type == 1) {//TODO 精品推荐
         if ($type == 1) {//TODO 精品推荐
             $info['banner'] = sys_data('routine_home_bast_banner') ?: [];//TODO 首页精品推荐图片
             $info['banner'] = sys_data('routine_home_bast_banner') ?: [];//TODO 首页精品推荐图片
-            $info['list'] = StoreProduct::getBestProduct('id,image,store_name,cate_id,price,ot_price,IFNULL(sales,0) + IFNULL(ficti,0) as sales,unit_name,sort');//TODO 精品推荐个数
+            $info['list'] = StoreProduct::getBestProduct('id,image,store_name,cate_id,price,ot_price,IFNULL(sales,0) + IFNULL(ficti,0) as sales,unit_name,sort', 0, $request->uid(), true, $request->store_id());//TODO 精品推荐个数
         } else if ($type == 2) {//TODO  热门榜单
         } else if ($type == 2) {//TODO  热门榜单
             $info['banner'] = sys_data('routine_home_hot_banner') ?: [];//TODO 热门榜单 猜你喜欢推荐图片
             $info['banner'] = sys_data('routine_home_hot_banner') ?: [];//TODO 热门榜单 猜你喜欢推荐图片
-            $info['list'] = StoreProduct::getHotProduct('id,image,store_name,cate_id,price,ot_price,unit_name,sort,IFNULL(sales,0) + IFNULL(ficti,0) as sales', 0, $request->uid());//TODO 热门榜单 猜你喜欢
+            $info['list'] = StoreProduct::getHotProduct('id,image,store_name,cate_id,price,ot_price,unit_name,sort,IFNULL(sales,0) + IFNULL(ficti,0) as sales', 0, $request->uid(), $request->store_id());//TODO 热门榜单 猜你喜欢
         } else if ($type == 3) {//TODO 首发新品
         } else if ($type == 3) {//TODO 首发新品
             $info['banner'] = sys_data('routine_home_new_banner') ?: [];//TODO 首发新品推荐图片
             $info['banner'] = sys_data('routine_home_new_banner') ?: [];//TODO 首发新品推荐图片
-            $info['list'] = StoreProduct::getNewProduct('id,image,store_name,cate_id,price,ot_price,unit_name,sort,IFNULL(sales,0) + IFNULL(ficti,0) as sales', 0, $request->uid());//TODO 首发新品
+            $info['list'] = StoreProduct::getNewProduct('id,image,store_name,cate_id,price,ot_price,unit_name,sort,IFNULL(sales,0) + IFNULL(ficti,0) as sales', 0, $request->uid(), true, $request->store_id());//TODO 首发新品
         } else if ($type == 4) {//TODO 促销单品
         } else if ($type == 4) {//TODO 促销单品
             $info['banner'] = sys_data('routine_home_benefit_banner') ?: [];//TODO 促销单品推荐图片
             $info['banner'] = sys_data('routine_home_benefit_banner') ?: [];//TODO 促销单品推荐图片
-            $info['list'] = StoreProduct::getBenefitProduct('id,image,store_name,cate_id,price,ot_price,stock,unit_name,sort');//TODO 促销单品
+            $info['list'] = StoreProduct::getBenefitProduct('id,image,store_name,cate_id,price,ot_price,stock,unit_name,sort', 0, $request->store_id());//TODO 促销单品
         }
         }
         return app('json')->successful($info);
         return app('json')->successful($info);
     }
     }

+ 22 - 6
app/models/store/StoreProduct.php

@@ -122,8 +122,8 @@ class StoreProduct extends BaseModel
                 if (is_null($item['cart_num'])) $item['cart_num'] = 0;
                 if (is_null($item['cart_num'])) $item['cart_num'] = 0;
             }
             }
             if ($store_id) {
             if ($store_id) {
-                $stockinfo = SystemStoreProductStock::where('product_id', $item['id'])->find();
+                $stockinfo = SystemStoreProductStock::where('product_id', $item['id'])->where('store_id', $store_id)->find();
-                $item['price'] = $stockinfo ? SystemStoreProductStock::where('product_id', $item['id'])->min('price') : $item['price'];
+                $item['price'] = $stockinfo ? SystemStoreProductStock::where('product_id', $item['id'])->where('store_id', $store_id)->min('price') : $item['price'];
             }
             }
         });
         });
         $list = count($list) ? $list->toArray() : [];
         $list = count($list) ? $list->toArray() : [];
@@ -179,7 +179,7 @@ class StoreProduct extends BaseModel
      * @param int $limit
      * @param int $limit
      * @return false|\PDOStatement|string|\think\Collection
      * @return false|\PDOStatement|string|\think\Collection
      */
      */
-    public static function getNewProduct($field = '*', $limit = 0, $uid = 0, bool $bool = true)
+    public static function getNewProduct($field = '*', $limit = 0, $uid = 0, bool $bool = true, $store_id = 0)
     {
     {
         if (!$limit && !$bool) return [];
         if (!$limit && !$bool) return [];
         $model = self::where('is_new', 1)->where('is_del', 0)->where('mer_id', 0)
         $model = self::where('is_new', 1)->where('is_del', 0)->where('mer_id', 0)
@@ -190,6 +190,10 @@ class StoreProduct extends BaseModel
         $list = count($list) ? $list->toArray() : [];
         $list = count($list) ? $list->toArray() : [];
         if (!empty($list)) {
         if (!empty($list)) {
             foreach ($list as $k => $v) {
             foreach ($list as $k => $v) {
+                if ($store_id) {
+                    $stockinfo = SystemStoreProductStock::where('product_id', $list[$k]['id'])->where('store_id', $store_id)->find();
+                    $item['price'] = $stockinfo ? SystemStoreProductStock::where('product_id', $list[$k]['id'])->where('store_id', $store_id)->min('price') : $list[$k]['price'];
+                }
                 $list[$k]['activity'] = self::activity($v['id']);
                 $list[$k]['activity'] = self::activity($v['id']);
             }
             }
         }
         }
@@ -202,7 +206,7 @@ class StoreProduct extends BaseModel
      * @param int $limit
      * @param int $limit
      * @return false|\PDOStatement|string|\think\Collection
      * @return false|\PDOStatement|string|\think\Collection
      */
      */
-    public static function getHotProduct($field = '*', $limit = 0, $uid = 0)
+    public static function getHotProduct($field = '*', $limit = 0, $uid = 0, $store_id = 0)
     {
     {
         $model = self::where('is_hot', 1)->where('is_del', 0)->where('mer_id', 0)
         $model = self::where('is_hot', 1)->where('is_del', 0)->where('mer_id', 0)
             ->where('stock', '>', 0)->where('is_show', 1)->field($field)
             ->where('stock', '>', 0)->where('is_show', 1)->field($field)
@@ -212,6 +216,10 @@ class StoreProduct extends BaseModel
         $list = count($list) ? $list->toArray() : [];
         $list = count($list) ? $list->toArray() : [];
         if (!empty($list)) {
         if (!empty($list)) {
             foreach ($list as $k => $v) {
             foreach ($list as $k => $v) {
+                if ($store_id) {
+                    $stockinfo = SystemStoreProductStock::where('product_id', $list[$k]['id'])->where('store_id', $store_id)->find();
+                    $item['price'] = $stockinfo ? SystemStoreProductStock::where('product_id', $list[$k]['id'])->where('store_id', $store_id)->min('price') : $list[$k]['price'];
+                }
                 $list[$k]['activity'] = self::activity($v['id']);
                 $list[$k]['activity'] = self::activity($v['id']);
             }
             }
         }
         }
@@ -246,7 +254,7 @@ class StoreProduct extends BaseModel
      * @param int $limit
      * @param int $limit
      * @return false|\PDOStatement|string|\think\Collection
      * @return false|\PDOStatement|string|\think\Collection
      */
      */
-    public static function getBestProduct($field = '*', $limit = 0, $uid = 0, bool $bool = true)
+    public static function getBestProduct($field = '*', $limit = 0, $uid = 0, bool $bool = true, $store_id = 0)
     {
     {
         if (!$limit && !$bool) return [];
         if (!$limit && !$bool) return [];
         $model = self::where('is_best', 1)->where('is_del', 0)->where('mer_id', 0)
         $model = self::where('is_best', 1)->where('is_del', 0)->where('mer_id', 0)
@@ -258,6 +266,10 @@ class StoreProduct extends BaseModel
         if (!empty($list)) {
         if (!empty($list)) {
             foreach ($list as $k => $v) {
             foreach ($list as $k => $v) {
                 $list[$k]['activity'] = self::activity($v['id']);
                 $list[$k]['activity'] = self::activity($v['id']);
+                if ($store_id) {
+                    $stockinfo = SystemStoreProductStock::where('product_id', $list[$k]['id'])->where('store_id', $store_id)->find();
+                    $item['price'] = $stockinfo ? SystemStoreProductStock::where('product_id', $list[$k]['id'])->where('store_id', $store_id)->min('price') : $list[$k]['price'];
+                }
             }
             }
         }
         }
         return self::setLevelPrice($list, $uid);
         return self::setLevelPrice($list, $uid);
@@ -309,7 +321,7 @@ class StoreProduct extends BaseModel
      * @param int $limit
      * @param int $limit
      * @return false|\PDOStatement|string|\think\Collection
      * @return false|\PDOStatement|string|\think\Collection
      */
      */
-    public static function getBenefitProduct($field = '*', $limit = 0)
+    public static function getBenefitProduct($field = '*', $limit = 0, $store_id = 0)
     {
     {
         $model = self::where('is_benefit', 1)
         $model = self::where('is_benefit', 1)
             ->where('is_del', 0)->where('mer_id', 0)->where('stock', '>', 0)
             ->where('is_del', 0)->where('mer_id', 0)->where('stock', '>', 0)
@@ -319,6 +331,10 @@ class StoreProduct extends BaseModel
         $data = $model->select();
         $data = $model->select();
         if (count($data) > 0) {
         if (count($data) > 0) {
             foreach ($data as $k => $v) {
             foreach ($data as $k => $v) {
+                if ($store_id) {
+                    $stockinfo = SystemStoreProductStock::where('product_id', $data[$k]['id'])->where('store_id', $store_id)->find();
+                    $data['price'] = $stockinfo ? SystemStoreProductStock::where('product_id', $data[$k]['id'])->where('store_id', $store_id)->min('price') : $data[$k]['price'];
+                }
                 $data[$k]['activity'] = self::activity($v['id']);
                 $data[$k]['activity'] = self::activity($v['id']);
             }
             }
         }
         }

+ 1 - 1
app/models/store/StoreProductAttr.php

@@ -58,7 +58,7 @@ class StoreProductAttr extends BaseModel
                 if (is_null($value['cart_num'])) $value['cart_num'] = 0;
                 if (is_null($value['cart_num'])) $value['cart_num'] = 0;
             }
             }
             if ($store_id && $type_id == 0) {
             if ($store_id && $type_id == 0) {
-                $stockinfo = SystemStoreProductStock::where('unique', $value['unique'])->find();
+                $stockinfo = SystemStoreProductStock::where('unique', $value['unique'])->where('store_id', $store_id)->find();
                 $value['price'] = $stockinfo ? $stockinfo['price'] : $value['price'];
                 $value['price'] = $stockinfo ? $stockinfo['price'] : $value['price'];
             }
             }
             $values[$value['suk']] = $value;
             $values[$value['suk']] = $value;