Browse Source

采购 支付方式

shish 3 years ago
parent
commit
4e8949c0ff
2 changed files with 96 additions and 72 deletions
  1. 43 38
      biz-ghs/product/classes/ProductClass.php
  2. 53 34
      biz-hd/purchase/classes/PurchaseClass.php

+ 43 - 38
biz-ghs/product/classes/ProductClass.php

@@ -627,7 +627,6 @@ class ProductClass extends BaseClass
     }
 
 
-
     //加库存,允许负库存,负数数量(盘点时)
     public static function addStock($productId, $itemNumBundle, $itemNumPiece)
     {
@@ -1000,16 +999,23 @@ class ProductClass extends BaseClass
     }
 
     //下单时计算商品的价格  lqh 2021.1.28
-    public static function formatProductInfo($itemInfo, $level = 0)
+    public static function formatProductInfo($itemInfo, $level = 0, $live = 1)
     {
         $data = [];
         if (empty($itemInfo)) {
             util::fail('请选择花材');
         }
         $itemInfo = self::mergeItemInfo($itemInfo);
+
         $productIds = array_column($itemInfo, 'productId');
-        $productData = ProductClass::getProductByIds($productIds);
-        $productData = array_column($productData, NULL, 'id');
+        $ghsProductData = ProductClass::getProductByIds($productIds);
+        $ghsProductData = array_column($ghsProductData, NULL, 'id');
+        if ($live == 1) {
+            $hdProductData = [];
+        } else {
+            $hdIds = array_column($itemInfo, 'hdProductId');
+            $hdProductData = ProductClass::getByIds($hdIds, null, 'id');
+        }
 
         $totalPrice = 0;
         $totalBigNum = 0;
@@ -1022,11 +1028,12 @@ class ProductClass extends BaseClass
         $totalItemNum = 0;
 
         foreach ($itemInfo as $v) {
-            $productId = $v['productId'];
-            $itemId = $productData[$productId]['itemId'] ?? 0;
-            $ratio = $productData[$productId]['ratio'] ?? 0;
-            $smallRatio = $productData[$productId]['smallRatio'] ?? 1;
-            $cost = $productData[$productId]['cost'] ?? 0;
+            $ghsProductId = $v['productId'];
+
+            $currentGhsProduct = $ghsProductData[$ghsProductId] ?? [];
+            $itemId = $currentGhsProduct['itemId'] ?? 0;
+            $ratio = $currentGhsProduct['ratio'] ?? 0;
+            $cost = $currentGhsProduct['cost'] ?? 0;
 
             $bigNum = $v['bigNum'] ?? 0;
             $smallNum = $v['smallNum'] ?? 0;
@@ -1035,42 +1042,39 @@ class ProductClass extends BaseClass
             $itemNum = self::mergeItemNum($bigNum, $smallNum, $ratio);
             $totalItemNum = bcadd($totalItemNum, $itemNum, 2);
 
-            //供货商开单可以传单价过来
-            $changePrice = isset($v['price']) && $v['price'] > 0 ? $v['price'] : 0;
-
-            //今日特价、会员价
-            $currentProduct = $productData[$productId] ?? [];
-            $itemPrice = self::getFinalPrice($currentProduct, $level, $priceMap, $addPriceMap, $changePrice);
-
-            $bigItemPrice = $itemPrice;
+            if ($live == 1) {
+                //供货商开单可以传单价过来
+                $changePrice = isset($v['price']) && $v['price'] > 0 ? $v['price'] : 0;
+                //今日特价、会员价
+                $itemPrice = self::getFinalPrice($currentGhsProduct, $level, $priceMap, $addPriceMap, $changePrice);
+                $thisPrice = $itemPrice;
+            } else {
+                $itemPrice = $v['unitPrice'] ?? 0;
+                $thisPrice = $itemPrice;
+            }
 
             if ($smallNum > 0) {
-                //如果是小单位数量,则传过来的就是小单位价格,无需转换
-                if (empty($changePrice)) {
-                    $itemPrice = bcdiv($itemPrice, $ratio, 2);
-                    $itemPrice = bcmul($itemPrice, $smallRatio, 2);
-                }
                 $price = bcmul($smallNum, $itemPrice, 2);
             } else {
                 $price = bcmul($bigNum, $itemPrice, 2);
             }
 
             $tmp = [];
-            $tmp['productId'] = $productId;
+            $tmp['productId'] = $ghsProductId;
             $tmp['price'] = $price;
 
             $totalPrice = bcadd($totalPrice, $price, 2);
 
-            $tmp['name'] = $productData[$productId]['name'] ?? '';
-            $tmp['smallUnit'] = $productData[$productId]['smallUnit'] ?? '支';
-            $tmp['bigUnit'] = $productData[$productId]['bigUnit'] ?? '扎';
-            $tmp['cover'] = $productData[$productId]['cover'] ?? '';
+            $tmp['name'] = $currentGhsProduct['name'] ?? '';
+            $tmp['smallUnit'] = $currentGhsProduct['smallUnit'] ?? '支';
+            $tmp['bigUnit'] = $currentGhsProduct['bigUnit'] ?? '扎';
+            $tmp['cover'] = $currentGhsProduct['cover'] ?? '';
             $tmp['itemId'] = $itemId;
-            $tmp['rank'] = $productData[$productId]['rank'] ?? '';
-            $tmp['ratio'] = $productData[$productId]['ratio'] ?? 1;
-            $tmp['variety'] = $productData[$productId]['variety'] ?? 0;
-            $tmp['unitPrice'] = $bigItemPrice;
-            $tmp['unitWeight'] = $productData[$productId]['weight'] ?? 0;;
+            $tmp['rank'] = $currentGhsProduct['rank'] ?? '';
+            $tmp['ratio'] = $currentGhsProduct['ratio'] ?? 1;
+            $tmp['variety'] = $currentGhsProduct['variety'] ?? 0;
+            $tmp['unitPrice'] = $thisPrice;
+            $tmp['unitWeight'] = $currentGhsProduct['weight'] ?? 0;;
             $tmp['num'] = $itemNum;
             $tmp['bigNum'] = $v['bigNum'];
             $tmp['smallNum'] = $v['smallNum'];
@@ -1078,13 +1082,12 @@ class ProductClass extends BaseClass
             $tmp['preBigNum'] = $v['bigNum'];
             $tmp['preSmallNum'] = $v['smallNum'];
             $tmp['userPrice'] = $price;
-            $tmp['weight'] = $productData[$productId]['weight'] ?? 0;
-            $tmp['sjId'] = $productData[$productId]['sjId'] ?? 0;
-            $tmp['shopId'] = $productData[$productId]['shopId'] ?? 0;
-            $tmp['mainId'] = $productData[$productId]['mainId'] ?? 0;
+            $tmp['weight'] = $currentGhsProduct['weight'] ?? 0;
+            $tmp['sjId'] = $currentGhsProduct['sjId'] ?? 0;
+            $tmp['shopId'] = $currentGhsProduct['shopId'] ?? 0;
+            $tmp['mainId'] = $currentGhsProduct['mainId'] ?? 0;
             $tmp['smallUnitPrice'] = $itemPrice;
 
-
             $totalBigNum += $bigNum;
             $totalSmallNum += $smallNum;
 
@@ -1496,6 +1499,7 @@ class ProductClass extends BaseClass
 
         foreach ($productList as $k => $v) {
             $itemId = $v['itemId'] ?? 0;
+            $ghsProductId = $v['productId'] ?? 0;
             if (!isset($hdProductData[$itemId])) {
                 //不存在,则从平台新增
                 $ptItem = PtItemClass::getById($itemId);
@@ -1518,7 +1522,8 @@ class ProductClass extends BaseClass
             } else {
                 $hdProductId = $hdProductData[$itemId]['id'];
             }
-            $productList[$k]['hdProductId'] = $hdProductId;
+            $productList[$k]['productId'] = $hdProductId;
+            $productList[$k]['ghsProductId'] = $ghsProductId;
         }
 
         return $productList;

+ 53 - 34
biz-hd/purchase/classes/PurchaseClass.php

@@ -407,13 +407,16 @@ class PurchaseClass extends BaseClass
         $sjId = $data['sjId'] ?? 0;
         $mainId = $data['mainId'] ?? 0;
         $ghsId = $data['ghsId'] ?? 0;
-        //花店真实向批发店采购花材,因为拿的供货商的ID,所以则需要转化;虚拟采购用的自己的ID所以不需要转化
+
         if ($live == 1) {
+            //花店真实向批发店采购花材,因为拿的供货商的ID,所以需要转化花店的id
             $productList = ProductClass::toggleProductList($productList, $shopId, $sjId, $mainId);
+            $ghsProductData = self::getProductMapData($productList, "ghsProductId");
+        } else {
+            //虚拟采购用的自己的ID所以不需要转化
+            $ghsProductData = [];
         }
-
-        $productData = self::getProductMapData($productList, "productId");
-        $hdProductData = self::getProductMapData($productList, "hdProductId");
+        $hdProductData = self::getProductMapData($productList, "productId");
 
         $giveLevel = $ghs['giveLevel'] ?? 0;
         $priceMap = CustomClass::$levelPriceKeyMap;
@@ -431,8 +434,13 @@ class PurchaseClass extends BaseClass
             $bigNum += $product['bigNum'] ?? 0;
             $smallNum += $product['smallNum'] ?? 0;
             $productList[$key]['orderSn'] = $orderSn;
-            $productId = $product['productId'];
-            $hdProductId = $product['hdProductId'];
+            if ($live == 1) {
+                $ghsProductId = $product['ghsProductId'];
+                $hdProductId = $product['productId'];
+            } else {
+                $hdProductId = $product['productId'] ?? 0;
+                $ghsProductId = 0;
+            }
 
             $unitWeight = $hdProductData[$hdProductId]['weight'] ?? 0;
             $variety = $hdProductData[$hdProductId]['variety'] ?? 0;
@@ -448,40 +456,50 @@ class PurchaseClass extends BaseClass
             $currentWeight = bcmul($weight, $itemNum, 2);
             $totalWeight = bcadd($currentWeight, $totalWeight, 2);
 
-            //供货商开单改价,这个价格优先级最高
-            $changePrice = isset($product['userPrice']) && $product['userPrice'] > 0 ? $product['userPrice'] : 0;
+            //1、供货商开单改价 2、花店向虚拟供货商采购录入价格
+            $userPrice = isset($product['userPrice']) && $product['userPrice'] > 0 ? $product['userPrice'] : 0;
+            $currentGhsProduct = $ghsProductData[$ghsProductId] ?? [];
+
+            if (!empty($currentGhsProduct) && $userPrice > 0) {
+                util::fail('商城下单暂不支持小单位');
+            }
 
-            $currentProduct = $productData[$productId] ?? [];
-            $price = ProductClass::getFinalPrice($currentProduct, $giveLevel, $priceMap, $addPriceMap, $changePrice);
-            $bigPrice = $price;
+            if (!empty($currentGhsProduct)) {
+                //用批发店的花材名称
+                $itemName = $currentGhsProduct['name'] ?? '';
+                $cover = $currentGhsProduct['cover'] ?? '';
+                //用批发店花材的价格
+                $price = ProductClass::getFinalPrice($currentGhsProduct, $giveLevel, $priceMap, $addPriceMap, $userPrice);
+                $thisPrice = $price;
+            } else {
+                $currentHdProduct = $hdProductData[$hdProductId] ?? [];
+                if (empty($currentHdProduct)) {
+                    util::fail('花材有问题哦');
+                }
+                $itemName = $currentHdProduct['name'] ?? '';
+                $cover = $currentHdProduct['cover'] ?? '';
+                $price = $userPrice;
+                $thisPrice = $userPrice;
+            }
 
             if ($currentSmallNum > 0) {
-                //如果是小单位数量,则传过来的就是小单位价格,无需转换
-                if (empty($changePrice)) {
-                    $ghsRatio = $currentProduct['ratio'] ?? 0;
-                    $ghsSmallRatio = $currentProduct['smallRatio'] ?? 1;
-                    $price = bcdiv($price, $ghsRatio, 2);
-                    $price = bcmul($price, $ghsSmallRatio, 2);
-                }
                 $productTotalPrice = bcmul($currentSmallNum, $price, 2);
             } else {
                 $productTotalPrice = bcmul($currentBigNum, $price, 2);
             }
-            //用批发店的花材名称
-            $itemName = $currentProduct['name'] ?? '';
-            $cover = $currentProduct['cover'] ?? '';
+
             $itemInfo = [
-                'itemName' => $itemName,//花材名称
-                'itemCover' => $cover,//花材图片
-                'bigNum' => $product['bigNum'] ?? 0,//采购数量(大单位)
-                'smallNum' => $product['smallNum'] ?? 0,//采购数量(小单位)
-                'bigNumStock' => $stockFormat['bigNum'],// 当时库存大单位数
-                'smallNumStock' => $stockFormat['smallNum'],//当时库存 小单位数
-                'itemUnit' => $ratio ? 2 : 1,//单位
-                'ratio' => $ratio,// 比例
-                'rank' => $rank,// 花材级别
-                'bigUnit' => $hdProductData[$hdProductId]['bigUnit'],//大单位名称 扎
-                'smallUnit' => $hdProductData[$hdProductId]['smallUnit'],//小单位名称 支
+                'itemName' => $itemName,
+                'itemCover' => $cover,
+                'bigNum' => $product['bigNum'] ?? 0,
+                'smallNum' => $product['smallNum'] ?? 0,
+                'bigNumStock' => $stockFormat['bigNum'],
+                'smallNumStock' => $stockFormat['smallNum'],
+                'itemUnit' => $ratio ? 2 : 1,
+                'ratio' => $ratio,
+                'rank' => $rank,
+                'bigUnit' => $hdProductData[$hdProductId]['bigUnit'],
+                'smallUnit' => $hdProductData[$hdProductId]['smallUnit'],
             ];
 
             $productList[$key]['itemInfo'] = json_encode($itemInfo);
@@ -491,13 +509,13 @@ class PurchaseClass extends BaseClass
             $productList[$key]['itemNum'] = $itemNum;
             $productList[$key]['bigNum'] = $product['bigNum'] ?? 0;
             $productList[$key]['smallNum'] = $product['smallNum'] ?? 0;
-            $productList[$key]['price'] = $bigPrice;
+            $productList[$key]['price'] = $thisPrice;
             $productList[$key]['ratio'] = $ratio;
             $productList[$key]['unitWeight'] = $unitWeight;
             $productList[$key]['totalPrice'] = $productTotalPrice;
             $productList[$key]['preTotalPrice'] = $productTotalPrice;
             $productList[$key]['productId'] = $hdProductId;
-            $productList[$key]['ghsProductId'] = $productId;
+            $productList[$key]['ghsProductId'] = $ghsProductId;
             $productList[$key]['smallPrice'] = $price;
             $productList[$key]['mainId'] = $mainId;
             $productList[$key]['ghsId'] = $ghsId;
@@ -583,6 +601,7 @@ class PurchaseClass extends BaseClass
         $data['bigNum'] = $bigNum;
         $data['smallNum'] = $smallNum;
         $data['discount'] = 1;
+        $data['status'] = self::STATUS_UN_PAY;
 
         //采购单有效期
         $currentTime = time();