|
|
@@ -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
|