MessagesModel.class.php 3.37 KB
<?php
/**
 * Created by PhpStorm.
 * User: Dell
 * Date: 2018/9/4
 * Time: 9:37
 */

namespace Common\Model;

use Common\Common\Constant;
use Common\Model\AttachmentModel;

class MessagesModel extends AbstractModel
{
    /*
     * m_status 1:未审核 2:审核未通过 3:审核通过 4:已删除
     */

    /**
     *  构造方法
     * MessagesModel constructor.
     */
    public function __construct()
    {
        $this->prefield = 'm_';
        parent::__construct();
    }

    /**
     * 联合用户表查询留言列表
     * @param null $page_option
     * @return array
     */
    public function all_mess_list($page_option = null)
    {
        $sql = "SELECT u_name,m.* FROM luoyanshou_luoyanshou,luoyanshou_messages m WHERE u_id = m.m_uid AND m.m_status <> 4 ORDER BY m.ins_date DESC ";
        return $this->_m->fetch_array($sql, [], $page_option);

    }

    /**
     * 查询留言详细
     * @param null $mid
     * @return array
     */
    public function get_mess_detail($mid = null)
    {
        $sql = "SELECT u_name,u_sex,u_mail,u_tel,m.* FROM luoyanshou_luoyanshou,luoyanshou_messages m WHERE u_id = m.m_uid AND m_id = {$mid} ";
        return $this->_m->fetch_row($sql);
    }

    /**
     * 修改留言状态
     * @param null $mid:留言ID
     * @param string $scenario:场景值
     * @param null $data:修改数据
     * @return array
     */
    public function update_mess($mid=null, $scenario='del', $data=null)
    {
        $time = date('Y-m-d H:i:s',time());
        /**
         * 留言删除
         */
        if ($scenario == 'del') {
            $sql = "UPDATE luoyanshou_messages SET m_status=4,m_updated='$time' WHERE m_id = {$mid}";
            return $this->_m->update($sql);
        }

        /**
         * 留言审核
         */
        if ($scenario == 'audit') {
            $sql = "UPDATE luoyanshou_messages SET m_status= {$data['m_status']}, m_reason='{$data['m_reason']}', m_updated='{$time}' WHERE m_id={$mid} ";
            return $this->_m->update($sql);
        }
    }


    public function search_messes($conds=null, $page_option=null)
    {
        $where = '';
        $sql1 ='';

        if ($conds != null && is_array($conds)) {
            if ($conds['u_name'] != '') {
                $where .= " u_name = '{$conds['u_name']}' OR ";
            }
            if ($conds['u_sex'] !='' ) {
                $where .= " u_sex = {$conds['u_sex']} OR ";
            }
            if ($conds['u_tel'] != '') {
                $where .= " u_tel = '{$conds['u_tel']}' OR ";
            }
            if ($conds['u_mail'] != '') {
                $where .= " u_mail = '{$conds['u_mail']}' OR ";
            }
            if ($where != '') {
                $where = substr(rtrim($where), 0, -2);
                $sql1 .= " AND m.m_uid IN ( SELECT u_id FROM luoyanshou_luoyanshou WHERE {$where} ) ";
            }

            if ($conds['m_title'] != '') {
                if ($sql1 !='') {
                    $sql1 .= "OR m.m_title = '{$conds['m_title']}' ";
                } else {
                    $sql1 .= "AND m.m_title = '{$conds['m_title']}' ";
                }
            }
        }

        $sql = " SELECT u_name,m.* from luoyanshou_luoyanshou,luoyanshou_messages m WHERE m.m_uid=u_id AND m_status <> 4 ";
        $order = " ORDER BY m.ins_date DESC ";
        $sql .= $sql1.$order;

        return $this->_m->fetch_array($sql, [], $page_option);
    }

}