MessageRead.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Support\Facades\DB;
  4. class MessageRead extends BaseModel
  5. {
  6. protected $table = "message_read";
  7. public $timestamps = false;
  8. function getlist($id)
  9. {
  10. $data = $this->where('account_identity', $id)->get();
  11. if (!$data) {
  12. return -4010010022; //没有数据
  13. }
  14. return $data->toArray();
  15. }
  16. //添加消息数据
  17. function addMessage($data)
  18. {
  19. $res = $this->insert($data);
  20. if (!$res) {
  21. return -6030001222;
  22. }
  23. return 1;
  24. }
  25. //查询消息
  26. function Messagelist($id, $admin_id)
  27. {
  28. $data = $this->where('message_id', $id)->where('account_identity', $admin_id)->first();
  29. if (!$data) {
  30. return -4010010022; //没有数据
  31. }
  32. return 1;
  33. }
  34. function updateMsg($id, $admin_id, $data)
  35. {
  36. $res = $this->where('message_id', $id)->where('account_identity', $admin_id)->update($data);
  37. if (!$res) {
  38. return -4010011122;
  39. }
  40. return 1;
  41. }
  42. //统计某个管理员的未读信息
  43. function countNoReade($id)
  44. {
  45. $sql = "SELECT count(*) as num FROM message WHERE type=4 and id not in( SELECT message_id from message_read WHERE account_identity = '" . $id . "' GROUP BY message_id)";
  46. $num=DB::select($sql);
  47. // var_dump($num);die;
  48. return $num[0]->num;
  49. }
  50. }