| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996 | 
							- <?php
 
- namespace app\api\controller;
 
- use app\common\controller\Api;
 
- use think\Db;
 
- use app\common\model\wallet;
 
- use Redis;
 
- /**
 
-  * 会员中心,不是个人中心
 
-  */
 
- class Usercenter extends Api
 
- {
 
-     protected $noNeedLogin = [];
 
-     protected $noNeedRight = '*';
 
-     protected $allowFields = [
 
-         'id',
 
-         'username',
 
-         'nickname',
 
-         'truename',
 
-         'mobile',
 
-         'avatar',
 
-         'real_status',
 
-         'gender',
 
-         'height',
 
-         'weight',
 
-         'birthday',
 
-         'bio',
 
-         'idcard_status',
 
-         'cityname',
 
-         'photo_images',
 
-         'tag_ids',
 
-         'attribute',
 
-         'shoesize',
 
-         'wechat_account',
 
-     ];
 
-     //获取他人用户信息,留下足迹
 
-     public function getuserinfo(){
 
-         $uid = input_post('uid',0);
 
-         $userinfo = Db::name('user')->field($this->allowFields)->where('id',$uid)->find();
 
-         if(!$userinfo){
 
-             $this->error('不存在的用户');
 
-         }
 
-         //用户数据
 
-         $userinfo = info_domain_image($userinfo,['avatar','photo_images']);
 
-         $idcard_confirm = Db::name('user_idconfirm')->where('user_id',$uid)->find();
 
-         $new_data = [
 
-             'age'            => birthtime_to_age($userinfo['birthday']),
 
-             'truename'       => ($userinfo['idcard_status'] == 1 && isset($idcard_confirm['truename'])) ? $idcard_confirm['truename'] : '',
 
-         ];
 
-         //合并
 
-         $userinfo = array_merge($userinfo,$new_data);
 
-         //枚举
 
-         $userinfo['tag'] = Db::name('enum_tag')->where('id','IN',$userinfo['tag_ids'])->field(['id','name'])->select();
 
-         //vip
 
-         $userinfo['vip_endtime'] = Db::name('user_wallet')->where('user_id',$uid)->value('vip_endtime');
 
-         $userinfo['is_vip'] = $userinfo['vip_endtime'] > time() ? 1 : 0;
 
-         //是否喜欢和关注
 
-         $is_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>$uid])->find();
 
-         $userinfo['is_follow'] = $is_follow ? 1 : 0;
 
-         $is_like   = Db::name('user_like')->where(['uid'=>$this->auth->id,'like_uid'=>$uid])->find();
 
-         $userinfo['is_like'] = $is_like ? 1 : 0;
 
-         //是否拉黑
 
-         $is_black = Db::name('user_black')->where(['uid'=>$this->auth->id,'black_uid'=>$uid])->find();
 
-         $userinfo['is_black'] = $is_black ? 1 : 0;
 
-         //关注人数,粉丝人数
 
-         $follow_num = Db::name('user_follow')->where(['uid'=>$this->auth->id])->count('id');
 
-         $fans_num   = Db::name('user_follow')->where(['follow_uid'=>$this->auth->id])->count('id');
 
-         $userinfo['follow_num'] = $follow_num;
 
-         $userinfo['fans_num'] = $fans_num;
 
-         //查看别人信息,就要留下痕迹
 
-         $data = [
 
-             'uid' => $this->auth->id,
 
-             'to_uid' => $uid,
 
-         ];
 
-         $check = Db::name('user_visit')->where($data)->find();
 
-         if($check){
 
-             Db::name('user_visit')->where($data)->update(['number'=>$check['number']+1,'updatetime'=>time()]);
 
-         }else{
 
-             $data['number'] = 1;
 
-             $data['updatetime'] = time();
 
-             Db::name('user_visit')->insertGetId($data);
 
-         }
 
-         //活跃,在线
 
-         $userinfo['is_active'] = $this->user_isactive($uid);
 
-         $this->success('success',$userinfo);
 
-     }
 
- /////////////////////////////////////////////////////////////////////////////////////
 
-     //这里不用连user_active表,完全使用user表的active_time,user_active表只做离线用
 
-     //同城
 
-     public function samecity(){
 
-         $gender = input_post('gender','all');
 
-         $agemin = input_post('agemin',0);
 
-         $agemax = input_post('agemax',100);
 
-         if(empty($this->auth->cityname) || empty($this->auth->longitude) || empty($this->auth->latitude)){
 
-            // $this->success('success',[]);
 
-         }
 
-         $map = [
 
-             'user.status' => 1,
 
-            // 'user.cityname' => $this->auth->cityname,
 
-             'user.id' => ['neq',$this->auth->id],
 
-            // 'user.longitude' => ['neq',''],
 
-            // 'user.latitude' => ['neq',''],
 
-            // 'user.is_online|user.is_livebc' => 1, //完全不考虑直播与语聊的权重,只用活跃做排序
 
-            // 'user.active_time' => ['gt',time()-86400],
 
-         ];
 
-         if($gender != 'all'){
 
-             $map['user.gender'] = $gender;
 
-         }
 
-         $map['user.birthday'] = ['between',[time() - $agemax * 31536000,time() - $agemin * 31536000]];
 
-         //dump($map);
 
-         $field = [
 
-             'user.id','user.username','user.nickname','user.birthday','user.height','user.longitude','user.latitude','user.avatar','user.audio_bio','user.bio','user.gender','user.active_time'
 
-         ];
 
-         $list = Db::name('user')->alias('user')->field($field)->where($map)->order('user.active_time desc')->autopage()->select();
 
-         //dump($list);
 
-         $list = list_domain_image($list,['avatar']);
 
-         foreach($list as $key => $one){
 
-             $one['age'] = birthtime_to_age($one['birthday']);
 
-            // $one['distance'] = $this->calc_map_distance([$this->auth->longitude,$this->auth->latitude],[$one['longitude'],$one['latitude']]);
 
-             $one['distance'] = rand(0,10).'km';
 
-             //状态
 
-             $one['active_text'] = '刚刚离线';
 
-             if($one['active_time'] > time()-21600){
 
-                 $one['active_text'] = '1小时内在线';
 
-             }
 
-             if($one['active_time'] > time()-3600){
 
-                 $one['active_text'] = '在线';
 
-             }
 
-             $list[$key] = $one;
 
-         }
 
-         $this->success('success',$list);
 
-     }
 
-     //附近
 
-     public function nearuser(){
 
-         $gender = input_post('gender','all');
 
-         $agemin = input_post('agemin',0);
 
-         $agemax = input_post('agemax',100);
 
-         if(empty($this->auth->cityname) || empty($this->auth->longitude) || empty($this->auth->latitude)){
 
-            // $this->success('success',[]);
 
-         }
 
-         //经过地图测算和公式推算,经度纬度 0.1即为11公里
 
-         $map = [
 
-             'user.status' => 1,
 
-             ////'user.cityname' => $this->auth->cityname,
 
-             'user.id' => ['neq',$this->auth->id],
 
-            // 'user.longitude' => ['between',[$this->auth->longitude - 0.1,$this->auth->longitude + 0.1]],
 
-            // 'user.latitude' => ['between',[$this->auth->latitude - 0.1,$this->auth->latitude + 0.1]],
 
-             // 'user.is_online|user.is_livebc' => 1, //完全不考虑直播与语聊的权重,只用活跃做排序
 
-            // 'user.active_time' => ['gt',time()-86400],
 
-         ];
 
-         if($gender != 'all'){
 
-             $map['user.gender'] = $gender;
 
-         }
 
-         $map['user.birthday'] = ['between',[time() - $agemax * 31536000,time() - $agemin * 31536000]];
 
-         //dump($map);
 
-         $field = [
 
-             'user.id','user.username','user.nickname','user.birthday','user.height','user.longitude','user.latitude','user.avatar','user.audio_bio','user.bio','user.gender','user.active_time'
 
-         ];
 
-         $list = Db::name('user')->alias('user')->field($field)->where($map)->order('user.active_time desc')->autopage()->select();
 
-         //dump($list);exit;
 
-         $list = list_domain_image($list,['avatar']);
 
-         foreach($list as $key => $one){
 
-             $one['age'] = birthtime_to_age($one['birthday']);
 
-             //$one['distance'] = $this->calc_map_distance([$this->auth->longitude,$this->auth->latitude],[$one['longitude'],$one['latitude']]);
 
-             $one['distance'] = rand(0,10).'km';
 
-             //状态
 
-             $one['active_text'] = '刚刚离线';
 
-             if($one['active_time'] > time()-21600){
 
-                 $one['active_text'] = '1小时内在线';
 
-             }
 
-             if($one['active_time'] > time()-3600){
 
-                 $one['active_text'] = '在线';
 
-             }
 
-             
 
-             $list[$key] = $one;
 
-         }
 
-         $this->success('success',$list);
 
-     }
 
-     //因为接受者拿不到发起者的uid,废弃了
 
-     //视频和语音,接收方使用,如果是性别劣势方,检查钱是否够用
 
-     public function video_audio_moneycheck(){
 
-         //检测用户,发起方的uid
 
-         $to_user_id = input_post('from_user_id');
 
-         $to_user_info = Db::name('user')->field('id,real_status,gender')->where('id',$to_user_id)->find();
 
-         if(!$to_user_info){
 
-             $this->error('不存在的用户');
 
-         }
 
-         //扣费金币
 
-         $type = input_post('type','video');       //类型
 
-         $price = $type == 'video' ? config('site.video_min_price') : config('site.audio_min_price');
 
-         //发起用户的分数,被发起用户的分数。按性别给分
 
-         $auth_level = 0;
 
-         $tous_level = 0;
 
-         //打分
 
-         if($this->auth->gender == 0 && $this->auth->real_status == 1){
 
-             $auth_level = 30;//实名女最高
 
-         }
 
-         if($this->auth->gender == 0 && $this->auth->real_status != 1){
 
-             $auth_level = 20;//未实名女次之
 
-         }
 
-         if($this->auth->gender == 1){
 
-             $auth_level = 10;//男性最低
 
-         }
 
-         if($to_user_info['gender'] == 0 && $to_user_info['real_status'] == 1){
 
-             $tous_level = 30;
 
-         }
 
-         if($to_user_info['gender'] == 0 && $to_user_info['real_status'] != 1){
 
-             $tous_level = 20;
 
-         }
 
-         if($to_user_info['gender'] == 1){
 
-             $tous_level = 10;
 
-         }
 
-         //同性不收钱
 
-         //都是男的,不扣钱
 
-         //都是实名认证的女性,不扣钱
 
-         //都是未实名认证的女性,不扣钱
 
-         if($auth_level == $tous_level){
 
-             $price = 0;
 
-             $this->success('success');
 
-         }
 
-         //扣钱uid,收钱uid,收钱free_video
 
-         //分数少扣钱,分数多收益
 
-         if($auth_level < $tous_level){
 
-             $kou_user = $this->auth->id;
 
-         }else{
 
-             $kou_user = $to_user_info['id'];
 
-         }
 
-         //需要扣我的(接收方的)钱,判断钱是否够
 
-         if($price > 0 && $kou_user == $this->auth->id){
 
-             Db::startTrans();
 
-             $gold = model('wallet')->getWallet($kou_user,'gold');
 
-             if(bccomp($price,$gold) == 1){
 
-                 Db::rollback();
 
-                 $this->error('金币不足');
 
-             }
 
-             Db::commit();
 
-         }
 
-         $this->success('success');
 
-     }
 
-     //视频通话每分钟调用一次
 
-     public function video_onemin(){
 
-         //检测用户
 
-         $to_user_id = input_post('to_user_id');
 
-         $to_user_info = Db::name('user')->field('id,real_status,gender,free_video,free_audio,free_typing')->where('id',$to_user_id)->find();
 
-         if(!$to_user_info){
 
-             $this->error('不存在的用户');
 
-         }
 
-         //正常价格
 
-         $price = config('site.video_min_price');  //扣费金币
 
-         $bili  = config('site.money_to_gold');    //兑换比例
 
-         $gift_plat_scale = config('site.gift_plat_scale');  //抽成比例
 
-         $money = bcdiv($price,$bili,2);           //对应人民币
 
-         $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
 
-         //发起用户的分数,被发起用户的分数。按性别给分
 
-         $auth_level = 0;
 
-         $tous_level = 0;
 
-         //打分
 
-         if($this->auth->gender == 0 && $this->auth->real_status == 1){
 
-             $auth_level = 30;//实名女最高
 
-         }
 
-         if($this->auth->gender == 0 && $this->auth->real_status != 1){
 
-             $auth_level = 20;//未实名女次之
 
-         }
 
-         if($this->auth->gender == 1){
 
-             $auth_level = 10;//男性最低
 
-         }
 
-         if($to_user_info['gender'] == 0 && $to_user_info['real_status'] == 1){
 
-             $tous_level = 30;
 
-         }
 
-         if($to_user_info['gender'] == 0 && $to_user_info['real_status'] != 1){
 
-             $tous_level = 20;
 
-         }
 
-         if($to_user_info['gender'] == 1){
 
-             $tous_level = 10;
 
-         }
 
-         //同性不收钱
 
-         //都是男的,不扣钱
 
-         //都是实名认证的女性,不扣钱
 
-         //都是未实名认证的女性,不扣钱
 
-         if($auth_level == $tous_level){
 
-             $price = 0;$money = 0;
 
-         }
 
-         Db::startTrans();
 
-         //记录日志
 
-         $data = [
 
-             'user_id' => $this->auth->id,
 
-             'price'   => $price,
 
-             'createtime' => time(),
 
-             'to_user_id' => $to_user_id,
 
-             'money' => $money,
 
-         ];
 
-         $log_id = Db::name('user_match_video_log')->insertGetId($data);
 
-         if(!$log_id){
 
-             Db::rollback();
 
-             $this->error('扣费失败');
 
-         }
 
-         //同性别,提前结束
 
-         if($auth_level == $tous_level){
 
-             Db::commit();
 
-             $this->success('success');
 
-         }
 
-         //扣钱uid,收钱uid,收钱free_video
 
-         //分数少扣钱,分数多收益
 
-         if($auth_level < $tous_level){
 
-             $kou_user = $this->auth->id;
 
-             $get_user = $to_user_info['id'];
 
-             $get_user_free = $to_user_info['free_video'];
 
-         }else{
 
-             $kou_user = $to_user_info['id'];
 
-             $get_user = $this->auth->id;
 
-             $get_user_free = $this->auth->free_video;
 
-         }
 
-         //需要扣别人的钱,判断钱是否购
 
-         if($price > 0 && $kou_user != $this->auth->id){
 
-             $gold = model('wallet')->getWallet($kou_user,'gold');
 
-             if(bccomp($price,$gold) == 1){
 
-                 Db::rollback();
 
-                 $this->error('对方金币不足');
 
-             }
 
-         }
 
-         //有性别差,扣费
 
-         if($price > 0){
 
-             $rs = model('wallet')->lockChangeAccountRemain($kou_user,'gold',-$price,11,'','user_match_video_log',$log_id);
 
-             if($rs['status'] === false){
 
-                 Db::rollback();
 
-                 $this->error($rs['msg']);
 
-             }
 
-         }
 
-         //另一方加钱,0收费
 
-         if($money > 0 && $get_user_free == 0){
 
-             $rs = model('wallet')->lockChangeAccountRemain($get_user,'money',$money,21,'','user_match_video_log',$log_id);
 
-             if($rs['status'] === false){
 
-                 Db::rollback();
 
-                 $this->error($rs['msg']);
 
-             }
 
-         }
 
-         Db::commit();
 
-         $this->success('success');
 
-     }
 
-     //语音通话每分钟调用一次
 
-     public function audio_onemin(){
 
-         //检测用户
 
-         $to_user_id = input_post('to_user_id');
 
-         $to_user_info = Db::name('user')->field('id,real_status,gender,free_video,free_audio,free_typing')->where('id',$to_user_id)->find();
 
-         if(!$to_user_info){
 
-             $this->error('不存在的用户');
 
-         }
 
-         //正常价格
 
-         $price = config('site.audio_min_price');  //扣费金币
 
-         $bili  = config('site.money_to_gold');    //兑换比例
 
-         $gift_plat_scale = config('site.gift_plat_scale');  //抽成比例
 
-         $money = bcdiv($price,$bili,2);           //对应人民币
 
-         $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
 
-         //发起用户的分数,被发起用户的分数。按性别给分
 
-         $auth_level = 0;
 
-         $tous_level = 0;
 
-         //打分
 
-         if($this->auth->gender == 0 && $this->auth->real_status == 1){
 
-             $auth_level = 30;//实名女最高
 
-         }
 
-         if($this->auth->gender == 0 && $this->auth->real_status != 1){
 
-             $auth_level = 20;//未实名女次之
 
-         }
 
-         if($this->auth->gender == 1){
 
-             $auth_level = 10;//男性最低
 
-         }
 
-         if($to_user_info['gender'] == 0 && $to_user_info['real_status'] == 1){
 
-             $tous_level = 30;
 
-         }
 
-         if($to_user_info['gender'] == 0 && $to_user_info['real_status'] != 1){
 
-             $tous_level = 20;
 
-         }
 
-         if($to_user_info['gender'] == 1){
 
-             $tous_level = 10;
 
-         }
 
-         //同性不收钱
 
-         //都是男的,不扣钱
 
-         //都是实名认证的女性,不扣钱
 
-         //都是未实名认证的女性,不扣钱
 
-         if($auth_level == $tous_level){
 
-             $price = 0;$money = 0;
 
-         }
 
-         Db::startTrans();
 
-         //记录日志
 
-         $data = [
 
-             'user_id' => $this->auth->id,
 
-             'price'   => $price,
 
-             'createtime' => time(),
 
-             'to_user_id' => $to_user_id,
 
-             'money' => $money,
 
-         ];
 
-         $log_id = Db::name('user_match_audio_log')->insertGetId($data);
 
-         if(!$log_id){
 
-             Db::rollback();
 
-             $this->error('扣费失败');
 
-         }
 
-         //同性别,提前结束
 
-         if($auth_level == $tous_level){
 
-             Db::commit();
 
-             $this->success('success');
 
-         }
 
-         //扣钱uid,收钱uid,收钱free_video
 
-         //分数少扣钱,分数多收益
 
-         if($auth_level < $tous_level){
 
-             $kou_user = $this->auth->id;
 
-             $get_user = $to_user_info['id'];
 
-             $get_user_free = $to_user_info['free_audio'];
 
-         }else{
 
-             $kou_user = $to_user_info['id'];
 
-             $get_user = $this->auth->id;
 
-             $get_user_free = $this->auth->free_audio;
 
-         }
 
-         //需要扣别人的钱,判断钱是否购
 
-         if($price > 0 && $kou_user != $this->auth->id){
 
-             $gold = model('wallet')->getWallet($kou_user,'gold');
 
-             if(bccomp($price,$gold) == 1){
 
-                 Db::rollback();
 
-                 $this->error('对方金币不足');
 
-             }
 
-         }
 
-         //有性别差,扣费
 
-         if($price > 0){
 
-             $rs = model('wallet')->lockChangeAccountRemain($kou_user,'gold',-$price,12,'','user_match_audio_log',$log_id);
 
-             if($rs['status'] === false){
 
-                 Db::rollback();
 
-                 $this->error($rs['msg']);
 
-             }
 
-         }
 
-         //另一方加钱,0收费
 
-         if($money > 0 && $get_user_free == 0){
 
-             $rs = model('wallet')->lockChangeAccountRemain($get_user,'money',$money,22,'','user_match_audio_log',$log_id);
 
-             if($rs['status'] === false){
 
-                 Db::rollback();
 
-                 $this->error($rs['msg']);
 
-             }
 
-         }
 
-         Db::commit();
 
-         $this->success('success');
 
-     }
 
-     //打字聊天每句话调用一次
 
-     public function typing_once(){
 
-         //检测用户
 
-         $to_user_id = input_post('to_user_id');
 
-         $to_user_info = Db::name('user')->field('id,real_status,gender,free_video,free_audio,free_typing')->where('id',$to_user_id)->find();
 
-         if(!$to_user_info){
 
-             $this->error('不存在的用户');
 
-         }
 
-         //正常价格
 
-         $price = config('site.typing_min_price');  //扣费金币
 
-         $bili  = config('site.money_to_gold');    //兑换比例
 
-         $gift_plat_scale = config('site.gift_plat_scale');  //抽成比例
 
-         $money = bcdiv($price,$bili,2);           //对应人民币
 
-         $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
 
-         //发起用户的分数,被发起用户的分数。按性别给分
 
-         $auth_level = 0;
 
-         $tous_level = 0;
 
-         //打分
 
-         if($this->auth->gender == 0 && $this->auth->real_status == 1){
 
-             $auth_level = 30;//实名女最高
 
-         }
 
-         if($this->auth->gender == 0 && $this->auth->real_status != 1){
 
-             $auth_level = 20;//未实名女次之
 
-         }
 
-         if($this->auth->gender == 1){
 
-             $auth_level = 10;//男性最低
 
-         }
 
-         if($to_user_info['gender'] == 0 && $to_user_info['real_status'] == 1){
 
-             $tous_level = 30;
 
-         }
 
-         if($to_user_info['gender'] == 0 && $to_user_info['real_status'] != 1){
 
-             $tous_level = 20;
 
-         }
 
-         if($to_user_info['gender'] == 1){
 
-             $tous_level = 10;
 
-         }
 
-         //同性不收钱
 
-         //都是男的,不扣钱
 
-         //都是实名认证的女性,不扣钱
 
-         //都是未实名认证的女性,不扣钱
 
-         if($auth_level == $tous_level){
 
-             $price = 0;$money = 0;
 
-         }
 
-         //性别优势的人发起,免费
 
-         if($auth_level > $tous_level){
 
-             $price = 0;$money = 0;
 
-         }
 
-         Db::startTrans();
 
-         //记录日志
 
-         $data = [
 
-             'user_id' => $this->auth->id,
 
-             'price'   => $price,
 
-             'createtime' => time(),
 
-             'to_user_id' => $to_user_id,
 
-             'money' => $money,
 
-         ];
 
-         $log_id = Db::name('user_match_typing_log')->insertGetId($data);
 
-         if(!$log_id){
 
-             Db::rollback();
 
-             $this->error('扣费失败');
 
-         }
 
-         //同性别,提前结束
 
-         if($auth_level == $tous_level){
 
-             Db::commit();
 
-             $this->success('success');
 
-         }
 
-         //零消费,零收益消费,提前结束,其实这条没必要,下面金钱操作还会过滤一次
 
-         if($price == 0 && $money == 0){
 
-             Db::commit();
 
-             $this->success('success');
 
-         }
 
-         //扣钱uid,收钱uid,收钱free_video
 
-         //分数少扣钱,分数多收益
 
-         if($auth_level < $tous_level){
 
-             $kou_user = $this->auth->id;
 
-             $get_user = $to_user_info['id'];
 
-             $get_user_free = $to_user_info['free_typing'];
 
-         }else{
 
-             //这种已经没有了
 
-             $kou_user = $to_user_info['id'];
 
-             $get_user = $this->auth->id;
 
-             $get_user_free = $this->auth->free_typing;
 
-         }
 
-         //有性别差,扣费
 
-         if($price > 0){
 
-             $rs = model('wallet')->lockChangeAccountRemain($kou_user,'gold',-$price,13,'','user_match_typing_log',$log_id);
 
-             if($rs['status'] === false){
 
-                 Db::rollback();
 
-                 $this->error($rs['msg']);
 
-             }
 
-         }
 
-         //另一方加钱,0收费
 
-         if($money > 0 && $get_user_free == 0){
 
-             $rs = model('wallet')->lockChangeAccountRemain($get_user,'money',$money,23,'','user_match_typing_log',$log_id);
 
-             if($rs['status'] === false){
 
-                 Db::rollback();
 
-                 $this->error($rs['msg']);
 
-             }
 
-         }
 
-         //tag任务赠送金币
 
-         //搭讪奖励
 
-         $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,15);
 
-         if($task_rs === false){
 
-             Db::rollback();
 
-             $this->error('完成任务赠送奖励失败');
 
-         }
 
-         Db::commit();
 
-         $this->success('success');
 
-     }
 
-     //语音匹配
 
-     public function getaudiouser(){
 
-         //判断资格
 
-         /*$start = strtotime(date('Y-m-d'));
 
-         $end   = $start + 86399;
 
-         $map = [
 
-             'user_id' => $this->auth->id,
 
-             'createtime' => ['between',[$start,$end]],
 
-             'price' => 0,
 
-         ];
 
-         $check = Db::name('user_match_audio_log')->where($map)->find();*/
 
-         $check = true;
 
-         //已经用掉免费的了,判断金额
 
-         if($check){
 
-             $price = config('site.audio_min_price');
 
-             $gold = model('wallet')->getWallet($this->auth->id,'gold');
 
-             if($gold < $price){
 
-                 $this->error('您的金币已经不足,请充值');
 
-             }
 
-         }
 
-         //找到互关的人,排除
 
-         //$follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
 
-         //dump($follow_me);
 
-         //$my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
 
-         //dump($my_follow);exit;
 
-         //给出备选用户
 
-         $map = [
 
-             'status' =>1,                                       //未封禁用户
 
-             'gender' => $this->auth->gender == 1 ? 0 : 1,       //异性
 
-             'is_online' => 0,                                   //不在语聊间的
 
-             'is_livebc' => 0,                                   //不在直播的
 
-             'is_active' => 1,                                   //在线的
 
-             //'real_status' => 1,                                 //真人认证
 
-             //'idcard_status' => 1,                               //实名认证
 
-             'open_match_audio' => 1,                            //打开语聊开关
 
-             //'id' => ['NOT IN',$my_follow]                       //不是好友的
 
-             'id' => ['BETWEEN',[368,382]]
 
-         ];
 
-         $lists = Db::name('user')->field('id,cityname,status,gender,real_status,tag_ids')->where($map)->order('logintime desc')->page($this->page,100)->select();
 
-         $lists = $this->fliter_user($lists,10);
 
-         $result = [];
 
-         if(!empty($lists)){
 
-             foreach($lists as $key => $val){
 
-                 $result[] = ['id'=>$val];
 
-             }
 
-         }
 
-         //tag任务赠送金币
 
-         //语音匹配奖励  +5金币
 
-         if(!empty($result)){
 
-             $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,11);
 
-             if($task_rs === false){
 
-                 $this->error('完成任务赠送奖励失败');
 
-             }
 
-         }
 
-         $this->success('success',$result);
 
-     }
 
-     //视频匹配
 
-     public function getvideouser(){
 
-         //判断资格
 
-         /*$start = strtotime(date('Y-m-d'));
 
-         $end   = $start + 86399;
 
-         $map = [
 
-             'user_id' => $this->auth->id,
 
-             'createtime' => ['between',[$start,$end]],
 
-             'price' => 0,
 
-         ];
 
-         $check = Db::name('user_match_video_log')->where($map)->find();*/
 
-         $check = true;
 
-         //已经用掉免费的了,判断金额
 
-         if($check){
 
-             $price = config('site.video_min_price');
 
-             $gold = model('wallet')->getWallet($this->auth->id,'gold');
 
-             if($gold < $price){
 
-                 $this->error('您的金币已经不足,请充值');
 
-             }
 
-         }
 
-         //找到互关的人,排除
 
-         //$follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
 
-         //dump($follow_me);
 
-         //$my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
 
-         //dump($my_follow);exit;
 
-         //给出备选用户
 
-         $map = [
 
-             'status' =>1,                                       //未封禁用户
 
-             'gender' => $this->auth->gender == 1 ? 0 : 1,       //异性
 
-             'is_online' => 0,                                   //不在语聊间的
 
-             'is_livebc' => 0,                                   //不在直播的
 
-             'is_active' => 1,                                   //在线的
 
-             //'real_status' => 1,                                 //真人认证
 
-             //'idcard_status' => 1,                               //实名认证
 
-             'open_match_video' => 1,                            //打开视频开关的
 
-            // 'id' => ['NOT IN',$my_follow]                       //不是好友的
 
-             'id' => ['BETWEEN',[368,382]]
 
-         ];
 
-         $lists = Db::name('user')->field('id,cityname,status,gender,real_status,tag_ids')->where($map)->order('logintime desc')->page($this->page,100)->select();
 
-         $lists = $this->fliter_user($lists,10);
 
-         $result = [];
 
-         if(!empty($lists)){
 
-             foreach($lists as $key => $val){
 
-                 $result[] = ['id'=>$val];
 
-             }
 
-         }
 
-         //tag任务赠送金币
 
-         //视频匹配奖励  +5金币
 
-         if(!empty($result)){
 
-             $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,12);
 
-             if($task_rs === false){
 
-                 $this->error('完成任务赠送奖励失败');
 
-             }
 
-         }
 
-         $this->success('success',$result);
 
-     }
 
-     //聊天匹配
 
-     public function gettypinguser(){
 
-         //找到互关的人,排除
 
-         //$follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
 
-         //dump($follow_me);
 
-         //$my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
 
-         //dump($my_follow);exit;
 
-         //给出备选用户
 
-         $map = [
 
-             'status' =>1,                                        //未封禁用户
 
-             'gender' => $this->auth->gender == 1 ? 0 : 1,        //异性
 
-             //'real_status' => 1,                                 //真人认证
 
-             //'idcard_status' => 1,                               //实名认证
 
-             //'is_active' => 1,                                   //在线的
 
-             //打开聊天开关的
 
-             'open_match_typing' => 1,                            //打开文字聊天开关的
 
-             //'id' => ['NOT IN',$my_follow]                        //不是好友的
 
-             'id' => ['BETWEEN',[368,382]]
 
-         ];
 
-         $lists = Db::name('user')->field('id,cityname,status,gender,real_status,tag_ids')->where($map)->order('logintime desc')->page($this->page,100)->select();
 
-         //$lists = $this->fliter_user($lists,100);
 
-         $lists = array_column($lists,'id');
 
-         $result = [];
 
-         if(!empty($lists)){
 
-             /*foreach($lists as $key => $val){
 
-                 $result[] = ['id'=>$val];
 
-             }*/
 
-             $result = Db::name('user')->field('id,nickname,username,avatar,audio_bio')->where(['id'=>['IN',$lists]])->select();
 
-             $result = list_domain_image($result,['avatar,audio_bio']);
 
-         }
 
-         //tag任务赠送金币
 
-         //缘分匹配奖励  +5金币
 
-         if(!empty($result)){
 
-             $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,10);
 
-             if($task_rs === false){
 
-                 $this->error('完成任务赠送奖励失败');
 
-             }
 
-         }
 
-         $this->success('success',$result);
 
-     }
 
-     //过滤规则
 
-     private function fliter_user($lists,$number = 1){
 
-         if(empty($lists)){
 
-             return $lists;
 
-         }
 
-         //dump($lists);
 
-         //过滤掉通话中的
 
-         foreach($lists as $key => $val){
 
-             if(redis_matching_get($val['id']) == 1){
 
-                 unset($lists[$key]);
 
-             }
 
-         }
 
-         //预留全部
 
-         $all_result = array_column($lists,'id');
 
-         //dump($all_result);
 
-         //提取同城的
 
-         $citydata = [];
 
-         foreach($lists as $key => $val){
 
-             if( !empty($this->auth->cityname) && $this->auth->cityname == $val['cityname'] ){
 
-                 $citydata[] = $val['id'];
 
-             }
 
-         }
 
-         //dump($citydata);
 
-         //有标签交集的
 
-         $tagdata = [];
 
-         foreach($lists as $key => $val){
 
-             if( !empty($this->auth->tag_ids) && !empty($val['tag_ids']) ){
 
-                 $auth_tag_ids = explode(',',$this->auth->tag_ids);
 
-                 $val_tag_ids  = explode(',',$val['tag_ids']);
 
-                 if(count(array_intersect($auth_tag_ids,$val_tag_ids)) > 0){
 
-                     $tagdata[] = $val['id'];
 
-                 }
 
-             }
 
-         }
 
-         //dump($tagdata);
 
-         //双条件都满足
 
-         $double_data = [];
 
-         if(!empty($citydata) && !empty($tagdata)){
 
-             $double_data = array_intersect($citydata,$tagdata);
 
-         }
 
-         //dump($double_data);
 
-         if(count($double_data) >= $number){
 
-             return $double_data;
 
-         }
 
-         //两种条件合并,去重。空数组合并没影响
 
-         $merge_data = array_merge($citydata,$tagdata);
 
-         $merge_data = array_flip(array_flip($merge_data));
 
-         //dump($merge_data);
 
-         if(count($merge_data) >= $number){
 
-             return $merge_data;
 
-         }
 
-         return $all_result;
 
-     }
 
-     /**
 
-      * 是否关注
 
-      */
 
-     public function isFollows() {
 
-         $user_id = $this->request->request("user_id",0,"intval");
 
-         if (!$user_id || $user_id<=0) {
 
-             $this->error(__('Invalid parameters'));
 
-         }
 
-         $map = [
 
-             'uid' => $this->auth->id,
 
-             'follow_uid' => $user_id,
 
-         ];
 
-         $check = Db::name('user_follow')->where($map)->find();
 
-         $data = [];
 
-         if($check){
 
-             $data["is_show_follow"] = 0;
 
-         }else{
 
-             $data["is_show_follow"] = 1;
 
-         }
 
-         $this->success("获取成功!",$data);
 
-     }
 
-     /**
 
-      * calc_map_distance() , 根据地图上的两个点各自的x,y坐标,计算出2点之间的直线距离
 
-      * @param array $point_1 第1个点的x,y坐标    array( 101 , 202 )
 
-      * @param array $point_2 第2个点的x,y坐标    array( 101 , 202 )
 
-      * @param bool $calc_as_string 是否计算为字符串公里距离 , 如果未否返回数字
 
-      * @return float | false | string
 
-      */
 
-     private function calc_map_distance( $point_1=array(  ) , $point_2=array(  ) , $calc_as_string=false ) {
 
-         if( empty( $point_1 ) || empty( $point_2 ) ){
 
-             return false;
 
-         }
 
-         // 经纬度不存在,或者经纬度超过最大范围 +-180 , +-90 ,返回false
 
-         $p1_x = $point_1[0];
 
-         $p1_y = $point_1[1];
 
-         $p2_x = $point_2[0];
 
-         $p2_y = $point_2[1];
 
-         if(
 
-             $p1_x < -180 || $p1_x > 180
 
-             || $p2_x < -180 || $p2_x > 180
 
-             || $p1_y < -90 || $p1_y > 90
 
-             || $p2_y < -90 || $p2_y > 90
 
-         ){
 
-             return '0公里';
 
-         }
 
-         // 根据2点各自的坐标,计算2点之间直线距离的公式
 
-         $distance = round(6378.138*2*asin(sqrt(pow(sin(( $p1_x *pi()/180-$p2_x*pi()/180)/2),2)+cos( $p1_x *pi()/180)*cos($p2_x*pi()/180)* pow(sin(( $p1_y *pi()/180-$p2_y*pi()/180)/2),2)))*1000);
 
-         // 是否计算为字符串公里距离
 
-         if( !$calc_as_string ){
 
-             return (string)round( $distance / 1000 , 1 ) . '公里';
 
-         }
 
-         // 如果计算为字符串公里距离
 
-         if( $distance / 1000 > 1 ){
 
-             $k = (string)round( $distance / 1000 , 1 );
 
-             $m = (string)$distance % 1000 ;
 
-             $distance = "{$k}公里{$m}米";
 
-         }
 
-         else{
 
-             $distance = "{$distance}米";
 
-         }
 
-         return $distance;
 
-     }
 
-     //地图api,根据两地坐标,获得两地距离,打卡用的
 
-     //type=0直线,type=1开车
 
-     private function getmapjuli($start_lon,$start_lat,$end_lon,$end_lat,$type = 0){
 
-         $result = 0;
 
-         $apiurl = 'https://restapi.amap.com/v3/distance?';
 
-         $param = [
 
-             'key' => '398c424811d1a59beac2f915323d334e',
 
-             'origins' => $start_lon.','.$start_lat,
 
-             'destination' => $end_lon.','.$end_lat,
 
-             'type' => $type,
 
-             'output' => 'json',
 
-         ];
 
-         $apiurl .= http_build_query($param);
 
-         $request_rs = json_decode(curl_get($apiurl),true);
 
-         if(isset($request_rs['status']) && $request_rs['status'] == 1){
 
-             if(isset($request_rs['results'][0]['distance']))
 
-             {
 
-                 $result = $request_rs['results'][0]['distance'];
 
-             }
 
-         }
 
-         //dump($result);
 
-         return $result;
 
-     }
 
-     public function distance()
 
-     {
 
-         $a = $this->calc_map_distance([118.339282,35.028445],[118.437399,35.017438]);
 
-         dump($a);
 
-         $a = $this->calc_map_distance([118.339282,35.028445],[118.437399,35.017438],true);
 
-         dump($a);
 
-         $b = $this->getmapjuli(118.339282,35.028445,118.437399,35.017438,1);
 
-         dump($b);
 
-         $b = $this->getmapjuli(118.339282,35.028445,118.437399,35.017438,0);
 
-         dump($b);
 
-     }
 
- }
 
 
  |