Message.php 5.5 KB

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