UserLog.go 2.51 KB
package Api

import (
	"encoding/json"
	"github.com/aarongao/tools"
	"github.com/gin-gonic/gin"
	"letu/DB"
	"time"
)

// @Title 增加访问日志
// @Description 增加用户行为日志
// @Accept  json
// @Produce  json
// @Param   Type     访问页面    string     true        "安装;卸载;访问页面;使用功能;缩放地图;进入景区"
// @Param   SubType     景区详情    string     true        "推荐;景区详情;登陆;商城;投诉建议;问券调查....(app中能点的都加上)"
// @Param   ScenicId     5dfb03070a9ac17ac7a82054    string     true        "景区id"
// @Param   UserId     5dfb03070a9ac17ac7a82054    string     true        "用户ID"
// @Param   UserName     Aaron    string     true        "用户名称"
// @Param   Location     {"Latitude": 119, "Longitude": 39}    string     true        "位置"
// @Param   Remarks     备注    string     true        "备注"
// @Param   Source     用户分享    string     true        "来源"
// @Param   DeviceId     abc123    string     true        "手机唯一识别码,不重复(存放于http.header中)"
// @Param   Mac     abc123    string     true        "网卡Mac地址(存放于http.header中)"
// @Param   SystemType     ios    string     true        "ios,android(存放于http.header中)"
// @Param   SystemVersion     13.01    string     true        "手机版本(存放于http.header中)"
// @Param   SystemModel     iphone8    string     true        "手机型号(存放于http.header中)"
// @Param   AppVersion     1.0    string     true        "app版本号"
// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":"ok"}"
// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
// @Router /UserLog? [post]
func UserLog(c *gin.Context) {
	c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
	c.Header("Access-Control-Allow-Credentials", "true")

	var Location DB.SLocation
	json.Unmarshal([]byte(c.PostForm("Location")), &Location)

	DB.CUserLog.Insert(DB.SUserLog{
		c.PostForm("Type"),
		c.PostForm("SubType"),
		c.PostForm("ScenicId"),
		c.PostForm("UserId"),
		c.PostForm("UserName"),
		time.Now().Unix(),
		Location,
		c.PostForm("Remarks"),
		c.PostForm("Source"),
		DB.SDevice{
			c.Request.Header.Get("DeviceId"),
			c.Request.Host,
			c.Request.Header.Get("Mac"),
			c.Request.Header.Get("SystemType"),
			c.Request.Header.Get("SystemVersion"),
			c.Request.Header.Get("SystemModel"),
			c.Request.Header.Get("AppVersion"),
		},
	})

	c.JSON(200, tools.ResponseSeccess{
		0,
		"ok",
	})

}