['neq',$this->auth->id], 'user.status' => 1, 'user.gender' => ['neq',$this->auth->gender], ]; if(!empty($keyworld)){ $where['user.username|nickname'] = ['LILE','%'.$keyworld.'%']; } //排除黑名单的 $where_black = []; $black_ids = Db::name('user_black')->where(['uid'=>$this->auth->id])->column('black_uid'); if(!empty($black_ids)){ $where_black['user.id'] = ['NOTIN',$black_ids]; } $field = [ 'user.id', 'user.username', 'user.nickname', 'user.avatar', 'user.idcard_status', 'user.real_status', 'user.photo_images', 'user.gender', 'user.birthday', 'user.is_active', 'wallet.vip_endtime', 'active.requesttime', ]; $list = Db::name('user')->alias('user')->field($field) ->join('user_wallet wallet','user.id = wallet.user_id','LEFT') ->join('user_active active' ,'user.id = active.user_id','LEFT') ->where($where) ->where($where_black) ->order('user.is_active desc,user.id desc') ->autopage() ->select(); $list = list_domain_image($list,['avatar','photo_images']); foreach($list as $key => &$val){ $val['age'] = birthtime_to_age($val['birthday']); $val['is_vip'] = $val['vip_endtime'] > time() ? 1 : 0; $val['active_info'] = $this->user_activeinfo($val['id'],$val['requesttime']); } $this->success(1,$list); } //新人 public function xinren(){ $keyworld = input('keyworld',''); $where = [ 'user.id' => ['neq',$this->auth->id], 'user.status' => 1, 'user.gender' => ['neq',$this->auth->gender], ]; if(!empty($keyworld)){ $where['user.username|nickname'] = ['LILE','%'.$keyworld.'%']; } //排除黑名单的 $where_black = []; $black_ids = Db::name('user_black')->where(['uid'=>$this->auth->id])->column('black_uid'); if(!empty($black_ids)){ $where_black['user.id'] = ['NOTIN',$black_ids]; } $field = [ 'user.id', 'user.username', 'user.nickname', 'user.avatar', 'user.idcard_status', 'user.real_status', 'user.photo_images', 'user.gender', 'user.birthday', 'user.is_active', 'wallet.vip_endtime', 'active.requesttime', ]; $list = Db::name('user')->alias('user')->field($field) ->join('user_wallet wallet','user.id = wallet.user_id','LEFT') ->join('user_active active' ,'user.id = active.user_id','LEFT') ->where($where) ->where($where_black) ->order('user.is_active desc,user.id desc') ->autopage() ->select(); $list = list_domain_image($list,['avatar','photo_images']); foreach($list as $key => &$val){ $val['age'] = birthtime_to_age($val['birthday']); $val['is_vip'] = $val['vip_endtime'] > time() ? 1 : 0; $val['active_info'] = $this->user_activeinfo($val['id'],$val['requesttime']); } $this->success(1,$list); } //匹配配置 public function pipei_config(){ $result = [ 'index_pipei_switch' => config('site.index_pipei_switch'), //匹配开关 ]; //首页匹配每天每人匹配次数 $user_id = $this->auth->id; $is_vip = $this->is_vip($this->auth->id); $times_limit = $is_vip == 1 ? config('site.pipei_oneday_vipuser_times') : config('site.index_pipei_oneday_user_times'); $times_limit_redis = 'pipei_times_limit_'.$user_id; $user_times = Cache::get($times_limit_redis) ?: 0; if($times_limit > -1){ $remain_times = $times_limit - $user_times; if($remain_times < 0){ $remain_times = 0; } }else{ $remain_times = -1; } $result['remain_times'] = $remain_times; $this->success(1,$result); } //匹配 //做防止重复处理,参照荔枝 public function pipei(){ //首页匹配功能开关 $index_pipei_switch = config('site.index_pipei_switch'); if($index_pipei_switch != 1){ $this->error('匹配功能维护中,请稍后再试'); } //缓存,防重复 $user_id = $this->auth->id; $user_id_redis = 'pipei_repeat_'.$user_id; $redis_ids = json_decode(Cache::get($user_id_redis),true); //首页匹配每天每人匹配次数 $is_vip = $this->is_vip($this->auth->id); $times_limit = $is_vip == 1 ? config('site.pipei_oneday_vipuser_times') : config('site.index_pipei_oneday_user_times'); $times_limit_redis = 'pipei_times_limit_'.$user_id; $user_times = Cache::get($times_limit_redis) ?: 0; if($times_limit > -1 && $user_times >= $times_limit){ $this->error('今日已超匹配上限'.$times_limit.'次'); } //where $where = [ 'user.id' => ['neq',$this->auth->id], 'user.status' => 1, 'user.is_active' => 1, ]; //性别 $gender = input('gender','all'); if($gender != 'all'){ $where['user.gender'] = $gender; } //排除黑名单的 $where_black = []; $black_ids = Db::name('user_black')->where(['uid'=>$this->auth->id])->column('black_uid'); if(!empty($black_ids)){ $where_black['user.id'] = ['NOTIN',$black_ids]; } //匹配一个 $result = $this->pipei_action($redis_ids,$where,$where_black); //匹配不到,移除防重复 if(!$result) { Cache::rm($user_id_redis); $redis_ids = []; $result = $this->pipei_action($redis_ids,$where,$where_black); } // 追加一个防重复 if($result){ if($redis_ids) { $redis_ids[] = $result; } else { $redis_ids = [$result]; } Cache::set($user_id_redis,json_encode($redis_ids)); //设置次数 $second = strtotime(date('Y-m-d'))+86400 - time(); Cache::set($times_limit_redis,$user_times+1,$second); }else{ Cache::rm($user_id_redis); } $this->success(1,$result); } private function pipei_action($redis_ids,$where,$where_black){ $where_op = []; if(!empty($redis_ids)){ $where_op['user.id'] = ['NOTIN',$redis_ids]; } $result = Db::name('user')->alias('user') //->join('user_active active' ,'user.id = active.user_id','LEFT') ->where($where) ->where($where_op) ->where($where_black) ->orderRaw('rand()') ->value('user.id'); return $result; } /////////////////////////////////// public function test(){ //缓存,防重复 $user_id = $this->auth->id; $user_id_redis = 'pipei_repeat_'.$user_id; $redis_ids = json_decode(Cache::get($user_id_redis),true); dump($redis_ids); $times_limit_redis = 'pipei_times_limit_'.$user_id; $user_times = Cache::get($times_limit_redis) ?: 0; dump($user_times); } public function testrm(){ $user_id = $this->auth->id; $user_id_redis = 'pipei_repeat_'.$user_id; Cache::rm($user_id_redis); $times_limit_redis = 'pipei_times_limit_'.$user_id; Cache::rm($times_limit_redis); } }