From d8c8ec8f6e9f7a8f96c0dc771f085d180c72759f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AD=90=E9=93=AD?= Date: Sat, 8 Mar 2025 15:17:07 +0800 Subject: [PATCH] cmb --- api/v1/cmb_cpn.proto | 11 ++++++++++- internal/biz/cmb.go | 19 ++++++++++++++++++- internal/biz/repo/order_wechat.go | 1 + internal/data/repoimpl/order_wechat.go | 16 ++++++++++++++++ 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/api/v1/cmb_cpn.proto b/api/v1/cmb_cpn.proto index bdcc146..834a91a 100644 --- a/api/v1/cmb_cpn.proto +++ b/api/v1/cmb_cpn.proto @@ -74,7 +74,16 @@ message CmbQueryRequest { string codeNo = 9 [json_name = "codeNo", (validate.rules).string = {min_len: 1,max_len: 32}]; } message CmbQueryReply { - + // 优惠券券码,codeNo + string ticket = 9 [json_name = "ticket"]; + // 更新后串码状态,0:可使用,1:已使用 + string status = 10 [json_name = "status"]; + // 验码日期,格式yyyy-mm-dd hh:mm:ss.sss + string transDate = 11 [json_name = "transDate"]; + // 发码机构号,固定值,掌上生活优惠券系统提供 + string orgNo = 12 [json_name = "orgNo"]; + // 扩展字段 + string ext = 13 [json_name = "ext"]; } diff --git a/internal/biz/cmb.go b/internal/biz/cmb.go index 236e1bf..4ea9e6f 100644 --- a/internal/biz/cmb.go +++ b/internal/biz/cmb.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "gorm.io/gorm" + "time" v1 "voucher/api/v1" "voucher/internal/biz/bo" "voucher/internal/biz/vo" @@ -53,7 +54,23 @@ func (v *VoucherBiz) CmbQuery(ctx context.Context, orderNo string) (reps *v1.Cmb err = lock.NewMutex(v.rdb.Rdb, c.TTL).Lock(ctx, c.Key, func(ctx context.Context) error { - reps = &v1.CmbQueryReply{} + orderWechat, err := v.OrderWechatRepo.GetByOrderNo(ctx, orderNo) + if err != nil { + return err + } + + status, err := orderWechat.Status.GetCmbStatusText() + if err != nil { + return err + } + + reps = &v1.CmbQueryReply{ + Ticket: orderWechat.OrderNo, + Status: status.GetValue(), + TransDate: time.Now().Format("20060102150405"), + OrgNo: v.bc.Cmb.OrgNo, + Ext: "", + } return nil }) diff --git a/internal/biz/repo/order_wechat.go b/internal/biz/repo/order_wechat.go index 1b73201..6cea8ca 100644 --- a/internal/biz/repo/order_wechat.go +++ b/internal/biz/repo/order_wechat.go @@ -10,6 +10,7 @@ type OrderWechatRepo interface { Success(ctx context.Context, id uint64, couponId string) error Fail(ctx context.Context, id uint64, remark string) error GetByOutRequestNo(ctx context.Context, outRequestNo string) (*bo.OrderWechatBo, error) + GetByOrderNo(ctx context.Context, orderNo string) (*bo.OrderWechatBo, error) GetByMSCId(ctx context.Context, mchId, stockId, couponId string) (*bo.OrderWechatBo, error) Used(ctx context.Context, id uint64) error Expired(ctx context.Context, id uint64) error diff --git a/internal/data/repoimpl/order_wechat.go b/internal/data/repoimpl/order_wechat.go index 93020df..1c96945 100644 --- a/internal/data/repoimpl/order_wechat.go +++ b/internal/data/repoimpl/order_wechat.go @@ -85,6 +85,22 @@ func (p *OrderWechatRepoImpl) GetByOutRequestNo(ctx context.Context, outRequestN return p.ToBo(info), nil } +func (p *OrderWechatRepoImpl) GetByOrderNo(ctx context.Context, orderNo string) (*bo.OrderWechatBo, error) { + info := &model.OrderWechat{} + + tx := p.DB(ctx).Where(model.OrderWechat{OrderNo: orderNo}).Find(&info) + + if tx.Error != nil { + return nil, tx.Error + } + + if tx.RowsAffected == 0 { + return nil, gorm.ErrRecordNotFound + } + + return p.ToBo(info), nil +} + func (p *OrderWechatRepoImpl) Success(ctx context.Context, id uint64, couponId string) error { now := time.Now()