shish před 4 roky
rodič
revize
80685e9cca

+ 2 - 2
app-ghs/controllers/ProductController.php

@@ -636,13 +636,13 @@ class ProductController extends BaseController
 
         $shopAdmin = $this->shopAdmin;
         if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
-            util::fail('管才能添加花材');
+            util::fail('管理员才能添加花材');
         }
 
         $shop = $this->shop;
         $default = $shop->default ?? 0;
         if ($default != 1) {
-            util::fail('请在店添加');
+            util::fail('请在店添加');
         }
 
         $post['sjId'] = $this->sjId;

+ 33 - 22
biz-ghs/product/classes/ProductClass.php

@@ -607,7 +607,7 @@ class ProductClass extends BaseClass
                 $addPrice = $currentInfo->addPrice ?? 0;
 
                 $skAddPrice = $currentInfo->skAddPrice ?? 0;
-                $sk = bcsub($addPrice,$skAddPrice, 2);
+                $sk = bcsub($addPrice, $skAddPrice, 2);
                 $currentInfo->skPrice = bcsub($price, $sk, 2);
 
                 $hjAddPrice = $currentInfo->hjAddPrice ?? 0;
@@ -1032,7 +1032,7 @@ class ProductClass extends BaseClass
     public static function addProduct($data)
     {
         $classId = $data['classId'] ?? 0;
-        $addPrice = $data['addPrice'] ?? false;
+
         $stockWarning = $data['stockWarning'] ?? false;
         $data['py'] = stringUtil::py($data['name']);
         $name = $data['name'] ?? false;
@@ -1055,17 +1055,16 @@ class ProductClass extends BaseClass
             }
             $stock = $data['stock'];
         }
-        if ($stock == 0) {
-            //下架
-            $data['status'] = 2;
-        }
+        //没有库存则下架
+        $data['status'] = $stock == 0 ? 2 : 1;
+
         if (!$classId) {
             util::fail("请选择分类");
         }
-        if (isset($data['price']) == false || is_numeric($data['price']) == false) {
+        if (isset($data['price']) == false || is_numeric($data['price']) == false || $data['price'] < 0) {
             util::fail("请输入价格");
         }
-        if ($addPrice === false) {
+        if (isset($data['addPrice']) == false || is_numeric($data['addPrice']) == false) {
             util::fail("请输入花材的加价");
         }
         if ($stockWarning === false) {
@@ -1115,23 +1114,35 @@ class ProductClass extends BaseClass
             $ptItemId = $data['itemId'] ?? 0;
             $ptItemInfo = PtItemClass::getById($ptItemId, true);
             $data['variety'] = $ptItemInfo->variety ?? 0;
-            //2021-12-07 lqh 如果前端有传取前端的,没有则取pt
-            if(!$addPrice){
-                $data['addPrice'] = $ptItemInfo->addPrice ?? 0;
-            }
-            $skAddPrice = $data['skAddPrice']??false;
-            $hjAddPrice = $data['hjAddPrice']??false;
-            $zsAddPrice = $data['zsAddPrice']??false;
-            if(!$skAddPrice){
-                $data['skAddPrice'] = $ptItemInfo->skAddPrice ?? 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('普店加价不能大于散客加价');
             }
-            if(!$hjAddPrice){
-                $data['hjAddPrice'] = $ptItemInfo->hjAddPrice ?? 0;
+            $hjAddPrice = $data['hjAddPrice'] ?? $ptItemInfo->hjAddPrice;
+            $data['hjAddPrice'] = $hjAddPrice;
+            if ($hjAddPrice > $addPrice) {
+                util::fail('银店加价不能大于普店加价');
             }
-            if($zsAddPrice){
-                $data['zsAddPrice'] = $ptItemInfo->zsAddPrice ?? 0;
+            $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,都添加
             $shopIds = ShopService::getShopIds($data['sjId']);
             foreach ($shopIds as $shopId) {