shish 4 gadi atpakaļ
vecāks
revīzija
d0949e20a8

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

@@ -67,6 +67,7 @@ class PurchaseController extends BaseController
             $shopAdmin = $this->shopAdmin->attributes;
             $name = $shopAdmin['name'] ?? '';
             $post['shopAdminName'] = $name;
+            $post['mainId'] = $this->mainId;
             $product = $post['product'] ?? '';
             $productList = json_decode($product, true);
 

+ 91 - 14
biz-ghs/order/classes/OrderClass.php

@@ -105,17 +105,84 @@ class OrderClass extends BaseClass
 
     public static function arrival($order, $data)
     {
-        //product [{"productId":"3674","num":0,"price":1}]
+        if ($order->stockChange == 1) {
+            util::fail('重复操作');
+        }
         $product = $data['product'] ?? '';
         if (empty($product)) {
-            util::fail('请填写成本价和到货数量');
+            util::fail('没有花材?');
         }
-        $product = json_decode($product, true);
-        if (empty($product)) {
-            util::fail('没有填写成本价和到货数量');
+        $ids = [];
+        $format = [];
+        foreach ($product as $val) {
+            $productId = $val['productId'] ?? 0;
+            $ids[] = $productId;
+            $format[$productId] = $val;
         }
-        $ids = array_column($product, 'productId');
         $info = ProductClass::getByIds($ids, null, 'id');
+        $orderSn = $order->orderSn ?? '';
+        $list = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
+        if (empty($list)) {
+            util::fail('没有找到订单的花材');
+        }
+
+        $itemPrice = 0;
+        $weight = 0;
+        foreach ($list as $key => $val) {
+            $productId = $val->productId ?? 0;
+            $num = $format[$productId]['num'] ?? 0;
+            $unitPrice = $format[$productId]['price'] ?? 0;
+            $price = bcmul($unitPrice, $num, 2);
+            $val->cost = $unitPrice;
+            $val->unitPrice = $unitPrice;
+            $val->price = $price;
+            $val->bigNum = $num;
+            $val->num = $num;
+            $val->save();
+
+            $price = bcmul($num, $unitPrice, 2);
+            $itemPrice = bcadd($itemPrice, $price, 2);
+
+            $productWeight = $info[$productId]['weight'] ?? 0;
+            $currentWeight = bcmul($productWeight, $num, 2);
+            $weight = bcadd($currentWeight, $weight, 2);
+        }
+
+        $data['itemPrice'] = $itemPrice;
+        $sendCost = 0;
+        $currentPrice = bcadd($itemPrice, $sendCost, 2);
+
+        $shopId = $order->shopId ?? 0;
+        $shop = ShopClass::getById($shopId, true);
+        $kiloFee = $shop->kiloFee ?? 0;
+        $miniKilo = $shop->miniKilo ?? 0;
+        $calcWeight = $weight > $miniKilo ? $weight : $miniKilo;
+        $allKiloFee = bcmul($calcWeight, $kiloFee, 2);
+        $currentPrice = bcadd($currentPrice, $allKiloFee, 2);
+        $order->prePrice = $currentPrice;
+        $order->orderPrice = $currentPrice;
+        $order->actPrice = $currentPrice;
+        $order->realPrice = $currentPrice;
+        $order->stockChange = 1;
+        $order->save();
+        $bookPrice = $order->bookPrice ?? 0;
+        if ($bookPrice == $currentPrice) {
+            return true;
+        }
+        if ($bookPrice > $currentPrice) {
+            $refundPrice = bcsub($bookPrice, $currentPrice, 2);
+            //退款
+            RefundOrderClass::add($data, true);
+            //门店余额减少
+            ShopClass::saleRefundReduceBalance($shop, $refund, $refundPrice);
+        } else {
+            //欠款
+            $currentDebt = bcsub($currentPrice, $bookPrice, 2);
+            $order->debtPrice = $currentDebt;
+            $order->remainDebtPrice = $currentDebt;
+            $order->debt = OrderClass::DEBT_YES;
+            $order->save();
+        }
     }
 
     //添加订单 ssh 2019.12.5
@@ -135,8 +202,12 @@ class OrderClass extends BaseClass
         //花材
         $product = $data['product'];
         $book = $data['book'] ?? 0;
-        $stockLock = $book == 1 ? false : true;
-        $respond = OrderItemClass::replaceItem($orderSn, $product, $data, $stockLock);
+        $stockMayChange = true;
+        if ($book == 1) {
+            $stockMayChange = false;
+            $data['stockChange'] = 0;
+        }
+        $respond = OrderItemClass::replaceItem($orderSn, $product, $data, $stockMayChange);
 
         $sendCost = isset($data['sendCost']) && is_numeric($data['sendCost']) ? $data['sendCost'] : 0;
         $data['sendCost'] = $sendCost;
@@ -357,6 +428,7 @@ class OrderClass extends BaseClass
         $modifyProduct = ['type' => 'modifyProduct', 'show' => 0, 'disable' => 0, 'name' => '修改花材'];
         $confirm = ['type' => 'confirm', 'show' => 0, 'disable' => 1, 'name' => '确认'];
         $cancel = ['type' => 'cancel', 'show' => 0, 'disable' => 0, 'name' => '取消'];
+        $arrival = ['type' => 'arrival', 'show' => 0, 'disable' => 0, 'name' => '到货'];
 
         if ($isList) {
             //订单列表页显示的按钮
@@ -391,13 +463,18 @@ class OrderClass extends BaseClass
 
         } else {
             //订单详情页显示的按钮
+            if (isset($order['book']) && $order['book'] == 1 && isset($order['stockChange']) && $order['stockChange'] == 0) {
+                if ($order['status'] != self::ORDER_STATUS_UN_PAY && $order['status'] != self::ORDER_STATUS_CANCEL) {
+                    $arrival['show'] = 1;
+                }
+            }
 
             //待确认订单显示延期付和已付款
             if ($order['status'] == self::ORDER_STATUS_UN_PAY) {
                 $debtPay = ['type' => 'debtPay', 'show' => 0, 'disable' => 0, 'name' => '延期收款'];
                 $hasPay = ['type' => 'hasPay', 'show' => 0, 'disable' => 0, 'name' => '欠款'];
                 $confirm['disable'] = 0;
-                return [$print, $debtPay, $hasPay, $confirm, $cancel];
+                return [$print, $debtPay, $hasPay, $confirm, $cancel, $arrival];
             }
 
             //待配送订单显示打印、发货和自取
@@ -405,16 +482,16 @@ class OrderClass extends BaseClass
                 $selfGet = ['type' => 'selfGet', 'show' => 0, 'disable' => 1, 'name' => '自取'];
                 $send = ['type' => 'send', 'show' => 0, 'disable' => 1, 'name' => '发货'];
                 if ($order['hasItem'] == 2) {
-                    return [$print, $selfGet, $send];
+                    return [$print, $selfGet, $send, $arrival];
                 }
                 $selfGet['disable'] = 0;
                 $send['disable'] = 0;
-                return [$print, $selfGet, $send];
+                return [$print, $selfGet, $send, $arrival];
             }
             //配送中显示按钮
             if ($order['status'] == self::ORDER_STATUS_SENDING) {
                 $send = ['type' => 'send', 'show' => 0, 'disable' => 0, 'name' => '发货'];
-                return [$print, $send];
+                return [$print, $send, $arrival];
             }
             //完成
             if ($order['status'] == self::ORDER_STATUS_COMPLETE) {
@@ -423,14 +500,14 @@ class OrderClass extends BaseClass
                 if ($order['sendType'] == self::SEND_TYPE_NO) {
                     $send['show'] = 0;
                 }
-                return [$print, $send];
+                return [$print, $send, $arrival];
             }
             //取消订单置灰
             if ($order['status'] == self::ORDER_STATUS_CANCEL) {
                 $selfGet['disable'] = 1;
                 $send['disable'] = 1;
                 $print['disable'] = 1;
-                return [$modifyProduct];
+                return [$modifyProduct, $arrival];
             }
             return [];
         }

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

@@ -48,7 +48,7 @@ class OrderItemClass extends BaseClass
     }
 
     //添加修改花材 ssh 2021.1.22
-    public static function replaceItem($orderSn, $product, $post = null, $stockLock = false)
+    public static function replaceItem($orderSn, $product, $post = null, $stockMayChange = false)
     {
         $customId = $post['customId'] ?? 0;
         $custom = CustomClass::getById($customId, true);
@@ -95,18 +95,15 @@ class OrderItemClass extends BaseClass
             $w = bcmul($itemNum, $currentWeight, 2);
             $weight = bcadd($w, $weight, 2);
 
-            if ($stockLock == true) {
+            if ($stockMayChange == true) {
 
                 $checkStock = true;
                 $stockInfo = ProductClass::decreaseStock($productId, $bigNum, $smallNum, $checkStock);
-                //记录库存流水
                 $recordData = [];
                 $recordData['sjId'] = $post['sjId'] ?? 0;
                 $recordData['shopId'] = $post['shopId'] ?? 0;
-                //增加中央ID
                 $recordData['mainId'] = $post['mainId'] ?? 0;
                 $recordData['itemId'] = $val['itemId'] ?? 0;
-
                 $recordData['itemNum'] = $itemNum;
                 $recordData['oldStock'] = $stockInfo['oldStock'];
                 $recordData['newStock'] = $stockInfo['newStock'];

+ 61 - 5
biz-ghs/order/services/OrderService.php

@@ -15,6 +15,7 @@ use bizGhs\custom\classes\CustomClass;
 use bizGhs\order\classes\OrderClass;
 use bizGhs\order\classes\OrderExpressClass;
 use bizGhs\order\classes\OrderSendClass;
+use bizGhs\product\classes\ProductClass;
 use bizGhs\stat\classes\StatYjClass;
 use bizGhs\ws\services\WsService;
 use bizHd\cg\services\CgRefundService;
@@ -32,17 +33,69 @@ class OrderService extends BaseService
 
     public static $baseFile = '\bizGhs\order\classes\OrderClass';
 
-    //到货 ssh 20220321
     public static function arrival($order, $data)
     {
+        //product [{"productId":"3674","num":0,"price":1}]
+        $product = $data['product'] ?? '';
+        if (empty($product)) {
+            util::fail('请填写成本价和到货数量');
+        }
+        $product = json_decode($product, true);
+        if (empty($product)) {
+            util::fail('没有填写成本价和到货数量');
+        }
+        $data['product'] = $product;
         OrderClass::arrival($order, $data);
-        PurchaseClass::arrival($order, $data);
+        $cgId = $order->purchaseId ?? 0;
+        $cg = PurchaseClass::getById($cgId, true);
+        if (empty($cg)) {
+            util::fail('没有找到采购单');
+        }
+
+        //花材转换
+        $ids = array_column($product, 'productId');
+        $productInfo = ProductClass::getByIds($ids);
+        if (empty($productInfo)) {
+            util::fail('没有花材??');
+        }
+        $relation = [];
+        foreach ($productInfo as $p) {
+            $id = $p['id'] ?? 0;
+            $ptItemId = $p['itemId'] ?? 0;
+            $relation[$ptItemId] = $id;
+        }
+        $ptIds = array_keys($relation);
+        $cgMainId = $cg->mainId ?? 0;
+        $cgItem = ProductClass::getAllByCondition(['mainId' => $cgMainId, 'itemId' => ['in', $ptIds]], null, '*');
+        $relateInfo = [];
+        foreach ($cgItem as $it) {
+            $ptItemId = $it['itemId'] ?? 0;
+            $saleItemId = $relation[$ptItemId] ?? 0;
+            $cgItemId = $it['id'] ?? 0;
+            $relateInfo[$saleItemId] = $cgItemId;
+        }
+        $cgProduct = [];
+        foreach ($product as $pro) {
+            $price = $pro['price'] ?? 0;
+            $num = $pro['num'] ?? 0;
+            $productId = $pro['productId'] ?? 0;
+            $currentId = $relateInfo[$productId] ?? 0;
+            $cgProduct[] = [
+                'num' => $num,
+                'price' => $price,
+                'productId' => $currentId,
+            ];
+        }
+print_r($cgProduct);die;
+        $cgData = [
+            'product' => $cgProduct,
+        ];
+        PurchaseClass::arrival($cg, $cgData);
     }
 
     //添加订单
     public static function createFinishOrder($data, $custom, $hasPay = 1)
     {
-
         //有unitType数据,说明是收银台传过来的数据,转换成和手机端结构一致
         $hasUnitType = array_column($data['product'], 'unitType');
         if (!empty($hasUnitType)) {
@@ -116,8 +169,10 @@ class OrderService extends BaseService
 
         $remark = $data['remark'] ?? '';
         $xj = $data['xj'] ?? '';
-
+        $book = $data['book'] ?? 0;
+        $cgMainId = $ghs['ownMainId'] ?? 0;
         $purchaseData = [
+            'book' => $book,
             'product' => $currentProduct,
             'sendTimeWant' => $sendTimeWant,
             'sendCost' => $data['sendCost'] ?: '0.00',
@@ -139,7 +194,8 @@ class OrderService extends BaseService
             'getType' => $getType,
             'remark' => $remark,
             'xj' => $xj,
-            'discount' => 1
+            'discount' => 1,
+            'mainId' => $cgMainId,
         ];
         if (isset($data['deadline']) && !empty($data['deadline'])) {
             $purchaseData['deadline'] = $data['deadline'];

+ 45 - 3
biz-hd/purchase/classes/PurchaseClass.php

@@ -50,9 +50,20 @@ class PurchaseClass extends BaseClass
     const REFUND_YES = 2;
 
     //到货之后 ssh 20220321
-    public static function arrival($order, $data)
+    public static function arrival($cg, $data)
     {
-
+        if ($cg->stockChange == 1) {
+            util::fail('重复操作');
+        }
+        $product = $data['product'] ?? '';
+        if (empty($product)) {
+            util::fail('请填写成本价和到货数量');
+        }
+        $product = json_decode($product, true);
+        if (empty($product)) {
+            util::fail('没有填写成本价和到货数量');
+        }
+        $info = ProductClass::getByIds($ids, null, 'id');
     }
 
     //添加采购 ssh 2021.1.18
@@ -136,8 +147,10 @@ class PurchaseClass extends BaseClass
             $productList[$key]['itemInfo'] = json_encode($itemInfo);
             $productList[$key]['variety'] = $variety;
             $productList[$key]['itemId'] = $itemId;
-            $productList[$key]['itemNum'] = $itemNum;
             $productList[$key]['preItemNum'] = $itemNum;
+            $productList[$key]['itemNum'] = $itemNum;
+            $productList[$key]['bigNum'] = $product['bigNum'] ?? 0;
+            $productList[$key]['smallNum'] = $product['smallNum'] ?? 0;
             $productList[$key]['price'] = $price;
             $productList[$key]['ratio'] = $ratio;
             $productList[$key]['totalPrice'] = $productTotalPrice;
@@ -158,6 +171,7 @@ class PurchaseClass extends BaseClass
 
         //预订单需要增加服务费
         $book = $data['book'] ?? 0;
+        $stockMayChange = true;
         if ($book == 1) {
             $kiloFee = $ghs['kiloFee'] ?? 0;
             $miniKilo = $ghs['miniKilo'] ?? 0;
@@ -167,6 +181,9 @@ class PurchaseClass extends BaseClass
             $data['allKiloFee'] = $allKiloFee;
             $data['kiloFee'] = $kiloFee;
             $data['miniKilo'] = $miniKilo;
+
+            $stockMayChange = false;
+            $data['stockChange'] = 0;
         }
 
         $actPrice = $prePrice;
@@ -239,6 +256,7 @@ class PurchaseClass extends BaseClass
         $respond = self::add($data, true);
 
         foreach ($productList as $productKey => $productVal) {
+            //增加采购单的花材
             $returnItem = PurchaseItemClass::add($productVal, true);
             //小菊
             if (isset($returnItem->variety) && $returnItem->variety == 1) {
@@ -261,6 +279,30 @@ class PurchaseClass extends BaseClass
                     }
                 }
             }
+            //库存变化
+            if ($stockMayChange == true) {
+                $checkStock = true;
+                $productId = $productVal['productId'] ?? 0;
+                $itemNum = $productVal['itemNum'] ?? 0;
+                $bigNum = $proDuctVal['bigNum'] ?? 0;
+                $smallNum = $proDuctVal['smallNum'] ?? 0;
+                $ptItemId = $proDuctVal['itemId'] ?? 0;
+                //$stockInfo = ProductClass::decreaseStock($productId, $bigNum, $smallNum, $checkStock);
+                //记录库存流水
+                $recordData = [];
+                $recordData['sjId'] = $data['sjId'] ?? 0;
+                $recordData['shopId'] = $data['shopId'] ?? 0;
+                //增加中央ID
+                $recordData['mainId'] = $data['mainId'] ?? 0;
+                $recordData['itemId'] = $ptItemId;
+                $recordData['itemNum'] = $itemNum;
+                //$recordData['oldStock'] = $stockInfo['oldStock'];
+                //$recordData['newStock'] = $stockInfo['newStock'];
+                $recordData['productId'] = $productId;
+                $recordData['orderSn'] = $orderSn;
+                $recordData['relateName'] = $ghs['name'] ?? '';
+                //StockRecordClass::addSellStockOrderRecord($recordData);
+            }
         }
 
         $shop = ShopClass::getLockById($shopId);

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

@@ -66,7 +66,9 @@ class PurchaseService extends BaseService
         $sendTimeWant = isset($data['sendTimeWant']) && !empty($data['sendTimeWant']) ? $data['sendTimeWant'] : date("Y-m-d");
         $orderType = 2;
         $book = $data['book'] ?? 0;
+        $mainId = $custom['ownMainId'] ?? 0;
         $arr = [
+            'mainId' => $mainId,
             'book' => $book,
             'product' => $product,
             'sjId' => $currentSjId,

+ 29 - 28
console/controllers/InitController.php

@@ -19,12 +19,14 @@ use biz\stat\classes\StatOutClass;
 use biz\stat\classes\StatOutMonthClass;
 use biz\stat\classes\StatSaleClass;
 use biz\stat\classes\StatSaleMonthClass;
+use bizGhs\custom\classes\CustomClass;
 use bizGhs\item\classes\ItemClass;
 use bizGhs\item\classes\ItemClassClass;
 use bizGhs\order\classes\StockWastageOrderClass;
 use bizGhs\order\classes\StockWastageOrderItemClass;
 use bizGhs\stat\classes\StatYjClass;
 use bizGhs\stat\classes\StatYjMonthClass;
+use bizHd\ghs\classes\GhsClass;
 use bizHd\goods\classes\CategoryClass;
 use bizHd\goods\classes\GoodsCategoryClass;
 use bizHd\goods\classes\GoodsClass;
@@ -104,6 +106,8 @@ class InitController extends Controller
             StatCgGhsClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
             StatCgGhsMonthClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
 
+            CustomClass::updateByCondition(['ownShopId' => $shopId], ['ownMainId' => $mainId]);
+
 
             /********琦海 start ************/
 
@@ -119,34 +123,28 @@ class InitController extends Controller
 
             //todo 分店需要建立自己独立的分类 和 花材与分类关系 --待测试
             //花材分类
-            $sjId = $shop->sjId;
-            if($mainId){
-                //判断花材分类是否存在
-                $itemClassResByMainId = ItemClassClass::getAllByCondition(['mainId'=>$mainId,'sjId'=>$sjId],null,"*");
-                if(empty($itemClassResByMainId)){
-                    //无,则要新增花材分类,根据sjId
-                    $itemClassResBySjId = ItemClassClass::getAllByCondition(['sjId'=>$sjId],null,"*");
-                    if($itemClassResBySjId){
-                        foreach ($itemClassResBySjId as $itemClass){
-                            $data = $itemClass;
-                            $oldItemClassId = $data['id'];
-                            unset($data['id']);
-                            unset($data['addTime']);
-                            unset($data['updateTime']);
-                            $data['mainId'] = $mainId;
-                            $save = ItemClassClass::add($data);
-                            $newItemClassId = $save['id'];
-                            ItemClass::updateByCondition(['shopId' => $shopId,'classId'=>$oldItemClassId], ['mainId' => $mainId,'classId'=>$newItemClassId]);
-                        }
-                    }
-                }
-            }
-
-
-//todo 临时处理
-if($shop->default == 1){
-    ItemClassClass::updateByCondition(['sjId' => $shop->sjId], ['mainId' => $mainId]);
-}
+//            $sjId = $shop->sjId;
+//            if($mainId){
+//                //判断花材分类是否存在
+//                $itemClassResByMainId = ItemClassClass::getAllByCondition(['mainId'=>$mainId,'sjId'=>$sjId],null,"*");
+//                if(empty($itemClassResByMainId)){
+//                    //无,则要新增花材分类,根据sjId
+//                    $itemClassResBySjId = ItemClassClass::getAllByCondition(['sjId'=>$sjId],null,"*");
+//                    if($itemClassResBySjId){
+//                        foreach ($itemClassResBySjId as $itemClass){
+//                            $data = $itemClass;
+//                            $oldItemClassId = $data['id'];
+//                            unset($data['id']);
+//                            unset($data['addTime']);
+//                            unset($data['updateTime']);
+//                            $data['mainId'] = $mainId;
+//                            $save = ItemClassClass::add($data);
+//                            $newItemClassId = $save['id'];
+//                            ItemClass::updateByCondition(['shopId' => $shopId,'classId'=>$oldItemClassId], ['mainId' => $mainId,'classId'=>$newItemClassId]);
+//                        }
+//                    }
+//                }
+//            }
 
 
             /********琦海 end ************/
@@ -185,6 +183,9 @@ if($shop->default == 1){
 
             FestRiseClass::updateByCondition(['sjId' => $sjId], ['mainId' => $mainId]);
 
+            GhsClass::updateByCondition(['ownShopId' => $shopId], ['ownMainId' => $mainId]);
+
+
             /********琦海 start ************/
 
             //花材

+ 7 - 1
sql.txt

@@ -618,4 +618,10 @@ ALTER TABLE xhCg ADD bookPrice DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '预
 ALTER TABLE xhCg ADD miniKilo SMALLINT(6) NOT NULL DEFAULT '0' COMMENT '最少公斤数' AFTER `weight`;
 ALTER TABLE xhGhsOrder ADD miniKilo SMALLINT(6) NOT NULL DEFAULT '0' COMMENT '最少公斤数' AFTER `weight`;
 
-====预订单 ssh 20220321
+ALTER TABLE xhGhsOrder CHANGE `stockLock` `stockChange` TINYINT(4) NOT NULL DEFAULT '1' COMMENT '0库存没有变动 1库存有变动';
+ALTER TABLE xhCg CHANGE `stockLock` `stockChange` TINYINT(4) NOT NULL DEFAULT '1' COMMENT '0库存没有变动 1库存有变动';
+
+ALTER TABLE xhGhs ADD ownMainId INT NOT NULL DEFAULT 0 COMMENT '中央id' AFTER `ownShopId`;
+ALTER TABLE xhGhsCustom ADD ownMainId INT NOT NULL DEFAULT 0 COMMENT '中央id' AFTER `ownShopId`;
+
+====预订单 ssh 20220321