Sfoglia il codice sorgente

客户端经纬度统计

wangshan 4 anni fa
parent
commit
dd47d53b60

+ 65 - 0
src/jfw/modules/app/src/web/staticres/jyapp/js/common.js

@@ -316,6 +316,10 @@ var JyObjMessage = new Object();
 $(function () {
   if (mySysIsIos()) {
     window.JyObj = {
+      //获取经纬度
+      getLLitude: function () {
+        return JyObj.IosCall("getLLitude")
+      },
       //调转到指定的webview
       //name 对应的值:search 搜索 subscribe 订阅 box 百宝箱 me 我的
       skipAppointTab: function (name) {
@@ -995,6 +999,7 @@ function afterPageInit () {
   }, 600000);
   try {
     afterJyObjInit();
+    latlongitude();//记录用户经纬度
   } catch (e) {
   }
   var sign = JyObj.getUserToken();
@@ -1418,3 +1423,63 @@ function afterReceivePushMessage (type, url) {
     receivePushMessageHandle(type, url);
   } catch (e) { }
 }
+//获取用户经纬度 每天记录一次
+function latlongitude(){
+	var llitude = JyObj.getLLitude();
+    if(llitude==""){
+      var ai = 0;
+      var llInterval = setInterval(function(){
+        ai=ai+1;
+        try{
+          llitude = JyObj.getLLitude();
+        }catch(e){}
+        //五次获取不到客户端经纬度 就不再获取,获取位置存localStorage 一天
+        //alert(llitude+"---:"+ai)
+        if((llitude!=""&&llitude!=undefined&&llitude.indexOf("null")<0)||ai>4){
+          clearInterval(llInterval);
+          llrequest(llitude)
+        }
+      },500)
+    }else{
+    	//alert("经纬度:"+llitude)
+    	llrequest(llitude)
+    }
+}
+//判断经纬度是否够收录条件
+function llrequest(ll){
+	//localStorage.removeItem("LLitude");
+	var latitude = parseFloat(ll.split("_")[1]);//纬度
+	var longitude =  parseFloat(ll.split("_")[0]);//经度
+	var llitude = localStorage.LLitude;
+	var _lat = 0.0;
+	var _long = 0.0;
+	var nowDate = new Date().getDate()+1;
+	var oldDate = new Date().getDate();
+	if (llitude!=null&&llitude.split("_").length>2){
+		_long =  parseFloat(llitude.split("_")[0]);//经度
+		_lat =  parseFloat(llitude.split("_")[1]);//纬度
+		oldDate =  Number(llitude.split("_")[2]);
+	}
+	if (nowDate!=oldDate&&caculateLL(latitude,longitude,_lat,_long)>0){
+    	$.post("/publicapply/appLoc/action", {
+	        "longitude": longitude,
+	        "latitude": latitude
+	    }, function (r) {
+	        if (r.data) {
+				localStorage.LLitude = ll+"_"+new Date().getDate();
+	        }
+      	})
+    }
+}
+/*计算两经纬度点之间的距离(单位:米)*/
+function caculateLL(lat1, lng1, lat2, lng2) {
+	var radLat1 = lat1 * Math.PI / 180.0;
+	var radLat2 = lat2 * Math.PI / 180.0;
+	var a = radLat1 - radLat2;
+	var b = lng1 * Math.PI / 180.0 - lng2 * Math.PI / 180.0;
+	var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
+	s = s * 6378.137;
+	s = Math.round(s * 10000) / 10;
+	alert("距离上个位置:"+s+" 米")
+	return s
+}

+ 3 - 0
src/jfw/modules/publicapply/src/applocation/apploc.json

@@ -0,0 +1,3 @@
+{
+	"colloctime":"12h"
+}

+ 37 - 0
src/jfw/modules/publicapply/src/applocation/apploc/apploc.go

@@ -0,0 +1,37 @@
+package applocation
+
+import (
+	"log"
+	"qfw/util"
+	"strconv"
+	"strings"
+)
+
+type apploc struct {
+	Colloctime string `json:"colloctime"` //间隔时间
+}
+
+var Apploctime = 12 * 60 * 60 //12小时
+var Apploc *apploc
+
+func init() {
+	util.ReadConfig("./applocation/apploc.json", &Apploc)
+	if Apploc.Colloctime != "" {
+		var seconds = 60 * 60
+		var shour = "60"
+		if strings.Contains(Apploc.Colloctime, "h") {
+			shour = strings.Split(Apploc.Colloctime, "h")[0]
+		} else if strings.Contains(Apploc.Colloctime, "m") {
+			shour = strings.Split(Apploc.Colloctime, "m")[0]
+			seconds = 60
+		} else if strings.Contains(Apploc.Colloctime, "s") {
+			shour = strings.Split(Apploc.Colloctime, "s")[0]
+			seconds = 1
+		}
+		ihour, _ := strconv.Atoi(shour)
+		if ihour > 0 {
+			Apploctime = ihour * seconds
+		}
+	}
+	log.Println("Apploctime:", Apploctime)
+}

+ 15 - 3
src/jfw/modules/publicapply/src/applocation/entity/entity.go

@@ -1,9 +1,12 @@
 package entity
 
 import (
+	ac "applocation/apploc"
 	"db"
 	"fmt"
 	"log"
+	"net/http"
+	"qfw/util"
 	"qfw/util/redis"
 	"time"
 )
@@ -12,10 +15,11 @@ type AppLocStruct struct {
 	UserId    string //用户id
 	Longitude string // 经度
 	Latitude  string //纬度
+	R         *http.Request
 }
 
-func NewAppLoc(userId, longitude, latitude string) *AppLocStruct {
-	return &AppLocStruct{userId, longitude, latitude}
+func NewAppLoc(userId, longitude, latitude string, r http.Request) *AppLocStruct {
+	return &AppLocStruct{userId, longitude, latitude, &r}
 }
 
 var AppLocLog = "apploc_log"
@@ -25,14 +29,22 @@ var RedisUserKey = "apploc_%s"
 func (this *AppLocStruct) SaveAppLocInfo() bool {
 	log.Println(this.Longitude, "---", this.Latitude)
 	timeNow := time.Now()
+	ref := this.R.Referer()
 	appLocInfo := map[string]interface{}{
 		"date":      timeNow.Unix(),
 		"userId":    this.UserId,
 		"longitude": this.Longitude,
 		"latitude":  this.Latitude,
+		"ip":        util.GetIp(this.R),
+		"refer":     ref,
+		"year":      timeNow.Year(),
+		"month":     timeNow.Month(),
+		"day":       timeNow.Day(),
+		"hour":      timeNow.Hour(),
+		"minutes":   timeNow.Minute(),
 	}
 	if db.Mgo_Log.Save(AppLocLog, appLocInfo) != "" {
-		redis.Put("other", fmt.Sprintf(RedisUserKey, this.UserId), timeNow.Day(), 12*60*60)
+		redis.Put("other", fmt.Sprintf(RedisUserKey, this.UserId), timeNow.Day(), ac.Apploctime)
 		return true
 	}
 	return false

+ 1 - 0
src/jfw/modules/publicapply/src/applocation/init.go

@@ -1,6 +1,7 @@
 package applocation
 
 import (
+	_ "applocation/apploc"
 	"applocation/service"
 
 	"github.com/go-xweb/xweb"

+ 3 - 1
src/jfw/modules/publicapply/src/applocation/service/service.go

@@ -4,6 +4,7 @@ import (
 	. "api"
 	"applocation/entity"
 	"log"
+	"net/http"
 	qu "qfw/util"
 
 	"github.com/go-xweb/xweb"
@@ -27,7 +28,8 @@ func (this *ServiceStruct) AppLocAction() {
 		}
 		longitude := this.GetString("longitude") //经度
 		latitude := this.GetString("latitude")   //纬度
-		newAppLoc := entity.NewAppLoc(userId, longitude, latitude)
+		var r http.Request
+		newAppLoc := entity.NewAppLoc(userId, longitude, latitude, r)
 		if newAppLoc.IsSaveBool() {
 			retBool = newAppLoc.SaveAppLocInfo()
 		}