From 69d2cd21af47a6537e450019e0f387af4c35945b Mon Sep 17 00:00:00 2001
From: zhang <xiang@qq.com>
Date: Thu, 11 Oct 2018 19:47:40 +0800
Subject: [PATCH] [留言板]评论,展示,删除,附件展示,删除

---
 trunk/Message/Api/Controller/Person/LoginController.class.php      | 11 ++++++++++-
 trunk/Message/Apicp/Controller/Message/MessageController.class.php | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------
 trunk/Message/Common/Model/AbstractModel.class.php                 |  4 ++++
 trunk/Message/Common/Model/AttachmentModel.class.php               | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------
 trunk/Message/Common/Model/CommentModel.class.php                  | 56 ++++++++++++++++++++++----------------------------------
 trunk/Message/Common/Model/MsgCommentModel.class.php               | 26 ++++++++++++++++++++++++++
 trunk/Message/Common/Sql/structure.php                             |  9 +++++----
 7 files changed, 176 insertions(+), 81 deletions(-)
 create mode 100644 trunk/Message/Common/Model/MsgCommentModel.class.php

diff --git a/trunk/Message/Api/Controller/Person/LoginController.class.php b/trunk/Message/Api/Controller/Person/LoginController.class.php
index e72f697..e58a694 100644
--- a/trunk/Message/Api/Controller/Person/LoginController.class.php
+++ b/trunk/Message/Api/Controller/Person/LoginController.class.php
@@ -1,4 +1,5 @@
 <?php
+
 namespace Api\Controller\Person;
 
 use Api\Controller\AbstractController;
@@ -42,10 +43,18 @@ class LoginController extends AbstractController
 
         $auth_login = false;
         if($user_info){
-            $user_info ? session('user_info',$user_info) : session('user_info',$user_info);
             $auth_login = true;
         }
 
         $this->_result = $auth_login;
+
+        if ($auth_login) {
+
+            redirect("http://127.0.0.1/message/list.php");
+        }
+        else {
+            redirect("http://127.0.0.1/message/login_error.php");
+        }
     }
+
 }
diff --git a/trunk/Message/Apicp/Controller/Message/MessageController.class.php b/trunk/Message/Apicp/Controller/Message/MessageController.class.php
index 0b37817..22f02ca 100644
--- a/trunk/Message/Apicp/Controller/Message/MessageController.class.php
+++ b/trunk/Message/Apicp/Controller/Message/MessageController.class.php
@@ -1,4 +1,5 @@
 <?php
+
 namespace Apicp\Controller\Message;
 
 use Apicp\Controller\AbstractController;
@@ -7,7 +8,9 @@ use Common\Model\MessageModel;
 class MessageController extends AbstractController
 {
     protected $_require_login = false;
-    private $m_message;   // MessageModel 模型对象
+
+    private $m_message;
+    // MessageModel 模型对象
 
     public function __construct()
     {
@@ -15,6 +18,7 @@ class MessageController extends AbstractController
 
         $this->m_message = new MessageModel;
     }
+
     /**
      * 留言删除
      * @author <362431947@qq.com>
@@ -29,10 +33,6 @@ class MessageController extends AbstractController
             E('_ERROR_MESSAGE_ID_EMPTY');
         }
 
-        $uid = intval($input['uid']);
-        if(! $uid){
-            E('_ERROR_USER_ID_EMPTY');
-        }
 
         $result = $this->m_message->del($message_id);
 
@@ -41,46 +41,87 @@ class MessageController extends AbstractController
 
     /**
      * 搜索 搜索(按姓名、性别、手机号、邮箱以及留言标题进行或查询)、列表、留言详情查看
-     * @author <362431947@qq.com>
-     * @date   2018-10-10
-     * @return [type]
+     * User: <362431947@qq.com>
+     * @return bool
+     * @throws \Think\Exception
+     * Date: 2018-10-10 Time: 9:31
      */
     public function search_post()
     {
         $input = I('post.');
 
-        $conds = $this->getConds($input);
-        if(false === $conds){
+//        print_r($input);
+
+        $conds = $input;
+//        $conds = $this->getConds($input);
+
+
+        if (false === $conds) {
             E('_ERROR_SEARCH_CONDS_EMPTY');
-            return false;
         }
 
         $list = $this->m_message->search($conds);
+
+
         $this->_result = $list;
 
         return true;
     }
 
     /**
+     * 留言信息列表
+     * User: <362431947@qq.com>
+     * Date: 2018-10-11 Time: 9:58
+     */
+    public function list_post()
+    {
+        $input = I('post.');
+
+        $page = intval($input['page']);
+
+        unset($input['page']);
+
+
+        $this->_result = $this->m_message->messageList($input,$page);
+    }
+
+    /**
+     * 留言详情
+     * User: <362431947@qq.com>
+     * Date: 2018-10-11 Time: 11:51
+     */
+    public function detail_post()
+    {
+        $input = I('post.');
+
+        $message_id = intval($input['message_id']);
+
+        $this->_result = $this->m_message->messageDetail($message_id);
+    }
+
+    /**
      * 获取搜索条件
-     * @author <362431947@qq.com>
-     * @date   2018-10-10
-     * @param  array      $search 搜索条件
-     * @return [type]
+     * User: <362431947@qq.com>
+     * @param array $search
+     * @return array|bool
+     * Date: 2018-10-10
      */
     private function getConds($search = [])
     {
-        if(! $search){
+        if (! $search) {
             return false;
         }
+
         $conds = [];
         $fields = ['name','sex','mobile','email','title'];
 
         foreach ($fields as  $field) {
-            if($val = trim($search[$field])){
+            if ($val = trim($search[$field])) {
                 $conds[$field] = $val;
+                break;
             }
         }
+        print_r($conds);
         return $conds;
     }
 }
diff --git a/trunk/Message/Common/Model/AbstractModel.class.php b/trunk/Message/Common/Model/AbstractModel.class.php
index aac9429..8b9ff9b 100644
--- a/trunk/Message/Common/Model/AbstractModel.class.php
+++ b/trunk/Message/Common/Model/AbstractModel.class.php
@@ -11,6 +11,10 @@ namespace Common\Model;
 
 abstract class AbstractModel extends \Com\Model
 {
+    const PAGING_DEFAULT_PAGE = 1;
+
+    const PAGING_DEFAULT_LIMIT = 20;
+
     // 构造方法
     public function __construct()
     {
diff --git a/trunk/Message/Common/Model/AttachmentModel.class.php b/trunk/Message/Common/Model/AttachmentModel.class.php
index 381a551..d1d1395 100644
--- a/trunk/Message/Common/Model/AttachmentModel.class.php
+++ b/trunk/Message/Common/Model/AttachmentModel.class.php
@@ -11,45 +11,71 @@ class AttachmentModel extends AbstractModel
 
     private $upload_dir = '../../trunk/Message/attachment/';
 
+    /**
+     * 构造方法
+     * @author <362431947@qq.com>
+     * @date   2018-10-10
+     */
+    public function __construct()
+    {
+        parent::__construct();
+    }
     // 素材入库
     public function add()
     {
-        $bool = false;
-        $attachment = $this->initAttac();
+        $attachment_id_arr = [];
+
+        $microtme = $this->microtime();
+        $domain = md5($_SERVER['HTTP_HOST']);
+        if($_FILES){
+            foreach ($_FILES as $key => $file) {
+                $attach_id = 0;
+                $attachment = [];
 
+                $attachment['path']    = $this->upload($file);
+                $attachment['domain']  = $domain;
+                $attachment['created'] = $microtme;
 
-        if(is_array($attachment) && $attachment){
-            $bool = $this->_m->insert_all($attachment);
+                $attach_id = $this->_m->insert($attachment);
+
+                if($attach_id){
+                    $attachment_id_arr[] = $attach_id;
+                }
+                else{
+                    break;
+                }
+            }
+
+            if(! $attach_id){
+                E('保存失败');
+                return false;
+            }
         }
-        return boolval($bool);
+
+        return $attachment_id_arr ? implode(',',$attachment_id_arr) : '';
     }
 
+
     /**
-     * 整理素材入库数据
-     * @author <362431947@qq.com>
-     * @date   2018-10-09
-     * @return array
+     * 附件删除
+     * User: <362431947@qq.com>
+     * @param string $attachment_id
+     * @return mixed
+     * Date: 2018-10-10 Time: 22:13
      */
-    private function initAttac()
+    public function del($attachment_id = '')
     {
-        $attachment = [];
-        $index = 0;
-        foreach ($_FILES as $key => $file) {
-            $attachment[$index]['path']    = $this->upload($file);
-            $attachment[$index]['domain']  = md5($_SERVER['HTTP_HOST']);
-            $attachment[$index]['created'] = $this->microtime();
-
-            $index++;
-        }
-        return $attachment;
+        return $this->_m->delete($attachment_id);
     }
+
     /**
      * 素材附件上传
-     * @author <362431947@qq.com>
-     * @date   2018-10-09
-     * @param  array     $file
-     * @param  string     $subdir
-     * @return mixed
+     * User: <362431947@qq.com>
+     * @param array $file
+     * @param string $subdir
+     * @return bool|string
+     * @throws \Think\Exception
+     * Date: 2018-10-9 Time: 22:14
      */
     public function upload(array $file,$subdir='')
     {
diff --git a/trunk/Message/Common/Model/CommentModel.class.php b/trunk/Message/Common/Model/CommentModel.class.php
index b3224a5..d521f18 100644
--- a/trunk/Message/Common/Model/CommentModel.class.php
+++ b/trunk/Message/Common/Model/CommentModel.class.php
@@ -9,49 +9,29 @@ class CommentModel extends AbstractModel
         parent::__construct();
     }
 
-    public function addOne($data)
-    {
-        return  $this->_m->insert($data);
-    }
 
     /**
      * 保存评论信息
-     * @author <362431947@qq.com>
-     * @date   2018-10-10
+     * User: <362431947@qq.com>
+     * @param array $data
+     * @return mixed
+     * Date: 2018-10-10 Time: 12:04
      */
     public function add($data = [])
     {
         $data['domain'] = md5($_SERVER['HTTP_HOST']);
         $data['created'] = $this->microtime();
-        print_r($data);
 
         return  $this->_m->insert($data);
-
-        // $comment_id =  $this->_m->insert($data);
-
-//        $msg_comment = [
-//            'message_id' => intval($data['message_id']),
-//            'comment_id' => $comment_id,
-//            'domain' => md5($_SERVER['HTTP_HOST']),
-//            'created' => $this->microtime(),
-//        ];
-
-//        $m_msg_comment = new MsgCommentModel();
-//
-//        $id =  $m_msg_comment->add($msg_comment);
-//
-//        if($comment_id && $id){
-//            $this->_m->commit();
-//            $result = true;
-//        }
-//        else{
-//            $this->_m->rollback();
-//            $result = false;
-//        }
-
-//        return $result;
     }
 
+    /**
+     * 通过留言id获取评论信息
+     * User: <362431947@qq.com>
+     * @param int $message_id
+     * @return array|bool
+     * Date: 2018-10-11 Time: 12:05
+     */
     public function getCommentByMsgId($message_id = 0)
     {
         $params = [];
@@ -66,15 +46,23 @@ class CommentModel extends AbstractModel
         $m_person = new PersonModel();
         $table_person = $m_person->get_tname();
 
-        $sql = "SELECT `comment`,b.name commenter 
-                FROM __TABLE a 
+        $sql = "SELECT `comment`,b.name commenter,a.created
+                FROM __TABLE__ a
                 LEFT JOIN {$table_person} b ON a.uid = b.person_id
-                WHERE `message` = ? ";
+                WHERE `message_id` = ? ";
         return $this->_m->fetch_array($sql,$params);
     }
 
+    /**
+     * 通过留言id删除评论
+     * User: <362431947@qq.com>
+     * @param int $message_id
+     * @return mixed
+     * Date: 2018-10-11 Time: 12:05
+     */
     public function del($message_id = 0)
     {
         return $this->_m->delete($message_id);
     }
+
 }
diff --git a/trunk/Message/Common/Model/MsgCommentModel.class.php b/trunk/Message/Common/Model/MsgCommentModel.class.php
new file mode 100644
index 0000000..ffc7c63
--- /dev/null
+++ b/trunk/Message/Common/Model/MsgCommentModel.class.php
@@ -0,0 +1,26 @@
+<?php
+namespace Common\Model;
+
+class MsgCommentModel extends AbstractModel
+{
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    /**
+     * 添加留言与评论关联信息
+     * @author <362431947@qq.com>
+     * @date   2018-10-10
+     * @param  array      $data
+     */
+    public function add($data = [])
+    {
+        return $this->_m->insert($data);
+    }
+
+    public function del($message_id = 0)
+    {
+        return $this->_m->delete($message_id);
+    }
+}
diff --git a/trunk/Message/Common/Sql/structure.php b/trunk/Message/Common/Sql/structure.php
index b222e6c..1e28d0b 100644
--- a/trunk/Message/Common/Sql/structure.php
+++ b/trunk/Message/Common/Sql/structure.php
@@ -47,7 +47,7 @@ CREATE TABLE IF NOT EXISTS `zx_message_message`(
 )ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='留言板-留言信息表';
 
 -- 留言与评论关联表
-CREATE TABLE IF NOT EXISTS `zx_message_msg__comment`(
+CREATE TABLE IF NOT EXISTS `zx_message_msg_comment`(
     `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
     `message_id` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '留言记录id',
     `comment_id` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '评论记录id',
@@ -69,8 +69,9 @@ CREATE TABLE IF NOT EXISTS `zx_message_msg__comment`(
 -- 评论表
 CREATE TABLE IF NOT EXISTS `zx_message_comment`(
     `comment_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
+    `message_id` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '留言记录id',
     `comment` varchar(140) NOT NULL DEFAULT '' COMMENT '评论内容',
-    `m_uid` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '操作用户id',
+    `uid` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '操作用户id',
     `domain` varchar(32) NOT NULL DEFAULT '' COMMENT '企业域名',
     `status` tinyint(3) unsigned NOT NULL DEFAULT 1 COMMENT '状态, 1=初始化,2=已更新,3=已删除',
     `created` bigint(13) unsigned NOT NULL DEFAULT 0 COMMENT '创建时间',
@@ -79,11 +80,11 @@ CREATE TABLE IF NOT EXISTS `zx_message_comment`(
     PRIMARY KEY(`comment_id`),
     INDEX(`domain`),
     INDEX(`status`),
-    INDEX(`m_uid`),
+    INDEX(`uid`),
     INDEX(`created`),
     INDEX(`updated`),
     INDEX(`deleted`)
-)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='留言与评论关联表';
+)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='评论表';
 
 -- 留言板素材表
 CREATE TABLE IF NOT EXISTS `zx_message_attachment`(
--
libgit2 0.22.2