Browse Source

收支统计

shish 2 years ago
parent
commit
8f9a21eea3

+ 1 - 2
app-ghs/controllers/StatKdController.php

@@ -28,7 +28,6 @@ class StatKdController extends BaseController
         $contain = $get['contain'] ?? 0;
         $return = StatKdClass::eachChannelIncome($this->mainId, $this->shop, $contain);
         $incomeList = $return['incomeList'];
-        $costIncome = $return['costIncome'];
         $totalIncome = 0;
         if (!empty($incomeList)) {
             foreach ($incomeList as $item) {
@@ -37,7 +36,7 @@ class StatKdController extends BaseController
                 $totalIncome = floatval($totalIncome);
             }
         }
-        util::success(['list' => $incomeList, 'totalIncome' => $totalIncome, 'costIncome' => $costIncome]);
+        util::success(['list' => $incomeList, 'totalIncome' => $totalIncome]);
     }
 
 }

+ 1 - 33
biz-ghs/stat/classes/StatKdClass.php

@@ -148,8 +148,6 @@ class StatKdClass extends BaseClass
             ],
         ];
 
-        $costIncome = [];
-
         //批发开单
         $where = ['mainId' => $mainId, 'status' => ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]]];
         $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
@@ -231,36 +229,6 @@ class StatKdClass extends BaseClass
                         }
                     }
                 }
-
-                //计算属于成本的收入
-                $orderSn = $ghsOrder['orderSn'] ?? '';
-                $payStatus = $ghsOrder['payStatus'] ?? 0;
-                $status = $ghsOrder['status'] ?? 0;
-                $book = $ghsOrder['book'] ?? 0;
-                if ($book == 0 || ($book == 1 && in_array($status, [3, 4]))) {
-                    $ghsOrderItemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
-                    if (!empty($ghsOrderItemList)) {
-                        foreach ($ghsOrderItemList as $ghsOrderItem) {
-                            $belongCost = $ghsOrderItem['belongCost'] ?? 0;
-                            if ($belongCost == 1) {
-                                //$costIncome
-                                $productId = $ghsOrderItem['productId'] ?? 0;
-                                $name = $ghsOrderItem['name'] ?? '';
-                                $num = $ghsOrderItem['xhNum'] ?? 0;
-                                $refundNum = $ghsOrderItem['refundNum'] ?? 0;
-                                $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);
-                                } else {
-                                    $costIncome[$productId] = ['name' => $name, 'num' => $remainNum, 'price' => $price];
-                                }
-                            }
-                        }
-                    }
-                }
             }
         }
 
@@ -510,7 +478,7 @@ class StatKdClass extends BaseClass
                 }
             }
         }
-        return ['costIncome' => $costIncome, 'incomeList' => $incomeList];
+        return ['incomeList' => $incomeList];
 
     }
 

+ 36 - 0
biz-ghs/stat/classes/StatSaleClass.php

@@ -450,11 +450,18 @@ class StatSaleClass extends BaseClass
 
         //批发开单
         $pfIncome = 0;
+        $costIncome = [];
         $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, '*');
         if (!empty($ghsOrderList)) {
             foreach ($ghsOrderList as $ghsKey => $ghsOrder) {
+                $book = $ghsOrder['book'] ?? 0;
+                $status = $ghsOrder['status'] ?? 0;
+                if ($book == 1 && $status == 2) {
+                    //预订单待发货的不算收入
+                    continue;
+                }
                 $orderSn = $ghsOrder['orderSn'] ?? '';
                 $actPrice = $ghsOrder['actPrice'] ?? 0;
                 $tkPrice = $ghsOrder['tkPrice'] ?? 0;
@@ -492,6 +499,34 @@ 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);
+                    if (!empty($ghsOrderItemList)) {
+                        foreach ($ghsOrderItemList as $ghsOrderItem) {
+                            $belongCost = $ghsOrderItem['belongCost'] ?? 0;
+                            if ($belongCost == 1) {
+                                //$costIncome
+                                $productId = $ghsOrderItem['productId'] ?? 0;
+                                $name = $ghsOrderItem['name'] ?? '';
+                                $num = $ghsOrderItem['xhNum'] ?? 0;
+                                $refundNum = $ghsOrderItem['refundNum'] ?? 0;
+                                $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);
+                                } else {
+                                    $costIncome[$productId] = ['name' => $name, 'num' => $remainNum, 'price' => $price];
+                                }
+                            }
+                        }
+                    }
+                }
+
             }
         }
 
@@ -569,6 +604,7 @@ class StatSaleClass extends BaseClass
             'totalIncome' => $totalIncome,
             'totalExpend' => $totalExpend,
             'totalProfit' => $totalProfit,
+            'costIncome' => $costIncome,
         ]);
     }