<?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; } }