Browse Source

Merge branch 'dev4.5.0.2' of http://192.168.3.207:8080/qmx/jy into dev4.5.0.2

zhangyuhan 4 năm trước cách đây
mục cha
commit
03a78dfee7

+ 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
 package entity
 
 
 import (
 import (
+	ac "applocation/apploc"
 	"db"
 	"db"
 	"fmt"
 	"fmt"
 	"log"
 	"log"
+	"net/http"
+	"qfw/util"
 	"qfw/util/redis"
 	"qfw/util/redis"
 	"time"
 	"time"
 )
 )
@@ -12,10 +15,11 @@ type AppLocStruct struct {
 	UserId    string //用户id
 	UserId    string //用户id
 	Longitude string // 经度
 	Longitude string // 经度
 	Latitude  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"
 var AppLocLog = "apploc_log"
@@ -25,14 +29,22 @@ var RedisUserKey = "apploc_%s"
 func (this *AppLocStruct) SaveAppLocInfo() bool {
 func (this *AppLocStruct) SaveAppLocInfo() bool {
 	log.Println(this.Longitude, "---", this.Latitude)
 	log.Println(this.Longitude, "---", this.Latitude)
 	timeNow := time.Now()
 	timeNow := time.Now()
+	ref := this.R.Referer()
 	appLocInfo := map[string]interface{}{
 	appLocInfo := map[string]interface{}{
 		"date":      timeNow.Unix(),
 		"date":      timeNow.Unix(),
 		"userId":    this.UserId,
 		"userId":    this.UserId,
 		"longitude": this.Longitude,
 		"longitude": this.Longitude,
 		"latitude":  this.Latitude,
 		"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) != "" {
 	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 true
 	}
 	}
 	return false
 	return false

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

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

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

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