|
|
@@ -388,6 +388,7 @@ class PurchaseClass extends BaseClass
|
|
|
$orderSn = orderSn::getPurchaseSn();
|
|
|
$data['orderSn'] = $orderSn;
|
|
|
$prePrice = 0;
|
|
|
+ $live = isset($ghs['live']) ? $ghs['live'] : 1;
|
|
|
$sendTimeWant = isset($data['sendTimeWant']) && !empty($data['sendTimeWant']) ? $data['sendTimeWant'] : date("Y-m-d");
|
|
|
if ($sendTimeWant < date("Y-m-d")) {
|
|
|
util::fail('您选了过去时间');
|
|
|
@@ -406,10 +407,16 @@ class PurchaseClass extends BaseClass
|
|
|
$sjId = $data['sjId'] ?? 0;
|
|
|
$mainId = $data['mainId'] ?? 0;
|
|
|
$ghsId = $data['ghsId'] ?? 0;
|
|
|
- $productList = ProductClass::toggleProductList($productList, $shopId, $sjId, $mainId);
|
|
|
|
|
|
- $productData = self::getProductMapData($productList, "productId");
|
|
|
- $hdProductData = self::getProductMapData($productList, "hdProductId");
|
|
|
+ if ($live == 1) {
|
|
|
+ //花店真实向批发店采购花材,因为拿的供货商的ID,所以需要转化花店的id
|
|
|
+ $productList = ProductClass::toggleProductList($productList, $shopId, $sjId, $mainId);
|
|
|
+ $ghsProductData = self::getProductMapData($productList, "ghsProductId");
|
|
|
+ } else {
|
|
|
+ //虚拟采购用的自己的ID所以不需要转化
|
|
|
+ $ghsProductData = [];
|
|
|
+ }
|
|
|
+ $hdProductData = self::getProductMapData($productList, "productId");
|
|
|
|
|
|
$giveLevel = $ghs['giveLevel'] ?? 0;
|
|
|
$priceMap = CustomClass::$levelPriceKeyMap;
|
|
|
@@ -427,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;
|
|
|
@@ -444,43 +456,46 @@ class PurchaseClass extends BaseClass
|
|
|
$currentWeight = bcmul($weight, $itemNum, 2);
|
|
|
$totalWeight = bcadd($currentWeight, $totalWeight, 2);
|
|
|
|
|
|
- //供货商开单改价,这个价格优先级最高
|
|
|
- $changePrice = isset($product['userPrice']) && $product['userPrice'] > 0 ? $product['userPrice'] : 0;
|
|
|
-
|
|
|
- $currentProduct = $productData[$productId] ?? [];
|
|
|
- $price = ProductClass::getFinalPrice($currentProduct, $giveLevel, $priceMap, $addPriceMap, $changePrice);
|
|
|
- $bigPrice = $price;
|
|
|
+ //1、供货商开单改价 2、花店向虚拟供货商采购录入价格
|
|
|
+ $userPrice = isset($product['userPrice']) && $product['userPrice'] > 0 ? $product['userPrice'] : 0;
|
|
|
+ $currentGhsProduct = $ghsProductData[$ghsProductId] ?? [];
|
|
|
+
|
|
|
+ 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 = $hdProductData[$hdProductId]['name'] ?? '';
|
|
|
- //用批发店的花材名称
|
|
|
- $itemName = $currentProduct['name'] ?? '';
|
|
|
- //$cover = $hdProductData[$hdProductId]['cover'] ?? '';
|
|
|
- $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);
|
|
|
@@ -490,16 +505,18 @@ 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;
|
|
|
+ $productList[$key]['name'] = $itemName;
|
|
|
+ $productList[$key]['cover'] = $cover;
|
|
|
|
|
|
$currentBigUnit = $hdProductData[$hdProductId]['bigUnit'] ?? '';
|
|
|
$currentSmallUnit = $hdProductData[$hdProductId]['smallUnit'] ?? '';
|
|
|
@@ -582,6 +599,7 @@ class PurchaseClass extends BaseClass
|
|
|
$data['bigNum'] = $bigNum;
|
|
|
$data['smallNum'] = $smallNum;
|
|
|
$data['discount'] = 1;
|
|
|
+ $data['status'] = self::STATUS_UN_PAY;
|
|
|
|
|
|
//采购单有效期
|
|
|
$currentTime = time();
|
|
|
@@ -643,147 +661,7 @@ class PurchaseClass extends BaseClass
|
|
|
//添加采购 ssh 2021.1.18
|
|
|
public static function updatePurchase($purchase, $data)
|
|
|
{
|
|
|
- $orderSn = $purchase->orderSn ?? '';
|
|
|
- $shopId = $purchase->shopId ?? 0;
|
|
|
- $sjId = $purchase->sjId ?? 0;
|
|
|
-
|
|
|
- $prePrice = 0;
|
|
|
-
|
|
|
- $data['sendTimeWant'] = date("Y-m-d") . ' ' . $data['sendTime'];
|
|
|
- unset($data['sendTime']);
|
|
|
-
|
|
|
- if (isset($data['product']) == false || empty($data['product'])) {
|
|
|
- util::fail('请选择花材');
|
|
|
- }
|
|
|
- $productList = $data['product'];
|
|
|
- $productList = self::mergeItemInfo($productList);
|
|
|
- $data['kindNum'] = count($productList); //多少种花材
|
|
|
- //供货商productId转成零售的productId
|
|
|
- $mainId = $purchase->mainId ?? 0;
|
|
|
- $productList = ProductClass::toggleProductList($productList, $shopId, $sjId, $mainId);
|
|
|
-
|
|
|
- $productData = self::getProductMapData($productList, "productId");
|
|
|
- $hdProductData = self::getProductMapData($productList, "hdProductId");
|
|
|
-
|
|
|
- //计算价格= 各个productId的price*num(bigNum,smallNum) + sendCost(配送费)
|
|
|
- $bigNum = 0; //总共多少扎
|
|
|
- $smallNum = 0; //总共多少支
|
|
|
- foreach ($productList as $key => $product) {
|
|
|
-
|
|
|
- $bigNum += $product['bigNum'] ?? 0;
|
|
|
- $smallNum += $product['smallNum'] ?? 0;
|
|
|
- $productList[$key]['orderSn'] = $orderSn;
|
|
|
- $productId = $product['productId'];
|
|
|
- $hdProductId = $product['hdProductId'];
|
|
|
-
|
|
|
- $ratio = $hdProductData[$hdProductId]['ratio'] ?? 0; //比例必须一致
|
|
|
- $itemId = $hdProductData[$hdProductId]['itemId'] ?? 0;
|
|
|
- $rank = $hdProductData[$hdProductId]['rank'] ?? 'B';// 花材级别
|
|
|
- $stock = $hdProductData[$hdProductId]['stock'] ?? 0;//当时库存
|
|
|
- $stockFormat = ProductClass::formatStock($stock, $ratio);
|
|
|
-
|
|
|
- $itemNum = ProductClass::mergeItemNum($product['bigNum'], $product['smallNum'], $ratio);//采购数量
|
|
|
- $price = $productData[$productId]['price']; //卖的单价
|
|
|
- //每个花材总价(原价)
|
|
|
- $productPrePrice = bcmul($itemNum, $price, 2); //采购总价
|
|
|
- //供货商开单的每个花材总价,可能会改价
|
|
|
- $productTotalPrice = isset($product['userPrice']) && $product['userPrice'] > 0 ? $product['userPrice'] : $productPrePrice;
|
|
|
-
|
|
|
- $itemInfo = [
|
|
|
- 'itemName' => $hdProductData[$hdProductId]['name'] ?? '',//花材名称
|
|
|
- 'itemCover' => $hdProductData[$hdProductId]['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);
|
|
|
- $productList[$key]['itemId'] = $itemId;
|
|
|
- $productList[$key]['itemNum'] = $itemNum;
|
|
|
- $productList[$key]['price'] = $price;
|
|
|
- $productList[$key]['ratio'] = $ratio;
|
|
|
- $productList[$key]['totalPrice'] = $productTotalPrice;
|
|
|
- $productList[$key]['preTotalPrice'] = $productPrePrice;
|
|
|
- $productList[$key]['productId'] = $hdProductId;
|
|
|
- $productList[$key]['ghsProductId'] = $productId;
|
|
|
- //小单位单价
|
|
|
- $smallPrice = bcdiv($price, $ratio, 2);
|
|
|
- $productList[$key]['smallPrice'] = $smallPrice;
|
|
|
-
|
|
|
- $prePrice = bcadd($prePrice, $productTotalPrice, 2);
|
|
|
-
|
|
|
- }
|
|
|
- //删除花材再添加
|
|
|
- PurchaseItemClass::deleteByCondition(['orderSn' => $orderSn]);
|
|
|
- PurchaseItemClass::batchAdd($productList);
|
|
|
-
|
|
|
- $data['itemPrice'] = $prePrice;
|
|
|
- $sendCost = $data['sendCost'] ?? 0.00;
|
|
|
- $prePrice = bcadd($prePrice, $sendCost, 2);
|
|
|
- $actPrice = $prePrice;
|
|
|
- $realPrice = $prePrice;
|
|
|
- if (isset($data['modifyPrice'])) {
|
|
|
- //商家打折,修改金额
|
|
|
- $modifyPrice = $data['modifyPrice'] ?? 0;
|
|
|
- if ($modifyPrice > $prePrice) {
|
|
|
- util::fail('实收金额大于订单总金额');
|
|
|
- }
|
|
|
- if ($modifyPrice < $prePrice) {
|
|
|
- $data['discountAmount'] = bcsub($prePrice, $modifyPrice, 2);
|
|
|
- $data['discountType'] = dict::getDict('discountType', 'discount');
|
|
|
- $actPrice = $modifyPrice;
|
|
|
- $realPrice = $modifyPrice;
|
|
|
- }
|
|
|
- } else {
|
|
|
- //验证优惠券
|
|
|
- $hbId = isset($data['hbId']) ? $data['hbId'] : 0;
|
|
|
- if (!empty($hbId)) {
|
|
|
- $coupon = ShopCouponClass::getLockById($hbId);
|
|
|
- ShopCouponClass::valid($coupon, $data['shopId']);
|
|
|
- if ($coupon->miniCost != 0 && $coupon->miniCost > $prePrice) {
|
|
|
- util::fail('达到最低消费才能使用优惠券');
|
|
|
- }
|
|
|
- if ($prePrice < $coupon->amount) {
|
|
|
- util::fail('总价应大于优惠金额');
|
|
|
- }
|
|
|
- $coupon->take = ShopCouponClass::TAKE_HAS;
|
|
|
- $coupon->save();
|
|
|
- $realPrice = bcsub($actPrice, $coupon->amount, 2);
|
|
|
- $data['discountType'] = dict::getDict('discountType', 'usePtCoupon');
|
|
|
- $data['discountAmount'] = $coupon->amount;
|
|
|
- $data['hbId'] = $hbId;
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- $data['prePrice'] = $prePrice;
|
|
|
- $data['actPrice'] = $actPrice;
|
|
|
- $data['realPrice'] = $realPrice;
|
|
|
- $data['bigNum'] = $bigNum;
|
|
|
- $data['smallNum'] = $smallNum;
|
|
|
- //采购单有效期
|
|
|
- $validTime = dict::getDict('order_pay_has_time');
|
|
|
- $current = time() + $validTime;
|
|
|
- $data['deadline'] = $data['deadline'] ?? date("Y-m-d H:i:s", $current);
|
|
|
-
|
|
|
- $purchaseId = $purchase->id ?? 0;
|
|
|
- self::updateById($purchaseId, $data);
|
|
|
- $respond = self::getLockById($purchaseId);
|
|
|
-
|
|
|
- $shop = ShopClass::getLockById($shopId);
|
|
|
- if (empty($shop)) {
|
|
|
- util::fail('没有找到门店');
|
|
|
- }
|
|
|
- $shop->cancelOrder -= 1;
|
|
|
- $shop->cgUnPay += 1;
|
|
|
- $shop->save();
|
|
|
-
|
|
|
- return $respond;
|
|
|
+ util::fail('已删除');
|
|
|
}
|
|
|
|
|
|
//组合数据 ssh 2021.1.25
|