where($where)->update(['is_read'=>1,'htime'=>date('Y-m-d H:i:s',time()),'count'=>0]); Cache::rm('messages_'.$doctor); }catch(\Exception $e){ return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]); } } //获取where条件 public static function getwhere($type){ $where = array(); switch($type){ case 1: $where['type'] = array('in','1,3'); break; case 2: $where['type'] = array('in','2,4'); break; case 3: $where['type'] = 1; break; case 4: $where['type'] = array('in','4,5'); break; case 5: $where['type'] = 7; break; }; return $where; } public static function get_messages(){ } // 新增消息 public static function insert($title,$content,$did,$type,$url,$count =1,$aid = ''){ Cache::rm('messages_'.$did); try{ $info['id'] = UUIDs::uuid16(); $info['title'] = $title; $info['content'] = $content; $info['doctor_id'] = $did; $info['type'] = $type; $info['ctime'] = date('Y-m-d H:i:s',time()); $info['is_read'] = 0; $info['status'] = 0; $info['url'] = $url; $info['count'] = $count; $info['application_id'] = $aid; DB::table('messages')->insert($info); }catch(\Exception $e){ return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]); } } // 获取跳转url public static function url($sessionid,$id,$is_remote,$exam_class,$report_id='',$rid=''){ $url = '/remotereport/edit/6?id='.$id.'&is_remote='.$is_remote.'&exam_class='.$exam_class.'&report_id='.$report_id.'&rid='.$rid; return $url; } // 消息未读条数自增 public static function bbs_message($aid,$doctor,$content,$did,$is_remote,$sessionid){ Cache::rm('messages_'.$did); try{ // 对话类查询 $message = DB::table('messages')->where('application_id',$aid)->where('doctor_id',$did)->where('type',7)->where('is_read',0)->find(); if($message['status'] == '0'){ // 未删除 有未读 Db::table('messages')->where('application_id',$aid)->where('doctor_id',$did)->where('type',7)->where('is_read',0)->setInc('count'); Db::table('messages')->where('application_id',$aid)->where('doctor_id',$did)->where('type',7)->where('is_read',0)->update(['content'=>$content]); }elseif($message['status'] == '1'){ // 有未读但已删除 Db::table('messages')->where('application_id',$aid)->where('doctor_id',$did)->where('type',7)->where('is_read',0)->update(['status'=>0,'count'=>1,'content'=>$content]); }elseif(empty($message)){ //没有未读消息 $read = DB::table('messages')->where('application_id',$aid)->where('doctor_id',$did)->where('type',7)->where('is_read',1)->find(); if($read['status'] == '0'){ // 未删除 有已读 变更为未读1条 Db::table('messages')->where('application_id',$aid)->where('doctor_id',$did)->where('type',7)->where('is_read',1)->update(['is_read'=>0,'count'=>1,'content'=>$content]); }elseif($read['status'] == '1'){ // 有已读并且已删除 变更为未读未删除1条 Db::table('messages')->where('application_id',$aid)->where('doctor_id',$did)->where('type',7)->where('is_read',1)->update(['status'=>0,'count'=>1,'is_read'=>0,'content'=>$content]); }else{ //没有改消息 新增消息 $title = '您收到一条新的远程诊断咨询消息'; $type = '7'; $application = DB::table('remote_application')->where('id',$aid)->find(); $exam = DB::table('exams')->where('id',$application['exam_id'])->field('exam_class')->find(); $report = DB::table('report')->where('remote_application_id',$aid)->field('id')->find(); $url = self::url($sessionid,$application['exam_id'],$is_remote,$exam['exam_class'],$report['id']); self::insert($title,$content,$did,$type,$url,$count =1,$aid); } } }catch(\Exception $e){ return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]); } } public static function delete($id){ } }