Commit 5e254bbe authored by wuxiaoli's avatar wuxiaoli

推荐好友

parent 0f857d33
Pipeline #749 canceled with stages
......@@ -12,6 +12,7 @@ use app\api\model\FriendCommentModel;
use app\api\model\FriendLikeModel;
use app\api\model\HotcircleModel;
use app\api\model\JoinCircle;
use app\api\model\UsersModel;
use app\common\controller\Api;
use fast\Tree;
use think\Db;
......@@ -345,29 +346,65 @@ class Friend extends Api{
* 随机推荐好友
*/
public function getRandomFriends(){
$where = ['user_id' =>['neq',$this->auth->id]];
$total = Db::name('fastim_user')->where($where)->count();
$min = Db::name('fastim_user')->where($where)->min('id');//统计某个字段最小数据
$num = 30;
if($total < $num){$num = $min;}
$i = 1;
$flag = 0;
$ary = [];
while($i<=$num){
$rundnum = rand($min, $total);//抽取随机数
if($flag != $rundnum){
//过滤重复
if(!in_array($rundnum,$ary)){
$ary[] = $rundnum;
$flag = $rundnum;
}else{
$i--;
$type=$this->request->post("type",1);
if($type==1){//推荐
$where = ['user_id' =>['neq',$this->auth->id]];
$total = Db::name('fastim_user')->where($where)->count();
$min = Db::name('fastim_user')->where($where)->min('id');//统计某个字段最小数据
$num = 30;
if($total < $num){$num = $min;}
$i = 1;
$flag = 0;
$ary = [];
while($i<=$num){
$rundnum = rand($min, $total);//抽取随机数
if($flag != $rundnum){
//过滤重复
if(!in_array($rundnum,$ary)){
$ary[] = $rundnum;
$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
//默认配置
protected $config = [];
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 = [])
{
......
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