Data.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. namespace Message\Lib;
  3. use Dever;
  4. use Passport\Src\User;
  5. use Passport\Src\Login;
  6. class Data
  7. {
  8. public function __construct()
  9. {
  10. # 获取用户信息
  11. //$user = new User();
  12. //$this->user = $user->data();
  13. }
  14. /**
  15. * 获取我的消息
  16. *
  17. * @return mixed
  18. */
  19. public function read($uid, $type = false, $update = false, $status = false, $project = 1)
  20. {
  21. if (!$uid) {
  22. Dever::alert('错误的用户信息');
  23. }
  24. $prefix = defined('DEVER_PROJECT') && DEVER_PROJECT != 'default' ? DEVER_PROJECT . '_' : '';
  25. $outbox = $prefix . 'message_outbox';
  26. $inbox = $prefix . 'message_inbox';
  27. $where = ' and a.state = 1 and a.project_id = ' . $project;
  28. $where .= ' and a.type <= 10';
  29. # 读取outbox里的数据
  30. $sql = 'select a.name,a.content,a.id,a.type,a.uid,a.project_id from '.$outbox.' as a where not exists(select oid from '.$inbox.' where a.id = oid and uid = '.$uid.')' . $where . ' ';
  31. $state = Dever::db('message/inbox')->query($sql);
  32. $outbox = $state->fetchAll();
  33. if ($outbox) {
  34. foreach ($outbox as $k => $v) {
  35. $insert['add_uid'] = $uid;
  36. $insert['add_oid'] = $v['id'];
  37. $insert['add_status'] = 1;
  38. $insert['add_project_id'] = $v['project_id'];
  39. $insert['add_type'] = $v['type'];
  40. //$insert['add_site'] = $v['site'];
  41. $insert['add_from_uid'] = $v['uid'];
  42. $insert['add_name'] = $v['name'];
  43. $insert['add_content'] = $v['content'];
  44. Dever::load('message/inbox-insert', $insert);
  45. }
  46. }
  47. if ($project) {
  48. $param['option_project_id'] = $project;
  49. }
  50. if ($type) {
  51. $param['option_type'] = $type;
  52. }
  53. $param['option_uid'] = $uid;
  54. if ($status > 0) {
  55. $param['option_status'] = $status;
  56. return Dever::load('message/inbox-total', $param);
  57. }
  58. $data = Dever::load('message/inbox-getAll', $param);
  59. if ($update) {
  60. foreach ($data as $k => $v) {
  61. Dever::load('message/inbox-update', array('where_id' => $v['id'], 'set_status' => 2));
  62. }
  63. }
  64. return $data;
  65. }
  66. /**
  67. * 查看我的新消息
  68. *
  69. * @return mixed
  70. */
  71. public function num($uid, $project = 1)
  72. {
  73. return $this->read($uid, false, false, 1, $project);
  74. }
  75. /**
  76. * 查看我的消息
  77. *
  78. * @return mixed
  79. */
  80. public function view($uid, $id)
  81. {
  82. if ($id > 0) {
  83. $info = Dever::load('message/inbox-one', array('option_uid' => $uid, 'option_id' => $id));
  84. if ($info) {
  85. Dever::load('message/inbox-update', array('where_id' => $id, 'set_status' => 2));
  86. $data = Dever::load('message/inbox-one', $id);
  87. return $data;
  88. }
  89. }
  90. Dever::alert('错误的消息信息');
  91. }
  92. /**
  93. * 推送消息
  94. *
  95. * @return mixed
  96. */
  97. public function push($uid, $to_uid, $name, $content, $type = 11, $project = 1)
  98. {
  99. if (!is_numeric($type)) {
  100. Dever::alert('错误的消息类型');
  101. }
  102. if ($type > 10 && !$uid) {
  103. Dever::alert('错误的发件人id');
  104. }
  105. if ($type > 10 && !$to_uid) {
  106. Dever::alert('错误的收件人id');
  107. }
  108. if (!$content) {
  109. Dever::alert('错误的消息内容');
  110. }
  111. if (is_numeric($uid) && $content && is_numeric($type)) {
  112. if ($type < 10) {
  113. $uid = -1;
  114. }
  115. $data['add_uid'] = $uid;
  116. $data['add_name'] = $name;
  117. $data['add_content'] = $content;
  118. $data['add_type'] = $type;
  119. $data['add_project_id'] = $project;
  120. $id = Dever::load('message/outbox-insert', $data);
  121. if ($id > 0) {
  122. if ($to_uid) {
  123. $to_uid = explode(',', $to_uid);
  124. foreach ($to_uid as $k => $v) {
  125. $insert['add_uid'] = $v;
  126. $insert['add_oid'] = $id;
  127. $insert['add_status'] = 1;
  128. $insert['add_type'] = $data['add_type'];
  129. $insert['add_project_id'] = $project;
  130. $insert['add_from_uid'] = $data['add_uid'];
  131. $insert['add_name'] = $data['add_name'];
  132. $insert['add_content'] = $data['add_content'];
  133. //$insert['add_origin'] = $origin;
  134. Dever::load('message/inbox-insert', $insert);
  135. //这里可以设置发送push
  136. }
  137. }
  138. }
  139. }
  140. }
  141. }