AddController.class.php
3.03 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
<?php
/**
* 【活动中心-手机端】 回复/评论接口
* User: caijaihua
* Date: 2017-05-09
*/
namespace Api\Controller\Comment;
use Common\Service\CommentService;
use Common\Service\ActivityService;
use Common\Common\TaskCenter;
class AddController extends AbstractController
{
/**
* @var ActivityService 活动yService对象
*/
protected $_activity_serv;
/**
* @var CommentService 评论回复信息表
*/
protected $_comment_serv;
public function before_action($action = '')
{
if (!parent::before_action($action)) {
return false;
}
// 实例化权限表
$this->_activity_serv = new ActivityService();
$this->_comment_serv = new CommentService();
return true;
}
//评论或回复
public function Index_post()
{
$params = I('post.');
// 判断是否外部人员
if (empty($this->uid)) {
E('_ERR_COMMENT_ADD');
}
// 活动详情
$ac_id = $params['ac_id'];
$activity = $this->_activity_serv->get($ac_id);
if (empty($activity)) {
E('_ERR_ACTIVITY_NOT_FOUNT');
}
// 常规类型验证
if (ActivityService::ROUTINE_TYPE == $activity['activity_type']) {
// 活动未开始不能评论
if ($activity['begin_time'] > MILLI_TIME || !$activity['activity_status']) {
E('_ERR_ACTIVE_NOT_BEGIN');
}
// 活动已结束不能对活动进行评论
if (($activity['end_time'] < MILLI_TIME || ActivityService::STOP_ACTIVITY == $activity['activity_status']) && !intval($params['comment_id'])) {
E('_ERR_ACTIVE_END');
}
}
// 发布评论ID
$username = $this->_login->user['memUsername'];
$id = $this->_comment_serv->publish_comment($params, $this->uid, $username, $activity);
//发布评论或者回复
if (!$id) {
E('_ERR_ADD_DATA');
}
// 积分消息
$msg = [];
// 常规类型埋点
if (ActivityService::ROUTINE_TYPE == $activity['activity_type']) {
// 获取积分消息
$msg = $this->_comment_serv->get_integral_msg($params, $this->uid, $id);
}
// 常规任务埋点:参与活动(进行评论)
if (ActivityService::TASK_TYPE == $activity['activity_type']) {
// 任务id
$customtask_id = intval($params['customtask_id']);
$params = array(
'uid' => $this->uid,
'customtask_id' => $customtask_id,
'app_data_id' => $ac_id,
'action_key' => 'activity_send_comment',
'description' => '参与活动(进行评论)'
);
$taskCenter = &TaskCenter::instance();
$taskCenter->triggerCustomtask($params);
}
$this->_result = array(
'comment_id' => $id,
'data' => $msg
);
return true;
}
}