<?php /** * 【销售活动-后台】管理员回帖审核接口 * * author xtong */ namespace Apicp\Controller\Comment; use Com\PackageValidate; use Common\Common\Helper; use Common\Common\User; use Common\Service\ActivityService; use Common\Service\CommentService; class CheckController extends \Apicp\Controller\AbstractController { protected $_require_login = false; /** * 接收参数 * comment_id int 必填 评论ID * check_status int 必填 审核状态(1=已审核,2:已驳回) * reason string 选填 驳回理由 * * @return bool */ public function Index_post() { // 验证规则 $rules = [ 'comment_id' => 'require', 'check_status' => 'require|between:1,2', 'reason' => 'max:140' ]; $msg = [ 'comment_id.require' => L('_ERR_COMMENT_ID_EMPTY'), 'check_status.require' => L('_ERR_APPROVAL_TYPE'), 'check_status.between' => L('_ERR_APPROVAL_TYPE'), 'reason.max' => L('_ERR_APPROVAL_REASON_LENGTH'), ]; // 验证数据 $validate = new PackageValidate($rules, $msg, array_keys($rules)); $postData = $validate->postData; // 根据评论ID获取评论详情与活动详情(含验证) $cmt_and_ac_info = $this->get_ac_info_by_comment_id($postData['comment_id']); // 帖子状态不是待审核 if ($cmt_and_ac_info['comment_info']['check_status'] != CommentService::CHECK_ING) { E('_ERR_COMMENT_CHECK_STATUS'); } // 更新评论信息 $comment_update_data = [ 'check_status' => $postData['check_status'], 'check_uname' => (string)$this->_login->user['eaRealname'], 'check_phone' => (string)$this->_login->user['eaMobile'], 'reason' => $postData['reason'] ? $postData['reason'] : '', 'check_time' => MILLI_TIME, ]; $comment_s = new CommentService(); try { // 开始事务 $comment_s->start_trans(); $comment_s->update($postData['comment_id'], $comment_update_data); if (CommentService::CHECK_OK == $postData['check_status']) { // 初始化主表 $activity_s = new ActivityService(); // 查询该用户在此活动的已通过的参与记录【包含已删除的】 $count = $comment_s->count_by_conds_contain_del([ 'check_status' => CommentService::CHECK_OK, 'uid' => $cmt_and_ac_info['comment_info']['uid'], 'ac_id' => $cmt_and_ac_info['activity_info']['ac_id'] ]); if ($count == 1) { // 更新活动表参与人数与评论数 $activity_s->update($cmt_and_ac_info['activity_info']['ac_id'], ['join_num=join_num+(?)' => 1, 'comments=comments+(?)' => 1]); } else { // 更新活动评论数 $activity_s->update($cmt_and_ac_info['activity_info']['ac_id'], ['comments=comments+(?)' => 1]); } } // 提交事物 $comment_s->commit(); } catch (\Think\Exception $e) { \Think\Log::record($e); $comment_s->rollback(); return false; } catch (\Exception $e) { \Think\Log::record($e); $comment_s->rollback(); return false; } // 发送审核消息 $comment_msg_params = [ 'subject' => $cmt_and_ac_info['activity_info']['subject'], 'comment_id' => $cmt_and_ac_info['comment_info']['comment_id'], 'ac_id' => $cmt_and_ac_info['activity_info']['ac_id'], 'created' => $cmt_and_ac_info['comment_info']['created'], 'username' => $this->_login->user['eaRealname'], 'check_time' => MILLI_TIME, 'uids' => $cmt_and_ac_info['comment_info']['uid'] ]; $message_type = CommentService::MSG_COMMENT_CHECK_SUCCESS; if (CommentService::COMMENT_CHECK_REJECT == $postData['check_status']) { $message_type = CommentService::MSG_COMMENT_CHECK_FAIL; $comment_msg_params['reason'] = $postData['reason'] ? $postData['reason'] : ''; } // 推送审核消息 $comment_s->send_msg($comment_msg_params, $message_type); // 如果开启发帖推送消息提醒 if (Helper::SALE_ALL_LOOK == $cmt_and_ac_info['activity_info']['is_post_remind'] && CommentService::CHECK_OK == $postData['check_status']) { // 获取用户详情 $user_info = User::instance()->getByUid($cmt_and_ac_info['comment_info']['uid']); // 拼接发送消息内容 $cmt_and_ac_info['activity_info']['content'] = strval($cmt_and_ac_info['comment_info']['content']); // 给有权限查看活动的人员推送消息 $comment_s->send_look_msg($cmt_and_ac_info['activity_info'], $user_info['memUsername'],$cmt_and_ac_info['comment_info']['uid']); } // 活动开启了红包功能 if (ActivityService::RED_OPENED == $cmt_and_ac_info['activity_info']['is_red_open'] && CommentService::CHECK_OK == $postData['check_status']) { // 组织分配红包请求参数 $red_params = [ 'ac_id' => $cmt_and_ac_info['comment_info']['ac_id'], 'p_type' => CommentService::RED_PACKET_RAND, 'uid' => $cmt_and_ac_info['comment_info']['uid'], 'comment_id' => $cmt_and_ac_info['comment_info']['comment_id'], ]; // 随机获取剩余红包并发送消息 $red_data = $comment_s->get_red_record($red_params); // 发放红包失败(超过领取限制或其他) if (empty($red_data['rid'])) { return true; } $red_msg_params = [ 'comment_id' => $cmt_and_ac_info['comment_info']['comment_id'], 'rid' => $red_data['rid'], 'ac_id' => $red_data['ac_id'], 'subject' => $cmt_and_ac_info['activity_info']['subject'], 'give_time' => $red_data['give_time'], 'uids' => $cmt_and_ac_info['comment_info']['uid'], ]; if (!empty($red_data['rid'])) { // 给用户发消息【获得随机红包】 $comment_s->send_msg($red_msg_params, CommentService::MSG_GET_RANDOM_REDPACKET); } } return true; } }