shish hace 2 años
padre
commit
e6f612f8b7

+ 1 - 0
biz-ghs/order/classes/PurchaseOrderClass.php

@@ -1063,6 +1063,7 @@ class PurchaseOrderClass extends BaseClass
             $itemId = $productData[$productId]['itemId'];
             $tmp['orderSn'] = $orderSn;
             $tmp['itemId'] = $itemId;
+            $tmp['belongCost'] = $productData[$productId]['belongCost'] ?? 0;
             $tmp['productId'] = $v['productId'];
             $tmp['itemStock'] = $productData[$productId]['stock'] ?? 0;
             $tmp['onStock'] = $productData[$productId]['onStock'] ?? 0;

+ 20 - 12
biz-ghs/stat/classes/StatSaleClass.php

@@ -378,9 +378,9 @@ class StatSaleClass extends BaseClass
         $s = strtotime($currentStartTime);
         $e = strtotime($currentEndTime);
         $p = bcsub($e, $s);
-        $xx = bcmul(86400, 60);
+        $xx = bcmul(86400, 90);
         if ($p > $xx) {
-            util::fail('查询时间不能超过个月');
+            util::fail('查询时间不能超过个月');
         }
 
         $classList = ItemClassClass::getAllByCondition(['mainId' => $mainId], null, 'id,name', 'id');
@@ -395,6 +395,7 @@ class StatSaleClass extends BaseClass
         $onlyRefund = 0;
 
         //采购入库
+        $tbCgIncome = [];
         $cgWhere = ['mainId' => $mainId, 'status' => 4];
         $cgWhere['entryTime'] = ['between', [$currentStartTime, $currentEndTime]];
         $cgList = PurchaseOrderClass::getAllByCondition($cgWhere, null, '*');
@@ -417,6 +418,8 @@ class StatSaleClass extends BaseClass
                 if (!empty($cgItemInfoList)) {
                     foreach ($cgItemInfoList as $cgData) {
                         $itemNum = $cgData->itemNum ?? 0;
+                        $productId = $cgData->productId ?? 0;
+                        $name = $cgData->name ?? '';
                         $refundNum = $cgData->refundNum ?? 0;
                         $remainNum = bcsub($itemNum, $refundNum);
                         $bigPrice = $cgData->bigPrice ?? 0;
@@ -431,6 +434,12 @@ class StatSaleClass extends BaseClass
                             $arr[$classId]['expend'] = $amount;
                             $arr[$classId]['income'] = 0;
                         }
+                        if (isset($tbCgIncome[$productId])) {
+                            $tbCgIncome[$productId]['num'] = bcadd($tbCgIncome[$productId]['num'], $remainNum);
+                            $tbCgIncome[$productId]['price'] = bcadd($tbCgIncome[$productId]['price'], $amount, 2);
+                        } else {
+                            $tbCgIncome[$productId] = ['num' => $remainNum, 'name' => $name, 'price' => $amount];
+                        }
                     }
                     if ($tkPrice > 0) {
                         $cgRefundOrderList = CgRefundClass::getAllByCondition(['relateOrderSn' => $orderSn], null, '*', null, true);
@@ -438,8 +447,6 @@ class StatSaleClass extends BaseClass
                             foreach ($cgRefundOrderList as $cgRefundOrder) {
                                 if ($cgRefundOrder->refundType == 2) {
                                     $onlyRefundCg = bcadd($cgRefundOrder->refundPrice, $onlyRefundCg, 2);
-                                } else {
-                                    //退货退款前面已经考虑,这里不再处理 OK
                                 }
                             }
                         }
@@ -450,7 +457,7 @@ class StatSaleClass extends BaseClass
 
         //批发开单
         $pfIncome = 0;
-        $costIncome = [];
+        $tbSaleIncome = [];
         $where = ['mainId' => $mainId, 'status' => ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]]];
         $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
         $ghsOrderList = OrderClass::getAllByCondition($where, null, '*');
@@ -500,7 +507,7 @@ class StatSaleClass extends BaseClass
 
                 }
 
-                //特别统计
+                //销售特别统计
                 $orderSn = $ghsOrder['orderSn'] ?? '';
                 if ($book == 0 || ($book == 1 && in_array($status, [3, 4]))) {
                     $ghsOrderItemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
@@ -508,7 +515,7 @@ class StatSaleClass extends BaseClass
                         foreach ($ghsOrderItemList as $ghsOrderItem) {
                             $belongCost = $ghsOrderItem['belongCost'] ?? 0;
                             if ($belongCost == 1) {
-                                //$costIncome
+                                //$tbSaleIncome
                                 $productId = $ghsOrderItem['productId'] ?? 0;
                                 $name = $ghsOrderItem['name'] ?? '';
                                 $num = $ghsOrderItem['xhNum'] ?? 0;
@@ -516,11 +523,11 @@ class StatSaleClass extends BaseClass
                                 $unitPrice = $ghsOrderItem['xhUnitPrice'] ?? 0;
                                 $remainNum = bcsub($num, $refundNum);
                                 $price = bcmul($remainNum, $unitPrice, 2);
-                                if (isset($costIncome[$productId])) {
-                                    $costIncome[$productId]['num'] = bcadd($costIncome[$productId]['num'], $remainNum);
-                                    $costIncome[$productId]['price'] = bcadd($costIncome[$productId]['price'], $price, 2);
+                                if (isset($tbSaleIncome[$productId])) {
+                                    $tbSaleIncome[$productId]['num'] = bcadd($tbSaleIncome[$productId]['num'], $remainNum);
+                                    $tbSaleIncome[$productId]['price'] = bcadd($tbSaleIncome[$productId]['price'], $price, 2);
                                 } else {
-                                    $costIncome[$productId] = ['name' => $name, 'num' => $remainNum, 'price' => $price];
+                                    $tbSaleIncome[$productId] = ['name' => $name, 'num' => $remainNum, 'price' => $price];
                                 }
                             }
                         }
@@ -604,7 +611,8 @@ class StatSaleClass extends BaseClass
             'totalIncome' => $totalIncome,
             'totalExpend' => $totalExpend,
             'totalProfit' => $totalProfit,
-            'costIncome' => $costIncome,
+            'tbSaleIncome' => $tbSaleIncome,
+            'tbCgIncome' => $tbCgIncome,
         ]);
     }