错误映射

This commit is contained in:
ziming 2026-03-13 15:55:41 +08:00
parent bbfc91da57
commit 81c53823af
2 changed files with 26 additions and 18 deletions

View File

@ -10,11 +10,11 @@ import (
"voucher/internal/biz/vo" "voucher/internal/biz/vo"
) )
func (this *VoucherBiz) CmbOrder(ctx context.Context, req *bo.OrderCreateReqBo) (*bo.OrderBo, error) { func (this *VoucherBiz) CmbOrder(ctx context.Context, req *bo.OrderCreateReqBo) (*bo.OrderBo, *bo.ProductBo, error) {
order, err3 := this.GetByOutBizNo(ctx, req) order, err3 := this.GetByOutBizNo(ctx, req)
if err3 != nil { if err3 != nil {
return nil, err3 return nil, nil, err3
} }
if order != nil { if order != nil {
@ -22,32 +22,32 @@ func (this *VoucherBiz) CmbOrder(ctx context.Context, req *bo.OrderCreateReqBo)
if order.Status.IsFail() || order.Status.IsIng() { if order.Status.IsFail() || order.Status.IsIng() {
if err4 := this.orderRetry(ctx, order); err4 != nil { if err4 := this.orderRetry(ctx, order); err4 != nil {
return nil, err4 return order, nil, err4
} }
} }
return order, nil return order, nil, nil
} }
product, err3 := this.ProductRepo.GetByProductNo(ctx, req.ProductNo) product, err3 := this.ProductRepo.GetByProductNo(ctx, req.ProductNo)
if err3 != nil { if err3 != nil {
return nil, err3 return nil, product, err3
} }
nowTime := time.Now() nowTime := time.Now()
if nowTime.Before(*product.StartTime) { if nowTime.Before(*product.StartTime) {
return nil, businesserr.BatchNotStartedError return nil, product, businesserr.BatchNotStartedError
} }
if nowTime.After(*product.EndTime) { if nowTime.After(*product.EndTime) {
return nil, businesserr.BatchEndedError return nil, product, businesserr.BatchEndedError
} }
order, err3 = this.order(ctx, req, product) order, err3 = this.order(ctx, req, product)
if err3 != nil { if err3 != nil {
return nil, err3 return nil, product, err3
} }
return order, nil return order, product, nil
} }
func (this *VoucherBiz) order(ctx context.Context, req *bo.OrderCreateReqBo, product *bo.ProductBo) (*bo.OrderBo, error) { func (this *VoucherBiz) order(ctx context.Context, req *bo.OrderCreateReqBo, product *bo.ProductBo) (*bo.OrderBo, error) {

View File

@ -11,20 +11,20 @@ import (
func (c *CmbService) Order(ctx context.Context, request *v1.CmbRequest) (*v1.CmbReply, error) { func (c *CmbService) Order(ctx context.Context, request *v1.CmbRequest) (*v1.CmbReply, error) {
order, err := c.order(ctx, request) order, product, err := c.order(ctx, request)
if err != nil { if err != nil {
return c.OrderFail(ctx, order, err) return c.OrderFail(ctx, order, product, err)
} }
return c.OrderSuccess(ctx, order.OrderNo) return c.OrderSuccess(ctx, order.OrderNo)
} }
func (c *CmbService) order(ctx context.Context, request *v1.CmbRequest) (*bo.OrderBo, error) { func (c *CmbService) order(ctx context.Context, request *v1.CmbRequest) (*bo.OrderBo, *bo.ProductBo, error) {
bizContent, err := c.CmbMixRepo.OrderVerify(ctx, request) bizContent, err := c.CmbMixRepo.OrderVerify(ctx, request)
if err != nil { if err != nil {
return nil, err return nil, nil, err
} }
boReq := &bo.OrderCreateReqBo{ boReq := &bo.OrderCreateReqBo{
@ -38,12 +38,12 @@ func (c *CmbService) order(ctx context.Context, request *v1.CmbRequest) (*bo.Ord
NotifyUrl: c.bc.Cmb.NotifyUrl, NotifyUrl: c.bc.Cmb.NotifyUrl,
} }
order, err := c.VoucherBiz.CmbOrder(ctx, boReq) order, product, err := c.VoucherBiz.CmbOrder(ctx, boReq)
if err != nil { if err != nil {
return nil, err return nil, nil, err
} }
return order, nil return order, product, nil
} }
func (c *CmbService) OrderSuccess(ctx context.Context, orderNo string) (*v1.CmbReply, error) { func (c *CmbService) OrderSuccess(ctx context.Context, orderNo string) (*v1.CmbReply, error) {
@ -59,13 +59,21 @@ func (c *CmbService) OrderSuccess(ctx context.Context, orderNo string) (*v1.CmbR
return c.GetResponse(ctx, replyBizContent) return c.GetResponse(ctx, replyBizContent)
} }
func (c *CmbService) OrderFail(ctx context.Context, order *bo.OrderBo, err error) (*v1.CmbReply, error) { func (c *CmbService) OrderFail(ctx context.Context, order *bo.OrderBo, product *bo.ProductBo, err error) (*v1.CmbReply, error) {
bizReply := &v1.CmbOrderReply{} bizReply := &v1.CmbOrderReply{}
if e, ok := err.(*businesserr.BusinessErr); ok { if e, ok := err.(*businesserr.BusinessErr); ok {
if order.ActivityId != "" { isMultiErr := false
if product != nil && product.ActivityId != "" {
isMultiErr = true
} else if order != nil && order.ActivityId != "" {
isMultiErr = true
}
if isMultiErr {
cmbAPIError := e.HandleMULTIThirdErrCode() cmbAPIError := e.HandleMULTIThirdErrCode()
bizReply = &v1.CmbOrderReply{ bizReply = &v1.CmbOrderReply{
RespCode: vo.CmbResponseStatusFail.GetValue(), RespCode: vo.CmbResponseStatusFail.GetValue(),