|
|
@@ -190,6 +190,47 @@ class TrainingLogic extends BaseLogic
|
|
|
// 开始考试
|
|
|
self::upWorkerCourse(['id'=>$params['worker_course_id'],'status'=> 4]);
|
|
|
}
|
|
|
+
|
|
|
+ $trainingCourse = TrainingCourse::where('id',$workerCourse['training_course_id'])->findOrEmpty();
|
|
|
+ // 配置是否随机出题? 0 1
|
|
|
+ if($trainingCourse->randomly_question){
|
|
|
+ $where = [];
|
|
|
+ if($trainingCourse->subclass){
|
|
|
+ $where[] = ['subclass','=',$trainingCourse->subclass];
|
|
|
+ }else{
|
|
|
+ $where[] = ['subclass','=',0];
|
|
|
+ }
|
|
|
+ // 随机出题 随机x个试题 x由该课程配置决定 比如10个试题
|
|
|
+ $trainingQuestions = TrainingQuestions::where($where)->order(Db::raw('rand()'))->limit($trainingCourse->randomly_num)->select()->toArray();
|
|
|
+ //每题多少分(按总分100分计算)
|
|
|
+ $score = bcdiv(100, count($trainingQuestions), 2);
|
|
|
+ $course_question = [];
|
|
|
+ foreach ($trainingQuestions as $block_key => $trainingQuestion) {
|
|
|
+ //[{"block_key":1,"select_value":1,"score":"20"},{"block_key":2,"select_value":2,"score":"10"},{"block_key":3,"select_value":3,"score":"70"}]
|
|
|
+ $course_question[] = [
|
|
|
+ 'block_key' => $block_key+1,
|
|
|
+ 'select_value' => $trainingQuestion['id'],
|
|
|
+ 'score' => $score
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ TrainingWorkerCourse::where('id',$workerCourse['id'])->update(['course_question_setting'=>json_encode($course_question)]);
|
|
|
+
|
|
|
+ TrainingWorkerQuestion::where('worker_course_id',$workerCourse['id'])->delete();
|
|
|
+
|
|
|
+ // 添加该工程师该课程的所有试题初始化记录
|
|
|
+ $course_question_ids = array_column($course_question,'select_value');
|
|
|
+ foreach ($course_question_ids as $question_id) {
|
|
|
+ TrainingWorkerQuestion::create([
|
|
|
+ 'master_worker_id' => $params['user_id'],
|
|
|
+ 'subclass' => $trainingCourse->subclass,
|
|
|
+ 'worker_course_id' => $workerCourse['id'],
|
|
|
+ 'questions_id' => $question_id,
|
|
|
+ 'worker_answer' => '',
|
|
|
+ 'exam_score' => 0
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
$list = TrainingWorkerQuestion::with(['trainingQuestions'])->where('worker_course_id',$params['worker_course_id'])->select()->toArray();
|
|
|
foreach ($list as &$item) {
|
|
|
$item['title'] = $item['trainingQuestions']['title'];
|
|
|
@@ -259,31 +300,25 @@ class TrainingLogic extends BaseLogic
|
|
|
// 判断是否为服务类目考试
|
|
|
if($exam_paper_details['subclass'] > 0){
|
|
|
if($study_status == 5){
|
|
|
- TrainingCategory::where('master_worker_id',$exam_paper_details['master_worker_id'])
|
|
|
- ->where('training_task_id',$exam_paper_details['training_task_id'])
|
|
|
- ->where('category_id',$exam_paper_details['subclass'])
|
|
|
- ->update(['is_must' => 1]);
|
|
|
-
|
|
|
- $masterWorker = MasterWorker::where('id',$exam_paper_details['master_worker_id'])->findOrEmpty();
|
|
|
- $category_ids = explode(',',$masterWorker->category_ids);
|
|
|
- $category_ids[] = $exam_paper_details['subclass'];
|
|
|
- $category_ids = array_unique($category_ids);
|
|
|
- // 更新工程师服务类目
|
|
|
- MasterWorker::update(['category_ids' => implode(',',$category_ids)],['id'=>$exam_paper_details['master_worker_id']]);
|
|
|
- }else{
|
|
|
- // 考试不合格则删除考试任务和考试记录,下次重新选题考试
|
|
|
- TrainingTask::where('master_worker_id',$exam_paper_details['master_worker_id'])
|
|
|
- ->where('subclass',$exam_paper_details['subclass'])->delete();
|
|
|
- TrainingCategory::where('master_worker_id',$exam_paper_details['master_worker_id'])
|
|
|
+ // 该工程师的服务类目课程全部完成,更新任务状态
|
|
|
+ $workerCourseCount = TrainingWorkerCourse::where('master_worker_id',$exam_paper_details['master_worker_id'])
|
|
|
->where('training_task_id',$exam_paper_details['training_task_id'])
|
|
|
- ->where('category_id',$exam_paper_details['subclass'])
|
|
|
- ->update(['training_task_id' => 0,'is_must' => 0]);
|
|
|
- TrainingWorkerCourse::where('master_worker_id',$exam_paper_details['master_worker_id'])
|
|
|
->where('subclass',$exam_paper_details['subclass'])
|
|
|
- ->delete();
|
|
|
- TrainingWorkerQuestion::where('master_worker_id',$exam_paper_details['master_worker_id'])
|
|
|
- ->where('subclass',$exam_paper_details['subclass'])
|
|
|
- ->delete();
|
|
|
+ ->where('study_status','<',5)
|
|
|
+ ->count();
|
|
|
+ if($workerCourseCount == 0){
|
|
|
+ TrainingCategory::where('master_worker_id',$exam_paper_details['master_worker_id'])
|
|
|
+ ->where('training_task_id',$exam_paper_details['training_task_id'])
|
|
|
+ ->where('category_id',$exam_paper_details['subclass'])
|
|
|
+ ->update(['is_must' => 1]);
|
|
|
+
|
|
|
+ $masterWorker = MasterWorker::where('id',$exam_paper_details['master_worker_id'])->findOrEmpty();
|
|
|
+ $category_ids = explode(',',$masterWorker->category_ids);
|
|
|
+ $category_ids[] = $exam_paper_details['subclass'];
|
|
|
+ $category_ids = array_unique($category_ids);
|
|
|
+ // 更新工程师服务类目
|
|
|
+ MasterWorker::update(['category_ids' => implode(',',$category_ids)],['id'=>$exam_paper_details['master_worker_id']]);
|
|
|
+ }
|
|
|
}
|
|
|
}else{
|
|
|
// 该工程师的课程全部完成,更新任务状态
|
|
|
@@ -501,64 +536,64 @@ class TrainingLogic extends BaseLogic
|
|
|
|
|
|
$trainingCategory->training_task_id = $trainingTask->id;
|
|
|
$trainingCategory->save();
|
|
|
- }
|
|
|
-
|
|
|
- // 保证用户进来后该分类都是新课程记录 新试题记录 即原来的记录被删除
|
|
|
- TrainingWorkerCourse::where('master_worker_id',$params['user_id'])
|
|
|
- ->where('subclass',$params['category_id'])
|
|
|
- ->delete();
|
|
|
- TrainingWorkerQuestion::where('master_worker_id',$params['user_id'])
|
|
|
- ->where('subclass',$params['category_id'])
|
|
|
- ->delete();
|
|
|
-
|
|
|
- $training_course_ids = json_decode(TrainingTask::where('id',$trainingTask->id)->value('training_course_id')??'[]',true);
|
|
|
- // 添加该工程师的所有培训课程初始化记录
|
|
|
- foreach ($training_course_ids as $course_id) {
|
|
|
- $workerCourse = TrainingWorkerCourse::create([
|
|
|
- 'master_worker_id' => $params['user_id'],
|
|
|
- 'training_task_id' => $trainingTask->id,
|
|
|
- 'training_course_id' => $course_id,
|
|
|
- 'subclass' => $params['category_id'],
|
|
|
- 'play_time' => 0,
|
|
|
- 'exam_start_time' => 0,
|
|
|
- 'exam_end_time' => 0,
|
|
|
- 'study_status' => 0,
|
|
|
- 'exam_score' => 0,
|
|
|
- ]);
|
|
|
|
|
|
- $trainingCourse = TrainingCourse::where('id',$course_id)->findOrEmpty();
|
|
|
- // 配置是否随机出题? 0 1
|
|
|
- $trainingCourse->randomly_question = true;
|
|
|
- if($trainingCourse->randomly_question){
|
|
|
- // 随机出题 随机x个试题 x由该课程配置决定 比如10个试题
|
|
|
- $trainingQuestions = TrainingQuestions::where('subclass',$trainingCourse->subclass)->order(Db::raw('rand()'))->limit($trainingCourse->randomly_num)->select()->toArray();
|
|
|
- //每题多少分(按总分100分计算)
|
|
|
- $score = 100 / count($trainingQuestions);
|
|
|
- $course_question = [];
|
|
|
- foreach ($trainingQuestions as $block_key => $trainingQuestion) {
|
|
|
- //[{"block_key":1,"select_value":1,"score":"20"},{"block_key":2,"select_value":2,"score":"10"},{"block_key":3,"select_value":3,"score":"70"}]
|
|
|
- $course_question[] = [
|
|
|
- 'block_key' => $block_key+1,
|
|
|
- 'select_value' => $trainingQuestion['id'],
|
|
|
- 'score' => $score
|
|
|
- ];
|
|
|
- }
|
|
|
- TrainingWorkerCourse::where('id',$workerCourse->id)->update(['course_question_setting'=>json_encode($course_question)]);
|
|
|
- }else{
|
|
|
- $course_question = $trainingCourse->course_question_setting;
|
|
|
- }
|
|
|
-
|
|
|
- // 添加该工程师该课程的所有试题初始化记录
|
|
|
- $course_question_ids = array_column($course_question,'select_value');
|
|
|
- foreach ($course_question_ids as $question_id) {
|
|
|
- $workerQuestion = TrainingWorkerQuestion::create([
|
|
|
+ /*// 保证用户进来后该分类都是新课程记录 新试题记录 即原来的记录被删除
|
|
|
+ TrainingWorkerCourse::where('master_worker_id',$params['user_id'])
|
|
|
+ ->where('subclass',$params['category_id'])
|
|
|
+ ->delete();
|
|
|
+ TrainingWorkerQuestion::where('master_worker_id',$params['user_id'])
|
|
|
+ ->where('subclass',$params['category_id'])
|
|
|
+ ->delete();*/
|
|
|
+
|
|
|
+ $training_course_ids = json_decode(TrainingTask::where('id',$trainingTask->id)->value('training_course_id')??'[]',true);
|
|
|
+ // 添加该工程师的所有培训课程初始化记录
|
|
|
+ foreach ($training_course_ids as $course_id) {
|
|
|
+ $workerCourse = TrainingWorkerCourse::create([
|
|
|
'master_worker_id' => $params['user_id'],
|
|
|
+ 'training_task_id' => $trainingTask->id,
|
|
|
+ 'training_course_id' => $course_id,
|
|
|
'subclass' => $params['category_id'],
|
|
|
- 'worker_course_id' => $workerCourse->id,
|
|
|
- 'questions_id' => $question_id,
|
|
|
- 'worker_answer' => '',
|
|
|
- 'exam_score' => 0
|
|
|
+ 'play_time' => 0,
|
|
|
+ 'exam_start_time' => 0,
|
|
|
+ 'exam_end_time' => 0,
|
|
|
+ 'study_status' => 0,
|
|
|
+ 'exam_score' => 0,
|
|
|
]);
|
|
|
+
|
|
|
+ $trainingCourse = TrainingCourse::where('id',$course_id)->findOrEmpty();
|
|
|
+ // 配置是否随机出题? 0 1
|
|
|
+ //$trainingCourse->randomly_question = true;
|
|
|
+ if($trainingCourse->randomly_question){
|
|
|
+ // 随机出题 随机x个试题 x由该课程配置决定 比如10个试题
|
|
|
+ $trainingQuestions = TrainingQuestions::where('subclass',$trainingCourse->subclass)->order(Db::raw('rand()'))->limit($trainingCourse->randomly_num)->select()->toArray();
|
|
|
+ //每题多少分(按总分100分计算)
|
|
|
+ $score = bcdiv(100, count($trainingQuestions), 2);
|
|
|
+ $course_question = [];
|
|
|
+ foreach ($trainingQuestions as $block_key => $trainingQuestion) {
|
|
|
+ //[{"block_key":1,"select_value":1,"score":"20"},{"block_key":2,"select_value":2,"score":"10"},{"block_key":3,"select_value":3,"score":"70"}]
|
|
|
+ $course_question[] = [
|
|
|
+ 'block_key' => $block_key+1,
|
|
|
+ 'select_value' => $trainingQuestion['id'],
|
|
|
+ 'score' => $score
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ TrainingWorkerCourse::where('id',$workerCourse->id)->update(['course_question_setting'=>json_encode($course_question)]);
|
|
|
+ }else{
|
|
|
+ $course_question = $trainingCourse->course_question_setting;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加该工程师该课程的所有试题初始化记录
|
|
|
+ $course_question_ids = array_column($course_question,'select_value');
|
|
|
+ foreach ($course_question_ids as $question_id) {
|
|
|
+ $workerQuestion = TrainingWorkerQuestion::create([
|
|
|
+ 'master_worker_id' => $params['user_id'],
|
|
|
+ 'subclass' => $params['category_id'],
|
|
|
+ 'worker_course_id' => $workerCourse->id,
|
|
|
+ 'questions_id' => $question_id,
|
|
|
+ 'worker_answer' => '',
|
|
|
+ 'exam_score' => 0
|
|
|
+ ]);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|