RMessageController.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. /**
  3. * 用户私信管理页面
  4. * @author zhouxuchen 2016-01-07
  5. */
  6. class RMessageController extends AdminController {
  7. public function actionIndex() {
  8. $status_option = Message::$status_option;
  9. $status = CommonFn::getComboboxData($status_option, 1, true, 100);
  10. $type_option = Message::$type_option;
  11. $type = CommonFn::getComboboxData($type_option, 'all', true, 'all');
  12. $data['status'] = $status;
  13. $data['type'] = $type;
  14. $this->render('index', $data);
  15. }
  16. public function actionList() {
  17. $params = CommonFn::getPageParams();
  18. $search = Yii::app()->request->getParam('search', '');
  19. $search_from = Yii::app()->request->getParam('search_from', '');
  20. $search_to = Yii::app()->request->getParam('search_to', '');
  21. $filter_start = Yii::app()->request->getParam('start', '');
  22. $filter_end = Yii::app()->request->getParam('end', '');
  23. $filter_status = intval(Yii::app()->request->getParam('status', 100));
  24. $filter_type = Yii::app()->request->getParam('type', 'all');
  25. $filter_is_kennel = intval(Yii::app()->request->getParam('is_kennel', 0));
  26. // 是否查看商家私信
  27. $kennel_manager_list = [];
  28. if ($filter_is_kennel) {
  29. $criteria = new EMongoCriteria();
  30. $criteria->status('==', 1);
  31. $managers = KennelManager::model()->findAll($criteria);
  32. foreach ($managers as $key => $item) {
  33. $kennel_manager_list[] = $item->user;
  34. }
  35. }
  36. $criteria = new EMongoCriteria($params);
  37. // 过滤系统通知
  38. $kefu_user = Yii::app()->params['kefu_user'];
  39. $sys_user = Yii::app()->params['sys_user'];
  40. $notin_user = [
  41. new MongoId($kefu_user),
  42. new MongoId($sys_user),
  43. ];
  44. $criteria->from_user('notin', $notin_user);
  45. $criteria->to_user('notin', $notin_user);
  46. if ($kennel_manager_list) {
  47. $criteria->from_user('in', $kennel_manager_list);
  48. $criteria->to_user('in', $kennel_manager_list);
  49. }
  50. if ($search != '') {
  51. $regex = new MongoRegex ('/'.$search.'/');
  52. $criteria->content('==', $regex);
  53. }
  54. if ($search_from != '') {
  55. if (CommonFn::isMongoId($search_from)) {
  56. $criteria->from_user('==', new MongoId($search_from));
  57. } else {
  58. $regex = new MongoRegex('/'.$search_from.'/');
  59. $criteria_from = new EMongoCriteria();
  60. $criteria_from->user_name('==', $regex);
  61. $cursor = RUser::model()->findAll($criteria_from);
  62. foreach ($cursor as $key => $eCursor) {
  63. $from_users[] = $eCursor->_id;
  64. }
  65. $criteria->from_user('in', $from_users);
  66. }
  67. }
  68. if ($search_to != '') {
  69. if (CommonFn::isMongoId($search_to)) {
  70. $criteria->to_user('==', new MongoId($search_to));
  71. } else {
  72. $regex = new MongoRegex('/'.$search_to.'/');
  73. $criteria_to = new EMongoCriteria();
  74. $criteria_to->user_name('==', $regex);
  75. $cursor = RUser::model()->findAll($criteria_to);
  76. foreach ($cursor as $key => $eCursor) {
  77. $to_users[] = $eCursor->_id;
  78. }
  79. $criteria->to_user('in', $to_users);
  80. }
  81. }
  82. if ($filter_status != 100) {
  83. $criteria->status('==', $filter_status);
  84. }
  85. if ($filter_start != '') {
  86. $start = strtotime($filter_start);
  87. $criteria->time('>=', $start);
  88. }
  89. if ($filter_end != '') {
  90. $end = strtotime($filter_end);
  91. $criteria->time('<=', $end);
  92. }
  93. if ($filter_type != 'all') {
  94. if ($filter_type == 'text') {
  95. $criteria->content('!=', '');
  96. } else if ($filter_type == 'image') {
  97. $criteria->pics('size', 1);
  98. } else if ($filter_type == 'voice') {
  99. $criteria->voice('exists', true);
  100. $criteria->voice('!=', array());
  101. } else if ($filter_type == 'video') {
  102. $criteria->video('exists', true);
  103. $criteria->video('!=', array());
  104. }
  105. }
  106. $cursor = Message::model()->findAll($criteria);
  107. // $total = $cursor->count();
  108. $total = 9999;
  109. $rows = CommonFn::getRowsFromCursor($cursor);
  110. $parsedRows = Message::model()->parse($rows);
  111. echo CommonFn::composeDatagridData($parsedRows, $total);
  112. }
  113. public function actionEdit() {
  114. $id = Yii::app()->request->getParam('id', '');
  115. $status = intval(Yii::app()->request->getParam('status', 1));
  116. $_id = new MongoId($id);
  117. $message = Message::get($_id);
  118. $message->status = $status;
  119. $success = $message->save();
  120. CommonFn::requestAjax($success, '', array());
  121. }
  122. }