This commit is contained in:
yangduo 2025-05-17 19:26:51 +08:00
parent 4a05b43729
commit f3596c6109
2 changed files with 46 additions and 7 deletions

View File

@ -233,8 +233,11 @@ func (gca *GiftCodeApi) ListType(c *gin.Context) {
func (gca *GiftCodeApi) AddType(c *gin.Context) {
req := struct {
GameId int32 `binding:"required" json:"gameid"`
Limit *int32 `binding:"required" json:"limit"`
Limit *int32 `binding:"required" json:"limit"`
Content string `binding:"required" json:"content"`
Start *int32 `binding:"required" json:"start"`
End *int32 `binding:"required" json:"end"`
Comment string `binding:"required" json:"comment"`
}{}
if err := c.ShouldBindJSON(&req); err != nil {
f5.RspErr2(c, 1, err.Error())
@ -271,6 +274,9 @@ func (gca *GiftCodeApi) AddType(c *gin.Context) {
if p.Limit > 1 {
p.Limit = 1
}
p.Start = *req.Start
p.End = *req.End
p.Comment = req.Comment
p.CreateTime = nowsecs
p.ModifyTime = nowsecs
@ -299,7 +305,7 @@ func (gca *GiftCodeApi) QueryCode(c *gin.Context) {
rspObj := struct {
ErrCode int32 `json:"errcode"`
ErrMsg string `json:"errmsg"`
CodeStatus int32 `json:"status"` //0:可用;1:已用;2:不存在
CodeStatus int32 `json:"status"` //0:可用;1:已用;2:不存在;3:失效
Type int32 `json:"type"`
}{}
codeinfo := new(system.GiftCode)
@ -314,7 +320,22 @@ func (gca *GiftCodeApi) QueryCode(c *gin.Context) {
} else if codeinfo.Limit > 0 && codeinfo.Count > 0 {
rspObj.CodeStatus = 1
} else {
rspObj.Type = codeinfo.GiftType
typeinfo := new(system.GiftType)
db := f5.GetApp().GetOrmDb(constant.ADMIN_DB).Table(typeinfo.TableName()).Take(typeinfo, "gameid = ? AND gift_type = ?", req.GameId, codeinfo.GiftType)
err := db.Error
nowsec := int32(f5.GetApp().GetRealSeconds())
if err != nil {
if !f5.IsOrmErrRecordNotFound(err) {
f5.RspErr(c, 1, err.Error())
return
}
rspObj.CodeStatus = 2
} else if (typeinfo.Start > 0 && typeinfo.Start > nowsec) ||
(typeinfo.End > 0 && typeinfo.End < nowsec) {
rspObj.CodeStatus = 3
} else {
rspObj.Type = codeinfo.GiftType
}
}
c.JSON(http.StatusOK, rspObj)
@ -347,7 +368,7 @@ func (gca *GiftCodeApi) UseCode(c *gin.Context) {
rspObj := struct {
ErrCode int32 `json:"errcode"`
ErrMsg string `json:"errmsg"`
CodeStatus int32 `json:"status"` //0:可用;1:已用;2:不存在
CodeStatus int32 `json:"status"` //0:可用;1:已用;2:不存在;3:失效
Limit int32 `json:"limit"`
Content string `json:"content"`
Type int32 `json:"type"`
@ -364,9 +385,24 @@ func (gca *GiftCodeApi) UseCode(c *gin.Context) {
} else if codeinfo.Limit > 0 && codeinfo.Count >= codeinfo.Limit {
rspObj.CodeStatus = 1
} else {
rspObj.Limit = codeinfo.Limit
rspObj.Content = codeinfo.Content
rspObj.Type = codeinfo.GiftType
typeinfo := new(system.GiftType)
db := f5.GetApp().GetOrmDb(constant.ADMIN_DB).Table(typeinfo.TableName()).Take(typeinfo, "gameid = ? AND gift_type = ?", req.GameId, codeinfo.GiftType)
err := db.Error
nowsec := int32(f5.GetApp().GetRealSeconds())
if err != nil {
if !f5.IsOrmErrRecordNotFound(err) {
f5.RspErr(c, 1, err.Error())
return
}
rspObj.CodeStatus = 2
} else if (typeinfo.Start > 0 && typeinfo.Start > nowsec) ||
(typeinfo.End > 0 && typeinfo.End < nowsec) {
rspObj.CodeStatus = 3
} else {
rspObj.Limit = codeinfo.Limit
rspObj.Content = codeinfo.Content
rspObj.Type = codeinfo.GiftType
}
}
c.JSON(http.StatusOK, rspObj)

View File

@ -21,6 +21,9 @@ type GiftType struct {
GiftType int32 `gorm:"column:gift_type" json:"gift_type"`
Content string `gorm:"column:content" json:"content"`
Limit int32 `gorm:"column:limit" json:"limit"`
Start int32 `gorm:"column:start" json:"start"`
End int32 `gorm:"column:end" json:"end"`
Comment string `gorm:"column:comment" json:"comment"`
CreateTime int32 `gorm:"column:createtime" json:"-"`
ModifyTime int32 `gorm:"column:modifytime" json:"-"`
}