ActionLogService.class.php
7.41 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?php
/**
* Created by PhpStorm.
* User: zhonglei
* Date: 2017/6/21
* Time: 17:14
*/
namespace Common\Service;
use Common\Common\Constant;
use Common\Common\Notice;
use Common\Model\ActionLogModel;
use Common\Model\MedalModel;
use Common\Model\MedalRecordModel;
use Common\Model\MedalRelationModel;
use Common\Common\Integral;
use Common\Common\User;
class ActionLogService extends AbstractService
{
/** @var MedalModel */
protected $_medal_model;
/** @var MedalRelationModel */
protected $_medal_relation_model;
/** @var MedalRecordModel */
protected $_medal_record_model;
// 构造方法
public function __construct()
{
$this->_medal_model = new MedalModel();
$this->_medal_relation_model = new MedalRelationModel();
$this->_medal_record_model = new MedalRecordModel();
$this->_d = new ActionLogModel();
parent::__construct();
}
/**
* 问答式中心勋章处理
*
* @author: 蔡建华
* @param int $class_id 问答类型ID
* @param string $uid 回答问题用户ID
* @param string $operator_uid 操作用户UID
* @param array &$award 返回数据
*
* @return bool
*/
public function medal($class_id = '', $uid = '', $operator_uid = '', &$award = [])
{
// 获取用户信息
$userServ = &User::instance();
$user = $userServ->getByUid($uid);
// 如果没有用户信息
if (empty($user['memUsername'])) {
return true;
}
// 获取用户权限
$rightServ = new RightService();
$right = $rightServ->get_by_right($user);
$data['right'] = $right;
$medal = $this->_medal_model->fetch_all_medal($data);
// 查询出相关激励
if (empty($medal)) {
return true;
}
// 获取符合条件的激励IDS
$em_ids = array_column($medal, 'em_id');
// 查询激励关系列表
$list = $this->_medal_relation_model->list_by_conds(['em_id' => $em_ids]);
// 如果存在符合条件激励
if (empty($list)) {
return true;
}
// 获取激励列表IDS
$em_id_arr = array_column($list, 'em_id');
// 如果查询出激励IDS
if (empty($em_id_arr)) {
return true;
}
// 初始化勋章
$integral = new Integral();
// 获取勋章列表
$integral_list = $integral->listMedal();
// 获取激励列表
$integral_key_list = array_combine_by_key($integral_list, 'im_id');
// 获取激励列表
$result = $this->_medal_model->list_by_conds(['em_id' => $em_id_arr]);
// 实例化积分勋章
$integralUtil = &Integral::instance();
// 遍历激励列表
foreach ($result as $val) {
$select_uid = $uid;
// 如果类型是采纳问题
if (Constant::LOG_ANSWERED_BEST_TYPE == $val['answer_type'] && !empty($operator_uid)) {
$select_uid = $operator_uid;
}
// 获取当前用户是否已经领取过当期激励
$count = $this->_medal_record_model->count_by_conds(['uid' => $select_uid, 'em_id' => $val['em_id']]);
// 如果已领取积分或者勋章
if ($count) {
continue;
}
// 查询勋章对应关系
$relate_total = $this->_medal_relation_model->count_by_conds(['class_id' => $class_id, 'em_id' => $val['em_id']]);
// 如果没有对应关系
if (!$relate_total) {
continue;
}
// 查出对应ep_list
$em_list = $this->_medal_relation_model->list_by_conds(['em_id' => $val['em_id']]);
$class_ids = array_column($em_list, 'class_id');
$answered_total = 0;
// 回答问题
if (Constant::LOG_ANSWERED_TYPE == $val['answer_type']) {
// 日志表查询当前用户是的回答问题次数
$answered_total = $this->_d->count_by_conds([
'class_id' => $class_ids,
'type' => Constant::LOG_ANSWERED_TYPE,
'answer_uid' => $uid
]);
}
// 问题被采纳
if (Constant::LOG_BEST_ANSWERED_TYPE == $val['answer_type']) {
// 日志表查询当前用户是的回答问题次数
$answered_total = $this->_d->count_by_conds([
'class_id' => $class_ids,
'type' => Constant::LOG_BEST_ANSWERED_TYPE,
'answer_uid' => $uid
]);
}
// 采纳问题
if (Constant::LOG_ANSWERED_BEST_TYPE == $val['answer_type'] && !empty($operator_uid)) {
// 日志表查询当前用户是的回答问题次数
$answered_total = $this->_d->count_by_conds([
'class_id' => $class_ids,
'type' => Constant::LOG_BEST_ANSWERED_TYPE,
'uid' => $operator_uid
]);
}
// 判断满足条件的次数
if ($val['em_number'] <= $answered_total) {
// 获取勋章
if (Constant::EC_MEDAL_TYPE_MEDAL == $val['em_type']) {
$integralUtil->endowMedal($val['im_id'], $select_uid, $user['memUsername']);
// 发送勋章消息
Notice::instance()->NoticeTIntegralMsg([$select_uid], strval($integral_key_list[$val['im_id']]['name']), $val['title']);
// 激励信息
$award[] = [
'award_id' => intval($val['em_id']), // 激励ID
'uid' => $select_uid,
'award_action' => strval($val['title']), // 激励行为
'description' => strval($val['em_desc']), // 描述
'award_type' => intval($val['em_type']), // 激励类型(1=勋章;2=积分)
'medals' => [
'im_id' => intval($val['im_id']), // 勋章ID
'icon' => strval($integral_key_list[$val['im_id']]['icon']), // 勋章图标URL或者前端路径
'icon_type' => intval($integral_key_list[$val['im_id']]['icon_type']), // 勋章图标来源(1=用户上传;2=系统预设)
'name' => strval($integral_key_list[$val['im_id']]['name']), // 勋章名称
'desc' => strval($integral_key_list[$val['im_id']]['desc']), // 勋章描述
],
'integral' => intval($val['em_integral']), // 积分
];
if (Constant::LOG_ANSWERED_BEST_TYPE == $val['answer_type'] && !empty($operator_uid)) {
// 满足次数加入记录
$this->_medal_record_model->insert([
'uid' => $operator_uid,
'em_id' => $val['em_id']
]);
} else {
// 满足次数加入记录
$this->_medal_record_model->insert([
'uid' => $uid,
'em_id' => $val['em_id']
]);
}
}
}
}
return true;
}
}