shish 2 ani în urmă
părinte
comite
c50db04833
1 a modificat fișierele cu 139 adăugiri și 0 ștergeri
  1. 139 0
      app-ghs/controllers/OrderController.php

+ 139 - 0
app-ghs/controllers/OrderController.php

@@ -2170,4 +2170,143 @@ class OrderController extends BaseController
         util::success(['list' => $list, 'totalAmount' => $totalAmount]);
     }
 
+
+    //客户业绩 ssh 20240528
+    public function actionYj()
+    {
+        $get = Yii::$app->request->get();
+        $mainId = $this->mainId;
+        $export = $get['export'] ?? 0;
+        $debt = isset($get['debt']) && is_numeric($get['debt']) ? $get['debt'] : -1;
+        $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'];
+
+        $customList = CustomClass::getAllByCondition(['ownMainId' => $mainId], null, '*', 'id');
+        $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];
+        if ($debt > -1) {
+            $where['debt'] = $debt;
+        }
+        $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
+        $orderList = OrderClass::getAllByCondition($where, null, '*');
+        $list = [];
+        $totalActPrice = 0;
+        $totalOrderPrice = 0;
+        $totalCarton = 0;
+        $totalPack = 0;
+        $totalFreight = 0;
+        $totalTkPrice = 0;
+        if (!empty($orderList)) {
+            foreach ($orderList as $orderInfo) {
+                $actPrice = $orderInfo['actPrice'] ?? 0;
+                $orderPrice = $orderInfo['orderPrice']??0;
+                $customId = $orderInfo['customId'] ?? 0;
+                $status = $orderInfo['status'] ?? 0;
+                $book = $orderInfo['book'] ?? 0;
+                $orderSn = $orderInfo['orderSn']??'';
+                $tkPrice = $orderInfo['tkPrice']??0;
+                if ($status == 1 || $status == 5) {
+                    continue;
+                }
+                if ($book == 1 && $status == 2) {
+                    continue;
+                }
+                $carton = 0;
+                $pack = 0;
+                $freight = 0;
+                $orderItemList = OrderItemClass::getAllByCondition(['orderSn'=>$orderSn],null,'*');
+                if(!empty($orderItemList)){
+                    foreach($orderItemList as $orderItem){
+                        $num = $orderItem['xhNum']??0;
+                        $unitPrice = $orderItem['xhUnitPrice']??0;
+                        $refundNum = $orderItem['refundNum']??0;
+                        $classId = $orderItem['classId']??0;
+                        if (getenv('YII_ENV') == 'production') {
+                            if($mainId == 23390){
+                                $remainNum = bcsub($num,$refundNum);
+                                $amount = bcmul($remainNum,$unitPrice,2);
+                                if($classId == 72106){
+                                    $carton = bcadd($carton,$amount,2);
+                                }
+                                if($classId == 72108){
+                                    $pack = bcadd($pack,$amount,2);
+                                }
+                                if($classId == 73118){
+                                    $freight = bcadd($freight,$amount,2);
+                                }
+                            }
+                        }
+                    }
+                }
+                $totalCarton = bcadd($totalCarton,$carton,2);
+                $totalPack = bcadd($totalPack,$pack,2);
+                $totalFreight = bcadd($totalFreight,$freight,2);
+                $totalTkPrice = bcadd($totalTkPrice,$tkPrice,2);
+                $totalActPrice = bcadd($totalActPrice, $actPrice, 2);
+                $totalOrderPrice = bcadd($totalOrderPrice,$orderPrice,2);
+                if (isset($list[$customId])) {
+                    $list[$customId]['actPrice'] = bcadd($list[$customId]['actPrice'], $actPrice, 2);
+                    $list[$customId]['orderPrice'] = bcadd($list[$customId]['orderPrice'], $orderPrice, 2);
+                    $list[$customId]['num'] = bcadd($list[$customId]['num'], 1);
+                    $list[$customId]['carton'] = bcadd($list[$customId]['carton'], $carton,2);
+                    $list[$customId]['pack'] = bcadd($list[$customId]['pack'], $carton,2);
+                    $list[$customId]['freight'] = bcadd($list[$customId]['freight'], $carton,2);
+                    $list[$customId]['tkPrice'] = bcadd($list[$customId]['tkPrice'], $tkPrice,2);
+                } else {
+                    $name = $customList[$customId] && $customList[$customId]['name'] ? $customList[$customId]['name'] : '未命名';
+                    $mobile = $customList[$customId] && $customList[$customId]['mobile'] ? $customList[$customId]['mobile'] : '0';
+                    $list[$customId] = [
+                        'id' => $customId,
+                        'name' => $name,
+                        'mobile'=>$mobile,
+                        'orderPrice'=>$orderPrice,
+                        'actPrice' => $actPrice,
+                        'num' => 1,
+                        'carton'=>0,
+                        'pack'=>0,
+                        'freight'=>0,
+                        'tkPrice'=>0,
+                    ];
+                }
+            }
+            foreach($customList as $key => $custom){
+                $customId = $custom['id']??0;
+                if(isset($list[$customId]) == false){
+                    $list[$customId] = [
+                        'id' => $customId,
+                        'name' => $custom['name'],
+                        'mobile'=>$custom['mobile'],
+                        'amount' => 0,
+                        'num' => 0,
+                        'carton'=>0,
+                        'pack'=>0,
+                        'freight'=>0,
+                        'tkPrice'=>0,
+                        'orderPrice'=>0,
+                    ];
+                }
+            }
+            $list = array_values($list);
+        }
+        if ($export == 1) {
+//            if (empty($list)) {
+//                util::fail('没有数据需要导出');
+//            }
+//            ini_set('memory_limit', '2045M');
+//            set_time_limit(0);
+//            OrderClass::exportAccountList($list, $mainId);
+//            util::stop();
+        }
+        util::success(['list' => $list, 'totalActPrice' => $totalActPrice,'totalOrderPrice'=>$totalOrderPrice,'totalCarton'=>$totalCarton,
+            'totalPack'=>$totalPack,'totalFreight'=>$totalFreight,'totalTkPrice'=>$totalTkPrice]);
+    }
+
 }