| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356 | 
							- <?php
 
- namespace app\api\controller;
 
- use app\common\controller\Api;
 
- use think\Db;
 
- use app\common\model\wallet;
 
- /**
 
-  * 会员中心
 
-  */
 
- class Usercenter extends Api
 
- {
 
-     protected $noNeedLogin = ['test'];
 
-     protected $noNeedRight = '*';
 
-     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];
 
-         //dump(array_intersect($a,$b));
 
-         $data = array_merge($c,$b);
 
-         dump($data);
 
-         dump(array_flip(array_flip($data)));
 
-         dump(array_flip([]));
 
-     }
 
-     //同城
 
-     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',''],
 
-         ];
 
-         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'
 
-         ];
 
-         $list = Db::name('user')->alias('user')->field($field)->where($map)->orderRaw('rand()')->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']]);
 
-             $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]],
 
-         ];
 
-         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'
 
-         ];
 
-         $list = Db::name('user')->alias('user')->field($field)->where($map)->orderRaw('rand()')->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']]);
 
-             $list[$key] = $one;
 
-         }
 
-         $this->success('success',$list);
 
-     }
 
-     //视频通话每分钟调用一次
 
-     public function video_onemin(){
 
-         $to_user_id = input_post('to_user_id');
 
-         //先检查今天免费的一分钟
 
-         $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_video_log')->where($map)->find();
 
-         //设置价格
 
-         $price = config('site.video_min_price');
 
-         $price = empty($check) ? 0 : $price;
 
-         Db::startTrans();
 
-         //记录日志
 
-         $data = [
 
-             'user_id' => $this->auth->id,
 
-             'price'   => $price,
 
-             'createtime' => time(),
 
-             'to_user_id' => $to_user_id,
 
-         ];
 
-         $log_id = Db::name('user_video_log')->insertGetId($data);
 
-         if(!$log_id){
 
-             Db::rollback();
 
-             $this->error('扣费失败');
 
-         }
 
-         //扣费
 
-         if(!empty($check) && $log_id){
 
-             $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'gold',-$price,11,'','user_video_log',$log_id);
 
-             if($rs['status'] === false){
 
-                 Db::rollback();
 
-                 $this->error($rs['msg']);
 
-             }
 
-         }
 
-         Db::commit();
 
-         $this->success('success');
 
-     }
 
-     //视频匹配
 
-     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_video_log')->where($map)->find();
 
-         //已经用掉免费的了,判断金额
 
-         if($check){
 
-             $price = config('site.video_min_price');
 
-             $gold = model('wallet')->getWallet($this->auth->id,'gold');
 
-             $moneyname = model('wallet')->getwalletname('gold');
 
-             if($gold < $price){
 
-                 $this->error('您的'.$moneyname.'已经不足,请充值');
 
-             }
 
-         }
 
-         
 
-         //给出备选用户
 
-         $map = [
 
-             'status' =>1,
 
-             //'gender' => $this->auth->gender == 1 ? 0 : 1,
 
-             //'real_status' => 1,
 
-             //打开视频开关的
 
-             'id' => ['neq',$this->auth->id]
 
-         ];
 
-         $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);
 
-         $this->success('success',$lists);
 
-     }
 
-     private function fliter_user($lists){
 
-         //预留全部
 
-         $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);
 
-         }
 
-         //两种条件合并,去重。空数组合并没影响
 
-         $merge_data = array_merge($citydata,$tagdata);
 
-         $merge_data = array_flip(array_flip($merge_data));
 
-         //最终结果
 
-         //双条件数量足够就return
 
-         if(count($double_data) >= 1){
 
-             //echo __LINE__;
 
-             return $double_data;
 
-         }
 
-         //不够就合并
 
-         $result_data = array_merge($double_data,$merge_data);
 
-         $result_data = array_flip(array_flip($result_data));
 
-         if(count($result_data) >= 1){
 
-             //echo __LINE__;
 
-             return $result_data;
 
-         }
 
-         //仍然不够,全合并
 
-         $all_data = array_merge($result_data,$result);
 
-         $all_data = array_flip(array_flip($all_data));
 
-         return $all_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);
 
-     }
 
- }
 
 
  |