123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810 |
- <?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\Lecturer;
- class Train
- {
- private $root_id = 0;//总后台店面id默认0
- /**
- * 课件列表页面展示
- */
- public function course_index()
- {
- $condition = [
- 'root_id' => $this->root_id,
- 'from_type' => 0
- ];
- $type = TrainType::where($condition)->select()->toArray();
- View::assign('type', $type);
- return View::fetch();
- }
- /**
- * 课件列表
- */
- public function trainCourseList()
- {
- $param = request()->param();
- $condition[] = ['root_id', '=', $this->root_id];
- if (isset($param['type_id']) && !empty($param['type_id'])) $condition[] = ['type_id', '=', $param['type_id']];
- if (isset($param['keyword']) && !empty($param['keyword'])) $condition[] = ['title', 'like', '%' . $param['keyword'] . '%'];
- if (isset($param['type']) && !empty($param['type'])) $condition[] = ['type', '=', $param['type']];
- if (isset($param['date']) && !empty($param['date'])) $condition[] = ['date', 'like', '%' . $param['date'] . '%'];
- $data = TrainCourse::where($condition)->page($param['page'], $param['limit'])->order('id desc')->select();
- $count = TrainCourse::where($condition)->count();
- 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 = (new TrainCourse())->where(['id' => $id, 'root_id' => $this->root_id])->find();
- View::assign('type_id', $data->getData('type_id'));
- View::assign('data', $data);
- View::assign('old_file', $data->getData('file'));
- View::assign('old_video_img', $data->getData('video_img'));
- //$type = TrainType::where(['root_id' => $this->root_id, 'id' => $data->getData('type_id')])->field('id,type')->find();
- $condition = [
- 'root_id' => $this->root_id,
- 'from_type' => 0
- ];
- $type = TrainType::where($condition)->select()->toArray();
- View::assign('type', $type);
- 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');
- $course = TrainCourse::where(['id' => $id, 'root_id' => $this->root_id])->find();
- if (!$course) return json(['code' => 1, 'msg' => '删除失败,课件不存在']);
- Db::startTrans();
- try {
- //查询课程中使用该课件的数据
- $data = TrainClass::field('id,course_id,publish')->whereRaw("FIND_IN_SET(" . $id . " , course_id)")->where([['root_id', '=', $this->root_id], ['del', '=', 0]])->select()->toArray();
- $column_cid = array_column($data, 'id');
- $course->delete_time = time();
- $course->save();
- foreach ($data as $item) {
- //删除绑定该课件的课程,如果该课程全部删除课件则下架课程
- $newArr = array_diff(explode(',', $item['course_id']), explode(',', $id));
- $newArrs = implode(',', $newArr);
- $update = [
- 'course_id' => $newArrs,
- 'publish' => empty($newArrs) ? 0 : $item['publish']
- ];
- TrainClass::where('id', $item['id'])->update($update);
- //查询完成数据中有存在删除的课件
- $log = TrainDoneLog::where([['from', '=', 0], ['class_id', '=', $item['id']], ['root_id', '=', $this->root_id]])->whereRaw("FIND_IN_SET(" . $id . " , course_id)")->field('id,course_id,done_percent')->select();
- foreach ($log as $val) {
- $newsArr = array_diff(explode(',', $val['course_id']), explode(',', $id));
- $newLogArr = implode(',', $newsArr);
- $GDP = $this->GDP(count($newsArr), count($newArr));
- TrainDoneLog::where('id', $val['id'])->update(['course_id' => $newLogArr, 'done_percent' => $GDP]);
- }
- }
- Db::commit();
- return json(['code' => 0, 'msg' => '删除成功']);
- } catch (\Exception $e) {
- Db::rollback();
- return json(['code' => 1, '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', '=', $root_id];
- $w[] = ['name', '=', $param['name']];
- $find = TrainClassCate::where($w)->findOrEmpty();
- if (!$find->isEmpty()) return json(['code' => 1, 'data' => '分类已存在', 'msg' => '分类已存在']);
- $id = TrainClassCate::insertGetId(['root_id' => $root_id, 'name' => $param['name']]);
- return json(['code' => 0, 'data' => '添加成功', 'msg' => '添加成功', 'id' => $id]);
- }
- /**
- * 分类管理列表
- */
- public function class_cate_list()
- {
- $root_id = $this->root_id;
- $param = Request::only(['page' => 1, 'limit' => 10]);
- $w[] = ['root_id', '=', $root_id];
- $w[] = ['pid', '=', 0];
- $list = TrainClassCate::where($w)->page($param['page'], $param['limit'])->order(['show' => 'asc','order' => 'asc'])->select();
- $count = TrainClassCate::where($w)->count();
- return json(['code' => 0, 'data' => $list, 'count' => $count]);
- }
- /**
- * 分类管理编辑
- */
- public function class_cate_edit()
- {
- $root_id = $this->root_id;
- $param = Request::only(['id' => 0, 'name' => '']);
- $w[] = ['root_id', '=', $root_id];
- $w[] = ['id', '<>', $param['id']];
- $w[] = ['name', '=', $param['name']];
- $w[] = ['pid', '=', 0];
- $find = TrainClassCate::where($w)->findOrEmpty();
- if (!$find->isEmpty()) return json(['code' => 1, 'data' => '分类已存在', 'msg' => '分类已存在']);
- $name = TrainClassCate::where('id', $param['id'])->value('name');
- TrainClassCate::where('id', $param['id'])->update(['name' => $param['name']]);
- $w1[] = ['cate', '=', $name];
- $w1[] = ['root_id', '=', $root_id];
- TrainClass::where($w1)->update(['cate' => $param['name']]);
- 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],
- ['pid', '=', 0]
- ];
- $type = TrainClassCate::where($w)->field('id,name')->select();
- View::assign('type', $type);
- $lecturer = Lecturer::where([['root_id', '=', $this->root_id]])->column('id,name');
- View::assign('lecturer', $lecturer);
- return View::fetch();
- }
- /**
- * 课件活动添加保存
- */
- public function classAddSave()
- {
- $data = Request::only(['title','label'=>0, 'cate', 'des'=>'', 'type', 'category', 'cover', 'course_id', 'sumup_num', 'sumup_keyword', 'score_one', 'score_two', 'score_three', 'train_employee','credit'=>0,'lecturer_id'=>0]);
- $data['sumup_num'] = $data['sumup_num'] ? $data['sumup_num'] : 0;
- $data['cate'] = str_replace(' ','',$data['cate']);
- $data['label'] = str_replace(' ','',$data['label']);
- $newData = [
- 'root_id' => $this->root_id,
- 'title' => $data['title'],
- 'type' => $data['type'],
- 'category' => $data['category'],
- 'course_id' => $data['course_id'],
- 'des' => $data['des'],
- 'sumup_num' => $data['sumup_num'],
- 'sumup_keyword' => empty(array_filter(explode('|', trim($data['sumup_keyword'], '|')))) ? null : json_encode(array_values(array_filter(explode('|', trim($data['sumup_keyword'], '|'))))),
- 'sumup_score' => json_encode(['score_one' => $data['score_one'], 'score_two' => $data['score_two'], 'score_three' => $data['score_three']]),
- 'qrcode' => '',
- 'train_employee' => '',
- 'cate' => $data['cate'],
- 'label' => $data['label'],
- 'credit' => $data['credit'],
- 'lecturer_id' => $data['lecturer_id']
- ];
- if (!isset($data['cover']) && empty($data['cover'])) return json(['code' => 1, 'msg' => '请选择封面']);
- $newData['cover'] = $data['cover'];
- $id = TrainClass::insertGetid($newData);
- if ($id) {
- return json(['code' => 0, 'msg' => '添加成功']);
- } else {
- return json(['code' => 1, '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' => '操作成功']);
- }
- /*
- * 培训课程删除
- */
- public function classDel($id)
- {
- $obj = TrainClass::where(['id' => $id, 'root_id' => $this->root_id])->find();
- if (empty($obj)) return json(['code' => 1, 'msg' => '删除失败,数据不存在']);
- $obj->del = 1;
- $obj->save();
- return json(['code' => 0, 'msg' => '删除成功']);
- }
- /*
- * 课程观看感悟
- */
- public function class_comment()
- {
- if (!Request::isAjax()) {
- $class_id = Request::param('class_id');
- View::assign('class_id', $class_id);
- return View::fetch();
- }
- $param = Request::param();
- $condition[] = [
- ['root_id', '=', $this->root_id],
- ['class_id', '=', $param['class_id']],
- ['course_id', '=', 0]
- ];
- if (isset($param['keyword']) && !empty($param['keyword'])) $condition[] = ['content', 'like', '%' . $param['keyword'] . '%'];
- $data = TrainSumup::with(['employee'])->where($condition)->page($param['page'], $param['limit'])->order('addtime desc')->select();
- $count = TrainSumup::where($condition)->count();
- $class = TrainClass::where('id', $param['class_id'])->field('sumup_keyword,sumup_score')->find();
- foreach ($data as &$item) {
- $item['score'] = TrainSumup::sumup_score_num($class['sumup_keyword'], $class['sumup_score'], $item['content']);
- }
- return json(['code' => 0, 'data' => $data, 'count' => $count]);
- }
- /*
- * 课程培训修改页
- */
- public function class_edit()
- {
- //分类
- $w = [
- ['root_id', '=', $this->root_id],
- ['pid', '=', 0]
- ];
- $type = TrainClassCate::where($w)->field('id,name')->select();
- View::assign('type', $type);
- $lecturer = Lecturer::where([['root_id', '=', $this->root_id]])->column('id,name');
- View::assign('lecturer', $lecturer);
- $class_id = request()->param('class_id');
- $class = TrainClass::where(['id' => $class_id, 'root_id' => $this->root_id])->find();
- $class['sumup_keyword'] = empty($class['sumup_keyword']) ? '' : implode('|', json_decode($class['sumup_keyword'], true));
- $class['sumup_score'] = json_decode($class['sumup_score'], true);
- View::assign('class', $class);
- View::assign('cover', $class->getData('cover'));
- $course = TrainCourse::where('id', 'in', $class['course_id'])->select();
- View::assign('course', $course);
- //标签
- $w[] = ['name', '=', $class->cate];
- $pid = TrainClassCate::where($w)->value('id');
- $labels = TrainClassCate::where('pid', $pid)->select();
- View::assign('labels', $labels);
- return View::fetch();
- }
- /**
- * 课件活动编辑保存
- */
- public function classEditSave()
- {
- $data = Request::only(['title', 'cate', 'label'=>0, 'des'=>'', 'type', 'category', 'cover', 'course_id', 'id', 'sumup_num', 'sumup_keyword', 'score_one', 'score_two', 'score_three','credit'=>0,'lecturer_id'=>0]);
- $data['cate'] = str_replace(' ', '', $data['cate']);
- $data['label'] = str_replace(' ', '', $data['label']);
- $data['sumup_num'] = $data['sumup_num'] ? $data['sumup_num'] : 0;
- $newData = [
- 'title' => $data['title'],
- 'type' => $data['type'],
- 'category' => $data['category'],
- 'course_id' => $data['course_id'],
- 'des' => $data['des'],
- 'cover' => $data['cover'],
- 'sumup_num' => $data['sumup_num'],
- 'sumup_keyword' => empty(array_filter(explode('|', trim($data['sumup_keyword'], '|')))) ? null : json_encode(array_values(array_filter(explode('|', trim($data['sumup_keyword'], '|'))))),
- 'sumup_score' => json_encode(['score_one' => $data['score_one'], 'score_two' => $data['score_two'], 'score_three' => $data['score_three']]),
- 'cate' => $data['cate'],
- 'label' => $data['label'],
- 'credit' => $data['credit'],
- 'lecturer_id' => $data['lecturer_id']
- ];
- if (empty($newData['cover'])) return json(['code' => 1, 'msg' => '请选择封面']);
- $class = TrainClass::where(['root_id' => $this->root_id, 'id' => $data['id']])->find();
- $newData['publish'] = empty($data['course_id']) ? 0 : $class['publish'];
- $stringA = explode(',', $class['course_id']);
- $stringB = explode(',', $newData['course_id']);
- if (array_diff($stringA, $stringB) || array_diff($stringB, $stringA)) {
- //修改课程课件时同步更新员工完成的完成情况
- $log = TrainDoneLog::where(['root_id' => $this->root_id, 'class_id' => $data['id'], 'from' => 0])->select();
- foreach ($log as $item) {
- //员工之前完成的课件 , 修改后的课件
- $contrast = array_intersect(explode(',', $newData['course_id']), explode(',', $item['course_id']));
- $contrastImplode = implode(',', $contrast);
- $fload = $this->GDP(count($contrast), count(explode(',', $data['course_id'])));
- TrainDoneLog::where('id', $item['id'])->update(['course_id' => $contrastImplode, 'done_percent' => $fload]);
- }
- }
- if (TrainClass::where(['root_id' => $this->root_id, 'id' => $data['id']])->update($newData)) {
- return json(['code' => 0, 'msg' => '修改成功']);
- } else {
- return json(['code' => 1, 'msg' => '修改失败']);
- }
- }
- /**
- * 课件浏览记录
- */
- public function courese_view_list()
- {
- $param = Request::only(['course_id' => 0, 'org_id' => 0, 'page' => 1, 'limit' => 10]);
- $course_id = $param['course_id'];
- $org_id = $param['org_id'];
- // $root_id = request()->employee->root_id;
- if ($org_id) {
- $eids = Employee::where([['org_id', '=', $org_id]])->column('id');
- $w[] = ['employee_id', 'in', $eids];
- }
- // $w[] = ['root_id', '=', $root_id];
- $w[] = ['con_id', '=', $course_id];
- $w[] = ['type', '=', 'traincourse'];
- $list = TrainCourseView::with(['employee' => function ($query) {
- $query->visible(['name', 'id'])->bind(['name']);
- }])->where($w)->page($param['page'], $param['limit'])->select();
- foreach ($list as $k => $v) {
- $v->org_name = $v->employee->org->name;
- }
- $count = TrainCourseView::where($w)->count();
- return json(['code' => 0, 'data' => $list, 'count' => $count]);
- }
- /**
- * 课件浏览记录
- */
- public function courese_view($course_id = 0)
- {
- // $root_id = request()->employee->root_id;
- // $org = Org::where([['path', 'like', $root_id . '-%']])->field('name,id')->select()->toArray();
- $org = [];
- View::assign('org', $org);
- View::assign('course_id', $course_id);
- return View::fetch();
- }
- }
|