-
Notifications
You must be signed in to change notification settings - Fork 93
/
ajax_home.php
458 lines (442 loc) · 15.7 KB
/
ajax_home.php
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
<?php
include '../common/servers.php';
include S_ROOT.'class/class_db_factory.php';
// 判断是否登陆
session_start();
if (!isset($_SESSION['user_name']) || empty($_SESSION['user_name'])) {
echo '{"code": 1, "message": "请重新登录"}';
die;
}
$active = isset($_POST['action']) ? trim($_POST['action']).'Action' : '';
api_log($active);
$today = date('Y-m-d',strtotime('-1 days'));
$start_date = isset($_REQUEST['start_date']) && !empty($_REQUEST['start_date']) ? $_REQUEST['start_date'] : date("Y-m-d", strtotime("$today -1 months"));
$end_date = isset($_REQUEST['end_date']) && !empty($_REQUEST['end_date']) ? $_REQUEST['end_date'] : $today;
$hour = date('G');
//$date = isset($_REQUEST['date']) && !empty($_REQUEST['date']) ? $_REQUEST['date'] : $today;
//选择用户登录下单时间
$start_period = isset($_REQUEST['start_period']) && !empty($_REQUEST['start_period']) ? $_REQUEST['start_period'] : $hour-1;
$end_period = isset($_REQUEST['end_period']) && !empty($_REQUEST['end_period']) ? $_REQUEST['end_period'] : $hour;
echo $active();
function getDatesBetweenTwoDate($start,$end) {
$dt_start = strtotime($start);
$dt_end = strtotime($end);
while ($dt_start <= $dt_end) {
$date_arr[] = date('Y-m-d',$dt_start);
$dt_start += 86400;
}
return $date_arr;
}
// 获取新增订单
function getNewOrdersAction() {
global $start_date;
global $end_date;
$db = DbFactory::getInstance()->getDB();
$result = array();
api_log("select sum(order_count) count, date from tbl_user_record group by date having date between '".$start_date."' and '".$end_date."' order by date asc");
$data = $db->getData("select sum(order_count) count, date from tbl_user_record group by date having date between '".$start_date."' and '".$end_date."' order by date asc");
//$data_count = $db->getData("select sum(order_success_count) count, date from tbl_user_record group by date having date between '".$start_date."' and '".$end_date."' order by date asc");
//完成订单
$data_count = $db->getData("select count(order_id) count, date from tbl_order where status in(3,4 ) group by date having date between '".$start_date."' and '".$end_date."' order by date asc");
$result['code'] = 0;
$categories = array();
$series = array();
$date_arr = getDatesBetweenTwoDate($start_date, $end_date);
if (!empty($date_arr)) {
foreach ($date_arr as $val_date) {
$categories[] = $val_date;
if ( false !== $data ) {
$i = 0;
$len = count($data);
foreach ($data as $key_user => $value_user) {
$i++;
if ($val_date == $value_user['date']) {
$series[] = (int)$value_user['count'];
break;
} else if ($i == $len) {
$series[] = 0;
}
}
}
if ( false !== $data_count ) {
$i = 0;
$len = count($data_count);
foreach ($data_count as $key_user => $value_user) {
$i++;
if ($val_date == $value_user['date']) {
$series_count[] = (int)$value_user['count'];
break;
} else if ($i == $len) {
$series_count[] = 0;
}
}
}
}
$result['data']['categories'] = $categories;
$result['data']['series'] = $series;
$result['data']['series_count'] = $series_count;
echo json_encode($result);
} else {
$result['code'] = 1;
echo json_encode($result);
}
}
// 获取新增用户
function getNewUsersAction() {
global $start_date;
global $end_date;
$result = array();
api_log("select sum(amount) count, date from tbl_user_summary group by date having date between '".$start_date."' and '".$end_date."' order by date asc");
$db = DbFactory::getInstance()->getDB();
$data = $db->getData("select sum(amount) count, date from tbl_user_summary where type=1 group by date having date between '".$start_date."' and '".$end_date."' order by date asc");
$date_arr = getDatesBetweenTwoDate($start_date, $end_date);
foreach($data as $k =>$v ){
$new[$v['date']]=$v["count"];
}
$data =array();
foreach($date_arr as $key =>$val ){
$data[$key]['count'] = isset($new[$val]) ? $new[$val] : 0;
$data[$key]['date'] = $val;
}
$newdata = $data;
//按date排序
usort($data, function($a, $b) {
if($a['date'] == $b['date']) return 0;
return $a['date'] > $b['date'] ? 1 : -1;
});
$amount = 0;
foreach($data as &$item) {
$amount += $item['count'];
$item['count'] = $amount;
}
unset($item);
$count_data = $data;//总用户数
$result['code'] = 0;
$categories = array();
$series = array();
$series_count = array();
if (!empty($date_arr)) {
foreach ($date_arr as $val_date) {
$categories[] = $val_date;
if (false != $newdata) {
$i = 0;
$len = count($newdata);
foreach ($newdata as $key_user => $value_user) {
$i++;
if ($val_date == $value_user['date']) {
$series[] = (int)$value_user['count'];
break;
} else if ($i == $len) {
$series[] = 0;
}
}
} else {
$series[] = 0;
}
if (false != $count_data) {
$i = 0;
$len = count($count_data);
foreach ($count_data as $key_count => $value_count) {
$max_count[] = $value_count['count'];
$i++;
if ($val_date == $value_count['date']) {
$series_count[] = (int)$value_count['count'];
break;
}else if ($i == $len) {
$series_count[] = 0;
}
}
} else {
$series_count[] = 0;
}
}
$result['data']['categories'] = $categories;
$result['data']['series'] = $series;
$result['data']['series_count'] = $series_count;
echo json_encode($result);
} else {
$result['code'] = 1;
echo json_encode($result);
}
}
//新增uv与活跃uv
function getSummaryAction() {
global $start_date;
global $end_date;
$result = array();
$db = DbFactory::getInstance()->getDB();
$data = $db->getData("select sum(amount) count,date from tbl_user_summary where type=1 group by date having date between '".$start_date."' and '".$end_date."' order by date asc");
$data_report = $db->getData("select sum(amount) count,date from tbl_user_summary where type=3 group by date having date between '".$start_date."' and '".$end_date."' order by date asc");
$result['code'] = 0;
$categories = array();
$series = array();
$series_report = array();
$date_arr = getDatesBetweenTwoDate($start_date, $end_date);
if (!empty($date_arr)) {
foreach ($date_arr as $key_date => $value_date) {
$categories[] = $value_date;
if (false != $data) {
$i = 0;
$len = count($data);
foreach ($data as $key_report => $value_report) {
$i++;
if ($value_date == $value_report['date']) {
$series[] = (int)$value_report['count'];
break;
} else if ($i == $len) {
$series[] = 0;
}
}
} else {
$series[] = 0;
}
if (false != $data_report) {
$i = 0;
$len = count($data_report);
foreach ($data_report as $key_report => $value_report) {
$i++;
if ($value_date == $value_report['date']) {
$series_report[] = (int)$value_report['count'];
break;
} else if ($i == $len) {
$series_report[] = 0;
}
}
} else {
$series_report[] = 0;
}
}
$result['data']['categories'] = $categories;
$result['data']['series'] = $series;
$result['data']['series_report'] = $series_report;
echo json_encode($result);
} else {
$result['code'] = 1;
echo json_encode($result);
}
}
//用户时间段内登陆次数、下单次数与完成订单次数
function getBehaviorAction() {
global $start_period;
global $end_period;
global $start_date;
global $end_date;
$result = array();
$db = DbFactory::getInstance()->getDB();
//api_log("select sum(amount) count ,time_period from tbl_user_behavior where date between '{$start_date}' and '{$end_date}' and type=2 and amount>1 group by time_period,date");
$data = $db->getData("select sum(amount) count ,time_period from tbl_user_behavior where date between '{$start_date}' and '{$end_date}' and type=1 group by time_period");//user_id in (select user_id from tbl_user_behavior where type=2 and amount>1) and
$data_order = $db->getData("select sum(amount) count ,time_period from tbl_user_behavior where date between '{$start_date}' and '{$end_date}' and type=2 group by time_period,date");
$data_finish = $db->getData("select sum(amount) count ,time_period from tbl_user_behavior where date between '{$start_date}' and '{$end_date}' and type=3 group by time_period");
//api_log_array($data);api_log_array($data_order);api_log_array($data_finish);
$data = getAmountByTime($data);
$data_order = getAmountByTime($data_order);
$data_finish = getAmountByTime($data_finish);
$result['code'] = 0;
$categories = array();
$series = array();
$series_order = array();
$series_finish = array();
$date_arr = range(0,23);
if (!empty($date_arr)) {
foreach ($date_arr as $key_date => $value_date) {
$categories[] = $value_date;
if (false != $data) {
$i = 0;
$len = count($data);
foreach ($data as $key_report => $value_report) {
$i++;
if ($value_date == $value_report['time_period']) {
$series[] = (int)$value_report['count'];
break;
} else if ($i == $len) {
$series[] = 0;
}
}
} else {
$series[] = 0;
}
if (false != $data_order) {
$i = 0;
$len = count($data_order);
foreach ($data_order as $key_order => $value_order) {
$i++;
if ($value_date == $value_order['time_period']) {
$series_order[] = (int)$value_order['count'];
break;
} else if ($i == $len) {
$series_order[] = 0;
}
}
} else {
$series_order[] = 0;
}
if (false != $data_finish) {
$i = 0;
$len = count($data_finish);
foreach ($data_finish as $key_finish => $value_finish) {
$i++;
if ($value_date == $value_finish['time_period']) {
$series_finish[] = (int)$value_finish['count'];
break;
} else if ($i == $len) {
$series_finish[] = 0;
}
}
} else {
$series_finish[] = 0;
}
}
$result['data']['categories'] = $categories;
$result['data']['series'] = $series;
$result['data']['series_order'] = $series_order;
$result['data']['series_finish'] = $series_finish;
echo json_encode($result);
} else {
$result['code'] = 1;
echo json_encode($result);
}
}
//获取每日订单均价
function getAvgPriceOrderAction() {
global $start_date;
global $end_date;
$db = DbFactory::getInstance()->getLifeDB();
include(S_ROOT.'common/filter_test.php');
$forbidden = array_merge($forbidden_bj,$forbidden_sz);
$forbidden = implode(',',$forbidden);
$forbidden_phone = implode(',',$forbidden_phone);
$result = array();
api_log("avgPrice: select count(*) count,sum(total_price) sum,from_unixtime(created, '%Y-%m-%d') as date from torder where shop_id not in ({$forbidden}) and id not in (select order_id id from torder_detail where phone in ({$forbidden_phone})) group by date having date between '".$start_date."' and '".$end_date."' order by date asc");
$data = $db->getData("select count(*) count,sum(total_price) sum,from_unixtime(created, '%Y-%m-%d') as date from torder where shop_id not in ({$forbidden}) and id not in (select order_id id from torder_detail where phone in ({$forbidden_phone})) group by date having date between '".$start_date."' and '".$end_date."' order by date asc");
if (false != $data) {
$result['code'] = 0;
$categories = array();
$series = array();
$date_arr = getDatesBetweenTwoDate($start_date, $end_date);
if (!empty($date_arr)) {
foreach ($date_arr as $val_date) {
$i = 0;
$len = count($data);
foreach ($data as $key_user => $value_user) {
$i++;
if ($val_date == $value_user['date']) {
$categories[] = $value_user['date'];
$series[] = round(floatval($value_user['sum']) / (int)$value_user['count'], 2);
break;
} else if ($i == $len) {
$categories[] = $val_date;
$series[] = 0;
}
}
}
$result['data']['categories'] = $categories;
$result['data']['series'] = $series;
echo json_encode($result);
}
} else {
$result['code'] = 1;
echo json_encode($result);
}
}
//获取理投诉
function getReportAction() {
global $start_date;
global $end_date;
$result = array();
$db = DbFactory::getInstance()->getLifeDB();
//未处理
$data = $db->getData("select count(*) count,from_unixtime(created, '%Y-%m-%d') as date from report where type = 0 and is_checked = 0
group by date having date between '".$start_date."' and '".$end_date."' order by date asc");
//已经处理
$data_report = $db->getData("select count(*) count,from_unixtime(created, '%Y-%m-%d') as date from report where type = 0 and is_checked <> 0
group by date having date between '".$start_date."' and '".$end_date."' order by date asc");
$result['code'] = 0;
$categories = array();
$series = array();
$series_report = array();
$date_arr = getDatesBetweenTwoDate($start_date, $end_date);
if (!empty($date_arr)) {
foreach ($date_arr as $key_date => $value_date) {
$categories[] = $value_date;
if (false != $data) {
$i = 0;
$len = count($data);
foreach ($data as $key_report => $value_report) {
$i++;
if ($value_date == $value_report['date']) {
$series[] = (int)$value_report['count'];
break;
} else if ($i == $len) {
$series[] = 0;
}
}
} else {
$series[] = 0;
}
if (false != $data_report) {
$i = 0;
$len = count($data_report);
foreach ($data_report as $key_report => $value_report) {
$i++;
if ($value_date == $value_report['date']) {
$series_report[] = (int)$value_report['count'];
break;
} else if ($i == $len) {
$series_report[] = 0;
}
}
} else {
$series_report[] = 0;
}
}
$result['data']['categories'] = $categories;
$result['data']['series'] = $series;
$result['data']['series_report'] = $series_report;
echo json_encode($result);
} else {
$result['code'] = 1;
echo json_encode($result);
}
}
//第一次关注后行为
function getOperateAction() {
global $start_date;
global $end_date;
$result = array();
$data = array();
$db = DbFactory::getInstance()->getDB();
$data_action = $db->getData("select count(id) count,type from tbl_first_action where type>0 group by type");
foreach ($data_action as $k=>$v) {
$data[$v['type']] = $v['count'];
}
$arr = array(1,2,3,4,5,6);
foreach ($arr as $k=>$v) {
$data[$v] = array_key_exists($v, $data) ? $data[$v] : 0;
}
if ($data != false) {
$series = array(
array("附近店铺",(int)$data[1]),
array("我的订单", (int)$data[2]),
array("帮助", (int)$data[3]),
array("关于", (int)$data[4]),
array("上传位置", (int)$data[5]),
array("图文", (int)$data[6])
);
$result['code'] = 0;
$result['data']['series'] = $series;
}
echo json_encode($result);
}
//获取2个时间段的amount
function getAmountByTime($data){
$temp = array();
foreach($data as $item) {
list($n, $p) = array_values($item);
$temp[$p] = array_key_exists($p, $temp) ? $temp[$p]+$n : $n;
}
$arr = array();
foreach($temp as $p => $n) {
$arr[] = array('count'=>$n, 'time_period'=>$p);
}
return $arr;
}