Commit 69d2cd21af47a6537e450019e0f387af4c35945b
1 parent
1ddd244a
[留言板]评论,展示,删除,附件展示,删除
Showing
7 changed files
with
176 additions
and
81 deletions
trunk/Message/Api/Controller/Person/LoginController.class.php
1 | <?php | 1 | <?php |
2 | + | ||
2 | namespace Api\Controller\Person; | 3 | namespace Api\Controller\Person; |
3 | 4 | ||
4 | use Api\Controller\AbstractController; | 5 | use Api\Controller\AbstractController; |
@@ -42,10 +43,18 @@ class LoginController extends AbstractController | @@ -42,10 +43,18 @@ class LoginController extends AbstractController | ||
42 | 43 | ||
43 | $auth_login = false; | 44 | $auth_login = false; |
44 | if($user_info){ | 45 | if($user_info){ |
45 | - $user_info ? session('user_info',$user_info) : session('user_info',$user_info); | ||
46 | $auth_login = true; | 46 | $auth_login = true; |
47 | } | 47 | } |
48 | 48 | ||
49 | $this->_result = $auth_login; | 49 | $this->_result = $auth_login; |
50 | + | ||
51 | + if ($auth_login) { | ||
52 | + | ||
53 | + redirect("http://127.0.0.1/message/list.php"); | ||
54 | + } | ||
55 | + else { | ||
56 | + redirect("http://127.0.0.1/message/login_error.php"); | ||
57 | + } | ||
50 | } | 58 | } |
59 | + | ||
51 | } | 60 | } |
trunk/Message/Apicp/Controller/Message/MessageController.class.php
1 | <?php | 1 | <?php |
2 | + | ||
2 | namespace Apicp\Controller\Message; | 3 | namespace Apicp\Controller\Message; |
3 | 4 | ||
4 | use Apicp\Controller\AbstractController; | 5 | use Apicp\Controller\AbstractController; |
@@ -7,7 +8,9 @@ use Common\Model\MessageModel; | @@ -7,7 +8,9 @@ use Common\Model\MessageModel; | ||
7 | class MessageController extends AbstractController | 8 | class MessageController extends AbstractController |
8 | { | 9 | { |
9 | protected $_require_login = false; | 10 | protected $_require_login = false; |
10 | - private $m_message; // MessageModel 模型对象 | 11 | + |
12 | + private $m_message; | ||
13 | + // MessageModel 模型对象 | ||
11 | 14 | ||
12 | public function __construct() | 15 | public function __construct() |
13 | { | 16 | { |
@@ -15,6 +18,7 @@ class MessageController extends AbstractController | @@ -15,6 +18,7 @@ class MessageController extends AbstractController | ||
15 | 18 | ||
16 | $this->m_message = new MessageModel; | 19 | $this->m_message = new MessageModel; |
17 | } | 20 | } |
21 | + | ||
18 | /** | 22 | /** |
19 | * 留言删除 | 23 | * 留言删除 |
20 | * @author <362431947@qq.com> | 24 | * @author <362431947@qq.com> |
@@ -29,10 +33,6 @@ class MessageController extends AbstractController | @@ -29,10 +33,6 @@ class MessageController extends AbstractController | ||
29 | E('_ERROR_MESSAGE_ID_EMPTY'); | 33 | E('_ERROR_MESSAGE_ID_EMPTY'); |
30 | } | 34 | } |
31 | 35 | ||
32 | - $uid = intval($input['uid']); | ||
33 | - if(! $uid){ | ||
34 | - E('_ERROR_USER_ID_EMPTY'); | ||
35 | - } | ||
36 | 36 | ||
37 | $result = $this->m_message->del($message_id); | 37 | $result = $this->m_message->del($message_id); |
38 | 38 | ||
@@ -41,46 +41,87 @@ class MessageController extends AbstractController | @@ -41,46 +41,87 @@ class MessageController extends AbstractController | ||
41 | 41 | ||
42 | /** | 42 | /** |
43 | * 搜索 搜索(按姓名、性别、手机号、邮箱以及留言标题进行或查询)、列表、留言详情查看 | 43 | * 搜索 搜索(按姓名、性别、手机号、邮箱以及留言标题进行或查询)、列表、留言详情查看 |
44 | - * @author <362431947@qq.com> | ||
45 | - * @date 2018-10-10 | ||
46 | - * @return [type] | 44 | + * User: <362431947@qq.com> |
45 | + * @return bool | ||
46 | + * @throws \Think\Exception | ||
47 | + * Date: 2018-10-10 Time: 9:31 | ||
47 | */ | 48 | */ |
48 | public function search_post() | 49 | public function search_post() |
49 | { | 50 | { |
50 | $input = I('post.'); | 51 | $input = I('post.'); |
51 | 52 | ||
52 | - $conds = $this->getConds($input); | ||
53 | - if(false === $conds){ | 53 | +// print_r($input); |
54 | + | ||
55 | + $conds = $input; | ||
56 | +// $conds = $this->getConds($input); | ||
57 | + | ||
58 | + | ||
59 | + if (false === $conds) { | ||
54 | E('_ERROR_SEARCH_CONDS_EMPTY'); | 60 | E('_ERROR_SEARCH_CONDS_EMPTY'); |
55 | - return false; | ||
56 | } | 61 | } |
57 | 62 | ||
58 | $list = $this->m_message->search($conds); | 63 | $list = $this->m_message->search($conds); |
64 | + | ||
65 | + | ||
59 | $this->_result = $list; | 66 | $this->_result = $list; |
60 | 67 | ||
61 | return true; | 68 | return true; |
62 | } | 69 | } |
63 | 70 | ||
64 | /** | 71 | /** |
72 | + * 留言信息列表 | ||
73 | + * User: <362431947@qq.com> | ||
74 | + * Date: 2018-10-11 Time: 9:58 | ||
75 | + */ | ||
76 | + public function list_post() | ||
77 | + { | ||
78 | + $input = I('post.'); | ||
79 | + | ||
80 | + $page = intval($input['page']); | ||
81 | + | ||
82 | + unset($input['page']); | ||
83 | + | ||
84 | + | ||
85 | + $this->_result = $this->m_message->messageList($input,$page); | ||
86 | + } | ||
87 | + | ||
88 | + /** | ||
89 | + * 留言详情 | ||
90 | + * User: <362431947@qq.com> | ||
91 | + * Date: 2018-10-11 Time: 11:51 | ||
92 | + */ | ||
93 | + public function detail_post() | ||
94 | + { | ||
95 | + $input = I('post.'); | ||
96 | + | ||
97 | + $message_id = intval($input['message_id']); | ||
98 | + | ||
99 | + $this->_result = $this->m_message->messageDetail($message_id); | ||
100 | + } | ||
101 | + | ||
102 | + /** | ||
65 | * 获取搜索条件 | 103 | * 获取搜索条件 |
66 | - * @author <362431947@qq.com> | ||
67 | - * @date 2018-10-10 | ||
68 | - * @param array $search 搜索条件 | ||
69 | - * @return [type] | 104 | + * User: <362431947@qq.com> |
105 | + * @param array $search | ||
106 | + * @return array|bool | ||
107 | + * Date: 2018-10-10 | ||
70 | */ | 108 | */ |
71 | private function getConds($search = []) | 109 | private function getConds($search = []) |
72 | { | 110 | { |
73 | - if(! $search){ | 111 | + if (! $search) { |
74 | return false; | 112 | return false; |
75 | } | 113 | } |
114 | + | ||
76 | $conds = []; | 115 | $conds = []; |
77 | $fields = ['name','sex','mobile','email','title']; | 116 | $fields = ['name','sex','mobile','email','title']; |
78 | 117 | ||
79 | foreach ($fields as $field) { | 118 | foreach ($fields as $field) { |
80 | - if($val = trim($search[$field])){ | 119 | + if ($val = trim($search[$field])) { |
81 | $conds[$field] = $val; | 120 | $conds[$field] = $val; |
121 | + break; | ||
82 | } | 122 | } |
83 | } | 123 | } |
124 | + print_r($conds); | ||
84 | return $conds; | 125 | return $conds; |
85 | } | 126 | } |
86 | } | 127 | } |
trunk/Message/Common/Model/AbstractModel.class.php
@@ -11,6 +11,10 @@ namespace Common\Model; | @@ -11,6 +11,10 @@ namespace Common\Model; | ||
11 | 11 | ||
12 | abstract class AbstractModel extends \Com\Model | 12 | abstract class AbstractModel extends \Com\Model |
13 | { | 13 | { |
14 | + const PAGING_DEFAULT_PAGE = 1; | ||
15 | + | ||
16 | + const PAGING_DEFAULT_LIMIT = 20; | ||
17 | + | ||
14 | // 构造方法 | 18 | // 构造方法 |
15 | public function __construct() | 19 | public function __construct() |
16 | { | 20 | { |
trunk/Message/Common/Model/AttachmentModel.class.php
@@ -11,45 +11,71 @@ class AttachmentModel extends AbstractModel | @@ -11,45 +11,71 @@ class AttachmentModel extends AbstractModel | ||
11 | 11 | ||
12 | private $upload_dir = '../../trunk/Message/attachment/'; | 12 | private $upload_dir = '../../trunk/Message/attachment/'; |
13 | 13 | ||
14 | + /** | ||
15 | + * 构造方法 | ||
16 | + * @author <362431947@qq.com> | ||
17 | + * @date 2018-10-10 | ||
18 | + */ | ||
19 | + public function __construct() | ||
20 | + { | ||
21 | + parent::__construct(); | ||
22 | + } | ||
14 | // 素材入库 | 23 | // 素材入库 |
15 | public function add() | 24 | public function add() |
16 | { | 25 | { |
17 | - $bool = false; | ||
18 | - $attachment = $this->initAttac(); | 26 | + $attachment_id_arr = []; |
27 | + | ||
28 | + $microtme = $this->microtime(); | ||
29 | + $domain = md5($_SERVER['HTTP_HOST']); | ||
30 | + if($_FILES){ | ||
31 | + foreach ($_FILES as $key => $file) { | ||
32 | + $attach_id = 0; | ||
33 | + $attachment = []; | ||
19 | 34 | ||
35 | + $attachment['path'] = $this->upload($file); | ||
36 | + $attachment['domain'] = $domain; | ||
37 | + $attachment['created'] = $microtme; | ||
20 | 38 | ||
21 | - if(is_array($attachment) && $attachment){ | ||
22 | - $bool = $this->_m->insert_all($attachment); | 39 | + $attach_id = $this->_m->insert($attachment); |
40 | + | ||
41 | + if($attach_id){ | ||
42 | + $attachment_id_arr[] = $attach_id; | ||
43 | + } | ||
44 | + else{ | ||
45 | + break; | ||
46 | + } | ||
47 | + } | ||
48 | + | ||
49 | + if(! $attach_id){ | ||
50 | + E('保存失败'); | ||
51 | + return false; | ||
52 | + } | ||
23 | } | 53 | } |
24 | - return boolval($bool); | 54 | + |
55 | + return $attachment_id_arr ? implode(',',$attachment_id_arr) : ''; | ||
25 | } | 56 | } |
26 | 57 | ||
58 | + | ||
27 | /** | 59 | /** |
28 | - * 整理素材入库数据 | ||
29 | - * @author <362431947@qq.com> | ||
30 | - * @date 2018-10-09 | ||
31 | - * @return array | 60 | + * 附件删除 |
61 | + * User: <362431947@qq.com> | ||
62 | + * @param string $attachment_id | ||
63 | + * @return mixed | ||
64 | + * Date: 2018-10-10 Time: 22:13 | ||
32 | */ | 65 | */ |
33 | - private function initAttac() | 66 | + public function del($attachment_id = '') |
34 | { | 67 | { |
35 | - $attachment = []; | ||
36 | - $index = 0; | ||
37 | - foreach ($_FILES as $key => $file) { | ||
38 | - $attachment[$index]['path'] = $this->upload($file); | ||
39 | - $attachment[$index]['domain'] = md5($_SERVER['HTTP_HOST']); | ||
40 | - $attachment[$index]['created'] = $this->microtime(); | ||
41 | - | ||
42 | - $index++; | ||
43 | - } | ||
44 | - return $attachment; | 68 | + return $this->_m->delete($attachment_id); |
45 | } | 69 | } |
70 | + | ||
46 | /** | 71 | /** |
47 | * 素材附件上传 | 72 | * 素材附件上传 |
48 | - * @author <362431947@qq.com> | ||
49 | - * @date 2018-10-09 | ||
50 | - * @param array $file | ||
51 | - * @param string $subdir | ||
52 | - * @return mixed | 73 | + * User: <362431947@qq.com> |
74 | + * @param array $file | ||
75 | + * @param string $subdir | ||
76 | + * @return bool|string | ||
77 | + * @throws \Think\Exception | ||
78 | + * Date: 2018-10-9 Time: 22:14 | ||
53 | */ | 79 | */ |
54 | public function upload(array $file,$subdir='') | 80 | public function upload(array $file,$subdir='') |
55 | { | 81 | { |
trunk/Message/Common/Model/CommentModel.class.php
@@ -9,49 +9,29 @@ class CommentModel extends AbstractModel | @@ -9,49 +9,29 @@ class CommentModel extends AbstractModel | ||
9 | parent::__construct(); | 9 | parent::__construct(); |
10 | } | 10 | } |
11 | 11 | ||
12 | - public function addOne($data) | ||
13 | - { | ||
14 | - return $this->_m->insert($data); | ||
15 | - } | ||
16 | 12 | ||
17 | /** | 13 | /** |
18 | * 保存评论信息 | 14 | * 保存评论信息 |
19 | - * @author <362431947@qq.com> | ||
20 | - * @date 2018-10-10 | 15 | + * User: <362431947@qq.com> |
16 | + * @param array $data | ||
17 | + * @return mixed | ||
18 | + * Date: 2018-10-10 Time: 12:04 | ||
21 | */ | 19 | */ |
22 | public function add($data = []) | 20 | public function add($data = []) |
23 | { | 21 | { |
24 | $data['domain'] = md5($_SERVER['HTTP_HOST']); | 22 | $data['domain'] = md5($_SERVER['HTTP_HOST']); |
25 | $data['created'] = $this->microtime(); | 23 | $data['created'] = $this->microtime(); |
26 | - print_r($data); | ||
27 | 24 | ||
28 | return $this->_m->insert($data); | 25 | return $this->_m->insert($data); |
29 | - | ||
30 | - // $comment_id = $this->_m->insert($data); | ||
31 | - | ||
32 | -// $msg_comment = [ | ||
33 | -// 'message_id' => intval($data['message_id']), | ||
34 | -// 'comment_id' => $comment_id, | ||
35 | -// 'domain' => md5($_SERVER['HTTP_HOST']), | ||
36 | -// 'created' => $this->microtime(), | ||
37 | -// ]; | ||
38 | - | ||
39 | -// $m_msg_comment = new MsgCommentModel(); | ||
40 | -// | ||
41 | -// $id = $m_msg_comment->add($msg_comment); | ||
42 | -// | ||
43 | -// if($comment_id && $id){ | ||
44 | -// $this->_m->commit(); | ||
45 | -// $result = true; | ||
46 | -// } | ||
47 | -// else{ | ||
48 | -// $this->_m->rollback(); | ||
49 | -// $result = false; | ||
50 | -// } | ||
51 | - | ||
52 | -// return $result; | ||
53 | } | 26 | } |
54 | 27 | ||
28 | + /** | ||
29 | + * 通过留言id获取评论信息 | ||
30 | + * User: <362431947@qq.com> | ||
31 | + * @param int $message_id | ||
32 | + * @return array|bool | ||
33 | + * Date: 2018-10-11 Time: 12:05 | ||
34 | + */ | ||
55 | public function getCommentByMsgId($message_id = 0) | 35 | public function getCommentByMsgId($message_id = 0) |
56 | { | 36 | { |
57 | $params = []; | 37 | $params = []; |
@@ -66,15 +46,23 @@ class CommentModel extends AbstractModel | @@ -66,15 +46,23 @@ class CommentModel extends AbstractModel | ||
66 | $m_person = new PersonModel(); | 46 | $m_person = new PersonModel(); |
67 | $table_person = $m_person->get_tname(); | 47 | $table_person = $m_person->get_tname(); |
68 | 48 | ||
69 | - $sql = "SELECT `comment`,b.name commenter | ||
70 | - FROM __TABLE a | 49 | + $sql = "SELECT `comment`,b.name commenter,a.created |
50 | + FROM __TABLE__ a | ||
71 | LEFT JOIN {$table_person} b ON a.uid = b.person_id | 51 | LEFT JOIN {$table_person} b ON a.uid = b.person_id |
72 | - WHERE `message` = ? "; | 52 | + WHERE `message_id` = ? "; |
73 | return $this->_m->fetch_array($sql,$params); | 53 | return $this->_m->fetch_array($sql,$params); |
74 | } | 54 | } |
75 | 55 | ||
56 | + /** | ||
57 | + * 通过留言id删除评论 | ||
58 | + * User: <362431947@qq.com> | ||
59 | + * @param int $message_id | ||
60 | + * @return mixed | ||
61 | + * Date: 2018-10-11 Time: 12:05 | ||
62 | + */ | ||
76 | public function del($message_id = 0) | 63 | public function del($message_id = 0) |
77 | { | 64 | { |
78 | return $this->_m->delete($message_id); | 65 | return $this->_m->delete($message_id); |
79 | } | 66 | } |
67 | + | ||
80 | } | 68 | } |
trunk/Message/Common/Model/MsgCommentModel.class.php
0 → 100644
1 | +<?php | ||
2 | +namespace Common\Model; | ||
3 | + | ||
4 | +class MsgCommentModel extends AbstractModel | ||
5 | +{ | ||
6 | + public function __construct() | ||
7 | + { | ||
8 | + parent::__construct(); | ||
9 | + } | ||
10 | + | ||
11 | + /** | ||
12 | + * 添加留言与评论关联信息 | ||
13 | + * @author <362431947@qq.com> | ||
14 | + * @date 2018-10-10 | ||
15 | + * @param array $data | ||
16 | + */ | ||
17 | + public function add($data = []) | ||
18 | + { | ||
19 | + return $this->_m->insert($data); | ||
20 | + } | ||
21 | + | ||
22 | + public function del($message_id = 0) | ||
23 | + { | ||
24 | + return $this->_m->delete($message_id); | ||
25 | + } | ||
26 | +} |
trunk/Message/Common/Sql/structure.php
@@ -47,7 +47,7 @@ CREATE TABLE IF NOT EXISTS `zx_message_message`( | @@ -47,7 +47,7 @@ CREATE TABLE IF NOT EXISTS `zx_message_message`( | ||
47 | )ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='留言板-留言信息表'; | 47 | )ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='留言板-留言信息表'; |
48 | 48 | ||
49 | -- 留言与评论关联表 | 49 | -- 留言与评论关联表 |
50 | -CREATE TABLE IF NOT EXISTS `zx_message_msg__comment`( | 50 | +CREATE TABLE IF NOT EXISTS `zx_message_msg_comment`( |
51 | `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', | 51 | `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', |
52 | `message_id` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '留言记录id', | 52 | `message_id` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '留言记录id', |
53 | `comment_id` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '评论记录id', | 53 | `comment_id` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '评论记录id', |
@@ -69,8 +69,9 @@ CREATE TABLE IF NOT EXISTS `zx_message_msg__comment`( | @@ -69,8 +69,9 @@ CREATE TABLE IF NOT EXISTS `zx_message_msg__comment`( | ||
69 | -- 评论表 | 69 | -- 评论表 |
70 | CREATE TABLE IF NOT EXISTS `zx_message_comment`( | 70 | CREATE TABLE IF NOT EXISTS `zx_message_comment`( |
71 | `comment_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', | 71 | `comment_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', |
72 | + `message_id` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '留言记录id', | ||
72 | `comment` varchar(140) NOT NULL DEFAULT '' COMMENT '评论内容', | 73 | `comment` varchar(140) NOT NULL DEFAULT '' COMMENT '评论内容', |
73 | - `m_uid` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '操作用户id', | 74 | + `uid` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '操作用户id', |
74 | `domain` varchar(32) NOT NULL DEFAULT '' COMMENT '企业域名', | 75 | `domain` varchar(32) NOT NULL DEFAULT '' COMMENT '企业域名', |
75 | `status` tinyint(3) unsigned NOT NULL DEFAULT 1 COMMENT '状态, 1=初始化,2=已更新,3=已删除', | 76 | `status` tinyint(3) unsigned NOT NULL DEFAULT 1 COMMENT '状态, 1=初始化,2=已更新,3=已删除', |
76 | `created` bigint(13) unsigned NOT NULL DEFAULT 0 COMMENT '创建时间', | 77 | `created` bigint(13) unsigned NOT NULL DEFAULT 0 COMMENT '创建时间', |
@@ -79,11 +80,11 @@ CREATE TABLE IF NOT EXISTS `zx_message_comment`( | @@ -79,11 +80,11 @@ CREATE TABLE IF NOT EXISTS `zx_message_comment`( | ||
79 | PRIMARY KEY(`comment_id`), | 80 | PRIMARY KEY(`comment_id`), |
80 | INDEX(`domain`), | 81 | INDEX(`domain`), |
81 | INDEX(`status`), | 82 | INDEX(`status`), |
82 | - INDEX(`m_uid`), | 83 | + INDEX(`uid`), |
83 | INDEX(`created`), | 84 | INDEX(`created`), |
84 | INDEX(`updated`), | 85 | INDEX(`updated`), |
85 | INDEX(`deleted`) | 86 | INDEX(`deleted`) |
86 | -)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='留言与评论关联表'; | 87 | +)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='评论表'; |
87 | 88 | ||
88 | -- 留言板素材表 | 89 | -- 留言板素材表 |
89 | CREATE TABLE IF NOT EXISTS `zx_message_attachment`( | 90 | CREATE TABLE IF NOT EXISTS `zx_message_attachment`( |