shish před 4 roky
rodič
revize
69643e0ac8

+ 6 - 4
biz-ghs/order/classes/OrderClass.php

@@ -106,7 +106,7 @@ class OrderClass extends BaseClass
     public static function arrival($order, $data)
     {
         if ($order->stockChange == 1) {
-            util::fail('重复操作');
+            util::fail('您已操作过了');
         }
         $product = $data['product'] ?? '';
         if (empty($product)) {
@@ -148,7 +148,7 @@ class OrderClass extends BaseClass
             $weight = bcadd($currentWeight, $weight, 2);
         }
 
-        $data['itemPrice'] = $itemPrice;
+        $order->itemPrice = $itemPrice;
         $sendCost = 0;
         $currentPrice = bcadd($itemPrice, $sendCost, 2);
 
@@ -166,10 +166,11 @@ class OrderClass extends BaseClass
         $order->stockChange = 1;
         $order->save();
         $bookPrice = $order->bookPrice ?? 0;
+
+        $refundId = 0;
         if ($bookPrice == $currentPrice) {
             return true;
-        }
-        if ($bookPrice > $currentPrice) {
+        } elseif ($bookPrice > $currentPrice) {
 //            $refundPrice = bcsub($bookPrice, $currentPrice, 2);
 //            //退款
 //            RefundOrderClass::add($data, true);
@@ -183,6 +184,7 @@ class OrderClass extends BaseClass
             $order->debt = OrderClass::DEBT_YES;
             $order->save();
         }
+        return ['kiloFee' => $kiloFee, 'refundId' => $refundId, 'miniKilo' => $miniKilo];
     }
 
     //添加订单 ssh 2019.12.5

+ 10 - 10
biz-ghs/order/services/OrderService.php

@@ -45,7 +45,9 @@ class OrderService extends BaseService
             util::fail('没有填写成本价和到货数量');
         }
         $data['product'] = $product;
-        OrderClass::arrival($order, $data);
+
+        //供应商到货
+        $respond = OrderClass::arrival($order, $data);
 
         $cgId = $order->purchaseId ?? 0;
         $cg = PurchaseClass::getById($cgId, true);
@@ -53,7 +55,7 @@ class OrderService extends BaseService
             util::fail('没有找到采购单');
         }
 
-        //花材转换
+        //供应商花材转换为零售店花材
         $ids = array_column($product, 'productId');
         $ghsProductInfo = ProductClass::getByIds($ids);
         if (empty($ghsProductInfo)) {
@@ -66,7 +68,6 @@ class OrderService extends BaseService
             $ghsPtIdRelation[$ptItemId] = $id;
         }
         $ptIds = array_keys($ghsPtIdRelation);
-
         $cgMainId = $cg->mainId ?? 0;
         $cgItem = ProductClass::getAllByCondition(['mainId' => $cgMainId, 'itemId' => ['in', $ptIds]], null, '*');
         $ghsHdIdRelate = [];
@@ -83,16 +84,15 @@ class OrderService extends BaseService
             $num = $pro['num'] ?? 0;
             $productId = $pro['productId'] ?? 0;
             $currentId = $ghsHdIdRelate[$productId] ?? 0;
-            $cgProduct[] = [
-                'num' => $num,
-                'price' => $price,
-                'productId' => $currentId,
-            ];
+            $cgProduct[$currentId] = ['num' => $num, 'price' => $price, 'productId' => $currentId];
         }
-        print_r($cgProduct);
-        die;
+        //零售到货
+        $kiloFee = $respond['kiloFee'] ?? 0;
+        $miniKilo = $respond['miniKilo'] ?? 0;
         $cgData = [
             'product' => $cgProduct,
+            'kiloFee' => $kiloFee,
+            'miniKilo' => $miniKilo,
         ];
         PurchaseClass::arrival($cg, $cgData);
     }

+ 7 - 3
biz-ghs/product/classes/ProductClass.php

@@ -1141,14 +1141,18 @@ class ProductClass extends BaseClass
             $data['zsPrice'] = $zsPrice;
 
             //根据sjId, 找到所有的shopId,都添加
-            $shopIds = ShopService::getShopIds($data['sjId']);
-            foreach ($shopIds as $shopId) {
+            $shopList = ShopClass::getAllByCondition(['sjId' => $data['sjId']], null, '*', null, true);
+            foreach ($shopList as $shop) {
+                $shopId = $shop->id ?? 0;
+                $currentMainId = $shop->mainId ?? 0;
                 $data['shopId'] = $shopId;
+                $data['mainId'] = $currentMainId;
                 //非当前门店库存默认为0并且是下架状态
                 if ($currentShopId != $shopId) {
                     $data['stock'] = 0;
                     $data['status'] = 2;
                 }
+
                 $res = self::add($data);
                 if ($stock > 0 && $res && $currentShopId == $shopId) {
                     //有库存数量,增加盘盈记录 2021.7.9 linqh
@@ -1198,7 +1202,7 @@ class ProductClass extends BaseClass
                     $record['sjId'] = $data['sjId'];
                     $record['shopId'] = $data['shopId'];
                     //增加中央ID
-                    $record['mainId'] = $data['mainId'];
+                    $record['mainId'] = $currentMainId;
                     $record['orderSn'] = $pdOrderSn;
                     $record['itemId'] = $data['itemId'];
                     $record['productId'] = $res['id'];

+ 58 - 5
biz-hd/purchase/classes/PurchaseClass.php

@@ -53,17 +53,70 @@ class PurchaseClass extends BaseClass
     public static function arrival($cg, $data)
     {
         if ($cg->stockChange == 1) {
-            util::fail('重复操作');
+            util::fail('您已操作过了');
         }
         $product = $data['product'] ?? '';
         if (empty($product)) {
             util::fail('请填写成本价和到货数量');
         }
-        $product = json_decode($product, true);
-        if (empty($product)) {
-            util::fail('没有填写成本价和到货数量');
+        $orderSn = $cg->orderSn ?? '';
+        $list = PurchaseItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
+        if (empty($list)) {
+            util::fail('没有找到花材哦');
+        }
+        $weight = 0;
+        $itemPrice = 0;
+        foreach ($list as $key => $val) {
+            $productId = $val->productId ?? 0;
+            if (isset($product[$productId]) == false) {
+                util::fail('没有找到对应采购花材');
+            }
+            $num = $product[$productId]['num'] ?? 0;
+            $price = $product[$productId]['price'] ?? 0;
+            $totalPrice = bcmul($num, $price, 2);
+            $itemPrice = bcadd($itemPrice, $totalPrice, 2);
+            $val->price = $price;
+            $val->itemNum = $num;
+            $val->preTotalPrice = $totalPrice;
+            $val->totalPrice = $totalPrice;
+            $val->save();
+            $unitWeight = $val->unitWeight ?? 0;
+            $currentWeight = bcmul($num, $unitWeight, 2);
+            $weight = bcadd($weight, $currentWeight, 2);
+        }
+
+        $cg->itemPrice = $itemPrice;
+        $sendCost = 0;
+        $currentPrice = bcadd($itemPrice, $sendCost, 2);
+        $kiloFee = $data['kiloFee'] ?? 0;
+        $miniKilo = $data['miniKilo'] ?? 0;
+        $calcWeight = $weight > $miniKilo ? $weight : $miniKilo;
+        $allKiloFee = bcmul($calcWeight, $kiloFee, 2);
+        $currentPrice = bcadd($currentPrice, $allKiloFee, 2);
+        $cg->prePrice = $currentPrice;
+        $cg->orderPrice = $currentPrice;
+        $cg->actPrice = $currentPrice;
+        $cg->realPrice = $currentPrice;
+        $cg->stockChange = 1;
+        $cg->save();
+        $bookPrice = $cg->bookPrice ?? 0;
+        if ($bookPrice == $currentPrice) {
+            return true;
+        } elseif ($bookPrice > $currentPrice) {
+            //退款
+//            $refundPrice = bcsub($bookPrice, $currentPrice, 2);
+//            //退款
+//            RefundOrderClass::add($data, true);
+//            //门店余额减少
+//            ShopClass::saleRefundReduceBalance($shop, $refund, $refundPrice);
+        } else {
+            //欠款
+            $currentDebt = bcsub($currentPrice, $bookPrice, 2);
+            $cg->debtPrice = $currentDebt;
+            $cg->remainDebtPrice = $currentDebt;
+            $cg->debt = PurchaseClass::DEBT_YES;
+            $cg->save();
         }
-        $info = ProductClass::getByIds($ids, null, 'id');
     }
 
     //添加采购 ssh 2021.1.18

+ 5 - 0
sql.txt

@@ -627,4 +627,9 @@ ALTER TABLE xhGhsCustom ADD ownMainId INT NOT NULL DEFAULT 0 COMMENT '中央id'
 ALTER TABLE xhGhsOrderItem ADD unitWeight DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '单位重量' AFTER `smallUnitPrice`;
 ALTER TABLE xhCgItem ADD unitWeight DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '单位重量' AFTER `variety`;
 
+ALTER TABLE xhRefund ADD book TINYINT NOT NULL DEFAULT 0 COMMENT '0非预订退款,有花材详情 1预订退款,暂无详情页' AFTER `cgRefundId`;
+ALTER TABLE xhCgRefund ADD book TINYINT NOT NULL DEFAULT 0 COMMENT '0非预订退款,有花材详情 1预订退款,暂无详情页' AFTER `saleRefundId`;
+ALTER TABLE xhRefund MODIFY `status` TINYINT(2) UNSIGNED NOT NULL DEFAULT '0' COMMENT '0 处理中 1已完成';
+ALTER TABLE xhCgRefund MODIFY `status` TINYINT(2) UNSIGNED NOT NULL DEFAULT '0' COMMENT '0 处理中 1已完成';
+
 ====预订单 ssh 20220321