Repository navigation
Expand file tree
/
Copy pathSiteFriendApplyTable.php
More file actions
184 lines (161 loc) · 5.27 KB
/
Copy pathSiteFriendApplyTable.php
File metadata and controls
184 lines (161 loc) · 5.27 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
<?php
/**
* Created by PhpStorm.
* User: childeYin<尹少爷>
* Date: 01/08/2018
* Time: 4:45 PM
*
*/
class SiteFriendApplyTable extends BaseTable
{
private $table = "siteFriendApply";
private $columns = [
"id",
"userId",
"friendId",
"greetings",
"applyTime"
];
private $selectColumns;
public function init()
{
$this->selectColumns = implode(",", $this->columns);
}
public function insertApplyData($data)
{
return $this->insertData($this->table, $data, $this->columns);
}
public function updateApplyData($where, $data)
{
return $this->updateInfo($this->table, $where, $data, $this->columns);
}
/**
* remove friend apply data
*
* @param $fromUserId
* @param $toUserId
* @return bool
* @throws Exception
*/
public function deleteApplyData($fromUserId, $toUserId)
{
$tag = __CLASS__ . "-" . __FUNCTION__;
$startTime = $this->getCurrentTimeMills();
$sql = "delete from $this->table where userId=:userId and friendId=:friendId;";
try {
$prepare = $this->db->prepare($sql);
$this->handlePrepareError($tag, $prepare);
$prepare->bindValue(":userId", $fromUserId);
$prepare->bindValue(":friendId", $toUserId);
$prepare->execute();
$num = $prepare->rowCount();
return $num > 0;
} finally {
$costTime = $this->getCurrentTimeMills() - $startTime;
$this->ctx->Wpf_Logger->dbLog($tag, $sql, [$fromUserId, $toUserId], $costTime, $num);
}
}
public function getDataByWhere($where, $limit = 0, $offset = 1)
{
$tag = __CLASS__ . "-" . __FUNCTION__;
if (!is_array($where)) {
throw new Exception("where params is error");
}
$whereKeys = array_keys($where);
$whereStr = "";
foreach ($whereKeys as $k => $key) {
$whereStr .= " $key=:$key and";
}
$whereStr = trim($whereStr, "and");
$sql = "select $this->selectColumns from $this->table where $whereStr limit :limit, :offset";
$prepare = $this->dbSlave->prepare($sql);
$this->handlePrepareError($tag, $prepare);
foreach ($where as $key => $val) {
$prepare->bindValue(":$key", $val);
}
$prepare->bindValue(":limit", $limit);
$prepare->bindValue(":offset", $offset);
$prepare->execute();
$results = $prepare->fetchAll(\PDO::FETCH_ASSOC);
return $results;
}
/**
* @param $userId
* @param $applyUserId
* @return mixed
* @throws Exception
*/
public function getApplyData($userId, $applyUserId)
{
$tag = __CLASS__ . "-" . __FUNCTION__;
$sql = "select
$this->selectColumns
from
$this->table
where
userId=:userId and friendId=:friendId order by applyTime desc limit 1;";
$prepare = $this->dbSlave->prepare($sql);
$this->handlePrepareError($tag, $prepare);
$prepare->bindValue(":userId", $userId);
$prepare->bindValue(":friendId", $applyUserId);
$prepare->execute();
return $prepare->fetch(\PDO::FETCH_ASSOC);
}
public function getApplyList($friendId, $offset, $limit)
{
$tag = __CLASS__ . "-" . __FUNCTION__;
$sql = "
select
siteFriendApply.greetings,
siteFriendApply.applyTime,
siteUser.userId,
siteUser.avatar,
siteUser.loginName,
siteUser.nickname,
siteUser.nicknameInLatin,
siteUser.availableType
from
siteFriendApply
inner join
siteUser
on
siteUser.userId = siteFriendApply.userId
where
siteFriendApply.friendId = :friendId
order BY
siteFriendApply.applyTime DESC
limit
:offset, :limit;";
$prepare = $this->dbSlave->prepare($sql);
$this->handlePrepareError($tag, $prepare);
$prepare->bindValue(":friendId", $friendId);
$prepare->bindValue(":offset", $offset, PDO::PARAM_INT);
$prepare->bindValue(":limit", $limit, PDO::PARAM_INT);
$prepare->execute();
$results = $prepare->fetchAll(\PDO::FETCH_ASSOC);
$this->ctx->Wpf_Logger->dbLog($tag, $sql, [$friendId, $offset, $limit], "", "");
return $results;
}
public function getApplyListCount($friendId)
{
$tag = __CLASS__ . "-" . __FUNCTION__;
$sql = "
select
count(siteFriendApply.friendId) as count
from
siteFriendApply
inner join
siteUser
on
siteUser.userId = siteFriendApply.userId
where
siteFriendApply.friendId = :friendId
";
$prepare = $this->dbSlave->prepare($sql);
$this->handlePrepareError($tag, $prepare);
$prepare->bindValue(":friendId", $friendId);
$prepare->execute();
$results = $prepare->fetchColumn();
return $results;
}
}