shish пре 1 година
родитељ
комит
ba1fcfdeb5

+ 2 - 2
app-ghs/controllers/ItemController.php

@@ -58,12 +58,12 @@ class ItemController extends BaseController
         if ($custom->ownMainId != $this->mainId) {
             util::fail('不是你的客户');
         }
-        ProductClass::cancelOneLimitBuy($productId, $customId);
+        ProductClass::baseClearLimitBuy($productId, $customId);
         util::complete('清除成功');
     }
 
 
-    //取消花材的限购,重新开始计算
+    //取消花材全部客户的已限数,重新开始计算
     public function actionClearLimitBuy()
     {
         $get = Yii::$app->request->get();

+ 6 - 0
biz-ghs/order/classes/OrderClass.php

@@ -2238,6 +2238,12 @@ class OrderClass extends BaseClass
                 $recordData['relateName'] = $order->customName ?? '';
                 $recordData['ptStyle'] = dict::getDict('ptStyle', 'ghs');
                 StockRecordClass::addSellStockOrderCancelRecord($recordData);
+
+                //如果有限购数量占用,也需要清除
+                $customId = $order->customId ?? 0;
+                $num = floor($v['num']);
+                ProductClass::baseClearLimitBuy($v['productId'], $customId, $num);
+
             }
         }
         return $order;

+ 20 - 7
biz-ghs/product/classes/ProductClass.php

@@ -2591,12 +2591,6 @@ class ProductClass extends BaseClass
         return $product['mainId'] ?? 0;
     }
 
-    public static function cancelOneLimitBuy($productId, $customId)
-    {
-        $limitKey = 'limit_buy_' . $productId;
-        Yii::$app->redis->executeCommand('HDEL', [$limitKey, $customId]);
-    }
-
     //取消限购的缓存 ssh 20240605
     public static function cancelLimitBuy($productId)
     {
@@ -2604,7 +2598,26 @@ class ProductClass extends BaseClass
         $arr = Yii::$app->redis->executeCommand('HKEYS', [$limitKey]);
         if (!empty($arr)) {
             foreach ($arr as $field) {
-                Yii::$app->redis->executeCommand('HDEL', [$limitKey, $field]);
+                self::baseClearLimitBuy($productId, $field);
+            }
+        }
+    }
+
+    //$num -1 表示减全部,大于-1表示减值
+    public static function baseClearLimitBuy($productId, $customId, $num = -1)
+    {
+        $limitKey = 'limit_buy_' . $productId;
+        if ($num <= -1) {
+            //清掉全部
+            Yii::$app->redis->executeCommand('HDEL', [$limitKey, $customId]);
+        } else {
+            $hasNum = Yii::$app->redis->executeCommand('HGET', [$limitKey, $customId]);
+            $remainNum = $hasNum > $num ? bcsub($num, $hasNum) : 0;
+            $remainNum = floor($remainNum);
+            if ($remainNum > 0) {
+                Yii::$app->redis->executeCommand('HSET', [$limitKey, $customId, $remainNum]);
+            } else {
+                Yii::$app->redis->executeCommand('HDEL', [$limitKey, $customId]);
             }
         }
     }