employee->root_id; $info = DayStudySetting::where('root_id', '=', $root_id)->find(); if (!empty($info)) { $setting = json_decode($info['setting'], true); $train_type = []; $question_cate = []; if (!empty($setting)) { foreach ($setting as $k => $v){ if ($v['type'] == 'train') { $train_type[] = $v['id']; } if ($v['type'] == 'question') { $question_cate[] = $v['id']; } } } // 已选课件场景 $train_type_select = TrainType::where([['id', 'in', $train_type]])->column('type'); $info['train_type_name'] = implode('/', $train_type_select); // 已选课件类型 $train_class_type = TrainCourse::where([['type_id', 'in', $train_type]])->group('type')->column('type'); $type_list = [ 'video'=> '视频', 'image'=> '图文', 'audio'=> '音频' ]; $type_name = ''; foreach ($type_list as $kk => $vv) { if (in_array($kk, $train_class_type)) { $type_name .= $vv.'/'; } } $info['train_class_type'] = trim($type_name, '/'); // 已选试题分类 $info['question_cate_name'] = implode('/', $question_cate); // 已选试题类型 $question_type = ExamQuestion::where([['cate', 'in', $question_cate]])->group('type')->column('type'); $info['question_type'] = implode('/', $question_type); $info['train_type_count'] = count($train_type_select); $info['train_count'] = TrainCourse::where([['type_id', 'in', $train_type]])->count(); $info['question_cate_count'] = count($question_cate); $info['question_count'] = ExamQuestion::where([['cate', 'in', $question_cate]])->count(); $info['total_count'] = $info['train_count'] + $info['question_count']; } else { $info['status'] = 0; } View::assign('data', $info); return View::fetch(); } /** * 设置每日学练 * @return string */ public function setting(){ if (request()->isPost()) { $param = request()->only(['status', 'amount', 'starttime', 'endtime', 'setting', 'timelimit']); $data = []; if(isset($param['status'])){ $data['status'] = $param['status']; } if(isset($param['amount'])){ $data['amount'] = $param['amount']; } if(isset($param['starttime'])){ $data['starttime'] = $param['starttime']; } if(isset($param['endtime'])){ $data['endtime'] = $param['endtime']; } if(isset($param['setting'])){ $all_amount = array_sum(array_column($param['setting'], 'percent')); $root_id = request()->employee->root_id; $find = DayStudySetting::where('root_id', '=', $root_id)->find(); if (empty($find) || $all_amount > $find['amount']){ return json(['code'=> 1, 'msg'=> '随机出题总量不能大于每日学习量']); } $data['setting'] = json_encode($param['setting']); } if(isset($param['timelimit'])){ $data['timelimit'] = $param['timelimit']; } $root_id = request()->employee->root_id; $find = DayStudySetting::where('root_id', '=', $root_id)->find(); if (empty($find)) { $data['root_id'] = request()->employee->root_id; $result = DayStudySetting::create($data); } else { $result = $find->save($data); } if ($result !== false) { return json(['code'=> 0, 'msg'=> '保存成功']); } } else { $root_id = request()->employee->root_id; $find = DayStudySetting::where('root_id', '=', $root_id)->find(); View::assign('data', $find); return View::fetch(); } } /** * 设置学练内容详情 */ public function setting_detail(){ $root_id = request()->employee->root_id; $find = DayStudySetting::where('root_id', '=', $root_id)->find(); $page = input('page', 1, 'intval'); $type = input('type', '', 'trim'); if (empty($find)) { return json(['code'=> 0, 'data'=> []]); } $setting = json_decode($find['setting'], true); $list = []; if (!empty($setting)) { foreach ($setting as $k => $v) { if ($v['type'] == 'train') { if ($type == '' || $type == 'train') { $setting[$k]['type_name'] = '课件'; $setting[$k]['name'] = TrainType::where('id', '=', $v['id'])->value('type'); $train_type = TrainCourse::where('type_id', '=', $v['id'])->group('type')->column('type'); $type_list = [ 'video'=> '视频', 'image'=> '图文', 'audio'=> '音频' ]; $type_name = ''; foreach ($type_list as $kk => $vv) { if (in_array($kk, $train_type)) { $type_name .= $vv.'/'; } } $setting[$k]['child_type'] = trim($type_name, '/'); $setting[$k]['child_count'] = TrainCourse::where([['type_id', '=', $v['id']], ['delete_time', '=', 0]])->count(); $list[] = $setting[$k]; } } elseif($v['type'] == 'question') { if ($type == 'question' || $type == '') { $setting[$k]['type_name'] = '试题'; $setting[$k]['name'] = $v['id']; $question_type = ExamQuestion::where('cate', '=', $v['id'])->group('type')->column('type'); $setting[$k]['child_type'] = implode('/', $question_type); $setting[$k]['child_count'] = ExamQuestion::where([['cate', '=', $v['id']], ['state', '=', 1]])->count(); $list[] = $setting[$k]; } } } } else { $list = []; } $start = ($page-1) * 10; $return_list = array_slice($list, $start, 10); return json(['code'=> 0, 'data'=> $return_list, 'count'=> count($list)]); } /** * 获取课程场景 */ public function getTrainType(){ $root_id = request()->employee->root_id; $find = DayStudySetting::where('root_id', '=', $root_id)->find(); if (empty($find)) { $setting = []; } else { $setting = json_decode($find['setting'], true); } $list = TrainType::where('root_id', '=', $root_id)->select()->each(function ($item) use ($setting){ $train_type = TrainCourse::where([['type_id', '=', $item['id']], ['delete_time', '=', 0]])->group('type')->column('type'); $type_list = [ 'video'=> '视频', 'image'=> '图文', 'audio'=> '音频' ]; $type_name = ''; foreach ($type_list as $k => $v) { if (in_array($k, $train_type)) { $type_name .= $v.'/'; } } $item['child_type'] = trim($type_name, '/'); $item['child_count'] = TrainCourse::where([['type_id', '=', $item['id']], ['delete_time', '=', 0]])->count(); $item['percent'] = 0; $item['selected'] = 0; if (!empty($setting)) { foreach ($setting as $kk => $vv) { if ($vv['type'] == 'train' && $vv['id'] == $item['id']) { $item['selected'] = 1; $item['percent'] = $vv['percent']; } } } }); return json(['code'=> 0, 'data'=> $list->toArray()]); } /** * 获取试题分类 */ public function getQuestionCate(){ $root_id = request()->employee->root_id; $cate = Setting::where([['name', '=', 'questioncate'],['root_id', '=', $root_id], ['state', '=', 1]])->find(); $find = DayStudySetting::where('root_id', '=', $root_id)->find(); if (empty($find)) { $setting = []; } else { $setting = json_decode($find['setting'], true); } $list = json_decode($cate['content'], true); $data = []; foreach ($list as $k => $v) { $question_type = ExamQuestion::where([['cate', '=', $v], ['state', '=', 1]])->group('type')->column('type'); $data[$k]['child_type'] = implode('/', $question_type); $data[$k]['child_count'] = ExamQuestion::where([['cate', '=', $v], ['state', '=', 1]])->count(); $data[$k]['percent'] = 0; $data[$k]['id'] = $v; $data[$k]['name'] = $v; $data[$k]['selected'] = 0; //是否已选 if (!empty($setting)) { foreach($setting as $kk => $vv){ if ($vv['type'] == 'question' && $vv['id'] == $v){ $data[$k]['selected'] = 1; $data[$k]['percent'] = $vv['percent']; } } } } return json(['code'=> 0, 'data'=> $data]); } }