shish 4 лет назад
Родитель
Сommit
bb116a3bc3

+ 3 - 12
app-hd/controllers/OrderController.php

@@ -147,16 +147,6 @@ class OrderController extends BaseController
             }
             $post['actPrice'] = $currentPrice;
             $post['realPrice'] = $currentPrice;
-            //来源 0微信 1支付宝 2小程序 3朋友圈 4美团
-//            $sourceType = $this->isWx ? 0 : 1;
-//            if (httpUtil::isMiniProgram()) {
-//                $sourceType = 2;
-//            }
-            //会员优惠价
-//            $discountData = OrderService::getDiscountPrice(['price' => $prePrice, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->adminId]);
-//            $actPrice = $discountData['price'];
-//            $post['discountType'] = $discountData['discountType'];
-//            $post['discountAmount'] = $discountData['discountAmount'];
             $order = OrderClass::addOrder($post);
             $orderId = $order['id'];
             $orderSn = $order['orderSn'];
@@ -175,7 +165,8 @@ class OrderController extends BaseController
             }
             $currentPrice = $post['packingFee'] ?? 0; //包装费
             $orderProduct = [];
-            $productInfo = ProductClass::formatProductInfo($product);
+            $level = 0;
+            $productInfo = ProductClass::formatProductInfo($product, $level);
             $currentPrice = bcadd($currentPrice, $productInfo['price'], 2);
             $sendCost = isset($post['sendCost']) && is_numeric($post['sendCost']) ? $post['sendCost'] : 0;
             $post['sendCost'] = $sendCost;
@@ -207,7 +198,7 @@ class OrderController extends BaseController
                     'smallNum' => $smallNum,
                 ];
                 //减库存
-                ProductClass::decreaseStock($productId, $bigNum, $smallNum,true);
+                ProductClass::decreaseStock($productId, $bigNum, $smallNum, true);
             }
 
             $order = OrderClass::addOrder($post);

+ 12 - 30
app-hd/controllers/ProductController.php

@@ -51,7 +51,7 @@ class ProductController extends BaseController
 
         $itemInfoData = ProductClass::getAllByCondition($where, ['actualSold' => SORT_DESC, 'inTurn' => SORT_DESC], "*");
         $itemInfoData = ProductClass::groupProductInfo($itemInfoData);
-        $data = ProductService::assembleData($classIds,  $itemInfoData);
+        $data = ProductService::assembleData($classIds, $itemInfoData);
 
         util::success($data);
     }
@@ -108,34 +108,16 @@ class ProductController extends BaseController
     {
         $get = Yii::$app->request->get();
         $id = $get['id'] ?? 0;
-        $ghs = [];
-        if (!empty($id)) {
-            $ghs = GhsClass::getGhsInfo($id);
-            if (empty($ghs)) {
-                util::fail('没有找到供应商');
-            }
-            $sjId = $ghs['sjId'] ?? 0;
-            $shopId = $ghs['shopId'] ?? 0;
-            $customId = $ghs['customId'] ?? 0;
-            if (!empty($customId)) {
-                $custom = CustomClass::getById($customId, true);
-                if (isset($custom->black) && $custom->black == CustomClass::IS_BLACK) {
-                    $ghsName = $ghs['name'] ?? '';
-                    util::fail('您已被' . $ghsName . '列入黑名单');
-                }
-            }
-        } else {
-            $shopId = $get['shopId'] ?? 0;
-            if (empty($shopId)) {
-                util::fail('没有供应商信息');
-            }
-            $shop = ShopClass::getShopInfo($shopId);
-            if (empty($shop)) {
-                util::fail('没有供应商门店');
-            }
-            $sjId = $shop['sjId'] ?? 0;
+        $ghs = GhsClass::getGhsInfo($id);
+        if (empty($ghs)) {
+            util::fail('没有找到供应商');
+        }
+        $sjId = $ghs['sjId'] ?? 0;
+        $shopId = $ghs['shopId'] ?? 0;
+        $black = $ghs['black'] ?? 2;
+        if ($black == 2) {
+            util::fail('您已被列入黑名单');
         }
-
         $connection = Yii::$app->db;//事务处理
         $transaction = $connection->beginTransaction();
         try {
@@ -148,9 +130,9 @@ class ProductController extends BaseController
             $where['delStatus'] = 0;
             $where['status'] = 1;
 
-
+            $level = $ghs['giveLevel'] ?? 0;
             $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], "*");
-            $itemInfoData = ProductClass::groupProductInfo($itemInfoData);
+            $itemInfoData = ProductClass::groupProductInfo($itemInfoData, $level);
 
             $data = ProductService::assembleData($classIds, $itemInfoData, true);
 

+ 4 - 2
biz-ghs/order/classes/OrderItemClass.php

@@ -3,6 +3,7 @@
 namespace bizGhs\order\classes;
 
 use biz\product\classes\XjClass;
+use bizGhs\custom\classes\CustomClass;
 use bizGhs\product\classes\ProductClass;
 use common\components\imgUtil;
 use common\components\util;
@@ -49,7 +50,9 @@ class OrderItemClass extends BaseClass
     public static function replaceItem($orderSn, $product, $post = null)
     {
         $customId = $post['customId'] ?? 0;
-        $respond = ProductClass::formatProductInfo($product, $customId);
+        $custom = CustomClass::getById($customId, true);
+        $level = $custom->level ?? 0;
+        $respond = ProductClass::formatProductInfo($product, $level);
         $product = $respond['product'];
         self::deleteByCondition(['orderSn' => $orderSn]);
         foreach ($product as $key => $val) {
@@ -79,7 +82,6 @@ class OrderItemClass extends BaseClass
                 }
             }
         }
-
         self::batchAdd($product);
         return $respond;
     }

+ 16 - 28
biz-ghs/product/classes/ProductClass.php

@@ -96,17 +96,11 @@ class ProductClass extends BaseClass
     }
 
     //花材图片,名称,大小单位,小单位价格
-    public static function groupProductInfo($list)
+    public static function groupProductInfo($list, $level = 0)
     {
-
-        $customId = isset(Yii::$app->params['customId']) ? Yii::$app->params['customId'] : 0;
-        $customInfo = [];
-        if (empty($customId)) {
-            $customInfo = CustomClass::getById($customId, true);
-        }
-        $levelPriceKey = CustomClass::$levelPriceKeyMap;
-        $customLevel = $customInfo->level ?? 0;
-        $levelAddPriceKey = CustomClass::$levelAddPriceKeyMap;
+        //各个等级对应的price addPrice字段
+        $priceMap = CustomClass::$levelPriceKeyMap;
+        $addPriceMap = CustomClass::$levelAddPriceKeyMap;
 
         foreach ($list as $k => $v) {
             $shortCover = $v['cover'] ?? '';
@@ -129,26 +123,25 @@ class ProductClass extends BaseClass
             $list[$k]['bigNum'] = $stockInfo['bigNum'];
             $list[$k]['smallNum'] = $stockInfo['smallNum'];
             $list[$k]['itemName'] = $v['name'] ?? '';
-            //原价 shish 20210703
             $list[$k]['prePrice'] = $v['price'] ?? 0;
             $price = $v['price'] ?? 0;
 
             //价格相关控制!!!!!!!请搜索 price_control
-            if (empty($customInfo)) {
+            if (empty($level)) {
                 $discountPrice = $v['discountPrice'] ?? 0;
                 if ($discountPrice > 0) {
                     $price = $discountPrice;
                 }
             } else {
-                $currentPriceKey = $levelPriceKey[$customLevel] ?? 'price';
+                $currentPriceKey = $priceMap[$level] ?? 'price';
                 $price = $v[$currentPriceKey] ?? 0;
 
                 //特价
                 $discountPrice = $v['discountPrice'] ?? 0;
                 if ($discountPrice > 0) {
-                    $preAddPriceKey = $levelAddPriceKey[0] ?? 'addPrice';
+                    $preAddPriceKey = $addPriceMap[0] ?? 'addPrice';
                     $preAddPrice = $v[$preAddPriceKey] ?? 0;
-                    $currentAddPriceKey = $levelAddPriceKey[$customLevel] ?? 'addPrice';
+                    $currentAddPriceKey = $addPriceMap[$level] ?? 'addPrice';
                     $currentAddPrice = $v[$currentAddPriceKey] ?? 0;
                     $diff = bcsub($preAddPrice, $currentAddPrice, 2);
                     $price = bcsub($discountPrice, $diff, 2);
@@ -635,7 +628,7 @@ class ProductClass extends BaseClass
     }
 
     //下单时计算商品的价格  linqh 2021.1.28
-    public static function formatProductInfo($itemInfo, $customId = 0)
+    public static function formatProductInfo($itemInfo, $level = 0)
     {
         $data = [];
         if (empty($itemInfo)) {
@@ -650,14 +643,9 @@ class ProductClass extends BaseClass
         $totalBigNum = 0;
         $totalSmallNum = 0;
 
-        //不同的人卖不现价格
-        $customLevel = 0;
-        if (!empty($customId)) {
-            $custom = CustomClass::getById($customId, true);
-            $customLevel = $custom->level ?? 0;
-        }
-        $levelPriceKey = CustomClass::$levelPriceKeyMap;
-        $levelAddPriceKey = CustomClass::$levelAddPriceKeyMap;
+        //不同等级对应 price addPrice
+        $priceMap = CustomClass::$levelPriceKeyMap;
+        $addPriceMap = CustomClass::$levelAddPriceKeyMap;
 
         foreach ($itemInfo as $v) {
             $productId = $v['productId'];
@@ -668,7 +656,7 @@ class ProductClass extends BaseClass
             $itemNum = self::mergeItemNum($v['bigNum'], $v['smallNum'], $ratio);
 
             //价格相关控制!!!!!!!请搜索 price_control
-            if (empty($customId)) {
+            if (empty($level)) {
                 $itemPrice = $productData[$productId]['price'] ?? 0;
                 $discountPrice = $productData[$productId]['discountPrice'] ?? 0;
                 if ($discountPrice > 0) {
@@ -676,15 +664,15 @@ class ProductClass extends BaseClass
                 }
             } else {
 
-                $currentPriceKey = $levelPriceKey[$customLevel] ?? 'price';
+                $currentPriceKey = $priceMap[$level] ?? 'price';
                 $itemPrice = $productData[$productId][$currentPriceKey] ?? 0;
 
                 //特价
                 $discountPrice = $productData[$productId]['discountPrice'] ?? 0;
                 if ($discountPrice > 0) {
-                    $preAddPriceKey = $levelAddPriceKey[0] ?? 'addPrice';
+                    $preAddPriceKey = $addPriceMap[0] ?? 'addPrice';
                     $preAddPrice = $productData[$productId][$preAddPriceKey] ?? 0;
-                    $currentAddPriceKey = $levelAddPriceKey[$customLevel] ?? 'addPrice';
+                    $currentAddPriceKey = $addPriceMap[$level] ?? 'addPrice';
                     $currentAddPrice = $productData[$productId][$currentAddPriceKey] ?? 0;
                     $diff = bcsub($preAddPrice, $currentAddPrice, 2);
                     $itemPrice = bcsub($discountPrice, $diff, 2);

+ 7 - 13
biz-ghs/product/services/ProductService.php

@@ -20,13 +20,14 @@ class ProductService extends BaseService
     //组装分类花材数据
     public static function assembleData($classIds, $itemInfoData, $showTodayDiscount = false)
     {
-        $saleItem = []; //今日特价
+        //今日特价
+        $tjItem = [];
 
         if ($itemInfoData) {
             foreach ($itemInfoData as $v) {
                 $v['classId'] = self::ALL_CLASS_ID;
                 if (isset($v['discountPrice']) && $v['discountPrice'] > 0) {
-                    $saleItem[] = $v;
+                    $tjItem[] = $v;
                 }
             }
         }
@@ -37,14 +38,7 @@ class ProductService extends BaseService
                 $classMapItem[$v['classId']][] = $v['itemId'];
             }
         }
-        //今日特价
-        $saleData = [
-            [
-                'classId' => self::ALL_CLASS_ID,
-                'className' => '今日特价',
-                'child' => $saleItem,
-            ]
-        ];
+
         $classData = [];
 
         foreach ($classIds as $classVal) {
@@ -72,9 +66,9 @@ class ProductService extends BaseService
                 $classData[] = $tmp;
             }
         }
-
-        if ($showTodayDiscount && !empty($saleItem)) {
-            $classData = array_merge($saleData, $classData);
+        if ($showTodayDiscount && !empty($tjItem)) {
+            $tjClass = [['classId' => self::ALL_CLASS_ID, 'className' => '今日特价', 'child' => $tjItem,]];
+            $classData = array_merge($tjClass, $classData);
         }
         return $classData;
     }