shish 9 månader sedan
förälder
incheckning
986c3eaf98
2 ändrade filer med 102 tillägg och 1 borttagningar
  1. 17 0
      app-ghs/controllers/StatKhCgController.php
  2. 85 1
      biz-ghs/stat/classes/StatSaleClass.php

+ 17 - 0
app-ghs/controllers/StatKhCgController.php

@@ -27,4 +27,21 @@ class StatKhCgController extends BaseController
         util::success($respond);
     }
 
+    //客户按片区划分业绩 ssh 20251117
+    public function actionDist()
+    {
+        ini_set('memory_limit', '2045M');
+        set_time_limit(0);
+
+        //查看财务的权限
+        $lookMoney = ShopAdminClass::lookMoneyPower($this->shopAdmin, $this->shop);
+        if ($lookMoney == 0) {
+            util::fail('无法查看');
+        }
+
+        $mainId = $this->mainId;
+        $respond = StatSaleClass::customDistStat($mainId);
+        util::success($respond);
+    }
+
 }

+ 85 - 1
biz-ghs/stat/classes/StatSaleClass.php

@@ -6,6 +6,7 @@ use biz\stat\classes\StatStockInClass;
 use biz\stat\classes\StatStockOutClass;
 use bizGhs\cg\classes\CgRefundClass;
 use bizGhs\custom\classes\CustomClass;
+use bizGhs\custom\classes\DistClass;
 use bizGhs\expend\classes\ExpendClass;
 use bizGhs\item\classes\ItemClassClass;
 use bizGhs\order\classes\OrderItemClass;
@@ -1342,7 +1343,7 @@ class StatSaleClass extends BaseClass
         $ghsOrderList = OrderClass::getAllByCondition($where, null, '*');
         $arr = [];
         if (!empty($ghsOrderList)) {
-            foreach ($ghsOrderList as $ghsKey => $ghsOrder) {
+            foreach ($ghsOrderList as $ghsOrder) {
                 $book = $ghsOrder['book'] ?? 0;
                 $status = $ghsOrder['status'] ?? 0;
                 if ($book == 1 && $status == 2) {
@@ -1383,4 +1384,87 @@ class StatSaleClass extends BaseClass
         return $arr;
     }
 
+    public static function customDistStat($mainId)
+    {
+        $get = Yii::$app->request->get();
+        $where = [];
+        $where['mainId'] = $mainId;
+        $searchTime = !empty($get['searchTime']) ? $get['searchTime'] : 'today';
+
+        $startTime = $get['startTime'] ?? '';
+        $endTime = $get['endTime'] ?? '';
+        $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
+        $start = $period['startTime'];
+        $end = $period['endTime'];
+        $where['time'] = ['between', [$start, $end]];
+
+        $currentStartDate = date('Y-m-d', strtotime($start));
+        $currentEndDate = date('Y-m-d', strtotime($end));
+        $currentStartTime = $currentStartDate . ' 00:00:00';
+        $currentEndTime = $currentEndDate . ' 23:59:59';
+
+        $where = ['mainId' => $mainId, 'status' => ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]]];
+        $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
+
+        $customList = CustomClass::getAllByCondition(['ownMainId' => $mainId], null, 'id,name,distId', 'id');
+
+        $distMap = DistClass::getAllByCondition(['mainId' => $mainId], null, '*', 'id');
+
+        $arr = [];
+        $ghsOrderList = OrderClass::getAllByCondition($where, null, '*');
+        $totalAmount = 0;
+        $totalNum = 0;
+        $totalProfit = 0;
+        $totalCost = 0;
+        if (!empty($ghsOrderList)) {
+            foreach ($ghsOrderList as $ghsOrder) {
+                $actPrice = $ghsOrder['actPrice'] ?? 0;
+                $cost = $ghsOrder['remainCost'] ?? 0;
+                $profit = $actPrice > $cost ? bcsub($actPrice, $cost, 2) : 0;
+                $orderPrice = $ghsOrder['orderPrice'] ?? 0;
+                $tkPrice = $ghsOrder['tkPrice'] ?? 0;
+                $customId = $ghsOrder['customId'] ?? 0;
+                $status = $ghsOrder['status'] ?? 0;
+                $book = $ghsOrder['book'] ?? 0;
+                if ($status == 1 || $status == 5) {
+                    continue;
+                }
+                if ($book == 1 && $status == 2) {
+                    continue;
+                }
+
+                $distId = $customList[$customId]['distId'] ?? 0;
+                $distName = isset($distMap[$distId]) ? $distMap[$distId]['name'] : '未划片区';
+
+                $totalNum++;
+                $totalAmount = bcadd($totalAmount, $actPrice, 2);
+                $totalProfit = bcadd($totalProfit, $profit, 2);
+                $totalCost = bcadd($totalCost, $cost, 2);
+                if (isset($arr[$distId])) {
+                    $arr[$distId]['num']++;
+                    $arr[$distId]['amount'] = bcadd($arr[$distId]['amount'], $actPrice, 2);
+                    $arr[$distId]['orderPrice'] = bcadd($arr[$distId]['orderPrice'], $orderPrice, 2);
+                    $arr[$distId]['tkPrice'] = bcadd($arr[$distId]['tkPrice'], $tkPrice, 2);
+                    $arr[$distId]['cost'] = bcadd($arr[$distId]['cost'], $cost, 2);
+                    $arr[$distId]['profit'] = bcadd($arr[$distId]['profit'], $profit, 2);
+                } else {
+                    $arr[$distId] = [
+                        'distId' => $distId,
+                        'distName' => $distName,
+                        'num' => 1,
+                        'amount' => $actPrice,
+                        'levelName' => '',
+                        'orderPrice' => $orderPrice,
+                        'tkPrice' => $tkPrice,
+                        'cost' => $cost,
+                        'profit' => $profit,
+                    ];
+                }
+            }
+            $arr = arrayUtil::arraySort($arr, 'profit');
+        }
+        $totalAmount = floatval($totalAmount);
+        return ['list' => $arr, 'totalAmount' => $totalAmount, 'totalNum' => $totalNum, 'totalCost' => $totalCost, 'totalProfit' => $totalProfit];
+    }
+
 }