MessageController.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. class MessageController extends AdminController{
  3. public function actionIndex()
  4. {
  5. $status = array(
  6. 1 => array('name' => '待处理')
  7. );
  8. $user_ids = $usernames = array();
  9. $sys_user_id = Yii::app()->params['kefu_user']; //系统客服账号
  10. array_push($user_ids,new MongoId($sys_user_id));
  11. $admin_info = $this->getAdminInfo(); //当前后台管理账号
  12. if($admin_info){
  13. foreach($admin_info['fake_users'] as $fake_user){
  14. array_push($user_ids,$fake_user);
  15. }
  16. }
  17. if($user_ids){
  18. $model = new ZUser();
  19. $users = $model->getUserInfo($user_ids,array('id',"user_name"));
  20. if($users){
  21. foreach($users as $user){
  22. $usernames[(string)$user["_id"]] = array(
  23. 'name' => $user['user_name']
  24. );
  25. }
  26. }
  27. }
  28. $user_names = CommonFn::getComboboxData($usernames, 10, true,10);
  29. $status = CommonFn::getComboboxData($status, 10, true,10);
  30. $this->render('index', array(
  31. 'status' => $status,
  32. 'usernames' => $user_names
  33. ));
  34. }
  35. public function actionList(){
  36. $params = CommonFn::getPageParams();
  37. $page = Yii::app()->request->getParam('page',1);
  38. $search = Yii::app()->request->getParam('search','');
  39. $filter_status = Yii::app()->request->getParam('filter_status',0);
  40. $filter_user = Yii::app()->request->getParam('filter_user','10'); // 选择全部的默认值
  41. $from_user_ids = array();
  42. $criteria = new EMongoCriteria($params);
  43. if ($search != ''){
  44. if (CommonFn::isMongoId($search)){
  45. $from_user_ids = array(new MongoId($search)); //当搜索项为MongoID时,重置user_ids
  46. } else {
  47. $user_regex = new MongoRegex('/'.$search.'/');
  48. $user_criteria = new EMongoCriteria();
  49. $user_criteria->user_name("==", $user_regex);
  50. $user = RUser::model()->findAll($user_criteria);
  51. foreach ($user as $key => $value) {
  52. array_push($from_user_ids, $value->_id);
  53. }
  54. }
  55. $criteria->from_user('in', $from_user_ids);
  56. }
  57. $to_user_ids = array();
  58. if($filter_user != '10'){
  59. array_push($to_user_ids,new MongoId($filter_user));
  60. }
  61. //默认为系统客服账号以及当前账号的马甲号
  62. if(empty($to_user_ids) && empty($from_user_ids)){
  63. array_push($to_user_ids,new MongoId(Yii::app()->params['kefu_user']));
  64. $admin_info = $this->getAdminInfo(); //当前后台管理账号
  65. if($admin_info){
  66. foreach($admin_info['fake_users'] as $fake_user){
  67. array_push($to_user_ids,$fake_user);
  68. }
  69. }
  70. }
  71. if (!empty($to_user_ids)) {
  72. $criteria->user('in',$to_user_ids);
  73. }
  74. $criteria->type("==",'message');
  75. if($filter_status == 1){
  76. $criteria->no_read_count(">",0);
  77. }
  78. $cursor = ActionCat::model()->findAll($criteria);
  79. $total = $cursor->count();
  80. $rows = CommonFn::getRowsFromCursor($cursor);
  81. $parsedRows = ActionCat::model()->parse($rows);
  82. echo CommonFn::composeDatagridData($parsedRows, $total);
  83. }
  84. public function actionGetUserMsgList(){
  85. $from_user_id = Yii::app()->getRequest()->getParam("from_user_id",'');
  86. $to_user_id = Yii::app()->getRequest()->getParam("to_user_id",'');;
  87. $page = Yii::app()->request->getParam('page',1);
  88. if(!$from_user_id || !$to_user_id){
  89. return CommonFn::returnInfo(false,CommonFn::getMessage('user','id_not_exist'),array(),201);
  90. }
  91. $criteria = new EMongoCriteria();
  92. $criteria->from_user('in', array(new MongoId($to_user_id),new MongoId($from_user_id)));
  93. $criteria->to_user('in', array(new MongoId($to_user_id),new MongoId($from_user_id)));
  94. $criteria->status('==', 1);
  95. $cursor = Message::model()->findAll($criteria);
  96. $total = $cursor->count();
  97. $model = new ZMessage();
  98. $data['page'] = $page;
  99. $data['from_user'] = $to_user_id;
  100. $data['to_user'] = $from_user_id;
  101. $result = $model->readMessage($data);
  102. $sModel = new Message();
  103. $msg_list = array();
  104. foreach($result['data']['messages'] as $key => $row){
  105. $row['html'] = $sModel->generateMsgHtml($row['type'],$row);
  106. $row['from_user']['avatar'] = CommonFn::getQiniuImage($row['from_user']['avatar'],50,50);
  107. $msg_list[] = $row;
  108. }
  109. $msg_list = array_reverse($msg_list);
  110. $data = array(
  111. 'msg_list' => $msg_list,
  112. 'total' => $total
  113. );
  114. echo json_encode($data);
  115. Yii::app()->end();
  116. }
  117. public function actionUnReadCount(){
  118. $user_ids = array();
  119. $admin_info = $this->getAdminInfo(); //当前后台管理账号
  120. if($admin_info){
  121. foreach($admin_info['fake_users'] as $fake_user){
  122. array_push($user_ids,$fake_user);
  123. }
  124. }
  125. $list = new ARedisList('admin_no_read_reply_'.$admin_info['_id']);
  126. $post_unread_count = $list->getCount();
  127. // $criteria = new EMongoCriteria();
  128. // $criteria->type("==",'message');
  129. // $criteria->no_read_count("!=",0);
  130. // $criteria->user('in',$user_ids);
  131. // $unread = ActionCat::model()->count($criteria);
  132. // echo CJSON::encode(array('count' => $unread,'post_unread_count'=>$post_unread_count));
  133. echo CJSON::encode(array('count' => 0,'post_unread_count'=>$post_unread_count));
  134. Yii::app()->end();
  135. }
  136. public function actionPush(){
  137. $title = Yii::app()->request->getParam('title', '');
  138. $content = Yii::app()->request->getParam('content', '');
  139. $url = Yii::app()->request->getParam('url', '');
  140. $stamp = uniqid();
  141. $gt_content = [
  142. 'title' => $title,
  143. 'content' => $content,
  144. 'type' => 'custom_url',
  145. 'data' => [ "url"=>$url],
  146. 'stamp' => $stamp
  147. ];
  148. $gt_content = json_encode($gt_content,JSON_UNESCAPED_SLASHES );
  149. $pay_load = json_encode(['t'=>'custom_url',"url"=>$url,'stamp' => $stamp],JSON_UNESCAPED_SLASHES );
  150. if($title && $url){
  151. echo '消息内容:'.$gt_content.'<br/>';
  152. echo 'Message:'.$title.$content.'<br/>';
  153. echo 'pay_load:'.$pay_load.'<br/>';
  154. die();
  155. }
  156. $this->renderPartial('pushparam',array());
  157. }
  158. }