Explorar el Código

修改价格 和 注册

shish hace 4 años
padre
commit
ad47eaf0cf

+ 5 - 4
app-ghs/controllers/ProductController.php

@@ -196,7 +196,7 @@ class ProductController extends BaseController
         $shop = $this->shop;
         $default = $shop->default ?? 0;
         $join = $shop->join ?? 0;
-        if ($join == 1 && $default != 1) {
+        if ($default != 1 && $join == 1) {
             util::fail('请在首店修改');
         }
 
@@ -249,14 +249,15 @@ class ProductController extends BaseController
                 if (empty($price)) {
                     continue;
                 }
-                //在首店修改需要同步到直营店
+                $ptItemId = $product->itemId;
+                //在首店修改需要同步到所有直营店
                 if ($default == 1) {
                     foreach ($chainShopList as $chain) {
-                        $ptItemId = $product->itemId;
                         ProductClass::changePrice($chain, $ptItemId, $price);
                     }
+                } else {
+                    ProductClass::changePrice($shop, $ptItemId, $price);
                 }
-
             }
             $transaction->commit();
             util::complete('修改成功');

+ 10 - 2
app-hd/controllers/AuthController.php

@@ -129,7 +129,7 @@ class AuthController extends PublicController
         if (empty($password)) {
             util::fail('请输入密码');
         }
-        $admin = AdminService::getByCondition(['mobile' => $mobile, 'style' => AdminClass::STYLE_HD]);
+        $admin = AdminService::getByCondition(['mobile' => $mobile]);
         if (password_verify($password, $admin['password']) == false) {
             util::fail('密码错误');
         }
@@ -141,14 +141,22 @@ class AuthController extends PublicController
             }
             util::fail('请先注册');
         }
+        $currentShop = \bizHd\shop\classes\ShopClass::getById($currentShopId, true);
+        if (empty($currentShop)) {
+            util::fail('没有找到门店');
+        }
+        $mainId = $currentShop->mainId ?? 0;
         $adminId = $admin['id'];
-        $shopAdmin = ShopAdminService::getByCondition(['adminId' => $adminId, 'shopId' => $currentShopId, 'delStatus' => 0], true);
+        $shopAdmin = ShopAdminService::getByCondition(['mainId' => $mainId, 'adminId' => $adminId], true);
         if (empty($shopAdmin)) {
             util::fail('没有权限操作');
         }
         if ($shopAdmin->status == 0) {
             util::fail("您的账号已冻结");
         }
+        if ($shopAdmin->delStatus == 1) {
+            util::fail("您的账号已删除");
+        }
         $shopId = $shopAdmin->shopId ?? 0;
         if (empty($shopId)) {
             util::fail('您不是管理员');

+ 61 - 96
biz-ghs/product/classes/ProductClass.php

@@ -552,75 +552,55 @@ class ProductClass extends BaseClass
     }
 
     //修改价格 lqh 2021.1.28
-    public static function changePrice($product, $price, $priceLabel)
+    public static function changePrice($shop, $ptItemId, $price)
     {
-        $shopId = $product->shopId ?? 0;
-
-        $shopInfo = ShopClass::getById($shopId, true);
-        $itemId = $product->itemId ?? 0;
-
-        $sjId = $shopInfo->sjId ?? 0;
-        $shopAll = ShopClass::getAllShop($sjId);
-        if ($shopAll) {
-            foreach ($shopAll as $shop) {
-                $currentId = $shop['id'] ?? 0;
-                $currentInfo = ProductClass::getByCondition(['itemId' => $itemId, 'shopId' => $currentId], true);
-                if (empty($currentInfo)) {
-                    continue;
-                }
-
-                //改价后取消特价
-                $currentInfo->price = $price;
-                $currentInfo->priceLabel = $priceLabel;
-
-                //会员价同步变化
-                $addPrice = $currentInfo->addPrice ?? 0;
+        $mainId = $shop->mainId ?? 0;
+        $productInfo = ProductClass::getByCondition(['itemId' => $ptItemId, 'mainId' => $mainId], true);
+        $productInfo->price = $price;
 
-                $skAddPrice = $currentInfo->skAddPrice ?? 0;
-                $sk = bcsub($addPrice, $skAddPrice, 2);
-                $currentInfo->skPrice = bcsub($price, $sk, 2);
+        $addPrice = $productInfo->addPrice ?? 0;
 
-                $hjAddPrice = $currentInfo->hjAddPrice ?? 0;
-                $hj = bcsub($addPrice, $hjAddPrice, 2);
-                $currentInfo->hjPrice = bcsub($price, $hj, 2);
+        $skAddPrice = $productInfo->skAddPrice ?? 0;
+        $sk = bcsub($addPrice, $skAddPrice, 2);
+        $productInfo->skPrice = bcsub($price, $sk, 2);
 
-                $zsAddPrice = $currentInfo->zsAddPrice ?? 0;
-                $zs = bcsub($addPrice, $zsAddPrice, 2);
-                $currentInfo->zsPrice = bcsub($price, $zs, 2);
+        $hjAddPrice = $productInfo->hjAddPrice ?? 0;
+        $hj = bcsub($addPrice, $hjAddPrice, 2);
+        $productInfo->hjPrice = bcsub($price, $hj, 2);
 
-                $currentInfo->save();
+        $zsAddPrice = $productInfo->zsAddPrice ?? 0;
+        $zs = bcsub($addPrice, $zsAddPrice, 2);
+        $productInfo->zsPrice = bcsub($price, $zs, 2);
 
-            }
-        }
-
-        return true;
+        $productInfo->save();
     }
 
-    //2021.7.6 修改花材同步其他分
-    public static function updateSyncProduct($productId, $shopId, $upData)
+    //2021.7.6 首店修改同步到其它的直营店
+    public static function updateSyncProduct($productId, $shop, $upData)
     {
-        $shopInfo = ShopClass::getById($shopId);
+        $shopId = $shop->id ?? 0;
         $productData = ProductClass::getById($productId);
-        $itemId = $productData['itemId'];
-        if ($shopInfo['default'] == 1) {
-            $sjId = $shopInfo['sjId'];
-            $shopAll = ShopClass::getAllShop($sjId);
-            if ($shopAll) {
-                foreach ($shopAll as $s) {
-                    if ($s['id'] != $shopId) {
-                        if (isset($upData['price'])) {
-                            $price = $upData['price'];
-                            $product = ProductClass::getByCondition(['shopId' => $s['id'], 'itemId' => $itemId], true);
-                            if (empty($product)) {
-                                continue;
-                            }
-                            self::changePrice($product, $price, self::PRICE_LABEL_CHANGE);
-                            unset($upData['price']);
-                        }
-                        ProductClass::updateByCondition(['itemId' => $itemId, 'shopId' => $s['id']], $upData);
-                    }
-                }
+        $ptItemId = $productData['itemId'];
+        if (isset($shop->default) == false || $shop->default != 1) {
+            return false;
+        }
+        $sjId = $shop->sjId;
+        $shopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
+        if (empty($shopList)) {
+            return false;
+        }
+        foreach ($shopList as $current) {
+            if ($current->id == $shopId) {
+                continue;
             }
+            //加盟店不需要同步
+            if (isset($current->join) && $current->join == 1) {
+                continue;
+            }
+            $mainId = $current->mainId ?? 0;
+            //前面已经修改价格
+            unset($upData['price']);
+            ProductClass::updateByCondition(['itemId' => $ptItemId, 'mainId' => $mainId], $upData);
         }
     }
 
@@ -761,7 +741,7 @@ class ProductClass extends BaseClass
     }
 
     //修改product
-    public static function updateProduct($data)
+    public static function updateProduct($data, $shop)
     {
         $id = $data['id'] ?? 0;
         $product = self::getLockById($id);
@@ -814,44 +794,29 @@ class ProductClass extends BaseClass
             }
             $upData['discountPrice'] = $discountPrice;
         }
-        if (isset($data['price']) && is_numeric($data['price'])) {
-            $upData['price'] = $data['price'];
-            //修改价格
-            self::changePrice($product, $data['price'], self::PRICE_LABEL_CHANGE);
+
+        //加价
+        $skAddPrice = $data['skAddPrice'] ?? 0;
+        $upData['skAddPrice'] = $skAddPrice;
+        $addPrice = $data['addPrice'] ?? 0;
+        $upData['addPrice'] = $addPrice;
+        if ($addPrice > $skAddPrice) {
+            util::fail('普店加价不能大于散客加价');
         }
-        if (isset($data['skPrice']) && is_numeric($data['skPrice'])) {
-            $upData['skPrice'] = $data['skPrice'];
-        } else {
-            //加价
-            $skAddPrice = $data['skAddPrice'] ?? 0;
-            $upData['skAddPrice'] = $skAddPrice;
-            $addPrice = $data['addPrice'] ?? 0;
-            $upData['addPrice'] = $addPrice;
-            if ($addPrice > $skAddPrice) {
-                util::fail('普店加价不能大于散客加价');
-            }
-            $hjAddPrice = $data['hjAddPrice'] ?? 0;
-            $upData['hjAddPrice'] = $hjAddPrice;
-            if ($hjAddPrice > $addPrice) {
-                util::fail('银店加价不能大于普店加价');
-            }
-            $zsAddPrice = $data['zsAddPrice'] ?? 0;
-            $upData['zsAddPrice'] = $zsAddPrice;
-            if ($zsAddPrice > $hjAddPrice) {
-                util::fail('金店加价不能大于银店加价');
-            }
-            //价格
-            $price = $data['price'] ?? 0;
-            if (is_numeric($price) == false || $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);
-            $upData['skPrice'] = $skPrice;
-            $upData['hjPrice'] = $hjPrice;
-            $upData['zsPrice'] = $zsPrice;
+        $hjAddPrice = $data['hjAddPrice'] ?? 0;
+        $upData['hjAddPrice'] = $hjAddPrice;
+        if ($hjAddPrice > $addPrice) {
+            util::fail('银店加价不能大于普店加价');
+        }
+        //价格
+        $price = $data['price'] ?? 0;
+        if (is_numeric($price) == false || $price < 0) {
+            util::fail('请填写价格');
         }
+        $skPrice = bcsub($price, bcsub($addPrice, $skAddPrice, 2), 2);
+        $hjPrice = bcsub($price, bcsub($addPrice, $hjAddPrice, 2), 2);
+        $upData['skPrice'] = $skPrice;
+        $upData['hjPrice'] = $hjPrice;
 
         if (isset($data['stockWarning'])) {
             $upData['stockWarning'] = $data['stockWarning'];
@@ -888,7 +853,7 @@ class ProductClass extends BaseClass
         self::updateById($id, $currentData);
 
         //2021.7.6 lqh 如果是首店,则更新全部分店
-        self::updateSyncProduct($id, $product->shopId, $upData);
+        self::updateSyncProduct($id, $shop, $upData);
     }
 
     //变成自动改价 2021.4.14