Dashboard.php
8.4 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<?php
namespace app\admin\controller;
use app\common\controller\Backend;
use think\Config;
use think\Db;
/**
* 控制台
*
* @icon fa fa-dashboard
* @remark 用于展示当前系统中的统计数据、统计报表及重要实时数据
*/
class Dashboard extends Backend
{
/**
* 查看
*/
public function index()
{
$seventtime = \fast\Date::unixtime('day', -7);
$paylist = $createlist = [];
for ($i = 0; $i < 7; $i++) {
$day = date("Y-m-d", $seventtime + ($i * 86400));
$createlist[$day] = mt_rand(20, 200);
$paylist[$day] = mt_rand(1, mt_rand(1, $createlist[$day]));
}
$hooks = config('addons.hooks');
$uploadmode = isset($hooks['upload_config_init']) && $hooks['upload_config_init'] ? implode(',', $hooks['upload_config_init']) : 'local';
$addonComposerCfg = ROOT_PATH . '/vendor/karsonzhang/fastadmin-addons/composer.json';
Config::parse($addonComposerCfg, "json", "composer");
$config = Config::get("composer");
$addonVersion = isset($config['version']) ? $config['version'] : __('Unknown');
/*Config 配置*/
//当日起止时间戳
$TodatStartTime = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
$TodatEndTime = mktime(0, 0, 0, date('m'), date('d') + 1, date('Y')) - 1;
/*新增逻辑*/
//当天登录人数总和 $todayuserlogin
$Dashboard = Db::name('dashboard')->find();
if (!empty($Dashboard)) {
if ($Dashboard['start'] != 0 && $Dashboard['end'] != 0) {
$map['updatetime'] = ['between', [$Dashboard['start'], $Dashboard['end']]];
$map2['createtime'] = ['between', [$Dashboard['start'], $Dashboard['end']]];
} else {
$map2 = [];
$map['updatetime'] = ['between', [$TodatStartTime, $TodatEndTime]];
}
if ($Dashboard['qudao_id'] != 1) {
$map3['qudao_id'] = ['EQ', $Dashboard['qudao_id']];
} else {
$map3 = [];
}
} else {
$map2 = [];
$map['updatetime'] = ['between', [$TodatStartTime, $TodatEndTime]];
$map3 = [];
}
Db::name('dashboard')->where('id', $Dashboard['id'])->delete();
$todayuserlogin = Db::name('user')->where($map)->select();
//当天成功支付人数总和
$todayorderUser = Db::name('pay_order')->where($map)->where('status', 1)->select();
$todayorder = $this->second_array_unique_bykey($todayorderUser, 'user_id');
//支付转化率 当天支付人数总和/当天登录人数总和
if (count($todayuserlogin) == 0 || count($todayorder) == 0) {
$sevendau = 0;
} else {
$sevendau = count($todayorder) / count($todayuserlogin) * 100;
}
//今日支付金额
if (empty($todayorder)) {
$unsettleorder = 0;
} else {
foreach ($todayorder as $k => $v) {
$TodayMoney[] = $v['money'];
}
$unsettleorder = array_sum($TodayMoney);
}
//当天成功支付订单数
$todayusersignup = Db::name('pay_order')->where($map)->where('status', 1)->select();
//人均订单数
if (count($todayusersignup) == 0 || count($todayorder) == 0) {
$sevendnu = 0;
} else {
$sevendnu = count($todayusersignup) / count($todayorder);
}
//新增新客数
$NewUserOrder = Db::name('pay_order')->where($map)->where('status', 1)->where('is_new', 1)->select();
//客单价
if ($unsettleorder == 0 || count($todayorder) == 0) {
$UserOrderPrice = 0;
} else {
$UserOrderPrice = $unsettleorder / count($todayorder);
}
//用户级别统计
//初始化参数
$First = 0;
$Second = 0;
$Third = 0;
$Fourth = 0;
$Fifth = 0;
$Sixth = 0;
$Seventh = 0;
$Eighth = 0;
$UserCountArray = Db::name('user')->where($map2)->where($map3)->select();
if (!empty($UserCountArray)) {
foreach ($UserCountArray as $k => $v) {
if ($v['level'] == 1) {
$First++;
} elseif ($v['level'] == 2) {
$Second++;
} elseif ($v['level'] == 3) {
$Third++;
} elseif ($v['level'] == 4) {
$Fourth++;
} elseif ($v['level'] == 5) {
$Fifth++;
} elseif ($v['level'] == 6) {
$Sixth++;
} elseif ($v['level'] == 7) {
$Seventh++;
} elseif ($v['level'] == 8) {
$Eighth++;
}
}
}
//授权登录人数
$CountMiniAppLoginHistory = Db::name('user')->where($map2)->select();
//当前做过测试人数
$SleepHistoryArray = Db::name('sleep')->where($map2)->select();
$SleepHistory = $this->second_array_unique_bykey($SleepHistoryArray, 'user_id');
//当前获取报告人数
$SleepTypeFirstArray = Db::name('sleep')->where($map2)->where('type', 1)->select();
$SleepTypeFirst = $this->second_array_unique_bykey($SleepHistoryArray, 'user_id');
//当前下过单的人数
$UpOrderNumArray = Db::name('pay_order')->where($map2)->where('status', 1)->select();
$UpOrderNum = $this->second_array_unique_bykey($UpOrderNumArray, 'user_id');
//渠道下拉菜单
$Qudao = Db::name('qudao_title')->select();
$this->view->assign([
/*用户级别统计*/
'UserFirst' => $First,
'UserSecond' => $Second,
'UserThird' => $Third,
'UserFourth' => $Fourth,
'UserFifth' => $Fifth,
'UserSixth' => $Sixth,
'UserSeventh' => $Seventh,
'UserEighth' => $Eighth,
//当前授权登录人数
'CountMiniAppLoginHistory' => count($CountMiniAppLoginHistory),
//当前做过测试人数
'SleepHistory' => count($SleepHistory),
//当前获取报告人数
'SleepTypeFirst' => count($SleepTypeFirst),
//当前下过单的人数
'UpOrderNum' => count($UpOrderNum),
//当天登录人数总和
'todayuserlogin' => count($todayuserlogin),
//当天成功支付订单数
'todayusersignup' => count($todayusersignup),
//当天成功支付人数总和
'todayorder' => count($todayorder),
//今日支付金额
'unsettleorder' => $unsettleorder,
//人均订单数
'sevendnu' => $sevendnu,
//支付转化率
'sevendau' => $sevendau . '%',
//新增新客数
'NewUserOrder' => count($NewUserOrder),
//客单价
'UserOrderPrice' => $UserOrderPrice,
'paylist' => $paylist,
'createlist' => $createlist,
'addonversion' => $addonVersion,
'uploadmode' => $uploadmode,
//渠道下拉菜单
'qudao' => $Qudao
]);
return $this->view->fetch();
}
// 数组去重
function second_array_unique_bykey($arr, $key)
{
$tmp_arr = array();
foreach ($arr as $k => $v) {
if (in_array($v[$key], $tmp_arr)) //搜索$v[$key]是否在$tmp_arr数组中存在,若存在返回true
{
unset($arr[$k]); //销毁一个变量 如果$tmp_arr中已存在相同的值就删除该值
} else {
$tmp_arr[$k] = $v[$key]; //将不同的值放在该数组中保存
}
}
//ksort($arr); //ksort函数对数组进行排序(保留原键值key) sort为不保留key值
return $arr;
}
public function ajaxBtn()
{
if ($this->request->isPost()) {
$params = $this->request->param();
$Start = strtotime($params['Start']);
$End = strtotime($params['End']);
$data = [
'start' => $Start,
'end' => $End,
'qudao_id' => $params['Qudao']
];
$res = Db::name('dashboard')->insert($data);
if ($res) {
$this->success();
} else {
$this->error('查询失败');
}
}
}
}