UserActionService.class.php
1.52 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
<?php
/**
* Created by PhpStorm.
* User: liyifei2012it
* Date: 17/4/12
* Time: 10:38
*/
namespace Common\Service;
use Common\Common\Constant;
use Common\Model\UserActionModel;
class UserActionService extends AbstractService
{
// 构造方法
public function __construct()
{
parent::__construct();
$this->_d = new UserActionModel();
}
/**
* 获取用户行为总数
* @author tangxingguo
* @param string $uid 用户ID
* @param string $action_key 行为key
* @return int
*/
public function countByActionKey($uid, $action_key)
{
return $this->_d->countByActionKey($uid, $action_key);
}
/**
* 记录用户动作
* @author zhonglei
* @param string $uid 用户ID
* @param int $data_id 数据ID
* @param string $action_key 动作Key
* @return bool
*/
public function save($uid, $data_id, $action_key)
{
// 单条数据只记录一次的动作Key
$unique_acts = [
Constant::INT_ACT_READ,
Constant::INT_ACT_SHARED,
Constant::INT_ACT_LIKE,
Constant::INT_ACT_COLLECT,
];
$data = [
'uid' => $uid,
'data_id' => $data_id,
'action_key' => $action_key,
];
if (in_array($action_key, $unique_acts)) {
$count = $this->count_by_conds($data);
if ($count > 0) {
return false;
}
}
$this->insert($data);
return true;
}
}