Преглед изворни кода

把商品详情接口补上限购清空配置回显

shizhongqi пре 3 месеци
родитељ
комит
1f737ccea4
2 измењених фајлова са 52 додато и 0 уклоњено
  1. 11 0
      app-ghs/controllers/ProductController.php
  2. 41 0
      biz-ghs/product/classes/ProductClass.php

+ 11 - 0
app-ghs/controllers/ProductController.php

@@ -1321,6 +1321,17 @@ class ProductController extends BaseController
         $id = Yii::$app->request->get('id', 0);
         $source = Yii::$app->request->get('source', '');
         $respond = ProductClass::getItemInfo($id);
+        if (empty($respond) || !is_array($respond)) {
+            util::fail('没有找到花材');
+        }
+        $limitBuyClearInfo = ProductClass::getLimitBuyClearInfo($id);
+        if (!is_array($limitBuyClearInfo)) {
+            $limitBuyClearInfo = [];
+        }
+        // foreach ($limitBuyClearInfo as $key => $value) {
+            // $respond[$key] = $value;
+        // }
+        $respond['limitBuyClearInfo'] = $limitBuyClearInfo;
         $ptItemId = $respond['itemId'] ?? 0;
         // 封面图与多花材图片的兼容处理
         if ($respond['images'] == '' && $respond['shortCover'] != '') {

+ 41 - 0
biz-ghs/product/classes/ProductClass.php

@@ -2862,6 +2862,47 @@ class ProductClass extends BaseClass
         return is_array($config) ? $config : [];
     }
 
+    // 获取限购清空配置,用于商品详情回显
+    public static function getLimitBuyClearInfo($productId)
+    {
+        $productId = intval($productId);
+        $info = [
+            'limitBuyClearType' => 0, // 0不清空 1定时清空 2循环清空
+            'limitBuyClearTypeName' => '不清空',
+            'limitBuyClearAt' => 0,
+            'limitBuyClearTime' => '',
+            'limitBuyNextClearAt' => 0,
+            'limitBuyNextClearTime' => '',
+            'limitBuyClearIntervalDays' => 0,
+            'cleartAt' => '',
+        ];
+        if ($productId <= 0) {
+            return $info;
+        }
+
+        $clearMarkKey = self::CLEAR_MARK_KEY . $productId;
+        $clearAt = intval(Yii::$app->redis->executeCommand('GET', [$clearMarkKey]));
+        if ($clearAt <= 0) {
+            return $info;
+        }
+
+        $info['limitBuyClearType'] = 1;
+        $info['limitBuyClearTypeName'] = '定时清空';
+        $info['limitBuyClearAt'] = $clearAt;
+        $info['limitBuyClearTime'] = date('Y-m-d H:i:s', $clearAt);
+        $info['limitBuyNextClearAt'] = $clearAt;
+        $info['limitBuyNextClearTime'] = $info['limitBuyClearTime'];
+
+        $loopConfig = self::getLimitBuyClearLoopConfigByProductId($productId);
+        if (!empty($loopConfig)) {
+            $info['limitBuyClearType'] = 2;
+            $info['limitBuyClearTypeName'] = '循环清空';
+            $info['limitBuyClearIntervalDays'] = intval($loopConfig['intervalDays'] ?? 0);
+            $info['cleartAt'] = intval($loopConfig['clearHour'] ?? 0);
+        }
+        return $info;
+    }
+
     // 清理循环清空限购配置
     public static function clearLimitBuyClearLoopConfig($productId)
     {