Browse Source

配送业绩

shish 1 year ago
parent
commit
651b41f733
2 changed files with 82 additions and 0 deletions
  1. 10 0
      app-ghs/controllers/StatController.php
  2. 72 0
      biz-ghs/stat/classes/StatSaleClass.php

+ 10 - 0
app-ghs/controllers/StatController.php

@@ -96,6 +96,16 @@ class StatController extends BaseController
         StatSaleClass::classProfile($mainId);
     }
 
+    //配送业绩 ssh 20240824
+    public function actionSend()
+    {
+        ini_set('memory_limit', '2045M');
+        set_time_limit(0);
+        $mainId = $this->mainId;
+        $arr = StatSaleClass::send($mainId);
+        util::success(['list'=>$arr]);
+    }
+
     public function actionIncomeOutItem()
     {
         ini_set('memory_limit', '2045M');

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

@@ -1265,4 +1265,76 @@ class StatSaleClass extends BaseClass
         util::success(['file' => $fileUrl, 'shortFile' => $file]);
     }
 
+    public static function send($mainId)
+    {
+        $get = Yii::$app->request->get();
+        $where = [];
+        $where['mainId'] = $mainId;
+        $searchTime = isset($get['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';
+
+        $s = strtotime($currentStartTime);
+        $e = strtotime($currentEndTime);
+        $p = bcsub($e, $s);
+        $xx = bcmul(86400, 90);
+        if ($p > $xx) {
+            util::fail('查询时间不能超过三个月');
+        }
+        $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, '*');
+        $arr = [];
+        if (!empty($ghsOrderList)) {
+            foreach ($ghsOrderList as $ghsKey => $ghsOrder) {
+                $book = $ghsOrder['book'] ?? 0;
+                $status = $ghsOrder['status'] ?? 0;
+                if ($book == 1 && $status == 2) {
+                    //预订单待发货的不算收入
+                    continue;
+                }
+                if ($status == 0 || $status == 5) {
+                    continue;
+                }
+                $orderSn = $ghsOrder['orderSn'] ?? '';
+                $actPrice = $ghsOrder['actPrice'] ?? 0;
+                if ($actPrice <= 0) {
+                    continue;
+                }
+                $sendStaffId = $ghsOrder['sendStaffId']??0;
+                $sendStaffName = $ghsOrder['sendStaffName']??'未记名';
+                if(isset($arr[$sendStaffId])){
+                    $arr[$sendStaffId]['orderNum'] = bcadd($arr[$sendStaffId]['orderNum'],1);
+                    $arr[$sendStaffId]['amount'] = bcadd($arr[$sendStaffId]['amount'],$actPrice,2);
+                }else{
+                    $arr[$sendStaffId] = ['staffName'=>$sendStaffName,'orderNum'=>1,'itemNum'=>0,'amount'=>$actPrice];
+                }
+                $orderItemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
+                if (!empty($orderItemList)) {
+                    foreach ($orderItemList as $orderItem) {
+                        $refundNum = $orderItem->refundNum ?? 0;
+                        $num = $orderItem->xhNum ?? 0;
+                        $remainNum = bcsub($num,$refundNum);
+                        $arr[$sendStaffId]['itemNum'] = bcadd($arr[$sendStaffId]['itemNum'],$remainNum);
+                    }
+                }
+            }
+
+        }
+        if (!empty($arr)) {
+            $arr = array_values($arr);
+        }
+        return $arr;
+    }
+
 }