|
@@ -0,0 +1,49 @@
|
|
|
+package entity
|
|
|
+
|
|
|
+import (
|
|
|
+ "db"
|
|
|
+ "fmt"
|
|
|
+ "log"
|
|
|
+ "qfw/util/redis"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+type AppLocStruct struct {
|
|
|
+ UserId string //用户id
|
|
|
+ Longitude string // 经度
|
|
|
+ Latitude string //纬度
|
|
|
+}
|
|
|
+
|
|
|
+func NewAppLoc(userId, longitude, latitude string) *AppLocStruct {
|
|
|
+ return &AppLocStruct{userId, longitude, latitude}
|
|
|
+}
|
|
|
+
|
|
|
+var AppLocLog = "apploc_log"
|
|
|
+var RedisUserKey = "apploc_%s"
|
|
|
+
|
|
|
+//保存定位信息
|
|
|
+func (this *AppLocStruct) SaveAppLocInfo() bool {
|
|
|
+ log.Println(this.Longitude, "---", this.Latitude)
|
|
|
+ timeNow := time.Now()
|
|
|
+ appLocInfo := map[string]interface{}{
|
|
|
+ "date": timeNow.Unix(),
|
|
|
+ "userId": this.UserId,
|
|
|
+ "longitude": this.Longitude,
|
|
|
+ "latitude": this.Latitude,
|
|
|
+ }
|
|
|
+ if db.Mgo_Log.Save(AppLocLog, appLocInfo) != "" {
|
|
|
+ redis.Put("other", fmt.Sprintf(RedisUserKey, this.UserId), timeNow.Day(), 12*60*60)
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ return false
|
|
|
+}
|
|
|
+
|
|
|
+//是否保存信息
|
|
|
+func (this *AppLocStruct) IsSaveBool() bool {
|
|
|
+ _day := time.Now().Day()
|
|
|
+ day := redis.GetInt("other", fmt.Sprintf(RedisUserKey, this.UserId))
|
|
|
+ if day != _day {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ return false
|
|
|
+}
|