-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetListV2.php
More file actions
109 lines (100 loc) · 3.57 KB
/
getListV2.php
File metadata and controls
109 lines (100 loc) · 3.57 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
<?php
header("content-type:text/html;charset=utf-8");
include_once(__DIR__ . "/common.php");
$data = initPostData();
$name = $sex = $health = $TNR = $keyword = $sch_area = $adopt = '';
$name = $data['name']; //~~~
$sex = $data['sex']; //empty/male/female
$health = $data['health']; //empty/healthy/sick/death
$TNR = $data['tnr']; //empty/cut/cutting
$keyword = $data['keyword']; //~~~
$sch_area = $data['area']; //empty/west/east/north/south/middle/ustciat/island/other
$adopt = $data['adopt']; //empty/yes/no
$color = $data['color'];
$status = $data['status']; //all/insc在校/grad毕业/miss休学/dead喵星
$page = (int)$data['page'];
$sorting_type = $data['sorting'];
$pagesize = 30;// = (int)$data['pagesize'];
if (!$page) {
$page=0;
}
$tag = $data['tag'];
$con = pdo_database();
$arr = array();
$SCondition = "SELECT id,name,sex,color,TNR,adopt,sch_area,health,rec_count FROM `catsinfo` WHERE ";
if(strlen($status) > 0 && $status != 'all') {
switch ($status) {
case 'insc'://在校:健康,未领养
$SCondition .= "health = 'healthy' AND adopt != 'yes' AND ";
break;
case 'grad'://毕业:已领养
$SCondition .= "health = 'healthy' AND adopt = 'yes' AND ";
break;
case 'miss'://休学:失踪
$SCondition .= "health = 'missing' AND ";
break;
case 'dead'://喵星:去世
$SCondition .= "health = 'death' AND ";
break;
#TODO:猫猫列表
case 'empty'://不明,需要补完,给管理员单开一个?
$SCondition .= "health = 'empty' AND ";
break;
default:
# code...
break;
}
}else {
if (strlen($adopt) > 0) { #根据领养情况进行筛选
$SCondition .= "adopt = :adopt AND ";
$arr[':adopt'] = $adopt;
}
if (strlen($health) > 0) { #根据健康情况进行筛选
$SCondition .= "health = :health AND ";
$arr[':health'] = $health;
}
}
if (strlen($sch_area) > 0 && $sch_area != 'all') { #根据校区进行筛选
$SCondition .= "sch_area = :sch_area AND ";
$arr[':sch_area'] = $sch_area;
}
if (strlen($sex) > 0) { #根据性别进行筛选
$SCondition .= "sex = :sex AND ";
$arr[':sex'] = $sex;
}
if (strlen($name) > 0) { #根据名字进行筛选
$SCondition .= "name LIKE :name AND ";
$arr[':name'] = "%$name%";
}
if (strlen($TNR) > 0) { #根据绝育情况进行筛选
$SCondition .= "TNR = :tnr AND ";
$arr[':tnr'] = $TNR;
}
if (strlen($color) > 0 && $color != 'all') { #根据健康情况进行筛选
$SCondition .= "color = :color AND ";
$arr[':color'] = $color;
}
if (strlen($keyword) > 0) { #根据关键词进行筛选
$SCondition .= "(name LIKE :keyword OR description LIKE :keyword ) AND ";
$arr[':keyword'] = '%' . "$keyword" . '%';
}
$poffset = $page*$pagesize;
switch ($sorting_type) {
case 'iddesc':
// 降序
$SCondition .= "hide = 0 ORDER BY `id` DESC LIMIT $poffset,$pagesize;";
break;
case 'idasc':
// 升序
$SCondition .= "hide = 0 ORDER BY `id` ASC LIMIT $poffset,$pagesize;";
break;
default:
$SCondition .= "hide = 0 ORDER BY `rec_count` DESC,`id` DESC LIMIT $poffset,$pagesize;";
break;
}
// $SCondition .= "hide = 0 ORDER BY `rec_count` DESC,`id` DESC LIMIT $poffset,$pagesize;";
$sth = $con->prepare($SCondition, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
$sth->execute($arr);
$rows = $sth->fetchAll(PDO::FETCH_ASSOC);
echo json_encode($rows, JSON_UNESCAPED_UNICODE);
$con = null;