<?php

namespace addons\exam\model;


use think\Db;

class PaperModel extends \app\admin\model\exam\PaperModel
{
    // 追加属性
    protected $type
        = [
            'configs' => 'array'
        ];
    // public function getConfigsAttr($value, $data)
    // {
    //     $value = $value ? $value : (isset($data['configs']) ? $data['configs'] : '');
    //     return $value ? json_decode($value, true) : [];
    // }

    /**
     * 获取试卷参与人员
     * @param $paper_id
     * @param $slice
     * @return array
     */
    public static function getJoinUsers($paper_id, $slice = 0)
    {
        $user_ids = Db::name('exam_grade')->where('paper_id', $paper_id)->group('user_id')->column('user_id');
        if ($user_ids) {
            // 截取数组
            $user_ids = $slice ? array_slice($user_ids, $slice) : $user_ids;
            return Db::name('user')->whereIn('id', $user_ids)->select();
        }

        return [];
    }
}
