|
@@ -300,122 +300,6 @@ class Usercenter extends Api
|
|
|
}
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * 是否关注
|
|
|
- */
|
|
|
- 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);
|
|
|
- }
|
|
|
-
|
|
|
//开通守护
|
|
|
public function addguard() {
|
|
|
// 接口防并发
|
|
@@ -1296,4 +1180,123 @@ $resArray['money'] = $money; //返回给前端的计算结果
|
|
|
public function unlockchat() {
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 是否关注
|
|
|
+ */
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
}
|