123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Db;
- use think\Cache;
- /**
- * 搜索
- */
- class Search extends Api
- {
- //
- // 无需登录的接口,*表示全部
- protected $noNeedLogin = [];
- // 无需鉴权的接口,*表示全部
- protected $noNeedRight = ['*'];
- public function search(){
- $page = $this->request->request('page',1); // 分页
- $pageNum = $this->request->request('pageNum',10); // 分页
- $type = input('type',1);
- $keyword = input('keyword','');
- if(empty($keyword)){
- $this->error('请输入关键词');
- }
- if($type == 1){
- $list = $this->getFate($keyword,$page,$pageNum);
- }else{
- $list = model('user')->field('id,nickname,avatar,age,constellation,profession,gender')->where('nickname','LIKE','%'.$keyword.'%')->page($page,$pageNum)->select();
- if ($list) {
- $user_fate = Db::name('user_fate');
- foreach ($list as &$v) {
- $fate_info = $user_fate->where(['user_id' => $this->auth->id, 'fate_user_id' => $v['id'], 'createtime' => ['egt', time() - 86400]])->find();
- if ($fate_info) {
- $v['is_fate'] = 1;
- $v['countdown'] = $fate_info['createtime'] + 86400 - time();
- } else {
- $v['is_fate'] = 0;
- $v['countdown'] = 0; //倒计时时间
- }
- //是否关注
- $follow_info = Db::name('user_follow')->where(['user_id' => $this->auth->id, 'to_user_id' => $v['id']])->find();
- if ($follow_info) {
- $v['is_follow'] = 1;
- } else {
- $v['is_follow'] = 0;
- }
- }
- }
- }
- $this->success('success',$list);
- }
- /**
- *
- * 获取眼缘视频/影集
- */
- public function getFate($keyword = '',$page,$pageNum) {
- $common_where = [];
- $common_where['a.status'] = 1;
- $common_where['a.content'] = ['LIKE','%'.$keyword.'%'];
- $field = "a.*,u.avatar,u.city_name,u.district_name,u.nickname,u.is_goddess,u.is_auth,vipStatus(u.vip_duetime) as is_vip,
- u.age,u.constellation,u.hobby_ids,u.profession,u.declaration,u.lng,u.lat,u.mobile,u.copy_mobile,u.wechat,u.gender,u.profession";
- $list = \app\common\model\Eyemargin::getDistanceList($this->auth->lng,$this->auth->lat,$field,$common_where,$this->auth->id,$page,$pageNum);
- return $list;
- }
- }
|