Commit 5e254bbe authored by wuxiaoli's avatar wuxiaoli

推荐好友

parent 0f857d33
Pipeline #749 canceled with stages
...@@ -12,6 +12,7 @@ use app\api\model\FriendCommentModel; ...@@ -12,6 +12,7 @@ use app\api\model\FriendCommentModel;
use app\api\model\FriendLikeModel; use app\api\model\FriendLikeModel;
use app\api\model\HotcircleModel; use app\api\model\HotcircleModel;
use app\api\model\JoinCircle; use app\api\model\JoinCircle;
use app\api\model\UsersModel;
use app\common\controller\Api; use app\common\controller\Api;
use fast\Tree; use fast\Tree;
use think\Db; use think\Db;
...@@ -345,6 +346,8 @@ class Friend extends Api{ ...@@ -345,6 +346,8 @@ class Friend extends Api{
* 随机推荐好友 * 随机推荐好友
*/ */
public function getRandomFriends(){ public function getRandomFriends(){
$type=$this->request->post("type",1);
if($type==1){//推荐
$where = ['user_id' =>['neq',$this->auth->id]]; $where = ['user_id' =>['neq',$this->auth->id]];
$total = Db::name('fastim_user')->where($where)->count(); $total = Db::name('fastim_user')->where($where)->count();
$min = Db::name('fastim_user')->where($where)->min('id');//统计某个字段最小数据 $min = Db::name('fastim_user')->where($where)->min('id');//统计某个字段最小数据
...@@ -366,8 +369,42 @@ class Friend extends Api{ ...@@ -366,8 +369,42 @@ class Friend extends Api{
$i++; $i++;
} }
} }
$list = Db::name('fastim_user')->where($where)->where(['id'=>['in',$ary]])->select(); $map['id'] = ['in',$ary];
$this->success('操作成功',['list' =>$list]); }else {
if($type==2){//同姓
$where['surname_id'] = $this->auth->surname_id;
}else if($type==3){//同乡
$where['village_id'] = $this->auth->village_id;
}else if($type==4){//同校
$educational=UsersModel::where(['id'=>$this->auth->id])->value("educational");
$school=array_column(json_decode($educational), "school");
$where = '';
foreach ($school as $k=>$v){
if($k==0){
$where = " educational like '%".$v."%'";
}else{
$where = $where. " OR educational like '%".$v."%'";
}
}
}else if($type==5){//同事
$work_experience=UsersModel::where(['id'=>$this->auth->id])->value("work_experience");
$company=array_column(json_decode($work_experience), "company");
$where = '';
foreach ($company as $k=>$v){
if($k==0){
$where = " work_experience like '%".$v."%'";
}else{
$where = $where. " OR work_experience like '%".$v."%'";
}
}
}
$ids=UsersModel::where($where)->column("id");
$map['user_id'] = ['in',$ids];
}
$list = Db::name('fastim_user')->where(['user_id'=>['neq',$this->auth->id]])->where($map)->limit(30)->select();
$this->success('操作成功',['list' =>$list]);
} }
} }
\ No newline at end of file
...@@ -29,7 +29,7 @@ class Auth ...@@ -29,7 +29,7 @@ class Auth
//默认配置 //默认配置
protected $config = []; protected $config = [];
protected $options = []; protected $options = [];
protected $allowFields = ['id', 'username', 'nickname', 'mobile', 'avatar', 'score', 'prevtime' ,'wx_openid', 'app_openid', 'unionid', 'money', 'level','is_shaikh','commission','agent_money', 'province_id', 'city_id','area_id','town_id','village_id']; protected $allowFields = ['id', 'username','surname_id', 'nickname', 'mobile', 'avatar', 'score', 'prevtime' ,'wx_openid', 'app_openid', 'unionid', 'money', 'level','is_shaikh','commission','agent_money', 'province_id', 'city_id','area_id','town_id','village_id'];
public function __construct($options = []) public function __construct($options = [])
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment