Index.php
12.9 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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
<?php
namespace app\admin\controller;
use think\Db;
use think\facade\Env;
use think\facade\Request;
class Index extends Common
{
public function initialize(){
parent::initialize();
}
public function index(){
//导航
// 获取缓存数据
$authRule = cache('authRule');
if(!$authRule){
$authRule = db('auth_rule')->where('menustatus=1')->order('sort')->select();
cache('authRule', $authRule, 3600);
}
//声明数组
$menus = array();
foreach ($authRule as $key=>$val){
$authRule[$key]['href'] = url($val['href']);
if($val['pid']==0){
if(session('aid')!=1){
if(in_array($val['id'],$this->adminRules)){
$menus[] = $val;
}
}else{
$menus[] = $val;
}
}
}
foreach ($menus as $k=>$v){
foreach ($authRule as $kk=>$vv){
if($v['id']==$vv['pid']){
if(session('aid')!=1) {
if (in_array($vv['id'], $this->adminRules)) {
$menus[$k]['children'][] = $vv;
}
}else{
$menus[$k]['children'][] = $vv;
}
}
}
}
//查询分组情况
$admin_info = db('admin')->field('group_id')->where('admin_id='.$_SESSION['think']['aid'])->select();
$url_address = in_array($admin_info[0]['group_id'],array(1,2,4,5)) ? url('main') : url('welcome');
//非内部人员 跳转其他页面
$this->assign('url_address',$url_address);
$this->assign('menus',json_encode($menus,true));
return $this->fetch();
}
//获取最近7天的所有日期
public function GetDate($format='Y-m-d'){
//组合数据
$date = [];
for ($i=1; $i<=7; $i++){
$date[date($format ,strtotime( '+' . $i-7 .' days'))]['sta'] = strtotime(date($format,strtotime( '+' . $i-7 .' days'))." 00:00:00");
$date[date($format ,strtotime( '+' . $i-7 .' days'))]['end'] = strtotime(date($format,strtotime( '+' . $i-7 .' days'))." 23:59:59");
}
return $date;
}
//构建地图分布
private function address_map(){
$arr = array(
array("name"=>"北京","value"=>0),
array("name"=>"天津","value"=>0),
array("name"=>"上海","value"=>0),
array("name"=>"重庆","value"=>0),
array("name"=>"河北","value"=>0),
array("name"=>"河南","value"=>0),
array("name"=>"云南","value"=>0),
array("name"=>"辽宁","value"=>0),
array("name"=>"黑龙江","value"=>0),
array("name"=>"湖南","value"=>0),
array("name"=>"安徽","value"=>0),
array("name"=>"山东","value"=>0),
array("name"=>"新疆","value"=>0),
array("name"=>"江苏","value"=>0),
array("name"=>"浙江","value"=>0),
array("name"=>"江西","value"=>0),
array("name"=>"湖北","value"=>0),
array("name"=>"广西","value"=>0),
array("name"=>"甘肃","value"=>0),
array("name"=>"山西","value"=>0),
array("name"=>"内蒙古","value"=>0),
array("name"=>"陕西","value"=>0),
array("name"=>"吉林","value"=>0),
array("name"=>"福建","value"=>0),
array("name"=>"贵州","value"=>0),
array("name"=>"广东","value"=>0),
array("name"=>"青海","value"=>0),
array("name"=>"西藏","value"=>0),
array("name"=>"四川","value"=>0),
array("name"=>"宁夏","value"=>0),
array("name"=>"海南","value"=>0),
array("name"=>"台湾","value"=>0),
array("name"=>"香港","value"=>0),
array("name"=>"澳门","value"=>0)
);
return $arr;
}
//主页
public function main() {
if(Request::isAjax()) {
$arr = cache('time_total');
if(!$arr){
$arr = array();
$time = $this->GetDate();
foreach ($time as $key => $value) {
$time[$key]['list'] = array_column( Db::query("SELECT
type
FROM
`xt-member-two-LINE`.xt_dc_reserve AS r
LEFT JOIN `xt-member-two-LINE`.xt_dc_dz_seller_type_rel AS t ON r.sid = t.sid
WHERE
r.cdate BETWEEN ".$value['sta']."
AND ".$value['end']."
AND t.type_id = 1 AND r.status not in (4,6)"), 'type');
$time[$key]['cancel'] = Db::query("SELECT
count(r.id) as cancel
FROM
`xt-member-two-LINE`.xt_dc_reserve AS r
LEFT JOIN `xt-member-two-LINE`.xt_dc_dz_seller_type_rel AS t ON r.sid = t.sid
WHERE
r.cdate BETWEEN ".$value['sta']."
AND ".$value['end']."
AND t.type_id = 1 AND r.status = 4");
$time[$key]['refuse'] = Db::query("SELECT
count(r.id) as refuse
FROM
`xt-member-two-LINE`.xt_dc_reserve AS r
LEFT JOIN `xt-member-two-LINE`.xt_dc_dz_seller_type_rel AS t ON r.sid = t.sid
WHERE
r.cdate BETWEEN ".$value['sta']."
AND ".$value['end']."
AND t.type_id = 1 AND r.status = 6");
}
foreach ($time as $key => $value) {
$arr['time'][] = $key; //日期
$arr['online'][] = array_sum($value['list']); //最近7天每天在线订单
$arr['unline'][] = count($value['list']) - array_sum($value['list']); //最近7天每天内部订单
$arr['cancel'][] = intval(join(",",$value['cancel'][0])); //最近7天每天取消的
$arr['refuse'][] = intval(join(",",$value['refuse'][0])); //最近7天每天拒单的
unset($time[$key]['list']);
}
$arr['online_sum'] = array_sum($arr['online']); //最近7天在线订单
$arr['unline_sum'] = array_sum($arr['unline']); //最近7天内部订单
$arr['cancel_sum'] = array_sum($arr['cancel']); //最近7天取消的
$arr['refuse_sum'] = array_sum($arr['refuse']); //最近7天拒单的
//获取全国商家分布图(合作与推广的商家)
$seller_total = Db::query("SELECT
province as `name`,
count( province ) AS `value`
FROM
`xt-member-two-LINE`.xt_dc_dz_address AS a
LEFT JOIN `xt-member-two-LINE`.xt_dc_dz_seller_type_rel AS r ON a.sid = r.sid
WHERE
province != ''
AND r.type_id IN ( 1, 2 )
GROUP BY
province ");
$arr['seller_total'] = $this->address_map();
foreach ($seller_total as $key => $value) {
foreach ($arr['seller_total'] as $k => $v) {
if(strstr($value['name'],$v['name']) !==false){
$arr['seller_total'][$k]['value'] = $value['value'];
}
}
}
array_multisort(array_column($arr['seller_total'],'value'),SORT_DESC,$arr['seller_total']); //按照商家数量排序
//获取首页基础数据
$user_total = Db::query("SELECT
count(*) AS total
FROM
`xt-member-two-LINE`.xt_dc_dz_wechat
WHERE
openid IS NOT NULL
AND openid != ''");
$res_total = Db::query("SELECT
count(*) AS total
FROM
`xt-member-two-LINE`.xt_dc_reserve AS r
LEFT JOIN `xt-member-two-LINE`.xt_dc_dz_seller_type_rel AS rel ON r.sid = rel.sid
WHERE
rel.type_id =1");
$price_total = Db::query(" SELECT
SUM(f.price) as total
FROM
`xt-member-two-LINE`.xt_dc_sms_flowing AS f
LEFT JOIN `xt-member-two-LINE`.xt_seller AS s ON f.sellerid = s.id
WHERE
f.paystatus = 1 and f.channel is null");
$seller_dv_total = Db::query(" SELECT
count(
DISTINCT ( d.sid )) AS total
FROM
`xt-member-two-LINE`.xt_dc_dz_seller_app_dv AS d
LEFT JOIN `xt-member-two-LINE`.xt_dc_dz_seller_type_rel AS r ON d.sid = r.sid
WHERE
r.type_id = 1");
$arr['user_total'] = $user_total ? $user_total[0]['total'] : 0;
$arr['res_total'] = $res_total ? $res_total[0]['total'] : 0;
$arr['sms_price_total'] = $price_total ? $price_total[0]['total'] : '0.00';
$arr['seller_dv_total'] = $seller_dv_total ? $seller_dv_total[0]['total'] : 0;
cache('time_total', $arr, 3600); //将数据集加入缓存
}
return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$arr,'rel'=>1];
}
$version = Db::query('SELECT VERSION() AS ver');
$config = [
'url' => $_SERVER['HTTP_HOST'],
'document_root' => $_SERVER['DOCUMENT_ROOT'],
'server_os' => PHP_OS,
'server_port' => $_SERVER['SERVER_PORT'],
'server_ip' => $_SERVER['SERVER_ADDR'],
'server_soft' => $_SERVER['SERVER_SOFTWARE'],
'php_version' => PHP_VERSION,
'mysql_version' => $version[0]['ver'],
'max_upload_size' => ini_get('upload_max_filesize')
];
//查询最近7天预订情况
$this->assign('config', $config);
return $this->fetch();
}
public function welcome(){
$config = "Welcome";
$this->assign('config', $config);
return $this->fetch();
}
public function navbar(){
return $this->fetch();
}
public function nav(){
return $this->fetch();
}
public function clear(){
$R = Env::get('runtime_path');
if ($this->_deleteDir($R)) {
$result['info'] = '清除缓存成功!';
$result['status'] = 1;
} else {
$result['info'] = '清除缓存失败!';
$result['status'] = 0;
}
$result['url'] = url('admin/index/index');
return $result;
}
private function _deleteDir($R)
{
$handle = opendir($R);
while (($item = readdir($handle)) !== false) {
if ($item != '.' and $item != '..') {
if (is_dir($R . '/' . $item)) {
$this->_deleteDir($R . '/' . $item);
} else {
if (!unlink($R . '/' . $item))
die('error!');
}
}
}
closedir($handle);
return rmdir($R);
}
//退出登陆
public function logout(){
session(null);
$this->redirect('login/index');
}
}