正在显示
1 个修改的文件
包含
32 行增加
和
2 行删除
| @@ -3,8 +3,10 @@ package controllers | @@ -3,8 +3,10 @@ package controllers | ||
| 3 | import ( | 3 | import ( |
| 4 | "errors" | 4 | "errors" |
| 5 | "fmt" | 5 | "fmt" |
| 6 | + "regexp" | ||
| 6 | "strconv" | 7 | "strconv" |
| 7 | "time" | 8 | "time" |
| 9 | + "unicode/utf8" | ||
| 8 | 10 | ||
| 9 | "github.com/astaxie/beego/logs" | 11 | "github.com/astaxie/beego/logs" |
| 10 | orderCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/command" | 12 | orderCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/command" |
| @@ -192,6 +194,9 @@ func (postData postPurposeOrderDetail) Valid() error { | @@ -192,6 +194,9 @@ func (postData postPurposeOrderDetail) Valid() error { | ||
| 192 | if len(postData.OrderDist) == 0 { | 194 | if len(postData.OrderDist) == 0 { |
| 193 | return lib.ThrowError(lib.ARG_ERROR, "订单区域必填") | 195 | return lib.ThrowError(lib.ARG_ERROR, "订单区域必填") |
| 194 | } | 196 | } |
| 197 | + if len(postData.Product) > 0 { | ||
| 198 | + return lib.ThrowError(lib.ARG_ERROR, "货品列表必填") | ||
| 199 | + } | ||
| 195 | if len(postData.Product) > 50 { | 200 | if len(postData.Product) > 50 { |
| 196 | return lib.ThrowError(lib.ARG_ERROR, "货品列表最多50项") | 201 | return lib.ThrowError(lib.ARG_ERROR, "货品列表最多50项") |
| 197 | } | 202 | } |
| @@ -213,9 +218,29 @@ type postOrderGood struct { | @@ -213,9 +218,29 @@ type postOrderGood struct { | ||
| 213 | } | 218 | } |
| 214 | 219 | ||
| 215 | func (postData postOrderGood) Valid() error { | 220 | func (postData postOrderGood) Valid() error { |
| 216 | - if len(postData.ProductName) == 0 { | 221 | + lenProductName := utf8.RuneCountInString(postData.ProductName) |
| 222 | + if lenProductName == 0 { | ||
| 217 | return lib.ThrowError(lib.ARG_ERROR, "商品名称必填") | 223 | return lib.ThrowError(lib.ARG_ERROR, "商品名称必填") |
| 218 | } | 224 | } |
| 225 | + if lenProductName >= 50 { | ||
| 226 | + return lib.ThrowError(lib.ARG_ERROR, "商品名称最多50位") | ||
| 227 | + } | ||
| 228 | + if postData.OrderNum >= 1e16 { | ||
| 229 | + return lib.ThrowError(lib.ARG_ERROR, "商品数量最多16位") | ||
| 230 | + } | ||
| 231 | + if postData.Univalence >= 1e16 { | ||
| 232 | + return lib.ThrowError(lib.ARG_ERROR, "商品单价最多16位") | ||
| 233 | + } | ||
| 234 | + if postData.PartnerRatio > 100 { | ||
| 235 | + return lib.ThrowError(lib.ARG_ERROR, "合伙人分红比例超额") | ||
| 236 | + } | ||
| 237 | + partnerRatio := fmt.Sprint(postData.PartnerRatio) | ||
| 238 | + regexpStr := `^(100|[1-9]\d|\d)(.\d{1,2})$` | ||
| 239 | + ok := regexp.MustCompile(regexpStr).MatchString(partnerRatio) | ||
| 240 | + if !ok { | ||
| 241 | + return lib.ThrowError(lib.ARG_ERROR, "合伙人分红比例精确到小数点2位") | ||
| 242 | + } | ||
| 243 | + | ||
| 219 | return nil | 244 | return nil |
| 220 | } | 245 | } |
| 221 | 246 | ||
| @@ -308,9 +333,14 @@ type postOrderPurposeDelivery struct { | @@ -308,9 +333,14 @@ type postOrderPurposeDelivery struct { | ||
| 308 | } | 333 | } |
| 309 | 334 | ||
| 310 | func (postData postOrderPurposeDelivery) Valid() error { | 335 | func (postData postOrderPurposeDelivery) Valid() error { |
| 311 | - if len(postData.ShipmentsId) == 0 { | 336 | + lenShipmentsId := utf8.RuneCountInString(postData.ShipmentsId) |
| 337 | + if lenShipmentsId == 0 { | ||
| 312 | return lib.ThrowError(lib.ARG_ERROR, "发货单号必填") | 338 | return lib.ThrowError(lib.ARG_ERROR, "发货单号必填") |
| 313 | } | 339 | } |
| 340 | + if lenShipmentsId > 50 { | ||
| 341 | + return lib.ThrowError(lib.ARG_ERROR, "发货单号最多50位") | ||
| 342 | + } | ||
| 343 | + | ||
| 314 | for i := range postData.ProductDetail { | 344 | for i := range postData.ProductDetail { |
| 315 | if err := postData.ProductDetail[i].Valid(); err != nil { | 345 | if err := postData.ProductDetail[i].Valid(); err != nil { |
| 316 | return err | 346 | return err |
-
请 注册 或 登录 后发表评论