56 lines
1.4 KiB
Go
56 lines
1.4 KiB
Go
package orderservicelogic
|
|
|
|
import (
|
|
"app-cloudep-trade-service/internal/domain"
|
|
"app-cloudep-trade-service/internal/domain/usecase"
|
|
ers "code.30cm.net/digimon/library-go/errs"
|
|
"context"
|
|
|
|
"app-cloudep-trade-service/gen_result/pb/trade"
|
|
"app-cloudep-trade-service/internal/svc"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type CancelOrderLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewCancelOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CancelOrderLogic {
|
|
return &CancelOrderLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
// CancelOrderQuery 1.建單失敗 9.交易取消 10.交易異常
|
|
type CancelOrderQuery struct {
|
|
BusinessID string `json:"business_id" validate:"required"`
|
|
Status int64 `json:"status" validate:"required,oneof=1 9 10"`
|
|
}
|
|
|
|
// CancelOrder 取消訂單
|
|
func (l *CancelOrderLogic) CancelOrder(in *trade.CancelOrderReq) (*trade.OKResp, error) {
|
|
// 驗證資料
|
|
if err := l.svcCtx.Validate.ValidateAll(&CancelOrderQuery{
|
|
BusinessID: in.GetBusinessId(),
|
|
Status: in.GetStatus(),
|
|
}); err != nil {
|
|
// 錯誤代碼 06-011-00
|
|
return nil, ers.InvalidFormat(err.Error())
|
|
}
|
|
|
|
err := l.svcCtx.OrderUseCase.CancelOrder(l.ctx, usecase.CancelOrderQuery{
|
|
BusinessID: in.GetBusinessId(),
|
|
Status: domain.OrderStatus(in.GetStatus()),
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &trade.OKResp{}, nil
|
|
}
|