Message.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace app\common\library;
  3. use think\Db;
  4. use app\common\library\UUIDs;
  5. /**
  6. * 结果整理类
  7. */
  8. class Message {
  9. /*
  10. * 消息已读
  11. * 1,新增远程申请2,远程申请驳回3,远程申请被撤回4,远程诊断接收5,报告已审核6,报告确认7,对话
  12. * type 1为远程进入(发申请和撤回核销) 2为本地进入(驳回和接收申请核销) 3为审核报告(发申请核销)
  13. * 4为确认报告(接收申请和审核报告核销) 5为对话
  14. */
  15. public static function read($doctor,$aid,$type){
  16. try{
  17. $where = self::getwhere($type);
  18. $where['doctor_id'] = $doctor;
  19. $where['application_id'] = $aid;
  20. $where['status'] = '0'; //未删除
  21. $where['is_read'] = '0'; //未读
  22. DB::table('messages')->where($where)->update(['is_read'=>1,'htime'=>date('Y-m-d H:i:s',time())]);
  23. }catch(\Exception $e){
  24. return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
  25. }
  26. }
  27. //获取where条件
  28. public static function getwhere($type){
  29. $where = array();
  30. switch($type){
  31. case 1:
  32. $where['type'] = array('in','1,3');
  33. break;
  34. case 2:
  35. $where['type'] = array('in','2,4');
  36. break;
  37. case 3:
  38. $where['type'] = 1;
  39. break;
  40. case 4:
  41. $where['type'] = array('in','4,5');
  42. break;
  43. case 5:
  44. $where['type'] = 7;
  45. break;
  46. };
  47. return $where;
  48. }
  49. public static function get_messages(){
  50. }
  51. // 新增消息
  52. public static function insert($title,$content,$did,$type,$url,$count =1,$aid = ''){
  53. try{
  54. $info['id'] = UUIDs::uuid16();
  55. $info['title'] = $title;
  56. $info['content'] = $content;
  57. $info['doctor_id'] = $did;
  58. $info['type'] = $type;
  59. $info['ctime'] = date('Y-m-d H:i:s',time());
  60. $info['is_read'] = 0;
  61. $info['status'] = 0;
  62. $info['url'] = $url;
  63. $info['count'] = $count;
  64. $info['application_id'] = $aid;
  65. DB::table('messages')->insert($info);
  66. }catch(\Exception $e){
  67. return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
  68. }
  69. }
  70. // 获取跳转url
  71. public static function url($sessionid,$id,$is_remote,$exam_class,$report_id=''){
  72. $url = 'remotereport/edit/6?sessionid='.$sessionid.'&id='.$id.'&is_remote='.$is_remote.'&exam_class='.$exam_class.'&report_id='.$report_id;
  73. return $url;
  74. }
  75. // 消息未读条数自增
  76. public static function bbs_message($aid,$doctor,$content,$did,$is_remote,$sessionid){
  77. try{
  78. // 对话类查询
  79. $message = DB::table('messages')->where('application_id',$aid)->where('doctor_id',$doctor)->where('type',7)->where('is_read',0)->find();
  80. if($message['status'] == '0'){
  81. // 未删除 有未读
  82. Db::table('messages')->where('application_id',$aid)->where('doctor_id',$doctor)->where('type',7)->where('is_read',0)->setInc('count');
  83. }elseif($message['status'] == '1'){
  84. // 有未读但已删除
  85. Db::table('messages')->where('application_id',$aid)->where('doctor_id',$doctor)->where('type',7)->where('is_read',0)->update(['status'=>0,'count'=>1]);
  86. }else{
  87. //没有未读消息
  88. $read = DB::table('messages')->where('application_id',$aid)->where('doctor_id',$doctor)->where('type',7)->where('is_read',1)->find();
  89. if($read['status'] == '0'){
  90. // 未删除 有已读 变更为未读1条
  91. Db::table('messages')->where('application_id',$aid)->where('doctor_id',$doctor)->where('type',7)->where('is_read',1)->update(['is_read'=>0,'count'=>1]);
  92. }elseif($read['status'] == '1'){
  93. // 有已读并且已删除 变更为未读未删除1条
  94. Db::table('messages')->where('application_id',$aid)->where('doctor_id',$doctor)->where('type',7)->where('is_read',1)->update(['status'=>0,'count'=>1,'is_read'=>0]);
  95. }else{
  96. //没有改消息 新增消息
  97. $title = '您收到一条远程诊断咨询消息';
  98. $type = '7';
  99. $application = DB::table('remote_application')->where('id',$aid)->find();
  100. $exam = DB::table('exams')->where('id',$application['exam_id'])->field('exam_class')->find();
  101. $report = DB::table('report')->where('remote_application_id',$aid)->field('id')->find();
  102. $url = self::url($sessionid,$application['exam_id'],$is_remote,$exam['exam_class'],$report['id']);
  103. self::insert($title,$content,$did,$type,$url,$count =1,$aid);
  104. }
  105. }
  106. }catch(\Exception $e){
  107. return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
  108. }
  109. }
  110. public static function delete($id){
  111. }
  112. }