create_order.go 1.6 KB
package command

import "errors"

//创建订单
type CreateOrderCommand struct {
	//订单类型
	OrderType int `json:"orderType"`
	//订单编号
	OrderCode string `json:"orderCode"`
	//交货编号
	DeliveryCode string `json:"deliveryCode"`
	//买家
	BuyerName string `json:"buyerName"`
	//订单区域信息
	OrderRegion string `json:"orderRegion"`
	//订单对应的合伙人
	PartnerId int64 `json:"partnerId"`
	//业务员抽成比例
	SalesmanBonusPercent float64 `json:"salesmanBonusPercent"`
	//货品
	Goods []OrderGoodData `json:"goods"`
	//公司id
	CompanyId int64 `json:"companyId"`
	//合伙人类型
	PartnerCategory int64 `json:"partner_category"`
	//行号-错误信息返回
	LineNumbers []int `json:"lineNumber"`
	//合伙人姓名
	PartnerName string `json:"partnerName"`
	//编号-错误信息返回
	Code string `json:"code"`
	//合伙人类型名称-错误信息返回
	PartnerCategoryName string `json:"partnerCategoryName"`
}

func (postData *CreateOrderCommand) Valid() error {
	if len(postData.OrderCode) == 0 {
		return errors.New("订单编号必填")
	}
	if len(postData.BuyerName) == 0 {
		return errors.New("买家信息必填")
	}
	if postData.PartnerId == 0 {
		return errors.New("合伙人信息必填")
	}
	if len(postData.OrderRegion) == 0 {
		return errors.New("订单区域必填")
	}
	if len(postData.Goods) == 0 {
		return errors.New("货品列表必填")
	}
	if len(postData.Goods) > 50 {
		return errors.New("货品列表最多50项")
	}
	for i := range postData.Goods {
		if err := postData.Goods[i].Valid(); err != nil {
			return err
		}
	}
	return nil
}