Sfoglia il codice sorgente

Merge branch 'dev' of http://git.huaml.com/zhh/huahuibao into dev

shish 1 mese fa
parent
commit
28d452c681

+ 18 - 1
app-ghs/controllers/OrderController.php

@@ -1426,12 +1426,27 @@ class OrderController extends BaseController
         $addPriceMap['risePercent'] = $custom['risePercent'] ?? 0;
 
         $level = $custom['level'] ?? 1;
+        $skipLimitBuy = !empty($shop->skCustomId) && intval($shop->skCustomId) == intval($customId);
+        $limitBuyCheckList = [];
+        foreach ($productList as $currentProduct) {
+            $limitBuyCheckList[] = [
+                'id' => $currentProduct['productId'] ?? 0,
+                'bigCount' => $currentProduct['bigNum'] ?? 0,
+                'smallCount' => $currentProduct['smallNum'] ?? 0,
+            ];
+        }
+        $limitBuyInfoList = ProductClass::getLimitBuyInfoByList($limitBuyCheckList, $customId);
+        $limitBuyInfoMap = array_column($limitBuyInfoList, null, 'id');
         foreach ($productList as $ptKey => $currentProduct) {
             $currentPrice = $currentProduct['price'] ?? 0;
             $currentId = $currentProduct['productId'] ?? 0;
             $systemInfo = $itemInfo[$currentId] ?? [];
             $name = $systemInfo['name'] ?? '';
-            $systemPrice = ProductClass::getFinalPrice($systemInfo, $level, $priceMap, $addPriceMap);
+            $limitBuyInfo = $limitBuyInfoMap[$currentId] ?? [];
+            $buyNum = $skipLimitBuy ? 0 : ($limitBuyInfo['currentBuyNum'] ?? 0);
+            $hasBuyNum = $skipLimitBuy ? 0 : ($limitBuyInfo['hasBuyNum'] ?? 0);
+            $totalBuyNum = $skipLimitBuy ? 0 : bcadd($hasBuyNum, $buyNum, 2);
+            $systemPrice = ProductClass::getFinalPrice($systemInfo, $level, $priceMap, $addPriceMap, 0, $buyNum, $totalBuyNum);
 
             if (getenv('YII_ENV') == 'production') {
                 //苏州小蔡鲜花,几个出车,不能低于原价卖,但可以高于原价卖的
@@ -1538,6 +1553,7 @@ class OrderController extends BaseController
             try {
                 $return = OrderService::createNewOrder($post, $custom, $hasPay);
                 $transaction->commit();
+                ProductClass::clearLimitBuyRollbackSnapshot();
             } catch (\Exception $exception) {
                 if ($transaction->isActive) {
                     $transaction->rollBack();
@@ -1604,6 +1620,7 @@ class OrderController extends BaseController
             }
             util::success($return);
         } catch (\Exception $e) {
+            ProductClass::rollbackLimitBuySnapshot();
             Yii::error("下单失败原因:" . $e->getMessage());
             noticeUtil::push("批发线下开单失败,原因:" . $e->getMessage(), '15280215347');
             if (util::isDbConcurrencyException($e)) {

+ 26 - 1
app-ghs/controllers/PurchaseController.php

@@ -3,8 +3,10 @@
 namespace ghs\controllers;
 
 use biz\ghs\classes\GhsClass;
+use bizGhs\custom\classes\CustomClass;
 use bizGhs\order\classes\PurchaseOrderClass;
 use bizGhs\order\services\PurchaseOrderService;
+use bizGhs\product\classes\ProductClass;
 use bizHd\purchase\classes\PurchaseClass;
 use common\components\dateUtil;
 use common\components\util;
@@ -41,6 +43,29 @@ class PurchaseController extends BaseController
         util::success(['salt' => $salt]);
     }
 
+    // 批发商开单限购花材信息
+    public function actionLimitBuyInfo()
+    {
+        $post = Yii::$app->request->post();
+        $customId = $post['customId'] ?? 0;
+        $list = $post['list'] ?? [];
+        if (empty($customId)) {
+            util::fail('缺少客户');
+        }
+        if (empty($list) || !is_array($list)) {
+            util::fail('请选择花材');
+        }
+
+        $custom = CustomClass::getCustom($customId);
+        if (empty($custom)) {
+            util::fail('没有找到客户');
+        }
+        CustomClass::valid($custom, $this->shopId);
+
+        $respond = ProductClass::getLimitBuyInfoByList($list, $customId);
+        util::success($respond);
+    }
+
     //待结款明细 ssh 2021.1.26
     public function actionDebtList()
     {
@@ -113,4 +138,4 @@ class PurchaseController extends BaseController
         util::complete('确认成功');
     }
 
-}
+}

+ 9 - 1
biz-ghs/order/classes/OrderItemClass.php

@@ -7,6 +7,7 @@ use bizGhs\book\classes\BookItemClass;
 use bizGhs\custom\classes\CustomClass;
 use bizGhs\ghs\classes\GhsClass;
 use bizGhs\product\classes\ProductClass;
+use bizGhs\shop\classes\ShopClass;
 use bizGhs\stock\classes\StockRecordClass;
 use bizHd\purchase\classes\PurchaseClass;
 use bizHd\purchase\classes\PurchaseItemClass;
@@ -335,6 +336,13 @@ class OrderItemClass extends BaseClass
 
         $level = $custom->level ?? 0;
         $live = isset($custom->live) ? $custom->live : 1;
+        $shopId = $post['shopId'] ?? 0;
+        $skipLimitBuy = false;
+        if (!empty($shopId)) {
+            $shop = ShopClass::getById($shopId, true, 'id, skCustomId');
+            $skipLimitBuy = !empty($shop->skCustomId) && intval($shop->skCustomId) == $customId;
+        }
+        $moreParams['skipLimitBuy'] = $skipLimitBuy;
         $respond = ProductClass::formatProductInfo($products, $level, $live, $moreParams);
         $products = $respond['product'];
         $weight = 0;
@@ -450,7 +458,7 @@ class OrderItemClass extends BaseClass
             $weight = bcadd($w, $weight, 2);
 
             $limitBuy = $p['limitBuy'];
-            if ($limitBuy > 0) {
+            if ($limitBuy > 0 && $skipLimitBuy == false) {
                 ProductClass::handleLimitBuy($p, $customId, floatval($itemNum));
             }
 

+ 10 - 4
biz-ghs/product/classes/ProductClass.php

@@ -366,6 +366,7 @@ class ProductClass extends BaseClass
             $list[$k]['smallNum'] = $stockInfo['smallNum'];
 
             $price = self::getFinalPrice($v, $level, $priceMap, $addPriceMap);
+            $list[$k]['originPrice'] = $list[$k]['price']; //原始价
             $list[$k]['price'] = $price;
             $list[$k]['bigPrice'] = $price;
             $smallRatio = $v['smallRatio'] ?? 0;
@@ -1465,6 +1466,7 @@ class ProductClass extends BaseClass
         $book = $moreParams['book'] ?? 0;
         $customShopAdminId = $moreParams['customShopAdminId'] ?? 0;
         $custom = $moreParams['custom'] ?? [];
+        $skipLimitBuy = $moreParams['skipLimitBuy'] ?? false;
         //不同等级对应 price addPrice
         $priceMap = CustomClass::$levelPriceKeyMap;
         //这个参数应该是要作废的,但下面加的参数是有用的,多处要同步修改,关键词 abandon_add_price_map ,ssh 20260116
@@ -1503,12 +1505,16 @@ class ProductClass extends BaseClass
                 if ($book == 1 && $customShopAdminId > 0) {
                     $itemPrice = 0.1;
                 } else {
-                    $limitKey = self::LIMIT_BUY_KEY . $ghsProductId;
-                    $hasBuyNum = Yii::$app->redis->executeCommand('HGET', [$limitKey, $custom['id']]);
-                    $hasBuyNum = $itemNum + ($hasBuyNum == null ? 0 : $hasBuyNum); // 已购买总数量
+                    $priceBuyNum = $skipLimitBuy ? 0 : $itemNum;
+                    $totalBuyNum = 0;
+                    if ($skipLimitBuy == false) {
+                        $limitKey = self::LIMIT_BUY_KEY . $ghsProductId;
+                        $hasBuyNum = Yii::$app->redis->executeCommand('HGET', [$limitKey, $custom['id']]);
+                        $totalBuyNum = $itemNum + ($hasBuyNum == null ? 0 : $hasBuyNum); // 已购买总数量
+                    }
 
                     //今日特价、会员价
-                    $itemPrice = self::getFinalPrice($currentGhsProduct, $level, $priceMap, $addPriceMap, $changePrice, $itemNum, $hasBuyNum);
+                    $itemPrice = self::getFinalPrice($currentGhsProduct, $level, $priceMap, $addPriceMap, $changePrice, $priceBuyNum, $totalBuyNum);
                 }
                 $thisPrice = $itemPrice;