Train.php 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980
  1. <?php
  2. declare(strict_types=1);
  3. namespace app\mobile\controller;
  4. use think\facade\Request;
  5. use think\facade\Log;
  6. use app\model\Org;
  7. use app\model\TrainClassCate;
  8. use app\model\TrainClass;
  9. use app\model\TrainDoneLog;
  10. use app\model\User;
  11. use app\model\Employee;
  12. use app\model\TrainCourse;
  13. use app\model\TrainSumup;
  14. use app\model\TrainThumbLog;
  15. use think\facade\Console;
  16. use app\model\Lecturer;
  17. use app\model\LecturerCompany;
  18. use app\model\TrainCourseView;
  19. use app\model\TrainClassView;
  20. use app\model\CreditsSetting;
  21. use app\model\TrainCredits;
  22. use app\model\PreformanceTasks;
  23. use app\model\PreformanceTasksOrg;
  24. class Train extends Base
  25. {
  26. /**
  27. * 一级分类
  28. */
  29. public function getCate()
  30. {
  31. $w[] = ['root_id','=',$this->rootId];
  32. $w[] = ['pid','=',0];
  33. $list = TrainClassCate::where($w)->field('id,name')->order(['order'=>'asc','id'=>'desc'])->select();
  34. return json(['code' => 0, 'data' => $list]);
  35. }
  36. /**
  37. * 店面课程列表
  38. * 培训课程列表from_type=3查询0,2
  39. * from_type:0自建,1集团指派,2店面共享
  40. */
  41. public function classList()
  42. {
  43. $param = Request::only(['page'=>1,'limit'=>10,'from_type'=>0,'cate'=>'','keyword'=>'','label'=>'']);
  44. $page = $param['page'];
  45. $limit = $param['limit'];
  46. $from_type = $param['from_type'];
  47. $cate = $param['cate'];
  48. $keyword = $param['keyword'];
  49. $label = $param['label'];
  50. $eid = $this->employeeId;
  51. $condition = [
  52. ['root_id','=',$this->rootId],
  53. ['del','=',0],
  54. ['publish','=',1]
  55. ];
  56. $condition[] = $from_type==3 ? ['from_type','in',[0,2]] : ['from_type','=',$from_type];
  57. if ($cate) $condition[] = ['cate','=',$cate];
  58. if ($label) $condition[] = ['label','=',$label];
  59. if ($keyword) $condition[] = ['title','like','%'.trim($keyword).'%'];
  60. $sql = TrainClass::field('id,title,cover,course_id,category,view,train_employee,addtime,type,from_type');
  61. //集团指派课程全员展示
  62. if($from_type != 1)
  63. {
  64. $sql->where(function ($query) use ($eid){
  65. $query->whereRaw("FIND_IN_SET(" . $eid . " , train_employee)")
  66. ->whereOr('train_employee', '=', '');
  67. });
  68. }
  69. $data = $sql->where($condition)->page((int)$page , (int)$limit)->order('addtime desc')->select()->toArray();
  70. $column_class_id = array_column($data , 'id');
  71. $doneLog = TrainDoneLog::where([['from','=',0],['class_id','in',$column_class_id] , ['root_id','=',$this->rootId] , ['done_percent','>',0]])->group('class_id')->column('count(class_id)','class_id');
  72. //查询最近完成人的头像取6个
  73. $res = TrainDoneLog::with(['employee'])->where([['from','=',0],['class_id','in',$column_class_id] , ['root_id','=',$this->rootId] , ['done_percent','=',100]])->order('addtime desc')->select()->toArray();
  74. $uid = array_column($res , 'uid');
  75. $user = User::where('id','in',$uid)->column('headimgurl','id');
  76. $headimgurl = [];
  77. foreach($res as &$r)
  78. {
  79. $headimgurl[$r['class_id']][] = isset($user[$r['uid']]) ? $user[$r['uid']] : '';
  80. }
  81. // 查询课程多少人参与,课程章节数
  82. foreach($data as &$item){
  83. $item['train_employee_count'] = count(explode(',',$item['train_employee']));
  84. $item['course_num'] = empty($item['course_id']) ? 0 : count(explode(',',$item['course_id']));
  85. $item['done_log_num'] = isset($doneLog[$item['id']]) ? $doneLog[$item['id']] : 0;
  86. $item['done_log_num'] = $item['view']>=$item['train_employee_count'] ? $item['train_employee_count'] : $item['view'];//学习人数太少先用浏览量展示
  87. $item['headimgurl'] = isset($headimgurl[$item['id']]) ? $headimgurl[$item['id']] : [];
  88. }
  89. return json(['code' => 0, 'data' => $data]);
  90. }
  91. /**
  92. * 学习中心首页轮播图
  93. */
  94. public function banner()
  95. {
  96. $img = ['Train/6466e5d1f3385.png'];
  97. $url = config('app.ali_oss_bindurl');
  98. foreach ($img as $key => $value) {
  99. $img[$key] = 'https://' . $url . '/' . $value;
  100. }
  101. return json(['code' => 0, 'data' => $img,'msg'=>'']);
  102. }
  103. /**
  104. * 学习中心首页精品课程
  105. */
  106. public function boutiqueTrain()
  107. {
  108. $limit = input('limit',4,'intval');
  109. $res = TrainClass::withCount(['doneLog'])->where([['root_id','=',0],['publish','=',1],['del','=',0]])->visible(['id','cover','title','done_log_count'])->order('view desc')->limit($limit)->select()->toArray();
  110. foreach ($res as $key => $value) {
  111. $res[$key]['position'] = '威智慧 · 讲师';
  112. }
  113. return json(['code' => 0, 'data' => $res,'msg'=>'']);
  114. }
  115. /**
  116. * 讲师团队
  117. */
  118. public function lecturerList()
  119. {
  120. $limit = input('limit',4,'intval');
  121. $res = Lecturer::with(['company'=>function($query){
  122. $query->field('id,name')->bind(['company_name'=>'name']);
  123. }])->where([['root_id','=',0],['del','=',0]])->order('id desc')->limit($limit)->select()->toArray();
  124. foreach ($res as $key => $value) {
  125. // $res[$key]['company'] = '威智慧';
  126. }
  127. return json(['code' => 0, 'data' => $res,'msg'=>'']);
  128. }
  129. /**
  130. * 首页直播列表
  131. */
  132. public function broadcastList()
  133. {
  134. $limit = input('limit',4,'intval');
  135. $res = Lecturer::with(['company'=>function($query){
  136. $query->field('id,name')->bind(['company_name'=>'name']);
  137. }])->where([['root_id','=',0],['del','=',0]])->order('id desc')->limit($limit)->select()->toArray();
  138. foreach ($res as $key => $value) {
  139. // $res[$key]['company'] = '威智慧';
  140. }
  141. return json(['code' => 0, 'data' => $res,'msg'=>'']);
  142. }
  143. /**
  144. * 课程详情
  145. */
  146. public function classRead($class_id)
  147. {
  148. $token['root_org'] = $this->rootId;
  149. $token['employee_id'] = $this->employeeId;
  150. $token['uid'] = $this->uid;
  151. $from = input('from',0) ? 1 : 0;
  152. $data = TrainClass::where([['id','=',$class_id],['root_id','in',[$token['root_org'],0]],['del','=',0],['publish','=',1]])->field('imgs,introduce,id,title,cover,des,course_id,type,category,train_employee,addtime,from_type,from_root_id')->findOrEmpty();
  153. if($data->isEmpty()) return json(['code' => 0, 'data' => []]);
  154. //课件数量
  155. $data['course_num'] = empty($data['course_id']) ? 0 : count(explode(',',$data['course_id']));
  156. //已经学习人数
  157. $data['done_log_num'] = TrainDoneLog::where([['from','=',$from],['class_id','=',$data['id']] , ['root_id','in',[$token['root_org'],0]] , ['done_percent','>',0]])->count();
  158. $data['is_success_class'] = false;//是否全部完成
  159. $data['is_course_num'] = 0;//完成课件数量
  160. $myDoneLog = TrainDoneLog::where([['from','=',$from],['employee_id','=',$token['employee_id']] , ['class_id','=',$data['id']] , ['root_id','in',[$token['root_org'],0]]])->findOrEmpty();
  161. if (!$myDoneLog->isEmpty()) {
  162. $data['is_success_class'] = $myDoneLog->done_percent==100 ? true : false;//是否全部完成
  163. $data['is_course_num'] = $myDoneLog->course_id ? count(explode(',',$myDoneLog->course_id)) : 0;//完成课件数量
  164. }
  165. $data['train_employee_num'] = $data->from_type = 1 ? '全员' : ($data->train_employee ? count(explode(',',$data->train_employee)) : 0);//学习总人数
  166. //全部完成人员信息
  167. $myDoneLog = TrainDoneLog::where([['from','=',$from],['class_id','=',$data['id']] , ['root_id','=',$token['root_org']],['done_percent','=',100]])->order('id desc')->group('employee_id')->limit(3)->column('employee_id');
  168. $tw[] = ['id','in',$myDoneLog];
  169. $data['train_employee_info'] = Employee::with('userImg')->where($tw)->visible(['name','img'])->select()->toArray();//
  170. $data['train_employee_info_count'] = count($data['train_employee_info']);
  171. //课程来源
  172. if ($data['from_type'] == 0)
  173. {
  174. $data['from'] = '店面发布';
  175. } elseif ($data['from_type'] == 1) {
  176. $data['from'] = '集团指派';
  177. } else {
  178. $company = Company::where('root_id',$data['from_root_id'])->value('company_name');
  179. $data['from'] = '集团从'.$company.'共享';
  180. }
  181. //浏览量+1
  182. // $rand = mt_rand(1,10);
  183. $view = input('view', '', 'trim');
  184. if ($view){
  185. TrainClass::where('id',$class_id)->inc('view',1)->update();
  186. }
  187. //当前评论数量
  188. $data['sumup_count'] = TrainSumup::where([['class_id','=',$class_id],['course_id','=',0]])->count();
  189. return json(['code' => 0, 'data' => $data]);
  190. }
  191. /**
  192. * 课程课件列表
  193. */
  194. public function trainCourseList($page,$class_id,$course_id=0)
  195. {
  196. $from = input('from',0) ? 1 : 0;
  197. $class = TrainClass::where([['id','=',$class_id ], ['root_id','in',[$this->rootId,0] ], ['publish','=',1],['del','=',0]])->field('course_id,type')->findOrEmpty();
  198. if($class->isEmpty()) return json(['code' => 0, 'data' => []]);
  199. $data = TrainCourse::field('id,title,type')->where([['id', 'in', $class['course_id']],['root_id','in',[$this->rootId,0]]])->page((int)$page , 40)->order('id desc')->select()->toArray();
  200. $employee_id = $this->employeeId;
  201. $doneLog = TrainDoneLog::where(['employee_id'=>$employee_id ,'from'=>$from ,'class_id'=>$class_id])->value('course_id');
  202. // 查询课件完成情况
  203. $arr = ['image'=>'图文课件','video'=>'视频','pdf'=>'PDF文件','audio'=>'音频'];
  204. $start_count = 0;
  205. if ($doneLog) {
  206. $doneLogArr = explode(',',$doneLog);
  207. $start_count = count($doneLogArr);
  208. foreach($data as $key => &$item){
  209. $item['done_state'] = $data[$key]['done_state'] = in_array($item['id'],$doneLogArr);
  210. $item['is_now'] = $course_id==$item['id'] ? true : false;
  211. $item['type_name'] = $arr[$item['type']];
  212. //是否可以学习
  213. $item['switch'] = ($class->type=='free' || $key==0) ? true : (isset($data[$key-1])&&$data[$key-1]['done_state'] ? true : false);
  214. }
  215. }else{
  216. $start_count = 0;
  217. foreach($data as $key => &$item){
  218. $item['done_state'] = false;
  219. $item['is_now'] = $course_id==$item['id'] ? true : false;
  220. $item['type_name'] = $arr[$item['type']];
  221. //是否可以学习
  222. $item['switch'] = ($class->type=='free'||$key==0) ? true : false;
  223. }
  224. }
  225. $count = count($data);
  226. return json(['code' => 0, 'data' => $data,'count'=>$count,'start_count'=>$start_count]);
  227. }
  228. /*
  229. * 课程观看感、课件读后感
  230. */
  231. public function watchFeel($page , $class_id , $course_id=0)
  232. {
  233. $course_id = empty($course_id) ? 0 : $course_id;
  234. $sumup = TrainSumup::with(['employee','user'])->where([['course_id','=',$course_id],['class_id','=',$class_id] , ['root_id','in',[$this->rootId,0]]])->page((int)$page , 10)->order('id desc')->select()->toArray();
  235. $column_sumup_id = array_column($sumup,'id');
  236. $employee_id = $this->employeeId;
  237. $log = TrainThumbLog::where([['sumup_id','in',$column_sumup_id] , ['employee_id','=',$employee_id] , ['root_id','in',[$this->rootId,0]]])->column('id','sumup_id');
  238. $class = TrainClass::where('id',$class_id)->field('sumup_keyword,sumup_score')->find();
  239. foreach($sumup as &$item)
  240. {
  241. $item['score'] = TrainSumup::sumup_score_num($class['sumup_keyword'] , $class['sumup_score'] , $item['content']);
  242. $item['thumblog'] = isset($log[$item['id']]) ? true : false;
  243. $item['addtime'] = date('Y-m-d',strtotime($item['addtime']));
  244. }
  245. $count = TrainSumup::where([['course_id','=',$course_id],['class_id','=',$class_id] , ['root_id','in',[$this->rootId,0]]])->count();
  246. return json(['code' => 0, 'data' => $sumup, 'count' => $count]);
  247. }
  248. /*
  249. * 根据时间计算距离现在多久
  250. */
  251. private function date_switch($time)
  252. {
  253. $now = time();
  254. $old = strtotime(date($time));
  255. $dur = $now - $old;
  256. if($dur <= 0){
  257. return $time;
  258. }elseif($dur < 60){
  259. return $dur.'秒前';
  260. }elseif($dur < 3600){
  261. return floor($dur/60).'分钟前';
  262. }elseif($dur < 86400){
  263. return floor($dur/3600).'小时前';
  264. }elseif($dur < 2678400){
  265. return floor($dur/86400).'天前';
  266. }elseif($dur < 2678400*12){
  267. return floor($dur/2678400).'月前';
  268. }else{
  269. return floor($dur/2678400/12).'年前';
  270. }
  271. }
  272. /*
  273. * 评论
  274. */
  275. public function commentAdd()
  276. {
  277. $param = request()->param(['class_id','course_id'=>0,'content','read_status','from'=>0,'study_time'=>0]);
  278. $where = [['root_id','in',[$this->rootId,0]],['id','=',$param['class_id']]];
  279. if($param['course_id']) $where[] = ['course_id','find in set',$param['course_id']];
  280. $TrainClass = TrainClass::where($where)->field('sumup_num,course_id')->findOrEmpty();
  281. if($TrainClass->isEmpty()) return json(['code' => 1, 'msg' => '提交失败1']);
  282. $data = [
  283. 'user_id' => $this->uid,
  284. 'root_id' => $this->rootId,
  285. 'employee_id' => $this->employeeId,
  286. 'org_id' => Employee::where('id',$this->employeeId)->value('org_id'),
  287. 'class_id' => $param['class_id'],
  288. 'course_id' => empty($param['course_id']) ? 0 : $param['course_id'],
  289. 'content' => $param['content']
  290. ];
  291. if(empty($param['course_id']) && $TrainClass->root_id)
  292. {
  293. //课程评论验证字数是否达标
  294. if(mb_strlen($param['content']) < $TrainClass['sumup_num']) return json(['code' => 1, 'msg' => '课程感悟不低于'.$TrainClass['sumup_num'].'字数']);
  295. }
  296. if(!empty($param['course_id']) && $TrainClass->root_id)
  297. {
  298. //查询课件评论字数限制
  299. $comment_word_num = TrainCourse::where(['root_id'=>$this->rootId , 'id'=>$param['course_id']])->value('comment_word_num');
  300. if($comment_word_num && mb_strlen($data['content'])<$comment_word_num) return json(['code' => 1, 'msg' => '课件评论不低于'.$comment_word_num.'字数']);
  301. //课件评论验证完成情况
  302. if(isset($param['read_status']) && $param['read_status'] == true)
  303. {
  304. $doneLog = TrainDoneLog::where(['from'=>$param['from'],'employee_id'=>$this->employeeId,'root_id'=>$this->rootId,'class_id'=>$param['class_id']])->find();
  305. $log_course_id = !$doneLog ? [] : explode(',',$doneLog['course_id']);
  306. if(!in_array($param['course_id'] , $log_course_id)){
  307. //完成课件操作
  308. $this->course_finish($TrainClass['course_id'],$doneLog,$param['course_id'],$param['class_id'],$param['from'],$param['study_time']);
  309. }
  310. }
  311. }
  312. if (TrainSumup::insert($data)) {
  313. //增加提交感悟送学分
  314. if($param['course_id']==0){
  315. $this->feeling_credits($this->rootId,$this->employeeId);
  316. }
  317. return json(['code' => 0, 'msg' => '提交成功']);
  318. } else {
  319. return json(['code' => 1, 'msg' => '提交失败']);
  320. }
  321. }
  322. /*
  323. * 精品课程添加评论 ,课件添加评论
  324. */
  325. public function boutiqueCommentAdd()
  326. {
  327. $param = request()->param(['class_id','content','course_id'=>0]);
  328. $where = [
  329. ['id','=',$param['class_id']],
  330. ['root_id','=',0]
  331. ];
  332. if($param['course_id']) $where[] = ['course_id','find in set',$param['course_id']];
  333. $check = TrainClass::where($where)->findOrEmpty();
  334. if($check->isEmpty()) return json(['code' => 1, 'msg' => '提交失败']);
  335. $data = [
  336. 'user_id' => $this->uid,
  337. 'root_id' => $this->rootId,
  338. 'employee_id' => $this->employeeId,
  339. 'org_id' => Employee::where('id',$this->employeeId)->value('org_id'),
  340. 'class_id' => $param['class_id'],
  341. 'course_id' => $param['course_id'],
  342. 'content' => $param['content']
  343. ];
  344. if (TrainSumup::insert($data)) {
  345. return json(['code' => 0, 'msg' => '提交成功']);
  346. } else {
  347. return json(['code' => 1, 'msg' => '提交失败']);
  348. }
  349. }
  350. //计算提交感悟送学分
  351. public function feeling_credits($root_id,$employee_id)
  352. {
  353. $maxcredit=$this->sumday_credit($root_id,$employee_id);
  354. $where[] = ['code', '=', 'studyfeeling_credit'];
  355. $where[] = ['root_id', '=', $root_id];
  356. $studyfeeling = CreditsSetting::where($where)->field('status,value')->find();
  357. if(empty($studyfeeling)) return;//如果没有设置感悟送学分直接返回
  358. $you=TrainCredits::where([['employee_id','=',$employee_id],['root_id','=',$root_id]])->order('id desc')->find();
  359. if($studyfeeling['status']==0 && $studyfeeling['value']>0){
  360. if(empty($maxcredit) || $maxcredit['status']==1 ||($maxcredit['status']!=1 && $maxcredit['yes_course'] > $studyfeeling['value'])){
  361. $add=['employee_id'=>$employee_id,'root_id'=>$root_id,'type'=>3,'credits'=>$studyfeeling['value'],'now_credits'=>$studyfeeling['value']];
  362. if(!empty($you)){
  363. $add['now_credits']=$you['now_credits']+$studyfeeling['value'];
  364. }
  365. $this->add_credit($add);
  366. }
  367. if(!empty($maxcredit) && $maxcredit['status']==0 && $maxcredit['yes_course']!=0 && $maxcredit['yes_course'] < $studyfeeling['value']){
  368. $add=['employee_id'=>$employee_id,'root_id'=>$root_id,'type'=>3,'credits'=>$maxcredit['yes_course'],'now_credits'=>$maxcredit['yes_course']+ (!empty($you['now_credits'])?$you['now_credits']:0)];
  369. $this->add_credit($add);
  370. }
  371. }
  372. }
  373. /*
  374. * 课件完成操作
  375. */
  376. private function course_finish($trainClassCourseId,$doneLog,$paramCourseId,$paramClassId,$from=0,$study_time=0)
  377. {
  378. //课程绑定的课件
  379. $course_id = explode(',',$trainClassCourseId);
  380. $class=TrainClass::find($paramClassId);
  381. if(!empty($doneLog))
  382. {
  383. $have = explode(',',$doneLog['course_id']);
  384. $checkCourse = [$paramCourseId];
  385. $newCourseArr = array_merge($have,$checkCourse);
  386. $GDP = floor((count($newCourseArr) / count($course_id))*100);
  387. $update = [
  388. 'done_percent' => $GDP,
  389. 'course_id' => implode(',',$newCourseArr)
  390. ];
  391. $res = TrainDoneLog::where(['from'=>$from,'employee_id'=>$this->employeeId,
  392. 'root_id'=>$this->rootId,
  393. 'class_id'=>$paramClassId])->update($update);
  394. if($res){
  395. if ($GDP==100) {//累计勋章
  396. $employee_id = $this->employeeId;
  397. $root_id = $this->rootId;
  398. Console::call('medal',['class',(string)$employee_id,(string)$root_id]);
  399. //完成课程增加学分
  400. $this->add_studylog($employee_id,$class,$root_id);
  401. }
  402. //完成单个课件增加学习时长
  403. $this->add_studytime($this->employeeId,$paramClassId,$paramCourseId,$study_time,$this->rootId);
  404. return true;
  405. }else{
  406. return false;
  407. }
  408. }else{
  409. $GDP = floor((1 / count($course_id))*100);
  410. //第一次完成课件直接添加
  411. if(TrainDoneLog::insert([
  412. 'employee_id' => $this->employeeId,
  413. 'root_id' => $this->rootId,
  414. 'org_id' => Employee::where('id',$this->employeeId)->value('org_id'),
  415. 'class_id' => $paramClassId,
  416. 'done_percent' => $GDP,
  417. 'course_id' => $paramCourseId,
  418. 'from' => $from
  419. ])){
  420. if ($GDP==100) {//累计勋章
  421. $employee_id = $this->employeeId;
  422. $root_id = $this->rootId;
  423. Console::call('medal',['class',(string)$employee_id,(string)$root_id]);
  424. //完成课程增加学分
  425. $this->add_studylog($employee_id,$class,$root_id);
  426. }
  427. //完成单个课件增加学习时长
  428. $this->add_studytime($this->employeeId,$paramClassId,$paramCourseId,$study_time,$this->rootId);
  429. return true;
  430. }else{
  431. return false;
  432. }
  433. }
  434. }
  435. //增加课程的学习完成记录
  436. public function add_studylog($employee_id, $class, $root_id)
  437. {
  438. if (empty($class['credit'])) return; //如果没有设置学分直接返回
  439. $maxcredit = $this->sumday_credit($root_id, $employee_id);
  440. $you = TrainCredits::where([['employee_id', '=', $employee_id], ['root_id', '=', $root_id]])->order('id desc')->find();
  441. if (empty($maxcredit) || $maxcredit['status'] == 1 || ($maxcredit['status'] == 0 && $maxcredit['yes_course'] > $class['credit'])) {
  442. $add = ['employee_id' => $employee_id, 'root_id' => $root_id, 'type' => 2, 'credits' => $class['credit'], 'now_credits' => $class['credit']];
  443. if (!empty($you)) {
  444. $add['now_credits'] = $you['now_credits'] + $class['credit'];
  445. }
  446. }
  447. if (!empty($maxcredit) && $maxcredit['status'] != 1 && $maxcredit['yes_course'] != 0 && $maxcredit['yes_course'] < $class['credit']) {
  448. $add = ['employee_id' => $employee_id, 'root_id' => $root_id, 'type' => 2, 'credits' => $maxcredit['yes_course'], 'now_credits' => $maxcredit['yes_course'] + (!empty($you['now_credits'])?$you['now_credits']:0)];
  449. }
  450. if (!empty($add)) {
  451. $this->add_credit($add);
  452. }
  453. }
  454. //增加课程的学习时间
  455. public function add_studytime($employee_id,$class_id,$course_id,$study_time,$root_id)
  456. {
  457. $where[] = ['code', '=', 'studytime_credit'];
  458. $where[] = ['root_id', '=', $root_id];
  459. $time_study=CreditsSetting::where($where)->field('status,value')->find();
  460. if(empty($time_study)) return;//如果没有设置学习时长直接返回;
  461. if($time_study['status']==0){
  462. $add=['empid'=>$employee_id,'classid'=>$class_id,'course_id'=>$course_id,'study_time'=>$study_time,'all_time'=>$study_time,'type'=>1];
  463. $you=TrainCouresStudytime::where([['empid','=',$employee_id]])->order('id desc')->find();
  464. if(!empty($you)){
  465. $add['all_time']=$you['all_time']+$study_time;
  466. }
  467. TrainCouresStudytime::insert($add);
  468. $this->call_studytime($employee_id);//增加完学习时长直接开始计算是否送学分
  469. }
  470. }
  471. //计算学习时长送学分
  472. public function call_studytime($employee_id)
  473. {
  474. $token['root_org'] = $this->rootId;
  475. $token['employee_id'] = $this->employeeId;
  476. $token['uid'] = $this->uid;
  477. $maxcredit=$this->sumday_credit($token['root_org'],$token['employee_id']);
  478. $all_time=TrainCouresStudytime::where('empid',$employee_id)->order('id desc')->value('all_time');
  479. $where[] = ['code', '=', 'studytime_credit'];
  480. $where[] = ['root_id', '=', $token['root_org']];
  481. $time_study=CreditsSetting::where($where)->field('status,value')->find();
  482. if(empty($time_study)) return;//如果没有设置学习时长直接返回
  483. $time_study['value']=!empty($time_study['value'])?json_decode($time_study['value'],true):['numtime' => 0, 'time_credit' => 0];
  484. if($time_study['status']==0 && $time_study['value']['numtime'] > 0 && $all_time >= $time_study['value']['numtime']*60){
  485. $b=floor($all_time/($time_study['value']['numtime']*60));
  486. $credits=$b*$time_study['value']['time_credit'];
  487. $reduce_time=$b*($time_study['value']['numtime']*60);
  488. $you=TrainCredits::where([['employee_id','=',$token['employee_id']],['root_id','=',$token['root_org']]])->order('id desc')->find();
  489. //正常情况所得学分不大于当天可获得最高学分
  490. if(empty($maxcredit) || $maxcredit['status']==1 ||($maxcredit['status']==0 && $maxcredit['yes_course'] > $credits)){
  491. $add=['employee_id'=>$token['employee_id'],'root_id'=>$token['root_org'],'type'=>1,'credits'=>$credits,'now_credits'=>$credits];
  492. if(!empty($you)){
  493. $add['now_credits']=$you['now_credits']+$credits;
  494. }
  495. $this->add_credit($add);
  496. $newadd=['empid'=>$token['employee_id'],'study_time'=>$reduce_time,'all_time'=>$all_time-$reduce_time,'type'=>2];
  497. $newadd['all_time'] = $newadd['all_time']>0 ? $newadd['all_time']:0;
  498. TrainCouresStudytime::insert($newadd);
  499. }
  500. //所得学分大于当天剩余可得学分时取差值补满当天最高学分
  501. if(!empty($maxcredit) && $maxcredit['status']==0 && $maxcredit['yes_course']!=0 && $maxcredit['yes_course'] < $credits){
  502. $add=['employee_id'=>$token['employee_id'],'root_id'=>$token['root_org'],'type'=>1,'credits'=>$maxcredit['yes_course'],'now_credits'=>$maxcredit['yes_course']+ (!empty($you['now_credits'])?$you['now_credits']:0)];
  503. $this->add_credit($add);
  504. $newadd=['empid'=>$token['employee_id'],'study_time'=>$reduce_time,'all_time'=>0,'type'=>2];
  505. TrainCouresStudytime::insert($newadd);
  506. }
  507. // if($maxcredit['status']!=1 && $maxcredit['yes_course'] < $credits){
  508. // $newadd=['empid'=>$token['employee_id'],'study_time'=>$reduce_time,'all_time'=>0,'type'=>2];
  509. // TrainCouresStudytime::insert($newadd);
  510. // }
  511. }
  512. }
  513. //赠送学分统一方法方便计划任务处理
  514. public function add_credit($add)
  515. {
  516. $id=TrainCredits::insertGetId($add);
  517. $this->preformance_tasks($add['credits'], $id);
  518. }
  519. /**
  520. * 计算业绩任务
  521. */
  522. public function preformance_tasks($credit = 0, $vislog_id)
  523. {
  524. $token['root_org'] = $this->rootId;
  525. $token['employee_id'] = $this->employeeId;
  526. $token['uid'] = $this->uid;
  527. //防止后台切换部门
  528. $token['org_id'] = Employee::where('id', $token['employee_id'])->value('org_id');
  529. $time = date('Y-m-d H:i:s');
  530. //查询进行中的指派到所属部门的所有进度
  531. // $w[] = ['org_id','=',$token['org_id']];
  532. $w[] = ['root_id', '=', $token['root_org']];
  533. $w[] = ['start_date', '<=', $time];
  534. $w[] = ['end_date', '>=', $time];
  535. $w[] = ['is_credit', '=', 1];
  536. $preformance_tasks = PreformanceTasks::where($w)->column('id');
  537. $w1[] = ['root_id', '=', $token['root_org']];
  538. $w1[] = ['org_id', '=', $token['org_id']];
  539. $w1[] = ['performance_tasks_id', 'in', $preformance_tasks];
  540. $w1[] = ['is_credit', '=', 1];
  541. //指派到自己部门
  542. $pid = PreformanceTasksOrg::where($w1)->group('performance_tasks_id')->column('*');
  543. $w4[] = ['id', 'in', array_column($pid, 'performance_tasks_id')];
  544. $model = PreformanceTasks::where($w4)->column('*');
  545. foreach ($model as $k => $v) {
  546. $u = [];
  547. $u['ok_credit'] = $v['ok_credit'] + $credit;
  548. $u['customer_visit_log_id'] = $v['customer_visit_log_id'] ? $v['customer_visit_log_id'] . ',' . $vislog_id : $vislog_id;
  549. PreformanceTasks::where('id', $v['id'])->update($u);
  550. unset($u);
  551. }
  552. PreformanceTasksOrg::where($w1)->inc('ok_credit', (int)$credit)->update();
  553. return 1;
  554. }
  555. //统计当天获得的总学分
  556. public function sumday_credit($root_id,$employee_id)
  557. {
  558. $where3[] = ['code', '=', 'studyday_maxcredit'];
  559. $where3[] = ['root_id', '=', $root_id];
  560. $maxcredit = CreditsSetting::where($where3)->field('status,value')->find();//->findOrEmpty();
  561. if(!empty($maxcredit) && $maxcredit['status']==0){
  562. $day_course=TrainCredits::where([['employee_id','=',$employee_id],['root_id','=',$root_id],['addtime','>=',date('Y-m-d').' 00:00:00'],['addtime','<=',date('Y-m-d').' 23:59:59']])->sum('credits');
  563. $yes_course=$maxcredit['value']-$day_course;
  564. $maxcredit['yes_course']=$yes_course;
  565. }
  566. return $maxcredit;
  567. }
  568. /**
  569. * 课件内容详情
  570. */
  571. public function courseDetail($class_id,$course_id)
  572. {
  573. $where = [
  574. ['id','=',$class_id],
  575. ['course_id','find in set',$course_id],
  576. ['root_id','in',[$this->rootId,0]],
  577. ['del','=',0]
  578. ];
  579. $check = TrainClass::where($where)->field('id,train_employee,from_type,type')->findOrEmpty();
  580. if($check->isEmpty()) return json(['code' => 1, 'data' => [],'msg'=>'课件不存在']);
  581. $data = TrainCourse::where('id',$course_id)->find()->toArray();
  582. //评论数量
  583. $w[] = ['class_id','=',$class_id];
  584. $w[] = ['course_id','=',$course_id];
  585. $w[] = ['root_id','in',[$this->rootId,0]];
  586. $data['comment_count'] = TrainSumup::with('employee')->where($w)->count();
  587. //学习总人数
  588. $tw[] = ['root_id','in',[$this->rootId,0]];
  589. //如果是集团指派的课程查询全部人员
  590. if($check['from_type'] == 1){
  591. $data['train_count'] = Employee::where([['root_id','=',$this->rootId],['uid','>',0],['state','=','在职']])->count();
  592. }else{
  593. $data['train_count'] = count(array_filter(array_unique(explode(',',$check['train_employee']))));
  594. }
  595. //学习完成人数
  596. $dw = [['from','=',0],['root_id','in',[$this->rootId,0]], ['class_id', '=', $class_id],['course_id','find in set',$course_id]];
  597. $data['complete_count'] = TrainDoneLog::where($dw)->group('employee_id')->count();
  598. //未学习人数
  599. $data['no_count'] = $data['train_count']-$data['complete_count'] > 0 ? $data['train_count']-$data['complete_count'] : 0;
  600. //pdf 页数
  601. $data['page_num'] = 0;
  602. if ($data['type']=='pdf') {
  603. $data['page_num'] = $data['file'] ? $this->getPageTotal($data['file']) : 0;
  604. }
  605. $data['class_type'] = $check->type;
  606. return json(['code' => 0, 'data' => $data]);
  607. }
  608. /**
  609. * 获取PDF的页数
  610. */
  611. public function getPageTotal($path){
  612. // 打开文件
  613. if (!$fp = @fopen($path,"r")) {
  614. $error = "打开文件{$path}失败";
  615. return 0;
  616. } else {
  617. $max=0;
  618. while(!feof($fp)) {
  619. $line = fgets($fp,255);
  620. if (preg_match('/\/Count [0-9]+/', $line, $matches)){
  621. preg_match('/[0-9]+/',$matches[0], $matches2);
  622. if ($max<$matches2[0]) $max=$matches2[0];
  623. }
  624. }
  625. fclose($fp);
  626. // 返回页数
  627. return $max;
  628. }
  629. }
  630. /**
  631. * 点赞
  632. */
  633. public function thumbing($sumup_id)
  634. {
  635. $root_id = $this->rootId;
  636. $employee_id = $this->employeeId;
  637. $sumup = TrainSumup::where(['root_id'=>$root_id , 'id'=>$sumup_id])->field('id')->findOrEmpty();
  638. if($sumup->isEmpty()) return json(['code' => 1, 'msg' => '点赞失败']);
  639. $log = TrainThumbLog::where([
  640. ['sumup_id','=',$sumup_id],
  641. ['employee_id','=',$employee_id],
  642. ['root_id','=',$root_id]
  643. ])->find();
  644. if ($log) {
  645. TrainThumbLog::where(['sumup_id' => $sumup_id, 'employee_id' => $employee_id, 'root_id'=>$root_id])->delete();
  646. TrainSumup::where(['root_id'=>$root_id , 'id'=>$sumup_id])->dec('thumb')->update();
  647. $msg = '点赞取消';
  648. $res = 0;
  649. } else {
  650. TrainThumbLog::insert(['sumup_id' => $sumup_id, 'employee_id' => $employee_id, 'root_id'=>$root_id]);
  651. TrainSumup::where(['root_id'=>$root_id , 'id'=>$sumup_id])->inc('thumb')->update();
  652. $msg = '点赞成功';
  653. $res = 1;
  654. }
  655. //点赞数量
  656. $count = TrainThumbLog::where([['sumup_id','=',$sumup_id]])->count();
  657. return json(['code' => 0, 'msg' => $msg,'count'=>$count,'res'=>$res]);
  658. }
  659. /**
  660. * 精品课程点赞
  661. */
  662. public function thumbings($sumup_id)
  663. {
  664. $root_id = $this->rootId;
  665. $employee_id = $this->employeeId;
  666. $sumup = TrainSumup::where(['id'=>$sumup_id])->field('id')->findOrEmpty();
  667. if($sumup->isEmpty()) return json(['code' => 1, 'msg' => '点赞失败']);
  668. $log = TrainThumbLog::where([
  669. ['sumup_id','=',$sumup_id],
  670. ['employee_id','=',$employee_id],
  671. ['root_id','=',$root_id]
  672. ])->findOrEmpty();
  673. if (!$log->isEmpty()) {
  674. TrainThumbLog::where(['sumup_id' => $sumup_id, 'employee_id' => $employee_id, 'root_id'=>$root_id])->delete();
  675. TrainSumup::where(['id'=>$sumup_id])->dec('thumb')->update();
  676. $msg = '取消点赞';
  677. $res = 0;
  678. } else {
  679. TrainThumbLog::insert(['sumup_id' => $sumup_id, 'employee_id' => $employee_id, 'root_id'=>$root_id]);
  680. TrainSumup::where(['id'=>$sumup_id])->inc('thumb')->update();
  681. $msg = '成功点赞';
  682. $res = 1;
  683. }
  684. //点赞数量
  685. $count = TrainThumbLog::where([['sumup_id','=',$sumup_id]])->count();
  686. return json(['code' => 0, 'msg' => $msg,'count'=>$count,'res'=>$res]);
  687. }
  688. /*
  689. * 精品课程列表
  690. */
  691. public function premiumCourseList()
  692. {
  693. $param = Request::only(['page'=>1,'limit'=>10,'cate'=>'','keyword'=>'','type'=>1]);
  694. $order = $param['type']==1 ? 'id desc' : 'view desc,id desc';
  695. $page = $param['page'];
  696. $limit = $param['limit'];
  697. $cate = $param['cate'];
  698. $keyword = $param['keyword'];
  699. // $eid = $this->employeeId;
  700. $condition = [
  701. ['root_id','=',0],
  702. ['del','=',0],
  703. ['publish','=',1]
  704. ];
  705. if ($cate) $condition[] = ['cate','=',$cate];
  706. if ($keyword) $condition[] = ['title','like','%'.trim($keyword).'%'];
  707. $data = TrainClass::with(['lecturer'=>function($query){
  708. $query->bind(['lecturer_name'=>'name']);
  709. }])->field('id,title,cover,course_id,category,view,train_employee,addtime,type,from_type,lecturer_id');
  710. $data = $data->where($condition)->page((int)$page , (int)$limit)->order($order)->select();
  711. $column_class_id = array_column($data->toArray() , 'id');
  712. $doneLog = TrainDoneLog::where([['from','=',0],['class_id','in',$column_class_id] , ['done_percent','>',0]])->group('class_id')->column('count(class_id)','class_id');
  713. foreach ($data as $key => $value) {
  714. $data[$key]['study_count'] = isset($doneLog[$value['id']]) ? $doneLog[$value['id']] : 0;//学习人次
  715. $data[$key]['lectruer_company_name'] = $value['lecturer_id'] ? $value['lecturer']->company->name : '';
  716. }
  717. $count = TrainClass::where($condition)->count();
  718. return json(['code' => 0, 'data' => $data,'count'=>$count]);
  719. }
  720. /*
  721. * 课件完成人员列表
  722. */
  723. public function getCourseEmployee()
  724. {
  725. $param = Request::only(['page'=>1,'limit'=>10,'course_id'=>0,'class_id'=>0,'org_id'=>0,'keyword'=>'','start_date'=>'','end_date'=>'']);
  726. $where = [
  727. ['id','=',$param['class_id']],
  728. ['root_id','in',[$this->rootId,0]]
  729. ];
  730. $check = TrainClass::where($where)->field('id')->findOrEmpty();
  731. if($check->isEmpty()) return json(['code' => 0, 'data' => [],'count'=>0]);
  732. $where1 = [['class_id','=',$param['class_id']],['from','=',0]];
  733. if($param['start_date']){
  734. $where1[] = ['addtime','>=',$param['start_date']];
  735. }
  736. if($param['end_date']){
  737. $where1[] = ['addtime','<=',$param['end_date'].' 23:59:59'];
  738. }
  739. $emp = TrainDoneLog::where($where1)->column('addtime','employee_id');
  740. if (empty($emp)) return json(['code' => 0, 'data' => [],'count'=>0]);
  741. $emp_ids = array_keys($emp);
  742. $query = [['id','in',$emp_ids]];
  743. if($param['keyword']) $query[] = ['name','like','%'.$param['keyword'].'%'];
  744. if($param['org_id']) $query[] = ['org_id','=',$param['org_id']];
  745. $data = Employee::with(['org'=>function($query){
  746. $query->bind(['org_name'=>'name']);
  747. },'user'=>function($query){
  748. $query->bind(['headimg'=>'headimgurl']);
  749. }])->where($query)->field('id,name,org_id,uid')->page((int)$param['page'],(int)$param['limit'])->select()->toArray();
  750. $count = Employee::where($query)->count();
  751. foreach ($data as $key => $value) {
  752. $data[$key]['addtime'] = isset($emp[$value['id']]) ? $this->date_switch($emp[$value['id']]) : '';
  753. }
  754. return json(['code' => 0, 'data' => $data,'count'=>$count]);
  755. }
  756. /*
  757. * 员工完成课件
  758. */
  759. public function doneLogging()
  760. {
  761. $param = request()->param(['course_id','class_id','study_time']);
  762. $employee_id = $this->employeeId;
  763. $root_id = $this->rootId;
  764. $from = 0;
  765. $token['org_id'] = Employee::where('id',$this->employeeId)->value('org_id');
  766. //查询课件是否存在
  767. $class = TrainClass::where(['root_id'=>$root_id , 'del'=>0 , 'publish'=>1 , 'id'=>$param['class_id']])->find();
  768. $c = explode(',',$class['course_id']);
  769. if(empty($class) || !in_array($param['course_id'] , $c)){
  770. return json(['code' => 1, 'msg' => '课件内容不存在']);
  771. }
  772. //判断是否已完成该课件
  773. $doneLog = TrainDoneLog::where(['employee_id'=>$employee_id,'from'=>$from,'root_id'=>$root_id,'class_id'=>$param['class_id']])->find();
  774. $log_course_id = !empty($doneLog['course_id']) ? explode(',',$doneLog['course_id']) : [];
  775. if(!empty($doneLog) && !empty($doneLog['done_percent']) && in_array($param['course_id'] , $log_course_id)){
  776. return json(['code' => 1, 'msg' => '该课件已完成,无需重复操作']);
  777. }
  778. //判断是否设置课件评论字数
  779. $comment_word_num = TrainCourse::where(['root_id'=>$root_id , 'id'=>$param['course_id']])->value('comment_word_num');
  780. if($comment_word_num > 0)
  781. {
  782. $where[] = ['employee_id','=',$employee_id];
  783. $where[] = ['course_id','=',$param['course_id']];
  784. $where[] = ['class_id','=',$param['class_id']];
  785. $where[] = ['','EXP',Db::raw('char_length(content) >= '.$comment_word_num.'')];
  786. $sumupcount = TrainSumup::where($where)->count();
  787. if($sumupcount == 0) return json(['code' => 1, 'msg' => '课件评论字数不达标']);
  788. }
  789. $course_id = explode(',',$class['course_id']);
  790. if(!empty($doneLog))
  791. {
  792. $have = explode(',',$doneLog['course_id']);
  793. $checkCourse = [$param['course_id']];
  794. $newCourseArr = array_filter(array_merge($have,$checkCourse));
  795. $GDP = floor((count($newCourseArr) / count($course_id))*100);
  796. $doneLog->done_percent = $GDP;
  797. $doneLog->course_id = implode(',',$newCourseArr);
  798. if($doneLog->save()){
  799. if ($GDP==100) {//累计勋章
  800. Console::call('medal',['class',(string)$employee_id,(string)$root_id]);
  801. //增加课程完成赠送学分
  802. $this->add_studylog($employee_id,$class,$root_id);
  803. }
  804. //完成单个课件增加学习时长
  805. if(!empty($param['study_time'])){
  806. $this->add_studytime($employee_id,$param['class_id'],$param['course_id'],$param['study_time'],$root_id);
  807. }
  808. return json(['code' => 0, 'msg' => '完成本节学习']);
  809. }else{
  810. return json(['code' => 1, 'msg' => '未能完成本节学习']);
  811. }
  812. }else{
  813. $GDP = floor((1 / count($course_id))*100);
  814. if(TrainDoneLog::insert([
  815. 'employee_id' => $employee_id,
  816. 'root_id' => $root_id,
  817. 'org_id' => $token['org_id'],
  818. 'class_id' => $param['class_id'],
  819. 'done_percent' => $GDP,
  820. 'course_id' => $param['course_id'],
  821. 'from'=>$from
  822. ])){
  823. if ($GDP==100) {//累计勋章
  824. Console::call('medal',['class',(string)$employee_id,(string)$root_id]);
  825. //增加课程完成赠送学分
  826. $this->add_studylog($employee_id,$class,$root_id);
  827. }
  828. //完成单个课件增加学习时长
  829. if(!empty($param['study_time'])){
  830. $this->add_studytime($employee_id,$param['class_id'],$param['course_id'],$param['study_time'],$root_id);
  831. }
  832. return json(['code' => 0, 'msg' => '完成本节学习']);
  833. }else{
  834. return json(['code' => 1, 'msg' => '未能完成本节学习']);
  835. }
  836. }
  837. }
  838. /**
  839. * 课件浏览详情+1
  840. */
  841. public function coureseView($course_id,$time=0)
  842. {
  843. $token['root_org'] = $this->rootId;
  844. $token['employee_id'] = $this->employeeId;
  845. $token['uid'] = $this->uid;
  846. $token['org_id'] = Employee::where('id',$this->employeeId)->value('org_id');
  847. $save['con_id'] = $course_id;
  848. $save['time'] = $time;
  849. $save['root_id'] = $token['root_org'];
  850. $save['employee_id'] = $token['employee_id'];
  851. $save['uid'] = $token['uid'];
  852. $save['org_id'] = $token['org_id'];
  853. $save['type'] = 'traincourse';
  854. TrainCourseView::insertGetId($save);
  855. TrainCourse::where(['id'=> $course_id,'root_id'=>$token['root_org']])->inc('view')->update();
  856. return json(['code' => 0, 'data' =>'成功浏览']);
  857. }
  858. //部门列表
  859. public function all_org(){
  860. $token['root_org'] = $this->rootId;
  861. $res = Org::where([['path', 'like', $token['root_org'] . '-%'],['status','=',1]])->field('id,name,pid')->select()->toArray();
  862. $res = $this->tree($res,0,[]);
  863. return json(['code' => 0, 'data' => $res]);
  864. }
  865. //部门人员树
  866. public function tree($data,$pid = 0, $persons)
  867. {
  868. $new_arr = [];
  869. foreach($data as $k => $v){
  870. if($v['pid'] == $pid) {
  871. $persions = isset($persons[$v['id']])?$persons[$v['id']]:[];
  872. $children = $this->tree($data, $v['id'], $persons);
  873. $v['children'] = array_merge_recursive($children,$persions);
  874. if (empty($v['children'])) $v['disabled']=true;
  875. $new_arr[] =$v;
  876. }
  877. }
  878. return $new_arr;
  879. }
  880. /**
  881. * 课程浏览 +1
  882. */
  883. public function classView(){
  884. $class_id = input('class_id', '', 'intval');
  885. $course_id = input('course_id', '', 'intval');
  886. $time = input('time', 0, 'intval');
  887. $token['root_org'] = $this->rootId;
  888. $token['employee_id'] = $this->employeeId;
  889. $token['org_id'] = Employee::where('id',$token['employee_id'])->value('org_id');
  890. $token['uid'] = $this->uid;
  891. $save['course_id'] = $course_id;
  892. $save['class_id'] = $class_id;
  893. $save['time'] = $time;
  894. $save['root_id'] = $token['root_org'];
  895. $save['employee_id'] = $token['employee_id'];
  896. $save['uid'] = $token['uid'];
  897. $save['org_id'] = $token['org_id'];
  898. $save['type'] = 'traincourse';
  899. TrainClassView::insertGetId($save);
  900. TrainCourse::where(['id'=> $course_id,'root_id'=>$token['root_org']])->inc('view')->update();
  901. return json(['code' => 0, 'data' =>'成功浏览']);
  902. }
  903. }