作者 陈志颖

Merge branch 'dev' of http://gitlab.fjmaimaimai.com/mmm-go/partnermg into v0.8.0-dev

package command
import "errors"
//创建订单
type CreateOrderCommand struct {
//订单类型
... ... @@ -22,3 +24,30 @@ type CreateOrderCommand struct {
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
}
... ...
package command
import (
"errors"
"fmt"
"regexp"
"unicode/utf8"
)
type OrderGoodData struct {
//货品id
Id int64 `json:"id"`
... ... @@ -14,3 +21,30 @@ type OrderGoodData struct {
//备注信息
Remark string `json:"remark"`
}
func (postData OrderGoodData) Valid() error {
lenProductName := utf8.RuneCountInString(postData.GoodName)
if lenProductName == 0 {
return errors.New("商品名称必填")
}
if lenProductName > 50 {
return errors.New("商品名称最多50位")
}
if postData.PlanGoodNumber >= 1e16 {
return errors.New("商品数量最多16位")
}
if postData.Price >= 1e16 {
return errors.New("商品单价最多16位")
}
if postData.PartnerBonusPercent > 100 {
return errors.New("合伙人分红比例超额")
}
partnerRatio := fmt.Sprint(postData.PartnerBonusPercent)
regexpStr := `^(100|[1-9]\d|\d)(.\d{1,2})?$`
ok := regexp.MustCompile(regexpStr).MatchString(partnerRatio)
if !ok {
return errors.New("合伙人分红比例精确到小数点2位")
}
return nil
}
... ...
... ... @@ -186,7 +186,9 @@ func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) (
transactionContext, _ = factory.CreateTransactionContext(nil)
err error
)
if err = cmd.Valid(); err != nil {
return nil, lib.ThrowError(lib.BUSINESS_ERROR, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -232,7 +234,15 @@ func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) (
} else if ok {
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "订单已存在")
}
//检查货品数据
var goodMap = map[string]int{}
for i := range cmd.Goods {
goodname := cmd.Goods[i].GoodName
if _, ok := goodMap[goodname]; ok {
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "订单中货品重复已存在")
}
goodMap[goodname] = 1
}
newOrder := &domain.OrderBase{
OrderType: cmd.OrderType, OrderCode: cmd.OrderCode,
DeliveryCode: cmd.DeliveryCode,
... ... @@ -435,6 +445,15 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand)
} else if ok {
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "订单已存在")
}
//检查货品数据
var goodMap = map[string]int{}
for i := range cmd.Goods {
goodname := cmd.Goods[i].GoodName
if _, ok := goodMap[goodname]; ok {
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "订单中货品重复已存在")
}
goodMap[goodname] = 1
}
//获取旧的订单中的商品
oldOrderGoods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{
OrderId: cmd.Id,
... ...