shish 2 роки тому
батько
коміт
5c407584fa
1 змінених файлів з 14 додано та 1 видалено
  1. 14 1
      biz-ghs/order/classes/OrderItemClass.php

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

@@ -353,6 +353,7 @@ class OrderItemClass extends BaseClass
             }
 
             $productId = $val['productId'];
+            $name = $val['name'] ?? '';
             $ratio = $val['ratio'] ?? 0;
             $currentWeight = $val['weight'];
 
@@ -363,8 +364,20 @@ class OrderItemClass extends BaseClass
             $weight = bcadd($w, $weight, 2);
 
             $limitBuy = $val['limitBuy'] ?? 0;
+            $limitKey = 'limit_buy_' . $productId;
+            $currentNum = floatval($itemNum);
             if ($limitBuy > 0) {
-
+                $has = Yii::$app->redis->executeCommand('HEXISTS', [$limitKey, $customId]);
+                if (!empty($has)) {
+                    $hasNum = Yii::$app->redis->executeCommand('HGET', [$limitKey, $customId]);
+                    $lastNum = bcadd($hasNum, $currentNum);
+                    if ($lastNum > $limitBuy) {
+                        util::fail($name . ' 超过可购买数量');
+                    }
+                    Yii::$app->redis->executeCommand('HSET', [$limitKey, $customId, $lastNum]);
+                } else {
+                    Yii::$app->redis->executeCommand('HSET', [$limitKey, $customId, $currentNum]);
+                }
             }
 
             if ($stockMayChange == true) {