92 lines
2.1 KiB
PHP
92 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace app\admin\model\app\testpaper;
|
|
|
|
use think\Model;
|
|
|
|
|
|
class Question extends Model
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
// 表名
|
|
protected $name = 'app_testpaper_question';
|
|
|
|
// 自动写入时间戳字段
|
|
protected $autoWriteTimestamp = 'integer';
|
|
|
|
// 定义时间戳字段名
|
|
protected $createTime = 'createtime';
|
|
protected $updateTime = false;
|
|
protected $deleteTime = false;
|
|
|
|
// 追加属性
|
|
protected $append = [
|
|
|
|
];
|
|
|
|
|
|
/**
|
|
* 设置试卷绑定的题目
|
|
* @return void
|
|
*/
|
|
public function setPaperQuestion($paperId,$questionList){
|
|
self::where(['testpaper_id'=>$paperId])->delete();
|
|
|
|
$data = [];
|
|
foreach ($questionList as $value) {
|
|
$data[] = [
|
|
'uniacid'=>UNIACID,
|
|
'testpaper_id'=>$paperId,
|
|
'question_id'=>$value['question_id'],
|
|
'miss_score_type'=>$value['miss_score_type'],
|
|
'score'=>$value['score'],
|
|
'score_miss'=>$value['score_miss'],
|
|
'score_miss_single'=>$value['score_miss_single'],
|
|
'createtime'=>time()
|
|
];
|
|
}
|
|
self::insertAll($data);
|
|
return true;
|
|
}
|
|
|
|
|
|
/**
|
|
* 获取试卷绑定的题目
|
|
* @param $paperId
|
|
* @return void
|
|
*/
|
|
public function getPaperQuestion($paperId){
|
|
$data = self::with('questionbank')
|
|
->where('testpaper_id',$paperId)
|
|
->order('id','asc')->select();
|
|
|
|
if(!empty($data)){
|
|
$data = collection($data)->toArray();
|
|
foreach ($data as $key => $item){
|
|
$data[$key] = array_merge($item,$item['questionbank']);
|
|
unset($data[$key]['questionbank']);
|
|
}
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
|
|
|
|
|
|
public function questionbank()
|
|
{
|
|
return $this->belongsTo('app\admin\model\app\exam\WarehouseQuestion', 'question_id', 'id', [], 'LEFT')->setEagerlyType(0);
|
|
}
|
|
|
|
|
|
public function testpaper()
|
|
{
|
|
return $this->belongsTo('app\admin\model\app\Testpaper', 'testpaper_id', 'id', [], 'LEFT')->setEagerlyType(0);
|
|
}
|
|
}
|