RangeModel.class.php
2.83 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
<?php
/**
* 直播对象范围表
* @author: houyingcai
* @email: 594609175@qq.com
* @date : 2018-01-08 16:01:17
* @version $Id$
*/
namespace Common\Model;
use Common\Common\Constant;
class RangeModel extends AbstractModel
{
/**
* 构造方法
*/
public function __construct()
{
parent::__construct();
}
/**
* 根据条件读取数据数组
*
* @param array $conds 条件数组
* @param string $fields 读取字段
*
* @return array|bool
*/
public function list_by_rang_conds($conds, $fields = '*')
{
$params = array();
// 条件
$wheres = array();
if (!$this->_parse_rang_where($wheres, $params, $conds)) {
return false;
}
// 企业标记
$wheres_prod[] = "(`domain`=?";
$params[] = QY_DOMAIN;
// 状态条件
$wheres_prod[] = "`status`<?)";
$params[] = $this->get_st_delete();
// 读取记录
$sql = "SELECT {$fields} FROM __TABLE__ ";
$sql .= 'WHERE ' . implode(' OR ', $wheres) . ' AND ' . implode(' AND ', $wheres_prod);
return $this->_m->fetch_array($sql, $params);
}
/**
*
* @param array $wheres
* @param array $params
* @param array $conds
* @return bool
*/
protected function _parse_rang_where(&$wheres = [], &$params = [], $conds = [])
{
// 全公司
$wheres[] = '( type=? AND obj_id=? )';
$params[] = Constant::RIGHT_TYPE_ALL;
$params[] = Constant::RIGHT_TYPE_ALL;
// 人员
if (!empty($conds[Constant::RIGHT_TYPE_USER])) {
$wheres[] = '( type=? AND obj_id IN(?) )';
$params[] = Constant::RIGHT_TYPE_USER;
$params[] = $conds[Constant::RIGHT_TYPE_USER];
}
// 职位
if (!empty($conds[Constant::RIGHT_TYPE_JOB])) {
$wheres[] = '( type=? AND obj_id IN(?) )';
$params[] = Constant::RIGHT_TYPE_JOB;
$params[] = $conds[Constant::RIGHT_TYPE_JOB];
}
// 角色
if (!empty($conds[Constant::RIGHT_TYPE_ROLE])) {
$wheres[] = '( type=? AND obj_id IN(?) )';
$params[] = Constant::RIGHT_TYPE_ROLE;
$params[] = $conds[Constant::RIGHT_TYPE_ROLE];
}
// 部门
if (!empty($conds[Constant::RIGHT_TYPE_DEPARTMENT])) {
$wheres[] = '( type=? AND obj_id IN(?) )';
$params[] = Constant::RIGHT_TYPE_DEPARTMENT;
$params[] = $conds[Constant::RIGHT_TYPE_DEPARTMENT];
}
// 如果存在tag
if (!empty($conds[Constant::RIGHT_TYPE_TAG])) {
$wheres[] = '( type=? AND obj_id IN(?) )';
$params[] = Constant::RIGHT_TYPE_TAG;
$params[] = $conds[Constant::RIGHT_TYPE_TAG];
}
return true;
}
}