Răsfoiți Sursa

价格管理

shish 11 luni în urmă
părinte
comite
79cd0c483c

+ 1 - 1
app-hd/controllers/ChatController.php

@@ -192,7 +192,7 @@ class ChatController extends BaseController
         $userId = $keyArr[1] ?? 0;
 
         // 无价格报价,多处相关,请搜索关键词 shopId-userId-goodsId
-        $currentKey = 'report_price' . $shopId . '_' . $userId . '_' . $goodsId;
+        $currentKey = 'report_price:' . $shopId . '_' . $userId . '_' . $goodsId;
         $val = Yii::$app->redis->executeCommand('GET', [$currentKey]);
         if (!empty($saveAuthCode)) { // 修改报价
             Yii::info('修改报价:' . $currentKey . ' -- 旧价:' . $val . ', 新价:' . $price);

+ 1 - 9
app-mall/controllers/GoodsController.php

@@ -22,17 +22,9 @@ class GoodsController extends BaseController
         $info = GoodsClass::getGoodsInfo($id);
         GoodsService::valid($info, $this->mainId);
         $setting = GoodsSettingClass::getByCondition(['mainId' => $this->mainId]);
-        $intro = isset($setting['goodsIntroduce']) ? $setting['goodsIntroduce'] : '';
+        $intro = $setting['goodsIntroduce'] ?? '';
         $info['commonIntro'] = $intro;
 
-        // 查询报价,多处同步修改,搜索关键词 shopId-userId-goodsId
-        $key = 'report_price' . $this->shopId . '_' . $this->userId . '_' . $id;
-        $val = Yii::$app->redis->executeCommand('GET', [$key]);
-        if (floatval($val) > 0) {
-            $info['price'] = floatval($val);
-            $info['priceType'] = 2;
-        }
-
         $pixTextGoods = PicTextGoodsClass::getByCondition(['mainId' => $this->mainId, 'goodsId' => $id], true);
         $info['picTextGoods'] = $pixTextGoods;
 

+ 6 - 8
app-mall/controllers/OrderController.php

@@ -411,13 +411,6 @@ class OrderController extends BaseController
         if ($stock <= 0) {
             util::fail('库存不足');
         }
-        // 从redis查询报价 shopId-userId-goodsId
-        $key = 'report_price' . $this->shopId . '_' . $this->userId . '_' . $goodsId;
-        $val = Yii::$app->redis->executeCommand('GET', [$key]);
-        if (floatval($val) > 0) {
-            $goodsInfo->price = $val;
-            $goodsInfo->priceType = 2;
-        }
 
         //事务处理
         $connection = Yii::$app->db;
@@ -447,10 +440,15 @@ class OrderController extends BaseController
             $params = [];
             $goodsData = $goodsInfo->attributes;
             $ret = \bizHd\goods\classes\GoodsClass::getFinalPrice($goodsData, $shop, $custom, $params);
+            $priceType = $ret['priceType'] ?? 0;
+            if ($priceType == 0) {
+                util::fail('没有价格,不能下单哈');
+            }
             $unitPrice = $ret['price'] ?? 0;
             if ($unitPrice <= 0) {
-                util::fail('没有价格,不能下单哈');
+                util::fail('没有价格,不能下单');
             }
+
             //计算总金额
             $goodsPrice = $unitPrice * $goodsNum;
 

+ 40 - 4
biz-hd/goods/classes/GoodsClass.php

@@ -352,6 +352,8 @@ class GoodsClass extends BaseClass
             return $data;
         }
         $mainId = $shop->mainId;
+        $shopId = $shop->id;
+        $userId = $custom['userId'] ?? 0;
         $rise = GoodsSettingClass::getRise($mainId);
         $riseSwitch = $rise['riseSwitch'] ?? 0;
         $riseType = $rise['riseType'] ?? 0;
@@ -359,12 +361,46 @@ class GoodsClass extends BaseClass
         reset($data);
         $current = current($data);
         if (is_array($current)) {
+            /** 处理多个商品 **/
             foreach ($data as $key => $item) {
-                $item = self::obeyRiseRule($item, $riseSwitch, $riseType, $riseAmount, $custom, $params);
+                // 从redis获取报价,关键词 shopId-userId-goodsId
+                $goodsId = $item['id'] ?? 0;
+                $key = 'report_price' . $shopId . '_' . $userId . '_' . $goodsId;
+                $reportPrice = Yii::$app->redis->executeCommand('GET', [$key]);
+                if (floatval($reportPrice) > 0) {
+                    //只要报价,不管是有无价格类型,就从报价里取,不参与涨价
+                    $item['price'] = $reportPrice;
+                    //无价类型变成有价类型
+                    $item['priceType'] = 1;
+                } else {
+                    if (isset($item['priceType']) && $item['priceType'] == 0) {
+                        //没有报价,无价格商品不参与涨价
+                    } else {
+                        //没有报价,有价格商品参与涨价
+                        $item = self::obeyRiseRule($item, $riseSwitch, $riseType, $riseAmount, $custom, $params);
+                    }
+                }
                 $data[$key] = $item;
             }
         } else {
-            $data = self::obeyRiseRule($data, $riseSwitch, $riseType, $riseAmount, $custom, $params);
+            /** 处理单个商品 **/
+            // 从redis获取报价,关键词 shopId-userId-goodsId
+            $goodsId = $data['id'] ?? 0;
+            $key = 'report_price' . $shopId . '_' . $userId . '_' . $goodsId;
+            $reportPrice = Yii::$app->redis->executeCommand('GET', [$key]);
+            if (floatval($reportPrice) > 0) {
+                //只要报价,不管是有无价格类型,就从报价里取,不参与涨价
+                $data['price'] = $reportPrice;
+                //无价类型变成有价类型
+                $data['priceType'] = 1;
+            } else {
+                if (isset($data['priceType']) && $data['priceType'] == 0) {
+                    //没有报价,无价商品不参与涨价
+                } else {
+                    //没有报价,有价商品参与涨价
+                    $data = self::obeyRiseRule($data, $riseSwitch, $riseType, $riseAmount, $custom, $params);
+                }
+            }
         }
         return $data;
     }
@@ -808,8 +844,8 @@ class GoodsClass extends BaseClass
             util::fail("非法参数");
         }
         //改库存
-        $preStock = $goodsData['stock']??0;
-        $newStock = bcsub($preStock,$num);
+        $preStock = $goodsData['stock'] ?? 0;
+        $newStock = bcsub($preStock, $num);
 
         if ($newStock < 0) {
             if ($checkStock) {

+ 3 - 16
biz-mall/goods/classes/GoodsClass.php

@@ -43,11 +43,6 @@ class GoodsClass extends BaseClass
         }
         $arrNotEmpty = is_array($sortIds) && !empty($sortIds);
 
-        //注意这里涉及商家节日涨价的问题,不要去取不同商家的商品,确有必要另外起方法!!!!!!
-        $currentData = current($list);
-        $mainId = $currentData['mainId'];
-        $rise = GoodsSettingClass::getRise($mainId);
-
         foreach ($list as $key => $val) {
             $id = $val['id'];
             //大中小图片转化
@@ -57,17 +52,9 @@ class GoodsClass extends BaseClass
             //多款式
             $val['goodsStyleList'] = [];
             $val['createDate'] = 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'];
-                }
-            }
+
+
+
             $shortCover = $val['cover'] ?? '';
             $val['cover'] = imgUtil::groupImg($shortCover);
             $val['shortCover'] = $shortCover;

+ 4 - 4
biz-mall/goods/services/GoodsCategoryService.php

@@ -58,7 +58,7 @@ class GoodsCategoryService extends BaseService
         if (empty($list)) {
             foreach ($category as $key => $val) {
                 $category[$key]['goodsInfoList'] = [];
-                $category[$key]['showRow'] = isset($showRowNum[$key]) ? $showRowNum[$key] : 2;
+                $category[$key]['showRow'] = $showRowNum[$key] ?? 2;
             }
             return $category;
         }
@@ -76,10 +76,10 @@ class GoodsCategoryService extends BaseService
         foreach ($category as $key => $val) {
             $id = $val['id'];
             //当前分类下有哪些商品id,并组合商品信息
-            $categoryGoodsIdList = isset($categoryGoods[$id]) ? $categoryGoods[$id] : [];
+            $categoryGoodsIdList = $categoryGoods[$id] ?? [];
             $info = [];
             if (!empty($categoryGoodsIdList)) {
-                $currentGetNum = isset($getNum[$key]) ? $getNum[$key] : 2;
+                $currentGetNum = $getNum[$key] ?? 2;
                 $categoryGoodsIdList = array_slice($categoryGoodsIdList, 0, $currentGetNum);
                 foreach ($categoryGoodsIdList as $currentGoodsId) {
                     if (isset($goodsInfoList[$currentGoodsId])) {
@@ -88,7 +88,7 @@ class GoodsCategoryService extends BaseService
                 }
             }
             $category[$key]['goodsInfoList'] = $info;
-            $category[$key]['showRow'] = isset($showRowNum[$key]) ? $showRowNum[$key] : 2;
+            $category[$key]['showRow'] = $showRowNum[$key] ?? 2;
         }
         return $category;
     }