| 
									
										
										
										
											2024-10-06 07:02:30 +00:00
										 |  |  | package orderservicelogic | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2024-10-23 09:50:11 +00:00
										 |  |  | 	"app-cloudep-order-server/gen_result/pb/order" | 
					
						
							|  |  |  | 	"app-cloudep-order-server/internal/domain" | 
					
						
							|  |  |  | 	model "app-cloudep-order-server/internal/model/mongo" | 
					
						
							| 
									
										
										
										
											2024-10-06 07:02:30 +00:00
										 |  |  | 	"context" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-23 09:50:11 +00:00
										 |  |  | 	ers "code.30cm.net/digimon/library-go/errs" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-06 07:02:30 +00:00
										 |  |  | 	"app-cloudep-order-server/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), | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-23 09:50:11 +00:00
										 |  |  | // CancelOrderQuery 1.建單失敗 9.交易取消 10.交易異常
 | 
					
						
							|  |  |  | type CancelOrderQuery struct { | 
					
						
							|  |  |  | 	BusinessID string `json:"business_id" validate:"required"` | 
					
						
							|  |  |  | 	Status     int64  `json:"status" validate:"required,oneof=1 9 10"` | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-06 07:02:30 +00:00
										 |  |  | // CancelOrder 取消訂單
 | 
					
						
							| 
									
										
										
										
											2024-10-23 09:50:11 +00:00
										 |  |  | func (l *CancelOrderLogic) CancelOrder(in *order.CancelOrderReq) (*order.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.OrderModel.UpdateStatus(l.ctx, | 
					
						
							|  |  |  | 		model.UpdateStatusReq{ | 
					
						
							|  |  |  | 			BusinessID: in.GetBusinessId(), | 
					
						
							|  |  |  | 			Status:     in.GetStatus(), | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		// 錯誤代碼 06-021-02
 | 
					
						
							|  |  |  | 		e := domain.CommentErrorL( | 
					
						
							|  |  |  | 			domain.CancelOrderErrorCode, | 
					
						
							|  |  |  | 			logx.WithContext(l.ctx), | 
					
						
							|  |  |  | 			[]logx.LogField{ | 
					
						
							|  |  |  | 				{Key: "req", Value: in}, | 
					
						
							|  |  |  | 				{Key: "func", Value: "OrderModel.UpdateStatus"}, | 
					
						
							|  |  |  | 				{Key: "err", Value: err}, | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			"failed to update order status:").Wrap(err) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return nil, e | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-10-06 07:02:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-23 09:50:11 +00:00
										 |  |  | 	return &order.OKResp{}, nil | 
					
						
							| 
									
										
										
										
											2024-10-06 07:02:30 +00:00
										 |  |  | } |