shish há 2 anos atrás
pai
commit
47b55ab3f7

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

@@ -77,7 +77,8 @@ class ConsoleController extends BaseController
             ]);
         }
 
-        $incomeList = StatKdClass::eachChannelIncome($this->mainId, $this->shop);
+        $return = StatKdClass::eachChannelIncome($this->mainId, $this->shop);
+        $incomeList = $return['incomeList'];
 
         $systemIncome1 = $incomeList['system']['category']['ls']['amount'] ?? 0;
         $systemCount1 = $incomeList['system']['category']['ls']['num'] ?? 0;

+ 4 - 4
app-ghs/controllers/StatKdController.php

@@ -13,13 +13,11 @@ class StatKdController extends BaseController
     //各渠道收入 ssh 20220711
     public function actionProfile()
     {
-
         //查看财务的权限
         $lookMoney = ShopAdminClass::lookMoneyPower($this->shopAdmin, $this->shop);
         if ($lookMoney == 0) {
             util::fail('无法查看');
         }
-
         //惠雅鲜花员工不能看收入情况
         $shopAdmin = $this->shopAdmin;
         $adminId = $shopAdmin->adminId ?? 0;
@@ -28,7 +26,9 @@ class StatKdController extends BaseController
         }
         $get = Yii::$app->request->get();
         $contain = $get['contain'] ?? 0;
-        $incomeList = StatKdClass::eachChannelIncome($this->mainId, $this->shop, $contain);
+        $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 +37,7 @@ class StatKdController extends BaseController
                 $totalIncome = floatval($totalIncome);
             }
         }
-        util::success(['list' => $incomeList, 'totalIncome' => $totalIncome]);
+        util::success(['list' => $incomeList, 'totalIncome' => $totalIncome, 'costIncome' => $costIncome]);
     }
 
 }

+ 2 - 1
app-hd/controllers/ConsoleController.php

@@ -137,7 +137,8 @@ class ConsoleController extends BaseController
             ]);
         }
 
-        $incomeList = \bizGhs\stat\classes\StatKdClass::eachChannelIncome($this->mainId, $this->shop);
+        $return = \bizGhs\stat\classes\StatKdClass::eachChannelIncome($this->mainId, $this->shop);
+        $incomeList = $return['incomeList'];
 
         $systemIncome1 = $incomeList['system']['category']['ls']['amount'] ?? 0;
         $systemCount1 = $incomeList['system']['category']['ls']['num'] ?? 0;

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

@@ -31,7 +31,8 @@ class StatKdController extends BaseController
         }
         $get = Yii::$app->request->get();
         $contain = $get['contain'] ?? 0;
-        $incomeList = \bizGhs\stat\classes\StatKdClass::eachChannelIncome($this->mainId, $this->shop, $contain);
+        $return = \bizGhs\stat\classes\StatKdClass::eachChannelIncome($this->mainId, $this->shop, $contain);
+        $incomeList = $return['incomeList'];
         $totalIncome = 0;
         if (!empty($incomeList)) {
             foreach ($incomeList as $item) {

+ 29 - 2
biz-ghs/stat/classes/StatKdClass.php

@@ -4,6 +4,7 @@ namespace bizGhs\stat\classes;
 
 use biz\shop\classes\ShopAdminClass;
 use bizGhs\order\classes\OrderClass;
+use bizGhs\order\classes\OrderItemClass;
 use bizGhs\order\classes\StockOutOrderClass;
 use bizHd\order\classes\SettleClass;
 use common\components\dateUtil;
@@ -147,6 +148,8 @@ 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]];
@@ -228,6 +231,31 @@ class StatKdClass extends BaseClass
                         }
                     }
                 }
+
+                //计算属于成本的收入
+                $orderSn = $ghsOrder['orderSn'] ?? '';
+                $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];
+                            }
+                        }
+                    }
+                }
             }
         }
 
@@ -477,8 +505,7 @@ class StatKdClass extends BaseClass
                 }
             }
         }
-        //noticeUtil::push(json_encode($incomeList), '15280215347');
-        return $incomeList;
+        return ['costIncome' => $costIncome, 'incomeList' => $incomeList];
 
     }