Commit 94e970a0 authored by hujiebin's avatar hujiebin

feat:调整路由

parent 681bf0f0
...@@ -3,6 +3,7 @@ package bag_m ...@@ -3,6 +3,7 @@ package bag_m
import ( import (
"git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql" "git.hilo.cn/hilo-common/resource/mysql"
"gorm.io/gorm/clause"
"hilo-user/_const/enum/res_e" "hilo-user/_const/enum/res_e"
"time" "time"
) )
...@@ -10,12 +11,25 @@ import ( ...@@ -10,12 +11,25 @@ import (
type UserBag struct { type UserBag struct {
mysql.Entity mysql.Entity
UserId mysql.ID UserId mysql.ID
ResType mysql.Type ResType mysql.Type // 资源类型 1:礼物
ResId mysql.ID ResId mysql.ID
Count mysql.Num Count mysql.Num
EndTime time.Time EndTime time.Time
} }
type UserBagDetail struct {
mysql.Entity
UserId mysql.ID
BagId mysql.ID
ResType mysql.Type // 资源类型 1:礼物
ResId mysql.ID
Count mysql.Num
AddReduce mysql.AddReduce
BefNum mysql.Num
AftNum mysql.Num
Remark mysql.Str
}
// 获取用户有效的背包 // 获取用户有效的背包
// param userId 用户id // param userId 用户id
// param resType 背包类型 1:礼物 // param resType 背包类型 1:礼物
...@@ -44,3 +58,49 @@ func GetUserBag(model *domain.Model, bagId mysql.ID) (*UserBag, error) { ...@@ -44,3 +58,49 @@ func GetUserBag(model *domain.Model, bagId mysql.ID) (*UserBag, error) {
} }
return res, nil return res, nil
} }
// 增加用户背包
// param userId 用户id
// param resType 道具类型
// param resId 道具id
// param count 增加数量
// param day 增加天数
// condition:
// 0.事务操作
// 1.背包表
// 2.明细表
func AddUserBag(model *domain.Model, userId mysql.ID, resType mysql.Type, resId mysql.ID, count mysql.Num, day int, reason string) error {
return model.Transaction(func(model *domain.Model) error {
// 1.背包表
endTime := time.Now().AddDate(0, 0, day)
userBag := &UserBag{
UserId: userId,
ResType: resType,
ResId: resId,
Count: count,
EndTime: endTime,
}
if err := model.DB().Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "user_id"}, {Name: "res_type"}, {Name: "res_id"}, {Name: "end_time"}},
DoUpdates: clause.AssignmentColumns([]string{"count"}),
}).Create(userBag).Error; err != nil {
return err
}
// 2.明细表
userBagDetail := &UserBagDetail{
UserId: userId,
BagId: userBag.ID,
ResType: resType,
ResId: resId,
Count: count,
AddReduce: mysql.ADD,
BefNum: 0, // 加背包的统一为0
AftNum: count, // 加背包统一为count,因为每次加几乎不可能是一样的
Remark: reason,
}
if err := model.DB().Create(userBagDetail).Error; err != nil {
return err
}
return nil
})
}
...@@ -26,7 +26,8 @@ func InitRouter() *gin.Engine { ...@@ -26,7 +26,8 @@ func InitRouter() *gin.Engine {
innerUser := inner.Group("/user") innerUser := inner.Group("/user")
{ {
innerUser.GET("/levels", wrapper(user_r.MGetUserLevels)) innerUser.GET("/levels", wrapper(user_r.MGetUserLevels))
innerUser.GET("/bag", wrapper(user_r.GetUserBag)) innerUser.GET("/bag/id", wrapper(user_r.GetUserBagId))
//innerUser.POST("/bag/send", wrapper(user_r.SendUserBag))
} }
return r return r
} }
...@@ -55,8 +55,8 @@ type GetUserBagReq struct { ...@@ -55,8 +55,8 @@ type GetUserBagReq struct {
// @Summary 获取单个背包 // @Summary 获取单个背包
// @Param bagId query int true "背包id" // @Param bagId query int true "背包id"
// @Success 200 {object} user_cv.UserBag // @Success 200 {object} user_cv.UserBag
// @Router /inner/user/bag [get] // @Router /inner/user/bag/id [get]
func GetUserBag(c *gin.Context) (*mycontext.MyContext, error) { func GetUserBagId(c *gin.Context) (*mycontext.MyContext, error) {
myCtx := mycontext.CreateMyContext(c.Keys) myCtx := mycontext.CreateMyContext(c.Keys)
var model = domain.CreateModelContext(myCtx) var model = domain.CreateModelContext(myCtx)
var req GetUserBagReq var req GetUserBagReq
......
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