123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- <?php
- namespace app\common\library;
- use think\Cache;
- use think\Db;
- use app\common\library\UUIDs;
- /**
- * 结果整理类
- */
- class Message {
- /*
- * 消息已读
- * 1,新增远程申请2,远程申请驳回3,远程申请被撤回4,远程诊断接收5,报告已审核6,报告确认7,对话
- * type 1为远程进入(发申请和撤回核销) 2为本地进入(驳回和接收申请核销) 3为审核报告(发申请核销)
- * 4为确认报告(接收申请和审核报告核销) 5为对话
- */
- public static function read($doctor,$aid,$type){
- try{
- $where = self::getwhere($type);
- $where['doctor_id'] = $doctor;
- $where['application_id'] = $aid;
- $where['status'] = '0'; //未删除
- $where['is_read'] = '0'; //未读
- DB::table('messages')->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){
- }
- }
|