Commit 1ddd244a8375dabe143843dfa58202c2273481dd

Authored by zhang
1 parent 649e653d

[留言板]留言信息展示,详情,删除

trunk/Message/Api/Controller/Comment/CommentController.class.php
... ... @@ -34,8 +34,8 @@ class CommentController extends AbstractController
34 34  
35 35 $m_comment = new CommentModel();
36 36  
37   - print_r($input);
38   - $result = $m_comment->addOne($input);
  37 +
  38 + $result = $m_comment->add($input);
39 39  
40 40 $this->_result = boolval($result);
41 41 }
... ...
trunk/Message/Api/Controller/Message/MsgController.class.php
... ... @@ -16,47 +16,73 @@ class MsgController extends AbstractController
16 16 */
17 17 public function Index_post()
18 18 {
19   - // echo md5('123');
20   - // echo $msectime; 1539069172335
21 19 $input = I('post.');
22 20  
23   - if(! $input){
  21 + if (! $input) {
24 22 E('_ERR_POST_EMPTY');
25 23 }
26 24  
27 25 $title = $input['title'];
28   - if(! $title){
  26 + if (! $title) {
29 27 E('_ERROR_TITLE_EMPTY');
30 28 }
31 29  
32   - if(get_str_len($title) > 80){
  30 + if (get_str_len($title) > 80) {
33 31 E('_ERROR_MESSAGE_TITLE_LENGTH');
34 32 }
35 33  
36 34 $message = $input['message'];
37   - if(! $message){
  35 + if (! $message) {
38 36 E('_ERROR_MESSAGE_EMPTY');
39 37 }
40 38  
41   - if(get_str_len($message) > 500){
  39 + if (get_str_len($message) > 500) {
42 40 E('_ERROR_MESSAGE_LENGTH');
43 41 }
44 42  
45 43 $input['ip'] = $_SERVER['REMOTE_ADDR'];
46   - $input['uid'] = session['auth_login']['uid'];
47   - $input['attachment'] = '';
  44 +
  45 +
  46 + $uid = $input['uid'];
  47 + if (! $uid) {
  48 + E('_ERROR_USER_ID_EMPTY');
  49 + }
  50 +
  51 + $m_attachment = new AttachmentModel();
  52 + $attach_id_str = $m_attachment->add();
  53 +
  54 + if (false !== $attach_id_str) {
  55 + $input['attachment'] = $attach_id_str;
  56 + }
  57 +
48 58 // 素材id,多个使用逗号分隔
49 59 // $input['receiver_uid'] = ''; // 不能是自己
50 60 $input['domain'] = md5($_SERVER['HTTP_HOST']);
51 61  
52 62  
53 63 $m_message = new MessageModel();
  64 + $result = $m_message->addOne($input);
54 65  
55   - $m_attachment = new AttachmentModel();
  66 + $this->_result = boolval($result);
  67 + }
56 68  
57   - $result = $m_attachment->add();
  69 + /**
  70 + * 留言列表
  71 + * @author <362431947@qq.com>
  72 + * @date 2018-10-10
  73 + */
  74 + public function list_post()
  75 + {
  76 + $input = I('post.');
58 77  
59   - $this->_result = boolval($result);
  78 + $uid = $input['uid'];
  79 + if (! $uid ) E('_ERROR_USER_ID_EMPTY');
  80 +
  81 + $m_message = new MessageModel();
  82 +
  83 + $message_list = $m_message->messageList($uid);
  84 +
  85 + $this->_result = $message_list;
60 86 }
61 87  
62 88 }
... ...
trunk/Message/Api/Lang/zh-cn.php
... ... @@ -8,6 +8,7 @@ return [
8 8 '_ERROR_TITLE_EMPTY' => '2018005:标题为空',
9 9 '_ERROR_MESSAGE_TITLE_LENGTH'=> '2018006:标题长度不能大于80个字符',
10 10 '_ERROR_MESSAGE_EMPTY' => '2018007:内容为空',
11   - '_ERROR_MESSAGE_LENGTH' => '2018007:内容长度不能大于500个字符',
  11 + '_ERROR_MESSAGE_LENGTH' => '2018008:内容长度不能大于500个字符',
  12 + '_ERROR_USER_ID_EMPTY' => '2091009:用户id为空',
12 13 '_ERR_ID_EMPTY' => '2091003:id为空',
13 14 ];
... ...
trunk/Message/Common/Model/MessageModel.class.php
1 1 <?php
  2 +
2 3 namespace Common\Model;
3 4  
4 5 class MessageModel extends AbstractModel
5 6 {
  7 + public function __construct()
  8 + {
  9 + parent::__construct();
  10 + }
  11 +
6 12 /**
7 13 * 添加留言内容
8   - * @author <362431947@qq.com>
9   - * @date 2018-10-09
10   - * @param array $data
  14 + * User: <362431947@qq.com>
  15 + * @param array $data
  16 + * @return bool|mixed
  17 + * Date: 2018-10-10 Time: 22:32
11 18 */
12   - public function addOne(array $data)
  19 + public function addOne($data = [])
13 20 {
14 21 if(! is_array($data)|| ! $data){
15 22 return false;
... ... @@ -21,4 +28,233 @@ class MessageModel extends AbstractModel
21 28  
22 29 return $result;
23 30 }
  31 +
  32 + /**
  33 + * 留言信息列表
  34 + * @author <362431947@qq.com>
  35 + * @date 2018-10-10
  36 + * @param $page int 页码
  37 + * @return array
  38 + */
  39 + public function messageList($conds = [],$page = 0)
  40 + {
  41 + $params = [];
  42 + $wheres = [];
  43 +
  44 + $conds['a.status'] = $this->get_st_create();
  45 +
  46 +
  47 + if (!$this->_parse_where($wheres, $params, $conds)) {
  48 + return false;
  49 + }
  50 +
  51 + $page_size = self::PAGING_DEFAULT_LIMIT;
  52 + $page_start = self::PAGING_DEFAULT_PAGE;
  53 +
  54 + if ($page) {
  55 + $page_start = ($page - 1) * $page_size;
  56 + }
  57 +
  58 + $option = [$page_start,$page_size];
  59 +
  60 +
  61 +
  62 + $m_person = new PersonModel();
  63 + $table = $m_person->get_tname();
  64 +
  65 +
  66 + if (in_array('title',$conds)) {
  67 + $where = " title LIKE ? ";
  68 + }
  69 + else{
  70 + $fields = array_keys($conds);
  71 +
  72 + if ($fields != 'status') {
  73 + $field = $fields[0];
  74 + }
  75 +
  76 + $where = " $field = ? ";
  77 +
  78 + }
  79 +
  80 + $sql = "SELECT a.* FROM __TABLE__ a
  81 + LEFT JOIN {$table} b ON a.uid = b.person_id
  82 + WHERE $where";
  83 +
  84 + $list = $this->_m->fetch_array($sql, $params,$option);
  85 +
  86 + return $list;
  87 + }
  88 +
  89 + /**
  90 + * 后台留言删除
  91 + * User: <362431947@qq.com>
  92 + * @param int $message_id
  93 + * @return bool
  94 + * Date: 2018-10-10 Time: 22:24
  95 + */
  96 + public function del($message_id = 0)
  97 + {
  98 + $this->_m->startTrans();
  99 +
  100 +
  101 + $attachment_id = $this->getAttachmentIdByMsgId($message_id);
  102 +
  103 + // 删除相关附件图片
  104 + $attachment_del = true;
  105 + if ($attachment_id) {
  106 + $m_attachment = new AttachmentModel();
  107 + $attachment_del = $m_attachment->del($attachment_id);
  108 + }
  109 +
  110 +
  111 +
  112 + // 删除留言
  113 + $message_del = $this->_m->delete($message_id);
  114 +
  115 +
  116 + // 删除留言评论
  117 +
  118 + $m_comment = new CommentModel();
  119 + $exists = $m_comment->getCommentByMsgId($message_id = 0);
  120 +
  121 + $comment_del = true;
  122 + if ($exists) {
  123 + $comment_del = $m_comment->del($message_id);
  124 + }
  125 +
  126 + if ($message_del && $comment_del && $attachment_del) {
  127 + $this->_m->commit();
  128 + return true;
  129 + }
  130 + else{
  131 + $this->_m->rollback();
  132 + return false;
  133 + }
  134 + }
  135 +
  136 + /**
  137 + * 根据搜索条件获取留言信息
  138 + * User: <362431947@qq.com>
  139 + * @param array $conds 搜索条件
  140 + * @return array|bool
  141 + * Date: 2018-10-10 Time: 22:24
  142 + */
  143 + public function search($conds = [])
  144 + {
  145 + $params = [];
  146 + $wheres = [];
  147 +
  148 + if (!$this->_parse_where($wheres, $params, $conds)) {
  149 + return false;
  150 + }
  151 +
  152 + $m_person = new PersonModel();
  153 + $table = $m_person->get_tname();
  154 +
  155 + if (in_array('title',$conds)) {
  156 + $where = " title LIKE ? ";
  157 + }
  158 + else{
  159 + $fields = array_keys($conds);
  160 + $field = $fields[0];
  161 +
  162 + $where = " $field = ? ";
  163 + }
  164 +
  165 +// print_r($conds);
  166 +// print_r($where);
  167 +// die;
  168 + if ($where) {
  169 + $sql = "SELECT a.* FROM __TABLE__ a
  170 + JOIN {$table} b ON a.uid = b.person_id
  171 + WHERE $where";
  172 + }
  173 + else {
  174 + return [];
  175 + }
  176 +
  177 +
  178 + return $this->_m->fetch_array($sql,$params);
  179 + }
  180 +
  181 + /**
  182 + * 留言详情
  183 + * User: <362431947@qq.com>
  184 + * @param int $message_id
  185 + * @return array|bool
  186 + * Date: 2018-10-11 Time: 11:47
  187 + */
  188 + public function messageDetail($message_id = 0)
  189 + {
  190 + $params = [];
  191 + $wheres = [];
  192 +
  193 + $conds = ['message_id' =>$message_id];
  194 +
  195 + if (!$this->_parse_where($wheres, $params, $conds)) {
  196 + return false;
  197 + }
  198 +
  199 + $m_person = new PersonModel();
  200 + $table_person = $m_person->get_tname();
  201 +
  202 +
  203 + $sql = "SELECT a.message_id,a.title,a.message,b.name as `from`,IFNULL(c.name,'') as `to`
  204 + FROM __TABLE__ a
  205 + LEFT JOIN {$table_person} b ON a.uid = b.person_id
  206 + LEFT JOIN {$table_person} c ON a.receiver_uid = c.person_id
  207 + WHERE `message_id` = ? ";
  208 +
  209 + $message = $this->_m->fetch_row($sql,$params);
  210 +
  211 +
  212 + $m_attachment = new AttachmentModel();
  213 + $table_attachment = $m_attachment->get_tname();
  214 +
  215 +
  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 +
  221 + $sql = "SELECT `path` FROM {$table_attachment}
  222 + WHERE attachment_id IN ($attachment_id_str)";
  223 +
  224 + $attachment = $this->_m->fetch_array($sql,$params);
  225 +
  226 + $message['attachment'] = $attachment;
  227 +
  228 + // 获取评论信息
  229 + $m_comment = new CommentModel();
  230 + $message['comment'] = $m_comment->getCommentByMsgId($message_id);
  231 +
  232 + return $message;
  233 + }
  234 +
  235 + /**
  236 + * getAttachmentIdByMsgId
  237 + * User: <362431947@qq.com>
  238 + * @param int $message_id
  239 + * @return bool
  240 + * Date: 2018-10-10 Time: 22:18
  241 + */
  242 + public function getAttachmentIdByMsgId($message_id = 0)
  243 + {
  244 + $params = [];
  245 + $wheres = [];
  246 + $conds = [
  247 + 'message_id' => $message_id,
  248 + ];
  249 + if (!$this->_parse_where($wheres, $params, $conds)) {
  250 + return false;
  251 + }
  252 +
  253 + $sql = "SELECT attachment
  254 + FROM __TABLE__ WHERE `message_id` = ? ";
  255 + $attachment = $this->_m->fetch_row($sql,$params);
  256 +
  257 +
  258 + return isset($attachment['attachment']) ? $attachment['attachment'] : '';
  259 + }
24 260 }
... ...