| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 | <?phpnamespace app\api\controller;use Limen\Redisun\Examples\HashModel;use Limen\Redisun\Examples\StringModel;use think\Db;use think\Cache;/** * 眼缘接口 */class Eyemargin extends Common{    protected $noNeedLogin = [];    protected $noNeedRight = '*';    public function _initialize()    {        parent::_initialize();    }    /**     * 发布眼缘     */    public function addFate() {        $eye_type = $this->request->request('eye_type'); // 动态类型        $content = $this->request->request('content'); // 内容        if (!in_array($eye_type,[1,2]) || !$content) {            $this->error(__('Invalid parameters'));        }        $str_arr = sensitive($content);        if($str_arr['count'] > 0) {            $this->error(__('发布内容存在敏感词汇:'.$str_arr['sensitiveWord'].' 请重新编辑后发布!'));        }        // 判断当前用户是否实名认证        $userAuthInfo = \app\common\model\UserAuth::userIsAuth($this->auth->id);        if($userAuthInfo['status'] == 0) $this->error($userAuthInfo['msg']);        $data = [];        $data["user_id"] = $this->auth->id;        $data["eye_type"] = $eye_type;        $data["content"] = $content;        if($eye_type == 2) {            $cover = $this->request->request('cover'); // 影集封面图            $album = $this->request->request('album'); // 影集图片            $music = $this->request->request('music'); // 背景音乐            if(!$cover || !$album || !$music) {                $this->error(__('Invalid parameters'));            }            $data['cover'] = $cover;            $data['album'] = $album;            $data['music'] = $music;        } elseif($eye_type == 1) {            $video = $this->request->request('video'); // 视频文件            if(!$video) {                $this->error(__('视频图片缺失!'));            }            $cover = $this->request->request('cover'); // 影集封面图            $data['cover'] = $cover;//            $video_cover = str_replace("https://","http://",$video);//            $cover = 'uploads/video_cover/'.date('Ymd').date('His').rand(1000,9999).'.png';//            getVideoCover($video_cover,2,$cover);//            $full_cover = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"].'/'.$cover;//            $data['cover'] = $full_cover;            $data['video'] = $video;        }        $eyemarginModel = new \app\common\model\Eyemargin();        $data["createtime"] = time();        // 判断是否是第一个视频        $info = $eyemarginModel->where(['user_id'=>$this->auth->id,'status'=>['in',[0,1]]])->find();        if(!$info) {            $data['is_main'] = 1;            $msg = "恭喜,视频已发布审核中!温馨提示:长按可以取消或者修改'推荐'短视频,推荐的视频会展示给同城好友哦";        } else {            $msg = "发布成功!请耐心等待审核!";        }        $res = $eyemarginModel->insertGetId($data);        if($res) {            $this->success($msg);        } else {            $this->error("网络错误,请稍后重试");        }    }    /**     * 当数据为空时     * @param $is_goddess     * @param $is_new     * @param $redis_ids     * @param $field     * @param $user_id     * @return false|mixed|\PDOStatement|string|\think\Collection     */    private function getFateInfo($redis_ids,$field,$user_id,&$common_where) {        $redis_ids && $common_where['a.id'] = ['notin',implode(',',$redis_ids)];        // 按照距离排序        $where = [];        $where = array_merge($where,$common_where);        $a = \app\common\model\Eyemargin::getDistanceList($this->auth->lng,$this->auth->lat,$field,$where,$user_id);        return $a;    }    /**     * 获取眼缘视频/影集     */    public function getFate() {        $is_goddess = $this->request->request('is_goddess'); // 是否女神:1=是,0=否        $is_new = $this->request->request('is_new'); // 是否新人:1=是,0=否        $is_neal = $this->request->request('is_neal'); // 是否附近:1=是,0=否        if (!in_array($is_goddess,[0,1]) && !in_array($is_new,[0,1]) && !in_array($is_neal,[0,1])) {            $this->error(__('请选择展示tab!'));        }        $pageNum = $this->request->request('pageNum',10); // 每页显示条数        $user_id = $this->auth->id;        $user_id_redis = 'u_'.$user_id;        $redis_ids = json_decode(Cache::get($user_id_redis),true);        $time = time() - 30*86400;        $common_where = [];        $common_where['a.is_main'] = 1;        $common_where['a.status'] = 1;        $common_where['u.city'] = $this->auth->city;        $is_goddess && $common_where['u.is_goddess'] = 1;        $is_new && $common_where['u.createtime'] = ['gt',$time];        $common_where['a.status'] = 1;        $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";        $list = [];        $a = $this->getFateInfo($redis_ids,$field,$user_id,$common_where);        if(!$a) {            Cache::rm($user_id_redis);            unset($common_where['a.id']);            $redis_ids = [];            $a = $this->getFateInfo($redis_ids,$field,$user_id,$common_where);        }        // 女神        $where = [];        $where['u.is_goddess'] = 1;        $where = array_merge($where,$common_where);        $b = \app\common\model\Eyemargin::getDistanceList($this->auth->lng,$this->auth->lat,$field,$where,$user_id);        // 喜好 期望对象        $expect = $this->auth->expect_ids;        $user_ids =\app\common\model\Expect::getTagsByExpect($expect);        if($user_ids) {            $where = [];            $where['u.id'] = ['in',implode(',',$user_ids)];            $where = array_merge($where,$common_where);            $c = \app\common\model\Eyemargin::getDistanceList($this->auth->lng,$this->auth->lat,$field,$where,$user_id);        } else {            $c = [];        }        // 新人        $where = [];        $where['u.createtime'] = ['gt',$time];        $where = array_merge($where,$common_where);        $d = \app\common\model\Eyemargin::getDistanceList($this->auth->lng,$this->auth->lat,$field,$where,$user_id);        // 剩余        // 三数组合并        $bcd = \app\common\model\Eyemargin::arrayMerge($b,$c,$d);        $e = array_diff($a,$bcd);        // 附近        $num_a = floor(config("site.nearbyTheOne") * 0.01 * $pageNum);        $num_bcd = floor(config("site.nearbyTheTwo") * 0.01 * $pageNum);        $num_e = $pageNum - $num_a - $num_bcd;        // 先做好去重        $a = array_slice($a,0,$pageNum);        $bcd = array_diff($bcd,$a);        $e = array_diff($e,array_merge($bcd,$a));        $count_a = count($a);        $count_e = count($e);        $count_bcd = count($bcd);        if($count_a <= ($num_a+$num_bcd+$num_e)) {            $list = $a;        }        if($count_a >= $num_a && $count_bcd >= $num_bcd && $count_e >= $num_e) {            $list_a = array_slice($a,0,$num_a);            $list_bcd = array_slice($bcd,0,$num_bcd);            $list_e = array_slice($e,0,$num_e);            $list = \app\common\model\Eyemargin::arrayMerge($list_a,$list_bcd,$list_e);        }        // 10 = 10 =        if($count_a >= $num_a && $count_bcd >= $num_bcd && $count_e < $num_e) {            $list_a = array_slice($a,0,$pageNum-$num_bcd - $count_e);            $list_bcd = array_slice($bcd,0,$num_bcd);            $list_e = $e;            $list = \app\common\model\Eyemargin::arrayMerge($list_a,$list_bcd,$list_e);        }        if($count_a >= $num_a && $count_bcd < $num_bcd && $count_e < $num_e) {            $list_a = array_slice($a,0,$pageNum-$count_bcd-$count_e);            $list_bcd = $bcd;            $list_e = $e;            $list = \app\common\model\Eyemargin::arrayMerge($list_a,$list_bcd,$list_e);        }        if($count_a >= $num_a && $count_bcd < $num_bcd && $count_e >= $num_e) {            $list_a = array_slice($a,0,$pageNum-$count_bcd-$num_e);            $list_bcd = $bcd;            $list_e = array_slice($e,0,$num_e);            $list = \app\common\model\Eyemargin::arrayMerge($list_a,$list_bcd,$list_e);        }        if($list) {            // 收集眼缘ID            $ids = array_column($list, 'id');            if($redis_ids) {                $redis_ids = array_merge($redis_ids,$ids);            } else {                $redis_ids = $ids;            }            Cache::set($user_id_redis,json_encode($redis_ids));        } else {            Cache::rm($user_id_redis);        }        $this->success("获取成功!",$list);    }    /**     * 判断当前用户是否已经把我加到黑名单     */    public function isBlackUser() {        $user_id = $this->request->request('user_id'); // 用户ID        if(!$user_id) $this->error("参数缺失!");        $where = [];        $where['user_id'] = $user_id;        $where['black_user_id'] = $this->auth->id;        $blackInfo = \app\common\model\UserBlacklist::where($where)->find();        if($blackInfo) {            $this->success("获取成功!",['is_black'=>1]);        } else {            $this->success("获取成功!",['is_black'=>0]);        }    }}
 |