From f840cbf0ae87a3749e44293aec0524e7e6308493 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AD=90=E9=93=AD?= Date: Tue, 4 Mar 2025 14:54:41 +0800 Subject: [PATCH] cmb --- internal/biz/cmb/voucher.go | 6 +++--- internal/service/base.go | 34 ---------------------------------- internal/service/cmb.go | 2 +- internal/service/voucher.go | 4 ++++ 4 files changed, 8 insertions(+), 38 deletions(-) delete mode 100644 internal/service/base.go diff --git a/internal/biz/cmb/voucher.go b/internal/biz/cmb/voucher.go index d4dfac8..767de95 100644 --- a/internal/biz/cmb/voucher.go +++ b/internal/biz/cmb/voucher.go @@ -12,7 +12,7 @@ import ( "voucher/internal/pkg/uid" ) -func (v *Cmb) CmbOrder(ctx context.Context, req *bo.OrderCreateReqBo) (reps *bo.OrderCreateRepBo, err error) { +func (v *Cmb) Order(ctx context.Context, req *bo.OrderCreateReqBo) (reps *bo.OrderCreateRepBo, err error) { err = lock.NewMutex(v.rdb.Rdb, time.Second*30).Lock(ctx, fmt.Sprintf("cmb_order_%s", req.OutBizNo), func(ctx context.Context) error { @@ -63,7 +63,7 @@ func (v *Cmb) CmbOrder(ctx context.Context, req *bo.OrderCreateReqBo) (reps *bo. return } -func (v *Cmb) CmbQuery(ctx context.Context, req *bo.OrderCreateReqBo) (reps *bo.OrderCreateRepBo, err error) { +func (v *Cmb) Query(ctx context.Context, req *bo.OrderCreateReqBo) (reps *bo.OrderCreateRepBo, err error) { err = lock.NewMutex(v.rdb.Rdb, time.Second*30).Lock(ctx, fmt.Sprintf("cmb_order_%s", req.OutBizNo), func(ctx context.Context) error { @@ -73,6 +73,6 @@ func (v *Cmb) CmbQuery(ctx context.Context, req *bo.OrderCreateReqBo) (reps *bo. return } -func (v *Cmb) CmbNotify(ctx context.Context, order *bo.OrderBo) (err error) { +func (v *Cmb) Notify(ctx context.Context, order *bo.OrderBo) (err error) { return } diff --git a/internal/service/base.go b/internal/service/base.go deleted file mode 100644 index d890fcc..0000000 --- a/internal/service/base.go +++ /dev/null @@ -1,34 +0,0 @@ -package service - -import ( - "github.com/go-kratos/kratos/v2/transport/http" - http2 "net/http" -) - -// BaseService order 公共方法 -type BaseService struct { -} - -type BaseResponse struct { - Code int `json:"code"` - Data interface{} `json:"data"` - Message string `json:"message"` -} - -// ResponseOK 返回 json 成功 -func (b *BaseService) ResponseOK(ctx http.Context, data interface{}) error { - return ctx.JSON(http2.StatusOK, &BaseResponse{ - Code: http2.StatusOK, - Data: data, - Message: "", - }) -} - -// ResponseError 返回 json 错误 -func (b *BaseService) ResponseError(ctx http.Context, error string) error { - return ctx.JSON(http2.StatusOK, &BaseResponse{ - Code: 4001, - Data: nil, - Message: error, - }) -} diff --git a/internal/service/cmb.go b/internal/service/cmb.go index 6b4ac9b..83c6041 100644 --- a/internal/service/cmb.go +++ b/internal/service/cmb.go @@ -27,7 +27,7 @@ func (s *VoucherService) CmbOrder(ctx http.Context) error { AccountType: vo.OrderAccountTypeOpenId, } - boRep, err := s.VoucherBiz.CmbOrder(ctx, boReq) + boRep, err := s.Cmb.Order(ctx, boReq) if err != nil { return err } diff --git a/internal/service/voucher.go b/internal/service/voucher.go index cf0bcc2..24277d3 100644 --- a/internal/service/voucher.go +++ b/internal/service/voucher.go @@ -2,20 +2,24 @@ package service import ( "voucher/internal/biz" + "voucher/internal/biz/cmb" "voucher/internal/conf" ) type VoucherService struct { bc *conf.Bootstrap VoucherBiz *biz.VoucherBiz + Cmb *cmb.Cmb } func NewVoucherService( bc *conf.Bootstrap, VoucherBiz *biz.VoucherBiz, + Cmb *cmb.Cmb, ) *VoucherService { return &VoucherService{ bc: bc, VoucherBiz: VoucherBiz, + Cmb: Cmb, } }