瀏覽代碼

app点位

wangshan 4 年之前
父節點
當前提交
1e3eff41ee

+ 49 - 0
src/jfw/modules/publicapply/src/applocation/entity/entity.go

@@ -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
+}

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

@@ -0,0 +1,11 @@
+package applocation
+
+import (
+	"applocation/service"
+
+	"github.com/go-xweb/xweb"
+)
+
+func init() {
+	xweb.AddAction(&service.ServiceStruct{})
+}

+ 38 - 0
src/jfw/modules/publicapply/src/applocation/service/service.go

@@ -0,0 +1,38 @@
+package service
+
+import (
+	. "api"
+	"applocation/entity"
+	"log"
+	qu "qfw/util"
+
+	"github.com/go-xweb/xweb"
+)
+
+type ServiceStruct struct {
+	*xweb.Action
+	appLocAction xweb.Mapper `xweb:"/appLoc/action"` //app端定位信息
+}
+
+var AppLocUser = map[string][]string{}
+
+//保存定位信息
+func (this *ServiceStruct) AppLocAction() {
+	userId, _ := this.GetSession("userId").(string)
+	defer qu.Catch()
+	r := func() Result {
+		var retBool = false
+		if this.Method() != "POST" {
+			return Result{Data: nil, Error_msg: Error_msg_1005}
+		}
+		longitude := this.GetString("longitude") //经度
+		latitude := this.GetString("latitude")   //纬度
+		newAppLoc := entity.NewAppLoc(userId, longitude, latitude)
+		if newAppLoc.IsSaveBool() {
+			retBool = newAppLoc.SaveAppLocInfo()
+		}
+		log.Println("retBool:", retBool)
+		return Result{Data: retBool}
+	}()
+	this.ServeJson(r)
+}

+ 1 - 0
src/jfw/modules/publicapply/src/main.go

@@ -2,6 +2,7 @@ package main
 
 import (
 	_ "a"
+	_ "applocation"
 	_ "bidcollection"
 	. "config"
 	_ "dataexport"