123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637 |
- <?php
- namespace app\adminall\controller;
- use app\model\Miniprogram;
- use app\model\TrainClassAssign;
- use app\model\TrainClassView;
- use think\facade\Request;
- use think\facade\View;
- use think\facade\Db;
- use app\model\TrainClass;
- use app\model\TrainCourse;
- use app\model\TrainType;
- use app\model\TrainDoneLog;
- use app\model\TrainSumup;
- use app\model\Org;
- use app\logics\OrgLogic;
- use app\model\Employee;
- use app\event\Msg;
- use wx\miniprogram\Qrcode;
- use app\model\User;
- use app\model\Company;
- use app\model\TrainCourseView;
- use app\model\TrainClassCate;
- use app\model\CreditsSetting;
- use app\model\ActivityCollor;
- use app\model\Broadcast;
- use app\model\Lecturer as LecturerModel;
- use app\model\LecturerCompany;
- class Lecturer
- {
- private $root_id = 0;//总后台店面id默认0
- /**
- * 课件列表页面展示
- */
- public function course_index()
- {
- $type = LecturerCompany::where('1=1')->select()->toArray();
- View::assign('type', $type);
- return View::fetch();
- }
- /**
- * 课件列表
- */
- public function trainCourseList()
- {
- $param = request()->param();
- $condition[] = ['root_id', '=', $this->root_id];
- $condition[] = ['del', '=', 0];
- if (isset($param['keyword']) && !empty($param['keyword'])) $condition[] = ['name', 'like', '%' . $param['keyword'] . '%'];
- if (isset($param['company_id']) && !empty($param['company_id'])) $condition[] = ['lecturer_company_id', '=', $param['company_id']];
- $data = LecturerModel::with(['company'=>function($query){
- $query->bind(['company_name'=>'name']);
- }])->withCount(['train'])->where($condition)->page($param['page'], $param['limit'])->order('id desc')->select()->toArray();
- $count = LecturerModel::where($condition)->count();
- $ids = array_column($data,'id');
- //观看人次
- $view_count = TrainClass::where([['lecturer_id','in',$ids]])->group('lecturer_id')->column('sum(view)','lecturer_id');
- //收藏数量
- $collor_count = ActivityCollor::where([['aid','in',$ids],['type','=',2]])->group('aid')->column('count(id)','aid');
- //直播次数
- $train_broadcast_view = Broadcast::where([['lecturer_id','in',$ids]])->group('lecturer_id')->column('count(id)','lecturer_id');
- foreach ($data as $key => $value) {
- $data[$key]['train_view'] = isset($view_count[$value['id']]) ? $view_count[$value['id']] : 0;
- $data[$key]['train_collor_view'] = isset($collor_count[$value['id']]) ? $collor_count[$value['id']] : 0;
- $data[$key]['train_broadcast_view'] = isset($train_broadcast_view[$value['id']]) ? $train_broadcast_view[$value['id']] : 0;
- }
- return json(['code' => 0, 'data' => $data, 'count' => $count]);
- }
- /*
- * 课件场景列表
- */
- public function type_index()
- {
- if (!Request::isAjax()) {
- return View::fetch();
- }
- $param = request()->param();
- $condition = [
- 'root_id' => $this->root_id,
- 'from_type' => 0
- ];
- $data = TrainType::where($condition)->page($param['page'], $param['limit'])
- // ->order('train_course_count desc,id desc')
- ->order(['show'=>'asc','id'=>'desc'])
- ->select();
- $count = TrainType::where($condition)->count();
- return json(['code' => 0, 'data' => $data, 'count' => $count]);
- }
- /*
- * 课件场景添加
- */
- public function add_train_type()
- {
- $type = Request::param('type');
- if (empty($type)) return json(['code' => 1, 'msg' => '请输入场景名称']);
- $isAdd = TrainType::where(['type' => $type, 'root_id' => $this->root_id])->count();
- if ($isAdd > 0) return json(['code' => 1, 'msg' => '场景已存在']);
- $objId = TrainType::insertGetId(['type' => $type, 'root_id' => $this->root_id]);
- return json(['code' => 0, 'msg' => '添加成功', 'data' => ['id' => $objId, 'type' => $type]]);
- }
- /*
- * 场景删除
- */
- public function del_train_type()
- {
- $id = Request::param('id');
- $data = TrainType::where(['id' => $id, 'root_id' => $this->root_id])->find();
- if (!$data) return json(['code' => 1, 'msg' => '删除失败']);
- $other_id = TrainType::where(['root_id'=>$this->root_id , 'show'=>1])->value('id');
- if(empty($other_id)) $other_id = TrainType::insertGetId(['type'=>'其它','root_id'=>$this->root_id,'show'=>1]);
- TrainCourse::where(['root_id'=>$this->root_id , 'type_id'=>$id])->update(['type_id'=>$other_id]);
- $data->delete();
- return json(['code' => 0, 'msg' => '删除成功']);
- }
- /*
- * 课件场景修改
- */
- public function edit_train_type()
- {
- $id = Request::param('id');
- $type = Request::param('type');
- if (empty($type)) return json(['code' => 1, 'msg' => '请输入场景名称']);
- if (TrainType::where(['id' => $id, 'root_id' => $this->root_id])->update(['type' => $type])) {
- return json(['code' => 0, 'msg' => '修改成功']);
- } else {
- return json(['code' => 1, 'msg' => '修改失败']);
- }
- }
- /**
- * 课件添加页面
- */
- public function course_add()
- {
- $condition = [
- 'root_id' => $this->root_id,
- 'from_type' => 0
- ];
- $type = TrainType::where($condition)->select()->toArray();
- View::assign('type', $type);
- return View::fetch();
- }
- /*
- * 课件保存
- */
- public function courseAddSave()
- {
- $data = Request::only(['title', 'type_id', 'type', 'content', 'video_img', 'file_image', 'file_video', 'file_audio', 'file_pdf', 'time_check', 'word_check', 'study_time', 'comment_word_num']);
- if ($data['time_check'] == 0 && $data['word_check'] == 0) return json(['code' => 1, 'msg' => '完成条件最少选择一项']);
- $ask = input('content');
- $ask = str_replace(' ', '', $ask);
- if (trim($ask) == '' && $data['type'] != 'pdf') {
- return json(['code' => 1, 'msg' => '课件内容不能为空']);
- }
- $newData = [
- 'root_id' => $this->root_id,
- 'title' => $data['title'],
- 'type_id' => $data['type_id'],
- 'content' => $data['content'],
- 'type' => $data['type'],
- 'study_time' => $data['time_check'] == 0 ? 0 : $data['study_time'],
- 'comment_word_num' => $data['word_check'] == 0 ? 0 : $data['comment_word_num']
- ];
- if ($data['type'] == 'video') {
- if (empty($data['file_video'])) return json(['code' => 1, 'msg' => '请选择视频']);
- $arr = explode(',', $data['file_video']);
- $newData['file'] = end($arr);
- $newData['video_img'] = !empty($data['video_img']) ? $data['video_img'] : null;
- } elseif ($data['type'] == 'image') {
- if (empty($data['file_image'])) return json(['code' => 1, 'msg' => '请选择图片']);
- $newData['file'] = $data['file_image'];
- } elseif ($data['type'] == 'pdf') {
- if (empty($data['file_pdf'])) return json(['code' => 1, 'msg' => '请选择pdf课程文件']);
- $arr = explode(',', $data['file_pdf']);
- $newData['file'] = end($arr);
- } else {
- if (empty($data['file_audio'])) return json(['code' => 1, 'msg' => '请选择音频']);
- $arr = explode(',', $data['file_audio']);
- $newData['file'] = end($arr);
- }
- if (TrainCourse::insert($newData)) {
- return json(['code' => 0, 'msg' => '添加成功']);
- } else {
- return json(['code' => 1, 'msg' => '添加失败']);
- }
- }
- /**
- * 课件富文本文件上传
- */
- public function fileupload()
- {
- $ali_oss_bindurl = config('app.ali_oss_bindurl');
- $url = 'https://' . $ali_oss_bindurl . '/' . Request::param('file');
- return json(['code' => 0, 'data' => ['src' => $url]]);
- }
- /**
- * 讲师编辑页面
- */
- public function course_edit()
- {
- $id = Request::param('id');
- $data = LecturerModel::where(['id' => $id, 'root_id' => $this->root_id])->find();
- View::assign('data', $data);
- return View::fetch();
- }
- /**
- * 课件活动编辑保存
- */
- public function courseEditSave()
- {
- $data = Request::only(['title', 'type_id', 'type', 'content', 'video_img', 'file_image', 'file_audio', 'file_video', 'file_pdf', 'id', 'time_check', 'word_check', 'study_time', 'comment_word_num']);
- if ($data['time_check'] == 0 && $data['word_check'] == 0) return json(['code' => 1, 'msg' => '完成条件最少选择一项']);
- $ask = input('content');
- $ask = str_replace(' ', '', $ask);
- if (trim($ask) == '' && $data['type'] != 'pdf') {
- return json(['code' => 1, 'msg' => '课件内容不能为空']);
- }
- $newData = [
- 'root_id' => $this->root_id,
- 'title' => $data['title'],
- 'type_id' => $data['type_id'],
- 'content' => $data['content'],
- 'type' => $data['type'],
- 'study_time' => $data['time_check'] == 0 ? 0 : $data['study_time'],
- 'comment_word_num' => $data['word_check'] == 0 ? 0 : $data['comment_word_num']
- ];
- // 添加判断
- $course = TrainCourse::where(['root_id' => $this->root_id, 'id' => $data['id']])->find();
- if (empty($course)) return json(['code' => 1, 'msg' => '课件不存在']);
- // 判断是否更换类型,如果更换类型,则内容需要重新上传
- if ($course->type != $data['type'] && empty($data['file_' . $data['type']])) {
- $msgType = [
- 'video' => '视频',
- 'audio' => '音频',
- 'pdf' => 'pdf课程文件',
- 'image' => '图片',
- ];
- return json(['code' => 1, 'msg' => '请选择' . $msgType[$data['type']]]);
- }
- if (!empty($data['file_' . $data['type']])) {
- if ($data['type'] == 'image') {
- $newData['file'] = $data['file_image'];
- } else {
- $arr = explode(',', $data['file_' . $data['type']]);
- $newData['file'] = end($arr);
- if ('video' == $data['type'])
- $newData['video_img'] = !empty($data['video_img']) ? $data['video_img'] : null;
- }
- }
- $course->save($newData);
- // if ($data['type'] == 'video') {
- // if (empty($data['file_video'])) return json(['code' => 1, 'msg' => '请选择视频']);
- // $arr = explode(',', $data['file_video']);
- // $newData['file'] = end($arr);
- // $newData['video_img'] = !empty($data['video_img']) ? $data['video_img'] : null;
- // } elseif ($data['type'] == 'audio') {
- // if (empty($data['file_audio'])) return json(['code' => 1, 'msg' => '请选择音频']);
- // $arr = explode(',', $data['file_audio']);
- // $newData['file'] = end($arr);
- // } elseif ($data['type'] == 'pdf') {
- // if (empty($data['file_pdf'])) return json(['code' => 1, 'msg' => '请选择pdf课程文件']);
- // $arr = explode(',', $data['file_pdf']);
- // $newData['file'] = end($arr);
- // } else {
- // if (empty($data['file_image'])) return json(['code' => 1, 'msg' => '请选择图片']);
- // $newData['file'] = $data['file_image'];
- // }
- // TrainCourse::where(['root_id' => $this->root_id, 'id' => $data['id']])->update($newData);
- return json(['code' => 0, 'msg' => '修改成功']);
- }
- /**
- * 课件删除
- */
- public function del_course_train()
- {
- $id = Request::param('id');
- $where = [
- ['root_id','=',0],
- ['id','=',$id]
- ];
- LecturerModel::where($where)->update(['del'=>1]);
- return json(['code' => 0, 'msg' => '删除成功']);
- }
- /*
- * 课程培训
- * 新逻辑 区分指派前和指派后 以train_class表的train_employee字段区分,为空则为指派前阶段,有值为指派后阶段
- * 指派前阶段为自由学习阶段,所有人都可以看到课程并学习,指派后则为指派的人能学习
- * 量化考核中也要区分,指派前和指派后互相数据不关联
- */
- public function class_index()
- {
- if (!Request::isAjax()) {
- return View::fetch();
- }
- $param = request()->param();
- $condition[] = ['del', '=', 0];
- $condition[] = ['root_id', '=', $this->root_id];
- $condition[] = ['from_type', 'in', [0, 2]];
- if (isset($param['keyword'])) $condition[] = ['title', 'like', '%' . $param['keyword'] . '%'];
- if (isset($param['date'])) $condition[] = ['addtime', 'like', '%' . $param['date'] . '%'];
- $data = TrainClass::withCount(['doneLog' => function ($query, &$alias) {
- $query->where('done_percent', 100);
- $alias = 'completeCount';
- }])->withCount(['doneLog' => function ($query, &$alias) {
- $query->where([['done_percent', '<', 100], ['done_percent', '>', 0]]);
- $alias = 'noFinishCount';
- }])->where($condition)->page($param['page'], $param['limit'])->order('addtime desc')
- ->field('id,title,course_id,addtime,org_id,train_employee')->select()->toArray();
-
- $orgCount = Employee::where([['root_id', '=', $this->root_id], ['state', 'like', '%在职%'], ['org_id', '>', 0], ['uid', '>', 0]])->group('org_id')->column('count(org_id)', 'org_id');
-
- //总人数
- $total = Employee::where([['root_id','=',$this->root_id],['state','=','在职'],['uid','>',0]])->count();
- //课程总结
- $trainSummary = TrainSumup::where([['root_id', '=', $this->root_id], ['course_id', '=', 0]])->group('class_id,employee_id')->column('count(id),class_id');
- foreach ($data as &$v) {
- //培训人数
- $v['trainNumber'] = 0;
- if (!empty($orgCount) && !empty($v['org_id'])) {
- $trainArr = explode(',', $v['org_id']);
- foreach ($trainArr as $c) {
- isset($orgCount[$c]) ? $v['trainNumber'] += $orgCount[$c] : 0;
- }
- }
- //章节数
- $v['courseCount'] = empty($v['course_id']) ? 0 : count(explode(',', $v['course_id']));
- //指派人员
- $employee_id = explode(',', $v['train_employee']);
- $v['train_employee'] = count(array_filter(explode(',', $v['train_employee'])));
- //未开始人数
- $v['noStartCount'] = $v['train_employee'] - ($v['completeCount'] + $v['noFinishCount']);
- $v['noStartCount'] = $v['noStartCount'] >= 0 ? $v['noStartCount'] : 0;
- //完成观后感
- $v['summaryCount'] = isset($trainSummary[$v['id']]) ? $trainSummary[$v['id']] : 0;
- //新逻辑 区分指派前和指派后 ,这段删除就是之前的逻辑
- if ($v['train_employee']) {
- $v['trainNumber'] = $v['train_employee'];
- //指派后,完成人数
- $v['completeCount'] = TrainDoneLog::where([['class_id','=',$v['id']],['employee_id','in',$employee_id],['done_percent','=',100]])->count();
- $nofinish = TrainDoneLog::where([['class_id','=',$v['id']],['employee_id','in',$employee_id],['done_percent','in',[1,99]]])->count();
- //未完成人数
- $v['noFinishCount'] = count($employee_id) - $v['completeCount'];
- //未开始
- $v['noStartCount'] = count($employee_id) - $v['completeCount'] - $nofinish;
- //感悟数量
- $v['summaryCount'] = TrainSumup::where([['employee_id','in',$employee_id],['class_id','=', $v['id']], ['course_id', '=', 0]])->group('employee_id')->count();
- }else{
- //指派前,培训人数和学习人数都是所有人
- $v['trainNumber'] = $v['train_employee'] = $total;
- //未开始人数
- $v['noStartCount'] = $total - ($v['completeCount'] + $v['noFinishCount']);
- //未完成
- $v['noFinishCount'] = $total - $v['completeCount'];
- }
- }
- $count = TrainClass::where($condition)->count();
- return json(['code' => 0, 'data' => $data, 'count' => $count]);
- }
- /**
- * 分类管理
- */
- public function class_cate()
- {
- return View::fetch();
- }
- /**
- * 分类管理添加
- */
- public function class_cate_add()
- {
- $root_id = $this->root_id;
- $param = Request::only(['name' => '']);
- $param['name'] = str_replace(' ', '', $param['name']);
- $w[] = ['root_id', '=', 0];
- $w[] = ['name', '=', $param['name']];
- $find = LecturerCompany::where($w)->findOrEmpty();
- if (!$find->isEmpty()) return json(['code' => 1, 'data' => '分类已存在', 'msg' => '分类已存在']);
- $id = LecturerCompany::insertGetId(['root_id' => $root_id, 'name' => $param['name']]);
- return json(['code' => 0, 'data' => '添加成功', 'msg' => '添加成功', 'id' => $id]);
- }
- /**
- * 讲师所属企业列表
- */
- public function class_cate_list()
- {
- $root_id = 0;
- $param = Request::only(['page' => 1, 'limit' => 10,'keyword'=>'']);
- $w[] = ['root_id', '=', $root_id];
- if($param['keyword']) $w[] = ['name','like','%'.$param['keyword'].'%'];
- $list = LecturerCompany::where($w)->page($param['page'], $param['limit'])->order('id asc')->select();
- $count = LecturerCompany::where($w)->count();
- return json(['code' => 0, 'data' => $list, 'count' => $count]);
- }
- /**
- * 分类管理编辑
- */
- public function class_cate_edit()
- {
- $root_id = 0;
- $param = Request::only(['id' => 0, 'name' => '']);
- $w[] = ['root_id', '=', $root_id];
- $w[] = ['id', '<>', $param['id']];
- $w[] = ['name', '=', $param['name']];
- $find = LecturerCompany::where($w)->findOrEmpty();
- if(!$find->isEmpty()) return json(['code' => 1, 'data' => '企业已存在', 'msg' => '企业已存在']);
- $w1[] = ['root_id', '=', $root_id];
- $w1[] = ['id', '=', $param['id']];
- LecturerCompany::where($w1)->update(['name' => $param['name']]);
- return json(['code' => 0, 'data' => '修改成功', 'msg' => '修改成功']);
- }
- /**
- * 分类管理删除
- */
- public function class_cate_del()
- {
- $root_id = $this->root_id;
- $param = Request::only(['id' => 0]);
- $w[] = ['root_id', '=',0];
- $w[] = ['id', '=', $param['id']];
- $find = LecturerCompany::where($w)->delete();
- return json(['code' => 0, 'data' => '删除成功', 'msg' => '删除成功']);
- }
- /*
- * 删除标签或分类前,查询关联的内容数量
- */
- public function with_type_count()
- {
- $param = Request::param();
- if($param['type'] == 'cate')
- {
- $field = 'cate';
- }else{
- $field = 'label';
- }
- $where = [
- ['root_id','=',$this->root_id],
- ['del','=',0],
- [$field,'=',$param[$field]]
- ];
- $count = TrainClass::where($where)->count();
- if($count > 0)
- {
- $type = $field == 'cate' ? '分类' : '标签' ;
- $msg = '该'.$type.'关联'.$count.'个'.'课程,删除后该内容将归为其它分类。';
- }else{
- $msg = '确定删除该分类吗?';
- }
- return $msg;
- }
- /*
- * 分类、标签删除
- */
- public function class_cate_or_label_del()
- {
- $param = Request::param();
- $trainCate = TrainClassCate::where(['root_id'=>$this->root_id,'id'=>$param['id']])->find();
- if(empty($trainCate)) return json(['code' => 1, 'msg' => '数据不存在']);
- Db::startTrans();
- try {
- if($param['type'] == 'cate')
- {
- //查询是否存在其它分类
- $type_id = TrainClassCate::where(['root_id'=>$this->root_id,'pid'=>0,'show'=>1])->value('id');
- if(empty($type_id)) $type_id = TrainClassCate::insertGetId(['pid'=>0,'name'=>'其它','root_id'=>$this->root_id,'show'=>1]);
- //更新关联内容
- TrainClass::where(['root_id'=>$this->root_id,'cate'=>$trainCate['name']])->update(['cate'=>'其它']);
- TrainClassCate::where(['root_id'=>$this->root_id,'pid'=>$trainCate['id']])->update(['pid'=>$type_id]);
- //去重
- $groupId = TrainClassCate::where(['root_id'=>$this->root_id,'pid'=>$type_id,'show'=>1])->min('id');
- TrainClassCate::where([['root_id','=',$this->root_id],['pid','=',$type_id],['show','=',1],['id','<>',$groupId]])->delete();
- //删除分类
- $trainCate->delete();
- }else{
- $label_id = TrainClassCate::where(['root_id'=>$this->root_id,'pid'=>$trainCate['pid'],'show'=>1])->value('id');
- if(empty($label_id)) $label_id = TrainClassCate::insertGetId(['pid'=>$trainCate['pid'],'name'=>'其它','root_id'=>$this->root_id,'show'=>1]);
- //更新关联内容
- TrainClass::where(['root_id'=>$this->root_id,'label'=>$trainCate['name']])->update(['label'=>'其它']);
- //删除分类
- $trainCate->delete();
- }
- Db::commit();
- return json(['code' => 0, 'msg' => '删除成功']);
- } catch (\Exception $e) {
- Db::rollback();
- return json(['code' => 1, 'msg' => '删除失败']);
- }
- }
- /*
- * 课程培训添加页
- */
- public function class_add()
- {
- $w = [
- ['root_id', '=', $this->root_id]
- ];
- $type = LecturerCompany::where($w)->field('id,name')->select();
- View::assign('type', $type);
- return View::fetch();
- }
- /*
- * 讲师编辑页面
- */
- public function class_edit()
- {
- $id = input('id',0);
- $data = LecturerModel::where('id',$id)->find();
- View::assign('data', $data);
- $w = [
- ['root_id', '=', $this->root_id]
- ];
- $type = LecturerCompany::where($w)->field('id,name')->select();
- View::assign('type', $type);
- return View::fetch();
- }
- /**
- * 课件活动添加保存
- */
- public function classAddSave()
- {
- $data = Request::only(['name'=>'','lecturer_company_id'=>0,'speaker_type'=>'','position'=>'','introduce'=>'','photo'=>'','poster'=>'']);
- $data['root_id'] = $this->root_id;
- if(LecturerModel::insertGetId($data)){
- return json(['code' => 0, 'msg' => '添加成功']);
- }else{
- return json(['code' => 1, 'msg' => '添加失败']);
- };
- }
- /**
- * 课件活动添加保存
- */
- public function classEditSave()
- {
- $data = Request::only(['name'=>'','lecturer_company_id'=>0,'speaker_type'=>'','position'=>'','introduce'=>'','photo'=>'','poster'=>'']);
- $id = input('id',0);
- $info = LecturerModel::where([['root_id','=',0],['id','=',$id]])->findOrEmpty();
- if($info->isEmpty()) return json(['code' => 1, 'msg' => '编辑失败']);
- foreach ($data as $key => $value) {
- $info->$key = $value;
- }
- $info->save();
- return json(['code' => 0, 'msg' => '编辑成功']);
- }
- /*
- * 课程培训添加页面所需课件展示
- */
- public function class_choice_course()
- {
- $param = Request::only(['page'=>1,'limit'=>10,'keyword'=>'']);
- $type = TrainType::where(['root_id' => $this->root_id, 'from_type' => 0])->field('id,type,from_type')->select()->toArray();
- if (!Request::isAjax()) {
- $checkValId = request()->param('course_id');
- View::assign('type', $type);
- View::assign('course_id', isset($checkValId) ? $checkValId : '');
- return View::fetch();
- }
- $type_id = request()->param('type_id');
- $course_id = request()->param('course_id');
- $condition[] = ['root_id', '=', $this->root_id];
- if (isset($type_id) && !empty($type_id)) $condition[] = ['type_id', '=', $type_id];
- if (!empty($course_id)) {
- $arrId = explode(',', $course_id);
- $condition[] = ['id', 'not in', $arrId];
- }
- if($param['keyword']) $condition[] = ['title','like','%'.$param['keyword'].'%'];
- $data = TrainCourse::where($condition)->order('id desc')->page($param['page'],$param['limit'])->select();
- $count = TrainCourse::where($condition)->count();
- return json(['code' => 0, 'data' => $data,'count'=>$count]);
- }
- /*
- * 培训课程上下架
- */
- public function classPublish($id)
- {
- $obj = TrainClass::where(['id' => $id, 'root_id' => $this->root_id])->find();
- if (empty($obj)) return json(['code' => 1, 'msg' => '操作失败,数据不存在']);
- if (empty($obj['course_id']) && $obj->publish == 0) return json(['code' => 1, 'msg' => '请先绑定课件']);
- $obj->publish = $obj->publish == 1 ? 0 : 1;
- $obj->save();
- return json(['code' => 0, 'msg' => '操作成功']);
- }
- }
|