|
|
@@ -276,6 +276,7 @@ class PaperService extends BaseService
|
|
|
$tid = isset($params['tid']) ? intval($params['tid']) : 0;
|
|
|
$rid = isset($params['rid']) ? intval($params['rid']) : 0;
|
|
|
$type = isset($params['type']) ? intval($params['type']) : 1;
|
|
|
+ $isError = isset($params['is_error']) ? intval($params['is_error']) : 1;
|
|
|
$sc = isset($params['sc']) ? intval($params['sc']) : 0;
|
|
|
$cacheKey = "caches:paper:info_{$userId}:p{$paperId}_t{$tid}_r{$rid}_l{$lid}_{$sc}";
|
|
|
$info = RedisService::get($cacheKey);
|
|
|
@@ -324,7 +325,6 @@ class PaperService extends BaseService
|
|
|
$info['fee_num'] = (int)ConfigService::make()->getConfigByCode('fee_answer_num',10);
|
|
|
|
|
|
// 当前题目
|
|
|
- //$prefix = env('DB_PREFIX','_lev');
|
|
|
$model = ExamTopicModel::from('exam_topics as a')
|
|
|
->leftJoin('exam_answers_topics as b', function ($join) use ($rid, $userId) {
|
|
|
// 是否有最近答题记录
|
|
|
@@ -441,20 +441,34 @@ class PaperService extends BaseService
|
|
|
|
|
|
|
|
|
// 上一题
|
|
|
- $info['last'] = ExamTopicModel::where(['paper_id'=> $paperId,'status'=>1,'mark'=>1])
|
|
|
- ->where('sort','>', $sort)
|
|
|
- ->select(['id','sort','topic_name'])
|
|
|
- ->orderBy('sort','asc')
|
|
|
- ->orderBy('id','asc')
|
|
|
+ $info['last'] = ExamTopicModel::from('exam_topics as a')
|
|
|
+ ->leftJoin('exam_answers_topics as b','b.topic_id','=','a.id')
|
|
|
+ ->where(['a.paper_id'=> $paperId,'a.status'=>1,'a.mark'=>1])
|
|
|
+ ->where(function($query) use($isError,$paperId){
|
|
|
+ if($isError==1){
|
|
|
+ $query->where(['b.paper_id'=> $paperId,'b.accurate'=>0])->where('b.id','>', 0);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ ->where('a.sort','>', $sort)
|
|
|
+ ->select(['a.id','a.sort','a.topic_name'])
|
|
|
+ ->orderBy('a.sort','asc')
|
|
|
+ ->orderBy('a.id','asc')
|
|
|
->first();
|
|
|
$info['last'] = $info['last'] ? $info['last']->toArray() : ['id' => 0];
|
|
|
|
|
|
// 下一题
|
|
|
- $info['next'] = ExamTopicModel::where(['paper_id'=> $paperId,'status'=>1,'mark'=>1])
|
|
|
- ->where('sort','<', $sort)
|
|
|
- ->select(['id','sort','topic_name'])
|
|
|
- ->orderBy('sort','desc')
|
|
|
- ->orderBy('id','desc')
|
|
|
+ $info['next'] = ExamTopicModel::from('exam_topics as a')
|
|
|
+ ->leftJoin('exam_answers_topics as b','b.topic_id','=','a.id')
|
|
|
+ ->where(['a.paper_id'=> $paperId,'a.status'=>1,'a.mark'=>1])
|
|
|
+ ->where(function($query) use($isError,$paperId){
|
|
|
+ if($isError==1){
|
|
|
+ $query->where(['b.paper_id'=> $paperId,'b.accurate'=>0])->where('b.id','>', 0);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ ->where('a.sort','<', $sort)
|
|
|
+ ->select(['a.id','a.sort','a.topic_name'])
|
|
|
+ ->orderBy('a.sort','desc')
|
|
|
+ ->orderBy('a.id','desc')
|
|
|
->first();
|
|
|
$info['next'] = $info['next'] ? $info['next']->toArray() : ['id' => 0];
|
|
|
}
|