UserActionModel.class.php
1.57 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
<?php
/**
* Created by PhpStorm.
* User: zhonglei
* Date: 17/7/25
* Time: 11:17
*/
namespace Common\Model;
class UserActionModel extends AbstractModel
{
// 构造方法
public function __construct()
{
parent::__construct();
}
/**
* 根据用户ID计算今日动作总数
* @author zhonglei
* @param array $action_keys 动作数组
* @param string $uid 用户ID
* @return array
* + string action_key 动作
* + int total 动作总数
* + int data_total 不重复的数据总数
*/
public function countTodayActionKeyByUid($action_keys, $uid)
{
if (!is_array($action_keys) || empty($action_keys) || empty($uid)) {
return [];
}
$conds = [
'uid' => $uid,
'action_key' => $action_keys,
'created >= ?' => rstrtotime(rgmdate(MILLI_TIME, 'Y-m-d'), 1),
];
$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 `action_key`, COUNT(`user_action_id`) `total`, COUNT(DISTINCT `app_data_id`) `data_total` FROM __TABLE__ ';
$sql .= "WHERE {$wheres_sql} GROUP BY `action_key`";
return $this->_m->fetch_array($sql, $params);
}
}