<?php /** * Created by PhpStorm. * User: liyifei2012it * Date: 17/7/12 * Time: 15:33 */ namespace Apicp\Controller\Exam; use Com\PackageValidate; use Common\Common\Constant; use Common\Common\User; use Common\Service\ArticleService; use Common\Service\ExamService; class ListController extends \Apicp\Controller\AbstractController { /** * List * @author liyifei * @desc 课程、素材测评明细列表 * @param Int page:1 当前页 * @param Int limit:20 每页数据总数 * @param Int article_id:true 课程ID(article_id>0,article_chapter_id=0时,查询课程测评) * @param Int article_chapter_id:false:0 素材所在章节ID * @param Int source_id:false:0 素材ID * @return array 题库列表 array( 'page' => 1, // 当前页 'limit' => 20, // 当前页条数 'total' => 100, // 总条数 'article_name' => '音频单课程', // 课程名称 'update_time' => '1494495893272', // 更新时间 'list' => array( // 列表数据 array( 'username' => '张三', // 姓名 'dp_name' => array('技术部', '产品部'), // 部门 'job' => 'CTO', // 职位 'mobile' => 13167166666, // 手机号 'exam_total' => 2, // 测评次数 'pass_total' => 1, // 通过次数 'timestamp' => 1494495893272, // 测评时间 ), ), ), */ public function Index_post() { // 验证规则 $rules = [ 'page' => 'integer', 'limit' => 'integer', 'article_id' => 'require|integer', 'article_chapter_id' => 'integer', 'source_id' => 'integer', ]; // 验证数据 $validate = new PackageValidate($rules, [], array_keys($rules)); $postData = $validate->postData; // 查询课程信息 $articleServ = new ArticleService(); $article = $articleServ->get($postData['article_id']); if (empty($article)) { E('课程不存在'); } // 分页默认值 $postData['page'] = isset($postData['page']) ? $postData['page'] : Constant::PAGING_DEFAULT_PAGE; $postData['limit'] = isset($postData['limit']) ? $postData['limit'] : Constant::PAGING_DEFAULT_LIMIT; list($start, $perpage) = page_limit($postData['page'], $postData['limit']); // 组合搜索条件 $conds = []; if ($postData['article_id'] > 0) { $conds['source_id'] = 0; $conds['article_chapter_id'] = 0; $conds['article_id'] = $postData['article_id']; } if ($postData['article_chapter_id'] > 0 && $postData['source_id'] > 0) { if (isset($conds['article_id'])) { unset($conds['article_id']); } $conds['source_id'] = $postData['source_id']; $conds['article_chapter_id'] = $postData['article_chapter_id']; } // 课程列表 $examServ = new ExamService(); $uidList = $examServ->listUidByConds($conds, [$start, $perpage]); $formatList = []; if (!empty($uidList)) { // 从UC获取人员详情 $uids = array_column($uidList, 'uid'); $userServ = &User::instance(); $users = $userServ->listByConds(['memUids' => $uids]); $uidUser = []; if (isset($users) && !empty($users['list'])) { $uidUser = array_combine_by_key($users['list'], 'memUid'); } // 获取相应人员所有测评列表 $conds['uid'] = $uids; $list = $examServ->list_by_conds($conds, null, ['created' => 'ASC']); if (!empty($list)) { foreach ($uids as $uid) { foreach ($list as $v) { if ($uid == $v['uid']) { $formatList[$uid] = [ 'username' => $uidUser[$uid]['memUsername'], 'dp_name' => $uidUser[$uid]['dpName'] ? array_column($uidUser[$uid]['dpName'], 'dpName') : [], 'job' => isset($uidUser[$uid]['memJob']) ? $uidUser[$uid]['memJob'] : '', 'mobile' => isset($uidUser[$uid]['memMobile']) ? $uidUser[$uid]['memMobile'] : '', 'exam_total' => $formatList[$uid]['exam_total'] + 1, 'pass_total' => $v['is_pass'] == Constant::ARTICLE_EXAM_IS_PASS ? $formatList[$uid]['pass_total'] + 1 : intval($formatList[$uid]['pass_total']), 'timestamp' => $v['created'], ]; } } } } } // 数据总数 $total = $examServ->countUidByConds($conds); $this->_result = [ 'page' => $postData['page'], 'limit' => $postData['limit'], 'total' => intval($total), 'article_name' => $article['article_title'], 'update_time' => $article['update_time'], 'list' => array_values($formatList), ]; } }