Commit 4e13372b29c66c20cb66eaff92a47024f9f2eb03
1 parent
4652874d
[留言板]留言模型类优化
Showing
2 changed files
with
74 additions
and
39 deletions
trunk/Message/Common/Model/MessageModel.class.php
1 | 1 | <?php |
2 | - | |
3 | 2 | namespace Common\Model; |
4 | 3 | |
5 | 4 | class MessageModel extends AbstractModel |
... | ... | @@ -36,8 +35,12 @@ class MessageModel extends AbstractModel |
36 | 35 | * @param $page int 页码 |
37 | 36 | * @return array |
38 | 37 | */ |
39 | - public function messageList($conds = [],$page = 0) | |
38 | + public function message_list($conds = [],$page = 0) | |
40 | 39 | { |
40 | + if ($page < 1 || !$page) { | |
41 | + $page = self::PAGING_DEFAULT_PAGE; | |
42 | + } | |
43 | + | |
41 | 44 | $params = []; |
42 | 45 | $wheres = []; |
43 | 46 | |
... | ... | @@ -49,11 +52,8 @@ class MessageModel extends AbstractModel |
49 | 52 | } |
50 | 53 | |
51 | 54 | $page_size = self::PAGING_DEFAULT_LIMIT; |
52 | - $page_start = self::PAGING_DEFAULT_PAGE; | |
53 | 55 | |
54 | - if ($page) { | |
55 | - $page_start = ($page - 1) * $page_size; | |
56 | - } | |
56 | + $page_start = ($page - 1) * $page_size; | |
57 | 57 | |
58 | 58 | $option = [$page_start,$page_size]; |
59 | 59 | |
... | ... | @@ -64,7 +64,7 @@ class MessageModel extends AbstractModel |
64 | 64 | |
65 | 65 | |
66 | 66 | if (in_array('title',$conds)) { |
67 | - $where = " title LIKE ? "; | |
67 | + $where = " title LIKE '?' "; | |
68 | 68 | } |
69 | 69 | else{ |
70 | 70 | $fields = array_keys($conds); |
... | ... | @@ -77,13 +77,20 @@ class MessageModel extends AbstractModel |
77 | 77 | |
78 | 78 | } |
79 | 79 | |
80 | - $sql = "SELECT a.* FROM __TABLE__ a | |
80 | + $sql = "SELECT a.message_id,a.title,a.message,IFNULL(b.name,'') AS `from`,IFNULL(c.name,'') AS `to`,a.checked | |
81 | + FROM __TABLE__ a | |
81 | 82 | LEFT JOIN {$table} b ON a.uid = b.person_id |
83 | + LEFT JOIN {$table} c ON a.receiver_uid = c.person_id | |
82 | 84 | WHERE $where"; |
83 | 85 | |
84 | 86 | $list = $this->_m->fetch_array($sql, $params,$option); |
85 | 87 | |
86 | - return $list; | |
88 | + $messageList['total'] = count($list); | |
89 | + $messageList['page'] = $page; | |
90 | + $messageList['limit'] = $page_size; | |
91 | + $messageList['list'] = $list; | |
92 | + | |
93 | + return $messageList; | |
87 | 94 | } |
88 | 95 | |
89 | 96 | /** |
... | ... | @@ -162,9 +169,6 @@ class MessageModel extends AbstractModel |
162 | 169 | $where = " $field = ? "; |
163 | 170 | } |
164 | 171 | |
165 | -// print_r($conds); | |
166 | -// print_r($where); | |
167 | -// die; | |
168 | 172 | if ($where) { |
169 | 173 | $sql = "SELECT a.* FROM __TABLE__ a |
170 | 174 | JOIN {$table} b ON a.uid = b.person_id |
... | ... | @@ -185,7 +189,7 @@ class MessageModel extends AbstractModel |
185 | 189 | * @return array|bool |
186 | 190 | * Date: 2018-10-11 Time: 11:47 |
187 | 191 | */ |
188 | - public function messageDetail($message_id = 0) | |
192 | + public function message_detail($message_id = 0) | |
189 | 193 | { |
190 | 194 | $params = []; |
191 | 195 | $wheres = []; |
... | ... | @@ -213,15 +217,16 @@ class MessageModel extends AbstractModel |
213 | 217 | $table_attachment = $m_attachment->get_tname(); |
214 | 218 | |
215 | 219 | |
216 | - $sql = "SELECT attachment FROM __TABLE__ m WHERE `message_id` = 5 "; | |
217 | - $attachment_id_arr = $this->_m->query($sql); | |
218 | - | |
219 | - $attachment_id_str = $attachment_id_arr[0]['attachment']; | |
220 | + $attachment_id_str = $this->getAttachmentIdByMsgId($message_id); | |
220 | 221 | |
221 | - $sql = "SELECT `path` FROM {$table_attachment} | |
222 | + $attachment = []; | |
223 | + if ($attachment_id_str) { | |
224 | + $sql = "SELECT `path` FROM {$table_attachment} | |
222 | 225 | WHERE attachment_id IN ($attachment_id_str)"; |
223 | 226 | |
224 | - $attachment = $this->_m->fetch_array($sql,$params); | |
227 | + $attachment = $this->_m->fetch_array($sql,$params); | |
228 | + } | |
229 | + | |
225 | 230 | |
226 | 231 | $message['attachment'] = $attachment; |
227 | 232 | |
... | ... | @@ -254,7 +259,36 @@ class MessageModel extends AbstractModel |
254 | 259 | FROM __TABLE__ WHERE `message_id` = ? "; |
255 | 260 | $attachment = $this->_m->fetch_row($sql,$params); |
256 | 261 | |
257 | - | |
258 | 262 | return isset($attachment['attachment']) ? $attachment['attachment'] : ''; |
259 | 263 | } |
264 | + | |
265 | + /** | |
266 | + * 留言审核 | |
267 | + * User: <362431947@qq.com> | |
268 | + * @param int $message_id | |
269 | + * @return bool | |
270 | + * Date: 2018-10-11 Time: 21:32 | |
271 | + */ | |
272 | + public function check($message_id = 0,$checked = 1) | |
273 | + { | |
274 | +// // 未审核状态 | |
275 | +// $conds = [ | |
276 | +// 'message_id' => $message_id, | |
277 | +// ]; | |
278 | + | |
279 | + $exists = $this->_m->field('message_id')->find($message_id); | |
280 | + | |
281 | + if ($exists) { | |
282 | + | |
283 | + $data = [ | |
284 | + 'checked' =>$checked, | |
285 | + ]; | |
286 | + | |
287 | + return $this->update($message_id,$data,true); | |
288 | + } | |
289 | + else{ | |
290 | + return false; | |
291 | + } | |
292 | + | |
293 | + } | |
260 | 294 | } | ... | ... |
trunk/Message/Common/Sql/structure.php
... | ... | @@ -46,25 +46,6 @@ CREATE TABLE IF NOT EXISTS `zx_message_message`( |
46 | 46 | INDEX(`deleted`) |
47 | 47 | )ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='留言板-留言信息表'; |
48 | 48 | |
49 | --- 留言与评论关联表 | |
50 | -CREATE TABLE IF NOT EXISTS `zx_message_msg_comment`( | |
51 | - `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', | |
52 | - `message_id` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '留言记录id', | |
53 | - `comment_id` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '评论记录id', | |
54 | - `domain` varchar(32) NOT NULL DEFAULT '' COMMENT '企业域名', | |
55 | - `status` tinyint(3) unsigned NOT NULL DEFAULT 1 COMMENT '状态, 1=初始化,2=已更新,3=已删除', | |
56 | - `created` bigint(13) unsigned NOT NULL DEFAULT 0 COMMENT '创建时间', | |
57 | - `updated` bigint(13) unsigned NOT NULL DEFAULT 0 COMMENT '更新时间', | |
58 | - `deleted` bigint(13) unsigned NOT NULL DEFAULT 0 COMMENT '删除时间', | |
59 | - PRIMARY KEY(`id`), | |
60 | - INDEX(`message_id`), | |
61 | - INDEX(`comment_id`), | |
62 | - INDEX(`domain`), | |
63 | - INDEX(`status`), | |
64 | - INDEX(`created`), | |
65 | - INDEX(`updated`), | |
66 | - INDEX(`deleted`) | |
67 | -)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='留言与评论关联表'; | |
68 | 49 | |
69 | 50 | -- 评论表 |
70 | 51 | CREATE TABLE IF NOT EXISTS `zx_message_comment`( |
... | ... | @@ -129,4 +110,24 @@ CREATE TABLE IF NOT EXISTS `zx_message_setting` ( |
129 | 110 | PRIMARY KEY (`id`), |
130 | 111 | KEY `domain_status` (`domain`,`status`) |
131 | 112 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='留言板-设置表'; |
113 | + | |
114 | +-- 留言与评论关联表 | |
115 | +CREATE TABLE IF NOT EXISTS `zx_message_msg_comment`( | |
116 | + `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', | |
117 | + `message_id` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '留言记录id', | |
118 | + `comment_id` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '评论记录id', | |
119 | + `domain` varchar(32) NOT NULL DEFAULT '' COMMENT '企业域名', | |
120 | + `status` tinyint(3) unsigned NOT NULL DEFAULT 1 COMMENT '状态, 1=初始化,2=已更新,3=已删除', | |
121 | + `created` bigint(13) unsigned NOT NULL DEFAULT 0 COMMENT '创建时间', | |
122 | + `updated` bigint(13) unsigned NOT NULL DEFAULT 0 COMMENT '更新时间', | |
123 | + `deleted` bigint(13) unsigned NOT NULL DEFAULT 0 COMMENT '删除时间', | |
124 | + PRIMARY KEY(`id`), | |
125 | + INDEX(`message_id`), | |
126 | + INDEX(`comment_id`), | |
127 | + INDEX(`domain`), | |
128 | + INDEX(`status`), | |
129 | + INDEX(`created`), | |
130 | + INDEX(`updated`), | |
131 | + INDEX(`deleted`) | |
132 | +)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='留言与评论关联表'; | |
132 | 133 | "; | ... | ... |