作者 tangxvhui

更新:新增 接受订单数据时进行参数检验

... ... @@ -3,8 +3,10 @@ package controllers
import (
"errors"
"fmt"
"regexp"
"strconv"
"time"
"unicode/utf8"
"github.com/astaxie/beego/logs"
orderCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/command"
... ... @@ -192,6 +194,9 @@ func (postData postPurposeOrderDetail) Valid() error {
if len(postData.OrderDist) == 0 {
return lib.ThrowError(lib.ARG_ERROR, "订单区域必填")
}
if len(postData.Product) > 0 {
return lib.ThrowError(lib.ARG_ERROR, "货品列表必填")
}
if len(postData.Product) > 50 {
return lib.ThrowError(lib.ARG_ERROR, "货品列表最多50项")
}
... ... @@ -213,9 +218,29 @@ type postOrderGood struct {
}
func (postData postOrderGood) Valid() error {
if len(postData.ProductName) == 0 {
lenProductName := utf8.RuneCountInString(postData.ProductName)
if lenProductName == 0 {
return lib.ThrowError(lib.ARG_ERROR, "商品名称必填")
}
if lenProductName >= 50 {
return lib.ThrowError(lib.ARG_ERROR, "商品名称最多50位")
}
if postData.OrderNum >= 1e16 {
return lib.ThrowError(lib.ARG_ERROR, "商品数量最多16位")
}
if postData.Univalence >= 1e16 {
return lib.ThrowError(lib.ARG_ERROR, "商品单价最多16位")
}
if postData.PartnerRatio > 100 {
return lib.ThrowError(lib.ARG_ERROR, "合伙人分红比例超额")
}
partnerRatio := fmt.Sprint(postData.PartnerRatio)
regexpStr := `^(100|[1-9]\d|\d)(.\d{1,2})$`
ok := regexp.MustCompile(regexpStr).MatchString(partnerRatio)
if !ok {
return lib.ThrowError(lib.ARG_ERROR, "合伙人分红比例精确到小数点2位")
}
return nil
}
... ... @@ -308,9 +333,14 @@ type postOrderPurposeDelivery struct {
}
func (postData postOrderPurposeDelivery) Valid() error {
if len(postData.ShipmentsId) == 0 {
lenShipmentsId := utf8.RuneCountInString(postData.ShipmentsId)
if lenShipmentsId == 0 {
return lib.ThrowError(lib.ARG_ERROR, "发货单号必填")
}
if lenShipmentsId > 50 {
return lib.ThrowError(lib.ARG_ERROR, "发货单号最多50位")
}
for i := range postData.ProductDetail {
if err := postData.ProductDetail[i].Valid(); err != nil {
return err
... ...