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"` CompanyId int64 `json:"companyId"` PartnerCategory int64 `json:"partner_category"` } 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 }