|
@@ -0,0 +1,1010 @@
|
|
|
+<?php
|
|
|
+/**
|
|
|
+ * UserController 用户相关api接口
|
|
|
+ */
|
|
|
+class UserController extends ApiBaseController{
|
|
|
+ public function beforeAction($action){
|
|
|
+ $weixin_use = array('info');
|
|
|
+ if(Yii::app()->getRequest()->getParam("request_from") == 'weixin' && in_array($action->id,$weixin_use)){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return $this->verify();
|
|
|
+ }
|
|
|
+ //用户邮箱注册
|
|
|
+ public function actionRegister(){
|
|
|
+ $userAr = new RUser();
|
|
|
+ $data = array();
|
|
|
+ $data['user_name'] = trim(Yii::app()->request->getParam('user_name',''));
|
|
|
+ $data['password'] = Yii::app()->request->getParam('password');
|
|
|
+ $data['email'] = Yii::app()->request->getParam('email','');
|
|
|
+ $data['avatar'] = Yii::app()->request->getParam('avatar','');
|
|
|
+ $data['city_info'] = json_decode(Yii::app()->request->getParam('city_info'),true);
|
|
|
+ $position = json_decode(Yii::app()->request->getParam('position'),true);
|
|
|
+ $data['position'][0] = isset($position['lng'])?floatval($position['lng']):0;
|
|
|
+ $data['position'][1] = isset($position['lat'])?floatval($position['lat']):0;
|
|
|
+ //防止city_info出现非法数据
|
|
|
+ if(!isset($data['city_info']['province'])){
|
|
|
+ $data['city_info']['province'] = '';
|
|
|
+ $data['city_info']['city'] = '';
|
|
|
+ $data['city_info']['area'] = '';
|
|
|
+ }elseif(!isset($data['city_info']['city'])){
|
|
|
+ $data['city_info']['city'] = '';
|
|
|
+ $data['city_info']['area'] = '';
|
|
|
+ }elseif(!isset($data['city_info']['area'])){
|
|
|
+ $data['city_info']['area'] = '';
|
|
|
+ }
|
|
|
+
|
|
|
+ $data['app_client_id'] = intval(Yii::app()->request->getParam('app_client_id'));
|
|
|
+ $data['device_id'] = Yii::app()->request->getParam('device_id');
|
|
|
+ $data['channel'] = Yii::app()->request->getParam('channel');
|
|
|
+ $data['openid'] = Yii::app()->request->getParam('openid');
|
|
|
+ $data['phone_type'] = Yii::app()->request->getParam('phone_type');
|
|
|
+ $data['os_version'] = Yii::app()->request->getParam('os_version');
|
|
|
+ $data['register_time'] = time();
|
|
|
+ $data['last_visit_time'] = time();
|
|
|
+
|
|
|
+ if(!preg_match(Yii::app()->params['emailReg'], $data['email'])){
|
|
|
+ CommonFn::requestAjax(false,CommonFn::getMessage('user','email_Illegal'));
|
|
|
+ }
|
|
|
+ $z_user = new ZUser();
|
|
|
+ $z_user->validate_user_name($data['user_name']);
|
|
|
+ if(strlen($data['password'])<6 || strlen($data['password'])>20){
|
|
|
+ CommonFn::requestAjax(false, CommonFn::getMessage('user','password_length_6_20'));
|
|
|
+ }
|
|
|
+ $userAr->attributes = $data;
|
|
|
+ $criteria = new EMongoCriteria();
|
|
|
+ $criteria->email('==',$userAr->email);
|
|
|
+ $olduser = RUser::model()->find($criteria);
|
|
|
+ if($olduser){
|
|
|
+ CommonFn::requestAjax(false,CommonFn::getMessage('user','email_already_registered'));
|
|
|
+ }
|
|
|
+ $criteria = new EMongoCriteria();
|
|
|
+ $criteria->user_name('==',$userAr->user_name);
|
|
|
+ $olduser = RUser::model()->find($criteria);
|
|
|
+ if($olduser){
|
|
|
+ CommonFn::requestAjax(false,CommonFn::getMessage('user','username_already_registered'));
|
|
|
+ }
|
|
|
+ $userAr->password = md5($userAr->password);
|
|
|
+ //用户注册后默认关注几个圈子
|
|
|
+ $z_group = new ZGroup();
|
|
|
+ $userAr->groups = $z_group->get_default_fllow_group();
|
|
|
+ if($userAr->save()){
|
|
|
+ $data = RUser::model()->parseRow($userAr->attributes);
|
|
|
+ CommonFn::requestAjax(true,CommonFn::getMessage('user','register_success'),$data);
|
|
|
+ }else{
|
|
|
+ CommonFn::requestAjax(false,CommonFn::getMessage('user','register_faild'));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //微信用户的登录
|
|
|
+ public function actionWeixinLogin(){
|
|
|
+ $data = array();
|
|
|
+ $data['user_name'] = mb_strtolower(Yii::app()->request->getParam('user_name',''));
|
|
|
+ $data['avatar'] = Yii::app()->request->getParam('avatar','');
|
|
|
+ $data['city_info'] = json_decode(Yii::app()->request->getParam('city_info'),true);
|
|
|
+ $position = json_decode(Yii::app()->request->getParam('position'),true);
|
|
|
+
|
|
|
+ //防止city_info出现非法数据
|
|
|
+ if(!isset($data['city_info']['province']) || $data['city_info']['province'] == '未知'){
|
|
|
+ $data['city_info']['province'] = '';
|
|
|
+ $data['city_info']['city'] = '';
|
|
|
+ $data['city_info']['area'] = '';
|
|
|
+ }elseif(!isset($data['city_info']['city'])){
|
|
|
+ $data['city_info']['city'] = '';
|
|
|
+ $data['city_info']['area'] = '';
|
|
|
+ }elseif(!isset($data['city_info']['area'])){
|
|
|
+ $data['city_info']['area'] = '';
|
|
|
+ }
|
|
|
+
|
|
|
+ $data['position'][0] = isset($position['lng'])?floatval($position['lng']):0;
|
|
|
+ $data['position'][1] = isset($position['lat'])?floatval($position['lat']):0;
|
|
|
+
|
|
|
+ $data['app_client_id'] = intval(Yii::app()->request->getParam('app_client_id'));
|
|
|
+ $data['device_id'] = Yii::app()->request->getParam('device_id');
|
|
|
+ $data['channel'] = Yii::app()->request->getParam('channel');
|
|
|
+ $data['phone_type'] = Yii::app()->request->getParam('phone_type');
|
|
|
+ if($data['channel'] == 'appstore'){
|
|
|
+ $data['phone_type'] = Yii::app()->request->getParam('device_model');
|
|
|
+ }
|
|
|
+ $data['app_version'] = Yii::app()->request->getParam('app_version');
|
|
|
+
|
|
|
+ $data['os_version'] = Yii::app()->request->getParam('os_version');
|
|
|
+
|
|
|
+ $data['openid'] = Yii::app()->request->getParam('openid','');
|
|
|
+ $data['unionid'] = Yii::app()->request->getParam('unionid','');
|
|
|
+
|
|
|
+ $data['sex'] = intval(Yii::app()->request->getParam('sex'));
|
|
|
+
|
|
|
+ $data['register_time'] = time();
|
|
|
+ $data['last_visit_time'] = time();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if ($data['openid'] == ''){
|
|
|
+ CommonFn::requestAjax(false, CommonFn::getMessage('user','weixin_login_faild'));
|
|
|
+ }
|
|
|
+
|
|
|
+ $criteria = new EMongoCriteria();
|
|
|
+ if(isset($data['unionid']) && !empty($data['unionid'])){
|
|
|
+ $criteria->unionid('==',$data['unionid']);//unionid保证账号统一
|
|
|
+ }else{
|
|
|
+ $criteria->openid('==',$data['openid']);
|
|
|
+ }
|
|
|
+ $user = RUser::model()->find($criteria);
|
|
|
+ if($user){
|
|
|
+ $user->os_version = $data['os_version'];
|
|
|
+ $user->device_id = $data['device_id'];
|
|
|
+ $user->app_client_id = $data['app_client_id'];
|
|
|
+ $paraArr = array('os_version','device_id','app_client_id');
|
|
|
+ if(!empty($data['position'])&&!empty($data['position'][0])&&!empty($data['position'][1])){
|
|
|
+ $user->position = $data['position'];
|
|
|
+ $paraArr[] = 'position';
|
|
|
+ }
|
|
|
+ if(!empty($data['city_info']['province'])){
|
|
|
+ $user->city_info = $data['city_info'];
|
|
|
+ $paraArr[] = 'city_info';
|
|
|
+ }
|
|
|
+ $user->update($paraArr,true);
|
|
|
+ $data = RUser::model()->parseRow($user->attributes);
|
|
|
+ $z_action_cat = new ZActionCat();
|
|
|
+ $news_count = $z_action_cat->getUnReadNews($user->_id);
|
|
|
+ $data['news'] = $news_count;
|
|
|
+ CommonFn::requestAjax(true,CommonFn::getMessage('user','login_success'),$data);
|
|
|
+ }else{
|
|
|
+ $z_user = new ZUser();
|
|
|
+ $z_user->validate_user_name($data['user_name']);
|
|
|
+ $userAr = new RUser();
|
|
|
+ $userAr->user_name = $data['user_name'];
|
|
|
+ $userAr->avatar = $data['avatar'];
|
|
|
+ $userAr->city_info = $data['city_info'];
|
|
|
+ $userAr->position = $data['position'];
|
|
|
+ $userAr->app_client_id = $data['app_client_id'];
|
|
|
+ $userAr->device_id = $data['device_id'];
|
|
|
+ $userAr->phone_type = $data['phone_type'];
|
|
|
+ $userAr->app_version = $data['app_version'];
|
|
|
+ $userAr->os_version = $data['os_version'];
|
|
|
+ $userAr->channel = $data['channel'];
|
|
|
+ $userAr->openid = $data['openid'];
|
|
|
+ $userAr->unionid = $data['unionid'];
|
|
|
+ $userAr->sex = $data['sex']?$data['sex']:3;
|
|
|
+ $userAr->register_time = $data['register_time'];
|
|
|
+ $userAr->last_visit_time = $data['last_visit_time'];
|
|
|
+ try {
|
|
|
+ $saveResult = $userAr->save();
|
|
|
+ }catch(Exception $e){
|
|
|
+ $userAr->user_name = 'wz_'.dechex(time());
|
|
|
+ $saveResult = $userAr->save();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($saveResult){
|
|
|
+ $z_group = new ZGroup();
|
|
|
+ $default_groups = $z_group->get_default_fllow_group();
|
|
|
+ $userAr->groups = $default_groups;
|
|
|
+ $userAr->update(array('groups'),true);
|
|
|
+ $list = new ARedisList('after_user_reg');
|
|
|
+ $user_id = (string)$userAr->_id;
|
|
|
+ $list->push($user_id);
|
|
|
+ $data = RUser::model()->parseRow($userAr->attributes);
|
|
|
+ $news = [
|
|
|
+ 'like'=>0,
|
|
|
+ 'message'=>0,
|
|
|
+ 'reply'=>0,
|
|
|
+ 'notice'=>0,
|
|
|
+ 'order'=>0,
|
|
|
+ 'follow'=>0,
|
|
|
+ 'new_topic'=>0,
|
|
|
+ 'new_card'=>0,
|
|
|
+ 'total'=>0
|
|
|
+ ];
|
|
|
+ $data['news'] = $news;
|
|
|
+ CommonFn::requestAjax(true,CommonFn::getMessage('user','register_success'),$data,200,array('is_new'=>1));
|
|
|
+ }else{
|
|
|
+ CommonFn::requestAjax(false,CommonFn::getMessage('user','register_faild'));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //用户登陆
|
|
|
+ public function actionLogin(){
|
|
|
+ $password = md5(Yii::app()->request->getParam('password'),'');
|
|
|
+ $email = preg_replace('/\0/','',Yii::app()->request->getParam('email',''));
|
|
|
+ $email = str_replace(' ','',$email);
|
|
|
+ if($password&&$email){
|
|
|
+ $criteria = new EMongoCriteria();
|
|
|
+ $criteria->email = new MongoRegex('/' . $email . '/i');
|
|
|
+
|
|
|
+ try {
|
|
|
+ $userAr = RUser::model()->find($criteria);
|
|
|
+ } catch (Exception $e) {
|
|
|
+ CommonFn::requestAjax(false,CommonFn::getMessage('user','id_not_exist'));
|
|
|
+ }
|
|
|
+ if(!$userAr){
|
|
|
+ CommonFn::requestAjax(false,CommonFn::getMessage('user','id_not_exist'));
|
|
|
+ }
|
|
|
+ if($password == $userAr->password){
|
|
|
+ $userAr->last_visit_time = time();
|
|
|
+ $userAr->update(array('last_visit_time'),true);
|
|
|
+ $z_action_cat = new ZActionCat();
|
|
|
+ $news_count = $z_action_cat->getUnReadNews($userAr->_id);
|
|
|
+ $data = RUser::model()->parseRow($userAr->attributes);
|
|
|
+ $data['news'] = $news_count;
|
|
|
+ CommonFn::requestAjax(true,CommonFn::getMessage('message','operation_success'),$data);
|
|
|
+ }else{
|
|
|
+ CommonFn::requestAjax(false,CommonFn::getMessage('user','username_or_password_error'));
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ CommonFn::requestAjax(false,CommonFn::getMessage('message','params_miss'));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //用户登陆前验证
|
|
|
+ public function actionValidate(){
|
|
|
+ $email = Yii::app()->request->getParam('email');
|
|
|
+ if(!$email){
|
|
|
+ CommonFn::requestAjax(false,CommonFn::getMessage('message','params_miss'));
|
|
|
+ }
|
|
|
+ $criteria = new EMongoCriteria();
|
|
|
+ if(preg_match(Yii::app()->params['emailReg'], $email)){
|
|
|
+ $criteria->email('==',$email);
|
|
|
+ }else{
|
|
|
+ $criteria->user_name('==',$email);
|
|
|
+ }
|
|
|
+ $userAr = RUser::model()->find($criteria);
|
|
|
+ if($userAr){
|
|
|
+ CommonFn::requestAjax(false,CommonFn::getMessage('user','email_already_registered'));
|
|
|
+ }else{
|
|
|
+ CommonFn::requestAjax(true,'');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //用户信息
|
|
|
+ public function actionInfo(){
|
|
|
+ if(Yii::app()->request->getParam('app_client_id') == 2){
|
|
|
+ $this->check_version();
|
|
|
+ }
|
|
|
+ $user_id = Yii::app()->getRequest()->getParam("user_id");
|
|
|
+ $uid = Yii::app()->getRequest()->getParam("to_user_id");
|
|
|
+ $user_name = Yii::app()->getRequest()->getParam("user_name");
|
|
|
+ if($user_name){
|
|
|
+ $criteria = new EMongoCriteria();
|
|
|
+ $criteria->user_name('==',$user_name);
|
|
|
+ $res = RUser::model()->find($criteria);
|
|
|
+ if(!$res){
|
|
|
+ CommonFn::requestAjax(false,CommonFn::getMessage('user','user_not_exist'),204);
|
|
|
+ }else{
|
|
|
+ $uid = $res->_id;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $page = intval(Yii::app()->getRequest()->getParam("page",1));
|
|
|
+ if(empty($page)){
|
|
|
+ $page = 1;
|
|
|
+ }
|
|
|
+ $notopic = Yii::app()->getRequest()->getParam("notopic");
|
|
|
+ if(empty($user_id) && empty($uid)){
|
|
|
+ CommonFn::requestAjax(false,CommonFn::getMessage('user','id_not_empty'),201);
|
|
|
+ }
|
|
|
+ $add_score = $this->today_first_login($user_id);
|
|
|
+ if($user_id){
|
|
|
+ $id = $user_id;
|
|
|
+ }
|
|
|
+ $model = new RUser();
|
|
|
+ if($uid){
|
|
|
+ if($user_id){
|
|
|
+ $user_node = new UserNodeRecord($user_id);
|
|
|
+ $relation = $user_node->relation($uid);
|
|
|
+ }
|
|
|
+ $id = $uid;
|
|
|
+ }
|
|
|
+ $user = CommonFn::apigetObJ($id,"ZUser",CommonFn::getMessage('user','id_not_exist'),201);
|
|
|
+ $user_data = $model->parseRow($user->attributes,array(),true);
|
|
|
+
|
|
|
+ $user_data['relation'] = isset($relation)?$relation:0;
|
|
|
+ $criteria = new EMongoCriteria();
|
|
|
+ $criteria->user('==',$user->_id);
|
|
|
+ $criteria->status("==",1);
|
|
|
+ $criteria->limit(3)->sort('time',EMongoCriteria::SORT_DESC);
|
|
|
+ $model = new Topic();
|
|
|
+ $cursor = $model->findAll($criteria);
|
|
|
+ $rows = CommonFn::getRows($cursor);
|
|
|
+ $topics = $model->parse($rows);
|
|
|
+ $feed = array();
|
|
|
+ if($topics){
|
|
|
+ $feed['pics'] = array();
|
|
|
+ foreach ($topics as $topic) {
|
|
|
+ $feed['pics'] = array_merge($feed['pics'],$topic['pics']);
|
|
|
+ $feed['pics'] = array_slice($feed['pics'],0,3);
|
|
|
+ }
|
|
|
+ if($feed['pics']){
|
|
|
+ $feed['type'] = 'pics';
|
|
|
+ $user_data['feed'] = $feed;
|
|
|
+ }elseif($topics[0]['content']){
|
|
|
+ $feed['type'] = 'text';
|
|
|
+ $feed['content'] = $topics[0]['content'];
|
|
|
+ $user_data['feed'] = $feed;
|
|
|
+ }else{
|
|
|
+ $feed['type'] = 'text';
|
|
|
+ $feed['content'] = '';
|
|
|
+ $user_data['feed'] = $feed;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $feed['type'] = 'text';
|
|
|
+ $feed['content'] = '';
|
|
|
+ $user_data['feed'] = $feed;
|
|
|
+ }
|
|
|
+ $z_action_cat = new ZActionCat();
|
|
|
+ $news_count = $z_action_cat->getUnReadNews($user->_id);
|
|
|
+ $user_data['news'] = $news_count;
|
|
|
+ $data['user'] = $user_data;
|
|
|
+ if(empty($notopic)){
|
|
|
+ $conditions = array(
|
|
|
+ 'user'=>array('==',$user->_id),
|
|
|
+ 'status'=>array('==',1)
|
|
|
+ );
|
|
|
+ $order = array(
|
|
|
+ 'time'=>'desc',
|
|
|
+ );
|
|
|
+ $model = new Topic();
|
|
|
+ $pagedata = CommonFn::getPagedata($model,$page,20,$conditions,$order);
|
|
|
+ $user_topics = $pagedata['res'];
|
|
|
+ if(!empty($user_id)){
|
|
|
+ foreach ($user_topics as $key => $topic) {
|
|
|
+ $z_like = new ZLike();
|
|
|
+ $like = $z_like->getLikeByLikeObj($user_id,$topic['id']);
|
|
|
+ if(empty($like)){
|
|
|
+ $user_topics[$key]['is_liked'] = false;
|
|
|
+ }else{
|
|
|
+ $user_topics[$key]['is_liked'] = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(Yii::app()->getRequest()->getParam("page_size",0)==1){
|
|
|
+ if(isset($user_topics[0]['pics'])&&count($user_topics[0]['pics'])<3){
|
|
|
+ $criteria = new EMongoCriteria();
|
|
|
+ $criteria->user('==',$user->_id);
|
|
|
+ $criteria->status("==",1);
|
|
|
+ $criteria->limit(2)->sort('time',EMongoCriteria::SORT_DESC)->offset(1);
|
|
|
+ $model = new Topic();
|
|
|
+ $cursor = $model->findAll($criteria);
|
|
|
+ $rows = CommonFn::getRows($cursor);
|
|
|
+ $topics = $model->parse($rows);
|
|
|
+ foreach ($topics as $topic) {
|
|
|
+ $user_topics[0]['pics'] = array_merge($user_topics[0]['pics'],$topic['pics']);
|
|
|
+ $user_topics[0]['pics'] = array_slice($user_topics[0]['pics'],0,3);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $data['topic_list'] = $user_topics;
|
|
|
+ }
|
|
|
+ if($add_score['status']){
|
|
|
+ $score_info['score_change'] = $add_score['score'];
|
|
|
+ $score_info['current_score'] = $add_score['current_score'];
|
|
|
+ $score_info['score_type'] = '签到';
|
|
|
+ if(isset($pagedata)){
|
|
|
+ CommonFn::requestAjax(true,CommonFn::getMessage('message','operation_success'),$data,303,array_merge($score_info,array('sum_count' => $pagedata['sum_count'],'sum_page'=>$pagedata['sum_page'],'page_size'=>$pagedata['page_size'],'current_page'=>$pagedata['current_page'])));
|
|
|
+ }else{
|
|
|
+ CommonFn::requestAjax(true,CommonFn::getMessage('message','operation_success'),$data,303,$score_info);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ if(isset($pagedata)){
|
|
|
+ CommonFn::requestAjax(true,CommonFn::getMessage('message','operation_success'),$data,200,array('sum_count' => $pagedata['sum_count'],'sum_page'=>$pagedata['sum_page'],'page_size'=>$pagedata['page_size'],'current_page'=>$pagedata['current_page']));
|
|
|
+ }else{
|
|
|
+ CommonFn::requestAjax(true,CommonFn::getMessage('message','operation_success'),$data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 按照时间线展现帖子列表
|
|
|
+ * 当前日期的帖子没有显示完后,会追加当天剩余帖子数.并传递实际数据偏移量给前端
|
|
|
+ */
|
|
|
+ public function actionInfoByTimeline(){
|
|
|
+ $user_id = Yii::app()->getRequest()->getParam("user_id");
|
|
|
+ $uid = Yii::app()->getRequest()->getParam("to_user_id");
|
|
|
+ $user_name = Yii::app()->getRequest()->getParam("user_name");
|
|
|
+ if($user_name){
|
|
|
+ $criteria = new EMongoCriteria();
|
|
|
+ $criteria->user_name('==',$user_name);
|
|
|
+ $res = RUser::model()->find($criteria);
|
|
|
+ if(!$res){
|
|
|
+ CommonFn::requestAjax(false,CommonFn::getMessage('user','user_not_exist'),array(),204);
|
|
|
+ }else{
|
|
|
+ $uid = $res->_id;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $page = intval(Yii::app()->getRequest()->getParam("page",1));
|
|
|
+ if(empty($page)){
|
|
|
+ $page = 1;
|
|
|
+ }
|
|
|
+ $offset = Yii::app()->getRequest()->getParam('offset',0);
|
|
|
+ if(empty($user_id) && empty($uid)){
|
|
|
+ CommonFn::requestAjax(false,CommonFn::getMessage('user','id_not_empty'),201);
|
|
|
+ }
|
|
|
+ if($uid){
|
|
|
+ if($user_id){
|
|
|
+ $user_node = new UserNodeRecord($user_id);
|
|
|
+ $relation = $user_node->relation($uid);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if($user_id){
|
|
|
+ $id = $user_id;
|
|
|
+ }
|
|
|
+ if($uid){
|
|
|
+ $id = $uid;
|
|
|
+ }
|
|
|
+ $model = new RUser();
|
|
|
+ $user_obj = CommonFn::apigetObJ($id,"ZUser",CommonFn::getMessage('user','id_not_exist'),201);
|
|
|
+ $user_data = $model->parseRow($user_obj->attributes);
|
|
|
+ $user_data['relation'] = isset($relation)?$relation:0;
|
|
|
+ //获取用户帖子信息
|
|
|
+ $topic_model = new ZTopic();
|
|
|
+ $user_topics = array();
|
|
|
+ $pagesize = 20;
|
|
|
+ $page_offset = ($page - 1) * $pagesize;
|
|
|
+ if(!$offset){
|
|
|
+ $offset = $offset > 0 && $page_offset < $offset ? $offset : $page_offset;
|
|
|
+ }
|
|
|
+ $criteria = new EMongoCriteria();
|
|
|
+ $criteria->user('==',$user_obj->_id);
|
|
|
+ $criteria->status("==",1);
|
|
|
+ $criteria->limit($pagesize)->sort('time',EMongoCriteria::SORT_DESC)->offset($offset);
|
|
|
+ $model = new Topic();
|
|
|
+ $cursor = $model->findAll($criteria);
|
|
|
+ $rows = CommonFn::getRows($cursor);
|
|
|
+ $rows = $model->parse($rows);
|
|
|
+ //获取有追加数据
|
|
|
+ if(count($rows)<1){
|
|
|
+ $data = array(
|
|
|
+ 'user' => $user_data,
|
|
|
+ 'topic_list' => array(),
|
|
|
+ 'offset' => $offset,
|
|
|
+ );
|
|
|
+ CommonFn::requestAjax(true,CommonFn::getMessage('message','operation_success'),$data,200,array('is_more'=>0));
|
|
|
+ }
|
|
|
+ $last_topic = $rows[count($rows)-1];
|
|
|
+ $append_data = $topic_model->getAppendDateByDate($uid,$last_topic['last_post_time']);
|
|
|
+ if($append_data){
|
|
|
+ $rows = array_merge($rows,$append_data);
|
|
|
+ }
|
|
|
+ //按时间顺序排列
|
|
|
+ foreach($rows as $row ){
|
|
|
+ $user_topics[$row['date']]['time'] = $row['date'];
|
|
|
+ $user_topics[$row['date']]['data'][] = $row;
|
|
|
+ }
|
|
|
+ $user_topics = array_values($user_topics);
|
|
|
+
|
|
|
+ $current_offset = count($rows)+$offset; //当前实际数据偏移值
|
|
|
+ if(count($rows)<20){
|
|
|
+ $is_more = 0;
|
|
|
+ }else{
|
|
|
+ $is_more = 1;
|
|
|
+ }
|
|
|
+ //追加到用户数据中
|
|
|
+ $data = array(
|
|
|
+ 'user' => $user_data,
|
|
|
+ 'topic_list' => $user_topics,
|
|
|
+ 'offset' => $current_offset
|
|
|
+ );
|
|
|
+ CommonFn::requestAjax(true,CommonFn::getMessage('message','operation_success'),$data,200,array('is_more'=>$is_more));
|
|
|
+ }
|
|
|
+
|
|
|
+ //用户收藏信息接口
|
|
|
+ public function actionFavList(){
|
|
|
+ $user_id = Yii::app()->getRequest()->getParam("user_id");
|
|
|
+ $page = intval(Yii::app()->getRequest()->getParam("page",1));
|
|
|
+ if(empty($page)){
|
|
|
+ $page = 1;
|
|
|
+ }
|
|
|
+ //获取用户收藏信息
|
|
|
+ $user = CommonFn::apigetObJ($user_id,'ZUser',CommonFn::getMessage('user','id_not_exist'),201);
|
|
|
+ $pagesize = Yii::app()->params['userFavsPageSize'];
|
|
|
+ $conditions = array(
|
|
|
+ 'user'=>array('==',$user->_id)
|
|
|
+ );
|
|
|
+ $order = array(
|
|
|
+ 'time'=>'desc',
|
|
|
+ );
|
|
|
+ $model = new Fav();
|
|
|
+ $pagedata = CommonFn::getPagedata($model,$page,$pagesize,$conditions,$order);
|
|
|
+ $user_favs = $pagedata['res'];
|
|
|
+ if(!empty($user_favs)){
|
|
|
+ foreach ($user_favs as $key => $value) {
|
|
|
+ if($value['fav_obj']['status']!=1){
|
|
|
+ unset($user_favs[$key]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $data = array();
|
|
|
+ foreach($user_favs as $fav){
|
|
|
+ $z_like = new ZLike();
|
|
|
+ $like = $z_like->getLikeByLikeObj($user_id,$fav['fav_obj']['id']);
|
|
|
+ if(empty($like)){
|
|
|
+ $fav['fav_obj']['is_liked'] = false;
|
|
|
+ }else{
|
|
|
+ $fav['fav_obj']['is_liked'] = true;
|
|
|
+ }
|
|
|
+ $data[] = $fav['fav_obj'];
|
|
|
+ }
|
|
|
+ CommonFn::requestAjax(true,CommonFn::getMessage('message','operation_success'),$data,200,array('sum_count' => $pagedata['sum_count'],'sum_page'=>$pagedata['sum_page'],'page_size'=>$pagedata['page_size'],'current_page'=>$pagedata['current_page']));
|
|
|
+ }
|
|
|
+
|
|
|
+ //用户帖子列表页面
|
|
|
+ public function actionTopicList(){
|
|
|
+ $user_id = Yii::app()->getRequest()->getParam("user_id");
|
|
|
+ $uid = Yii::app()->getRequest()->getParam("to_user_id");
|
|
|
+ $page = intval(Yii::app()->getRequest()->getParam("page",1));
|
|
|
+ if(empty($page)){
|
|
|
+ $page = 1;
|
|
|
+ }
|
|
|
+ $offset = Yii::app()->getRequest()->getParam('offset',0);
|
|
|
+
|
|
|
+ if(empty($user_id) && empty($uid)){
|
|
|
+ CommonFn::requestAjax(false,CommonFn::getMessage('user','id_not_empty'),201);
|
|
|
+ }
|
|
|
+ if($user_id){
|
|
|
+ $id = $user_id;
|
|
|
+ $time_list_flag = true;
|
|
|
+ }
|
|
|
+ if($uid){
|
|
|
+ $id = $uid;
|
|
|
+ $time_list_flag = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取用户帖子列表
|
|
|
+ $topic_model = new ZTopic();
|
|
|
+ $user_topics = array();
|
|
|
+ $rows = $topic_model->getUserTopic($id,$page,$offset);
|
|
|
+ if(count($rows)<1){
|
|
|
+ $data = array(
|
|
|
+ 'topic_list' => array(),
|
|
|
+ 'offset' => $offset,
|
|
|
+ );
|
|
|
+ CommonFn::requestAjax(true,CommonFn::getMessage('message','operation_success'),$data);
|
|
|
+ }
|
|
|
+
|
|
|
+ if($time_list_flag){
|
|
|
+ //获取有追加数据
|
|
|
+ $last_topic = $rows[count($rows)-1];
|
|
|
+ $append_data = $topic_model->getAppendDateByDate($id,$last_topic['last_post_time']);
|
|
|
+ if($append_data){
|
|
|
+ $rows = array_merge($rows,$append_data);
|
|
|
+ }
|
|
|
+
|
|
|
+ //按时间顺序排列
|
|
|
+ foreach($rows as $row ){
|
|
|
+ $user_topics[$row['date']]['time'] = $row['date'];
|
|
|
+ $user_topics[$row['date']]['data'][] = $row;
|
|
|
+ }
|
|
|
+ $user_topics = array_values($user_topics);
|
|
|
+
|
|
|
+ }else{
|
|
|
+ $user_topics = $rows;
|
|
|
+ }
|
|
|
+ $current_offset = count($rows); //当前实际数据偏移值
|
|
|
+
|
|
|
+ $data = array(
|
|
|
+ 'topic_list' => $user_topics,
|
|
|
+ 'offset' => $current_offset,
|
|
|
+ );
|
|
|
+ CommonFn::requestAjax(true,CommonFn::getMessage('message','operation_success'),$data);
|
|
|
+ }
|
|
|
+
|
|
|
+ //修改用户资料
|
|
|
+ public function actionEdit(){
|
|
|
+ $data['_id'] = Yii::app()->getRequest()->getParam('user_id');
|
|
|
+ if(!CommonFn::isMongoId($data['_id'])){
|
|
|
+ CommonFn::requestAjax(false,CommonFn::getMessage('user','id_not_exist'),201);
|
|
|
+ }
|
|
|
+ $model = new RUser();
|
|
|
+ $user = CommonFn::apigetObJ($data['_id'],"ZUser",CommonFn::getMessage('user','id_not_exist'),201);
|
|
|
+
|
|
|
+ //需要进行修改的数据内容
|
|
|
+ $data['avatar'] = Yii::app()->getRequest()->getParam('avatar','');
|
|
|
+ $data['mobile'] = Yii::app()->getRequest()->getParam('mobile','');
|
|
|
+ $data['sex'] = intval(Yii::app()->getRequest()->getParam('sex'));
|
|
|
+ $data['user_name']= Yii::app()->getRequest()->getParam('user_name','');
|
|
|
+ $data['city_info'] = json_decode(Yii::app()->request->getParam('city_info'),true);
|
|
|
+ //防止city_info出现非法数据
|
|
|
+ if(!isset($data['city_info']['province'])){
|
|
|
+ $data['city_info']['province'] = '';
|
|
|
+ $data['city_info']['city'] = '';
|
|
|
+ $data['city_info']['area'] = '';
|
|
|
+ }elseif(!isset($data['city_info']['city'])){
|
|
|
+ $data['city_info']['city'] = '';
|
|
|
+ $data['city_info']['area'] = '';
|
|
|
+ }elseif(!isset($data['city_info']['area'])){
|
|
|
+ $data['city_info']['area'] = '';
|
|
|
+ }
|
|
|
+ if($data['avatar']){
|
|
|
+ if(!CommonFn::checkPicFormat($data['avatar'])){
|
|
|
+ CommonFn::requestAjax(false,CommonFn::getMessage('user','user_avatar_illegal'));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if($user->certify_status == 1 && $data['user_name'] && $user->user_name != $data['user_name']){
|
|
|
+ CommonFn::requestAjax(false,'你已通过认证,不允许修改昵称');
|
|
|
+ }
|
|
|
+ //过滤user_id ,检测本接口所需参数是否完整
|
|
|
+ $item_count = 0;
|
|
|
+ unset($data['_id']);
|
|
|
+ //用户名检测
|
|
|
+ if(isset($data['user_name']) && $data['user_name']){
|
|
|
+ if(mb_strlen($data['user_name'],'utf-8')<2||mb_strlen($data['user_name'],'utf-8')>16){
|
|
|
+ CommonFn::requestAjax(false,CommonFn::getMessage('user','username_length_illegal'));
|
|
|
+ }
|
|
|
+ $z_user = new ZUser();
|
|
|
+ $z_user->validate_user_name($data['user_name']);
|
|
|
+ $u_criteria = new EMongoCriteria();
|
|
|
+ $u_criteria->user_name('==',$data['user_name']);
|
|
|
+ $olduser = RUser::model()->find($u_criteria);
|
|
|
+ if($olduser&&$olduser->_id!=$user->_id){
|
|
|
+ CommonFn::requestAjax(false,CommonFn::getMessage('user','username_already_registered'));
|
|
|
+ }
|
|
|
+ }elseif(empty($data['user_name'])){
|
|
|
+ $data['user_name'] = $user->user_name;
|
|
|
+ }
|
|
|
+ foreach($data as $key => $val){
|
|
|
+ if(!empty($val)){
|
|
|
+ if($key=='city_info' && empty($val['province'])){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $item_count++;
|
|
|
+ $user->{$key} = $val;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //更新数据
|
|
|
+ if($item_count){
|
|
|
+ if($user->save(true)){
|
|
|
+ $data = $user->parseRow($user->attributes,array(),true);
|
|
|
+ CommonFn::requestAjax(true,CommonFn::getMessage('message','operation_success'),$data);
|
|
|
+ }else{
|
|
|
+ CommonFn::requestAjax(false,CommonFn::getMessage('message','operation_faild'));
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ CommonFn::requestAjax(false,CommonFn::getMessage('message','params_illegal'));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //用户爪币记录
|
|
|
+ public function actionScoreLog(){
|
|
|
+ $user_id = Yii::app()->getRequest()->getParam("user_id");
|
|
|
+ $page = intval(Yii::app()->getRequest()->getParam("page",1));
|
|
|
+ if(empty($page)){
|
|
|
+ $page = 1;
|
|
|
+ }
|
|
|
+ if(empty($user_id) ){
|
|
|
+ CommonFn::requestAjax(false,CommonFn::getMessage('user','id_not_exist'),201);
|
|
|
+ }
|
|
|
+ if($user_id){
|
|
|
+ $id = $user_id;
|
|
|
+ }
|
|
|
+ $deviceid = Yii::app()->request->getParam('device_id');
|
|
|
+ //设置首次访问时间,保证一次浏览的回复列表不变
|
|
|
+ $actiontime = CommonFn::getFirstTime(ActionTimeRedis::TYPE_GET_SCORELOG,$deviceid,$page);
|
|
|
+ $pagesize = Yii::app()->params['userScoreLogPageSize'];
|
|
|
+ $conditions = array(
|
|
|
+ 'user'=>array('==',$id),
|
|
|
+ 'time'=>array('<=',$actiontime)
|
|
|
+ );
|
|
|
+ $order = array(
|
|
|
+ 'time'=>'desc',
|
|
|
+ );
|
|
|
+ $model = new UserScoreLog();
|
|
|
+ $pagedata = CommonFn::getPagedata($model,$page,$pagesize,$conditions,$order);
|
|
|
+ $logs = $pagedata['res'];
|
|
|
+ CommonFn::requestAjax(true,CommonFn::getMessage('message','operation_success'),$logs,200,array('sum_count' => $pagedata['sum_count'],'sum_page'=>$pagedata['sum_page'],'page_size'=>$pagedata['page_size'],'current_page'=>$pagedata['current_page']));
|
|
|
+ }
|
|
|
+
|
|
|
+ //用户拒绝接受推送
|
|
|
+ public function actionSetPush(){
|
|
|
+ $user_id = Yii::app()->getRequest()->getParam("user_id");
|
|
|
+ $user = CommonFn::apigetObJ($user_id,"ZUser",CommonFn::getMessage('user','id_not_exist'),201);
|
|
|
+ if($user->receive_push == 0){
|
|
|
+ $user->receive_push = 1;
|
|
|
+ if($user->update(array('receive_push'),true)){
|
|
|
+ CommonFn::requestAjax(true,CommonFn::getMessage('message','operation_success'),array('op'=>'receive'));
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $user->receive_push = 0;
|
|
|
+ if($user->update(array('receive_push'),true)){
|
|
|
+ CommonFn::requestAjax(true,CommonFn::getMessage('message','operation_success'),array('op'=>'unreceive'));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //用户分享成功后增加爪币
|
|
|
+ public function actionShareSuccess(){
|
|
|
+ $user_id = Yii::app()->getRequest()->getParam("user_id");
|
|
|
+ $user = CommonFn::apigetObJ($user_id,"ZUser",CommonFn::getMessage('user','id_not_exist'),201);
|
|
|
+ $add_score = $this->addScore($user_id,'score_share');
|
|
|
+ $result = array();
|
|
|
+ if($add_score['status']){
|
|
|
+ $add_score['score_change'] = $add_score['score'];
|
|
|
+ $add_score['current_score'] = $add_score['current_score'];
|
|
|
+ $add_score['score_type'] = '分享成功';
|
|
|
+ CommonFn::requestAjax(true,'分享增加爪币成功',array(),301,$add_score);
|
|
|
+ }else{
|
|
|
+ CommonFn::requestAjax(false,'分享增加爪币失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //用户申请认证接口
|
|
|
+ public function actionApplyCertify(){
|
|
|
+ $data = array();
|
|
|
+ $data['content'] = '您好,目前握爪仅开放认证宠物医生、营养师、训犬师、美容师,认证需要您相关的资格证书或学校就读证书照片及您与证书合影的照片,直接在私信里发给爪爪就好了。';
|
|
|
+ $data['from_user'] = Yii::app()->params['kefu_user'];
|
|
|
+ $data['to_user'] = Yii::app()->request->getParam('user_id','');
|
|
|
+ $date = date('Ymd');
|
|
|
+ $Key = HelperKey::generateUserActionKey('applycertify',$date,$data['to_user']);
|
|
|
+ $status = UserActionRedis::get($Key);
|
|
|
+ if($status){
|
|
|
+ CommonFn::requestAjax(false,'你今天已提交过认证申请,请不要重复申请');
|
|
|
+ }else{
|
|
|
+ UserActionRedis::set($Key,true);
|
|
|
+ }
|
|
|
+ $data['voice'] = json_decode(Yii::app()->request->getParam('voice'),true);
|
|
|
+ $data['video'] = json_decode(Yii::app()->request->getParam('video'),true);
|
|
|
+ $data['pics'] = json_decode(Yii::app()->request->getParam('pics'),true);
|
|
|
+ $z_message = new ZMessage();
|
|
|
+ $result = $z_message->addMessage($data);
|
|
|
+ if($result['status']){
|
|
|
+ CommonFn::requestAjax(true,'已提交认证申请');
|
|
|
+ }else{
|
|
|
+ CommonFn::requestAjax(false,'提交申请失败,请重试');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //用户加与取消关注接口
|
|
|
+ public function actionFollow(){
|
|
|
+ $user_id = Yii::app()->getRequest()->getParam("user_id");
|
|
|
+ $user = CommonFn::apigetObJ($user_id,"ZUser",CommonFn::getMessage('user','id_not_exist'),201);
|
|
|
+ $f_id = Yii::app()->getRequest()->getParam("to_user_id");
|
|
|
+ $f_id_list = json_decode(Yii::app()->getRequest()->getParam("to_user_list"),true);
|
|
|
+ if(!$f_id_list && !CommonFn::isMongoId($f_id)){
|
|
|
+ CommonFn::requestAjax(false,CommonFn::getMessage('message','params_illegal'));
|
|
|
+ }
|
|
|
+ $user_node = new UserNodeRecord($user->_id);
|
|
|
+ //批量关注
|
|
|
+ if(is_array($f_id_list) && !empty($f_id_list)){
|
|
|
+ foreach ($f_id_list as $value) {
|
|
|
+ $user_node->follow($value);
|
|
|
+ }
|
|
|
+ CommonFn::requestAjax(true,CommonFn::getMessage('message','operation_success'),array('op'=>'follow','follow_count'=>$user_node->follow_count(),'fans_count'=>$user_node->follower_count()));
|
|
|
+ }
|
|
|
+ if($user_node->is_following($f_id)){
|
|
|
+ $user_node->unfollow($f_id);
|
|
|
+ $op = 'unfollow';
|
|
|
+ $message = '取消关注成功';
|
|
|
+ }else{
|
|
|
+ $user_node->follow($f_id);
|
|
|
+ $message = '关注成功';
|
|
|
+ $op = 'follow';
|
|
|
+ }
|
|
|
+ CommonFn::requestAjax(true,$message,array('op'=>$op,'follow_count'=>$user_node->follow_count(),'fans_count'=>$user_node->follower_count()));
|
|
|
+ }
|
|
|
+
|
|
|
+ //好友帖子列表
|
|
|
+ public function actionFriendsTopicList(){
|
|
|
+ $last_obj_id = Yii::app()->getRequest()->getParam("last_object_id",'');
|
|
|
+ $user_id = Yii::app()->getRequest()->getParam("user_id");
|
|
|
+ $user = CommonFn::apigetObJ($user_id,"ZUser",CommonFn::getMessage('user','id_not_exist'),201);
|
|
|
+ if(CommonFn::isMongoId($last_obj_id)){
|
|
|
+ $last_topic_obj = Topic::get(new MongoId($last_obj_id));
|
|
|
+ if($last_topic_obj){
|
|
|
+ $last_obj_time = $last_topic_obj->time;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $last_obj_time = time();
|
|
|
+ }
|
|
|
+ if(!isset($last_obj_time)){
|
|
|
+ CommonFn::requestAjax(false,CommonFn::getMessage('message','params_illegal'));
|
|
|
+ }
|
|
|
+ //设置小红点
|
|
|
+ // $cache = new ARedisCache();
|
|
|
+ // $cache->set('friend_topic_'.$user_id,0);
|
|
|
+ $user_node = new UserNodeRecord($user_id);
|
|
|
+ $follow_list = $user_node->following();
|
|
|
+ $f_ids = array();
|
|
|
+ foreach ($follow_list as $key => $value) {
|
|
|
+ $f_ids[] = new MongoId($value);
|
|
|
+ }
|
|
|
+ $conditions = array(
|
|
|
+ 'user'=>array('in',$f_ids),
|
|
|
+ 'status'=>array('==',1),
|
|
|
+ 'time'=>array('<',$last_obj_time)
|
|
|
+ );
|
|
|
+ $order = array(
|
|
|
+ '_id'=>'desc',
|
|
|
+ );
|
|
|
+ $model = new Topic();
|
|
|
+ $pagedata = CommonFn::getPagedataById($model,20,$conditions,$order);
|
|
|
+ $topics = $pagedata['res'];
|
|
|
+ foreach ($topics as $key=>$value) {
|
|
|
+ if($user){
|
|
|
+ //判断用户是否收藏过该帖子
|
|
|
+ $z_fav = new ZFav();
|
|
|
+ $fav = $z_fav->getFavByFavObj($user_id,$value['id']);
|
|
|
+ if(empty($fav)){
|
|
|
+ $value['is_faved'] = false;
|
|
|
+ }else{
|
|
|
+ $value['is_faved'] = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断用户是否喜欢过该帖子
|
|
|
+ $z_like = new ZLike();
|
|
|
+ $like = $z_like->getLikeByLikeObj($user_id,$value['id']);
|
|
|
+ if(empty($like)){
|
|
|
+ $value['is_liked'] = false;
|
|
|
+ }else{
|
|
|
+ $value['is_liked'] = true;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $value['is_faved'] = false;
|
|
|
+ $value['is_liked'] = false;
|
|
|
+ }
|
|
|
+ $topics[$key] = $value;
|
|
|
+ }
|
|
|
+ $data['topic_list'] = $topics;
|
|
|
+ CommonFn::requestAjax(true,'',$data,200,array('has_more' => $pagedata['has_more'],'page_size'=>$pagedata['page_size']));
|
|
|
+ }
|
|
|
+
|
|
|
+ //我的关注接口
|
|
|
+ public function actionFollowList(){
|
|
|
+ $user_id = Yii::app()->getRequest()->getParam("user_id");
|
|
|
+ $to_user = Yii::app()->getRequest()->getParam("to_user_id");
|
|
|
+ $page = Yii::app()->getRequest()->getParam("page");
|
|
|
+ $page_size = Yii::app()->getRequest()->getParam("page_size",20);
|
|
|
+ if($to_user){
|
|
|
+ $uid = $to_user;
|
|
|
+ $user_node = new UserNodeRecord($to_user);
|
|
|
+ $current_user_node = new UserNodeRecord($user_id);
|
|
|
+ $need_refresh = true;
|
|
|
+ }else{
|
|
|
+ $uid = $user_id;
|
|
|
+ $user_node = new UserNodeRecord($user_id);
|
|
|
+ }
|
|
|
+ $follow_list = $user_node->following();
|
|
|
+ $sum = count($follow_list);
|
|
|
+ $follow_list = array_slice($follow_list,$page_size*($page-1),$page_size*$page);
|
|
|
+ $user_model = new RUser();
|
|
|
+ foreach ($follow_list as $key => $f_user) {
|
|
|
+ $follow_list[$key] = $user_model->parseRow(RUser::get(new MongoId($f_user)),array('id','user_name','sex','avatar','level','city_info','pets','certify_status','certify_info','can_access'));
|
|
|
+ if(isset($need_refresh)){
|
|
|
+ $follow_list[$key]['relation'] = $current_user_node->relation($f_user);
|
|
|
+ }else{
|
|
|
+ $follow_list[$key]['relation'] = $user_node->relation($f_user);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ CommonFn::requestAjax(true,CommonFn::getMessage('message','operation_success'),$follow_list,200,array('sum_count' => $sum ,'sum_page'=> ceil($sum/$page_size),'page_size'=>$page_size,'current_page'=>$page));
|
|
|
+ }
|
|
|
+
|
|
|
+ //粉丝列表
|
|
|
+ public function actionFansList(){
|
|
|
+ $user_id = Yii::app()->getRequest()->getParam("user_id");
|
|
|
+ $to_user = Yii::app()->getRequest()->getParam("to_user_id");
|
|
|
+ $page = Yii::app()->getRequest()->getParam("page");
|
|
|
+ $page_size = Yii::app()->getRequest()->getParam("page_size",20);
|
|
|
+ if($to_user){
|
|
|
+ $uid = $to_user;
|
|
|
+ $user_node = new UserNodeRecord($to_user);
|
|
|
+ $current_user_node = new UserNodeRecord($user_id);
|
|
|
+ $need_refresh = true;
|
|
|
+ }else{
|
|
|
+ $uid = $user_id;
|
|
|
+ $user_node = new UserNodeRecord($user_id);
|
|
|
+ }
|
|
|
+ $followed_by = $user_node->followed_by();
|
|
|
+ $sum = count($followed_by);
|
|
|
+ $followed_by = array_slice($followed_by,$page_size*($page-1),$page_size*$page);
|
|
|
+ $user_model = new RUser();
|
|
|
+ foreach ($followed_by as $key => $f_user) {
|
|
|
+ $followed_by[$key] = $user_model->parseRow(RUser::get(new MongoId($f_user)),array('id','user_name','sex','avatar','level','city_info','pets','certify_status','certify_info','can_access'));
|
|
|
+ if(isset($need_refresh)){
|
|
|
+ $followed_by[$key]['relation'] = $current_user_node->relation($f_user);
|
|
|
+ }else{
|
|
|
+ $followed_by[$key]['relation'] = $user_node->relation($f_user);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ CommonFn::requestAjax(true,CommonFn::getMessage('message','operation_success'),$followed_by,200,array('sum_count' => $sum ,'sum_page'=> ceil($sum/$page_size),'page_size'=>$page_size,'current_page'=>$page));
|
|
|
+ }
|
|
|
+
|
|
|
+ //推荐关注用户
|
|
|
+ public function actionRecommendUsers(){
|
|
|
+ $user_id = Yii::app()->getRequest()->getParam("user_id");
|
|
|
+ $city_info = Yii::app()->getRequest()->getParam("city_info");
|
|
|
+ $city_info = json_decode($city_info,true);
|
|
|
+ $user_obj = CommonFn::apigetObJ($user_id,"ZUser",CommonFn::getMessage('user','id_not_exist'),201);
|
|
|
+
|
|
|
+ $user_node = new UserNodeRecord($user_obj->_id);
|
|
|
+ $follow_list = $user_node->following();
|
|
|
+ $follow_users = array();
|
|
|
+ foreach ($follow_list as $key => $value) {
|
|
|
+ $follow_users[] = new MongoId($value);
|
|
|
+ }
|
|
|
+
|
|
|
+ $follow_users[] = $user_obj->_id;
|
|
|
+ $criteria = new EMongoCriteria;
|
|
|
+ $criteria->certify_status('==',1);
|
|
|
+ $criteria->_id('notin',$follow_users);
|
|
|
+ $criteria->is_fake_user('!=',1);
|
|
|
+ $criteria->sort('last_visit_time',EMongoCriteria::SORT_DESC);
|
|
|
+ $criteria->limit(5);
|
|
|
+ $cursor = RUser::model()->findAll($criteria);
|
|
|
+ $rows = RUser::model()->parse($cursor,true,array('id','user_name','sex','avatar','level','city_info','certify_status','certify_info','can_access'));
|
|
|
+ $certify_users = array();
|
|
|
+ foreach ($rows as $value) {
|
|
|
+ $value['recommend_reason'] = $value['certify_info'];
|
|
|
+ $certify_users[] = $value;
|
|
|
+ }
|
|
|
+
|
|
|
+ $criteria = new EMongoCriteria;
|
|
|
+ if(isset($city_info['province']) && $city_info['province']){
|
|
|
+ $criteria->city_info->province('==',$city_info['province']);
|
|
|
+ }else{
|
|
|
+ $criteria->city_info->province('==','上海市');
|
|
|
+ }
|
|
|
+ $criteria->_id('notin',$follow_users);
|
|
|
+ $criteria->is_fake_user('!=',1);
|
|
|
+ $criteria->certify_status('!=',1);
|
|
|
+ $criteria->sort('last_visit_time',EMongoCriteria::SORT_DESC);
|
|
|
+ $criteria->limit(10);
|
|
|
+ $cursor = RUser::model()->findAll($criteria);
|
|
|
+ $rows = RUser::model()->parse($cursor,true,array('id','user_name','sex','avatar','level','city_info','certify_status','certify_info','can_access'));
|
|
|
+ $local_user = array();
|
|
|
+ foreach ($rows as $value) {
|
|
|
+ $value['recommend_reason'] = '同城用户';
|
|
|
+ $local_user[] = $value;
|
|
|
+ }
|
|
|
+
|
|
|
+ $criteria = new EMongoCriteria;
|
|
|
+ if(isset($city_info['province']) && $city_info['province']){
|
|
|
+ $criteria->city_info->province('!=',$city_info['province']);
|
|
|
+ }else{
|
|
|
+ $criteria->city_info->province('!=','上海市');
|
|
|
+ }
|
|
|
+ $criteria->_id('notin',$follow_users);
|
|
|
+ $criteria->is_fake_user('!=',1);
|
|
|
+ $criteria->certify_status('!=',1);
|
|
|
+ $criteria->sort('posts_count',EMongoCriteria::SORT_DESC);
|
|
|
+ $criteria->sort('last_visit_time',EMongoCriteria::SORT_DESC);
|
|
|
+ $criteria->limit(5);
|
|
|
+ $cursor = RUser::model()->findAll($criteria);
|
|
|
+ $rows = RUser::model()->parse($cursor,true,array('id','user_name','sex','avatar','level','city_info','certify_status','certify_info','can_access'));
|
|
|
+ $hot_users = array();
|
|
|
+ foreach ($rows as $value) {
|
|
|
+ $value['recommend_reason'] = '活跃用户';
|
|
|
+ $hot_users[] = $value;
|
|
|
+ }
|
|
|
+
|
|
|
+ $result = array_merge($certify_users,$local_user,$hot_users);
|
|
|
+ shuffle($result);
|
|
|
+ foreach ($result as $key => $user) {
|
|
|
+ $result[$key]['relation'] = $user_node->relation($user['id']);
|
|
|
+ }
|
|
|
+ CommonFn::requestAjax(true,CommonFn::getMessage('message','operation_success'),array('recommend_list'=>$result));
|
|
|
+ }
|
|
|
+
|
|
|
+ //用户登出接口
|
|
|
+ public function actionLogout(){
|
|
|
+ $user_id = Yii::app()->getRequest()->getParam("user_id");
|
|
|
+ $xinge_token = Yii::app()->getRequest()->getParam("xinge_token");
|
|
|
+ $app_client_id = Yii::app()->getRequest()->getParam("app_client_id");
|
|
|
+ require_once(APP_PATH."/protected/vendors/tencent/XingeApp.php");
|
|
|
+ if($app_client_id == '2'){
|
|
|
+ $xinge_config = Yii::app()->params['xingeConfig']['android'];
|
|
|
+ $push = new XingeApp($xinge_config['accessId'],$xinge_config['secretKey']);
|
|
|
+ $ret = $push->DeleteTokenOfAccount($user_id,$xinge_token);
|
|
|
+ CommonFn::requestAjax(true,'注销成功');
|
|
|
+ }elseif($app_client_id == '1'){
|
|
|
+ $xinge_ios_config = Yii::app()->params['xingeConfig']['ios'];
|
|
|
+ $push = new XingeApp($xinge_ios_config['accessId'],$xinge_ios_config['secretKey']);
|
|
|
+ $ret = $push->DeleteTokenOfAccount($user_id,$xinge_token);
|
|
|
+ CommonFn::requestAjax(true,'注销成功');
|
|
|
+ }else{
|
|
|
+ CommonFn::requestAjax(false,'操作失败');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|