create_order.go 1.1 KB
package command

import (
	"fmt"

	"github.com/beego/beego/v2/core/validation"
)

type CreateOrderCommand struct {
	// 订单编号
	OrderNo string `json:"orderNo" valid:"Required"`
	// 公司Id
	CompanyId int64 `json:"companyId" valid:"Required"`
	// 买家名称
	BuyerName string `json:"buyerName,omitempty"`
	// 联系信息
	ContactInfo string `json:"contactInfo,omitempty"`
	// 发货地址
	ShippingAddress string `json:"shippingAddress,omitempty"`
	// 订单商品总数
	OrderNum int64 `json:"orderNum" valid:"Required"`
	// 订单总价
	TotalPrice float64 `json:"totalPrice" valid:"Required"`
}

func (createOrderCommand *CreateOrderCommand) Valid(validation *validation.Validation) {
	validation.SetError("CustomValid", "未实现的自定义认证")
}

func (createOrderCommand *CreateOrderCommand) ValidateCommand() error {
	valid := validation.Validation{}
	b, err := valid.Valid(createOrderCommand)
	if err != nil {
		return err
	}
	if !b {
		for _, validErr := range valid.Errors {
			return fmt.Errorf("%s  %s", validErr.Key, validErr.Message)
		}
	}
	return nil
}