Browse Source

编写添加用户选择武器记录接口

mj-wq
majun 6 months ago
parent
commit
8b7ae02a8b
  1. 5
      api/v1/couponusers/couponUsers.go
  2. 1
      internal/cmd/cmd.go
  3. 2
      internal/consts/consts.go
  4. 26
      internal/controller/couponusers/couponUsers.go
  5. 11
      internal/logic/couponusers/couponUsers.go
  6. 2
      internal/service/couponusers.go

5
api/v1/couponusers/couponUsers.go

@ -26,3 +26,8 @@ type InsertCouponUserReq struct {
type IssueCouponUserReq struct {
CouponId int `json:"couponId" dc:"卡券id"`
}
type AddRecordReq struct {
CouponId int `json:"couponId" dc:"卡券id"`
Name string `json:"name" dc:"选择武器名称"`
}

1
internal/cmd/cmd.go

@ -24,6 +24,7 @@ var (
//近期使用
group.POST("/insert-users-to-redis", couponusers.NewCouponUsers().InsertJwcodesToRedisByExcel) //导入满足条件的用户jwcode到redis
group.POST("/issue-coupon-to-users", couponusers.NewCouponUsers().IssueCouponUser) //给单个用户发放卡券
group.POST("/add-record", couponusers.NewCouponUsers().AddRecord) //添加用户选择武器记录
})
s.Run()
return nil

2
internal/consts/consts.go

@ -5,5 +5,5 @@ const (
//内容: http://39.101.133.168:8828/hljw
//测试环境解析token接口: http://39.101.133.168:8828/hljw/api/v2/member/info
//正式环境解析token接口: http://api.homilychart.com:8828/hljw/api/v2/member/info
URL_HASH_KEY = "HLJW_BASE_URL"
URL_HASH_KEY = "HLJW_URL"
)

26
internal/controller/couponusers/couponUsers.go

@ -186,3 +186,29 @@ 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

@ -311,3 +311,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

@ -26,6 +26,8 @@ type (
InsertJwcodesToRedisByExcel(file multipart.File) (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