移动端:
public function specialTestPaper(){
list($special_id, $type) = UtilService::PostMore([
['special_id', 0],
['type', 1],
], $this->request, true);
if (!$special_id) return JsonService::fail('缺少参数,无法访问');
switch ($type) {
case 1:
$relationship = 1;
break;
case 2:
$relationship = 2;
break;
}
$data = Relation::alias('r')->join('TestPaper t', 'r.relation_id=t.id')->where(['r.is_del' => 0, 't.is_show' => 1, 't.is_del' => 0, 't.type' => $type, 'r.relationship' => $relationship, 'r.relationship_id' => $special_id])->field('t.*,r.id as rid,r.sort')->order('r.sort DESC,rid DESC')->select();
$data = count($data) > 0 ? $data->toArray() : [];
foreach ($data as $key => &$value) {
if ($type == 1) {
$record = ExaminationRecord::where(['test_id' => $value['id'], 'uid' => $this->uid, 'type' => 1])->order('id desc')->find();
if (!$record) $value['done'] = 0;
else $value['done'] = ExaminationTestRecord::where(['e_id' => $record['id'], 'uid' => $this->uid, 'type' => 1])->count();
} else if ($type == 2) {
$value['is_pay'] = (!$this->uid || $this->uid == 0) ? false : TestPaperObtain::PayTestPaper($value['id'], $this->uid, 2);
}
}
return JsonService::successful($data);
}
pc端:
public function specialTestPaper()
{
list($special_id, $type) = UtilService::PostMore([
['special_id', 0],
['type', 1],
], $this->request, true);
if (!$special_id) return JsonService::fail('缺少参数,无法访问');
switch ($type) {
case 1:
$relationship = 1;
break;
case 2:
$relationship = 2;
break;
}
$data = Relation::alias('r')->join('TestPaper t', 'r.relation_id=t.id')
->where(['r.is_del' => 0, 't.is_show' => 1, 't.is_del' => 0, 't.type' => $type, 'r.relationship' => $relationship, 'r.relationship_id' => $special_id])
->field('t.*,r.id as rid,r.sort')->order('r.sort DESC,rid DESC')->select();
$data = count($data) > 0 ? $data->toArray() : [];
foreach ($data as $key => &$value) {
if ($type == 1) {
$record = ExaminationRecord::where(['test_id' => $value['id'], 'uid' => $this->uid, 'type' => 1])->order('id desc')->find();
if (!$record) $value['done'] = 0;
else $value['done'] = ExaminationTestRecord::where(['e_id' => $record['id'], 'uid' => $this->uid, 'type' => 1])->count();
} else if ($type == 2) {
$value['is_pay'] = (!$this->uid || $this->uid == 0) ? false : TestPaperObtain::PayTestPaper($value['id'], $this->uid, 2);
}
}
return JsonService::successful($data);
}