Internal.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace App\Module\Ulogic;
  3. use App\Module\Ulogic\Enum\INTERNAL_TYPE;
  4. /**
  5. * 站内信
  6. *
  7. */
  8. class Internal
  9. {
  10. /**
  11. * 列表
  12. *
  13. * @param $page
  14. * @param $limit
  15. * @param $w
  16. * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
  17. */
  18. public static function list1($page, $limit, $w, $order ='')
  19. {
  20. $q = \App\Module\Ulogic\Model\Internal::query();
  21. if($order){
  22. $q = $q->orderBy($order);
  23. }else{
  24. $q = $q->orderBy('id','desc');
  25. }
  26. if ($w['user_id'] ?? 0) {
  27. $q = $q->where('user_id', '=', $w['user_id']);
  28. }
  29. if ($w['is_read'] ?? '') {
  30. $q = $q->where('is_read', '=', $w['is_read']);
  31. }
  32. return $q->paginate($limit, [ '*' ], '', $page);
  33. }
  34. /**
  35. * 发送消息
  36. *
  37. * @param $user_id
  38. * @param $to_user_id
  39. * @param $content
  40. * @param $app_data
  41. * @param $cate
  42. * @return bool
  43. */
  44. static public function send($user_id, $to_user_id, $content, $app_data, $cate = 0,$admin_id = 0)
  45. {
  46. $model = new \App\Module\Ulogic\Model\Internal();
  47. $model->status = 0;
  48. $model->is_read = 0;
  49. $model->content = $content;
  50. $model->cate = $cate;
  51. $model->from_id = $user_id;
  52. if($user_id){
  53. $model->type1= INTERNAL_TYPE::USER;
  54. }
  55. if(!$user_id){
  56. if($admin_id){
  57. $model->type1= INTERNAL_TYPE::ADMIN;
  58. }else{
  59. $model->type1= INTERNAL_TYPE::SYSTEM;
  60. }
  61. }
  62. $model->admin_id = $admin_id;
  63. $model->user_id = $to_user_id;
  64. $model->data = serialize($app_data);
  65. $model->save();
  66. $model->refresh();
  67. // $model->at_users = '';
  68. if ($model->id > 0) {
  69. return true;
  70. }
  71. return false;
  72. }
  73. /**
  74. * 单条信息
  75. * @param $where
  76. * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|null
  77. */
  78. static public function info($where)
  79. {
  80. return \App\Module\Ulogic\Model\Internal::query()->where($where)->first();
  81. }
  82. /**
  83. * 设置已读
  84. *
  85. * @param $ids
  86. * @return void
  87. */
  88. static public function reads($ids, $user_id = null)
  89. {
  90. $q = \App\Module\Ulogic\Model\Internal::query()->whereIn('id', $ids);
  91. if ($user_id) {
  92. $q = $q->where('user_id', $user_id);
  93. }
  94. $q->update([
  95. 'is_read' => 1
  96. ]);
  97. }
  98. }