Files
servicebase/pkg/dto/request/BaseOrerIdRequest.go
2025-11-19 14:24:13 +08:00

154 lines
3.3 KiB
Go

package request
import (
"errors"
"gitea.ddegame.cn/open/servicebase/pkg/tools"
"github.com/shopspring/decimal"
)
type BaseOrderIdRequest struct {
BaseRequest
OrderId string
OrderCountComplete string // 实际完成的订单量(局)
}
// 参数合法性检验
func (request *BaseOrderIdRequest) CheckParameter() (err error) {
if len(request.OrderId) == 0 {
err = errors.New("OrderId不能为空")
return
}
return
}
type PayOrderIdRequest struct {
BaseRequest
OrderId string
BuyerUserId string
}
// 参数合法性检验
func (request *PayOrderIdRequest) CheckParameter() (err error) {
if len(request.OrderId) == 0 {
err = errors.New("OrderId不能为空")
return
}
return
}
type SellerOrderIdRequest struct {
BaseRequest
OrderId string
SellerUserId string
}
// 参数合法性检验
func (request *SellerOrderIdRequest) CheckParameter() (err error) {
if len(request.OrderId) == 0 {
err = errors.New("OrderId不能为空")
return
}
return
}
// 卖家提前完成订单
type BuyerEarlyFinishOrderRequest struct {
BaseOrderIdRequest
OrderCountComplete string // 实际完成得订单量
OrderAmountPaid string // 实际应支付的订单金额
}
// 参数合法性检验
func (request *BuyerEarlyFinishOrderRequest) CheckParameter() (err error) {
if len(request.OrderId) == 0 {
err = errors.New("OrderId不能为空")
return
}
return
}
type FreeOfChargeOrderRequest struct {
BaseRequest
OrderId string
ChangeCount string // 完成单数
}
// 参数合法性检验
func (request *FreeOfChargeOrderRequest) CheckParameter() (err error) {
if len(request.OrderId) == 0 {
err = errors.New("OrderId不能为空")
return
}
if len(request.ChangeCount) == 0 {
err = errors.New("完成单数不能为空")
return
}
var count decimal.Decimal
if count, err = decimal.NewFromString(request.ChangeCount); err != nil {
err = errors.New("完成单数不能为非数字")
return
}
if !tools.IsHalfMultiple(count) {
err = errors.New("完成单数必须为0.5的倍数")
return
}
if count.LessThanOrEqual(decimal.NewFromInt(0)) {
err = errors.New("完成单数不能小于等于零")
return
}
return
}
type ReduceOrderRequest struct {
BaseRequest
OrderId string
ChangeCount string // 完成单数
}
// 参数合法性检验
func (request *ReduceOrderRequest) CheckParameter() (err error) {
if len(request.OrderId) == 0 {
err = errors.New("OrderId不能为空")
return
}
if len(request.ChangeCount) == 0 {
err = errors.New("减少单数不能为空")
return
}
var count decimal.Decimal
if count, err = decimal.NewFromString(request.ChangeCount); err != nil {
err = errors.New("减少数不能为非数字")
return
}
if !tools.IsHalfMultiple(count) {
err = errors.New("减少单数必须为0.5的倍数")
return
}
if count.LessThanOrEqual(decimal.NewFromInt(0)) {
err = errors.New("减少单数不能小于等于零")
return
}
return
}
// 卖家提前完成订单
type SellerFinishOrderRequest struct {
BaseOrderIdRequest
OrderCountComplete string // 实际完成的订单量(局)
}
// 参数合法性检验
func (request *SellerFinishOrderRequest) CheckParameter() (err error) {
if len(request.OrderId) == 0 {
err = errors.New("OrderId不能为空")
return
}
if len(request.OrderCountComplete) == 0 {
err = errors.New("OrderId不能为空")
return
}
return
}