Data.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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)
  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';
  28. $where .= ' and a.type <= 10';
  29. # 读取outbox里的数据
  30. $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 . ' ';
  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_type'] = $v['type'];
  39. //$insert['add_site'] = $v['site'];
  40. $insert['add_from_uid'] = $v['uid'];
  41. $insert['add_name'] = $v['name'];
  42. $insert['add_content'] = $v['content'];
  43. Dever::load('message/inbox-insert', $insert);
  44. }
  45. }
  46. if ($type) {
  47. $param['option_type'] = $type;
  48. }
  49. $param['option_uid'] = $uid;
  50. if ($status > 0) {
  51. $param['option_status'] = $status;
  52. return Dever::load('message/inbox-total', $param);
  53. }
  54. $data = Dever::load('message/inbox-getAll', $param);
  55. if ($update) {
  56. foreach ($data as $k => $v) {
  57. Dever::load('message/inbox-update', array('where_id' => $v['id'], 'set_status' => 2));
  58. }
  59. }
  60. return $data;
  61. }
  62. /**
  63. * 查看我的新消息
  64. *
  65. * @return mixed
  66. */
  67. public function num($uid)
  68. {
  69. return $this->read($uid, false, false, 1);
  70. }
  71. /**
  72. * 查看我的消息
  73. *
  74. * @return mixed
  75. */
  76. public function view($uid, $id)
  77. {
  78. if ($id > 0) {
  79. $info = Dever::load('message/inbox-one', array('option_uid' => $uid, 'option_id' => $id));
  80. if ($info) {
  81. Dever::load('message/inbox-update', array('where_id' => $id, 'set_status' => 2));
  82. $data = Dever::load('message/inbox-one', $id);
  83. return $data;
  84. }
  85. }
  86. Dever::alert('错误的消息信息');
  87. }
  88. /**
  89. * 推送消息
  90. *
  91. * @return mixed
  92. */
  93. public function push($uid, $to_uid, $name, $content, $type = 1)
  94. {
  95. //$site = intval(Dever::input('site', -1));
  96. if (!is_numeric($type)) {
  97. Dever::alert('错误的消息类型');
  98. }
  99. /*
  100. if(!is_numeric($site))
  101. {
  102. Dever::alert('错误的站点ID');
  103. }
  104. */
  105. if ($type > 10 && !is_numeric($uid)) {
  106. Dever::alert('错误的发件人id');
  107. }
  108. if ($type > 10 && !$to_uid) {
  109. Dever::alert('错误的收件人id');
  110. }
  111. if (!$content) {
  112. Dever::alert('错误的消息内容');
  113. }
  114. if (is_numeric($uid) && $content && is_numeric($type)) {
  115. if ($type < 10) {
  116. $uid = -1;
  117. }
  118. $data['add_uid'] = $uid;
  119. $data['add_name'] = $name;
  120. $data['add_content'] = $content;
  121. $data['add_type'] = $type;
  122. //$data['add_site'] = $site;
  123. $id = Dever::load('message/outbox-insert', $data);
  124. if ($id > 0) {
  125. if ($to_uid) {
  126. $to_uid = explode(',', $to_uid);
  127. foreach ($to_uid as $k => $v) {
  128. $insert['add_uid'] = $v;
  129. $insert['add_oid'] = $id;
  130. $insert['add_status'] = 1;
  131. $insert['add_type'] = $data['add_type'];
  132. //$insert['add_site'] = $site;
  133. $insert['add_from_uid'] = $data['add_uid'];
  134. $insert['add_name'] = $data['add_name'];
  135. $insert['add_content'] = $data['add_content'];
  136. //$insert['add_origin'] = $origin;
  137. Dever::load('message/inbox-insert', $insert);
  138. //这里可以设置发送push
  139. }
  140. }
  141. }
  142. }
  143. }
  144. }