message.service.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. class messageService{
  3. /**
  4. * 消息列表
  5. * $data = array("user_id"=>$user_id,"page"=>$page,"page_size"=>$page_size);
  6. * return array("rs_count"=>$rs_count,"list"=>$list,"page"=>$page);
  7. */
  8. public function getlist($data){
  9. $user_id = (int)$data['user_id'];
  10. $page = (int)$data['page'];
  11. $page_size = (int)$data['page_size'];
  12. $limit = (($page-1)*$page_size).",".$page_size;
  13. $rs_count = $GLOBALS['db']->getOne("SELECT count(*) FROM ".DB_PREFIX."user_notice WHERE user_id=".$user_id,true,true);
  14. $list = array();
  15. $pages['page'] = $page;
  16. $pages['has_next'] = 0;
  17. if($rs_count > 0){
  18. $list = $GLOBALS['db']->getAll("SELECT * FROM ".DB_PREFIX."user_notice WHERE user_id=".$user_id." ORDER BY id desc limit ".$limit,true,true);
  19. foreach($list as $k=>$v){
  20. if(intval($v['send_id'])){
  21. $head_image = $GLOBALS['db']->getOne("select head_image from ".DB_PREFIX."user where id=".intval($v['send_id']),true,true);
  22. if($head_image){
  23. $list[$k]['send_user_avatar'] = get_spec_image($head_image);
  24. }else{
  25. $list[$k]['send_user_avatar'] = '';
  26. }
  27. }else{
  28. $list[$k]['send_user_avatar'] = '';
  29. }
  30. $list[$k]['content'] = emoji_decode($v['content']);
  31. }
  32. $total = ceil($rs_count/$page_size);
  33. if($total > $page)
  34. $pages['has_next'] = 1;
  35. }
  36. return array("rs_count"=>$rs_count,"list"=>$list,"page"=>$pages);
  37. }
  38. /**
  39. * 消息推送
  40. * $data = array("send_type"=>$send_type,"user_ids"=>$user_ids,"send_user_id"=>$send_user_id,"send_status"=>$send_status,"content"=>$content);
  41. * return array("status"=>$status);
  42. */
  43. public function send($data){
  44. $send_type = trim($data['send_type']);//消息类型
  45. $user_ids = $data['user_ids'];//推送会员,array(1,2,3,4,5);
  46. $send_user_id = (int)$data['send_user_id'];//发送人
  47. $send_status = (int)$data['send_status'];//0 仅消息,1 推送, 2 消息+推送
  48. $content = trim($data['content']);//推送内容
  49. if(empty($send_type)){
  50. $root['status'] = 10021;
  51. return $root;
  52. }
  53. if(sizeof($user_ids)<=0){
  54. $root['status'] = 10033;
  55. return $root;
  56. }
  57. $create_time = get_gmtime();
  58. $message['type'] = $send_type;
  59. $message['send_id'] = $send_user_id;
  60. $message['content'] = $content;
  61. $message['create_time'] = $create_time;
  62. $message['create_date'] = to_date($create_time,'Y-m-d H:i:s');
  63. $message['create_time_ymd'] = to_date($create_time,'Y-m-d');
  64. $message['create_time_y'] = to_date($create_time,'Y');
  65. $message['create_time_m'] = to_date($create_time,'m');
  66. $message['create_time_d'] = to_date($create_time,'d');
  67. $message['is_read'] = 0;
  68. $message['send_user_name'] = '官方';
  69. if($send_user_id){
  70. $send_user_name = $GLOBALS['db']->getOne("select nick_name from ".DB_PREFIX."user where id=".$send_user_id,true,true);
  71. if($send_user_name!=''){
  72. $message['send_user_name'] = $send_user_name;
  73. }
  74. }
  75. $count = 0;
  76. foreach($user_ids as $v) {
  77. //消息入库
  78. if ($send_status == 0 || $send_status == 2) {
  79. $message['user_id'] = (int)$v;
  80. $GLOBALS['db']->autoExecute(DB_PREFIX . "user_notice", $message, "INSERT");
  81. if ($GLOBALS['db']->insert_id()) {
  82. $count++;
  83. }
  84. }
  85. }
  86. if($count){
  87. $root['status'] = 1;
  88. }else{
  89. $root['status'] = 10022;
  90. }
  91. return $root;
  92. }
  93. /**
  94. * 删除消息
  95. * $data = array("id"=>$id,"user_id"=>$user_id);
  96. * return array("status"=>$status);
  97. */
  98. public function del($data){
  99. $id = (int)$data['id'];//收货地址id
  100. $user_id = (int)$data['user_id'];//所有用户id
  101. $GLOBALS['db']->query("delete from ".DB_PREFIX."user_notice where id = ".$id." and user_id = ".$user_id);
  102. if($GLOBALS['db']->affected_rows()>0){
  103. $root['status'] = 1;
  104. }else{
  105. $root['status'] = 10023;
  106. }
  107. return $root;
  108. }
  109. /**
  110. * IM推送服务
  111. * $data = array("pai_id"=>$pai_id,"page"=>$page,"page_size"=>$page_size);
  112. * return array("rs_count"=>$rs_count,"info"=>$info,"joins"=>$joins,"page"=>$page);
  113. */
  114. public function paiinfo($data){
  115. $pai_id = (int)$data['pai_id'];
  116. $page = (int)$data['page'];
  117. $page_size = (int)$data['page_size'];
  118. $limit = (($page-1)*$page_size).",".$page_size;
  119. $joins = array();
  120. $rs_count = 0;
  121. $pages['page'] = $page;
  122. $pages['has_next'] = 0;
  123. $info = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."pai_goods where id = ".$pai_id,true,true);
  124. if($info){
  125. $rs_count = $GLOBALS['db']->getOne("SELECT count(*) FROM ".DB_PREFIX."pai_join WHERE pai_id=".$pai_id,true,true);
  126. if($rs_count > 0){
  127. $joins = $GLOBALS['db']->getAll("SELECT * FROM ".DB_PREFIX."pai_join WHERE pai_id=".$pai_id." ORDER BY pai_diamonds desc limit ".$limit,true,true);
  128. foreach($joins as $k=>$v){
  129. if($v['consignee_district']!=''){
  130. $joins[$k]['consignee_district'] = json_decode($v['consignee_district'],true);
  131. if($joins[$k]['consignee_district']==''){
  132. $joins[$k]['consignee_district'] = array();
  133. }
  134. }else{
  135. $joins[$k]['consignee_district'] = array();
  136. }
  137. }
  138. $total = ceil($rs_count/$page_size);
  139. if($total > $page)
  140. $pages['has_next'] = 1;
  141. }
  142. }
  143. return array("info"=>$info,"joins"=>$joins,"page"=>$pages,"rs_count"=>$rs_count);
  144. }
  145. /**
  146. * 消息内容
  147. * $data = array("user_id"=>$user_id,"id"=>$id);
  148. * return array("status"=>$status,"data"=>$data);
  149. */
  150. public function info($data){
  151. $status = 1;
  152. $user_id = (int)$data['user_id'];
  153. $id = (int)$data['id'];
  154. $info = $GLOBALS['db']->getRow("SELECT * FROM ".DB_PREFIX."user_notice WHERE user_id=".$user_id." and id = ".$id,true,true);
  155. if(empty($info)){
  156. $status = 10001;
  157. }
  158. $info['content'] = emoji_decode($info['content']);
  159. return array("status"=>$status,"data"=>$info);
  160. }
  161. }
  162. ?>