UserListController.class.php 2.52 KB
<?php
/**
 * 考生列表接口
 * User: yingcai
 * Date: 2018/4/11
 * Time: 下午2:05
 */

namespace Api\Controller\Marking;

use Common\Common\User;
use Common\Service\AnswerService;

class UserListController extends AbstractController
{
    public function Index_post()
    {
        // 接收post参数
        $params = I('post.');

        $ep_id = intval($params['ep_id']);

        if (!$ep_id) {

            E('_EMPTY_EP_ID');
        }

        $page = !empty($params['page']) ? intval($params['page']) : self::DEFAULT_PAGE;
        $limit = !empty($params['limit']) ? intval($params['limit']) : self::DEFAULT_LIMIT;
        // 查询条件
        $conds = [
            'ep_id' => $ep_id,
            'marking_uid' => $this->uid,
        ];

        // 【员工名称】
        if (isset($params['username']) && $params['username']) {

            $user_conds = ['memUsername' => $params['username']];
            $user = User::instance();
            // 查询
            $sel_users = $user->listAll($user_conds);

            $memUserids = '';
            // 检索员工存在
            if (!empty($sel_users)) {
                // 员工id
                $memUserids = array_column($sel_users, 'memUid');
            }

            $conds['uid'] = $memUserids;
        }

        // 排序
        $order_option = ['my_end_time' => 'ASC'];

        // 分页
        list($start, $limit) = page_limit($page, $limit);
        $page_option = [$start, $limit];

        // 查询的字段
        $fields = 'ea_id,uid,my_score,my_is_pass,my_end_time,is_makeup';

        $answer_serv = new AnswerService();

        // 统计总数
        $total = $answer_serv->count_by_conds($conds);

        // 初始化列表数据
        $list = [];

        if ($total) {
            // 获取列表
            $list = $answer_serv->list_by_conds($conds, $page_option, $order_option, $fields);
            // 考生UID列表
            $uids = array_column($list, 'uid');
            // 获取考试信息
            $user = User::instance();
            $users_info = $user->listUsersAll([
                'memUids' => $uids,
                'memAll' => 1,
            ]);

            // 组装用户信息
            foreach ($list as &$val) {
                $val['username'] = $users_info[$val['uid']]['memUsername'];
            }
        }

        // 返回数据
        $this->_result = [
            'page' => $page,
            'limit' => $limit,
            'total' => $total,
            'list' => $list,
        ];

        return true;
    }
}