StatisticsController.php
4.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;
use cmf\controller\AdminBaseController;
use app\portal\model\NeedAnswerModel;
use app\portal\model\MemberModel;
use app\portal\model\UserModel;
use app\portal\service\PostService;
use think\Db;
use think\Request;
use think\Loader;
/**
* @title 保证金内容管理
* @description 接口说明
* @group 接口分组
*/
class StatisticsController extends AdminBaseController
{
/**
* API返回信息格式函数 ;0失败,1成功,-1需要登录
* @param string $code
* @param string $message
* @param array $data
*/
public function apiResponse($code = '0', $message = '',$data = array(),$nums =0){
header('Access-Control-Allow-Origin: *');
header('Content-Type:application/json; charset=utf-8');
$result = array(
'code'=>$code,
'message'=>$message,
'data'=>$data,
'nums'=>''.$nums
);
die(json_encode($result,JSON_UNESCAPED_UNICODE));
}
// 列表
public function index(Request $request)
{
return $this->fetch('index');
}
public function find(){
// 注册人数
// 中介
$data = $this->request->param();
foreach ($data['time'] as $tk=>$tv){
$time[$tk]['start_time'] = strtotime($tv);
$time[$tk]['end_time'] = strtotime($tv)+86400;
}
$start_time = '';
$end_time = '';
$where_member['status'] = array('neq',9);
$all_member = Db::name('Member')->where($where_member)->select()->toArray();
$pie_user = 0;
$pie_member = 0;
// 筛选时间判断
if(!empty($data['start_time']) || !empty($data['end_time'])) {
// 搜索
if (!empty($data['start_time'])) {
$start_time = strtotime($data['start_time']);
}
if (!empty($data['end_time'])) {
$end_time = strtotime($data['end_time']);
}
}else{
// 默认
$date_str = date('Y-m-d',time());
$date_time = strtotime($date_str);
$end_time = time();
$start_time = $date_time;
}
// 饼状图
foreach ($all_member as $mk => $mv) {
if ($mv['create_time'] >= $start_time && $mv['create_time'] <= $end_time) {
if ($mv['type'] == 1) {
$pie_user += 1;
} else {
$pie_member += 1;
}
}
}
// 柱状图
foreach ($time as $timek=>$timev){
$user_add = 0;
$member_add = 0;
foreach ($all_member as $memberk=>$memberv){
// 判断时间
if($memberv['create_time'] >=$timev['start_time'] && $memberv['create_time'] <=$timev['end_time']){
// 判断类型
if($memberv['type'] == 1){
$user_add += 1;
}else{
$member_add += 1;
}
}
}
$user[] = $user_add;
$member[] = $member_add;
}
$final['user'] = $user;
$final['member'] = $member;
$final['start_time'] = $start_time;
$final['end_time'] = $end_time;
$final['pie_user'] = $pie_user;
$final['pie_member'] = $pie_member;
$this->apiResponse('1','成功',$final);
}
}