shish пре 4 година
родитељ
комит
855fd1d01e

+ 3 - 1
app-ghs/controllers/RefundController.php

@@ -67,6 +67,8 @@ class RefundController extends BaseController
             $refundType = $post['refundType'] ?? 1;
 
             if ($refundType == RefundOrderClass::REFUND_TYPE_MONEY_GOOD) {
+                //花材列表结构
+                // [{productId:0,num:1,unitType:0,unitPrice:12,unitName:'扎'}] productId 花材id num 退货数 unitType 大小单位0大1小 unitPrice 售价 unitName单位名称
                 $productJson = $post['product'] ?? '';
                 if (empty($productJson)) {
                     util::fail('请选择花材');
@@ -79,7 +81,7 @@ class RefundController extends BaseController
                 $post['product'] = $productList;
             } else {
                 //仅退款花材直接设置为空
-                $post['product'] = '';
+                $post['product'] = [];
             }
             $post['price'] = $post['price'] ?? 0;
             if ($post['price'] <= 0) {

+ 48 - 24
biz-ghs/order/classes/RefundOrderItemClass.php

@@ -2,6 +2,10 @@
 
 namespace bizGhs\order\classes;
 
+use biz\stat\classes\StatItemClass;
+use bizGhs\product\classes\ProductClass;
+use bizGhs\stock\classes\StockRecordClass;
+use common\components\dict;
 use Yii;
 use bizGhs\base\classes\BaseClass;
 
@@ -12,34 +16,54 @@ class RefundOrderItemClass extends BaseClass
 
     public static function addData($data)
     {
-
-        //退货加库存
-        foreach ($productInfo as $k => $v) {
-            $stockInfo = ProductClass::addStock($v['productId'], $v['bigNum'], $v['smallNum']);
-            $productInfo[$k]['oldStock'] = $stockInfo['oldStock'];
-            $productInfo[$k]['newStock'] = $stockInfo['newStock'];
+        $productId = $data['productId'] ?? 0;
+        $mainId = $data['mainId'] ?? 0;
+        $unitType = $data['xhUnitType'] ?? 0;
+        $num = $data['xhNum'] ?? 0;
+        $xhUnitPrice = $data['xhUnitPrice'] ?? 0;
+        $xhNum = $data['xhNum'] ?? 0;
+        $totalNum = $data['itemNum'] ?? 0;
+        $orderSn = $data['orderSn'] ?? '';
+
+        if ($unitType == dict::getDict('unitType', 'small')) {
+            $smallNum = $num;
+            $bigNum = 0;
+        } else {
+            $smallNum = 0;
+            $bigNum = $num;
         }
 
-
-        $batchData = RefundOrderClass::groupOrderItem($productInfo, $orderSn, $orderItemData);
-        RefundOrderItemClass::batchAddOrderItem($batchData);
+        //退货加库存
+        $stockInfo = ProductClass::addStock($productId, $bigNum, $smallNum);
+        $oldStock = $stockInfo['oldStock'] ?? 0;
+        $newStock = $stockInfo['newStock'] ?? 0;
+        $data['itemStock'] = $oldStock;
+        $data['newStock'] = $newStock;
+        self::add($data);
 
         //花材销量统计变动
-        foreach ($batchData as $refundItemInfo) {
-            StatItemClass::refundReplace($refundItemInfo);
-        }
-
-
-        $orderData = RefundOrderClass::getOrderDetail($orderSn, $refund->shopId);
-        $orderData['shopId'] = $data['shopId'];
-
-        //增加库存变动记录
-        if ($data['refundType'] == RefundOrderClass::REFUND_TYPE_MONEY_GOOD) {
-            $orderData['relateName'] = $order->customName ?? '';
-            StockRecordClass::addRecordByOrder($orderData, StockRecordClass::STOCK_RECORD_TYPE_REFUND);
-        }
-
-
+        $refundStat = [
+            'mainId' => $mainId,
+            'productId' => $productId,
+            'itemNum' => $xhNum,
+            'itemPrice' => $xhUnitPrice,
+        ];
+        StatItemClass::refundReplace($refundStat);
+
+        //库存变动记录
+        $recordData = [];
+        $recordData['shopId'] = $data['shopId'];
+        $recordData['relateName'] = $order->customName ?? '';
+        $recordData['itemNum'] = $totalNum;
+        $recordData['sjId'] = $data['sjId'] ?? 0;
+        $recordData['shopId'] = $data['shopId'] ?? 0;
+        $recordData['mainId'] = $data['mainId'] ?? 0;
+        $recordData['orderSn'] = $orderSn;
+        $recordData['itemId'] = $data['itemId'] ?? 0;
+        $recordData['oldStock'] = $oldStock; //当时库存
+        $recordData['productId'] = $productId;
+        $recordData['newStock'] = $newStock;// 最新库存
+        StockRecordClass::ghsRefundAddRecord($recordData);
     }
 
     public static function batchAddOrderItem($data)

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

@@ -785,6 +785,11 @@ class OrderService extends BaseService
         $saleRefund = RefundOrderService::addRefund($post, $order);
         $saleRefundId = $saleRefund->id;
 
+        //花材列表结构
+        // [{productId:0,num:1,unitType:0,unitPrice:12,unitName:'扎'}] productId 花材id num 退货数 unitType 大小单位0大1小 unitPrice 售价 unitName单位名称
+        $ghsProduct = $post['product'] ?? '';
+
+
         //零售采购单退款
         $cgRefund = CgRefundService::addRefund($post, $order);
         $cgRefundId = $cgRefund->id;

+ 15 - 8
biz-ghs/order/services/RefundOrderService.php

@@ -53,10 +53,10 @@ class RefundOrderService extends BaseService
         $data['shopAdminId'] = $post['shopAdminId'] ?? 0;
         $data['shopAdminName'] = $post['shopAdminName'] ?? '';
 
-        //花材列表 [{productId:0,num:1,unitType:0}] productId 花材id num 退货数 unitType 大小单位0大1小
         $postProduct = $post['product'] ?? '';
-
         if ($data['refundType'] == RefundOrderClass::REFUND_TYPE_MONEY_GOOD) {
+            //花材列表结构
+            // [{productId:0,num:1,unitType:0,unitPrice:12,unitName:'扎'}] productId 花材id num 退货数 unitType 大小单位0大1小 unitPrice 售价 unitName单位名称
             if (empty($postProduct)) {
                 util::fail('没有退款花材');
             }
@@ -72,10 +72,16 @@ class RefundOrderService extends BaseService
             foreach ($postProduct as $currentProduct) {
                 $id = $currentProduct['productId'] ?? 0;
                 $num = $currentProduct['num'] ?? 0;
+                $xhUnitName = $currentProduct['unitName'] ?? '';
+                $xhUnitPrice = $currentProduct['unitPrice'] ?? '';
                 $unitType = $currentProduct['unitType'] ?? 0;
+
+                $xhPrice = bcmul($num, $xhUnitPrice, 2);
+
                 $name = $productInfo[$id]['name'] ?? '';
                 $ptItemId = $productInfo[$id]['itemId'] ?? 0;
                 $itemCost = $productInfo[$id]['cost'] ?? 0;
+                $ratio = $productInfo[$id]['ratio'] ?? 0;
 
                 $xhNum = $orderItemData[$id]['xhNum'] ?? 0;
                 $refundNum = $orderItemData[$id]['refundNum'] ?? 0;
@@ -84,6 +90,11 @@ class RefundOrderService extends BaseService
                     util::fail("{$name}超过可退数量");
                 }
 
+                $itemNum = $num;
+                if ($unitType == dict::getDict('unitType', 'small')) {
+                    $itemNum = bcdiv($num, $ratio, 2);
+                }
+
                 $thisItemData = [
                     'sjId' => $sjId,
                     'shopId' => $shopId,
@@ -91,31 +102,28 @@ class RefundOrderService extends BaseService
                     'productId' => $id,
                     'name' => $name,
                     'itemId' => $ptItemId,
-                    'itemStock' => 0,
                     'itemCost' => $itemCost,
-                    'newStock' => 0,
+                    'itemNum' => $itemNum,
                     'xhNum' => $xhNum,
                     'xhUnitName' => $xhUnitName,
                     'xhUnitType' => $unitType,
                     'xhUnitPrice' => $xhUnitPrice,
                     'xhPrice' => $xhPrice,
+                    'mainId' => $mainId,
                 ];
                 RefundOrderItemClass::addData($thisItemData);
             }
 
         }
 
-
         $data['customId'] = $order->customId ?? 0;
         $data['remark'] = $post['remark'] ?? '';
         $data['refundPrice'] = $refundPrice;
         $data['refundType'] = $post['refundType'] ?? 0;
 
-
         //写入订单表
         $refund = RefundOrderClass::add($data, true);
 
-
         $payWay = $order->payWay;
         $shopId = $order->shopId;
         $shop = ShopClass::getLockById($shopId);
@@ -156,7 +164,6 @@ class RefundOrderService extends BaseService
         $order->refund = OrderClass::REFUND_YES;
         $order->save();
 
-
         //退款流程
         if ($payWay == dict::getDict('payWay', 'wxPay')) {
 

+ 8 - 1
biz-ghs/stock/classes/StockRecordClass.php

@@ -105,7 +105,7 @@ class StockRecordClass extends BaseClass
             $record['sjId'] = $orderData['sjId'];
             $record['shopId'] = $orderData['shopId'];
             //增加mainId
-            $record['mainId'] = $productData[$productId]['mainId']??0;
+            $record['mainId'] = $productData[$productId]['mainId'] ?? 0;
             $record['orderSn'] = $orderData['orderSn'];
             $record['itemId'] = $itemId;
             $record['itemNum'] = $itemNum;
@@ -118,6 +118,13 @@ class StockRecordClass extends BaseClass
         }
     }
 
+    //供应商给零售店退款退货增加库存变动记录 ssh 20220330
+    public static function ghsRefundAddRecord($refundRecord)
+    {
+        $refundRecord['recordType'] = self::STOCK_RECORD_TYPE_REFUND;
+        self::add($refundRecord);
+    }
+
     //采购订单流水记录
     public static function addPurchaseOrderRecord($data)
     {

+ 8 - 24
biz-hd/cg/services/CgRefundService.php

@@ -60,7 +60,6 @@ class CgRefundService extends BaseService
             util::fail('没有找到门店');
         }
 
-        $ghsItemInfo = $post['product'] ?? '';
         $data = [];
         $data['status'] = CgRefundClass::STATUS_COMPLETE;
         $data['orderSn'] = $refundOrderSn;
@@ -70,38 +69,22 @@ class CgRefundService extends BaseService
         $data['shopAdminId'] = $cg->shopAdminId;
         $data['shopAdminName'] = $cg->shopAdminName;
         $data['cgId'] = $cg->id;
-        $data['refundType'] = $post['refundType'];
+        $refundType = $post['refundType'] ?? 0;
+        $data['refundType'] = $refundType;
         $data['refundPrice'] = $refundPrice;
         $data['remark'] = $post['remark'];
 
-        //退款金额和采购单金额一样,使用的红包原路退回
-        $actPrice = $cg->actPrice ?? 0;
-        if (floatval($actPrice) == floatval($refundPrice)) {
-            $hbId = $cg->hbId ?? 0;
-            if (!empty($hbId)) {
-                $hbInfo = HbClass::getById($hbId, true);
-                $hbInfo->status = HbClass::STATUS_UN_USE;
-                $hbInfo->take = HbClass::TAKE_UN;
-                $hbInfo->save();
-                $data['hbAmount'] = $hbInfo->amount ?? 0;
-                $data['hbRefund'] = 1;
-                $data['hbId'] = $hbId;
-            }
-        }
+        $ghsItemInfo = $post['product'] ?? '';
 
-        if ($ghsItemInfo) {
-            $ghsItemInfo = CgRefundClass::mergeItemInfo($ghsItemInfo);
-            $sumNum = CgRefundClass::sumNumByItemInfo($ghsItemInfo);
-        }
         $data['bigNum'] = $sumNum['bigNum'] ?? 0;// 总的大单位数量 总共多少扎
         $data['smallNum'] = $sumNum['smallNum'] ?? 0; //总的小单位数量 总共多少支
 
         //写入订单表
         $cgRefund = CgRefundClass::add($data, true);
-        if ($ghsItemInfo) {
-            //写入cgRefundItem, 转hdProductId
-            $ghsItemInfo = self::toggleProductList($ghsItemInfo, $cg->shopId, $cg->sjId, $cg->mainId);
-            //将hdProductId =》productId
+
+        if ($refundType == CgRefundClass::REFUND_TYPE_MONEY_GOOD) {
+
+
             foreach ($ghsItemInfo as $k => $v) {
                 $ghsItemInfo[$k]['productId'] = $v['hdProductId'];
             }
@@ -125,6 +108,7 @@ class CgRefundService extends BaseService
 
         }
 
+
         //门店总收入增加
         $currentTotalIncome = bcadd($shop->totalIncome, $refundPrice, 2);
         $shop->totalIncome = $currentTotalIncome;

+ 3 - 4
biz/stat/classes/StatItemClass.php

@@ -41,13 +41,12 @@ class StatItemClass extends BaseClass
     //退款花材
     public static function refundReplace($item, $date = null)
     {
-        $sjId = $item['sjId'] ?? 0;
-        $shopId = $item['shopId'] ?? 0;
+        $mainId = $item['mainId'] ?? 0;
         $productId = $item['productId'] ?? 0;
         $time = $date == null ? date('Ymd') : $date;
-        $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'itemId' => $productId, 'time' => $time], true);
+        $stat = self::getByCondition(['mainId' => $mainId, 'itemId' => $productId, 'time' => $time], true);
         if (empty($stat)) {
-            $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'itemId' => $productId, 'time' => $time], true);
+            $stat = self::add(['mainId' => $mainId, 'itemId' => $productId, 'time' => $time], true);
         }
         $id = $stat->id;
         $unique = self::getLockById($id);

+ 9 - 1
sql.txt

@@ -698,4 +698,12 @@ ALTER TABLE xhCgRefundItem ADD `xhUnitType` TINYINT(4) NOT NULL DEFAULT '0' COMM
 ALTER TABLE xhCgRefundItem ADD `xhUnitPrice` DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '当前单位单价,售价' AFTER `xhUnitType`;
 ALTER TABLE xhCgRefundItem ADD `xhPrice` DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '当前单位的总价,售价总和' AFTER `xhUnitPrice`;
 
-====预订单 ssh 20220327
+====预订单 ssh 20220327
+
+ALTER TABLE xhStatItem DROP INDEX `shop`;
+ALTER TABLE xhStatItemMonth DROP INDEX `shop`;
+ALTER TABLE xhStatItem ADD mainId INT NOT NULL DEFAULT 0 COMMENT '中央id' AFTER `id`;
+ALTER TABLE xhStatItemMonth ADD mainId INT NOT NULL DEFAULT 0 COMMENT '中央id' AFTER `id`;
+
+ALTER TABLE xhRefundItem ADD mainId INT NOT NULL DEFAULT 0 COMMENT '中央id' AFTER `id`;
+ALTER TABLE xhCgRefundItem ADD mainId INT NOT NULL DEFAULT 0 COMMENT '中央id' AFTER `id`;