From 8b7ae02a8b3464c223cc08857267f4a800ad9364 Mon Sep 17 00:00:00 2001 From: majun <3060162534@qq.com> Date: Sat, 28 Dec 2024 10:32:50 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=96=E5=86=99=E6=B7=BB=E5=8A=A0=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E9=80=89=E6=8B=A9=E6=AD=A6=E5=99=A8=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/v1/couponusers/couponUsers.go | 5 +++++ internal/cmd/cmd.go | 1 + internal/consts/consts.go | 2 +- internal/controller/couponusers/couponUsers.go | 26 ++++++++++++++++++++++++++ internal/logic/couponusers/couponUsers.go | 11 +++++++++++ internal/service/couponusers.go | 2 ++ 6 files changed, 46 insertions(+), 1 deletion(-) diff --git a/api/v1/couponusers/couponUsers.go b/api/v1/couponusers/couponUsers.go index 3fd5f27..e48cc18 100644 --- a/api/v1/couponusers/couponUsers.go +++ b/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:"选择武器名称"` +} diff --git a/internal/cmd/cmd.go b/internal/cmd/cmd.go index 6d1d5c5..c3e90c1 100644 --- a/internal/cmd/cmd.go +++ b/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 diff --git a/internal/consts/consts.go b/internal/consts/consts.go index 6f51821..2c59161 100644 --- a/internal/consts/consts.go +++ b/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" ) diff --git a/internal/controller/couponusers/couponUsers.go b/internal/controller/couponusers/couponUsers.go index 178081a..729cc24 100644 --- a/internal/controller/couponusers/couponUsers.go +++ b/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("记录成功")) +} diff --git a/internal/logic/couponusers/couponUsers.go b/internal/logic/couponusers/couponUsers.go index a5eea82..a436c70 100644 --- a/internal/logic/couponusers/couponUsers.go +++ b/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 +} diff --git a/internal/service/couponusers.go b/internal/service/couponusers.go index 8f3215e..472aecf 100644 --- a/internal/service/couponusers.go +++ b/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) } )