-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetMsg.php
68 lines (64 loc) · 2.43 KB
/
getMsg.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
<?php
header("content-type:text/html;charset=utf-8");
include_once __DIR__ . "/common.php";
$data = initPostData();
$token = $data['token'];
$page = (int)$data['page'];
$read_class = $data['read_class'];
$pagesize = 30;// = (int)$data['pagesize'];
if (!$page) {
$page=0;
}
$con = pdo_database();
if ($token) {
[$openid, $identity, $nickName] = pdoCheckUserPrivilege($con, $token);
//var_dump([$token,$openid,$identity,$nickName]);
}
if ($identity == 's' || $identity == 'a'){
$isA = 1;
} else {
$isA = 0;
}
// 还得有一个切换已读/未读的按钮
if ($openid) {
$poffset = $page*$pagesize;
$sqlGetMsgs = "SELECT msgid,msg_status,toadmin,msg_with_user,msg_with_cat,msgdate,msg from messages WHERE ";
if ($read_class = 'all') {
if ($identity == 's') {
$sqlGetMsgs .= "openid = :openid OR toadmin!=0";
} elseif ($identity == 'a') {
$sqlGetMsgs .= "openid = :openid OR toadmin=1";
} else {
$sqlGetMsgs .= "openid = :openid";
}
} elseif ($read_class = 'marked') {
if ($identity == 's') {
$sqlGetMsgs .= "(openid = :openid AND (msg_status!=0 AND msg_status!=2)) OR (toadmin!=0 AND msg_status!=2)";
} elseif ($identity == 'a') {
$sqlGetMsgs .= "(openid = :openid AND (msg_status!=0 AND msg_status!=2)) OR (toadmin=1 AND msg_status!=2)";
} else {
$sqlGetMsgs .= "openid = :openid AND (msg_status!=0 AND msg_status!=2)";
}
} elseif ($read_class = 'tomark') {
if ($identity == 's') {
$sqlGetMsgs .= "(openid = :openid AND (msg_status=0 OR msg_status=2)) OR (toadmin!=0 AND msg_status=2)";
} elseif ($identity == 'a') {
$sqlGetMsgs .= "(openid = :openid AND (msg_status=0 OR msg_status=2)) OR (toadmin=1 AND msg_status=2)";
} else {
$sqlGetMsgs .= "openid = :openid AND (msg_status=0 OR msg_status=2)";
}
}
$sqlGetMsgs .= " ORDER BY `msgid` DESC LIMIT $poffset,$pagesize;";
$sthGetMsgs = $con->prepare($sqlGetMsgs, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
$sthGetMsgs->execute(array(':openid' => $openid));
$msgs = $sthGetMsgs->fetchAll(PDO::FETCH_ASSOC);
$result = array();
$result['code'] = 10;
$result['msgs'] = $msgs;
$result['isadmin'] = $isA;
echo json_encode($result, JSON_UNESCAPED_UNICODE);
$con = null;
} else {
$con = null;
die('{"code":1002,"msg":"请重新登录!"}');
}