打包费参数有效性检查

This commit is contained in:
gazebo
2019-12-30 18:35:49 +08:00
parent 3ee2e72a5e
commit d3a02ef958
3 changed files with 48 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ package cms
import (
"fmt"
"reflect"
"strconv"
"strings"
"time"
@@ -193,6 +194,20 @@ func SendMsg2Somebody(ctx *jxcontext.Context, mobileNum, verifyCode, msgType, ms
return err
}
func checkSysConfig(key, value string) (err error) {
if limit := model.SysConfigLimitMap[key]; limit != nil {
if limit.ValueType == reflect.Int {
int64Value, err2 := strconv.ParseInt(value, 10, 64)
if err = err2; err == nil {
if int64Value < limit.MinValue || int64Value > limit.MaxValue {
err = fmt.Errorf("配置%s,值%s超范围[%d,%d]", key, value, limit.MinValue, limit.MaxValue)
}
}
}
}
return err
}
func checkConfig(opFlag int, configType, key, value string) (err error) {
switch configType {
case model.ConfigTypePricePack:
@@ -228,8 +243,10 @@ func checkConfig(opFlag int, configType, key, value string) (err error) {
}
case model.ConfigTypeRole:
case model.ConfigTypeSys:
if opFlag&(model.SyncFlagNewMask|model.SyncFlagDeletedMask) != 0 {
err = fmt.Errorf("系统参数只支持修改,不支持自由添加")
if opFlag&( /*model.SyncFlagNewMask|*/ model.SyncFlagDeletedMask) != 0 {
err = fmt.Errorf("系统参数只支持修改或添加,不支持删除")
} else {
err = checkSysConfig(key, value)
}
default:
err = fmt.Errorf("当前只支持配置:%s, 传入的配置类型:%s", utils.Format4Output(model.ConfigTypeName, true), configType)

View File

@@ -236,7 +236,9 @@ func formalizeStoreSkuList(inSkuList []*dao.StoreSkuSyncInfo) []*dao.StoreSkuSyn
if len(inSkuList) > 0 {
boxFee := getSkuBoxFee(inSkuList[0].VendorID)
for _, skuItem := range inSkuList {
skuItem.BoxFee = boxFee
if skuItem.VendorPrice > skuItem.BoxFee {
skuItem.BoxFee = boxFee
}
skuItem.MergedStatus = jxutils.MergeSkuStatus(skuItem.Status, skuItem.StoreSkuStatus)
skuItem.SkuName = jxutils.ComposeSkuNameSync(skuItem.Prefix, skuItem.Name, skuItem.Comment, skuItem.Unit, skuItem.SpecQuality, skuItem.SpecUnit, 0, skuItem.ExPrefix, skuItem.ExPrefixBegin, skuItem.ExPrefixEnd)
}

View File

@@ -1,5 +1,7 @@
package model
import "reflect"
const (
ConfigTypeSys = "Sys"
ConfigTypePricePack = "PricePack"
@@ -15,6 +17,12 @@ const (
ConfigSysMtwmSkuBoxFee = "MtwmSkuBoxFee" // 美团外卖单商品打包费
)
type SysConfigLimit struct {
ValueType reflect.Kind
MinValue int64
MaxValue int64
}
var (
ConfigTypeName = map[string]string{
ConfigTypeSys: "系统",
@@ -23,6 +31,24 @@ var (
ConfigTypeBank: "银行",
ConfigTypeRole: "角色",
}
SysConfigLimitMap = map[string]*SysConfigLimit{
ConfigSysEbaiBoxFee: &SysConfigLimit{
ValueType: reflect.Int,
MinValue: 0,
MaxValue: 500,
},
ConfigSysMtwmBoxFee: &SysConfigLimit{
ValueType: reflect.Int,
MinValue: 0,
MaxValue: 500,
},
ConfigSysMtwmSkuBoxFee: &SysConfigLimit{
ValueType: reflect.Int,
MinValue: 0,
MaxValue: 50,
},
}
)
type NewConfig struct {