Просмотр исходного кода

Merge branch 'zhongqi-itemUpdate' into dev

shizhongqi 3 месяцев назад
Родитель
Сommit
bb07b298b4

+ 6 - 1
app-ghs/controllers/ProductController.php

@@ -158,7 +158,12 @@ class ProductController extends BaseController
             }
             $info->presell = $presell;
             $info->presellDate = $newStr;
-            $info->discountPrice = 0;
+
+            //$info->discountPrice = 0;
+            if ($presell == 1 && $info->discountPrice > 0) {
+                util::fail('已设置特价,无法开启预售');
+            }
+
             $info->save();
         }catch(\Exception $e){
             // 失败情况,要把缓存删除

+ 0 - 1
app-hd/controllers/ProductController.php

@@ -1091,5 +1091,4 @@ class ProductController extends BaseController
         $info->save();
         util::complete('取消成功');
     }
-
 }

+ 42 - 3
app-hd/controllers/PurchaseController.php

@@ -225,6 +225,32 @@ class PurchaseController extends BaseController
         }
     }
 
+    // 批发商的限购花材信息
+    public function actionLimitBuyInfo()
+    {
+        $post = Yii::$app->request->post();
+        $ghsId = $post['ghsId'] ?? 0;
+        $list = $post['list'] ?? [];
+        if (empty($ghsId)) {
+            util::fail('缺少供货商');
+        }
+        if (empty($list) || !is_array($list)) {
+            util::fail('请选择花材');
+        }
+
+        $ghsInfo = GhsClass::getById($ghsId);
+        if (empty($ghsInfo)) {
+            util::fail('没有找到供货商');
+        }
+        $customId = $ghsInfo['customId'] ?? 0;
+        if (empty($customId)) {
+            util::fail('没有找到客户');
+        }
+
+        $respond = ProductClass::getLimitBuyInfoByList($list, $customId);
+        util::success($respond);
+    }
+
     //生成采购单 ssh 2021.1.17
     public function actionCreateOrder()
     {
@@ -446,6 +472,19 @@ class PurchaseController extends BaseController
                     }
                 }
 
+                foreach ($productList as $itemData) {
+                    $productId = $itemData['productId'] ?? 0;
+                    $product = $productInfoList[$productId] ?? [];
+                    if (empty($product)) {
+                        util::fail('有商品信息没有找到');
+                    }
+                    $bigNum = $itemData['bigNum'] ?? 0;
+                    if (($product['limitBuy'] ?? 0) > 0) {
+                        $product['productId'] = $productId;
+                        ProductClass::handleLimitBuy($product, $customId, floatval($bigNum));
+                    }
+                }
+
             } else {
                 util::fail('花材不存在');
             }
@@ -776,7 +815,7 @@ class PurchaseController extends BaseController
 
             util::success($respond);
 
-        } catch (Exception $e) {
+        } catch (\Exception $e) {
             if ($transaction->isActive) {
                 $transaction->rollBack();
             }
@@ -928,7 +967,7 @@ class PurchaseController extends BaseController
                 }
 
             }
-        } catch (Exception $e) {
+        } catch (\Exception $e) {
             $transaction->rollBack();
             util::fail('支付失败');
         }
@@ -970,7 +1009,7 @@ class PurchaseController extends BaseController
             //余额支付
             purchaseService::balancePay($info);
             $transaction->commit();
-        } catch (Exception $e) {
+        } catch (\Exception $e) {
             $transaction->rollBack();
             util::fail('支付失败');
         }

+ 0 - 2
app-hd/controllers/WxOpenController.php

@@ -3,9 +3,7 @@
 namespace hd\controllers;
 
 use biz\wx\classes\WxOpenClass;
-use common\components\jsSDK;
 use common\components\util;
-use Yii;
 
 class WxOpenController extends BaseController
 {

+ 1 - 1
biz-ghs/order/classes/OrderClass.php

@@ -3096,7 +3096,7 @@ XL;
             $itemNum = floatval($itemNum);
             $payTime = $order->payTime ?? '';
             $payDate = date('m-d H:i', strtotime($payTime));
-            $content = '<TEXT x="400" y="30" font="12" w="2" h="2" r="90">' . $customName . '</TEXT>';
+            $content = '<TEXT x="400" y="30" font="12" w="3" h="3" r="90">' . $customName . '</TEXT>';
             $content .= '<TEXT x="280" y="30" font="12" w="2" h="2" r="90">' . $fullAddress . '</TEXT>';
             $content .= '<TEXT x="180" y="30" font="12" w="2" h="2" r="90">' . $customMobile . '  ' . $itemNum . '扎</TEXT>';
             $content .= '<TEXT x="86" y="30" font="12" w="2" h="2" r="90">' . $distName . ' ' . $payDate . '</TEXT>';

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

@@ -345,8 +345,8 @@ class OrderItemClass extends BaseClass
             $p['mainId'] = $mainId;
             $item = self::add($p, true);
 
-            $currentPtItemId = $item->itemId ?? 0;
-            $unitPrice = $p['unitPrice'] ?? 0;
+            $currentPtItemId = $item->itemId;
+            $unitPrice = $p['unitPrice'];
             if (isset($post['xj'][$currentPtItemId]) && !empty($post['xj'][$currentPtItemId])) {
                 $xjArr = $post['xj'][$currentPtItemId];
                 if (is_array($xjArr)) {

+ 83 - 1
biz-ghs/product/classes/ProductClass.php

@@ -1496,8 +1496,12 @@ class ProductClass extends BaseClass
                 if ($book == 1 && $customShopAdminId > 0) {
                     $itemPrice = 0.1;
                 } else {
+                    $limitKey = self::LIMIT_BUY_KEY . $ghsProductId;
+                    $hasBuyNum = Yii::$app->redis->executeCommand('HGET', [$limitKey, $custom['id']]);
+                    $hasBuyNum = $itemNum + ($hasBuyNum == null ? 0 : $hasBuyNum); // 已购买总数量
+
                     //今日特价、会员价
-                    $itemPrice = self::getFinalPrice($currentGhsProduct, $level, $priceMap, $addPriceMap, $changePrice, $itemNum);
+                    $itemPrice = self::getFinalPrice($currentGhsProduct, $level, $priceMap, $addPriceMap, $changePrice, $itemNum, $hasBuyNum);
                 }
                 $thisPrice = $itemPrice;
 
@@ -3003,6 +3007,84 @@ class ProductClass extends BaseClass
         return true;
     }
 
+    // 获取客户当前采购清单中各花材的限购情况
+    public static function getLimitBuyInfoByList($list, $customId)
+    {
+        if (empty($list) || !is_array($list)) {
+            return [];
+        }
+
+        $buyNumMap = [];
+        $ids = [];
+        foreach ($list as $item) {
+            $productId = $item['id'] ?? 0;
+            if (empty($productId)) {
+                continue;
+            }
+
+            $productId = intval($productId);
+            $bigNum = $item['bigCount'] ?? ($item['bigNum'] ?? 0);
+            $smallNum = $item['smallCount'] ?? ($item['smallNum'] ?? 0);
+            if (isset($buyNumMap[$productId]) == false) {
+                $buyNumMap[$productId] = [
+                    'bigNum' => 0,
+                    'smallNum' => 0,
+                ];
+            }
+            $buyNumMap[$productId]['bigNum'] = bcadd($buyNumMap[$productId]['bigNum'], $bigNum, 2);
+            $buyNumMap[$productId]['smallNum'] = bcadd($buyNumMap[$productId]['smallNum'], $smallNum, 2);
+            $ids[] = $productId;
+        }
+
+        $ids = array_values(array_unique($ids));
+        if (empty($ids)) {
+            return [];
+        }
+
+        $productData = self::getProductByIds($ids);
+        $productData = array_column($productData, null, 'id');
+        $respond = [];
+        foreach ($ids as $productId) {
+            $product = $productData[$productId] ?? [];
+            if (empty($product)) {
+                continue;
+            }
+
+            $limitBuy = $product['limitBuy'] ?? 0;
+            $isLimit = $limitBuy > 0 ? true : false;
+            $hasBuyNum = 0;
+            if ($isLimit) {
+                $limitKey = self::LIMIT_BUY_KEY . $productId;
+                $hasBuyNum = Yii::$app->redis->executeCommand('HGET', [$limitKey, $customId]);
+                $hasBuyNum = $hasBuyNum == null ? 0 : $hasBuyNum;
+            }
+
+            $buyNum = $buyNumMap[$productId] ?? [];
+            $ratio = $product['ratio'] ?? 1;
+            $currentBuyNum = self::mergeItemNum($buyNum['bigNum'] ?? 0, $buyNum['smallNum'] ?? 0, $ratio);
+            $totalBuyNum = bcadd($hasBuyNum, $currentBuyNum, 2);
+            $specialPrice = (
+                ($product['hjDiscountPrice'] ?? 0) > 0
+                && ($product['discountPrice'] ?? 0) > 0
+                && ($product['skDiscountPrice'] ?? 0) > 0
+            ) ? true : false;
+
+            $respond[] = [
+                'id' => $productId,
+                'name' => $product['name'] ?? '',
+                'isLimit' => $isLimit, //是否限购
+                'limitBuy' => (float)$limitBuy, //限购数量
+                'specialPrice' => $specialPrice, //是否特价
+                'hasBuyNum' => $isLimit ? (float)$hasBuyNum : 0, //已购买数量
+                'currentBuyNum' => (float)$currentBuyNum, //此次购买的数量
+                'reachLimitBuyNum' => ($isLimit && $totalBuyNum > $limitBuy) ? true : false, //是否达到限购数量
+                'exceedNum' => $isLimit ? (float)bcsub($hasBuyNum, $limitBuy, 2) : 0, //超出数量, 小于等于0表示未超出
+            ];
+        }
+
+        return $respond;
+    }
+
     /**
      * 限购处理
      * @param $product

+ 2 - 2
biz-hd/purchase/classes/PurchaseClass.php

@@ -819,11 +819,11 @@ class PurchaseClass extends BaseClass
             $kind = $hdProductData[$hdProductId]['kind'] ?? 0;
             $stockFormat = ProductClass::formatStock($stock, $ratio);
 
-            $limitKey = ProductClass::LIMIT_BUY_KEY . $hdProductId;
+            $limitKey = ProductClass::LIMIT_BUY_KEY . $ghsProductId; // 注意:要使用批发的花材id
             $hasNum = Yii::$app->redis->executeCommand('HGET', [$limitKey, $customId]);
             $hasBuyNum = $hasNum ?: 0;
             $itemNum = ProductClass::mergeItemNum($product['bigNum'], $product['smallNum'], $ratio);
-            $hasBuyNum = bcadd($itemNum, $hasBuyNum, 2);
+            $hasBuyNum = bcadd($itemNum, $hasBuyNum, 2);  // 已购买总数量
 
             $weight = $hdProductData[$hdProductId]['weight'] ?? 0;
             $currentWeight = bcmul($weight, $itemNum, 2);

+ 1 - 2
biz-hd/purchase/services/PurchaseService.php

@@ -127,8 +127,7 @@ class PurchaseService extends BaseService
             'sendDistance' => $sendDistance,
         ];
         $result = OrderClass::addOrder($arr,$custom);
-        $saleId = $result['id'] ?? 0;
-        $respond->saleId = $saleId;
+        $respond->saleId = $result['id'];
         $respond->save();
 
         return $respond;