request()->employee->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', '=', request()->employee->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::withCount(['trainCourseView'=>function($query){ $query->where([['type', '=', '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 course_add() { $condition = [ 'root_id' => request()->employee->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' => request()->employee->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' => request()->employee->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' => request()->employee->root_id, 'id' => $data->getData('type_id')])->field('id,type')->find(); $condition = [ 'root_id' => request()->employee->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' => request()->employee->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' => request()->employee->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' => request()->employee->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' => request()->employee->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', '=', request()->employee->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', '=', request()->employee->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' => '删除失败']); } } /* * 课件场景列表 */ public function type_index() { if (!Request::isAjax()) { return View::fetch(); } $param = request()->param(); $condition = [ 'root_id' => request()->employee->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' => request()->employee->root_id])->count(); if ($isAdd > 0) return json(['code' => 1, 'msg' => '场景已存在']); $objId = TrainType::insertGetId(['type' => $type, 'root_id' => request()->employee->root_id]); return json(['code' => 0, 'msg' => '添加成功', 'data' => ['id' => $objId, 'type' => $type]]); } /* * 课件场景修改 */ 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' => request()->employee->root_id])->update(['type' => $type])) { return json(['code' => 0, 'msg' => '修改成功']); } else { return json(['code' => 1, 'msg' => '修改失败']); } } /* * 场景删除 */ public function del_train_type() { $id = Request::param('id'); $data = TrainType::where(['id' => $id, 'root_id' => request()->employee->root_id])->find(); if (!$data) return json(['code' => 1, 'msg' => '删除失败']); $other_id = TrainType::where(['root_id'=>request()->employee->root_id , 'show'=>1])->value('id'); if(empty($other_id)) $other_id = TrainType::insertGetId(['type'=>'其它','root_id'=>request()->employee->root_id,'show'=>1]); TrainCourse::where(['root_id'=>request()->employee->root_id , 'type_id'=>$id])->update(['type_id'=>$other_id]); $data->delete(); 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', '=', request()->employee->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', '=', request()->employee->root_id], ['state', 'like', '%在职%'], ['org_id', '>', 0], ['uid', '>', 0]])->group('org_id')->column('count(org_id)', 'org_id'); //总人数 $total = Employee::where([['root_id','=',request()->employee->root_id],['state','=','在职'],['uid','>',0]])->count(); //课程总结 $trainSummary = TrainSumup::where([['root_id', '=', request()->employee->root_id], ['course_id', '=', 0]])->group('class_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]])->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 qrcode($id) { $class = TrainClass::where(['id' => $id, 'root_id' => request()->employee->root_id])->field('qrcode')->find(); if (empty($class)) return json(['code' => 1, 'msg' => '课程信息不存在']); $qrcode = $class['qrcode']; if (empty($class['qrcode'])) { // 生成二维码 $mini = Miniprogram::where([['root_id', '=', request()->employee->root_id]])->find(); $qrObj = new Qrcode; $param = [ 'scene' => 'cli=' . $mini['notify'] . '&id=' . $class['id'] . '&t=tl', 'page' => 'pages/index/index', 'width' => '280px', ]; $qr = $qrObj->getUnlimited($mini->accesstoken, $param); $rs = json_decode($qr, true); if (!is_null($rs)) { return json(['code' => 1, 'msg' => '课程二维码生成失败']); } $path = 'trainClassQrcode/' . uniqid() . '.jpeg'; ossContentUpload($path, $qr); $class->qrcode = $path; $class->save(); $qrcode = 'https://' . config('app.ali_oss_bindurl') . '/' . $path; } return json(['code' => 0, 'msg' => '获取成功', 'qrcode' => $qrcode]); } /* * 完成画像列表 * 新逻辑 区分指派前和指派后 以train_class表的train_employee字段区分,为空则为指派前阶段,有值为指派后阶段 * 指派前阶段为自由学习阶段,所有人都可以看到课程并学习,指派后则为指派的人能学习 * 量化考核中也要区分,指派前和指派后互相数据不关联 * * 指派前未完成列表要把公司所有人都列出来 * 指派后只查询指派范围内的未学习和未完成人员 */ public function doneLog($page = 1, $limit = 10, $type, $class_id, $keyword = null) { if (!Request::isAjax()) { View::assign('type', $type); View::assign('class_id', $class_id); return View::fetch(); } //没有指派就把公司所有没学完的人 $train = TrainClass::where('id',$class_id)->field('id,train_employee')->findOrEmpty(); if($train->isEmpty()) return json(['code' => 1, 'data' => [], 'count' => 0]); //未指派 if (!$train->train_employee) { $condition = [ ['root_id', '=', request()->employee->root_id], ['class_id', '=', $class_id], ['from','=',0] ]; $finish = TrainDoneLog::where(array_merge([['done_percent', '=', 100]],$condition))->column('done_percent','employee_id'); $nofinish = TrainDoneLog::where(array_merge([['done_percent', 'between', [1,99]]],$condition))->column('done_percent','employee_id'); if ($type == 'complete') { //已完成 $where[] = ['id','in',array_keys($finish)]; } else { //未完成 $employee_id = Employee::where([['root_id','=',request()->employee->root_id],['state','=','在职'],['uid','>',0]])->column('id'); $employee = array_diff($employee_id,array_keys($finish)); $where[] = ['id','in',$employee]; } }else{ $employee_id = explode(',',$train->train_employee); //已指派 $condition = [ ['root_id', '=', request()->employee->root_id], ['class_id', '=', $class_id], ['from','=',0], ['employee_id','in',$employee_id] ]; $finish = TrainDoneLog::where(array_merge([['done_percent', '=', 100]],$condition))->column('done_percent','employee_id'); $nofinish = TrainDoneLog::where(array_merge([['done_percent', 'between', [1,99]]],$condition))->column('done_percent','employee_id'); if ($type == 'complete') { //已完成 $where[] = ['id','in',array_keys($finish)]; } else { //未完成 $employee = array_diff($employee_id,array_keys($finish)); $where[] = ['id','in',$employee]; } } if ($keyword) { $where[] = ['name','like','%'.$keyword.'%']; } $data = Employee::with(['user'])->where($where)->field('id,name,uid')->page($page, $limit)->select()->toArray(); $column_uid = array_column($data, 'uid'); $user = User::where('id', 'in', $column_uid)->column('headimgurl', 'id'); foreach ($data as &$val) { //头像 $val['headimgurl'] = isset($user[$val['uid']]) ? $user[$val['uid']] : ''; //进度 $val['done_percent'] = isset($finish[$val['id']]) ? $finish[$val['id']] : (isset($nofinish[$val['id']]) ? $nofinish[$val['id']] : '未学习'); } $count = Employee::where($where)->count(); return json(['code' => 0, 'data' => $data, 'count' => $count]); // $condition = [ // ['root_id', '=', request()->employee->root_id], // ['class_id', '=', $class_id] // ]; // if ($type == 'complete') { // $condition[] = [['done_percent', '=', 100]]; // } else { // $condition[] = [['done_percent', 'BETWEEN', [1, 99]]]; // } // if (!empty($keyword)) { // $employee_id = Employee::where([['root_id', '=', request()->employee->root_id], ['name', 'like', '%' . $keyword . '%']])->column('id'); // $condition[] = [['employee_id', 'in', $employee_id]]; // } // $condition[] = ['from', '=', 0]; // $data = TrainDoneLog::with(['employee'])->field('id,employee_id,done_percent')->where($condition)->page($page, $limit)->order('done_percent desc')->select()->toArray(); // $column_uid = array_column($data, 'uid'); // $user = User::where('id', 'in', $column_uid)->column('headimgurl', 'id'); // foreach ($data as &$val) { // $val['headimgurl'] = isset($user[$val['uid']]) ? $user[$val['uid']] : ''; // } // $count = TrainDoneLog::where($condition)->count(); // return json(['code' => 0, 'data' => $data, 'count' => $count]); } /* * 课程培训添加页 */ public function class_add() { $w = [ ['root_id', '=', request()->employee->root_id], ['pid', '=', 0] ]; $type = TrainClassCate::where($w)->field('id,name')->select(); View::assign('type', $type); return View::fetch(); } /* * 获取分类标签 */ public function get_label() { $param = Request::only(['id' => 0, 'name' => '']); if ($param['id']) { $w[] = ['pid', '=', $param['id']]; } else if ($param['name']) { $w1 = [ ['root_id', '=', request()->employee->root_id], ['name', '=', $param['name']] ]; $pid = TrainClassCate::where($w1)->value('id'); $w[] = ['pid', '=', $pid]; } else { return json(['code' => 0, 'data' => []]); } $w[] = ['root_id', '=', request()->employee->root_id]; $list = TrainClassCate::where($w)->field('id,name')->order('id desc')->select(); return json(['code' => 0, 'data' => $list]); } /* * 课程培训添加页面所需课件展示 */ public function class_choice_course() { $param = Request::only(['page'=>1,'limit'=>10,'keyword'=>'']); $type = TrainType::where(['root_id' => request()->employee->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', '=', request()->employee->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 class_edit() { //分类 $w = [ ['root_id', '=', request()->employee->root_id], ['pid', '=', 0] ]; $type = TrainClassCate::where($w)->field('id,name')->select(); View::assign('type', $type); $class_id = request()->param('class_id'); $class = TrainClass::where(['id' => $class_id, 'root_id' => request()->employee->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', 'des'=>'', 'type', 'category', 'cover', 'course_id', 'id', 'sumup_num', 'sumup_keyword', 'score_one', 'score_two', 'score_three','credit']); $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'] ]; if (empty($newData['cover'])) return json(['code' => 1, 'msg' => '请选择封面']); $class = TrainClass::where(['root_id' => request()->employee->root_id, 'id' => $data['id']])->find(); $newData['publish'] = empty($data['course_id']) ? 0 : $class['publish']; if (empty($class['qrcode'])) { // 生成二维码 $rootOrgId = request()->employee->root_id; $mini = Miniprogram::where([['root_id', '=', $rootOrgId]])->find(); $qrObj = new Qrcode; $param = [ 'scene' => 'cli=' . $mini['notify'] . '&id=' . $data['id'] . '&t=tl', 'page' => 'pages/index/index', 'width' => '280px', ]; $qr = $qrObj->getUnlimited($mini->accesstoken, $param); $rs = json_decode($qr, true); if (!is_null($rs)) { trace('课程二维码生成失败' . ';error:' . $qr, 'error'); } $path = 'trainClassQrcode/' . uniqid() . '.jpeg'; ossContentUpload($path, $qr); $newData['qrcode'] = $path; } $stringA = explode(',', $class['course_id']); $stringB = explode(',', $newData['course_id']); if (array_diff($stringA, $stringB) || array_diff($stringB, $stringA)) { //修改课程课件时同步更新员工完成的完成情况 $log = TrainDoneLog::where(['root_id' => request()->employee->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' => request()->employee->root_id, 'id' => $data['id']])->update($newData)) { return json(['code' => 0, 'msg' => '修改成功']); } else { return json(['code' => 1, 'msg' => '修改失败']); } } /** * 课件活动添加保存 */ public function classAddSave() { $data = Request::only(['title','label', 'cate', 'des'=>'', 'type', 'category', 'cover', 'course_id', 'sumup_num', 'sumup_keyword', 'score_one', 'score_two', 'score_three', 'train_employee','credit']); $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' => request()->employee->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'] ]; if (!isset($data['cover']) && empty($data['cover'])) return json(['code' => 1, 'msg' => '请选择封面']); $newData['cover'] = $data['cover']; $id = TrainClass::insertGetid($newData); if ($id) { // 生成二维码 $rootOrgId = request()->employee->root_id; $mini = Miniprogram::where([['root_id', '=', $rootOrgId]])->find(); $qrObj = new Qrcode; $param = [ 'scene' => 'cli=' . $mini['notify'] . '&id=' . $id . '&t=tl', 'page' => 'pages/index/index', 'width' => '280px', ]; $qr = $qrObj->getUnlimited($mini->accesstoken, $param); $rs = json_decode($qr, true); if (!is_null($rs)) { trace('课程二维码生成失败' . ';error:' . $qr, 'error'); } $path = 'trainClassQrcode/' . uniqid() . '.jpeg'; ossContentUpload($path, $qr); (new TrainClass())->update(['id' => $id, 'qrcode' => $path]); dataStatistics(request()->employee->root_id,'course_count',1,'inc');//manage应用首页统计数据 return json(['code' => 0, 'msg' => '添加成功']); } else { return json(['code' => 1, 'msg' => '添加失败']); } } /* * 培训课程删除 */ public function classDel($id) { $obj = TrainClass::where(['id' => $id, 'root_id' => request()->employee->root_id])->find(); if (empty($obj)) return json(['code' => 1, 'msg' => '删除失败,数据不存在']); $obj->del = 1; $obj->save(); dataStatistics(request()->employee->root_id,'course_count',1,'dec');//manage应用首页统计数据 return json(['code' => 0, 'msg' => '删除成功']); } /* * 培训课程上下架 */ public function classPublish($id) { $obj = TrainClass::where(['id' => $id, 'root_id' => request()->employee->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 class_assign() { if (!Request::isAjax()) { $id = Request::param('id'); View::assign('id', $id); return View::fetch(); } $id = Request::param('id'); $org = TrainClass::where(['root_id' => request()->employee->root_id, 'id' => $id])->value('org_id'); $datastr = OrgLogic::struc(request()->employee['root_id']); $datastr = json_decode($datastr, true); return json(['code' => 0, 'data' => $datastr, 'checkOrg' => $org]); } /* * 课程指派展示 */ public function class_assigns() { if (!Request::isAjax()) { $id = Request::param('id'); View::assign('id', $id); $info = TrainClass::where(['root_id' => request()->employee->root_id, 'id' => $id])->value('train_employee'); $count = $info ? count(explode(',', $info)) : 0; view::assign('count', $count); return View::fetch(); } $id = Request::param('id'); //课程id $pid = Request::param('pid'); //多选框选中id $type = Request::param('type'); //选中类型,人/部门 $res = Request::param('res'); //选择结果 1选中,0取消 $data = []; $info = TrainClass::where(['root_id' => request()->employee->root_id, 'id' => $id])->find(); $a = 0; if ($type == 'per' && $pid) { $data[] = 'per_' . $pid; $pid = [$pid]; $a = 1; } elseif ($type == 'org' && $pid) { $data[] = 'org_' . $pid; $org = Org::where([['id', '=', $pid]])->value('path'); $orgs = Org::where([['path', 'like', $org . '%']])->column('id'); $pid = Employee::where([['root_id', '=', request()->employee->root_id], ['org_id', 'in', $orgs], ['state', '=', '在职'], ['uid', '>', 0]])->order('is_manager desc,id desc')->column('id'); $a = 1; foreach ($pid as $v) { $data[] = 'per_' . $v; } foreach ($orgs as $v2) { $data[] = 'org_' . $v2; } } $train_employee = explode(',', $info['train_employee']); if ($a) { $arr = array_filter(array_diff($train_employee, $pid)); $arr = $res ? array_merge($pid, $arr) : $arr; $arr = array_unique($arr); //过滤运营人员,旧bug导致选择根部门时,运营人员也会在内 $arr = Employee::where([['id', 'in', $arr], ['uid', '>', 0], ['state', '=', '在职']])->column('id'); //查询指派人的组织 $employee_org = Employee::where('id', 'in', $arr)->group('org_id')->column('org_id'); $employee_org = implode(',', $employee_org); TrainClass::where(['root_id' => request()->employee->root_id, 'id' => $id])->update(['org_id' => $employee_org, 'train_employee' => implode(',', $arr)]); // 指派记录调整 $assign = TrainClassAssign::where([['root_id', '=', request()->employee->root_id], ['class_id', '=', $id]])->select(); foreach ($assign as $k => $v) { if (!in_array($v['id'], $arr)) { $v->delete(); } } $old_assign = array_column($assign->toArray(), 'employee_id'); $new_assign_emp = array_diff($arr, $old_assign); $new_assign = []; foreach ($new_assign_emp as $e) { $new_assign[] = [ 'class_id' => $id, 'employee_id' => $e, 'root_id' => request()->employee->root_id ]; if ($info['publish'] == 1){ event(new Msg($e, '你有新的课程被指派,请前往学习', 'trainClass', $id)); } } (new TrainClassAssign)->saveAll($new_assign); } return json(['code' => 0, 'data' => $data]); } /* * 课程指派展示列表 */ public function class_assigns_list() { $id = Request::param('id'); $page = Request::param('page') ?: 1; $limit = Request::param('limit') ?: 10; $keyword = Request::param('keyword') ?: ''; if ($keyword) { $w[] = ['name', 'like', '%' . $keyword . '%']; } $arr = TrainClass::where(['root_id' => request()->employee->root_id, 'id' => $id])->value('train_employee'); $arr = $arr ? explode(',', $arr) : []; $w[] = ['id', 'in', $arr]; $w[] = ['state', '=', '在职']; $w[] = ['uid', '>', 0]; $data = Employee::with('orgName')->where($w)->visible(['name', 'org_name', 'id', 'is_manager'])->select()->toArray(); $count = count($data); $arr = array_flip($arr); foreach ($data as $k => $v) { $data[$k]['order'] = $arr[$v['id']]; } array_multisort(array_column($data, 'order'), SORT_ASC, $data); foreach ($data as $k => $v) { $data[$k]['xh'] = $k + 1; } $data = array_slice($data, ($page - 1) * $limit, $limit); return json(['code' => 0, 'data' => $data, 'count' => $count]); } /* * 课程指派展示列表 */ public function del_assign() { $id = Request::param('id'); $eid = Request::param('eid'); if ($id && $eid) { if ($eid == -1) { TrainClass::where(['root_id' => request()->employee->root_id, 'id' => $id])->update(['train_employee' => '']); } else { $arr = TrainClass::where(['root_id' => request()->employee->root_id, 'id' => $id])->value('train_employee'); $arr = array_filter(array_diff(explode(',', $arr), [$eid])); TrainClass::where(['root_id' => request()->employee->root_id, 'id' => $id])->update(['train_employee' => implode(',', $arr)]); } } return json(['code' => 0, 'data' => '取消成功', 'msg' => '取消成功']); } /* * 课程指派入库 */ public function class_assign_edit() { $param = Request::param(['id', 'org']); $before = TrainClass::where(['root_id' => request()->employee->root_id, 'id' => $param['id']])->field('org_id,title')->find()->toArray(); if (TrainClass::where(['root_id' => request()->employee->root_id, 'id' => $param['id']])->update(['org_id' => $param['org']])) { $title = $before['title']; $before = $before['org_id']; //发送消息通知 $arr1 = $before ? explode(',', $before) : []; $arr2 = explode(',', $param['org']); $add = array_diff($arr1, $arr2); $reduce = array_diff($arr2, $arr1); if ($add) { $eids = Employee::where([['org_id', 'in', $add], ['state', '=', '在职']])->column('id'); foreach ($eids as $v1) { event(new Msg($v1, '您的培训“' . $title . '”已取消。', 'cancelTraining')); } } if ($reduce) { $eids = Employee::where([['org_id', 'in', $reduce], ['state', '=', '在职']])->column('id'); foreach ($eids as $v2) { event(new Msg($v2, '您有新的培训“' . $title . '”请及时参加。', 'courseTraining', $param['id'])); } } return json(['code' => 0, 'msg' => '保存成功']); } else { return json(['code' => 1, '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', '=', request()->employee->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]); } /* * 量化考核 * 新逻辑 区分指派前和指派后 以train_class表的train_employee字段区分,为空则为指派前阶段,有值为指派后阶段 * 指派前阶段为自由学习阶段,所有人都可以看到课程并学习,指派后则为指派的人能学习 * 量化考核中也要区分,指派前和指派后互相数据不关联 * * 调整部门逻辑, 部门调整后学习和感悟跟着走,人在那个部门内数据就属于那个部门 * */ public function class_org_data() { $class_id = request()->param('class_id'); $root_id = request()->employee->root_id; $info = TrainClass::where(['root_id' => $root_id, 'id' => $class_id])->find(); // $org_id = TrainClass::where(['root_id' => $root_id, 'id' => $class_id])->value('org_id'); // //指派前所有部门,指派后指派的部门 // $org_id = $org_id ? explode(',', $org_id) : Org::where([['path', 'like', request()->employee->root_id . '-%']])->column('id'); //有切换部门情况 $org_id = $info->train_employee ? Employee::where([['id','in',explode(',',$info->train_employee)]])->group('org_id')->column('org_id') : Org::where([['path', 'like', request()->employee->root_id . '-%']])->column('id'); if (!Request::isAjax()) { //trainNumber 培训人数,指派部门的所有人数,completeCount 完成进度为100 的人数,summaryCount课程感悟人次 $data = request()->param(['trainNumber', 'completeCount', 'summaryCount']); // $data['trainNumber'] = count(array_filter(explode(',',$info->train_employee))); $data['studyGDP'] = $this->GDP($data['completeCount'], $data['trainNumber']); $data['summaryGDP'] = $this->GDP($data['summaryCount'], $data['completeCount']); $data['earnestGDP'] = $this->GDP($data['summaryCount'], $data['trainNumber']); $org = Org::where('id', 'in', $org_id)->field('id,name')->select()->toArray(); $orgNum = Employee::where([['root_id', '=', $root_id],['uid','>',0], ['state', '=', '在职'], ['org_id', '>', 0]])->group('org_id')->column('count(org_id)', 'org_id'); // // $sumup = TrainSumup::where([['root_id', '=', $root_id], ['class_id', '=', $class_id]])->group(['org_id', 'employee_id'])->column('count(org_id)', 'org_id'); $sumup = TrainSumup::where([['root_id', '=', $root_id], ['class_id', '=', $class_id]])->group('employee_id')->column('employee_id'); $sumup = Employee::where([['id','in',$sumup]])->group('org_id')->column('count(org_id)', 'org_id'); foreach ($org as &$item) { $employeeNum = isset($orgNum[$item['id']]) ? $orgNum[$item['id']] : 0; $writeSummary = isset($sumup[$item['id']]) ? $sumup[$item['id']] : 0; $item['summaryDGP'] = $this->GDP($writeSummary, $employeeNum); } $last_data = array_column($org, 'summaryDGP'); array_multisort($last_data, SORT_DESC, $org); $data['max_org'] = empty($org) || $org[0]['summaryDGP'] == 0 ? '暂无数据' : $org[0]['name']; array_multisort($last_data, SORT_ASC, $org); $data['min_org'] = empty($org) || $org[0]['summaryDGP'] == 0 ? '暂无数据' : $org[0]['name']; View::assign('data', $data); View::assign('org', $org); View::assign('class_id', $class_id); return View::fetch(); } $info = TrainClass::where(['root_id' => $root_id, 'id' => $class_id])->find(); // $train_employee = []; //指派的员工 // if (!empty($info->train_employee)){ // $train_employee = explode(',', $info->train_employee); // } // 已学习的员工。 如果没指派员工则需要用已学习的员工去统计,合并数组是因为可能存在先是未指派,后面又指派的情况 // $learned_employee = TrainDoneLog::where([['root_id', '=', $root_id], ['class_id', '=', $class_id]])->column('employee_id'); // $all_employee = array_values(array_filter(array_unique(array_merge($train_employee, $learned_employee)))); $param = Request::param(['org_id'=>0, 'study_state', 'view_state']); $where = $query = []; if($info->train_employee) $where[] = $query[] = ['id','in',explode(',',$info->train_employee)]; if($param['org_id']) $where[] = ['org_id','=',$param['org_id']]; $org_id = Employee::where([['state','=','在职'],['uid','>',0],['root_id','=',$root_id]])->where($where)->group('org_id')->column('org_id'); $orgCondition[] = ['id', 'in', $org_id]; // if (!empty($param['org_id'])) { // $orgCondition[] = ['id', '=', $param['org_id']]; // } $org = Org::where($orgCondition)->field('id,name')->select(); $orgCount = Employee::where([['root_id', '=', $root_id], ['state', 'like', '%在职%'], ['org_id', '>', 0], ['uid', '>', 0]])->where($query)->group('org_id')->column('count(id)', 'org_id'); //已学完 //$class_success = TrainDoneLog::where(['from' => 0, 'root_id' => $root_id, 'class_id' => $class_id, 'done_percent' => 100])->group('org_id')->column('count(employee_id)', 'org_id'); $class_success_employee = TrainDoneLog::where(['from' => 0, 'root_id' => $root_id, 'class_id' => $class_id, 'done_percent' => 100])->column('employee_id'); $class_success = Employee::where('id', 'in', $class_success_employee)->group('org_id')->column('count(id)', 'org_id'); //未学完 //$class_no_success = TrainDoneLog::where([['from', '=', 0], ['root_id', '=', $root_id], ['class_id', '=', $class_id], ['done_percent', '<', 100]])->group('org_id')->column('count(employee_id)', 'org_id'); $class_no_success_employee = TrainDoneLog::where([['from', '=', 0], ['root_id', '=', $root_id], ['class_id', '=', $class_id], ['done_percent', '<', 100]])->column('employee_id'); $class_no_success = Employee::where('id', 'in', $class_no_success_employee)->group('org_id')->column('count(id)', 'org_id'); //感悟 $sumup_org_employee = TrainSumup::where([['root_id', '=', $root_id], ['class_id', '=', $class_id], ['course_id', '=', 0]])->group('employee_id')->column('employee_id'); $sumup_org = Employee::where('id', 'in', $sumup_org_employee)->field('id,org_id')->select(); $sumup_org_id = []; foreach ($sumup_org as $k => $v){ $sumup_org_id[$v['org_id']][] = $v['id']; } $sumup = []; foreach ($sumup_org_id as $k => $v) { $sumup[$k] = TrainSumup::where([['employee_id', 'in', $v], ['class_id', '=', $class_id], ['course_id', '=', 0]])->group('employee_id')->count(); } foreach ($org as &$item) { //学习人数 $item['trainNumber'] = isset($orgCount[$item['id']]) ? $orgCount[$item['id']] : 0; //已学完 $item['completeCount'] = isset($class_success[$item['id']]) ? $class_success[$item['id']] : 0; //未学完 $item['noFinishCount'] = isset($class_no_success[$item['id']]) ? $class_no_success[$item['id']] : 0; //写观后感 $item['summaryCount'] = isset($sumup[$item['id']]) ? $sumup[$item['id']] : 0; //学习完成率 $item['studyDGP'] = $this->GDP($item['completeCount'], $item['trainNumber']); //观看感完成率 $item['summaryCountDGP'] = $this->GDP($item['summaryCount'], $item['completeCount']); //认真完成率 $item['earnestDGP'] = $this->GDP($item['summaryCount'], $item['trainNumber']); } $data = $org; $count = $org->count(); return json(['code' => 0, 'data' => $data, 'count' => $count]); } /* * 计算率;根据两个数计算 */ private function GDP($data1, $data2) { if (empty($data1) || empty($data2)) { return 0; } else { return floor(($data1 / $data2) * 100) > 100 ? 100 : floor(($data1 / $data2) * 100); } } /** * 量化考核员工学习情况 */ public function class_employee_data() { $param = Request::param(['org_id']); $class_id = request()->param('class_id'); $dataurl = request()->param(['trainNumber', 'completeCount', 'summaryCount']); $from = input('from', '', 'trim'); if ($from) { $where1[] = ['from_content_id', '=', $class_id]; $where1[] = ['root_id', '=', orgRootId($param['org_id'])]; $class_id = TrainClass::where($where1)->value('id'); } $info = TrainClass::where('id',$class_id)->find(); $employee_id = $info->train_employee ? explode(',',$info->train_employee) : []; if ($employee_id) $where[] = ['id','in',$employee_id]; $where[] = ['org_id', '=', $param['org_id']]; $where[] = ['state', '=', '在职']; $where[] = ['uid', '>', 0]; $employee = Employee::where($where)->select(); if (!Request::isAjax()) { $data['employeeCount'] = $employee->count(); $data['completeCount'] = TrainDoneLog::where(['from' => 0, 'class_id' => $class_id, 'done_percent' => 100])->where([['employee_id','in',array_column($employee->toArray(),'id')]])->count(); $data['summaryCount'] = TrainSumup::where([['class_id', '=', $class_id], ['course_id', '=', 0], ['employee_id', 'in', array_column($employee->toArray(),'id')]])->group('employee_id')->count(); View::assign('class_id', $class_id); View::assign('org_id', $param['org_id']); View::assign('data', $data); View::assign('dataurl', $dataurl); return View::fetch(); } $org_name = Org::where('id', '=', $param['org_id'])->value('name'); foreach ($employee as $k => $v) { $employee[$k]['org_name'] = $org_name; $employee[$k]['done_percent'] = TrainDoneLog::where(['from' => 0, 'class_id' => $class_id, 'employee_id' => $v['id']])->value('done_percent'); $employee[$k]['summary'] = TrainSumup::where([['class_id', '=', $class_id], ['course_id', '=', 0], ['employee_id', '=', $v['id']]])->value('content'); } $count = $employee->count(); return json(['code' => 0, 'data' => $employee->toArray(), 'count' => $count]); } //部门人员树 public function tree($data, $pid = 0, $persons) { $new_arr = []; foreach ($data as $k => $v) { if ($v['pid'] == $pid) { $persions = isset($persons[$v['id']]) ? $persons[$v['id']] : []; $children = $this->tree($data, $v['id'], $persons); $v['children'] = array_merge_recursive($children, $persions); if (empty($v['children'])) $v['disabled'] = true; $new_arr[] = $v; } } return $new_arr; } /* * 培训人员 */ public function get_person($id) { $ids = input('id', ''); $root_id = request()->employee->root_id; $keyword = input('keyword', ''); //所有员工 $w1[] = ['root_id', '=', $root_id]; $w1[] = ['state', '=', '在职']; $w1[] = ['org_id', '>', 0]; $w1[] = ['uid', '>', 0]; if ($keyword) { $w1[] = ['name', 'like', '%' . $keyword . '%']; } $employee = Employee::where($w1)->field('id,name title,org_id,is_manager')->order('is_manager desc,id desc')->select()->toArray(); if ($ids) { $ids = explode(',', $ids); foreach ($employee as $k => &$v) { $v['selected'] = in_array($v['id'], $ids); $v['children'] = []; $v['title'] = $v['is_manager'] ? $v['title'] . '(负责人)' : $v['title']; $v['org_class'] = 'org_' . $v['org_id']; $v['per_class'] = 'per_' . $v['id']; $v['type'] = 'per'; } } else { foreach ($employee as $k => &$v) { $v['selected'] = false; $v['children'] = []; $v['all_count'] = 0; $v['title'] = $v['is_manager'] ? $v['title'] . '(负责人)' : $v['title']; $v['org_class'] = 'org_' . $v['org_id']; $v['per_class'] = 'per_' . $v['id']; $v['type'] = 'per'; } } $persons = []; foreach ($employee as $k => $v1) { $persons[$v1['org_id']][] = $v1; } $where = [ ['path', 'like', $root_id . '-%'], ['status', '=', 1] ]; $count = Employee::where([['root_id', '=', $root_id], ['state', '=', '在职'], ['uid', '>', 0]])->group('org_id')->column('count(*) count', 'org_id'); $allnodes = Org::where($where)->field('id,pid,name title,level,org_type,info,path')->order('level asc, id asc')->select()->toArray(); foreach ($allnodes as $k => $v) { $allnodes[$k]['count'] = isset($count[$v['id']]) ? $count[$v['id']] : 0; //本部门人数 $allnodes[$k]['all_count'] = 0; //包含子部门总数 $allnodes[$k]['org_class'] = 'org_' . $v['id']; $allnodes[$k]['per_class'] = 'per_org_' . $v['id']; $allnodes[$k]['type'] = 'org'; foreach ($allnodes as $k2 => $v2) { if (strpos($v2['path'], $v['path']) !== false) { $allnodes[$k]['all_count'] = isset($count[$v2['id']]) ? $count[$v2['id']] + $allnodes[$k]['all_count'] : $allnodes[$k]['all_count']; } } $allnodes[$k]['title'] = $allnodes[$k]['title'] . ' (' . $allnodes[$k]['all_count'] . ')'; } $tree = $this->tree($allnodes, 0, $persons); $info = TrainClass::where(['root_id' => request()->employee->root_id, 'id' => $id])->value('train_employee'); return json(['code' => 0, 'data' => $tree, 'checkOrg' => $info]); } /***************** 集团课程板块列表 *****************/ /* * 集团后台课程自建 */ public function groupClassList() { $param = request()->param(); if (!Request::isAjax()) { View::assign('from', isset($param['from']) ? 'share' : 'add'); View::assign('root_id', isset($param['root_id']) ? $param['root_id'] : ''); View::assign('company_group', isset($param['company_group']) ? $param['company_group'] : ''); return View::fetch(); } $condition = [ ['del', '=', 0], ['from_type', '=', 0], ['root_id', '=', request()->employee->root_id] ]; if (isset($param['keyword'])) $condition[] = ['title', 'like', '%' . $param['keyword'] . '%']; $data = TrainClass::where($condition)->field('id,title,course_id,addtime')->page($param['page'], $param['limit'])->order('addtime desc')->select()->toArray(); $class_id = array_column($data, 'id'); $shareCompany = TrainClass::where([['from_content_id', 'in', $class_id], ['from_type', '=', 1]])->group('from_content_id')->column('count(id)', 'from_content_id'); foreach ($data as &$v) { //培训人数 $from_content_id = TrainClass::where('from_content_id', $v['id'])->column('root_id'); $v['trainNumber'] = Employee::where([['root_id', 'in', $from_content_id], ['state', 'like', '%在职%'], ['uid', '>', 0]])->count(); //已完成人数 $from_class_id = TrainClass::where('from_content_id', $v['id'])->column('id'); $v['completeCount'] = TrainDoneLog::where([['from', '=', 0], ['root_id', 'in', $from_content_id], ['class_id', 'in', $from_class_id], ['done_percent', '=', 100]])->count(); //未完成人数 $v['noFinishCount'] = TrainDoneLog::where([['from', '=', 0], ['root_id', 'in', $from_content_id], ['class_id', 'in', $from_class_id], ['done_percent', '<', 100], ['done_percent', '>', 0]])->count(); //章节数 $v['courseCount'] = empty($v['course_id']) ? 0 : count(explode(',', $v['course_id'])); //完成观看感 $v['summaryCount'] = TrainSumup::where([['root_id', 'in', $from_content_id], ['class_id', 'in', $from_class_id], ['course_id', '=', 0]])->count(); //未开始人数 $v['noStartCount'] = $v['trainNumber'] - ($v['completeCount'] + $v['noFinishCount']); $v['noStartCount'] = $v['noStartCount'] >= 0 ? $v['noStartCount'] : 0; $v['shareCompany'] = isset($shareCompany[$v['id']]) ? $shareCompany[$v['id']] : 0; } $count = TrainClass::where($condition)->count(); return json(['code' => 0, 'data' => $data, 'count' => $count]); } /* * 集团指派完成画像列表 */ public function groupDoneLog($page = 1, $limit = 10, $type, $class_id, $keyword = null, $company_name_id = 0) { if (!Request::isAjax()) { View::assign('type', $type); View::assign('class_id', $class_id); $data = TrainClass::with(['company'])->where('from_content_id', $class_id)->select(); View::assign('data', $data); return View::fetch(); } $classid = TrainClass::with(['company'])->where('from_content_id', $class_id)->column('id'); $condition = [ ['class_id', 'in', $classid], ]; if (empty($company_name_id)) { $company = TrainClass::with(['company'])->where('from_content_id', $class_id)->column('root_id'); $condition[] = ['root_id', 'in', $company]; } else { $condition[] = ['root_id', '=', $company_name_id]; } if ($type == 'complete') { $condition[] = ['done_percent', '=', 100]; } else { $condition[] = ['done_percent', 'BETWEEN', [1, 99]]; } if (!empty($keyword)) { $where = [['name', 'like', '%' . $keyword . '%']]; if (empty($company_name_id)) { $where[] = ['root_id', 'in', $company]; } else { $where[] = ['root_id', '=', $company_name_id]; } $employee_id = Employee::where($where)->column('id'); $condition[] = ['employee_id', 'in', $employee_id]; } $condition[] = ['from', '=', 0]; $data = TrainDoneLog::with(['employee'])->field('id,employee_id,done_percent')->where($condition)->page($page, $limit)->order('done_percent desc')->select()->toArray(); $column_uid = array_column($data, 'uid'); $user = User::where('id', 'in', $column_uid)->column('headimgurl', 'id'); foreach ($data as &$val) { $val['headimgurl'] = isset($user[$val['uid']]) ? $user[$val['uid']] : ''; } $count = TrainDoneLog::where($condition)->count(); return json(['code' => 0, 'data' => $data, 'count' => $count]); } /* * 集团后台课程自建 */ public function groupCompanyClassList() { $param = request()->param(); if (!Request::isAjax()) { View::assign('from', isset($param['from']) ? 'share' : 'add'); View::assign('root_id', isset($param['root_id']) ? $param['root_id'] : ''); View::assign('company_group', isset($param['company_group']) ? $param['company_group'] : ''); return View::fetch(); } $condition = [ ['del', '=', 0], ['from_type', '=', 0] ]; if ($param['from'] == 'share') { $fromRootId = Company::where('id', $param['company_group'])->value('root_id'); if ($fromRootId !== request()->employee->root_id) return json(['code' => 0, 'msg' => '未找到店面信息']); $condition[] = ['root_id', '=', $param['root_id']]; } else { $condition[] = ['root_id', '=', request()->employee->root_id]; } if (isset($param['keyword'])) $condition[] = ['title', 'like', '%' . $param['keyword'] . '%']; $data = TrainClass::where($condition)->field('id,title,course_id,addtime,org_id')->page($param['page'], $param['limit'])->order('addtime desc')->select()->toArray(); //获取课程id $class_id = array_column($data, 'id'); $shareCompany = TrainClass::where([['from_content_id', 'in', $class_id], ['from_type', 'in', [1, 2]]])->group('from_content_id')->column('count(id)', 'from_content_id'); foreach ($data as &$v) { //章节数 $v['courseCount'] = empty($v['course_id']) ? 0 : count(explode(',', $v['course_id'])); $v['shareCompany'] = isset($shareCompany[$v['id']]) ? $shareCompany[$v['id']] : 0; } $count = TrainClass::where($condition)->count(); return json(['code' => 0, 'data' => $data, 'count' => $count]); } /* * 集团课件场景列表 */ public function groupType() { if (!Request::isAjax()) { return View::fetch(); } $param = request()->param(); $condition[] = ['root_id', '=', request()->employee->root_id]; $data = TrainType::withCount(['trainCourse' => function ($query) { $query->where(['root_id' => request()->employee->root_id, 'delete_time' => 0]); }])->withMax(['trainCourse' => function ($query) { $query->where(['root_id' => request()->employee->root_id, 'delete_time' => 0]); }], 'addtime')->where($condition)->page($param['page'], $param['limit'])->order('train_course_count desc')->select(); $count = TrainType::where($condition)->count(); return json(['code' => 0, 'data' => $data, 'count' => $count]); } /* * 共享的店面 */ public function groupShareCompany() { if (!Request::isAjax()) { $id = request()->param('id'); $form = request()->param('form'); view::assign('id', $id); view::assign('form', $form); return View::fetch(); } $id = request()->param('id'); $page = input('page', 1); $limit = input('limit', 10); $data = TrainClass::with(['company'])->where('from_content_id', $id)->page($page, $limit)->select(); $count = TrainClass::with(['company'])->where('from_content_id', $id)->count(); return json(['code' => 0, 'data' => $data, 'count' => $count]); } /* * 集团后台课程店面共享 */ public function groupCompanyClass() { if (!Request::isAjax()) { return View::fetch(); } $param = Request::param(); //查询店面 $companyId = Company::where('root_id', request()->employee->root_id)->value('id'); $data = Company::where('company_group', $companyId)->field('root_id,company_name,company_group')->page($param['page'], $param['limit'])->select()->toArray(); $count = Company::where('company_group', $companyId)->count(); //内容 $root_id = array_column($data, 'root_id'); $train = TrainClass::where([['root_id', 'in', $root_id], ['del', '=', 0], ['from_type', '=', 0]])->group('root_id')->column('count(id)', 'root_id'); foreach ($data as &$v) { $v['count'] = isset($train[$v['root_id']]) ? $train[$v['root_id']] : 0; } return json(['code' => 0, 'data' => $data, 'count' => $count]); } /* * 指派 */ public function group_assign() { $param = request()->param(); if (!Request::isAjax()) { View::assign('id', $param['id']); View::assign('from', $param['from']); View::assign('root_id', $param['root_id']); return View::fetch(); } //查询店面 $page = input('page', 1); $limit = input('limit', 10); $id = input('id', 0); //课程id $from = input('from'); //add指派, share共享 $class = TrainClass::where('id', $id)->find(); $companyId = Company::where('root_id', request()->employee->root_id)->value('id'); $tw = [['company_group', '=', $companyId]]; if ($from == 'share') { //排除自己共享给自己的课程 $tw[] = ['root_id', '<>', $class->root_id]; } $data = Company::where($tw)->field('root_id,company_name')->page($page, $limit)->select(); $count = Company::where($tw)->count(); return json(['code' => 0, 'data' => $data, 'count' => $count]); } /* * 批量指派共享 */ public function all_train_assign() { $root_id = request()->employee->root_id; $root_ids = input('ids', ''); //指派/贡献店面id $id = input('id', 0); //课程id $from = input('from', ''); //指派 $eq = ($from == 'add') ? '=' : '<>'; $w[] = ['root_id', $eq, $root_id]; $w[] = ['id', '=', $id]; $w[] = ['from_type', '=', 0]; //来源类型,0自建/1集团/2其它店面 $w[] = ['from_root_id', '=', 0]; //0为自建/其它店面 $w[] = ['from_content_id', '=', 0]; //0为自建/内容id $class = TrainClass::where($w)->find(); if (!$class) return json(['code' => 1, 'msg' => '课程不存在']); $root_ids = explode(',', $root_ids); if ($from == 'share') $root_ids = array_diff($root_ids, [$class->root_id]); //排除自己的课程指派给自己 //排除重复指派共享 foreach ($root_ids as $k => $v) { $w = []; $w[] = ['root_id', '=', $v]; $w[] = ['from_content_id', '=', $id]; $check = TrainClass::where($w)->find(); if ($check) unset($root_ids[$k]); } if (empty($root_ids)) return json(['code' => 1, 'msg' => '重复操作']); $course = TrainCourse::where('id', 'in', explode(',', $class['course_id']))->column('*'); //指派 Db::startTrans(); try { $trainNewCourseId = []; $from = $from == 'add' ? 1 : 2; //课件数据 foreach ($course as $val) { $type = TrainType::where('id', $val['type_id'])->find(); $save_courses = $save_type = []; foreach ($root_ids as $v) { //场景 $save = []; $save['from_type'] = $from; $save['from_root_id'] = $type['root_id']; $save['type'] = $type['type']; $save['root_id'] = $v; $check = TrainType::where($save)->find(); if ($check) { $newTypeId = $check->id; } else { $newTypeId = TrainType::insertGetId($save); } //课件 $save = []; $save['root_id'] = $v; $save['title'] = $val['title']; $save['type'] = $val['type']; $save['content'] = $val['content']; $save['type_id'] = $newTypeId; $save['file'] = $val['file']; $save['study_time'] = $val['study_time']; $save['comment_word_num'] = $val['comment_word_num']; $trainNewCourseId[$v][] = TrainCourse::insertGetId($save); } } foreach ($root_ids as $v2) { //课程数据 $classNewData = []; $classNewData = [ 'root_id' => $v2, 'title' => $class['title'], 'des' => $class['des'], 'cover' => $class->getData('cover'), 'publish' => 1, 'type' => $class['type'], 'course_id' => implode(',', $trainNewCourseId[$v2]), 'org_id' => '', 'sumup_num' => $class['sumup_num'], 'sumup_keyword' => $class['sumup_keyword'], 'sumup_score' => $class['sumup_score'], 'qrcode' => '', 'category' => $class['category'], 'train_employee' => '', 'from_type' => $from, 'from_root_id' => $class['root_id'], 'from_content_id' => $class['id'] ]; TrainClass::insertGetId($classNewData); } Db::commit(); $msg = $from == 1 ? '指派' : '共享'; return json(['code' => 0, 'msg' => $msg . '成功']); } catch (\Exception $e) { Db::rollback(); return json(['code' => 1, 'msg' => $msg . '失败']); } } /* * 课程观看感悟 */ public function groupComment() { if (!Request::isAjax()) { $class_id = Request::param('class_id'); View::assign('class_id', $class_id); $data = TrainClass::with(['company'])->where('from_content_id', $class_id)->select(); View::assign('data', $data); return View::fetch(); } $param = Request::param(); $class_id = TrainClass::where(['from_type' => 1, 'from_content_id' => $param['class_id'], 'from_root_id' => request()->employee->root_id])->column('id'); $condition[] = [ ['class_id', 'in', $class_id], ['course_id', '=', 0] ]; if (isset($param['company_name_id']) && !empty($param['company_name_id'])) $condition[] = ['root_id', '=', $param['company_name_id']]; 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'], 'root_id' => request()->employee->root_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 groupOrgData() { $class_id = request()->param('class_id'); if (!Request::isAjax()) { $data = TrainClass::with(['company'])->where('from_content_id', $class_id)->order('id desc')->select(); View::assign('data', $data); View::assign('class_id', $class_id); return View::fetch(); } $param = request()->param(); //培训人 $where1 = [['from_content_id', '=', $param['class_id']]]; if (!empty($param['org_id'])) { $where1[] = ['root_id', '=', $param['org_id']]; } $employee_root = TrainClass::with(['company'])->where($where1)->column('root_id'); $trainNumber = Employee::where([['root_id', 'in', $employee_root], ['state', 'like', '%在职%'], ['uid', '>', 0]])->count(); //培训完 $complete_class_id = TrainClass::with(['company'])->where($where1)->column('id'); $completeCount = TrainDoneLog::where([['class_id', 'in', $complete_class_id], ['done_percent', '=', 100], ['from', '=', 0], ['root_id', 'in', $employee_root]])->count(); //写观后感人 $summaryCount = TrainSumup::where([['class_id', 'in', $complete_class_id], ['course_id', '=', 0], ['root_id', 'in', $employee_root]])->group('employee_id')->count(); //学习完成率 $studyGDP = $this->GDP($completeCount, $trainNumber); //写观后感率 $summaryGDP = $this->GDP($summaryCount, $completeCount); //认真完成率 $earnestGDP = $this->GDP($summaryCount, $trainNumber); //查询有哪些部门 $orgArray = []; foreach ($employee_root as $items) { $org = Org::where('path', 'like', '%' . $items . '-%')->select()->toArray(); foreach ($org as $res) { $array = ['id' => $res['id'], 'name' => $res['name']]; $orgArray[] = $array; } } $orgCount = Employee::where([['root_id', 'in', $employee_root], ['state', 'like', '%在职%'], ['uid', '>', 0]])->group('org_id')->column('count(org_id)', 'org_id'); $class_success = TrainDoneLog::where([['from', '=', 0], ['root_id', 'in', $employee_root], ['class_id', 'in', $complete_class_id], ['done_percent', '=', 100]])->group('org_id')->column('count(org_id)', 'org_id'); $class_no_success = TrainDoneLog::where([['from', '=', 0], ['root_id', 'in', $employee_root], ['class_id', 'in', $complete_class_id], ['done_percent', '<', 100]])->group('org_id')->column('count(org_id)', 'org_id'); $sumup_org_id = TrainSumup::where([['root_id', 'in', $employee_root], ['class_id', 'in', $complete_class_id], ['course_id', '=', 0]])->group('org_id')->column('org_id'); $sumup = []; foreach ($sumup_org_id as $k => $v) { $sumup[$v] = TrainSumup::where([['org_id', '=', $v], ['class_id', 'in', $complete_class_id], ['course_id', '=', 0]])->group('employee_id')->count(); } foreach ($orgArray as &$item) { //学习人数 $item['trainNumber'] = isset($orgCount[$item['id']]) ? $orgCount[$item['id']] : 0; //已学完 $item['completeCount'] = isset($class_success[$item['id']]) ? $class_success[$item['id']] : 0; //未学完 $item['noFinishCount'] = isset($class_no_success[$item['id']]) ? $class_no_success[$item['id']] : 0; //写观后感 $item['summaryCount'] = isset($sumup[$item['id']]) ? $sumup[$item['id']] : 0; //学习完成率 $item['studyDGP'] = $this->GDP($item['completeCount'], $item['trainNumber']); //观看感完成率 $item['summaryCountDGP'] = $this->GDP($item['summaryCount'], $item['completeCount']); //认真完成率 $item['earnestDGP'] = $this->GDP($item['summaryCount'], $item['trainNumber']); } //查询认真率最高和最低部门 $last_data = array_column($orgArray, 'earnestDGP'); array_multisort($last_data, SORT_DESC, $orgArray); $max_org = empty($orgArray) || $orgArray[0]['earnestDGP'] == 0 ? '暂无数据' : $orgArray[0]['name']; array_multisort($last_data, SORT_ASC, $orgArray); $min_org = empty($orgArray) || $orgArray[0]['earnestDGP'] == 0 ? '暂无数据' : $orgArray[0]['name']; return json([ 'code' => 0, 'data' => $orgArray, 'count' => count($orgArray), 'trainNumber' => $trainNumber, 'completeCount' => $completeCount, 'summaryCount' => $summaryCount, 'studyGDP' => $studyGDP, 'summaryGDP' => $summaryGDP, 'earnestGDP' => $earnestGDP, 'max_org' => $max_org, 'min_org' => $min_org, ]); } /** * 课件浏览记录 */ 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], ['root_id', '=', $root_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(); View::assign('org', $org); View::assign('course_id', $course_id); return View::fetch(); } /** * 课程浏览记录 */ public function class_view_list() { $param = Request::only(['class_id' => 0, 'org_id' => 0, 'page' => 1, 'limit' => 10]); $class_id = $param['class_id']; $org_id = $param['org_id']; $root_id = request()->employee->root_id; if ($org_id) { $eids = Employee::where([['org_id', '=', $org_id], ['root_id', '=', $root_id]])->column('id'); $w[] = ['employee_id', 'in', $eids]; } $w[] = ['root_id', '=', $root_id]; $w[] = ['class_id', '=', $class_id]; $w[] = ['type', '=', 'traincourse']; $list = TrainClassView::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 = TrainClassView::where($w)->count(); return json(['code' => 0, 'data' => $list, 'count' => $count]); } /** * 课程浏览记录 */ public function class_view($class_id = 0) { $root_id = request()->employee->root_id; $org = Org::where([['path', 'like', $root_id . '-%']])->field('name,id')->select()->toArray(); View::assign('org', $org); View::assign('class_id', $class_id); return View::fetch(); } /** * 分类管理 */ public function class_cate() { return View::fetch(); } /** * 分类管理列表 */ public function class_cate_list() { $root_id = request()->employee->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 = request()->employee->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 class_cate_add() { $root_id = request()->employee->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 with_type_count() { $param = Request::param(); if($param['type'] == 'cate') { $field = 'cate'; }else{ $field = 'label'; } $where = [ ['root_id','=',request()->employee->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'=>request()->employee->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'=>request()->employee->root_id,'pid'=>0,'show'=>1])->value('id'); if(empty($type_id)) $type_id = TrainClassCate::insertGetId(['pid'=>0,'name'=>'其它','root_id'=>request()->employee->root_id,'show'=>1]); //更新关联内容 TrainClass::where(['root_id'=>request()->employee->root_id,'cate'=>$trainCate['name']])->update(['cate'=>'其它']); TrainClassCate::where(['root_id'=>request()->employee->root_id,'pid'=>$trainCate['id']])->update(['pid'=>$type_id]); //去重 $groupId = TrainClassCate::where(['root_id'=>request()->employee->root_id,'pid'=>$type_id,'show'=>1])->min('id'); TrainClassCate::where([['root_id','=',request()->employee->root_id],['pid','=',$type_id],['show','=',1],['id','<>',$groupId]])->delete(); //删除分类 $trainCate->delete(); }else{ $label_id = TrainClassCate::where(['root_id'=>request()->employee->root_id,'pid'=>$trainCate['pid'],'show'=>1])->value('id'); if(empty($label_id)) $label_id = TrainClassCate::insertGetId(['pid'=>$trainCate['pid'],'name'=>'其它','root_id'=>request()->employee->root_id,'show'=>1]); //更新关联内容 TrainClass::where(['root_id'=>request()->employee->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_label() { return View::fetch(); } /** * 标签管理列表 */ public function class_label_list() { $root_id = request()->employee->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','id'=>'desc'])->select(); if (!$list->isEmpty()) { $w1[] = ['root_id', '=', $root_id]; $w1[] = ['pid', '=', 0]; $cates = TrainClassCate::where($w1)->column('name', 'id'); foreach ($list as $k => $v) { $v->pname = isset($cates[$v->pid]) ? $cates[$v->pid] : ''; } } $count = TrainClassCate::where($w)->count(); return json(['code' => 0, 'data' => $list, 'count' => $count]); } /** * 标签管理编辑 */ public function class_label_edit() { $root_id = request()->employee->root_id; $param = Request::only(['id' => 0, 'name' => '', 'pid' => 0]); $param['name'] = str_replace(' ', '', $param['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[] = ['label', '=', $name]; $w1[] = ['root_id', '=', $root_id]; TrainClass::where($w1)->update(['label' => $param['name']]); return json(['code' => 0, 'data' => '修改成功', 'msg' => '修改成功']); } /** * 分类管理添加页面 */ public function class_label_add() { $root_id = request()->employee->root_id; $w[] = ['root_id', '=', $root_id]; $w[] = ['pid', '=', 0]; $cate = TrainClassCate::where($w)->order('id desc')->select(); View::assign('cate', $cate); return View::fetch(); } /** * 标签管理添加 */ public function class_label_add_ajax() { $root_id = request()->employee->root_id; $param = Request::only(['name' => '', 'pid' => 0]); $param['name'] = str_replace(' ', '', $param['name']); $w[] = ['root_id', '=', $root_id]; $w[] = ['name', '=', $param['name']]; $w[] = ['pid', '=', $param['pid']]; $find = TrainClassCate::where($w)->findOrEmpty(); if (!$find->isEmpty()) return json(['code' => 1, 'data' => '标签已存在', 'msg' => '标签已存在']); $id = TrainClassCate::insertGetId(['root_id' => $root_id, 'name' => $param['name'], 'pid' => $param['pid']]); return json(['code' => 0, 'data' => '添加成功', 'msg' => '添加成功', 'id' => $id]); } //学分设置 public function credit_setting() { $request = request(); $type=$request->param('type'); $where[] = ['code', '=', 'studytime_credit']; $where[] = ['root_id', '=', $request->employee->root_id]; $time_study=CreditsSetting::where($where)->field('status,value')->find(); $data['studytime_credit'] = !empty($time_study['value']) ? json_decode($time_study['value'], true) : ['numtime' => 0, 'time_credit' => 0]; $data['studytime_status']=!empty($time_study)?$time_study['status']:1; $where3[] = ['code', '=', 'studyday_maxcredit']; $where3[] = ['root_id', '=', $request->employee->root_id]; $maxcredit = CreditsSetting::where($where3)->field('status,value')->find(); $data['studyday_maxcredit'] = !empty($maxcredit['value'])?$maxcredit['value']:0; $data['studyday_status'] = !empty($maxcredit)?$maxcredit['status']:1; $where4[] = ['code', '=', 'studyfeeling_credit']; $where4[] = ['root_id', '=', $request->employee->root_id]; $person2 = CreditsSetting::where($where4)->field('status,value')->find(); $data['studyfeeling_credit'] = !empty($person2['value'])?$person2['value']:0; $data['studyfeeling_status'] = !empty($person2)?$person2['status']:1; View::assign('data', $data); return View::fetch(); } //设置学分 public function reward_credit_save() { $request = request(); $param = Request::only(['numtime','time_credit','max_credit','howday','feeling_credit','studytime_status','studyday_status','studyfeeling_status']); // var_dump($param); // exit; if($param['studytime_status']==2 && ($param['numtime']==0 || $param['time_credit']==0)){ return json(['code' => 1, 'msg' => '设置学习时长不能有0值']); }if($param['studyday_status']==2 && $param['max_credit']==0){ return json(['code' => 1, 'msg' => '设置一天可得学分不能为0']); }if($param['studyfeeling_status']==2 && $param['feeling_credit']==0){ return json(['code' => 1, 'msg' => '设置感悟学分不能为0']); } if ($param['studytime_status']==2 && isset($param['numtime']) && isset($param['time_credit'])) { $json = json_encode(['numtime' => $param['numtime'], 'time_credit' => $param['time_credit']]); credits($request->employee->root_id, $json, 'studytime_credit', 0); //贡献值 } if ($param['studyday_status']==2 && isset($param['max_credit'])) { credits($request->employee->root_id, $param['max_credit'], 'studyday_maxcredit', 0); //积分 } if ($param['studyfeeling_status']==2 && isset($param['feeling_credit'])) { credits($request->employee->root_id, $param['feeling_credit'], 'studyfeeling_credit', 0); //积分 } return json(['code' => 0, 'msg' => '保存成功']); } //修改学分开启关闭 public function up_credit_status() { $request = request(); $param = Request::only(['code']); $arr=['studyfeeling_credit','studyday_maxcredit','studycourse_credit','studytime_credit']; if(!in_array($param['code'],$arr)) return json(['code' => 1, 'msg' => '参数错误']); $ms=CreditsSetting::where([['root_id', '=', $request->employee->root_id],['code', '=', $param['code']]])->find(); $tips=1; if(!empty($ms)){ $tips=$ms['status']; $ms->status=!empty($ms['status'])?0:1; $ms->save(); } if($tips==1){ return json(['code' => 0, 'msg' => '开启成功']); }else{ return json(['code' => 0, 'msg' => '关闭成功']); } } /** * root_id 被复制的店面id * * new_root_id 新添加数据的店面 */ public function addData($root_id=0,$new_root_id=0) { //train_class train_class_cate fl_train_type fl_train_course if (!$root_id || !$new_root_id) { return false; } // TrainClassCate // TrainType // TrainCourse // TrainClass $where[] = ['root_id','=',$root_id]; $query[] = ['root_id','=',$new_root_id]; // $train_type = TrainType::where($where)->field('type,'.' '.$new_root_id.' as root_id')->select()->toArray(); $train_type = TrainType::where($where)->column('type'); //去重 $j_type = TrainType::where($query)->column('type'); $new_type = array_diff($train_type,$j_type); $type = []; foreach ($new_type as $v) { $type[] = [ 'root_id'=>$new_root_id, 'type' => $v ]; } TrainType::InsertAll($type); //TrainClassCate $train_class_cate = TrainClassCate::where($where)->column('id,pid,name'); $cate = []; foreach ($train_class_cate as $v1) { if ($v1['pid']==0) { $cate[$v1['name']] = []; foreach ($train_class_cate as $v2) { if($v1['id']==$v2['pid']) $cate[$v1['name']][] = $v2['name']; } } } foreach ($cate as $k3 => $v3) { $where_cate = []; $where_cate[] = ['root_id','=',$new_root_id]; $where_cate[] = ['name','=',$k3]; $where_cate[] = ['pid','=',0]; $check = TrainClassCate::where($where_cate)->findOrEmpty(); unset($where_cate); if ($check->isEmpty()) { $pid = TrainClassCate::InsertGetId([ 'root_id' => $new_root_id, 'name' => $k3, 'pid' => 0 ]); }else{ $pid = $check->id; } //二级分类 foreach ($v3 as $k4 => $v4) { $where_cate2 = []; $where_cate2[] = ['pid','=',$pid]; $where_cate2[] = ['name','=',$v4]; $where_cate2[] = ['root_id','=',$new_root_id]; $check2 = TrainClassCate::where($where_cate2)->findOrEmpty(); unset($where_cate2); if ($check2->isEmpty()) { TrainClassCate::Insert([ 'root_id' => $new_root_id, 'name' => $v4, 'pid' => $pid ]); } } } //TrainClass $train_class = TrainClass::where($where)->column('*'); foreach ($train_class as $k6 => $v6) { unset($train_class[$k6]['id']); $train_class[$k6]['addtime'] = date('Y-m-d H:i:s'); $train_class[$k6]['root_id'] = $new_root_id; $train_class[$k6]['course_id'] = ''; if ($v6['course_id']) { $train_class[$k6]['course_id'] = $this->course($v6['course_id'],$new_root_id); } $train_class[$k6]['qrcode'] = ''; $train_class[$k6]['org_id'] = ''; $train_class[$k6]['train_employee'] = ''; } TrainClass::insertAll($train_class); return 1; } public function course($ids,$new_root_id){ $ids = explode(',',$ids); // TrainCourse $where[] = ['id','in',$ids]; $train_course = TrainCourse::where($where)->column('*'); foreach ($train_course as $k5 => $v5) { unset($train_course[$k5]['id']); //type_id $name = TrainType::where('id',$v5['type_id'])->value('type'); $train_course_where = []; $train_course_where[] = ['type','=',$name]; $train_course_where[] = ['root_id','=',$new_root_id]; $train_course[$k5]['type_id'] = TrainType::where($train_course_where)->value('id'); unset($train_course_where); $train_course[$k5]['root_id'] = $new_root_id; $train_course[$k5]['addtime'] = date('Y-m-d H:i:s'); } $id = []; foreach ($train_course as $v) { $id[] = TrainCourse::insertGetId($v); } return implode(',',$id); } }