LikeService.class.php
1.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
<?php
/**
* 考试-标签信息表
* @author: houyingcai
* @email: 594609175@qq.com
* @date : 2017-05-19 17:44:12
* @version $Id$
*/
namespace Common\Service;
use Common\Model\LikeModel;
class LikeService extends AbstractService
{
// 构造方法
public function __construct()
{
$this->_d = new LikeModel();
parent::__construct();
}
/**
* 点赞
*
* @author: 蔡建华
* @param int $ea_id 答卷ID
* @param string $uid 用户ID
*
* @return bool
*/
public function add_like_data($ea_id = 0, $uid = '')
{
if (!$ea_id) {
E('_EMPTY_EA_ID');
}
if (!$uid) {
E('_EMPTY_UID');
}
// 查询点赞记录
$data = [
'uid' => $uid,
'ea_id' => $ea_id
];
$count = $this->count_by_conds($data);
// 已点赞
if ($count) {
E('_ERR_AC_LIKE_END');
}
$rel = $this->_d->insert($data);
if ($rel) {
return true;
}
return false;
}
/**
* 取消点赞接口
*
* @author: 蔡建华
* @param int $ea_id 答卷ID
* @param string $uid 用户ID
*
* @return bool
*/
public function del_like_data($ea_id = 0, $uid = '')
{
if (!$ea_id) {
E('_EMPTY_EA_ID');
}
if (!$uid) {
E('_EMPTY_UID');
}
// 查询点赞记录
$data = [
'uid' => $uid,
'ea_id' => $ea_id
];
$count = $this->count_by_conds($data);
// 没有点赞记录
if (!$count) {
E('_ERR_EA_UNLIKE_END');
}
$rel = $this->_d->delete_by_conds($data);
if ($rel) {
return true;
}
return false;
}
}