123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104 |
- <?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 = ['test','testredis'];
- protected $noNeedRight = '*';
- protected $allowFields = [
- 'id',
- 'username',
- 'nickname',
-
- 'email',
- 'mobile',
- 'avatar',
- 'real_status',
- 'gender',
- 'height',
- 'weight',
- 'birthday',
- 'bio',
- 'audio_bio',
-
- 'idcard_status',
- 'longitude',
- 'latitude',
- 'cityname',
- 'photo_images',
- 'education_id',
- 'hobby_ids',
- 'job_id',
- 'marital_id',
- 'tag_ids',
- 'wages_id',
- 'hometown_cityid',
- 'wechat_account',
- 'secretvideo_status',
- ];
- public function testredis(){
-
- dump(redis_matching_get(1));
- $a = cache('?mt_matching_uid_1','',['type'=>'Redis']);
- dump($a);
- }
- public function test(){
- $a = [1,4,10,22,66,36,102,45,23,52,35,76,7];
- $b = [1,10,7,102];
- $c = [10,102];
-
- $data = array_merge($c,$b);
- dump($data);
- dump(array_flip(array_flip($data)));
- dump(array_flip([]));
- }
-
- 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();
- $secretvideo = Db::name('user_secretvideo')->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'] : '',
- 'alipay_account' => ($userinfo['idcard_status'] == 1 && isset($idcard_confirm['alipay_account'])) ? $idcard_confirm['alipay_account'] : '',
- 'secretvideo' => ($userinfo['secretvideo_status'] == 1 && isset($secretvideo['secretvideo'])) ? $secretvideo['secretvideo'] : '',
- ];
-
- $gift_map = [
- 'user_id' => $this->auth->id,
- 'user_to_id' => $uid,
- ];
- $gift_user_typing = Db::name('gift_user_typing')->where($gift_map)->sum('price');
- $gift_user_party = Db::name('gift_user_party')->where($gift_map)->sum('value');
- $gift_user_livebc = Db::name('gift_user_livebc')->where($gift_map)->sum('price');
- $match_map_str = '(user_id = '.$this->auth->id.' and to_user_id = '.$uid.') or (user_id = '.$uid.' and to_user_id = '.$this->auth->id.')';
- $match_typing = Db::name('user_match_typing_log')->where($match_map_str)->sum('price');
- $match_audio = Db::name('user_match_audio_log')->where($match_map_str)->sum('price');
- $match_video = Db::name('user_match_video_log')->where($match_map_str)->sum('price');
- $new_data['qinmi_sum'] = $qinmi_sum = $gift_user_typing + $gift_user_party + $gift_user_livebc + $match_typing + $match_audio + $match_video;
-
- $new_data['isshow_unlock_wechataccount'] = $qinmi_sum >= 15 ? 1 : 0;
- if(config('site.open_unlock_wechataccount') == 0){
- $new_data['isshow_unlock_wechataccount'] = 0;
- }
- $new_data['isshow_unlock_secretvideo'] = $qinmi_sum >= 15 ? 1 : 0;
-
- $check_map = [
- 'user_id' => $this->auth->id,
- 'to_user_id' => $uid,
- ];
- $order_secretvideo = Db::name('order_secretvideo')->where($check_map)->order('id desc')->value('endtime');
- $order_wechataccount = Db::name('order_wechataccount')->where($check_map)->order('id desc')->value('endtime');
- $new_data['unlock_secretvideo_endtime'] = !empty($order_secretvideo) ? $order_secretvideo : 0;
- $new_data['unlock_secretvideo_status'] = $new_data['unlock_secretvideo_endtime'] > time() ? 1 : 0;
- $new_data['unlock_wechataccount_endtime'] = !empty($order_wechataccount) ? $order_wechataccount : 0;
- $new_data['unlock_wechataccount_status'] = $new_data['unlock_wechataccount_endtime'] > time() ? 1 : 0;
-
- $new_data['unlock_secretvideo_notice'] = '是否花费'.config('site.unlock_secretvideo').'金币解锁一周(或年费vip可每日免费解锁一次)?';
- $new_data['unlock_wechataccount_notice'] = '是否花费'.config('site.unlock_wechataccount').'金币解锁一周(或年费vip可每日免费解锁一次)?';
-
- $userinfo = array_merge($userinfo,$new_data);
-
- $userinfo['education'] = Db::name('enum_education')->where('id',$userinfo['education_id'])->value('name');
- $userinfo['hobby'] = Db::name('enum_hobby')->where('id','IN',$userinfo['hobby_ids'])->field(['id','name'])->select();
- $userinfo['job'] = Db::name('enum_job')->where('id',$userinfo['job_id'])->value('name');
- $userinfo['marital'] = Db::name('enum_marital')->where('id',$userinfo['marital_id'])->value('name');
- $userinfo['tag'] = Db::name('enum_tag')->where('id','IN',$userinfo['tag_ids'])->field(['id','name'])->select();
- $userinfo['wages'] = Db::name('enum_wages')->where('id',$userinfo['wages_id'])->value('name');
-
- $userinfo['hometown_city'] = Db::name('area')->where('id',$userinfo['hometown_cityid'])->value('name');
-
- $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);
- }
- $this->success('success',$userinfo);
- }
-
- 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)){
-
- }
- $map = [
- 'user.status' => 1,
-
- 'user.id' => ['neq',$this->auth->id],
-
-
-
-
- ];
- if($gender != 'all'){
- $map['user.gender'] = $gender;
- }
- $map['user.birthday'] = ['between',[time() - $agemax * 31536000,time() - $agemin * 31536000]];
-
- $field = [
- 'user.id','user.username','user.nickname','user.birthday','user.height','user.longitude','user.latitude','user.avatar','user.audio_bio','user.bio','user.gender'
- ];
- $list = Db::name('user')->alias('user')->field($field)->where($map)->order('is_active desc,active_time desc')->autopage()->select();
-
- $list = list_domain_image($list,['avatar']);
- foreach($list as $key => $one){
- $one['age'] = birthtime_to_age($one['birthday']);
-
- $one['distance'] = rand(0,10).'km';
-
- $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)){
-
- }
-
- $map = [
- 'user.status' => 1,
-
- 'user.id' => ['neq',$this->auth->id],
-
-
-
-
- ];
- if($gender != 'all'){
- $map['user.gender'] = $gender;
- }
- $map['user.birthday'] = ['between',[time() - $agemax * 31536000,time() - $agemin * 31536000]];
-
- $field = [
- 'user.id','user.username','user.nickname','user.birthday','user.height','user.longitude','user.latitude','user.avatar','user.audio_bio','user.bio','user.gender'
- ];
- $list = Db::name('user')->alias('user')->field($field)->where($map)->order('is_active desc,active_time desc')->autopage()->select();
-
- $list = list_domain_image($list,['avatar']);
- foreach($list as $key => $one){
- $one['age'] = birthtime_to_age($one['birthday']);
-
- $one['distance'] = rand(0,10).'km';
-
- $one['active_text'] = '在线';
-
- $list[$key] = $one;
- }
- $this->success('success',$list);
- }
-
-
- public function video_audio_moneycheck(){
-
- $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');
- }
-
-
- 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');
- }
-
-
- 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']);
- }
- }
-
- 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');
- }
-
-
- 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']);
- }
- }
-
- 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');
- }
-
-
- 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']);
- }
- }
-
- 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']);
- }
- }
-
-
- $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(){
-
-
- $check = true;
-
- if($check){
- $price = config('site.audio_min_price');
- $gold = model('wallet')->getWallet($this->auth->id,'gold');
- if($gold < $price){
- $this->error('您的金币已经不足,请充值');
- }
- }
-
-
-
-
-
-
- $map = [
- 'status' =>1,
- 'gender' => $this->auth->gender == 1 ? 0 : 1,
- 'is_online' => 0,
- 'is_livebc' => 0,
- 'is_active' => 1,
-
-
- 'open_match_audio' => 1,
-
- ];
- $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];
- }
- }
-
-
- 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(){
-
-
- $check = true;
-
- if($check){
- $price = config('site.video_min_price');
- $gold = model('wallet')->getWallet($this->auth->id,'gold');
- if($gold < $price){
- $this->error('您的金币已经不足,请充值');
- }
- }
-
-
-
-
-
-
- $map = [
- 'status' =>1,
- 'gender' => $this->auth->gender == 1 ? 0 : 1,
- 'is_online' => 0,
- 'is_livebc' => 0,
- 'is_active' => 1,
-
-
- 'open_match_video' => 1,
-
- ];
- $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];
- }
- }
-
-
- 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(){
-
-
-
-
-
-
- $map = [
- 'status' =>1,
- 'gender' => $this->auth->gender == 1 ? 0 : 1,
-
-
-
-
- 'open_match_typing' => 1,
-
- ];
- $lists = Db::name('user')->field('id,cityname,status,gender,real_status,tag_ids')->where($map)->order('logintime desc')->page($this->page,100)->select();
-
- $lists = array_column($lists,'id');
- $result = [];
- if(!empty($lists)){
-
- $result = Db::name('user')->field('id,nickname,username,avatar,audio_bio')->where(['id'=>['IN',$lists]])->select();
- $result = list_domain_image($result,['avatar,audio_bio']);
- }
-
-
- 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;
- }
-
-
- foreach($lists as $key => $val){
- if(redis_matching_get($val['id']) == 1){
- unset($lists[$key]);
- }
- }
-
- $all_result = array_column($lists,'id');
-
-
- $citydata = [];
- foreach($lists as $key => $val){
- if( !empty($this->auth->cityname) && $this->auth->cityname == $val['cityname'] ){
- $citydata[] = $val['id'];
- }
- }
-
-
- $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'];
- }
- }
- }
-
-
- $double_data = [];
- if(!empty($citydata) && !empty($tagdata)){
- $double_data = array_intersect($citydata,$tagdata);
- }
-
- if(count($double_data) >= $number){
- return $double_data;
- }
-
- $merge_data = array_merge($citydata,$tagdata);
- $merge_data = array_flip(array_flip($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);
- }
-
- public function getAnchorType() {
- $this->success("获取成功!",\app\common\model\UserAnchorType::select());
- }
-
- public function anchorApply() {
- $this->error('不需要申请');
-
- }
-
- public function getMyUserInfo() {
- $userInfo = $this->auth->getUserinfo();
-
- $redis = new Redis();
- $redisconfig = config("redis");
- $redis->connect($redisconfig["host"], $redisconfig["port"]);
- $user_renew2 = $redis->get('user_renew2_'.$this->auth->id);
- $userInfo['user_renew2'] = empty($user_renew2)?0:intval($user_renew2);
- $this->success("获取成功!",$userInfo);
- }
-
- private function calc_map_distance( $point_1=array( ) , $point_2=array( ) , $calc_as_string=false ) {
- if( empty( $point_1 ) || empty( $point_2 ) ){
- return 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公里';
- }
-
- $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;
- }
-
-
- 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'];
- }
- }
-
- 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);
- }
- }
|