<?php /** * 【销售活动-后台】获取评论列表接口 * * User: WJY * Date: 2017-11-02 */ namespace Apicp\Controller\Comment; use Common\Service\ActivityService; use Common\Service\CommentService; use Common\Service\PacketService; class CommentListOldController extends \Apicp\Controller\AbstractController { /** @var ActivityService */ protected $activity_s; /** @var PacketService */ protected $packet_s; /** @var CommentService */ protected $comment_s; public function before_action($action = '') { if (!parent::before_action($action)) { return false; } // 实例化活动信息表 $this->activity_s = new ActivityService(); // 实例化红包表 $this->packet_s = new PacketService(); // 实例化评论表 $this->comment_s = new CommentService(); return true; } public function Index_post() { $params = I('post.'); $result = $this->comment_list($params); $this->_result = $result; return true; } /** * 获取评论列表(后台) * * @param array $reqData 请求数据 * * @return array */ protected function comment_list($reqData) { // 活动存在性判断 $ac_id = intval($reqData['ac_id']); if (empty($ac_id)) { E('_EMPTY_ACTIVITY_ID'); } // 查询活动信息 $activity_info = $this->activity_s->get($ac_id); if (empty($activity_info)) { E('_ERR_ACTIVITY_DATA'); } // 红包开启状态,审核开启状态 $red_status = $activity_info['is_red_open']; $is_check_open = $activity_info['is_check_open']; // 默认值 $page = isset($reqData['page']) ? intval($reqData['page']) : ActivityService::DEFAULT_PAGE; // 默认每页条数 $limit = isset($reqData['limit']) ? intval($reqData['limit']) : ActivityService::DEFAULT_LIMIT; // 分页 list($start, $limit) = page_limit($page, $limit); $page_option = [$start, $limit]; // 排序 $order_option = ['check_time' => 'DESC']; // 审核状态 $check_status = isset($reqData['check_status']) ? $reqData['check_status'] : ActivityService::CHECK_PASS; // 条件组装 $conds = [ 'ac_id' => $ac_id, 'check_status' => $check_status ]; // 查询总记录数 $total = $this->comment_s->count_by_conds($conds); // 初始化审核统计字段 $passtotal = 0; $checkingtotal = 0; $failtotal = 0; if (ActivityService::IS_CHECK_OPEN == $is_check_open) { //统计通过/审核中/已驳回的数目 $passtotal = $this->comment_s->count_by_conds([ 'ac_id' => $ac_id, 'check_status' => ActivityService::CHECK_PASS ]); $checkingtotal = $this->comment_s->count_by_conds([ 'ac_id' => $ac_id, 'check_status' => ActivityService::CHECK_ING ]); $failtotal = $this->comment_s->count_by_conds([ 'ac_id' => $ac_id, 'check_status' => ActivityService::CHECK_FAIL ]); } // 查询列表 $list = []; $datalist = [ 'red_status' => $red_status, 'is_check_open' => $is_check_open, 'check_status' => $check_status ]; if ($total > 0) { $comm_list = $this->comment_s->list_by_conds($conds, $page_option, $order_option); // 格式化列表数据 $list = $this->comment_s->format_comment_list_admin($comm_list, $datalist); } $result = [ 'check_status' => $check_status, 'page' => $page, 'limit' => $limit, 'total' => (int)$total, 'pass_total' => (int)$passtotal, 'checking_total' => (int)$checkingtotal, 'fail_total' => (int)$failtotal, 'is_red_open' => (int)$red_status, 'list' => $list ]; return $result; } }