CommentModel.class.php 1.85 KB
<?php

namespace Common\Model;

class CommentModel extends AbstractModel
{
    public function __construct()
    {
        parent::__construct();
    }

    public function addOne($data)
    {
        return  $this->_m->insert($data);
    }

    /**
     * 保存评论信息
     * @author <362431947@qq.com>
     * @date   2018-10-10
     */
    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;
    }

    public function getCommentByMsgId($message_id = 0)
    {
        $params = [];
        $wheres = [];

        $conds = ['message_id' =>$message_id];

        if (!$this->_parse_where($wheres, $params, $conds)) {
            return false;
        }

        $m_person = new PersonModel();
        $table_person = $m_person->get_tname();

        $sql = "SELECT `comment`,b.name commenter 
                FROM __TABLE a 
                LEFT JOIN {$table_person} b ON a.uid = b.person_id
                WHERE `message` = ? ";
        return $this->_m->fetch_array($sql,$params);
    }

    public function del($message_id = 0)
    {
        return $this->_m->delete($message_id);
    }
}