Data.php 5.0 KB

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