|
@@ -832,6 +832,64 @@ class CustomService
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Notes: 前12个月统计数据
|
|
|
+ * User: yb
|
|
|
+ * Date: 2024/8/21
|
|
|
+ * Time: 15:56
|
|
|
+ */
|
|
|
+ public static function statisticsMonth()
|
|
|
+ {
|
|
|
+ $months = month_12();
|
|
|
+ sort($months);
|
|
|
+ $startDate = $months[0];
|
|
|
+ $startDateTime = strtotime($startDate.'/01 00:00:00');
|
|
|
+ $endDateTime = time();
|
|
|
+ $where = [
|
|
|
+ ['created_at', '>=', $startDateTime],
|
|
|
+ ['created_at', '<=', $endDateTime]
|
|
|
+ ];
|
|
|
+ $currentTime = time();
|
|
|
+ $diffNums = self::DIFF_TIME;
|
|
|
+ $deptIds = TeamService::getIdsByUser();
|
|
|
+ if (false === $deptIds) {
|
|
|
+ //无权限
|
|
|
+ $where[] = ['dept_id', '=', 0];
|
|
|
+ } else if (is_array($deptIds)) {
|
|
|
+ //指定团队下的权限
|
|
|
+ if (!empty($params['dept_id'])) {
|
|
|
+ $deptId = end($params['dept_id']);
|
|
|
+ $deptIds = SysDept::where('dept_super_path','like', "%/{$deptId}/%")->where('dept_category', '=', TeamService::DEPT_CATEGORY)->pluck('dept_id')->toArray();
|
|
|
+ }
|
|
|
+ $where[] = [function($query) use ($deptIds) {
|
|
|
+ $query->whereIn('dept_id', $deptIds);
|
|
|
+ }];
|
|
|
+ } else {
|
|
|
+ if (!empty($params['dept_id'])) {
|
|
|
+ $deptId = end($params['dept_id']);
|
|
|
+ $deptIds = SysDept::where('dept_super_path','like', "%/{$deptId}/%")->where('dept_category', '=', TeamService::DEPT_CATEGORY)->pluck('dept_id')->toArray();
|
|
|
+ $where[] = [function($query) use ($deptIds) {
|
|
|
+ $query->whereIn('dept_id', $deptIds);
|
|
|
+ }];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $selectRaw = Db::raw("DATE_FORMAT(FROM_UNIXTIME(created_at), '%Y/%m') as date,count(*) as nums");
|
|
|
+ $groupRaw = Db::raw("DATE_FORMAT(FROM_UNIXTIME(created_at), '%Y/%m')");
|
|
|
+ $totalData = MarketCustomer::where($where)->selectRaw($selectRaw)->groupByRaw($groupRaw)->get();
|
|
|
+ $payData = MarketCustomer::where($where)->where([['current_status', '=', 3], ['check_status', '=', 2]])->selectRaw($selectRaw)->groupByRaw($groupRaw)->get();
|
|
|
+ $visitData = MarketCustomer::where($where)->where([['current_status', '=', 2], ['check_status', '=', 2]])->selectRaw($selectRaw)->groupByRaw($groupRaw)->get();
|
|
|
+ $dealData = MarketCustomer::where($where)->where([['current_status', '=', 4], ['check_status', '=', 2]])->selectRaw($selectRaw)->groupByRaw($groupRaw)->get();
|
|
|
+ $returnData = [
|
|
|
+ 'total' => $totalData->pluck('nums','date'),
|
|
|
+ 'pay' => $payData->pluck('nums','date'),
|
|
|
+ 'visit' => $visitData->pluck('nums','date'),
|
|
|
+ 'deal' => $dealData->pluck('nums','date'),
|
|
|
+ 'date' => $months
|
|
|
+ ];
|
|
|
+ return json_success('请求成功', $returnData);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Notes: 导出数据
|
|
|
* User: yb
|