AccessLog.go 1.5 KB
package Api

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

// @Title 增加访问日志
// @Description 增加访问日志
// @Accept  json
// @Produce  json
// @Param   UserId     5dfb03070a9ac17ac7a82054    string     true        "用户ID"
// @Param   UserName     Aaron    string     true        "用户名称"
// @Param   TypeNum     9    int     true        "类型编号"
// @Param   TypeName     点击个人中心    string     true        "类型名称"
// @Param   DateTime     1578556751220    int     true        "时间戳"
// @Param   Location     {"Latitude": 119, "Longitude": 39}    string     true        "位置"
// @Param   Remarks     备注    string     true        "备注"
// @Success 200 {object} tools.ResponseSeccess ""
// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
// @Router /AccessLog? [post]
func AccessLog(c *gin.Context) {
	c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
	c.Header("Access-Control-Allow-Credentials", "true")

	if c.Request.Method == "post" {

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

		DateTime, _ := strconv.ParseInt(c.PostForm("DateTime"), 0, 64)

		DB.CAccessLog.Insert(DB.SAccessLog{
			c.PostForm("UserId"),
			c.PostForm("UserName"),
			c.PostForm("TypeNum"),
			c.PostForm("TypeName"),
			DateTime,
			Location,
			c.PostForm("Remarks"),
		})

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

}