chat.action.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | FANWE 直播系统
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2011 http://www.fanwe.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: 云淡风轻(1956838968@qq.com)
  8. // +----------------------------------------------------------------------
  9. class chatCModule extends baseCModule
  10. {
  11. //推荐
  12. public function index()
  13. {
  14. if(!$GLOBALS['user_info']){
  15. $root['error'] = "用户未登陆,请先登陆.";
  16. $root['status'] = 0;
  17. api_ajax_return($root);
  18. }
  19. $page = intval($_REQUEST['page'])?intval($_REQUEST['page']):1;
  20. $page_size = 6;
  21. $limit = (($page-1) * $page_size) . "," . $page_size;
  22. $root = array(
  23. 'has_next'=>1,
  24. 'page'=>$page,
  25. 'status'=>1,
  26. 'error'=>''
  27. );
  28. $user_list = $GLOBALS['db']->getAll("select id as user_id,head_image,city,nick_name from ".DB_PREFIX."user where weibo_count>0 or is_authentication = 2 limit $limit");
  29. foreach($user_list as $k=>$v){
  30. if($v){
  31. $user_list[$k]['head_image'] = deal_weio_image($v['head_image'],'head_image');
  32. if(!$v['city']){
  33. $user_list[$k]['city'] = '喵星';
  34. }
  35. }
  36. }
  37. $root['user_list'] = $user_list;
  38. if(count($user_list)==$page_size){
  39. $root['has_next'] = 1;
  40. }else{
  41. $root['has_next'] = 0;
  42. }
  43. $user_id = $GLOBALS['user_info']['id'];
  44. $sql = "select count(*) from ".DB_PREFIX."weibo_comment as com left join ".DB_PREFIX."weibo as wei on com.weibo_id = wei.id
  45. where ((com.to_user_id = $user_id and com.user_id != $user_id) or wei.user_id = $user_id) and com.is_read = 0 and com.is_del = 0";
  46. $comment_count = $GLOBALS['db']->getOne($sql);
  47. // log_result($sql);
  48. $root['comment_count'] = intval($comment_count);
  49. api_ajax_return($root);
  50. }
  51. //评论列表
  52. public function my_comment(){
  53. if(!$GLOBALS['user_info']){
  54. $root['error'] = "用户未登陆,请先登陆.";
  55. $root['status'] = 0;
  56. api_ajax_return($root);
  57. }
  58. $user_id = $GLOBALS['user_info']['id'];
  59. $page = intval($_REQUEST['page'])?intval($_REQUEST['page']):1;
  60. $page_size = 20;
  61. $limit = (($page-1) * $page_size) . "," . $page_size;
  62. $root = array(
  63. 'has_next'=>1,
  64. 'page'=>$page,
  65. 'status'=>1,
  66. 'error'=>''
  67. );
  68. $sql = "select com.comment_id,com.content,com.user_id,com.type as comment_type,u.nick_name,u.head_image,com.create_time,com.weibo_id,w.user_id as weibo_user_id,us.nick_name as weibo_user_name,us.head_image as weibo_head_image,w.photo_image as weibo_photo_image,w.data as weibo_images,w.type as weibo_type,w.content as weibo_content from ".DB_PREFIX."weibo_comment as com
  69. left join ".DB_PREFIX."user as u on com.user_id = u.id
  70. left join ".DB_PREFIX."weibo as w on w.id = com.weibo_id
  71. left join ".DB_PREFIX."user as us on w.user_id = us.id
  72. where ((com.to_user_id = $user_id and com.user_id != $user_id) or w.user_id = $user_id) and com.type = 1 order by com.create_time desc limit $limit";
  73. $comment_list = $GLOBALS['db']->getAll($sql);
  74. foreach($comment_list as $k=>$v){
  75. if($v){
  76. $has_first = 0;
  77. $comment_list[$k]['head_image'] = deal_weio_image($v['head_image'],'head_image');
  78. if($v['weibo_photo_image']){
  79. $comment_list[$k]['weibo_photo_image'] = deal_weio_image($v['weibo_photo_image']);
  80. $has_first = 1;
  81. }
  82. if($v['weibo_images']){
  83. $weibo_images = unserialize($v['weibo_images']);
  84. $comment_list[$k]['weibo_images'] = $weibo_images;
  85. if(!$has_first){
  86. if($weibo_images[0]['is_model']){
  87. $comment_list[$k]['weibo_photo_image'] =deal_weio_image($v['weibo_head_image'],'head_image') ;
  88. }else{
  89. $comment_list[$k]['weibo_photo_image'] = $weibo_images[0]['url'];
  90. }
  91. }
  92. }
  93. unset( $comment_list[$k]['weibo_images']);
  94. unset( $comment_list[$k]['weibo_head_image']);
  95. }else{
  96. unset( $comment_list[$k]);
  97. }
  98. }
  99. $root['comment_list'] = $comment_list;
  100. if(count($comment_list)==$page_size){
  101. $root['has_next'] = 1;
  102. }else{
  103. $root['has_next'] = 0;
  104. }
  105. //设置已经读取
  106. $sql = "select com.comment_id from ".DB_PREFIX."weibo_comment as com left join ".DB_PREFIX."weibo as wei on com.weibo_id = wei.id
  107. where ((com.to_user_id = $user_id and com.user_id != $user_id) or wei.user_id = $user_id) and com.is_read = 0 ";
  108. $comment_list = $GLOBALS['db']->getAll($sql);
  109. $comment_ids = array();
  110. foreach($comment_list as $k=>$v){
  111. if($v['comment_id']){
  112. $comment_ids[] = $v['comment_id'];
  113. }
  114. }
  115. if(count($comment_ids)>0){
  116. $GLOBALS['db']->query("update ".DB_PREFIX."weibo_comment set is_read = 1 where comment_id in (".implode(',',$comment_ids).") ");
  117. }
  118. api_ajax_return($root);
  119. }
  120. }
  121. ?>