MessageModel.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. namespace app\api\model\message;
  3. use app\api\model\ZskkDefaultModel;
  4. use think\facade\Log;
  5. class MessageModel extends ZskkDefaultModel {
  6. protected $connection = 'db_config_public';
  7. protected $table= 'messages';
  8. protected $logName = "MessageModel";
  9. public function getMessageList($params,$id)
  10. {
  11. $list = $this
  12. ->where('doctor_id', $id)
  13. ->where('status', 0)
  14. ->page($params['page'],$params['num'])
  15. ->order('createdAt desc,is_read asc')
  16. // ->field('doctor_id,status,institution_id,department_id,url,application_id', true)
  17. ->select();
  18. $total = $this
  19. ->where('doctor_id', $id)
  20. ->where('status', 0)
  21. ->count();
  22. return ['total'=>$total, 'list'=>$list];
  23. }
  24. public function readMessage($id)
  25. {
  26. $res = $this
  27. ->where('doctor_id',$id)
  28. ->update(['is_read'=>1]);
  29. return $res;
  30. }
  31. public function unReadMessage($id,$insId)
  32. {
  33. $res = $this
  34. ->where("(institution_id='$insId' and doctor_id is null) or doctor_id='$id'")
  35. ->where('is_read',0)
  36. ->where('status',0)
  37. ->count();
  38. return $res;
  39. }
  40. public function getUnReadList($id)
  41. {
  42. $res = $this
  43. ->where('institution_id',$id)
  44. ->where('is_read',0)
  45. ->where('status',0)
  46. ->where('type',1)
  47. // ->where('notice',0)
  48. ->count();
  49. return $res;
  50. }
  51. public function noticeUnread($id)
  52. {
  53. // $res = $this
  54. // ->where('doctor_id',$id)
  55. // ->where('type',1)
  56. // ->where('notice',0)
  57. // ->update(['notice'=>1]);
  58. // return $res;
  59. }
  60. public function getAppUnread($id,$insId)
  61. {
  62. $info = $this->where('is_read',0)
  63. // ->where('notice',0)
  64. ->where("(institution_id='$insId' and doctor_id is null) or doctor_id='$id'")
  65. ->field("count(*) as count,application_id")
  66. ->group('application_id')
  67. ->select();
  68. return $info;
  69. }
  70. public function delReadMessage($id)
  71. {
  72. $info = $this
  73. ->where('doctor_id', $id)
  74. ->where('is_read', 1)
  75. ->update(['status'=>1]);
  76. return $info;
  77. }
  78. public function delAllMessage($id)
  79. {
  80. $info = $this
  81. ->where('doctor_id', $id)
  82. ->update(['status'=>1]);
  83. return $info;
  84. }
  85. public function read($id)
  86. {
  87. $res = $this
  88. ->where('id',$id)
  89. ->update(['is_read'=>1]);
  90. return $res;
  91. }
  92. public function getInfo($id)
  93. {
  94. $info = $this
  95. ->where('id',$id)
  96. ->field('title,content,application_id,is_read,exam_id,is_remote')
  97. ->find();
  98. $this->where('id',$id)
  99. ->update(['is_read'=>1]);
  100. return $info;
  101. }
  102. public function deleteone($id)
  103. {
  104. $info = $this
  105. ->where('id',$id)
  106. ->update(['status'=>1]);
  107. return $info;
  108. }
  109. public function getSpecialMessage($institution)
  110. {
  111. $message = $this->where('institution_id',$institution)->where('type',10)->where('status',0)->value('content');
  112. return $message;
  113. }
  114. }