shish vor 4 Jahren
Ursprung
Commit
cbff2ca48c

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

@@ -622,17 +622,18 @@ class ProductController extends BaseController
     {
         $post = Yii::$app->request->post();
 
+        $shop = $this->shop;
+        $default = $shop->default ?? 0;
+        $join = $shop->join ?? 0;
+        if ($join == 1 && $default != 1) {
+            util::fail('直营店暂无权限操作');
+        }
+
         $shopAdmin = $this->shopAdmin;
         if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
             util::fail('管理员才能添加花材');
         }
 
-        $shop = $this->shop;
-        $default = $shop->default ?? 0;
-        if ($default != 1) {
-            util::fail('请在总店添加');
-        }
-
         $post['sjId'] = $this->sjId;
         $post['adminId'] = $this->adminId;
         $post['mainId'] = $this->mainId;
@@ -699,6 +700,8 @@ class ProductController extends BaseController
     //(管理后台)复制花材
     public function actionCopy()
     {
+        util::fail('停用');
+
         $shopAdmin = $this->shopAdmin;
         if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
             util::fail('超管才能添加花材');
@@ -739,7 +742,7 @@ class ProductController extends BaseController
     public function actionGeneratePriceTable()
     {
         $level = Yii::$app->request->get('level', 0);
-        $respond = ProductService::generatePriceTable($this->sjId, $this->shopId, $level,$this->mainId);
+        $respond = ProductService::generatePriceTable($this->sjId, $this->shopId, $level, $this->mainId);
         $file = $respond['file'] ?? '';
         $shortFile = $respond['shortFile'] ?? '';
         $fileUrl = Yii::$app->params['ghsHost'] . $file;
@@ -749,7 +752,7 @@ class ProductController extends BaseController
     //下载条形码 lqh 20211227
     public function actionGenerateBarcodeTable()
     {
-        $respond = ProductService::generateBarcodeTable($this->sjId, $this->shopId,$this->mainId);
+        $respond = ProductService::generateBarcodeTable($this->sjId, $this->shopId, $this->mainId);
         $file = $respond['file'] ?? '';
         $shortFile = $respond['shortFile'] ?? '';
         $fileUrl = Yii::$app->params['ghsHost'] . $file;

+ 14 - 23
app-hd/controllers/ProductController.php

@@ -1,9 +1,4 @@
 <?php
-/**
- * User: admin
- * Date Time: 2021/3/2 14:34
- */
-
 namespace hd\controllers;
 
 use biz\ghs\classes\GhsClass;
@@ -33,17 +28,18 @@ class ProductController extends BaseController
             util::fail('请在批发端添加');
         }
 
+        $shop = $this->shop;
+        $default = $shop->default ?? 0;
+        $join = $shop->join ?? 0;
+        if ($join == 1 && $default != 1) {
+            util::fail('直营店暂无权限操作');
+        }
+
         $shopAdmin = $this->shopAdmin;
         if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
             util::fail('管理员才能添加花材');
         }
 
-        $shop = $this->shop;
-        $default = $shop->default ?? 0;
-        if ($default != 1) {
-            util::fail('请在总店添加');
-        }
-
         $post['sjId'] = $this->sjId;
         $post['adminId'] = $this->adminId;
         $post['mainId'] = $this->mainId;
@@ -302,23 +298,18 @@ class ProductController extends BaseController
             util::fail('请在批发端修改');
         }
 
+        $default = $shop->default ?? 0;
+        $join = $shop->join ?? 0;
+        if ($join == 1 && $default != 1) {
+            util::fail('直营店暂无权限操作');
+        }
+
         $post = Yii::$app->request->post();
         $shopAdmin = $this->shopAdmin;
         if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
             util::fail('超管才能修改');
         }
-        $shop = $this->shop;
-        $pfShopId = $shop->pfShopId ?? 0;
-        if (!empty($pfShopId)) {
-            util::fail('请在批发端修改花材');
-        }
-        $default = $shop->default ?? 0;
-        if ($default != 1) {
-            //除了上下架其它只能在首店修改
-            if (isset($post['status']) == false) {
-                util::fail('请在首店修改');
-            }
-        }
+
         $post['adminId'] = $this->adminId;
         ProductClass::updateProduct($post);
         util::complete();

+ 26 - 29
biz-ghs/product/classes/ProductClass.php

@@ -1054,7 +1054,7 @@ class ProductClass extends BaseClass
             util::fail("请输入价格");
         }
         if (isset($data['addPrice']) == false || is_numeric($data['addPrice']) == false) {
-            util::fail("请输入花材的加价");
+            util::fail("请输入加价");
         }
         if ($stockWarning === false) {
             util::fail("请输入库存预警值");
@@ -1078,27 +1078,26 @@ class ProductClass extends BaseClass
         $connection = Yii::$app->db;
         $transaction = $connection->beginTransaction();
         try {
-            //新增到平台
-            $defaultInfo = PtItemClassClass::getByCondition(['isDefault' => 1]);
-            $defaultClassId = $defaultInfo['id'] ?? 0;
-            if (empty($defaultClassId)) {
-                Yii::info('添加花材时没有找到默认分类');
-                util::fail('添加失败');
-            }
 
-            $itemData = $data;
-            $itemData['classId'] = $defaultClassId;
             if (isset($data['itemId']) == false || empty($data['itemId'])) {
-                $itemData['skAddPrice'] = 3;
-                $itemData['hjAddPrice'] = 2;
-                $itemData['zsAddPrice'] = 1;
+                //添加新品种先在平台新增花材
+                $defaultInfo = PtItemClassClass::getByCondition(['isDefault' => 1]);
+                $defaultClassId = $defaultInfo['id'] ?? 0;
+                if (empty($defaultClassId)) {
+                    util::fail('没有找到平台默认分类');
+                }
+                $itemData = $data;
+                $itemData['classId'] = $defaultClassId;
+                $itemData['skAddPrice'] = $itemData['skAddPrice'] ?? 3;
+                $itemData['hjAddPrice'] = $itemData['hjAddPrice'] ?? 2;
+                $itemData['zsAddPrice'] = $itemData['zsAddPrice'] ?? 1;
                 $ptItemInfo = PtItemClass::addItem($itemData);
                 $data['itemId'] = $ptItemInfo['id'];
             } else {
-                //从平台导入花材方式添加有带itemId
-                $has = self::getByCondition(['shopId' => $data['shopId'], 'itemId' => $data['itemId']], true);
+                //从平台导入花材
+                $has = self::getByCondition(['mainId' => $mainId, 'itemId' => $data['itemId']], true);
                 if (!empty($has)) {
-                    util::fail('已经添加过了');
+                    util::fail('已经导入过了');
                 }
             }
 
@@ -1113,31 +1112,30 @@ class ProductClass extends BaseClass
             $addPrice = $data['addPrice'] ?? $ptItemInfo->addPrice;
             $data['addPrice'] = $addPrice;
             if ($addPrice > $skAddPrice) {
-                util::fail('店加价不能大于散客加价');
+                util::fail('店加价不能大于散客加价');
             }
             $hjAddPrice = $data['hjAddPrice'] ?? $ptItemInfo->hjAddPrice;
             $data['hjAddPrice'] = $hjAddPrice;
             if ($hjAddPrice > $addPrice) {
-                util::fail('银店加价不能大于普店加价');
-            }
-            $zsAddPrice = $data['zsAddPrice'] ?? $ptItemInfo->zsAddPrice;
-            $data['zsAddPrice'] = $zsAddPrice;
-            if ($zsAddPrice > $hjAddPrice) {
-                util::fail('金店加价不能大于银店加价');
+                util::fail('同行加价不能大于花店加价');
             }
 
             //价格
             $price = $data['price'] ?? 0;
+            if (empty($price) || $price <= 0) {
+                util::fail('请填写价格');
+            }
             $skPrice = bcsub($price, bcsub($addPrice, $skAddPrice, 2), 2);
             $hjPrice = bcsub($price, bcsub($addPrice, $hjAddPrice, 2), 2);
-            $zsPrice = bcsub($price, bcsub($addPrice, $zsAddPrice, 2), 2);
             $data['skPrice'] = $skPrice;
             $data['hjPrice'] = $hjPrice;
-            $data['zsPrice'] = $zsPrice;
 
-            //根据sjId, 找到所有的shopId,都添加
+            //找到父级sj下的所有直营店,添加花材
             $shopList = ShopClass::getAllByCondition(['sjId' => $data['sjId']], null, '*', null, true);
             foreach ($shopList as $shop) {
+                if (isset($shop->join) && $shop->join == 1) {
+                    continue;
+                }
                 $shopId = $shop->id ?? 0;
                 $currentMainId = $shop->mainId ?? 0;
                 $data['shopId'] = $shopId;
@@ -1147,7 +1145,6 @@ class ProductClass extends BaseClass
                     $data['stock'] = 0;
                     $data['status'] = 2;
                 }
-
                 $res = self::add($data);
                 if ($stock > 0 && $res && $currentShopId == $shopId) {
                     //有库存数量,增加盘盈记录 2021.7.9 lqh
@@ -1208,10 +1205,10 @@ class ProductClass extends BaseClass
                 }
             }
             $transaction->commit();
-
         } catch (\Exception $exception) {
             $transaction->rollBack();
-            util::fail($exception->getMessage());
+            Yii::info('失败原因:' . $exception->getMessage());
+            util::fail('添加失败');
         }
     }
 

+ 24 - 55
biz-hd/item/classes/ItemClass.php

@@ -18,6 +18,7 @@ use common\components\orderSn;
 use common\components\stringUtil;
 use common\components\util;
 use common\services\xhItemService;
+use Yii;
 
 class ItemClass extends BaseClass
 {
@@ -57,11 +58,11 @@ class ItemClass extends BaseClass
         if (!$classId) {
             util::fail("请选择分类");
         }
-        if (isset($data['price']) == false || is_numeric($data['price']) == false || $data['price'] < 0) {
+        if (isset($data['skPrice']) == false || is_numeric($data['skPrice']) == false || $data['skPrice'] < 0) {
             util::fail("请输入价格");
         }
-        if (isset($data['addPrice']) == false || is_numeric($data['addPrice']) == false) {
-            util::fail("请输入花材的加价");
+        if (isset($data['skAddPrice']) == false || is_numeric($data['skAddPrice']) == false) {
+            util::fail("请输入加价");
         }
         if ($stockWarning === false) {
             util::fail("请输入库存预警值");
@@ -85,66 +86,35 @@ class ItemClass extends BaseClass
         $connection = Yii::$app->db;
         $transaction = $connection->beginTransaction();
         try {
-            //新增到平台
-            $defaultInfo = PtItemClassClass::getByCondition(['isDefault' => 1]);
-            $defaultClassId = $defaultInfo['id'] ?? 0;
-            if (empty($defaultClassId)) {
-                Yii::info('添加花材时没有找到默认分类');
-                util::fail('添加失败');
-            }
-
-            $itemData = $data;
-            $itemData['classId'] = $defaultClassId;
             if (isset($data['itemId']) == false || empty($data['itemId'])) {
-                $itemData['skAddPrice'] = 3;
-                $itemData['hjAddPrice'] = 2;
-                $itemData['zsAddPrice'] = 1;
+                //添加新品种先在平台新增花材
+                $defaultInfo = PtItemClassClass::getByCondition(['isDefault' => 1]);
+                $defaultClassId = $defaultInfo['id'] ?? 0;
+                if (empty($defaultClassId)) {
+                    Yii::info('添加花材时没有找到默认分类');
+                    util::fail('添加失败');
+                }
+                $itemData = $data;
+                $itemData['classId'] = $defaultClassId;
+                $itemData['skAddPrice'] = $itemData['skAddPrice'] ?? 3;
+                $itemData['hjAddPrice'] = $itemData['hjAddPrice'] ?? 2;
+                $itemData['zsAddPrice'] = $itemData['zsAddPrice'] ?? 1;
                 $ptItemInfo = PtItemClass::addItem($itemData);
                 $data['itemId'] = $ptItemInfo['id'];
             } else {
-                //从平台导入花材方式添加有带itemId
+                //从平台导入花材
                 $has = self::getByCondition(['shopId' => $data['shopId'], 'itemId' => $data['itemId']], true);
                 if (!empty($has)) {
-                    util::fail('已经添加过了');
+                    util::fail('已经过了');
                 }
             }
 
-            //小菊的结构
-            $ptItemId = $data['itemId'] ?? 0;
-            $ptItemInfo = PtItemClass::getById($ptItemId, true);
-            $data['variety'] = $ptItemInfo->variety ?? 0;
-
-            //加价 2021-12-07 lqh 如果前端有传取前端的,没有则取pt
-            $skAddPrice = $data['skAddPrice'] ?? $ptItemInfo->skAddPrice;
-            $data['skAddPrice'] = $skAddPrice;
-            $addPrice = $data['addPrice'] ?? $ptItemInfo->addPrice;
-            $data['addPrice'] = $addPrice;
-            if ($addPrice > $skAddPrice) {
-                util::fail('普店加价不能大于散客加价');
-            }
-            $hjAddPrice = $data['hjAddPrice'] ?? $ptItemInfo->hjAddPrice;
-            $data['hjAddPrice'] = $hjAddPrice;
-            if ($hjAddPrice > $addPrice) {
-                util::fail('银店加价不能大于普店加价');
-            }
-            $zsAddPrice = $data['zsAddPrice'] ?? $ptItemInfo->zsAddPrice;
-            $data['zsAddPrice'] = $zsAddPrice;
-            if ($zsAddPrice > $hjAddPrice) {
-                util::fail('金店加价不能大于银店加价');
-            }
-
-            //价格
-            $price = $data['price'] ?? 0;
-            $skPrice = bcsub($price, bcsub($addPrice, $skAddPrice, 2), 2);
-            $hjPrice = bcsub($price, bcsub($addPrice, $hjAddPrice, 2), 2);
-            $zsPrice = bcsub($price, bcsub($addPrice, $zsAddPrice, 2), 2);
-            $data['skPrice'] = $skPrice;
-            $data['hjPrice'] = $hjPrice;
-            $data['zsPrice'] = $zsPrice;
-
-            //根据sjId, 找到所有的shopId,都添加
+            //找到父级sj下的所有直营店,添加花材
             $shopList = ShopClass::getAllByCondition(['sjId' => $data['sjId']], null, '*', null, true);
             foreach ($shopList as $shop) {
+                if (isset($shop->join) && $shop->join == 1) {
+                    continue;
+                }
                 $shopId = $shop->id ?? 0;
                 $currentMainId = $shop->mainId ?? 0;
                 $data['shopId'] = $shopId;
@@ -154,7 +124,6 @@ class ItemClass extends BaseClass
                     $data['stock'] = 0;
                     $data['status'] = 2;
                 }
-
                 $res = self::add($data);
                 if ($stock > 0 && $res && $currentShopId == $shopId) {
                     //有库存数量,增加盘盈记录 2021.7.9 lqh
@@ -215,10 +184,10 @@ class ItemClass extends BaseClass
                 }
             }
             $transaction->commit();
-
         } catch (\Exception $exception) {
             $transaction->rollBack();
-            util::fail($exception->getMessage());
+            Yii::info('失败原因:' . $exception->getMessage());
+            util::fail('添加失败');
         }
     }
 

+ 1 - 1
sql.sql

@@ -972,5 +972,5 @@ ALTER TABLE xhAdmin MODIFY `miniOpenId` VARCHAR(100) COLLATE utf8mb4_unicode_ci
 
 ALTER TABLE `xhAdmin` MODIFY `currentShopId` INT(11) NOT NULL DEFAULT '0' COMMENT '零售当前管理的门店' AFTER `super`;
 ALTER TABLE `xhAdmin` MODIFY `openShop` TINYINT(4) NOT NULL DEFAULT '1' COMMENT '零售申请开店 1没有 2有申请,待审核 3有申请,已审核通过' AFTER `currentShopId`;
-
+ALTER TABLE xhShop ADD `join` TINYINT NOT NULL DEFAULT 0 COMMENT '0非加盟店,直营,1加盟店' AFTER `ptStyle`;
 -- ssh 20220424