shizhongqi před 11 měsíci
rodič
revize
1f0cf2b9ed

+ 1 - 15
app-ghs/controllers/CategoryController.php

@@ -72,27 +72,13 @@ class CategoryController extends BaseController
     public function actionDelete()
     {
         $get = Yii::$app->request->get();
-        $categoryId = isset($get['categoryId']) ? $get['categoryId'] : 0;
+        $categoryId = $get['categoryId'] ?? 0;
         $category = CategoryService::getById($categoryId);
         CategoryService::valid($category, $this->mainId);
         CategoryClass::deleteCategory($categoryId);
         util::complete('删除成功');
     }
 
-    //取分类下商品 ssh 2019.12.2
-    public function actionGoodsList()
-    {
-        $catId = Yii::$app->request->get('catId', '');
-        $where = [];
-        $where['sjId'] = $this->sjId;
-        if (is_numeric($catId)) {
-            $where['cId'] = $catId;
-        }
-        $where['delStatus'] = 0;
-        $data = GoodsCategoryService::getGoodsList($where);
-        util::success($data);
-    }
-
     //分类排序 ssh 2020.3.11
     public function actionSort()
     {

+ 24 - 48
app-hd/controllers/CategoryController.php

@@ -12,6 +12,20 @@ use common\components\util;
 class CategoryController extends BaseController
 {
 
+    public function actionGetMenu()
+    {
+        $mainId = $this->mainId;
+        $classInfo = CategoryClass::getMenuList($mainId);
+        $index = [];
+        if (!empty($classInfo)) {
+            foreach ($classInfo as $class) {
+                $id = $class['id'] ?? 0;
+                $index[$id] = $class;
+            }
+        }
+        util::success(['class' => $classInfo, 'classIndex' => $index]);
+    }
+
     public function actionGetAllCategory()
     {
         $where = ['mainId' => $this->mainId, 'delStatus' => 0];
@@ -23,7 +37,6 @@ class CategoryController extends BaseController
     public function actionList()
     {
         $get = Yii::$app->request->get();
-        //$flower = $get['flower'] ?? '';
         $list = CategoryService::getCategoryList($this->mainId);
         util::success($list);
     }
@@ -80,11 +93,11 @@ class CategoryController extends BaseController
         CategoryService::valid($category, $this->mainId);
 
         if ($category['goodsNum'] > 0) {
-            $goodsCateObjs = GoodsCategoryClass::getAllByCondition(['mainId'=>$this->mainId, 'cId'=>$categoryId]);
+            $goodsCateObjs = GoodsCategoryClass::getAllByCondition(['mainId' => $this->mainId, 'cId' => $categoryId]);
 
             //检查是否有默认分类,没有默认分类创建一个
-            $defaultCategory = CategoryClass::getByCondition(['mainId'=>$this->mainId, 'default'=>1]);
-            if ($defaultCategory == null){
+            $defaultCategory = CategoryClass::getByCondition(['mainId' => $this->mainId, 'default' => 1]);
+            if ($defaultCategory == null) {
                 $data = [
                     'mainId' => $this->mainId,
                     'sjId' => $this->sjId,
@@ -96,7 +109,7 @@ class CategoryController extends BaseController
             $defaultCategoryId = $defaultCategory['id'];
             foreach ($goodsCateObjs as $gcObj) {
                 // 先判断商品是否也在其它分类下
-                $goodsOtherCateCount = GoodsCategoryClass::getCount(['mainId'=>$this->mainId, 'gId'=>$gcObj['gId'], 'delStatus'=>0]);
+                $goodsOtherCateCount = GoodsCategoryClass::getCount(['mainId' => $this->mainId, 'gId' => $gcObj['gId'], 'delStatus' => 0]);
                 if ($goodsOtherCateCount == 1) {
                     // 如果商品仅在此分类下,则归到默认分类
                     GoodsCategoryClass::updateById($gcObj['id'], ['cId' => $defaultCategoryId, 'delStatus' => 0]);
@@ -118,46 +131,9 @@ class CategoryController extends BaseController
     public function actionGoodsList()
     {
         $get = Yii::$app->request->get();
-        $catId = $get['catId'] ?? 0;
-        $where = [];
-        $goodsCond = [];
-        $where['mainId'] = $this->mainId;
-        if (!empty($catId)) {
-            $where['cId'] = $catId;
-        }
-        $flower = $get['flower'] ?? '';
-        if (is_numeric($flower)) {
-            $where['flower'] = $flower;
-        }
-        // flowerNum 是针对 xhGoods 表的条件查询
-        $flowerNum = $get['flowerNum'] ?? 0;
-        if ($flowerNum > 0) {
-            $goodsCond['flowerNum'] = $flowerNum;
-        }
-        if (isset($get['lookPrice'])) { // 1:有价格 2:无价格 -- 根据前端的传值
-            $lookPrice = intval($get['lookPrice']);
-            if ($lookPrice == 1) {
-                $goodsCond['priceType'] = 1;
-            }
-            if ($lookPrice == 2) {
-                $goodsCond['priceType'] = 0;
-            }
-        }
-        if (isset($get['lookStock'])) { // 1:有库存 2:无库存 -- 根据前端的传值
-            $lookStock = intval($get['lookStock']);
-            if ($lookStock == 1) {
-                $goodsCond['stock>'] = 0;
-            }
-            if ($lookStock == 2) {
-                $goodsCond['stock'] = 0;
-            }
-        }
-
-        $searchText = $get['searchText'] ?? '';
-        if (!empty($searchText)) {
-            $where['name'] = ['like', $searchText];
-        }
-        $data = GoodsCategoryService::getGoodsList($where, $goodsCond);
+        $shop = $this->shop;
+        $custom = $this->custom;
+        $data = GoodsCategoryClass::getGoodsList($get, $shop, $custom);
         util::success($data);
     }
 
@@ -169,7 +145,7 @@ class CategoryController extends BaseController
 
         //验证商品
         // 提取所有商品ID
-        $categoryIds = array_map(function($item) {
+        $categoryIds = array_map(function ($item) {
             return intval($item['id']);
         }, $items);
 
@@ -177,12 +153,12 @@ class CategoryController extends BaseController
         $goodsInfos = CategoryClass::getByIds($categoryIds);
 
         // 批量验证商品
-        foreach($goodsInfos as $info) {
+        foreach ($goodsInfos as $info) {
             CategoryService::valid($info, $this->mainId);
         }
 
         // 更新商品排序
-        foreach($items as $item) {
+        foreach ($items as $item) {
             $id = intval($item['id']);
             $inTurn = intval($item['inTurn']);
             CategoryClass::updateById($id, ['inTurn' => $inTurn]);

+ 25 - 15
app-hd/controllers/GoodsController.php

@@ -64,7 +64,7 @@ class GoodsController extends BaseController
         if (!$form->validateForm()) {
             return;
         }
-        
+
         //$data = Yii::$app->request->post();
         $data = $form->attributes;
         $data['sjId'] = $this->sjId;
@@ -138,7 +138,7 @@ class GoodsController extends BaseController
         }
         // 需求变动:不再用 flower 做区分
         //if (is_numeric($flower)) {
-            //$where['flower'] = $flower;
+        //$where['flower'] = $flower;
         //}
         if ($hasStock == 1) {
             $where['stock>'] = 0;
@@ -150,17 +150,17 @@ class GoodsController extends BaseController
     public function actionGetGoodsInfoList()
     {
         $get = Yii::$app->request->get();
-        $cId = isset($get['cId']) ? $get['cId'] : 0;
-        $flowerNum = isset($get['flowerNum']) ? $get['flowerNum'] : 0;
-        if(empty($cId)){
+        $cId = $get['cId'] ?? 0;
+        $flowerNum = $get['flowerNum'] ?? 0;
+        if (empty($cId)) {
             util::fail('分类不能为空');
         }
         $where = ['cId' => $cId];
         $params = [];
-        if(!empty($flowerNum)){
+        if (!empty($flowerNum)) {
             $params['flowerNum'] = $flowerNum;
         }
-        $data = GoodsClass::getGoodsData($where,$params);
+        $data = GoodsClass::getGoodsData($where, $params);
         util::success($data);
     }
 
@@ -168,7 +168,11 @@ class GoodsController extends BaseController
     public function actionDetail()
     {
         $id = intval(Yii::$app->request->get('id'));
-        $goods = GoodsClass::getGoodsInfo($id);
+        $shop = $this->shop;
+        $custom = $this->custom;
+        //只取原价
+        $params = ['getOriginalPrice' => 1];
+        $goods = GoodsClass::getGoodsInfo($id, $shop, $custom, $params);
         GoodsClass::valid($goods, $this->mainId);
         util::success($goods);
     }
@@ -181,11 +185,17 @@ class GoodsController extends BaseController
         if (!$form->validateForm()) {
             return;
         }
-        
+
         $data = $form->attributes;
         $id = $data['id'];
         $info = GoodsClass::getById($id);
-        GoodsService::valid($info, $this->mainId);
+        if (empty($info)) {
+            util::fail('没有找到商品');
+        }
+        if ($info['mainId'] != $this->mainId) {
+            util::fail('不是你的商品');
+        }
+
         $data['sjId'] = $this->sjId;
         $data['mainId'] = $this->mainId;
         $data['shopId'] = $this->shopId ?? 0;
@@ -219,21 +229,21 @@ class GoodsController extends BaseController
 
         //验证商品
         // 提取所有商品ID
-        $categoryIds = array_map(function($item) {
+        $categoryIds = array_map(function ($item) {
             return intval($item['id']);
         }, $items);
 
         // 批量获取商品信息
         $goodsInfos = GoodsClass::getByIds($categoryIds);
         // 批量验证商品
-        foreach($goodsInfos as $info) {
+        foreach ($goodsInfos as $info) {
             GoodsService::valid($info, $this->mainId);
         }
 
         $category = CategoryService::getById($cId);
         CategoryService::valid($category, $this->mainId);
         // 更新商品排序
-        foreach($items as $item) {
+        foreach ($items as $item) {
             $id = intval($item['id']);
             $inTurn = intval($item['inTurn']);
             GoodsCategoryClass::updateByCondition(['cId' => $cId, 'gId' => $id], ['inTurn' => $inTurn]);
@@ -284,7 +294,7 @@ class GoodsController extends BaseController
     public function actionDesc()
     {
         $goodsId = Yii::$app->request->get('id', 0);
-        $picText = PicTextGoodsClass::getByCondition(['mainId'=> $this->mainId, 'goodsId' => $goodsId, 'delStatus' => 0], true);
+        $picText = PicTextGoodsClass::getByCondition(['mainId' => $this->mainId, 'goodsId' => $goodsId, 'delStatus' => 0], true);
         if (empty($picText)) {
             // 适配前端的返回处理 -- 本来要使用 util::fail()
             util::success('not_exist');
@@ -356,7 +366,7 @@ class GoodsController extends BaseController
         if (!$form->validateForm()) {
             return;
         }
-        
+
         $post = $form->attributes;
         $festIdList = isset($post['festIdList']) && !empty($post['festIdList']) ? $post['festIdList'] : [];
         unset($post['festIdList']);

+ 0 - 28
app-hd/controllers/KindController.php

@@ -121,34 +121,6 @@ class KindController extends BaseController
         util::complete('删除成功');
     }
 
-    //取品类下商品 ssh 20220406
-    public function actionGoodsList()
-    {
-        $get = Yii::$app->request->get();
-        $catId = $get['catId'] ?? 0;
-        if (empty($catId)) {
-            util::fail('没有品类');
-        }
-        $where = [];
-        $where['mainId'] = $this->mainId;
-        $where['cId'] = $catId;
-        $flower = $get['flower'] ?? '';
-        if (is_numeric($flower)) {
-            $where['flower'] = $flower;
-        }
-        $where['delStatus'] = $get['delStatus'] ?? 0;
-        $status = $get['status'] ?? '';
-        if (is_numeric($status)) {
-            $where['status'] = $status;
-        }
-        $flowerNum = $get['flowerNum'] ?? 0;
-        if (!empty($flowerNum)) {
-            $where['flowerNum'] = $flowerNum;
-        }
-        $data = GoodsCategoryService::getGoodsList($where);
-        util::success($data);
-    }
-
     //品类排序 ssh 2020.3.11
     public function actionSort()
     {

+ 49 - 13
app-hd/controllers/OrderController.php

@@ -472,6 +472,7 @@ class OrderController extends BaseController
         $post['sjId'] = $this->sjId;
         $post['shopId'] = $this->shopId;
         $post['mainId'] = $this->mainId ?? 0;
+        $shop = $this->shop;
         $now = time();
         $orderValidTime = getenv('ORDER_VALID_TIME') == false ? 600 : getenv('ORDER_VALID_TIME');
         $expireTime = $now + $orderValidTime;
@@ -597,29 +598,64 @@ class OrderController extends BaseController
             if ($version == 2) {
                 $dealPrice = $post['dealPrice'] ?? 0;
                 if ($dealPrice == 0) {
-                    $ids = array_unique(array_filter(array_column($productList, 'productId')));
-                    $itemInfo = ProductClass::getByIds($ids, null, 'id');
-                    if (empty($itemInfo)) {
-                        util::fail('要选择花材哦');
+                    $productIds = [];
+                    $hsIds = [];
+                    foreach ($productList as $pv) {
+                        $property = $pv['property'] ?? 0;
+                        $puId = $pv['productId'] ?? 0;
+                        if ($property == 0) {
+                            $hsIds[] = $puId;
+                        } else {
+                            $productIds[] = $puId;
+                        }
+                    }
+                    $itemInfo = [];
+                    if (!empty($productIds)) {
+                        $itemInfo = ProductClass::getByIds($productIds, null, 'id');
+                    }
+                    $hsInfo = [];
+                    if (!empty($hsIds)) {
+                        $hsInfo = GoodsClass::getByIds($hsIds, null, 'id');
                     }
                     $diff = [];
                     $priceMap = \bizGhs\custom\classes\CustomClass::$levelPriceKeyMap;
                     $addPriceMap = \bizGhs\custom\classes\CustomClass::$levelAddPriceKeyMap;
                     $level = 0;
                     foreach ($productList as $currentProduct) {
+                        $property = $currentProduct['property'] ?? 0;
                         $currentPrice = $currentProduct['unitPrice'] ?? 0;
                         $currentId = $currentProduct['productId'] ?? 0;
-                        $systemInfo = $itemInfo[$currentId] ?? [];
-                        $name = $systemInfo['name'] ?? '';
-                        $systemPrice = \bizGhs\product\classes\ProductClass::getFinalPrice($systemInfo, $level, $priceMap, $addPriceMap);
-                        if (floatval($currentPrice) != floatval($systemPrice)) {
-                            $diff[] = [
-                                'name' => $name,
-                                'price' => $systemPrice,
-                                'kdPrice' => $currentPrice,
-                            ];
+                        if ($property == 1) {
+                            $systemInfo = $itemInfo[$currentId] ?? [];
+                            if (!empty($systemInfo)) {
+                                $name = $systemInfo['name'] ?? '';
+                                $systemPrice = \bizGhs\product\classes\ProductClass::getFinalPrice($systemInfo, $level, $priceMap, $addPriceMap);
+                                if (floatval($currentPrice) != floatval($systemPrice)) {
+                                    $diff[] = [
+                                        'name' => $name,
+                                        'price' => $systemPrice,
+                                        'kdPrice' => $currentPrice,
+                                    ];
+                                }
+                            }
+                        } else {
+                            $systemInfo = $hsInfo[$currentId] ?? [];
+                            if (!empty($systemInfo)) {
+                                $params = [];
+                                $name = $systemInfo['name'] ?? '';
+                                $hsData = GoodsClass::getFinalPrice($systemInfo, $shop, $custom, $params);
+                                $systemPrice = $hsData['price'] ?? 0;
+                                if (floatval($currentPrice) != floatval($systemPrice)) {
+                                    $diff[] = [
+                                        'name' => $name,
+                                        'price' => $systemPrice,
+                                        'kdPrice' => $currentPrice,
+                                    ];
+                                }
+                            }
                         }
                     }
+
                     if (!empty($diff)) {
                         util::success(['diff' => $diff, 'respondType' => 'priceError']);
                     }

+ 3 - 23
app-mall/controllers/CategoryController.php

@@ -3,6 +3,7 @@
 namespace mall\controllers;
 
 use bizHd\custom\classes\CustomClass;
+use bizHd\goods\classes\GoodsCategoryClass;
 use bizMall\goods\services\CategoryService;
 use bizMall\goods\services\GoodsCategoryService;
 use Yii;
@@ -51,31 +52,10 @@ class CategoryController extends BaseController
             util::success(['list' => []]);
         }
 
-        $where = [];
-        $goodsCond = [];
         $get = Yii::$app->request->get();
-        $categoryId = isset($get['categoryId']) ? intval($get['categoryId']) : 0;
-        if ($categoryId != 0) {
-            $where['cId'] = $categoryId;
-        }
-        $where['mainId'] = $this->mainId;
-        $where['delStatus'] = 0;//只获取非删除状态
-        $where['status'] = 1;//上下架状态为1(正常)
-
-        $searchText = $get['searchText'] ?? '';
-        if (!empty($searchText)) {
-            $where['name'] = ['like', $searchText];
-        }
-
         $shop = $this->shop;
-        $stockModel = $shop->stockModel ?? 0;
-        if ($stockModel == 1) {
-            //管到支的,查看所有上架并且花材数量设置好的商品
-            //$where['setItemNum'] = 1;
-        }
-        $goodsCond['priceType'] = 1;//限定查询的是有价格商品
-
-        $data = GoodsCategoryService::getGoodsList($where, $goodsCond);
+        $custom = $this->custom;
+        $data = GoodsCategoryClass::getGoodsList($get, $shop, $custom);
         util::success($data);
     }
 

+ 18 - 1
biz-hd/goods/classes/CategoryClass.php

@@ -3,6 +3,7 @@
 namespace bizHd\goods\classes;
 
 use common\components\business;
+use common\components\imgUtil;
 use common\components\stringUtil;
 use common\components\util;
 use Yii;
@@ -15,6 +16,22 @@ class CategoryClass extends BaseClass
 
     //可以使用的分类:花束 花盒 蝴蝶兰 花篮 植物 永生花 散花 充值卡 花艺课 花礼 瓶器
 
+    public static function getMenuList($mainId)
+    {
+        $where = ['mainId' => $mainId, 'delStatus' => 0];
+        $cat = CategoryClass::getAllByCondition($where, 'inTurn DESC', '*');
+        if (empty($cat)) {
+            return $cat;
+        }
+        foreach ($cat as $key => $info) {
+            $img = $info['img'] ?? '';
+            $cat[$key]['img'] = imgUtil::groupImg($img) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
+            $cat[$key]['bigImg'] = imgUtil::groupImg($img) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
+            $cat[$key]['shortImg'] = $img;
+        }
+        return $cat;
+    }
+
     //取出商家所有的分类 ssh 2019.12.7
     public static function getCategoryIds($mainId)
     {
@@ -79,6 +96,6 @@ class CategoryClass extends BaseClass
     //删除分类 ssh 2020.3.3
     public static function deleteCategory($id)
     {
-        return self::updateByCondition(['id' => $id], ['goodsNum'=>0, 'delStatus'=>1]);
+        return self::updateByCondition(['id' => $id], ['goodsNum' => 0, 'delStatus' => 1]);
     }
 }

+ 140 - 31
biz-hd/goods/classes/GoodsCategoryClass.php

@@ -2,42 +2,151 @@
 
 namespace bizHd\goods\classes;
 
+use bizHd\goods\models\GoodsCategory;
 use common\components\business;
+use common\components\util;
 use Yii;
 use bizHd\base\classes\BaseClass;
 
 class GoodsCategoryClass extends BaseClass
 {
 
-	public static $baseFile = '\bizHd\goods\models\GoodsCategory';
-
-	//删除商品的分类
-	public static function delGoodsCategory($mainId, $categoryId, $goodsId)
-	{
-		self::updateByCondition(['mainId'=>$mainId, 'cId'=>$categoryId, 'gId'=>$goodsId], ['delStatus' => 1]);
-	}
-
-	//批量获取多个商品的分类ID ssh 2023
-	public static function getGoodsHasCategoryIdsBatch($goodsIds)
-	{
-		if (empty($goodsIds)) {
-			return [];
-		}
-		
-		// 一次性查询所有商品的分类关系
-		$categoryList = self::getAllByCondition(['gId' => ['in', $goodsIds]], null, 'gId,cId');
-		
-		// 按商品ID分组整理结果
-		$result = [];
-		foreach ($categoryList as $item) {
-			$goodsId = $item['gId'];
-			$categoryId = $item['cId'];
-			if (!isset($result[$goodsId])) {
-				$result[$goodsId] = [];
-			}
-			$result[$goodsId][] = $categoryId;
-		}
-		
-		return $result;
-	}
+    public static $baseFile = '\bizHd\goods\models\GoodsCategory';
+
+    //$params 必须预留字段,为后面做准备
+    public static function getGoodsList($askInfo, $shop, $custom, $params = [])
+    {
+        $requestType = $askInfo['requestType'] ?? '';
+        $page = $askInfo['page'] ?? 1;
+        $pageSize = $askInfo['pageSize'] ?? 20;
+        if (empty($requestType)) {
+            util::fail('没有请求类型');
+        }
+
+        /** GoodsCategory 版块查询 **/
+        $mainId = $shop->mainId;
+        $query = GoodsCategory::find();
+        $query->where(['xhGoodsCategory.mainId' => $mainId]);
+        if (!empty($askInfo['cId']) || !empty($askInfo['categoryId'])) {
+            $cId = $askInfo['cId'] ?? 0;
+            if (empty($cId)) {
+                $cId = $askInfo['categoryId'] ?? 0;
+            }
+            $query->andWhere(['xhGoodsCategory.cId' => $cId]);
+        }
+        if (!empty($askInfo['searchText'])) {
+            $query->andWhere(['like', 'xhGoodsCategory.name', $askInfo['searchText']]);
+        }
+
+        $query->joinWith(['goods' => function ($query) use ($askInfo,$requestType) {
+
+            if ($requestType == 'kd') {
+                //花束开单
+                $query->andWhere(['xhGoods.delStatus' => 0]);
+                $query->andWhere(['>', 'xhGoods.stock', 0]);
+            } elseif ($requestType == 'goodsList') {
+                //花束管理列表
+                $query->andWhere(['xhGoods.delStatus' => 0]);
+
+                $priceStatus = $askInfo['priceStatus'] ?? -1;
+                if ($priceStatus > -1) {
+                    //1 有价格,2 无价格
+                    if ($priceStatus == 1) {
+                        $query->andWhere(['xhGoods.priceType' => 1]);
+                    }
+                    if ($priceStatus == 2) {
+                        $query->andWhere(['xhGoods.priceType' => 0]);
+                    }
+                }
+
+                $stockStatus = $askInfo['stockStatus'] ?? -1;
+                if ($stockStatus > -1) {
+                    //1 有库存,2 无库存
+                    if ($stockStatus == 1) {
+                        $query->andWhere(['>', 'xhGoods.stock', 0]);
+                    }
+                    if ($stockStatus == 2) {
+                        $query->andWhere(['xhGoods.stock' => 0]);
+                    }
+                }
+
+                $flowerNum = $askInfo['flowerNum'] ?? 0;
+                if ($flowerNum > 0) {
+                    $query->andWhere(['xhGoods.flowerNum' => $flowerNum]);
+                }
+            } elseif ($requestType == 'mall') {
+                //花束商城
+                $query->andWhere(['xhGoods.delStatus' => 0]);
+                $query->andWhere(['xhGoods.status' => 1]);
+                $query->andWhere(['xhGoods.priceType' => 1]);
+            } elseif ($requestType == 'album') {
+                //相册
+                $query->andWhere(['xhGoods.delStatus' => 0]);
+                $query->andWhere(['xhGoods.status' => 1]);
+                $query->andWhere(['xhGoods.priceType' => 0]);
+            }
+
+        }]);
+
+
+
+        $query->orderBy(['inTurn' => SORT_DESC]);
+        // 获取总数
+        $total = $query->count();
+        // 分页查询
+        $goodsCategoryInfoList = $query->offset(($page - 1) * $pageSize)
+            ->limit($pageSize)
+            ->all();
+
+        // 整理结果,只要有库存的商品
+        $list = [];
+        foreach ($goodsCategoryInfoList as $info) {
+            if ($info->goods) { // 只要有关联且有库存的商品
+                $list[] = $info->goods->attributes;
+            }
+        }
+
+        $list = GoodsClass::groupGoodsBaseInfo($list, $shop, $custom, $params);
+
+        $totalPage = ceil($total / $pageSize);
+        $moreData = $totalPage > $page ? 1 : 0;//是否还有更多数据
+
+        return [
+            'list' => $list,
+            'total' => $total,
+            'page' => $page,
+            'pageSize' => $pageSize,
+            'moreData' => $moreData
+        ];
+    }
+
+    //删除商品的分类
+    public static function delGoodsCategory($mainId, $categoryId, $goodsId)
+    {
+        self::updateByCondition(['mainId' => $mainId, 'cId' => $categoryId, 'gId' => $goodsId], ['delStatus' => 1]);
+    }
+
+    //批量获取多个商品的分类ID ssh 2023
+    public static function getGoodsHasCategoryIdsBatch($goodsIds)
+    {
+        if (empty($goodsIds)) {
+            return [];
+        }
+
+        // 一次性查询所有商品的分类关系
+        $categoryList = self::getAllByCondition(['gId' => ['in', $goodsIds]], null, 'gId,cId');
+
+        // 按商品ID分组整理结果
+        $result = [];
+        foreach ($categoryList as $item) {
+            $goodsId = $item['gId'];
+            $categoryId = $item['cId'];
+            if (!isset($result[$goodsId])) {
+                $result[$goodsId] = [];
+            }
+            $result[$goodsId][] = $categoryId;
+        }
+
+        return $result;
+    }
 }

+ 73 - 99
biz-hd/goods/classes/GoodsClass.php

@@ -282,43 +282,43 @@ class GoodsClass extends BaseClass
     }
 
     //获取商品完整详情,包括商品的分类 ssh 2019.12.3
-    public static function getGoodsInfo($id)
+    public static function getGoodsInfo($id, $shop, $custom, $params)
     {
         $info = self::getById($id);
         if (empty($info)) {
             return [];
         }
-        $list = self::groupGoodsBaseInfo([$info], true);
-        $info = current($list);
-        return $info;
+        $list = self::groupGoodsBaseInfo([$info], $shop, $custom, $params);
+        return current($list);
     }
 
-    public static function getGoodsData($where,$params){
+    public static function getGoodsData($where, $params)
+    {
         // 获取分页参数
         $page = Yii::$app->request->get('page', 1);
         $pageSize = Yii::$app->request->get('pageSize', 20);
-        
+
         $flowerNum = $params['flowerNum'] ?? 0;
         // 查询某分类下有库存的商品
         $query = GoodsCategory::find()
             ->where($where)
-            ->joinWith(['goods' => function($query) use ($flowerNum) {
+            ->joinWith(['goods' => function ($query) use ($flowerNum) {
                 $query->andWhere(['>', 'xhGoods.stock', 0]);
-                if(isset($flowerNum) && $flowerNum > 0){
-                    $query->andWhere(['xhGoods.flowerNum' => $flowerNum]); 
+                if (isset($flowerNum) && $flowerNum > 0) {
+                    $query->andWhere(['xhGoods.flowerNum' => $flowerNum]);
                 }
             }])
             ->andWhere(['xhGoodsCategory.delStatus' => 0])
             ->orderBy(['inTurn' => SORT_DESC]);
-            
+
         // 获取总数
         $total = $query->count();
-        
+
         // 分页查询
         $goodsList = $query->offset(($page - 1) * $pageSize)
             ->limit($pageSize)
             ->all();
-        
+
         // 整理结果,只要有库存的商品
         $list = [];
         foreach ($goodsList as $goodsCategory) {
@@ -326,7 +326,7 @@ class GoodsClass extends BaseClass
                 $list[] = $goodsCategory->goods->attributes;
             }
         }
-        if(!empty($list)){
+        if (!empty($list)) {
             $list = self::groupGoodsBaseInfo($list);
         }
 
@@ -342,43 +342,64 @@ class GoodsClass extends BaseClass
         ];
     }
 
-    /**
-     * 组装商品基本信息
-     * @param $list  "goods商品数组"
-     * @param bool $getItem 是否获取"成品的花材"
-     * @param array $sortIds 按商品分类的inTurn 进行排序的商品id数组
-     * @return mixed
-     */
-    public static function groupGoodsBaseInfo($list, $getItem = false, $sortIds= [])
+    //$data 可以是一维数组,也可以二维数组
+    //花束的价格全部由这边输出 $custom $params 必须预留,为后面做准备
+    //会返回两个参数 price 价格,涨价后的价格 priceBeforeRise 涨价前的价格,如果price==priceBeforeRise说明没有涨价
+    public static function getFinalPrice($data, $shop, $custom, $params)
+    {
+        if (empty($data)) {
+            return $data;
+        }
+        $mainId = $shop->mainId;
+        $rise = GoodsSettingClass::getRise($mainId);
+        $riseSwitch = $rise['riseSwitch'] ?? 0;
+        $riseType = $rise['riseType'] ?? 0;
+        $riseAmount = $rise['riseAmount'] ?? 0;
+        reset($data);
+        $current = current($data);
+        if (is_array($current)) {
+            foreach ($data as $key => $item) {
+                $item = self::obeyRiseRule($item, $riseSwitch, $riseType, $riseAmount, $custom, $params);
+                $data[$key] = $item;
+            }
+        } else {
+            $data = self::obeyRiseRule($data, $riseSwitch, $riseType, $riseAmount, $custom, $params);
+        }
+        return $data;
+    }
+
+    //遵循涨价规则 ssh 20250828
+    //会返回两个参数 price 价格或涨价后的价格 priceBeforeRise 涨价前的价格,如果price==priceBeforeRise说明没有涨价
+    public static function obeyRiseRule($data, $riseSwitch, $riseType, $riseAmount, $custom, $params)
+    {
+        $price = $data['price'] ?? 0;
+        $priceBeforeRise = $price;
+        //后台修改商品时,取原价,不需要显示涨价金额 getOriginalPrice=1 有涨价也强制取原价
+        $getOriginalPrice = $params['getOriginalPrice'] ?? 0;
+        if ($riseSwitch == 1 && $riseAmount > 0 && $getOriginalPrice == 0) {
+            if ($riseType == 0) {
+                //百分比
+                $add = sprintf("%.1f", ($price * $riseAmount / 100));
+                $price = bcadd($price, $add, 2);
+            } else {
+                //金额
+                $price = bcadd($price, $riseAmount, 2);
+            }
+        }
+        $data['price'] = $price;
+        $data['priceBeforeRise'] = $priceBeforeRise;
+        return $data;
+    }
+
+    public static function groupGoodsBaseInfo($list, $shop, $custom, $params)
     {
         if (empty($list)) {
             return [];
         }
-        $arrNotEmpty = is_array($sortIds) && !empty($sortIds);
-        
-        //注意这里涉及商家节日涨价的问题,不要去取不同商家的商品,确有必要另外起方法!!!!!!!!!!
-        $currentData = current($list);
-        $mainId = intval($currentData['mainId']);
-        if ($mainId <= 0) {
-            util::fail('mainId 出错');
-        }
-        $rise = GoodsSettingClass::getRise($mainId);
-        $sjHasCategory = CategoryClass::getCategory($mainId);
-        
         // 收集所有商品ID
         $goodsIds = array_column($list, 'id');
         // 一次性获取所有商品的分类关系
         $allGoodsCategories = GoodsCategoryClass::getGoodsHasCategoryIdsBatch($goodsIds);
-
-        $groupedItems = [];
-        if ($getItem && !empty($goodsIds)) {
-            $itemList = GoodsItemClass::getAllByCondition(['goodsId' => ['in', $goodsIds]]);
-            // 手动按 goodsId 分组
-            foreach ($itemList as $item) {
-                $groupedItems[$item['goodsId']][] = $item;
-            }
-        }
-        
         foreach ($list as $key => &$val) {
             $id = $val['id'];
             //大中小图片转化
@@ -386,66 +407,21 @@ class GoodsClass extends BaseClass
             //免费配送范围
             $val['freeSendDist'] = 5;
             $val['createDate'] = isset($val['createTime']) ? date("Y-m-d", strtotime($val['createTime'])) : '';
-            //节日涨价
-            if (!empty($rise)) {
-                $price = $val['price'];
-                if ($rise['riseType'] == 0) {
-                    //百分比
-                    $val['price'] = $price + sprintf("%.1f", ($price * $rise['riseAmount'] / 100));
-                } else {
-                    //金额
-                    $val['price'] = $price + $rise['riseAmount'];
-                }
-            }
             //商品的分类
             $categoryIds = $allGoodsCategories[$id] ?? [];
             $val['categoryIdList'] = $categoryIds;
-            $belongCategory = [];
-            if (!empty($categoryIds)) {
-                foreach ($categoryIds as $currentId) {
-                    $belongCategory[] = $sjHasCategory[$currentId]['categoryName'] ?? '';
-                }
-            }
-            $val['belongCategory'] = $belongCategory;
-
             $shortCover = $val['cover'] ?? '';
             $val['shortCover'] = $shortCover;
-            $val['cover'] = imgUtil::groupImg($shortCover);
-            $val['smallCover'] = $val['cover'] . "?x-oss-process=image/resize,m_fill,h_130,w_130";
-            $val['bigCover'] = $val['cover'] . "?x-oss-process=image/resize,m_fill,h_700,w_700";
-
-            if ($getItem) {
-                $currentItems = isset($groupedItems[$id]) ? $groupedItems[$id] : [];
-                foreach ($currentItems as &$itemVal) {
-                    $shortCover = $itemVal['cover'] ?? '';
-                    $itemVal['shortCover'] = $shortCover;
-                    $itemVal['smallCover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
-                    $itemVal['bigCover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
-                }
-                $val['goodsItem'] = $currentItems;
-            }
+            $val['cover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
+            $val['smallCover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
+            $val['bigCover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
             //前端使用字段
             $val['bigCount'] = 0;
-            if ($arrNotEmpty) {
-                $sortIndex = array_search($id, $sortIds);
-                // $newList[$sortIndex] = $val;
-                $val['sortWeight'] = $sortIndex !== false ? $sortIndex : count($sortIds);
-            }
         }
-        unset($val); // 销毁引用
-
-        if ($arrNotEmpty) {
-            usort($list, function($a, $b) {
-                return $a['sortWeight'] - $b['sortWeight'];
-            });
-            //return $newList;
-            // return array_values($newList);
-        }
-
-        return $list;
+        //获取最终需要的价格
+        return self::getFinalPrice($list, $shop, $custom, $params);
     }
 
-
     //新建商品 ssh 20220404
     public static function addGoods($data, $work = null)
     {
@@ -587,7 +563,7 @@ class GoodsClass extends BaseClass
         $id = $goods['id'] ?? 0;
         $preSetItemNum = $goods['setItemNum'] ?? 0;
 
-        $categoryIdList = isset($data['categoryIdList']) && !empty($data['categoryIdList']) ? $data['categoryIdList'] : [];
+        $categoryIdList = !empty($data['categoryIdList']) ? $data['categoryIdList'] : [];
         unset($data['categoryIdList']);
         if (empty($categoryIdList)) {
             util::fail('没有选择分类');
@@ -608,7 +584,7 @@ class GoodsClass extends BaseClass
         }
         //精确处理分类变更:分别处理删除、新增、修改三种情况
         $goodsHasCategoryIds = GoodsCategoryService::getGoodsHasCategoryIds($id);
-        
+
         // 1. 找出需要删除的分类:原有分类中不在新分类列表中的
         $toDeleteCategoryIds = array_diff($goodsHasCategoryIds, $categoryIdList);
         if (!empty($toDeleteCategoryIds)) {
@@ -617,7 +593,7 @@ class GoodsClass extends BaseClass
             //\bizHd\goods\models\GoodsCategory::deleteAll(['and', ['gId' => $id], ['in', 'cId', $toDeleteCategoryIds]]); //直接调用 deleteAll 方法
             CategoryClass::counters(['goodsNum' => -1], ['id' => $toDeleteCategoryIds]);
         }
-        
+
         // 2. 找出需要新增的分类:新分类列表中不在原有分类中的
         $toAddCategoryIds = array_diff($categoryIdList, $goodsHasCategoryIds);
         if (!empty($toAddCategoryIds)) {
@@ -633,14 +609,13 @@ class GoodsClass extends BaseClass
                     'sjId' => $sjId,
                     'flower' => $flower,
                     'mainId' => $mainId,
-                    'status' => $status,
                     'setItemNum' => $setItemNum,
                 ];
             }
             GoodsCategoryClass::batchAdd($addCategory);
             CategoryClass::counters(['goodsNum' => 1], ['id' => $toAddCategoryIds]);
         }
-        
+
         // 3. 处理需要修改的分类:既在原有分类中也在新分类列表中的
         $toUpdateCategoryIds = array_intersect($goodsHasCategoryIds, $categoryIdList);
         if (!empty($toUpdateCategoryIds)) {
@@ -650,13 +625,12 @@ class GoodsClass extends BaseClass
                     'name' => $name,
                     'py' => $py,
                     'cName' => $cName,
-                    'status' => $status,
                     'setItemNum' => $setItemNum,
                 ];
                 GoodsCategoryClass::updateByCondition(['gId' => $id, 'cId' => $categoryId], $updateData);
             }
         }
-        
+
         // 字符串的,即认为是 图片URL
         if (isset($data['cover']) && is_string($data['cover'])) {
 

+ 9 - 26
biz-hd/goods/classes/GoodsSettingClass.php

@@ -12,35 +12,18 @@ class GoodsSettingClass extends BaseClass
 
     public static $baseFile = '\bizHd\goods\models\GoodsSetting';
 
-    //获取商品涨价比例或金额 ssh 2020.5.20
+    // $riseSwitch == 1 && $riseAmount > 0 表示有涨价,其他情况表示没有
     public static function getRise($mainId)
     {
-        $festRise = FestRiseClass::getAllByCondition(['mainId' => $mainId], null, 'festId', 'festId');
-        if (empty($festRise)) {
-            return [];
+        $set = self::getByCondition(['mainId' => $mainId], true);
+        $riseSwitch = $set->riseSwitch ?? 0;
+        $riseType = 0;
+        $riseAmount = 0;
+        if ($riseSwitch == 1) {
+            $riseType = $set->riseType ?? 0;
+            $riseAmount = $set->riseAmount ?? 0;
         }
-        $festId = array_keys($festRise);
-        $fest = FestClass::getByIds($festId);
-        $today = date("Y-n-j");
-        $arr = [];
-        foreach ($fest as $single) {
-            $current = date("Y") . '-' . $single['month'] . '-' . $single['day'];
-            $past = date("Y-n-j", (strtotime($current) - 86400));
-            $arr = array_merge($arr, [$current, $past]);
-        }
-        if (in_array($today, $arr) == false) {
-            return [];
-        }
-        $set = self::getByCondition(['mainId' => $mainId]);
-        if (empty($set)) {
-            util::fail('没有找到涨价需求');
-        }
-        if ($set['riseSwitch'] == 0) {
-            return [];
-        }
-        $riseType = $set['riseType'];
-        $riseAmount = $set['riseAmount'];
-        return ['riseType' => $riseType, 'riseAmount' => $riseAmount];
+        return ['riseType' => $riseType, 'riseAmount' => $riseAmount, 'riseSwitch' => $riseSwitch];
     }
 
 }

+ 0 - 4
biz-hd/goods/services/CategoryService.php

@@ -16,10 +16,6 @@ class CategoryService extends BaseService
     public static function getCategoryList($mainId)
     {
         $where = ['mainId' => $mainId, 'delStatus' => 0];
-        // 需求变动:不再用 flower 做区分
-        //if (is_numeric($flower)) {
-            //$where['flower'] = $flower;
-        //}
         $cat = CategoryClass::getAllByCondition($where, 'inTurn DESC', '*');
         if (empty($cat)) {
             return $cat;

+ 0 - 25
biz-hd/goods/services/GoodsCategoryService.php

@@ -10,31 +10,6 @@ class GoodsCategoryService extends BaseService
 {
     public static $baseFile = '\bizHd\goods\classes\GoodsCategoryClass';
 
-    /**
-     * 查询一个分类下的商品,有分页
-     * @param array $where 分类的查询条件
-     * @param array $goodsCondition 商品的查询条件
-     * @return mixed
-     */
-    public static function getGoodsList($where, $goodsCondition = [])
-    {
-        $where['delStatus'] = 0; // 排除已删除
-        $data = GoodsCategoryClass::getList('*', $where, 'inTurn DESC');
-        $list = isset($data['list']) ? $data['list'] : [];
-        if (empty($list)) {
-            return $data;
-        }
-
-        $ids = array_column($list, 'gId');
-        $goodsWhere = ['id' => ['in', $ids]];
-        if (count($goodsCondition) > 0) {
-            $goodsWhere = array_merge($goodsWhere, $goodsCondition);
-        }
-        $goodsList = GoodsClass::getAllByCondition($goodsWhere, null, '*');
-        $data['list'] = GoodsClass::groupGoodsBaseInfo($goodsList, false, $ids);
-        return $data;
-    }
-
     //获取商品所属的分类id  ssh 201917
     public static function getGoodsHasCategoryIds($goodsId)
     {

+ 2 - 1
biz/shop/classes/ShopClass.php

@@ -247,7 +247,8 @@ class ShopClass extends BaseClass
         Yii::info('收款码url:' . $url);
         $gatheringCode = qrCodeUtil::generateGatheringQrCode($url, $sjId, $shopId, '', 16);
         Yii::info('gatheringCode:' . $gatheringCode);
-        $imgUrl = Yii::$app->params['hdImgHost'] . 'gathering/1.jpg?x-oss-process=image/watermark,image_' . base64_encode($gatheringCode) . ',g_nw,x_276,y_463/watermark,image_' . base64_encode('gathering/logo_big.png?x-oss-process=image/resize,P_12') . ',g_nw,x_555,y_728';
+        //$imgUrl = Yii::$app->params['hdImgHost'] . 'gathering/1.jpg?x-oss-process=image/watermark,image_' . base64_encode($gatheringCode) . ',g_nw,x_276,y_463/watermark,image_' . base64_encode('gathering/logo_big.png?x-oss-process=image/resize,P_12') . ',g_nw,x_555,y_728';
+        $imgUrl = Yii::$app->params['hdImgHost'] . 'gathering/1.jpg?x-oss-process=image/watermark,image_' . base64_encode($gatheringCode) . ',g_nw,x_276,y_463';
         return $imgUrl;
     }