Przeglądaj źródła

供货商花材新接口

shish 2 lat temu
rodzic
commit
94527e6503
1 zmienionych plików z 60 dodań i 2 usunięć
  1. 60 2
      app-hd/controllers/ProductController.php

+ 60 - 2
app-hd/controllers/ProductController.php

@@ -358,8 +358,6 @@ class ProductController extends BaseController
         $connection = Yii::$app->db;//事务处理
         $transaction = $connection->beginTransaction();
         try {
-
-
             //获取所有当前供货商的分类 (全部、常用)
             //根据分类组装分类下的花材信息
             $shop = ShopClass::getById($shopId, true);
@@ -404,7 +402,67 @@ class ProductController extends BaseController
             Yii::info("报错内容:" . $e->getMessage());
             util::fail();
         }
+    }
 
+    public function actionGhsItemV2()
+    {
+        $get = Yii::$app->request->get();
+        $id = $get['id'] ?? 0;
+        $ghs = GhsClass::getGhsInfo($id);
+        if (empty($ghs)) {
+            util::fail('没有找到供货商');
+        }
+        $shopId = $ghs['shopId'] ?? 0;
+        $black = $ghs['black'] ?? 2;
+        if ($black == 2) {
+            util::fail('暂无花材');
+        }
+        $connection = Yii::$app->db;//事务处理
+        $transaction = $connection->beginTransaction();
+        try {
+            //获取所有当前供货商的分类 (全部、常用)
+            //根据分类组装分类下的花材信息
+            $shop = ShopClass::getById($shopId, true);
+            $mainId = $shop->mainId ?? 0;
+            $classIds = ItemClassClass::getGhsItemClassAll($mainId);
+            $where['mainId'] = $mainId;
+            $where['delStatus'] = 0;
+            //是否显示全部花材,包括下架的
+            $showAll = $get['showAll'] ?? 0;
+            if ($showAll == 0) {
+                $where['status'] = 1;
+            }
+            $where['frontHide'] = 0;
+
+            $level = $ghs['giveLevel'] ?? 1;
+            $field = 'id,py,cover,name,ratio,classId,itemId,weight,smallUnit,bigUnit,smallUnit,smallRatio,ratioType,variety,price,skPrice,skDiscountPrice,hjPrice,hjDiscountPrice,actualSold,stock,stockWarning,discountPrice,presell,presellDate,reachNum,reachNumDiscount';
+            $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
+            $itemInfoData = ProductClass::hdCgGroup($itemInfoData, $level);
+            $myProduct = ProductClass::getAllByCondition(['mainId' => $this->mainId, 'delStatus' => 0], null, 'id,stock,onStock,stockWarning,itemId', 'itemId');
+            if (!empty($itemInfoData)) {
+                $myShop = $this->shop;
+                $myDisplay = isset($myShop->pfShopId) && $myShop->pfShopId > 0 ? 1 : 0;
+                foreach ($itemInfoData as $key => $val) {
+                    $ptItemId = $val['itemId'] ?? 0;
+                    $myStock = $myProduct[$ptItemId]['stock'] ?? 0;
+                    $myStock = floatval($myStock);
+                    $myOnStock = $myProduct[$ptItemId]['onStock'] ?? 0;
+                    $myStockWarning = $myProduct[$ptItemId]['stockWarning'] ?? 5;
+                    $myLack = bcadd($myStock, $myOnStock, 2) > $myStockWarning ? 0 : 1;
+                    $itemInfoData[$key]['myStock'] = $myStock;
+                    $itemInfoData[$key]['myOnStock'] = $myOnStock;
+                    $itemInfoData[$key]['myStockWarning'] = $myStockWarning;
+                    $itemInfoData[$key]['myLack'] = $myLack;
+                    $itemInfoData[$key]['myDisplay'] = $myDisplay;
+                }
+            }
+            $respond = ProductService::assembleData($classIds, $itemInfoData, true);
+            util::success($respond);
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            Yii::info("报错内容:" . $e->getMessage());
+            util::fail();
+        }
     }
 
     public function actionDetail()