JoinListController.class.php 2.57 KB
<?php
/**
 *【积分抽奖-后台】已参与人员列表接口
 * User: daijun
 * Date: 2018/3/23
 * Time: 下午3:42
 */

namespace Apicp\Controller\Activity;


use Common\Common\Constant;
use Common\Service\ActivityService;
use Common\Service\RecordService;
use Common\Service\RightService;

class JoinListController extends \Apicp\Controller\AbstractController
{

    public function Index_post()
    {
        // 获取参数
        $params = I('post.');

        if (empty($params['ac_id'])) {
            // 活动ID不能为空
            E('_EMPTY_ACTIVITY_ID');
        }

        $activity_serv = new ActivityService();

        $detail = $activity_serv->get($params['ac_id']);

        if (empty($detail)) {
            // 活动信息不存在
            E('_ERR_ACTIVITY_DATA');
        }

        // 默认值
        $page = !empty($params['page']) ? intval($params['page']) : Constant::DEFAULT_PAGE;
        $limit = !empty($params['limit']) ? intval($params['limit']) : Constant::DEFAULT_LIMIT;

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

        $record_serv = new RecordService();

        // 查询参与人员总数
        $total = $record_serv->count_by_where($params);

        $list = [];

        if ($total > 0) {
            // 定义查询字段
            $fields = 'lr_id,username,dp_name,mobile,role,job,remark,created';
            // 查询列表数据
            $list = $record_serv->list_by_where($params, $page_option, $fields);
        }

        $un_join_uids = [];

        if (Constant::DEFAULT_PAGE == $page) {
            // 如果是第一页,则需要查询未参与人员总数

            $record_list = $record_serv->list_by_conds(['ac_id' => $params['ac_id']], null, [], 'uid');

            // 已参与的人员uid集合
            $uids = [];
            if (!empty($record_list)) {
                $uids = array_filter(array_unique(array_column($record_list, 'uid')));
            }

            // 查询权限人员集合
            $right = new RightService();
            $all_right_users = $right->get_uids_by_right($detail);

            // 获取未参与人员uid集合
            $un_join_uids = array_diff($all_right_users, $uids);
        }

        // 组装返回数据
        $this->_result = [
            'total' => intval($total),
            'limit' => intval($limit),
            'join_total' => intval($total),
            'un_join_total' => count($un_join_uids),
            'page' => intval($page),
            'list' => $list
        ];

        return true;
    }

}