From d3a02ef958e603593abce503b0418a9847671d6c Mon Sep 17 00:00:00 2001 From: gazebo Date: Mon, 30 Dec 2019 18:35:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=93=E5=8C=85=E8=B4=B9=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E6=9C=89=E6=95=88=E6=80=A7=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/cms.go | 21 +++++++++++++++++++-- business/jxstore/cms/sync_store_sku.go | 4 +++- business/model/new_config.go | 26 ++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/business/jxstore/cms/cms.go b/business/jxstore/cms/cms.go index 68258f6cb..3908dba05 100644 --- a/business/jxstore/cms/cms.go +++ b/business/jxstore/cms/cms.go @@ -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) diff --git a/business/jxstore/cms/sync_store_sku.go b/business/jxstore/cms/sync_store_sku.go index 155767a77..9e88aa013 100644 --- a/business/jxstore/cms/sync_store_sku.go +++ b/business/jxstore/cms/sync_store_sku.go @@ -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) } diff --git a/business/model/new_config.go b/business/model/new_config.go index a3805bac0..70fbf353e 100644 --- a/business/model/new_config.go +++ b/business/model/new_config.go @@ -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 {