123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- <?php
- class MessageController extends AdminController{
- public function actionIndex()
- {
- $status = array(
- 1 => array('name' => '待处理')
- );
- $user_ids = $usernames = array();
- $sys_user_id = Yii::app()->params['kefu_user']; //系统客服账号
- array_push($user_ids,new MongoId($sys_user_id));
- $admin_info = $this->getAdminInfo(); //当前后台管理账号
- if($admin_info){
- foreach($admin_info['fake_users'] as $fake_user){
- array_push($user_ids,$fake_user);
- }
- }
- if($user_ids){
- $model = new ZUser();
- $users = $model->getUserInfo($user_ids,array('id',"user_name"));
- if($users){
- foreach($users as $user){
- $usernames[(string)$user["_id"]] = array(
- 'name' => $user['user_name']
- );
- }
- }
- }
- $user_names = CommonFn::getComboboxData($usernames, 10, true,10);
- $status = CommonFn::getComboboxData($status, 10, true,10);
- $this->render('index', array(
- 'status' => $status,
- 'usernames' => $user_names
- ));
- }
- public function actionList(){
- $params = CommonFn::getPageParams();
- $page = Yii::app()->request->getParam('page',1);
- $search = Yii::app()->request->getParam('search','');
- $filter_status = Yii::app()->request->getParam('filter_status',0);
- $filter_user = Yii::app()->request->getParam('filter_user','10'); // 选择全部的默认值
- $from_user_ids = array();
- $criteria = new EMongoCriteria($params);
- if ($search != ''){
- if (CommonFn::isMongoId($search)){
- $from_user_ids = array(new MongoId($search)); //当搜索项为MongoID时,重置user_ids
- } else {
- $user_regex = new MongoRegex('/'.$search.'/');
- $user_criteria = new EMongoCriteria();
- $user_criteria->user_name("==", $user_regex);
- $user = RUser::model()->findAll($user_criteria);
- foreach ($user as $key => $value) {
- array_push($from_user_ids, $value->_id);
- }
- }
- $criteria->from_user('in', $from_user_ids);
- }
- $to_user_ids = array();
- if($filter_user != '10'){
- array_push($to_user_ids,new MongoId($filter_user));
- }
- //默认为系统客服账号以及当前账号的马甲号
- if(empty($to_user_ids) && empty($from_user_ids)){
- array_push($to_user_ids,new MongoId(Yii::app()->params['kefu_user']));
- $admin_info = $this->getAdminInfo(); //当前后台管理账号
- if($admin_info){
- foreach($admin_info['fake_users'] as $fake_user){
- array_push($to_user_ids,$fake_user);
- }
- }
- }
- if (!empty($to_user_ids)) {
- $criteria->user('in',$to_user_ids);
- }
- $criteria->type("==",'message');
- if($filter_status == 1){
- $criteria->no_read_count(">",0);
- }
- $cursor = ActionCat::model()->findAll($criteria);
- $total = $cursor->count();
- $rows = CommonFn::getRowsFromCursor($cursor);
- $parsedRows = ActionCat::model()->parse($rows);
- echo CommonFn::composeDatagridData($parsedRows, $total);
- }
- public function actionGetUserMsgList(){
- $from_user_id = Yii::app()->getRequest()->getParam("from_user_id",'');
- $to_user_id = Yii::app()->getRequest()->getParam("to_user_id",'');;
- $page = Yii::app()->request->getParam('page',1);
- if(!$from_user_id || !$to_user_id){
- return CommonFn::returnInfo(false,CommonFn::getMessage('user','id_not_exist'),array(),201);
- }
- $criteria = new EMongoCriteria();
- $criteria->from_user('in', array(new MongoId($to_user_id),new MongoId($from_user_id)));
- $criteria->to_user('in', array(new MongoId($to_user_id),new MongoId($from_user_id)));
- $criteria->status('==', 1);
- $cursor = Message::model()->findAll($criteria);
- $total = $cursor->count();
- $model = new ZMessage();
- $data['page'] = $page;
- $data['from_user'] = $to_user_id;
- $data['to_user'] = $from_user_id;
- $result = $model->readMessage($data);
- $sModel = new Message();
- $msg_list = array();
- foreach($result['data']['messages'] as $key => $row){
- $row['html'] = $sModel->generateMsgHtml($row['type'],$row);
- $row['from_user']['avatar'] = CommonFn::getQiniuImage($row['from_user']['avatar'],50,50);
- $msg_list[] = $row;
- }
- $msg_list = array_reverse($msg_list);
- $data = array(
- 'msg_list' => $msg_list,
- 'total' => $total
- );
- echo json_encode($data);
- Yii::app()->end();
- }
- public function actionUnReadCount(){
- $user_ids = array();
- $admin_info = $this->getAdminInfo(); //当前后台管理账号
- if($admin_info){
- foreach($admin_info['fake_users'] as $fake_user){
- array_push($user_ids,$fake_user);
- }
- }
- $list = new ARedisList('admin_no_read_reply_'.$admin_info['_id']);
- $post_unread_count = $list->getCount();
- // $criteria = new EMongoCriteria();
- // $criteria->type("==",'message');
- // $criteria->no_read_count("!=",0);
- // $criteria->user('in',$user_ids);
- // $unread = ActionCat::model()->count($criteria);
- // echo CJSON::encode(array('count' => $unread,'post_unread_count'=>$post_unread_count));
- echo CJSON::encode(array('count' => 0,'post_unread_count'=>$post_unread_count));
- Yii::app()->end();
- }
- public function actionPush(){
- $title = Yii::app()->request->getParam('title', '');
- $content = Yii::app()->request->getParam('content', '');
- $url = Yii::app()->request->getParam('url', '');
- $stamp = uniqid();
- $gt_content = [
- 'title' => $title,
- 'content' => $content,
- 'type' => 'custom_url',
- 'data' => [ "url"=>$url],
- 'stamp' => $stamp
- ];
- $gt_content = json_encode($gt_content,JSON_UNESCAPED_SLASHES );
- $pay_load = json_encode(['t'=>'custom_url',"url"=>$url,'stamp' => $stamp],JSON_UNESCAPED_SLASHES );
- if($title && $url){
- echo '消息内容:'.$gt_content.'<br/>';
- echo 'Message:'.$title.$content.'<br/>';
- echo 'pay_load:'.$pay_load.'<br/>';
- die();
- }
- $this->renderPartial('pushparam',array());
- }
- }
|