AnswerTempService.class.php
1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/**
* 随机答卷临时表
* Created by PhpStorm.
* User: yingcai
* Date: 2017/8/9
* Time: 下午3:35
*/
namespace Common\Service;
use Common\Model\AnswerDetailTempModel;
use Common\Model\AnswerTempModel;
class AnswerTempService extends AbstractService
{
/** @var AnswerDetailTempModel */
protected $answer_dt_model;
// 构造方法
public function __construct()
{
$this->_d = new AnswerTempModel();
$this->answer_dt_model = new AnswerDetailTempModel();
parent::__construct();
}
/**
* 根据试卷ID获取一份答卷
*
* @param $ep_id int 试卷ID
*
* @return array
*/
public function get_answer_temp($ep_id)
{
$data = [];
// 获取所有临时试卷ID列表
$eat_ids = $this->_d->list_by_conds(['ep_id' => $ep_id], null, [], 'eat_id');
$eat_ids = array_column($eat_ids, 'eat_id');
// 随机获取一个临时试卷ID
$eat_id = array_rand($eat_ids);
if (!$eat_id) {
// 根据答卷ID获取答卷详情
$data = $this->answer_dt_model->list_by_conds(['eat_id' => $eat_id]);
}
return $data;
}
}