Ver Fonte

待入库

shish há 3 anos atrás
pai
commit
572d44ac70

+ 5 - 2
app-ghs/controllers/PurchaseOrderController.php

@@ -129,7 +129,7 @@ class PurchaseOrderController extends BaseController
         $post['adminId'] = $this->adminId;
         $post['mainId'] = $this->mainId;
         $staff = $this->shopAdmin;
-        $post['staffId'] = $staff->id??0;
+        $post['staffId'] = $staff->id ?? 0;
         $post['staffName'] = $staff->name ?? '';
 
         $shopAdmin = $this->shopAdmin;
@@ -186,7 +186,10 @@ class PurchaseOrderController extends BaseController
                 }
             }
             $post['itemInfo'] = $ghsItemInfo;
-            $post['debt'] = PurchaseOrderClass::DEBT_YES;
+            //0稍后入库 1直接入库
+            $inType = $post['inType'] ?? PurchaseOrderClass::IN_TYPE_NOW;
+            $debtStatus = $inType == 1 ? PurchaseOrderClass::DEBT_YES : PurchaseOrderClass::DEBT_UNKNOWN;
+            $post['debt'] = $debtStatus;
             $order = PurchaseOrderClass::addOrder($post);
             $transaction->commit();
             util::success($order);

+ 178 - 166
biz-ghs/order/classes/PurchaseOrderClass.php

@@ -30,15 +30,15 @@ class PurchaseOrderClass extends BaseClass
     public static $baseFile = '\bizGhs\order\models\PurchaseOrder';
 
     const PURCHASE_ORDER_STATUS_WAIT = 1; //待确认
-    const PURCHASE_ORDER_STATUS_UN_SEND = 2; //待配送
-    const PURCHASE_ORDER_STATUS_SENDING = 3; //配送中
-    const PURCHASE_ORDER_STATUS_COMPLETE = 4; //已完成
+    const PURCHASE_ORDER_STATUS_UN_SEND = 2; //待配送,待发货
+    const PURCHASE_ORDER_STATUS_SENDING = 3; //配送中,待入库
+    const PURCHASE_ORDER_STATUS_COMPLETE = 4; //已入库
 
     public static $statusMap = [
         self::PURCHASE_ORDER_STATUS_WAIT => '待确认',
         self::PURCHASE_ORDER_STATUS_UN_SEND => '待配送',
-        self::PURCHASE_ORDER_STATUS_SENDING => '配送中',
-        self::PURCHASE_ORDER_STATUS_COMPLETE => '已完成',
+        self::PURCHASE_ORDER_STATUS_SENDING => '待入库',
+        self::PURCHASE_ORDER_STATUS_COMPLETE => '已入库',
     ];
 
     const DEBT_UNKNOWN = 0;
@@ -49,6 +49,10 @@ class PurchaseOrderClass extends BaseClass
     const YF_PAY_WAY_JF = 1;
     const YF_PAY_WAY_DF = 2;
 
+    //稍后入库和直接入库
+    const IN_TYPE_LATER = 0;
+    const IN_TYPE_NOW = 1;
+
     //添加采购单 lqh 2021.1.19
     public static function addOrder($data)
     {
@@ -58,10 +62,12 @@ class PurchaseOrderClass extends BaseClass
         $ghsName = $data['ghsName'] ?? '';
         $staffId = $data['staffId'] ?? 0;
         $staffName = $data['staffName'] ?? '';
+        $inType = $data['inType'] ?? self::IN_TYPE_NOW;
         $adminId = $data['adminId'] ?? 0;
-        $data['status'] = self::PURCHASE_ORDER_STATUS_COMPLETE;
         $orderSn = orderSn::getGhsPurchaseSn();
         $data['orderSn'] = $orderSn;
+        $status = $inType == self::IN_TYPE_NOW ? self::PURCHASE_ORDER_STATUS_COMPLETE : self::PURCHASE_ORDER_STATUS_SENDING;
+        $data['status'] = $status;
         //数据结构 [{itemId:0,bigNum:0,smallNum:0,productId:12,itemPrice:1,weight:1}]
         $ghsItemInfo = $data['itemInfo'];
         $ghsItemInfo = self::mergeItemInfo($ghsItemInfo);
@@ -202,21 +208,24 @@ class PurchaseOrderClass extends BaseClass
             foreach ($batchData as $currentKey => $v) {
                 $itemId = $v['itemId'];
                 $productId = $v['productId'];
-                //流水记录
-                $record = [];
-                $record['sjId'] = $sjId;
-                $record['shopId'] = $shopId;
-                $record['mainId'] = $mainId;
-                $record['orderSn'] = $orderSn;
-                $record['productId'] = $productId;
-                $record['itemId'] = $itemId;
-                $record['relateName'] = $ghsName;
-                $record['itemNum'] = $v['itemNum'];
-                $record['oldStock'] = $v['itemStock'];
-                $record['newStock'] = bcadd($v['itemStock'], $v['itemNum'], 2);
-                StockRecordClass::addPurchaseOrderRecord($record);
-                //加库存
-                ProductClass::addStockByItemNum($productId, $v['itemNum']);
+
+                if ($inType == self::IN_TYPE_NOW) {
+                    //流水记录
+                    $record = [];
+                    $record['sjId'] = $sjId;
+                    $record['shopId'] = $shopId;
+                    $record['mainId'] = $mainId;
+                    $record['orderSn'] = $orderSn;
+                    $record['productId'] = $productId;
+                    $record['itemId'] = $itemId;
+                    $record['relateName'] = $ghsName;
+                    $record['itemNum'] = $v['itemNum'];
+                    $record['oldStock'] = $v['itemStock'];
+                    $record['newStock'] = bcadd($v['itemStock'], $v['itemNum'], 2);
+                    StockRecordClass::addPurchaseOrderRecord($record);
+                    //加库存
+                    ProductClass::addStockByItemNum($productId, $v['itemNum']);
+                }
 
                 //单位采购价
                 $unitCgPrice = $v['bigPrice'] ?? 0;
@@ -239,161 +248,164 @@ class PurchaseOrderClass extends BaseClass
                 $batchData[$currentKey]['smallUnit'] = $currentSmallUnit;
                 $batchData[$currentKey]['ratio'] = $currentRatio;
 
-                $product = ProductClass::getLockById($productId);
-                $product->cost = $unitCost;
-                $product->priceLabel = ProductClass::PRICE_LABEL_AUTO;
-                $product->save();
-
-                //成本变动记录
-                $changeData = [
-                    'ptStyle' => 2,
-                    'sjId' => $sjId,
-                    'mainId' => $mainId,
-                    'itemId' => $productId,
-                    'ptItemId' => $itemId,
-                    'cost' => $unitCost,
-                    'staffId' => $staffId,
-                    'staffName' => $staffName,
-                    'name' => $product->name ?? '',
-                    'cover' => $product->cover ?? '',
-                    'targetId' => $order->id ?? 0,
-                    'event' => '采购',
-                ];
-                CostChangeClass::addData($changeData);
-
-                if (isset($shop->default) && $shop->default == 1) {
-                    //直营门店的成本价也要一起改掉
-                    $allShop = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
-                    if (!empty($allShop)) {
-                        $currentItemId = $product->itemId ?? 0;
-                        foreach ($allShop as $currentShop) {
-                            $currentId = $currentShop->mainId ?? 0;
-                            if ($currentId == $mainId) {
-                                continue;
-                            }
-                            if (isset($currentShop->join) && $currentShop->join == 1) {
-                                continue;
-                            }
-                            $currentProduct = ProductClass::getByCondition(['mainId' => $currentId, 'itemId' => $currentItemId], true);
-                            if (!empty($currentProduct)) {
-                                $currentProduct->cost = $unitCost;
-                                $currentProduct->save();
-                                $currentStaff = ShopAdminClass::getByCondition(['mainId' => $currentProduct->mainId, 'adminId' => $adminId], true);
-                                //成本变动记录
-                                $changeData = [
-                                    'ptStyle' => 2,
-                                    'sjId' => $currentProduct->sjId ?? 0,
-                                    'mainId' => $currentProduct->mainId ?? 0,
-                                    'itemId' => $currentProduct->id ?? 0,
-                                    'ptItemId' => $currentProduct->itemId ?? 0,
-                                    'cost' => $unitCost,
-                                    'staffId' => $currentStaff->id ?? 0,
-                                    'staffName' => $currentStaff->name ?? '',
-                                    'name' => $currentProduct->name ?? '',
-                                    'cover' => $currentProduct->cover ?? '',
-                                    'targetId' => $order->id ?? 0,
-                                    'event' => $shop->shopName . '采购',
-                                ];
-                                CostChangeClass::addData($changeData);
+                if ($inType == self::IN_TYPE_NOW) {
+                    $product = ProductClass::getLockById($productId);
+                    $product->cost = $unitCost;
+                    $product->priceLabel = ProductClass::PRICE_LABEL_AUTO;
+                    $product->save();
+                    //成本变动记录
+                    $changeData = [
+                        'ptStyle' => 2,
+                        'sjId' => $sjId,
+                        'mainId' => $mainId,
+                        'itemId' => $productId,
+                        'ptItemId' => $itemId,
+                        'cost' => $unitCost,
+                        'staffId' => $staffId,
+                        'staffName' => $staffName,
+                        'name' => $product->name ?? '',
+                        'cover' => $product->cover ?? '',
+                        'targetId' => $order->id ?? 0,
+                        'event' => '采购',
+                    ];
+                    CostChangeClass::addData($changeData);
+                    if (isset($shop->default) && $shop->default == 1) {
+                        //直营门店的成本价也要一起改掉
+                        $allShop = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
+                        if (!empty($allShop)) {
+                            $currentItemId = $product->itemId ?? 0;
+                            foreach ($allShop as $currentShop) {
+                                $currentId = $currentShop->mainId ?? 0;
+                                if ($currentId == $mainId) {
+                                    continue;
+                                }
+                                if (isset($currentShop->join) && $currentShop->join == 1) {
+                                    continue;
+                                }
+                                $currentProduct = ProductClass::getByCondition(['mainId' => $currentId, 'itemId' => $currentItemId], true);
+                                if (!empty($currentProduct)) {
+                                    $currentProduct->cost = $unitCost;
+                                    $currentProduct->save();
+                                    $currentStaff = ShopAdminClass::getByCondition(['mainId' => $currentProduct->mainId, 'adminId' => $adminId], true);
+                                    //成本变动记录
+                                    $changeData = [
+                                        'ptStyle' => 2,
+                                        'sjId' => $currentProduct->sjId ?? 0,
+                                        'mainId' => $currentProduct->mainId ?? 0,
+                                        'itemId' => $currentProduct->id ?? 0,
+                                        'ptItemId' => $currentProduct->itemId ?? 0,
+                                        'cost' => $unitCost,
+                                        'staffId' => $currentStaff->id ?? 0,
+                                        'staffName' => $currentStaff->name ?? '',
+                                        'name' => $currentProduct->name ?? '',
+                                        'cover' => $currentProduct->cover ?? '',
+                                        'targetId' => $order->id ?? 0,
+                                        'event' => $shop->shopName . '采购',
+                                    ];
+                                    CostChangeClass::addData($changeData);
+                                }
                             }
                         }
                     }
                 }
+
             }
 
             //写入详情表
             PurchaseOrderItemClass::batchAddOrderItem($batchData);
 
-            //门店支出增加
-            $mainId = $shop->mainId ?? 0;
-            $main = MainClass::getLockById($mainId);
-            if (empty($main)) {
-                util::fail('没有资产信息');
-            }
-            //支出增加
-            $currentTotalExpend = bcadd($main->totalExpend, $currentPrice, 2);
-            $main->totalExpend = $currentTotalExpend;
-            $main->save();
-
-            //采购增加
-            $main->cgFinish += 1;
-            $main->totalPurchaseOrder += 1;
-            $currentTotalPurchase = bcadd($main->totalPurchase, $currentPrice, 2);
-            $main->totalPurchase = $currentTotalPurchase;
-            $main->save();
-
-            //供货商资产增加
-            $ghsId = $data['ghsId'] ?? 0;
-            $ghs = GhsClass::getLockById($ghsId);
-            if (empty($ghs)) {
-                util::fail('没有找到供货商');
-            }
-            $ghs->debt = GhsClass::DEBT_YES;
-            $ghs->debtAmount = bcadd($ghs->debtAmount, $currentPrice, 2);
-
-            $ghs->debtNum += 1;
-            $ghs->expendAmount = bcadd($ghs->expendAmount, $currentPrice, 2);
-            $ghs->expendNum += 1;
-            $ghs->save();
-
-            //采购统计
-            $cgNum = $order->itemNum ?? 0;
-            StatCgClass::replace($main, $shop, $currentPrice, $cgNum);
-            //采购按供货商统计
-            StatCgGhsClass::ghsReplace($order);
-
-            //门店应收客户款增加
-            $ghsShopId = $ghs->shopId;
-            $ghsShop = ShopClass::getLockById($ghsShopId);
-            if (empty($ghsShop)) {
-                util::fail('没有找到门店');
-            }
-            $ghsMainId = $ghsShop->mainId ?? 0;
-            $ghsMain = \bizGhs\shop\classes\MainClass::getLockById($ghsMainId);
-            if (empty($ghsMain)) {
-                util::fail('没有main信息');
-            }
-            $currentMayGathering = bcadd($ghsMain->mayGathering, $currentPrice, 2);
-            $ghsMain->mayGathering = $currentMayGathering;
-
-            //客户资产增加
-            $customId = $ghs->customId;
-            $custom = CustomClass::getLockById($customId);
-            if (empty($custom)) {
-                util::fail('没有找到客户信息');
-            }
-            $custom->isDebt = CustomClass::IS_DEBT_YES;
-            $custom->debtAmount = bcadd($custom->debtAmount, $currentPrice, 2);
-            if ($custom->debtNum == 0) {
-                $ghsMain->mayGatheringNum += 1;
+            if ($inType == self::IN_TYPE_NOW) {
+                //门店支出增加
+                $mainId = $shop->mainId ?? 0;
+                $main = MainClass::getLockById($mainId);
+                if (empty($main)) {
+                    util::fail('没有资产信息');
+                }
+                //支出增加
+                $currentTotalExpend = bcadd($main->totalExpend, $currentPrice, 2);
+                $main->totalExpend = $currentTotalExpend;
+                $main->save();
+
+                //采购增加
+                $main->cgFinish += 1;
+                $main->totalPurchaseOrder += 1;
+                $currentTotalPurchase = bcadd($main->totalPurchase, $currentPrice, 2);
+                $main->totalPurchase = $currentTotalPurchase;
+                $main->save();
+
+                //供货商资产增加
+                $ghsId = $data['ghsId'] ?? 0;
+                $ghs = GhsClass::getLockById($ghsId);
+                if (empty($ghs)) {
+                    util::fail('没有找到供货商');
+                }
+                $ghs->debt = GhsClass::DEBT_YES;
+                $ghs->debtAmount = bcadd($ghs->debtAmount, $currentPrice, 2);
+
+                $ghs->debtNum += 1;
+                $ghs->expendAmount = bcadd($ghs->expendAmount, $currentPrice, 2);
+                $ghs->expendNum += 1;
+                $ghs->save();
+
+                //采购统计
+                $cgNum = $order->itemNum ?? 0;
+                StatCgClass::replace($main, $shop, $currentPrice, $cgNum);
+                //采购按供货商统计
+                StatCgGhsClass::ghsReplace($order);
+
+                //门店应收客户款增加
+                $ghsShopId = $ghs->shopId;
+                $ghsShop = ShopClass::getLockById($ghsShopId);
+                if (empty($ghsShop)) {
+                    util::fail('没有找到门店');
+                }
+                $ghsMainId = $ghsShop->mainId ?? 0;
+                $ghsMain = \bizGhs\shop\classes\MainClass::getLockById($ghsMainId);
+                if (empty($ghsMain)) {
+                    util::fail('没有main信息');
+                }
+                $currentMayGathering = bcadd($ghsMain->mayGathering, $currentPrice, 2);
+                $ghsMain->mayGathering = $currentMayGathering;
+
+                //客户资产增加
+                $customId = $ghs->customId;
+                $custom = CustomClass::getLockById($customId);
+                if (empty($custom)) {
+                    util::fail('没有找到客户信息');
+                }
+                $custom->isDebt = CustomClass::IS_DEBT_YES;
+                $custom->debtAmount = bcadd($custom->debtAmount, $currentPrice, 2);
+                if ($custom->debtNum == 0) {
+                    $ghsMain->mayGatheringNum += 1;
+                }
+                $ghsMain->save();
+                $custom->debtNum += 1;
+                $custom->buyNum += 1;
+                $custom->buyAmount = bcadd($custom->buyAmount, $currentPrice, 2);
+                $custom->save();
+
+                //当天和当月支出统计
+                StatOutClass::updateOrInsert($main, $shop, $currentPrice);
+                //支出流水
+                $payWay = dict::getDict('payWay', 'unknown');
+                $capitalType = dict::getDict('capitalType', 'ghsPurchase', 'id');
+                $sjId = $order->sjId ?? 0;
+                $shopId = $order->shopId ?? 0;
+                $event = '采购';
+                $mainId = $shop->mainId ?? 0;
+                $capitalData = [
+                    'capitalType' => $capitalType,
+                    'io' => 0,
+                    'totalExpend' => $currentTotalExpend,
+                    'payWay' => $payWay,
+                    'amount' => $currentPrice,
+                    'sjId' => $sjId,
+                    'shopId' => $shopId,
+                    'event' => $event,
+                    'mainId' => $mainId
+                ];
+                ShopCapitalClass::addCapital($capitalData);
             }
-            $ghsMain->save();
-            $custom->debtNum += 1;
-            $custom->buyNum += 1;
-            $custom->buyAmount = bcadd($custom->buyAmount, $currentPrice, 2);
-            $custom->save();
-
-            //当天和当月支出统计
-            StatOutClass::updateOrInsert($main, $shop, $currentPrice);
-            //支出流水
-            $payWay = dict::getDict('payWay', 'unknown');
-            $capitalType = dict::getDict('capitalType', 'ghsPurchase', 'id');
-            $sjId = $order->sjId ?? 0;
-            $shopId = $order->shopId ?? 0;
-            $event = '采购';
-            $mainId = $shop->mainId ?? 0;
-            $capitalData = [
-                'capitalType' => $capitalType,
-                'io' => 0,
-                'totalExpend' => $currentTotalExpend,
-                'payWay' => $payWay,
-                'amount' => $currentPrice,
-                'sjId' => $sjId,
-                'shopId' => $shopId,
-                'event' => $event,
-                'mainId' => $mainId
-            ];
-            ShopCapitalClass::addCapital($capitalData);
 
             $transaction->commit();
             return $order;