Browse Source

12.28日合并ljk, mj-wq分支

master
lijikun 6 months ago
parent
commit
94f7d77ffb
  1. 5
      api/v1/couponusers/couponUsers.go
  2. 1
      internal/cmd/cmd.go
  3. 26
      internal/controller/couponusers/couponUsers.go
  4. 11
      internal/logic/couponusers/couponUsers.go
  5. 2
      internal/service/couponusers.go

5
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:"选择武器名称"`
}

1
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

26
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("记录成功"))
}
/*近期使用*/
// 未编写

11
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
}

2
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)
}
)

Loading…
Cancel
Save