Commit 1996b12a authored by szh's avatar szh

add device code

parent d447e2b6
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
"courseSign/server/model/course" "courseSign/server/model/course"
courseReq "courseSign/server/model/course/request" courseReq "courseSign/server/model/course/request"
"courseSign/server/service" "courseSign/server/service"
"courseSign/server/utils"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"go.uber.org/zap" "go.uber.org/zap"
"gorm.io/gorm" "gorm.io/gorm"
...@@ -297,4 +298,108 @@ func (courseActionUsersApi *CourseActionUsersApi) GetMyAction(c *gin.Context) { ...@@ -297,4 +298,108 @@ func (courseActionUsersApi *CourseActionUsersApi) GetMyAction(c *gin.Context) {
PageSize: pageInfo.PageSize, PageSize: pageInfo.PageSize,
}, "获取成功", c) }, "获取成功", c)
} }
} }
\ No newline at end of file
// WebSignAction 设备码签到
// @Tags CourseActionUsers
// @Summary 设备码签到
// @accept application/json
// @Produce application/json
// @Param data body courseReq.ReqCode true "设备码签到"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /courseActionUsers/signActionWeb [post]
func (courseActionUsersApi *CourseActionUsersApi) WebSignAction(c *gin.Context) {
var reqCode courseReq.ReqCode
err := c.ShouldBindJSON(&reqCode)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if reqCode.DeviceCode == "" || reqCode.Aid == 0{
response.FailWithMessage("invalid params", c)
return
}
j := utils.NewJWT()
cliams,err := j.ParseToken(reqCode.DeviceCode)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
actionInfo,err := courseActionService.GetCourseAction(uint(reqCode.Aid))
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
user,err := courseUsersService.GetCourseUsersByAddr(cliams.Username)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if user.Invitor == "" {
response.FailWithMessage("没有推荐者", c)
return
}
//检查活动是否已签到
actionSign,err := courseActionUsersService.GetCourseActionUsersByUidAndAid(reqCode.Aid,int(user.ID))
if err != nil && err != gorm.ErrRecordNotFound {
response.FailWithMessage(err.Error(), c)
return
}
if actionSign.ID > 0 {
response.FailWithMessage("已签到", c)
return
}
// 检查课程活动 信息
courseAction,err := courseActionService.GetCourseAction(uint(*actionInfo.Cid))
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if !*courseAction.IsShow {
response.FailWithMessage("活动已下线", c)
return
}
if courseAction.ActionEnd.Unix() < time.Now().Unix() {
response.FailWithMessage("活动已结束", c)
return
}
courseSign,err := courseSignupService.GetCourseSignupByUidAndCid(uint(*actionInfo.Cid),user.ID)
if err != nil && err != gorm.ErrRecordNotFound {
response.FailWithMessage(err.Error(), c)
return
} else if err != nil && err == gorm.ErrRecordNotFound {
response.FailWithMessage("课程未报名", c)
return
}
if courseSign.ID > 0 && !*courseSign.IsPass {
response.FailWithMessage("报名审核未通过", c)
return
}
signDate := utils.GetTodayTime(time.DateOnly)
courseActionUsers := &course.CourseActionUsers{}
*courseActionUsers.Uid = int(user.ID)
*courseActionUsers.Aid = int(actionInfo.ID)
courseActionUsers.Cid = actionInfo.Cid
courseActionUsers.SignDate = &signDate
if err := courseActionUsersService.CreateCourseActionUsers(*courseActionUsers); err != nil {
global.GVA_LOG.Error("创建失败!", zap.Error(err))
response.FailWithMessage("创建失败", c)
} else {
response.OkWithMessage("创建成功", c)
}
}
...@@ -270,11 +270,15 @@ func (courseUsersApi *CourseUsersApi) MetaMaskLogin(c *gin.Context) { ...@@ -270,11 +270,15 @@ func (courseUsersApi *CourseUsersApi) MetaMaskLogin(c *gin.Context) {
return return
} }
// device token
deviceCode := utils.CreateDeviceCode(loginUser.Addr)
j := &utils.JWT{SigningKey: []byte(global.GVA_CONFIG.JWT.SigningKey)} // 唯一签名 j := &utils.JWT{SigningKey: []byte(global.GVA_CONFIG.JWT.SigningKey)} // 唯一签名
claims := j.CreateClaims(systemReq.BaseClaims{ claims := j.CreateClaims(systemReq.BaseClaims{
//ID: user.ID, //ID: user.ID,
NickName: loginUser.Addr, NickName: loginUser.Addr,
Username: loginUser.Addr, Username: loginUser.Addr,
DeviceCode: deviceCode,
}) })
token, err := j.CreateToken(claims) token, err := j.CreateToken(claims)
if err != nil { if err != nil {
...@@ -282,6 +286,7 @@ func (courseUsersApi *CourseUsersApi) MetaMaskLogin(c *gin.Context) { ...@@ -282,6 +286,7 @@ func (courseUsersApi *CourseUsersApi) MetaMaskLogin(c *gin.Context) {
response.FailWithMessage("获取token失败", c) response.FailWithMessage("获取token失败", c)
return return
} }
// jwt token
if jwtStr, err := jwtService.GetRedisJWT(loginUser.Addr); err == redis.Nil { if jwtStr, err := jwtService.GetRedisJWT(loginUser.Addr); err == redis.Nil {
if err := jwtService.SetRedisJWT(token, loginUser.Addr); err != nil { if err := jwtService.SetRedisJWT(token, loginUser.Addr); err != nil {
global.GVA_LOG.Error("设置登录状态失败!", zap.Error(err)) global.GVA_LOG.Error("设置登录状态失败!", zap.Error(err))
...@@ -305,6 +310,28 @@ func (courseUsersApi *CourseUsersApi) MetaMaskLogin(c *gin.Context) { ...@@ -305,6 +310,28 @@ func (courseUsersApi *CourseUsersApi) MetaMaskLogin(c *gin.Context) {
} }
// if deviceStr, err := jwtService.GetRedisJWT(deviceCode); err == redis.Nil {
// if err := jwtService.SetRedisJWT(deviceAddr, deviceCode); err != nil {
// global.GVA_LOG.Error("设置登录状态失败!", zap.Error(err))
// response.FailWithMessage("设置登录状态失败", c)
// return
// }
// } else if err != nil {
// global.GVA_LOG.Error("设置设备码状态失败!", zap.Error(err))
// response.FailWithMessage("设置设备码状态失败", c)
// } else {
// var blackJWT system.JwtBlacklist
// blackJWT.Jwt = deviceStr
// if err := jwtService.JsonInBlacklist(blackJWT); err != nil {
// response.FailWithMessage("device code作废失败", c)
// return
// }
// if err := jwtService.SetRedisJWT(deviceAddr, deviceCode); err != nil {
// response.FailWithMessage("设置设备码状态失败", c)
// return
// }
// }
_,err = courseUsersService.GetCourseUsersByAddr(loginUser.Invitor) _,err = courseUsersService.GetCourseUsersByAddr(loginUser.Invitor)
if err != nil && err == gorm.ErrRecordNotFound{ if err != nil && err == gorm.ErrRecordNotFound{
response.FailWithMessage("邀请者不存在", c) response.FailWithMessage("邀请者不存在", c)
...@@ -336,4 +363,35 @@ func (courseUsersApi *CourseUsersApi) MetaMaskLogin(c *gin.Context) { ...@@ -336,4 +363,35 @@ func (courseUsersApi *CourseUsersApi) MetaMaskLogin(c *gin.Context) {
return return
} }
response.OkWithData(token, c) response.OkWithData(token, c)
}
// GetDeviceCode 获取设备码
// @Tags DeviceCode
// @Summary 分页获取CourseUsers列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query courseReq.CourseUsersSearch true "分页获取CourseUsers列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /courseUsers/getCode [get]
func (courseUsersApi *CourseUsersApi) GetDeviceCode(c *gin.Context) {
var pageInfo courseReq.CourseUsersSearch
err := c.ShouldBindQuery(&pageInfo)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
deviceStr, err := jwtService.GetRedisJWT(c.Request.Header.Get("address"))
if err == redis.Nil {
response.FailWithMessage("code not exists",c)
return
}
j := utils.NewJWT()
claims,err := j.ParseToken(deviceStr)
if err != nil {
response.FailWithMessage(err.Error(),c)
return
}
response.OkWithData(claims.DeviceCode,c)
} }
\ No newline at end of file
...@@ -2193,6 +2193,11 @@ var doc = `{ ...@@ -2193,6 +2193,11 @@ var doc = `{
}, },
{ {
"type": "string", "type": "string",
"name": "actionDesc",
"in": "query"
},
{
"type": "string",
"name": "actionEnd", "name": "actionEnd",
"in": "query" "in": "query"
}, },
...@@ -2290,6 +2295,11 @@ var doc = `{ ...@@ -2290,6 +2295,11 @@ var doc = `{
}, },
{ {
"type": "string", "type": "string",
"name": "actionDesc",
"in": "query"
},
{
"type": "string",
"name": "actionEnd", "name": "actionEnd",
"in": "query" "in": "query"
}, },
...@@ -2382,6 +2392,11 @@ var doc = `{ ...@@ -2382,6 +2392,11 @@ var doc = `{
}, },
{ {
"type": "string", "type": "string",
"name": "actionDesc",
"in": "query"
},
{
"type": "string",
"name": "actionEnd", "name": "actionEnd",
"in": "query" "in": "query"
}, },
...@@ -2507,6 +2522,11 @@ var doc = `{ ...@@ -2507,6 +2522,11 @@ var doc = `{
}, },
{ {
"type": "string", "type": "string",
"name": "actionDesc",
"in": "query"
},
{
"type": "string",
"name": "actionEnd", "name": "actionEnd",
"in": "query" "in": "query"
}, },
...@@ -3164,6 +3184,39 @@ var doc = `{ ...@@ -3164,6 +3184,39 @@ var doc = `{
} }
} }
}, },
"/courseActionUsers/signActionWeb": {
"post": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"CourseActionUsers"
],
"summary": "设备码签到",
"parameters": [
{
"description": "设备码签到",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.ReqCode"
}
}
],
"responses": {
"200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"获取成功\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/courseActionUsers/updateCourseActionUsers": { "/courseActionUsers/updateCourseActionUsers": {
"put": { "put": {
"security": [ "security": [
...@@ -4723,6 +4776,12 @@ var doc = `{ ...@@ -4723,6 +4776,12 @@ var doc = `{
"in": "query" "in": "query"
}, },
{ {
"type": "string",
"description": "CourseSignup ` + "`" + `gorm:\"foreignKey:Uid\"` + "`" + `\nCourseActionUsers ` + "`" + `gorm:\"foreignKey:Uid\"` + "`" + `",
"name": "deviceCode",
"in": "query"
},
{
"type": "integer", "type": "integer",
"description": "主键ID", "description": "主键ID",
"name": "id", "name": "id",
...@@ -4815,6 +4874,12 @@ var doc = `{ ...@@ -4815,6 +4874,12 @@ var doc = `{
"in": "query" "in": "query"
}, },
{ {
"type": "string",
"description": "CourseSignup ` + "`" + `gorm:\"foreignKey:Uid\"` + "`" + `\nCourseActionUsers ` + "`" + `gorm:\"foreignKey:Uid\"` + "`" + `",
"name": "deviceCode",
"in": "query"
},
{
"type": "integer", "type": "integer",
"description": "主键ID", "description": "主键ID",
"name": "id", "name": "id",
...@@ -4872,6 +4937,137 @@ var doc = `{ ...@@ -4872,6 +4937,137 @@ var doc = `{
} }
} }
}, },
"/courseUsers/getCode": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"DeviceCode"
],
"summary": "分页获取CourseUsers列表",
"parameters": [
{
"type": "string",
"name": "address",
"in": "query"
},
{
"type": "integer",
"name": "age",
"in": "query"
},
{
"type": "string",
"name": "company",
"in": "query"
},
{
"type": "string",
"description": "创建时间",
"name": "createdAt",
"in": "query"
},
{
"type": "string",
"description": "CourseSignup ` + "`" + `gorm:\"foreignKey:Uid\"` + "`" + `\nCourseActionUsers ` + "`" + `gorm:\"foreignKey:Uid\"` + "`" + `",
"name": "deviceCode",
"in": "query"
},
{
"type": "string",
"name": "endCreatedAt",
"in": "query"
},
{
"type": "integer",
"description": "主键ID",
"name": "id",
"in": "query"
},
{
"type": "string",
"name": "invitor",
"in": "query"
},
{
"type": "boolean",
"name": "isAdmin",
"in": "query"
},
{
"type": "string",
"description": "关键字",
"name": "keyword",
"in": "query"
},
{
"type": "string",
"name": "name",
"in": "query"
},
{
"type": "integer",
"description": "页码",
"name": "page",
"in": "query"
},
{
"type": "integer",
"description": "每页大小",
"name": "pageSize",
"in": "query"
},
{
"type": "string",
"name": "phone",
"in": "query"
},
{
"type": "string",
"name": "photo",
"in": "query"
},
{
"type": "string",
"name": "position",
"in": "query"
},
{
"type": "boolean",
"name": "sex",
"in": "query"
},
{
"type": "string",
"name": "startCreatedAt",
"in": "query"
},
{
"type": "string",
"description": "更新时间",
"name": "updatedAt",
"in": "query"
}
],
"responses": {
"200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"获取成功\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/courseUsers/getCourseUsersList": { "/courseUsers/getCourseUsersList": {
"get": { "get": {
"security": [ "security": [
...@@ -4913,6 +5109,12 @@ var doc = `{ ...@@ -4913,6 +5109,12 @@ var doc = `{
}, },
{ {
"type": "string", "type": "string",
"description": "CourseSignup ` + "`" + `gorm:\"foreignKey:Uid\"` + "`" + `\nCourseActionUsers ` + "`" + `gorm:\"foreignKey:Uid\"` + "`" + `",
"name": "deviceCode",
"in": "query"
},
{
"type": "string",
"name": "endCreatedAt", "name": "endCreatedAt",
"in": "query" "in": "query"
}, },
...@@ -19143,6 +19345,9 @@ var doc = `{ ...@@ -19143,6 +19345,9 @@ var doc = `{
"actionBanner": { "actionBanner": {
"type": "string" "type": "string"
}, },
"actionDesc": {
"type": "string"
},
"actionEnd": { "actionEnd": {
"type": "string" "type": "string"
}, },
...@@ -19370,6 +19575,10 @@ var doc = `{ ...@@ -19370,6 +19575,10 @@ var doc = `{
"description": "创建时间", "description": "创建时间",
"type": "string" "type": "string"
}, },
"deviceCode": {
"description": "CourseSignup ` + "`" + `gorm:\"foreignKey:Uid\"` + "`" + `\nCourseActionUsers ` + "`" + `gorm:\"foreignKey:Uid\"` + "`" + `",
"type": "string"
},
"id": { "id": {
"description": "主键ID", "description": "主键ID",
"type": "integer" "type": "integer"
...@@ -20137,6 +20346,17 @@ var doc = `{ ...@@ -20137,6 +20346,17 @@ var doc = `{
} }
} }
}, },
"request.ReqCode": {
"type": "object",
"properties": {
"aid": {
"type": "integer"
},
"deviceCode": {
"type": "string"
}
}
},
"request.RollBack": { "request.RollBack": {
"type": "object", "type": "object",
"properties": { "properties": {
......
...@@ -2177,6 +2177,11 @@ ...@@ -2177,6 +2177,11 @@
}, },
{ {
"type": "string", "type": "string",
"name": "actionDesc",
"in": "query"
},
{
"type": "string",
"name": "actionEnd", "name": "actionEnd",
"in": "query" "in": "query"
}, },
...@@ -2274,6 +2279,11 @@ ...@@ -2274,6 +2279,11 @@
}, },
{ {
"type": "string", "type": "string",
"name": "actionDesc",
"in": "query"
},
{
"type": "string",
"name": "actionEnd", "name": "actionEnd",
"in": "query" "in": "query"
}, },
...@@ -2366,6 +2376,11 @@ ...@@ -2366,6 +2376,11 @@
}, },
{ {
"type": "string", "type": "string",
"name": "actionDesc",
"in": "query"
},
{
"type": "string",
"name": "actionEnd", "name": "actionEnd",
"in": "query" "in": "query"
}, },
...@@ -2491,6 +2506,11 @@ ...@@ -2491,6 +2506,11 @@
}, },
{ {
"type": "string", "type": "string",
"name": "actionDesc",
"in": "query"
},
{
"type": "string",
"name": "actionEnd", "name": "actionEnd",
"in": "query" "in": "query"
}, },
...@@ -3148,6 +3168,39 @@ ...@@ -3148,6 +3168,39 @@
} }
} }
}, },
"/courseActionUsers/signActionWeb": {
"post": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"CourseActionUsers"
],
"summary": "设备码签到",
"parameters": [
{
"description": "设备码签到",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.ReqCode"
}
}
],
"responses": {
"200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"获取成功\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/courseActionUsers/updateCourseActionUsers": { "/courseActionUsers/updateCourseActionUsers": {
"put": { "put": {
"security": [ "security": [
...@@ -4707,6 +4760,12 @@ ...@@ -4707,6 +4760,12 @@
"in": "query" "in": "query"
}, },
{ {
"type": "string",
"description": "CourseSignup `gorm:\"foreignKey:Uid\"`\nCourseActionUsers `gorm:\"foreignKey:Uid\"`",
"name": "deviceCode",
"in": "query"
},
{
"type": "integer", "type": "integer",
"description": "主键ID", "description": "主键ID",
"name": "id", "name": "id",
...@@ -4799,6 +4858,12 @@ ...@@ -4799,6 +4858,12 @@
"in": "query" "in": "query"
}, },
{ {
"type": "string",
"description": "CourseSignup `gorm:\"foreignKey:Uid\"`\nCourseActionUsers `gorm:\"foreignKey:Uid\"`",
"name": "deviceCode",
"in": "query"
},
{
"type": "integer", "type": "integer",
"description": "主键ID", "description": "主键ID",
"name": "id", "name": "id",
...@@ -4856,6 +4921,137 @@ ...@@ -4856,6 +4921,137 @@
} }
} }
}, },
"/courseUsers/getCode": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"DeviceCode"
],
"summary": "分页获取CourseUsers列表",
"parameters": [
{
"type": "string",
"name": "address",
"in": "query"
},
{
"type": "integer",
"name": "age",
"in": "query"
},
{
"type": "string",
"name": "company",
"in": "query"
},
{
"type": "string",
"description": "创建时间",
"name": "createdAt",
"in": "query"
},
{
"type": "string",
"description": "CourseSignup `gorm:\"foreignKey:Uid\"`\nCourseActionUsers `gorm:\"foreignKey:Uid\"`",
"name": "deviceCode",
"in": "query"
},
{
"type": "string",
"name": "endCreatedAt",
"in": "query"
},
{
"type": "integer",
"description": "主键ID",
"name": "id",
"in": "query"
},
{
"type": "string",
"name": "invitor",
"in": "query"
},
{
"type": "boolean",
"name": "isAdmin",
"in": "query"
},
{
"type": "string",
"description": "关键字",
"name": "keyword",
"in": "query"
},
{
"type": "string",
"name": "name",
"in": "query"
},
{
"type": "integer",
"description": "页码",
"name": "page",
"in": "query"
},
{
"type": "integer",
"description": "每页大小",
"name": "pageSize",
"in": "query"
},
{
"type": "string",
"name": "phone",
"in": "query"
},
{
"type": "string",
"name": "photo",
"in": "query"
},
{
"type": "string",
"name": "position",
"in": "query"
},
{
"type": "boolean",
"name": "sex",
"in": "query"
},
{
"type": "string",
"name": "startCreatedAt",
"in": "query"
},
{
"type": "string",
"description": "更新时间",
"name": "updatedAt",
"in": "query"
}
],
"responses": {
"200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"获取成功\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/courseUsers/getCourseUsersList": { "/courseUsers/getCourseUsersList": {
"get": { "get": {
"security": [ "security": [
...@@ -4897,6 +5093,12 @@ ...@@ -4897,6 +5093,12 @@
}, },
{ {
"type": "string", "type": "string",
"description": "CourseSignup `gorm:\"foreignKey:Uid\"`\nCourseActionUsers `gorm:\"foreignKey:Uid\"`",
"name": "deviceCode",
"in": "query"
},
{
"type": "string",
"name": "endCreatedAt", "name": "endCreatedAt",
"in": "query" "in": "query"
}, },
...@@ -19127,6 +19329,9 @@ ...@@ -19127,6 +19329,9 @@
"actionBanner": { "actionBanner": {
"type": "string" "type": "string"
}, },
"actionDesc": {
"type": "string"
},
"actionEnd": { "actionEnd": {
"type": "string" "type": "string"
}, },
...@@ -19354,6 +19559,10 @@ ...@@ -19354,6 +19559,10 @@
"description": "创建时间", "description": "创建时间",
"type": "string" "type": "string"
}, },
"deviceCode": {
"description": "CourseSignup `gorm:\"foreignKey:Uid\"`\nCourseActionUsers `gorm:\"foreignKey:Uid\"`",
"type": "string"
},
"id": { "id": {
"description": "主键ID", "description": "主键ID",
"type": "integer" "type": "integer"
...@@ -20121,6 +20330,17 @@ ...@@ -20121,6 +20330,17 @@
} }
} }
}, },
"request.ReqCode": {
"type": "object",
"properties": {
"aid": {
"type": "integer"
},
"deviceCode": {
"type": "string"
}
}
},
"request.RollBack": { "request.RollBack": {
"type": "object", "type": "object",
"properties": { "properties": {
......
...@@ -785,6 +785,8 @@ definitions: ...@@ -785,6 +785,8 @@ definitions:
properties: properties:
actionBanner: actionBanner:
type: string type: string
actionDesc:
type: string
actionEnd: actionEnd:
type: string type: string
actionName: actionName:
...@@ -940,6 +942,11 @@ definitions: ...@@ -940,6 +942,11 @@ definitions:
createdAt: createdAt:
description: 创建时间 description: 创建时间
type: string type: string
deviceCode:
description: |-
CourseSignup `gorm:"foreignKey:Uid"`
CourseActionUsers `gorm:"foreignKey:Uid"`
type: string
id: id:
description: 主键ID description: 主键ID
type: integer type: integer
...@@ -1470,6 +1477,13 @@ definitions: ...@@ -1470,6 +1477,13 @@ definitions:
example: 用户名 example: 用户名
type: string type: string
type: object type: object
request.ReqCode:
properties:
aid:
type: integer
deviceCode:
type: string
type: object
request.RollBack: request.RollBack:
properties: properties:
deleteTable: deleteTable:
...@@ -3795,6 +3809,9 @@ paths: ...@@ -3795,6 +3809,9 @@ paths:
name: actionBanner name: actionBanner
type: string type: string
- in: query - in: query
name: actionDesc
type: string
- in: query
name: actionEnd name: actionEnd
type: string type: string
- in: query - in: query
...@@ -3852,6 +3869,9 @@ paths: ...@@ -3852,6 +3869,9 @@ paths:
name: actionBanner name: actionBanner
type: string type: string
- in: query - in: query
name: actionDesc
type: string
- in: query
name: actionEnd name: actionEnd
type: string type: string
- in: query - in: query
...@@ -3911,6 +3931,9 @@ paths: ...@@ -3911,6 +3931,9 @@ paths:
name: actionBanner name: actionBanner
type: string type: string
- in: query - in: query
name: actionDesc
type: string
- in: query
name: actionEnd name: actionEnd
type: string type: string
- in: query - in: query
...@@ -3986,6 +4009,9 @@ paths: ...@@ -3986,6 +4009,9 @@ paths:
name: actionBanner name: actionBanner
type: string type: string
- in: query - in: query
name: actionDesc
type: string
- in: query
name: actionEnd name: actionEnd
type: string type: string
- in: query - in: query
...@@ -4396,6 +4422,27 @@ paths: ...@@ -4396,6 +4422,27 @@ paths:
summary: 创建CourseActionUsers summary: 创建CourseActionUsers
tags: tags:
- CourseActionUsers - CourseActionUsers
/courseActionUsers/signActionWeb:
post:
consumes:
- application/json
parameters:
- description: 设备码签到
in: body
name: data
required: true
schema:
$ref: '#/definitions/request.ReqCode'
produces:
- application/json
responses:
"200":
description: '{"success":true,"data":{},"msg":"获取成功"}'
schema:
type: string
summary: 设备码签到
tags:
- CourseActionUsers
/courseActionUsers/updateCourseActionUsers: /courseActionUsers/updateCourseActionUsers:
put: put:
consumes: consumes:
...@@ -5346,6 +5393,12 @@ paths: ...@@ -5346,6 +5393,12 @@ paths:
in: query in: query
name: createdAt name: createdAt
type: string type: string
- description: |-
CourseSignup `gorm:"foreignKey:Uid"`
CourseActionUsers `gorm:"foreignKey:Uid"`
in: query
name: deviceCode
type: string
- description: 主键ID - description: 主键ID
in: query in: query
name: id name: id
...@@ -5405,6 +5458,12 @@ paths: ...@@ -5405,6 +5458,12 @@ paths:
in: query in: query
name: createdAt name: createdAt
type: string type: string
- description: |-
CourseSignup `gorm:"foreignKey:Uid"`
CourseActionUsers `gorm:"foreignKey:Uid"`
in: query
name: deviceCode
type: string
- description: 主键ID - description: 主键ID
in: query in: query
name: id name: id
...@@ -5444,6 +5503,89 @@ paths: ...@@ -5444,6 +5503,89 @@ paths:
summary: 用id查询CourseUsers summary: 用id查询CourseUsers
tags: tags:
- CourseUsers - CourseUsers
/courseUsers/getCode:
get:
consumes:
- application/json
parameters:
- in: query
name: address
type: string
- in: query
name: age
type: integer
- in: query
name: company
type: string
- description: 创建时间
in: query
name: createdAt
type: string
- description: |-
CourseSignup `gorm:"foreignKey:Uid"`
CourseActionUsers `gorm:"foreignKey:Uid"`
in: query
name: deviceCode
type: string
- in: query
name: endCreatedAt
type: string
- description: 主键ID
in: query
name: id
type: integer
- in: query
name: invitor
type: string
- in: query
name: isAdmin
type: boolean
- description: 关键字
in: query
name: keyword
type: string
- in: query
name: name
type: string
- description: 页码
in: query
name: page
type: integer
- description: 每页大小
in: query
name: pageSize
type: integer
- in: query
name: phone
type: string
- in: query
name: photo
type: string
- in: query
name: position
type: string
- in: query
name: sex
type: boolean
- in: query
name: startCreatedAt
type: string
- description: 更新时间
in: query
name: updatedAt
type: string
produces:
- application/json
responses:
"200":
description: '{"success":true,"data":{},"msg":"获取成功"}'
schema:
type: string
security:
- ApiKeyAuth: []
summary: 分页获取CourseUsers列表
tags:
- DeviceCode
/courseUsers/getCourseUsersList: /courseUsers/getCourseUsersList:
get: get:
consumes: consumes:
...@@ -5462,6 +5604,12 @@ paths: ...@@ -5462,6 +5604,12 @@ paths:
in: query in: query
name: createdAt name: createdAt
type: string type: string
- description: |-
CourseSignup `gorm:"foreignKey:Uid"`
CourseActionUsers `gorm:"foreignKey:Uid"`
in: query
name: deviceCode
type: string
- in: query - in: query
name: endCreatedAt name: endCreatedAt
type: string type: string
......
...@@ -70,6 +70,7 @@ func Routers() *gin.Engine { ...@@ -70,6 +70,7 @@ func Routers() *gin.Engine {
courseRouter.InitCourseBannersPubRouter(AppGroup) courseRouter.InitCourseBannersPubRouter(AppGroup)
courseRouter.InitCourseListPubRouter(AppGroup) courseRouter.InitCourseListPubRouter(AppGroup)
courseRouter.InitCourseActionWebRouter(AppGroup) courseRouter.InitCourseActionWebRouter(AppGroup)
courseRouter.InitCourseActionUsersPubRouter(AppGroup)
} }
PrivateGroup := Router.Group(global.GVA_CONFIG.System.RouterPrefix) PrivateGroup := Router.Group(global.GVA_CONFIG.System.RouterPrefix)
PrivateGroup.Use(middleware.JWTAuth()).Use(middleware.CasbinHandler()) PrivateGroup.Use(middleware.JWTAuth()).Use(middleware.CasbinHandler())
......
...@@ -22,6 +22,7 @@ type CourseUsers struct { ...@@ -22,6 +22,7 @@ type CourseUsers struct {
// CourseSignup `gorm:"foreignKey:Uid"` // CourseSignup `gorm:"foreignKey:Uid"`
// CourseActionUsers `gorm:"foreignKey:Uid"` // CourseActionUsers `gorm:"foreignKey:Uid"`
DeviceCode string `json:"deviceCode" form:"deviceCode" gorm:"-"`
} }
......
package request package request
import ( import (
"courseSign/server/model/course"
"courseSign/server/model/common/request"
"time" "time"
"courseSign/server/model/common/request"
"courseSign/server/model/course"
) )
type CourseActionUsersSearch struct{ type CourseActionUsersSearch struct{
...@@ -12,3 +13,8 @@ type CourseActionUsersSearch struct{ ...@@ -12,3 +13,8 @@ type CourseActionUsersSearch struct{
EndCreatedAt *time.Time `json:"endCreatedAt" form:"endCreatedAt"` EndCreatedAt *time.Time `json:"endCreatedAt" form:"endCreatedAt"`
request.PageInfo request.PageInfo
} }
type ReqCode struct {
Aid int `json:"aid" form:"aid"`
DeviceCode string `json:"deviceCode" form:"deviceCode"`
}
\ No newline at end of file
...@@ -18,4 +18,5 @@ type BaseClaims struct { ...@@ -18,4 +18,5 @@ type BaseClaims struct {
Username string Username string
NickName string NickName string
AuthorityId uint AuthorityId uint
DeviceCode string
} }
...@@ -35,4 +35,13 @@ func (s *CourseActionUsersRouter) InitCourseActionUsersMetaMaskRouter(Router *gi ...@@ -35,4 +35,13 @@ func (s *CourseActionUsersRouter) InitCourseActionUsersMetaMaskRouter(Router *gi
courseActionUsersRouter.POST("signAction", courseActionUsersApi.SignAction) // 新建CourseActionUsers courseActionUsersRouter.POST("signAction", courseActionUsersApi.SignAction) // 新建CourseActionUsers
courseActionUsersRouter.GET("myAction", courseActionUsersApi.GetMyAction) // 新建CourseActionUsers courseActionUsersRouter.GET("myAction", courseActionUsersApi.GetMyAction) // 新建CourseActionUsers
} }
}
// InitCourseActionUsersPubRouter 初始化 CourseActionUsers 路由信息
func (s *CourseActionUsersRouter) InitCourseActionUsersPubRouter(Router *gin.RouterGroup) {
courseActionUsersRouter := Router.Group("courseActionUsers").Use(middleware.OperationRecord())
var courseActionUsersApi = v1.ApiGroupApp.CourseApiGroup.CourseActionUsersApi
{
courseActionUsersRouter.POST("signActionWeb", courseActionUsersApi.WebSignAction) // 新建CourseActionUsers
}
} }
\ No newline at end of file
...@@ -33,6 +33,7 @@ func (s *CourseUsersRouter) InitCourseUsersMetaMaskRouter(Router *gin.RouterGrou ...@@ -33,6 +33,7 @@ func (s *CourseUsersRouter) InitCourseUsersMetaMaskRouter(Router *gin.RouterGrou
var courseUsersApi = v1.ApiGroupApp.CourseApiGroup.CourseUsersApi var courseUsersApi = v1.ApiGroupApp.CourseApiGroup.CourseUsersApi
{ {
courseUsersRouter.GET("findUsers", courseUsersApi.FindCourseUsersMM) // 根据ID,addr获取用户信息 courseUsersRouter.GET("findUsers", courseUsersApi.FindCourseUsersMM) // 根据ID,addr获取用户信息
courseUsersRouter.GET("getCode",courseUsersApi.GetDeviceCode) // 获取设备码
} }
} }
......
...@@ -2,13 +2,16 @@ package utils ...@@ -2,13 +2,16 @@ package utils
import ( import (
"crypto/md5" "crypto/md5"
"encoding/base64"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"log" "log"
"math" "math"
"math/rand"
"net/url" "net/url"
"sort" "sort"
"strings" "strings"
"time"
) )
func MapToSortUrlEncode(paramsMap map[string]string) string { func MapToSortUrlEncode(paramsMap map[string]string) string {
...@@ -49,4 +52,10 @@ func Decimal(value float64, num int) float64 { ...@@ -49,4 +52,10 @@ func Decimal(value float64, num int) float64 {
func UniqueId (id int64) string { func UniqueId (id int64) string {
return fmt.Sprintf("addr-%d",id) return fmt.Sprintf("addr-%d",id)
}
func CreateDeviceCode(addr string) string {
rand.Seed(time.Now().UnixNano())
rr := rand.Intn(1e4)
return base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s-%d",addr,rr)))
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment