diff --git a/api/v1/couponusers/couponUsers.go b/api/v1/couponusers/couponUsers.go index c32bfce..5821d5d 100644 --- a/api/v1/couponusers/couponUsers.go +++ b/api/v1/couponusers/couponUsers.go @@ -30,3 +30,8 @@ type IssueCouponUserReq struct { type IsEligibleUserReq struct { CouponIds []int `json:"couponIds" dc:"能抽出的卡券id"` } + +type AddRecordReq struct { + CouponId int `json:"couponId" dc:"卡券id"` + Name string `json:"name" dc:"选择武器名称"` +} diff --git a/internal/cmd/cmd.go b/internal/cmd/cmd.go index 36c557d..fd9dbba 100644 --- a/internal/cmd/cmd.go +++ b/internal/cmd/cmd.go @@ -27,6 +27,7 @@ var ( group.POST("/insert-users-to-redis", couponusers.NewCouponUsers().InsertJwcodesToRedisByExcel) //导入满足条件的用户jwcode到redis group.POST("/is-eligible-user", couponusers.NewCouponUsers().IsEligibleUser) //判断用户是否满足领取条件 group.POST("/issue-coupon-to-users", couponusers.NewCouponUsers().IssueCouponUser) //给单个用户发放卡券 + group.POST("/add-record", couponusers.NewCouponUsers().AddRecord) //添加用户选择武器记录 }) s.Run() return nil diff --git a/internal/controller/couponusers/couponUsers.go b/internal/controller/couponusers/couponUsers.go index 352ed1a..b54d804 100644 --- a/internal/controller/couponusers/couponUsers.go +++ b/internal/controller/couponusers/couponUsers.go @@ -215,6 +215,32 @@ func (c *CouponUsers) IssueCouponUser(r *ghttp.Request) { } +// 添加用户选择武器记录 +func (c *CouponUsers) AddRecord(r *ghttp.Request) { + var req *couponusers.AddRecordReq + if err := r.Parse(&req); err != nil { + r.Response.WriteJsonExit(dto.Error(err.Error())) + } + //解析token,获取jwcode + token := r.Header.Get("token") + if token == "" { + r.Response.WriteJsonExit(dto.Error("token为空")) + } + + jwcode, err := utility.GetJwcodeJSON(token) + if err != nil { + r.Response.WriteJsonExit(dto.Error(err.Error())) + } + + err = service.CouponUsers().AddRecord(r.Context(), jwcode, req.CouponId, req.Name) + //错误处理 + if err != nil { + r.Response.WriteJsonExit(dto.Error(err.Error())) + } + //成功处理 + r.Response.WriteJsonExit(dto.SuccessWithMsg("记录成功")) +} + /*近期使用*/ // 未编写 diff --git a/internal/logic/couponusers/couponUsers.go b/internal/logic/couponusers/couponUsers.go index 4286988..02c6bd2 100644 --- a/internal/logic/couponusers/couponUsers.go +++ b/internal/logic/couponusers/couponUsers.go @@ -355,3 +355,14 @@ func (s *sCouponUsers) IssueCouponToUser(ctx context.Context, jwcode, couponId i return errors.New("该用户精网号不符合领取条件") //遍历完了所有满足条件的用户,发现不在其中,不符合条件 } + +// 添加用户选择武器记录 +func (s *sCouponUsers) AddRecord(ctx context.Context, jwcode int, id int, name string) (err error) { + _, err = dao.CouponUsers.Ctx(ctx).Data(g.Map{ + "record": name, + }).Where("jwcode = ? and coupon_id = ?", jwcode, id).Update() + if err != nil { + return errors.New("添加武器记录失败") + } + return +} diff --git a/internal/service/couponusers.go b/internal/service/couponusers.go index e06d13a..03ea8d6 100644 --- a/internal/service/couponusers.go +++ b/internal/service/couponusers.go @@ -28,6 +28,8 @@ type ( IsEligibleUser(ctx context.Context, jwcode int, couponIds []int) (img string, err error) // 给单个用户发放卡券 IssueCouponToUser(ctx context.Context, jwcode int, couponId int) (err error) + // 添加用户选择武器记录 + AddRecord(ctx context.Context, jwcode int, id int, name string) (err error) } )