ApproveQuestionController.class.php
4.24 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
<?php
/**
* Created by PhpStorm.
* User: tangxingguo
* Date: 2017/4/11
* Time: 18:36
*/
namespace Apicp\Controller\Answer;
use Com\PackageValidate;
use Common\Common\TaskCenter;
use Common\Common\AnswerHelper;
use Common\Common\Constant;
use Common\Common\Notice;
use Common\Service\QuestionService;
use Common\Common\IntegralStrategy;
use Common\Service\UserActionService;
class ApproveQuestionController extends \Apicp\Controller\AbstractController
{
/**
* ApproveQuestion
*
* @author
* @desc 审批提问接口
*
* @param Int type:true 审批类型(1=驳回;2=通过)
* @param Int question_id:true 问题ID
*/
public function Index_post()
{
// 验证规则
$rules = [
'type' => 'require|integer|in:1,2',
'question_id' => 'require|integer',
];
// 验证数据
$validate = new PackageValidate($rules, [], array_keys($rules));
$type = $validate->postData['type'];
$questionId = $validate->postData['question_id'];
// 提问信息
$questionServ = new QuestionService();
$questionInfo = $questionServ->get($questionId);
// 提问数据不存在
if (empty($questionInfo)) {
E('_ERR_ANSWER_QUESTION_NOT_FOUND');
}
// 审批状态为非待审批
if ($questionInfo['check_status'] != Constant::QUESTION_CHECK_STATUS_WAIT) {
// 提问已经被审批
E('_ERR_ANSWER_QUESTION_IS_APPROVED');
}
// 审批
$checkStatus = $type == Constant::QUESTION_CHECK_IS_FAIL ? Constant::QUESTION_CHECK_STATUS_FAIL : Constant::QUESTION_CHECK_STATUS_PASS;
$data = [
'checker_type' => Constant::CHECKER_IS_ADMIN, // 审批人类型:管理员
'check_time' => MILLI_TIME,
'check_status' => $checkStatus,
'checker_uid' => $this->_login->user['eaId'],
'checker_name' => $this->_login->user['eaRealname'],
];
$questionServ->update($questionId, $data);
// 记录提问次数(审核通过后)
if (Constant::QUESTION_CHECK_STATUS_PASS == $type) {
$actionServ = new UserActionService();
$saveRes = $actionServ->save($questionInfo['uid'], $questionInfo['question_id'], Constant::INT_ACT_QUESTION);
if ($saveRes) {
// 触发积分策略:提问次数
$questionTotal = $actionServ->count_by_conds([
'uid' => $questionInfo['uid'],
'action_key' => Constant::INT_ACT_QUESTION,
]);
$triggerTypes[] = [
'triggerKey' => Constant::INT_TRIGGER_QUESTION,
'value' => $questionTotal,
];
// 触发积分规则,获得积分数
$strategyServ = &IntegralStrategy::instance();
$intTotal = $strategyServ->trigger($questionInfo['uid'], $questionInfo['question_id'], '', Constant::INT_ACT_QUESTION, $triggerTypes);
}
}
// 消息推送
$noticeServ = &Notice::instance();
$questionInfo = $questionServ->get($questionId);
$answerHelper = &AnswerHelper::instance();
// 驳回
if (Constant::QUESTION_CHECK_IS_FAIL == $type) {
if ($questionInfo['integral'] > 0) {
// 有积分,退积分
$answerHelper->updateUserIntegral($questionInfo['uid'], $questionInfo['integral'], Constant::INTEGRAL_CHANGE_DESC_LIST['reject_question']);
} else {
// 没积分,消息通知发起人
$noticeServ->failNoticeToQer($questionInfo['uid'], $questionInfo);
}
} else { // 通过
// 任务中心-日常任务埋点
$taskCenter = &TaskCenter::instance();
$taskCenter->triggerDailytask([
'uid' => $questionInfo['uid'],
'app_data_id' => $questionInfo['question_id'],
'action_key' => Constant::ACTION_KEYS_ANSWER_SEND_QUESTION,
'description' => '提问审批通过',
]);
// 发消息给推送人
$noticeServ->passNoticeToQer($questionInfo['uid'], $questionInfo);
}
}
}