Browse Source

用户的定位

lizhen_gitee 10 months ago
parent
commit
8bd08e04bb

+ 1 - 0
application/api/controller/Topicdongtai.php

@@ -270,6 +270,7 @@ class Topicdongtai extends Api
         $content = Keyworld::sensitive($content);
 
         $address = $this->ip_to_address();
+        $address = $address['provincename'].$address['cityname'];
 
         $data = [
             'topic_id' => $topic_id,

+ 0 - 2
application/api/controller/Usercenter.php

@@ -100,8 +100,6 @@ class Usercenter extends Api
 
         $new_data = [
             'age'            => birthtime_to_age($userinfo['birthday']),
-            'truename'       => '',
-            'alipay_account' => '',
         ];
 
 

+ 13 - 6
application/common/controller/Api.php

@@ -382,7 +382,11 @@ class Api
             db('user_active')->where('user_id',$this->auth->id)->update(['requesttime'=>time()]);
             if($this->auth->is_active == 0){
                 $update['is_active'] = 1;
+                $update['cityname'] = $this->ip_to_address()['cityname'];
+
                 db('user')->where('id',$this->auth->id)->update($update);
+
+                $this->auth->setuser('cityname',$update['cityname']);
             }
         }
     }
@@ -390,6 +394,11 @@ class Api
     //ip获取地址
     protected  function ip_to_address(){
 
+        $data = [
+            'provincename' => '',
+            'cityname' => '',
+        ];
+
         try{
             $ip = request()->ip();
             //$ip = '182.37.138.94';
@@ -397,8 +406,6 @@ class Api
             // http协议:http://api.ip138.com/ip/
             // https协议:https://api.ip138.com/ip/
 
-            $data = '';
-
             $url = 'http://api.ip138.com/ip/?ip='.$ip.'&datatype=jsonp&token=19fc471ea42124e6d1f7e4e473ef2647'; //15811816496   huang19871217
             $result = json_decode(curl_get($url),true);
             //dump($result);exit;
@@ -408,10 +415,10 @@ class Api
                     if(isset($result['data']) && is_array($result['data']) && !empty($result['data'])){
 
                         if(isset($result['data'][1]) && !empty($result['data'][1])){
-                            $data .= $result['data'][1];
+                            $data['provincename'] = $result['data'][1];
                         }
                         if(isset($result['data'][2]) && !empty($result['data'][2])){
-                            $data .= $result['data'][2];
+                            $data['cityname'] = $result['data'][2];
                         }
 
                     }
@@ -420,10 +427,10 @@ class Api
             //dump($data);
             return $data;
         }catch (Exception $e) {
-            return [];
+            return $data;
         }
 
-        return [];
+        return $data;
     }
 
     protected function request_log_update($log_result){

+ 4 - 0
application/common/library/Auth.php

@@ -149,6 +149,10 @@ class Auth
         return $this->_user ? $this->_user->$name : null;
     }
 
+    public function setuser($field,$value){
+        return $this->_user->$field = $value;
+    }
+
     /**
      * 兼容调用user模型的属性
      */