Browse Source

Merge branch 'redesign‌-260706' into dev

shish 1 day ago
parent
commit
080bd99b7f
2 changed files with 12 additions and 3 deletions
  1. 2 1
      app-ghs/controllers/StatKhCgController.php
  2. 10 2
      biz-ghs/stat/classes/StatSaleClass.php

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

@@ -10,7 +10,8 @@ use common\components\util;
 class StatKhCgController extends BaseController
 {
 
-    //客户业绩,有多个地方,需要同步,搜索关键词 customYj ssh 20240628
+    // 客户业绩,有多个地方,需要同步,搜索关键词 customYj ssh 20240628
+    // 返回 list + totalNum/totalCount/totalAmount/totalCost/totalProfit,totalCount 为总扎数
     public function actionProfile()
     {
         ini_set('memory_limit', '2045M');

+ 10 - 2
biz-ghs/stat/classes/StatSaleClass.php

@@ -121,7 +121,10 @@ class StatSaleClass extends BaseClass
         return ['list' => $ghsOrderList];
     }
 
-    //客户下单榜 ssh 20230502
+    /**
+     * 客户业绩:按客户汇总笔数/扎数/金额/成本/利润,供 ghsApp customSale、/stat-kh-cg/profile 使用。
+     * totalCount 为总扎数(含隔天售后扣减),与各行 count 口径一致。
+     */
     public static function statCustomCg($mainId)
     {
         $get = Yii::$app->request->get();
@@ -150,6 +153,7 @@ class StatSaleClass extends BaseClass
         $ghsOrderList = OrderClass::getAllByCondition($where, null, '*');
         $totalAmount = 0;
         $totalNum = 0;
+        $totalCount = 0;
         $totalProfit = 0;
         $totalCost = 0;
         if (!empty($ghsOrderList)) {
@@ -176,6 +180,7 @@ class StatSaleClass extends BaseClass
                 $customName = $customList[$customId]['name'] ?? '';
                 $py = $customList[$customId]['py'] ?? '';
                 $totalNum++;
+                $totalCount = bcadd($totalCount, $count, 2);
                 $totalAmount = bcadd($totalAmount, $actPrice, 2);
                 $totalProfit = bcadd($totalProfit, $profit, 2);
                 $totalCost = bcadd($totalCost, $cost, 2);
@@ -261,6 +266,7 @@ class StatSaleClass extends BaseClass
                 }
                 $profit = bcsub($actPrice, $cost, 2);
                 $totalNum++;
+                $totalCount = bcadd($totalCount, $count, 2);
                 $totalAmount = bcadd($totalAmount, $actPrice, 2);
                 $totalProfit = bcadd($totalProfit, $profit, 2);
                 $totalCost = bcadd($totalCost, $cost, 2);
@@ -324,6 +330,7 @@ class StatSaleClass extends BaseClass
             $arr[$cid]['count'] = bcsub((string)($arr[$cid]['count'] ?? 0), (string)$qty, 2);
             $totalAmount = bcsub((string)$totalAmount, (string)$amt, 2);
             $totalProfit = bcsub((string)$totalProfit, (string)$amt, 2);
+            $totalCount = bcsub((string)$totalCount, (string)$qty, 2);
         }
 
         // hd 零售隔天:独立 key +「零售-」客户名
@@ -372,12 +379,13 @@ class StatSaleClass extends BaseClass
             $arr[$rowKey]['count'] = bcsub((string)($arr[$rowKey]['count'] ?? 0), (string)$qty, 2);
             $totalAmount = bcsub((string)$totalAmount, (string)$amt, 2);
             $totalProfit = bcsub((string)$totalProfit, (string)$amt, 2);
+            $totalCount = bcsub((string)$totalCount, (string)$qty, 2);
         }
         if (!empty($arr)) {
             $arr = arrayUtil::arraySort($arr, 'profit');
         }
         $totalAmount = floatval($totalAmount);
-        return ['list' => $arr, 'totalAmount' => $totalAmount, 'totalNum' => $totalNum, 'totalCost' => $totalCost, 'totalProfit' => $totalProfit];
+        return ['list' => $arr, 'totalAmount' => $totalAmount, 'totalNum' => $totalNum, 'totalCount' => floatval($totalCount), 'totalCost' => $totalCost, 'totalProfit' => $totalProfit];
     }
 
     public static function profile($mainId)