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,29 +346,65 @@ class Friend extends Api{ ...@@ -345,29 +346,65 @@ class Friend extends Api{
* 随机推荐好友 * 随机推荐好友
*/ */
public function getRandomFriends(){ public function getRandomFriends(){
$where = ['user_id' =>['neq',$this->auth->id]]; $type=$this->request->post("type",1);
$total = Db::name('fastim_user')->where($where)->count(); if($type==1){//推荐
$min = Db::name('fastim_user')->where($where)->min('id');//统计某个字段最小数据 $where = ['user_id' =>['neq',$this->auth->id]];
$num = 30; $total = Db::name('fastim_user')->where($where)->count();
if($total < $num){$num = $min;} $min = Db::name('fastim_user')->where($where)->min('id');//统计某个字段最小数据
$i = 1; $num = 30;
$flag = 0; if($total < $num){$num = $min;}
$ary = []; $i = 1;
while($i<=$num){ $flag = 0;
$rundnum = rand($min, $total);//抽取随机数 $ary = [];
if($flag != $rundnum){ while($i<=$num){
//过滤重复 $rundnum = rand($min, $total);//抽取随机数
if(!in_array($rundnum,$ary)){ if($flag != $rundnum){
$ary[] = $rundnum; //过滤重复
$flag = $rundnum; if(!in_array($rundnum,$ary)){
}else{ $ary[] = $rundnum;
$i--; $flag = $rundnum;
}else{
$i--;
}
$i++;
} }
$i++;
} }
$map['id'] = ['in',$ary];
}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($where)->where(['id'=>['in',$ary]])->select();
$this->success('操作成功',['list' =>$list]);
$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