wesmiler преди 1 месец
родител
ревизия
2050c1cd7c
променени са 1 файла, в които са добавени 58 реда и са изтрити 79 реда
  1. 58 79
      app/Services/Common/OrderService.php

+ 58 - 79
app/Services/Common/OrderService.php

@@ -143,6 +143,7 @@ class OrderService extends BaseService
             'code' => 0,
             'data' => $list['data'] ?? [],
             'count' => $list['total'] ?? 0,
+            'counts' => $counts,
         ];
     }
 
@@ -237,77 +238,6 @@ class OrderService extends BaseService
             });
     }
 
-    /**
-     * 按日期统计订单数
-     * @param string $beginAt 开始时间
-     * @param string $endAt 结束时间
-     * @param int[] $status 状态:数组或数值
-     * @return mixed
-     */
-    public function getCountByTime($beginAt = '', $endAt = '', $status = 3)
-    {
-        $cacheKey = "caches:orders:count_{$status}_{$beginAt}_{$endAt}";
-        $data = RedisService::get($cacheKey);
-        if ($data) {
-            return $data;
-        }
-        $where = ['mark' => 1];
-        $data = $this->model->where($where)->where(function ($query) use ($beginAt, $endAt, $status) {
-            if ($beginAt && $endAt) {
-                $query->whereBetween('create_time', [strtotime($beginAt), strtotime($endAt)]);
-            } else if ($beginAt) {
-                $query->where('create_time', '>=', strtotime($beginAt));
-            }
-
-            if ($status && is_array($status)) {
-                $query->whereIn('status', $status);
-            } else if ($status) {
-                $query->where('status', $status);
-            }
-        })->count('id');
-
-        if ($data) {
-            RedisService::set($cacheKey, $data, rand(300, 600));
-        }
-
-        return $data;
-    }
-
-    /**
-     * 按日期统计订单金额
-     * @param string $beginAt 开始时间
-     * @param string $endAt 结束时间
-     * @param int[] $status 状态:数组或数值
-     * @return mixed
-     */
-    public function getTotalByTime($beginAt = '', $endAt = '', $status = 3)
-    {
-        $cacheKey = "caches:orders:total_{$status}_{$beginAt}_{$endAt}";
-        $data = RedisService::get($cacheKey);
-        if ($data) {
-            return $data;
-        }
-        $where = ['mark' => 1];
-        $data = $this->model->where($where)->where(function ($query) use ($beginAt, $endAt, $status) {
-            if ($beginAt && $endAt) {
-                $query->whereBetween('create_time', [strtotime($beginAt), strtotime($endAt)]);
-            } else if ($beginAt) {
-                $query->where('create_time', '>=', strtotime($beginAt));
-            }
-
-            if ($status && is_array($status)) {
-                $query->whereIn('status', $status);
-            } else if ($status) {
-                $query->where('status', $status);
-            }
-        })->sum('total');
-
-        if ($data) {
-            RedisService::set($cacheKey, $data, rand(300, 600));
-        }
-
-        return $data;
-    }
 
     /**
      * 添加或编辑
@@ -894,34 +824,83 @@ class OrderService extends BaseService
      */
     public function getStatistics($storeId = 0)
     {
+        $meetingId = request()->get('meeting_id',0);
+        $userId = request()->get('user_id',0);
+        $sid = request()->get('store_id',0);
+        $storeId = $storeId?$storeId:$sid;
+
         // 总订单数
         $total = $this->model->where('mark', 1)
-            ->when($storeId > 0, function ($query) use ($storeId) {
-                return $query->where('store_id', $storeId);
+            ->when($storeId > 0, function ($query) use ($storeId,$meetingId,$userId) {
+                if($storeId){
+                    $query->where('store_id', $storeId);
+                }
+
+                if($meetingId){
+                    $query->where('meeting_id', $meetingId);
+                }
+
+
+                if($userId){
+                    $query->where('user_id', $userId);
+                }
             })
             ->count();
 
         // 总交易额(已完成订单)
         $totalAmount = $this->model->where('mark', 1)
             ->where('status', 4)
-            ->when($storeId > 0, function ($query) use ($storeId) {
-                return $query->where('store_id', $storeId);
+            ->when($storeId > 0, function ($query) use ($storeId,$meetingId,$userId) {
+                if($storeId){
+                    $query->where('store_id', $storeId);
+                }
+
+                if($meetingId){
+                    $query->where('meeting_id', $meetingId);
+                }
+
+
+                if($userId){
+                    $query->where('user_id', $userId);
+                }
             })
             ->sum('pay_total');
 
         // 待处理订单(待付款 + 已付款)
         $pending = $this->model->where('mark', 1)
             ->whereIn('status', [1, 2])
-            ->when($storeId > 0, function ($query) use ($storeId) {
-                return $query->where('store_id', $storeId);
+            ->when($storeId > 0, function ($query) use ($storeId,$meetingId,$userId) {
+                if($storeId){
+                    $query->where('store_id', $storeId);
+                }
+
+                if($meetingId){
+                    $query->where('meeting_id', $meetingId);
+                }
+
+
+                if($userId){
+                    $query->where('user_id', $userId);
+                }
             })
             ->count();
 
         // 待退款订单
         $refunding = $this->model->where('mark', 1)
             ->where('refund_status', 3)
-            ->when($storeId > 0, function ($query) use ($storeId) {
-                return $query->where('store_id', $storeId);
+            ->when($storeId > 0, function ($query) use ($storeId,$meetingId,$userId) {
+                if($storeId){
+                    $query->where('store_id', $storeId);
+                }
+
+                if($meetingId){
+                    $query->where('meeting_id', $meetingId);
+                }
+
+
+                if($userId){
+                    $query->where('user_id', $userId);
+                }
             })
             ->count();