__('Random_type random'), 'type' => __('Random_type type')]; } public function getStatusList() { return ['1' => __('Status 1'), '0' => __('Status 0')]; } public function getRandomTypeTextAttr($value, $data) { $value = $value ? $value : (isset($data['random_type']) ? $data['random_type'] : ''); $list = $this->getRandomTypeList(); return isset($list[$value]) ? $list[$value] : ''; } public function getStatusTextAttr($value, $data) { $value = $value ? $value : (isset($data['status']) ? $data['status'] : ''); $list = $this->getStatusList(); return isset($list[$value]) ? $list[$value] : ''; } public function group() { return $this->belongsTo('Group', 'group_id', 'id', [], 'LEFT')->setEagerlyType(0); } /** * 获取试卷总分 * @param $value * @param $data * @return mixed */ public function getScoreAmountAttr($value, $data) { $count = Question::where([ 'testpaper_id'=>$data['id'] ])->sum('score'); return $count; } /** * 获取题目数量 * @param $value * @param $data * @return mixed */ public function getQuestionAmountAttr($value, $data) { $count = Question::where([ 'testpaper_id'=>$data['id'] ])->count(); return $count; } }