shish 2 лет назад
Родитель
Сommit
079bc8148b
1 измененных файлов с 98 добавлено и 0 удалено
  1. 98 0
      app-ghs/controllers/ProductController.php

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

@@ -687,6 +687,104 @@ class ProductController extends BaseController
 
     }
 
+    //多个花材同时改成一个价 ssh 20231003
+    public function actionManyItemChangeOnePrice()
+    {
+        $post = Yii::$app->request->post();
+        $idsList = $post['ids'] ?? '';
+        $ids = json_decode($idsList, true);
+        if (empty($ids)) {
+            util::fail('请选择花材');
+        }
+        $list = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
+        if (empty($list)) {
+            util::fail('请选择花材哦');
+        }
+        $mainId = $this->mainId;
+        $adminId = $this->adminId ?? 0;
+        $shop = $this->shop;
+        $default = $shop->default ?? 0;
+        $shopAdmin = $this->shopAdmin;
+        $price = $post['price'] ?? 0;
+        if (is_numeric($price) == false) {
+            util::fail('批发价填写错误');
+        }
+        $skPrice = $post['skPrice'] ?? 0;
+        if (is_numeric($skPrice) == false) {
+            util::fail('散客价填写错误');
+        }
+        $hjPrice = $post['hjPrice'] ?? 0;
+        if (is_numeric($hjPrice) == false) {
+            util::fail('会员价填写错误');
+        }
+        if ($hjPrice > $price) {
+            util::fail('会员价不能大于批发价');
+        }
+        if ($price > $skPrice) {
+            util::fail('批发价不能大于零售价');
+        }
+
+        $sjId = $shop->sjId ?? 0;
+        $chainShopList = [];
+        if ($default == 1) {
+            $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId, 'join' => 0], null, '*', null, true);
+        }
+
+        //normal常规改价,cg采购改价
+        $changeType = Yii::$app->request->post('changeType', 'normal');
+        $targetId = 0;
+        $changeParams = ['staffId' => $shopAdmin->id, 'staffName' => $shopAdmin->name, 'changeType' => $changeType, 'targetId' => $targetId];
+
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+
+            foreach ($list as $product) {
+
+                if ($product->mainId != $mainId) {
+                    util::fail('修改失败,不是你的花材');
+                }
+                $ptItemId = $product->itemId;
+                ProductClass::changeSinglePrice($shop, $ptItemId, $price, $skPrice, $hjPrice, $changeParams);
+                //在首店修改需要同步到所有直营店
+                if ($default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
+                    if (!empty($chainShopList)) {
+                        foreach ($chainShopList as $chain) {
+                            if ($chain->id == $shop->id) {
+                                continue;
+                            }
+                            $chainMainId = $chain->mainId ?? 0;
+                            $staff = ShopAdminClass::getByCondition(['mainId' => $chainMainId, 'adminId' => $adminId], true);
+                            $changeParams2 = ['staffId' => $staff->id, 'staffName' => $staff->name, 'changeType' => $changeType, 'targetId' => $targetId];
+                            ProductClass::changeSinglePrice($chain, $ptItemId, $price, $skPrice, $hjPrice, $changeParams2);
+                        }
+                    }
+                }
+            }
+
+            if (!empty($mainId)) {
+                //提醒零售收银台界面要刷新
+                $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
+                if (!empty($staffList)) {
+                    foreach ($staffList as $staff) {
+                        $staffId = $staff->id ?? 0;
+                        Yii::$app->redis->executeCommand('SET', ['cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
+                        Yii::$app->redis->executeCommand('SET', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
+                    }
+                }
+            }
+
+            $transaction->commit();
+            util::complete('修改成功');
+
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            Yii::info("修改失败原因:" . $e->getMessage());
+            util::fail('修改失败');
+        }
+
+    }
+
     //改价
     public function actionChangePrice()
     {