ソースを参照

备注的添加修改和删除

shish 1 ヶ月 前
コミット
badba78a89
2 ファイル変更132 行追加2 行削除
  1. 66 1
      app-ghs/controllers/ItemController.php
  2. 66 1
      app-hd/controllers/ItemController.php

+ 66 - 1
app-ghs/controllers/ItemController.php

@@ -1,7 +1,15 @@
 <?php
+/**
+ * 供货商端花材管理控制器
+ * 主要用途:供货商(批发商)后台管理花材,例如:获取花材列表、修改或清除花材展示备注说明、隐藏/显示花材等。
+ * 使用角色:供货商管理员。
+ * 解决问题:在总店修改或清除花材备注说明时,不管分店是直营还是加盟,均同步更新花材备注。
+ */
 
 namespace ghs\controllers;
 
+use bizGhs\merchant\classes\ShopClass;
+
 use biz\item\classes\PtItemClass;
 use biz\item\classes\UnitClass;
 use biz\shop\classes\ShopExtClass;
@@ -736,7 +744,13 @@ class ItemController extends BaseController
     }
 
 
-    //花材展示备注 ssh 20260527
+    /**
+     * 修改花材展示备注说明 (供货商端)
+     * 职责:更新指定供货商花材的备注内容。如果当前店铺是总店,则需将修改同步到该商户下的所有分店(不论直营还是加盟店)。
+     * 入参:id (花材ID,来自 GET 传参), itemRemark (备注内容,来自 GET 传参)
+     * 返回:保存成功提示(JSON 格式)
+     * 副作用:会更新该供货商下所有分店对应花材的备注说明。
+     */
     public function actionUpdateItemRemark()
     {
         $get = Yii::$app->request->get();
@@ -757,9 +771,38 @@ class ItemController extends BaseController
         }
         $info->itemRemark = $itemRemark;
         $info->save();
+
+        // 复杂分支:若当前店铺是总店(default = 1),不管分店是直营还是加盟,都需要将修改后的花材备注同步至旗下所有分店,保证全渠道花材备注的一致性
+        $shop = $this->shop;
+        if (isset($shop->default) && $shop->default == 1) {
+            $sjId = $shop->sjId ?? 0;
+            $ptItemId = $info->itemId ?? 0;
+            $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
+            foreach ($chainShopList as $chainShop) {
+                $chainShopId = $chainShop->id ?? 0;
+                if ($chainShopId == $shop->id) {
+                    continue;
+                }
+                $chainMainId = $chainShop->mainId ?? 0;
+                $chainProduct = ItemClass::getByCondition(['mainId' => $chainMainId, 'itemId' => $ptItemId], true);
+                if (empty($chainProduct)) {
+                    continue;
+                }
+                $chainProduct->itemRemark = $itemRemark;
+                $chainProduct->save();
+            }
+        }
+
         util::complete('保存成功');
     }
 
+    /**
+     * 清除花材展示备注说明 (供货商端)
+     * 职责:清空指定供货商花材的备注内容。如果当前店铺是总店,则需同步清除商户下的所有分店(不论直营还是加盟店)对应花材的备注内容。
+     * 入参:id (花材ID,来自 GET 传参)
+     * 返回:清除成功提示(JSON 格式)
+     * 副作用:会清空该供货商下所有分店对应花材的备注说明。
+     */
     public function actionClearItemRemark()
     {
         $get = Yii::$app->request->get();
@@ -773,6 +816,28 @@ class ItemController extends BaseController
         }
         $info->itemRemark = '';
         $info->save();
+
+        // 复杂分支:若当前店铺是总店(default = 1),不管分店是直营还是加盟,都需要同步清空其花材备注说明,确保全渠道数据同步与统一
+        $shop = $this->shop;
+        if (isset($shop->default) && $shop->default == 1) {
+            $sjId = $shop->sjId ?? 0;
+            $ptItemId = $info->itemId ?? 0;
+            $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
+            foreach ($chainShopList as $chainShop) {
+                $chainShopId = $chainShop->id ?? 0;
+                if ($chainShopId == $shop->id) {
+                    continue;
+                }
+                $chainMainId = $chainShop->mainId ?? 0;
+                $chainProduct = ItemClass::getByCondition(['mainId' => $chainMainId, 'itemId' => $ptItemId], true);
+                if (empty($chainProduct)) {
+                    continue;
+                }
+                $chainProduct->itemRemark = '';
+                $chainProduct->save();
+            }
+        }
+
         util::complete('清除成功');
     }
 

+ 66 - 1
app-hd/controllers/ItemController.php

@@ -1,7 +1,15 @@
 <?php
+/**
+ * 零售端花材管理控制器
+ * 主要用途:供花店后台管理花材,例如:获取花材列表、隐藏或显示花材、修改或清除花材展示备注说明、限购设置等。
+ * 使用角色:花店管理员/商户管理员。
+ * 解决问题:在总店修改或清除花材备注说明时,能跨越直营和加盟店的限制,一键同步更新到所有分店,保证全店备注信息统一。
+ */
 
 namespace hd\controllers;
 
+use bizHd\shop\classes\ShopClass;
+
 use biz\item\classes\PtItemClass;
 use bizHd\item\classes\ItemClass;
 use bizGhs\pictext\classes\PicTextGhsItemClass;
@@ -475,7 +483,13 @@ class ItemController extends BaseController
         util::success(['customList' => $customList]);
     }
 
-    //花材展示备注
+    /**
+     * 修改花材展示备注说明
+     * 职责:更新指定花材的备注内容。如果当前店铺是总店,则需将修改同步到商户下的所有分店(不论直营还是加盟店)。
+     * 入参:id (花材ID,来自 GET 传参), itemRemark (备注内容,来自 GET 传参)
+     * 返回:保存成功提示(JSON 格式)
+     * 副作用:会更新该商家下所有分店对应花材的备注说明。
+     */
     public function actionUpdateItemRemark()
     {
         $get = Yii::$app->request->get();
@@ -496,9 +510,38 @@ class ItemController extends BaseController
         }
         $info->itemRemark = $itemRemark;
         $info->save();
+
+        // 复杂分支:若当前店铺是总店(default = 1),不管分店是直营还是加盟,都需要将修改后的花材备注同步至旗下所有分店,保证全渠道花材备注的一致性
+        $shop = $this->shop;
+        if (isset($shop->default) && $shop->default == 1) {
+            $sjId = $shop->sjId ?? 0;
+            $ptItemId = $info->itemId ?? 0;
+            $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
+            foreach ($chainShopList as $chainShop) {
+                $chainShopId = $chainShop->id ?? 0;
+                if ($chainShopId == $shop->id) {
+                    continue;
+                }
+                $chainMainId = $chainShop->mainId ?? 0;
+                $chainProduct = ItemClass::getByCondition(['mainId' => $chainMainId, 'itemId' => $ptItemId], true);
+                if (empty($chainProduct)) {
+                    continue;
+                }
+                $chainProduct->itemRemark = $itemRemark;
+                $chainProduct->save();
+            }
+        }
+
         util::complete('保存成功');
     }
 
+    /**
+     * 清除花材展示备注说明
+     * 职责:清空指定花材的备注内容。如果当前店铺是总店,则需同步清除商户下的所有分店(不论直营还是加盟店)对应花材的备注内容。
+     * 入参:id (花材ID,来自 GET 传参)
+     * 返回:清除成功提示(JSON 格式)
+     * 副作用:会清空该商家下所有分店对应花材的备注说明。
+     */
     public function actionClearItemRemark()
     {
         $get = Yii::$app->request->get();
@@ -512,6 +555,28 @@ class ItemController extends BaseController
         }
         $info->itemRemark = '';
         $info->save();
+
+        // 复杂分支:若当前店铺是总店(default = 1),不管分店是直营还是加盟,都需要同步清空其花材备注说明,确保全渠道数据同步与统一
+        $shop = $this->shop;
+        if (isset($shop->default) && $shop->default == 1) {
+            $sjId = $shop->sjId ?? 0;
+            $ptItemId = $info->itemId ?? 0;
+            $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
+            foreach ($chainShopList as $chainShop) {
+                $chainShopId = $chainShop->id ?? 0;
+                if ($chainShopId == $shop->id) {
+                    continue;
+                }
+                $chainMainId = $chainShop->mainId ?? 0;
+                $chainProduct = ItemClass::getByCondition(['mainId' => $chainMainId, 'itemId' => $ptItemId], true);
+                if (empty($chainProduct)) {
+                    continue;
+                }
+                $chainProduct->itemRemark = '';
+                $chainProduct->save();
+            }
+        }
+
         util::complete('清除成功');
     }
 }