MessagesModel.class.php
3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?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);
}
}