CommentModel.class.php
3.14 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
<?php
/**
* Created by PhpStorm.
* User: liyifei2012it
* Date: 17/5/18
* Time: 11:35
*/
namespace Common\Model;
class CommentModel extends AbstractModel
{
// 构造方法
public function __construct()
{
parent::__construct();
}
/**
* 获取用户评论排行
* @author zhonglei
* @param array $conds 条件
* @param int $limit 数据总数,0为取所有数据
* @return array
*/
public function listUserRank($conds, $limit = 0)
{
$wheres = [];
$params = [];
if (is_array($conds) && !empty($conds)) {
$this->_parse_where($wheres, $params, $conds);
}
// 企业标记
$wheres[] = "`{$this->prefield}domain`=?";
$params[] = QY_DOMAIN;
// 状态条件
$wheres[] = "`{$this->prefield}status`<?";
$params[] = $this->get_st_delete();
$wheres_sql = implode(' AND ', $wheres);
$sql = "SELECT *, COUNT(*) `total` FROM __TABLE__ WHERE {$wheres_sql} GROUP BY `uid` ORDER BY `total` DESC, `created` DESC";
if ($limit > 0) {
$sql .= " LIMIT {$limit}";
}
return $this->_m->fetch_array($sql, $params);
}
/**
* 获取应用数据评论排行
* @author zhonglei
* @param array $conds 条件
* @param int $limit 数据总数,0为取所有数据
* @return array
*/
public function listCommentRank($conds, $limit = 0)
{
$wheres = [];
$params = [];
if (is_array($conds) && !empty($conds)) {
$this->_parse_where($wheres, $params, $conds);
}
// 企业标记
$wheres[] = "`{$this->prefield}domain`=?";
$params[] = QY_DOMAIN;
// 状态条件
$wheres[] = "`{$this->prefield}status`<?";
$params[] = $this->get_st_delete();
$wheres_sql = implode(' AND ', $wheres);
$sql = "SELECT *, COUNT(*) `total` FROM __TABLE__ WHERE {$wheres_sql} GROUP BY `app_data_id` ORDER BY `total` DESC";
if ($limit > 0) {
$sql .= " LIMIT {$limit}";
}
return $this->_m->fetch_array($sql, $params);
}
/**
* 批量获取多人员、多评论对象的评论总数
* @author liyifei
* @param array $uids 人员UID数组
* @param string $app 应用
* @param array $app_data_ids 评论对象ID
* @return array
*/
public function listCommentTotalGroup($uids, $app, $app_data_ids)
{
$conds = [
'uid' => $uids,
'app' => $app,
'app_data_id' => $app_data_ids,
];
$wheres = [];
$params = [];
$this->_parse_where($wheres, $params, $conds);
// 企业标记
$wheres[] = "`{$this->prefield}domain`=?";
$params[] = QY_DOMAIN;
// 状态条件
$wheres[] = "`{$this->prefield}status`<?";
$params[] = $this->get_st_delete();
$wheres_sql = implode(' AND ', $wheres);
$sql = "SELECT `uid`, `app_data_id`, count(*) total FROM __TABLE__ WHERE {$wheres_sql} GROUP BY `uid`,`app_data_id` ORDER BY `total` DESC";
return $this->_m->fetch_array($sql, $params);
}
}