From 7f6ec1b9dec0b803e8a198e674a729ce07c33c76 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 25 Jul 2019 11:46:32 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E9=85=8D=E7=BD=AE=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=93=B6=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/cms.go | 46 +++++++++++++++++++++++------------- business/model/new_config.go | 10 ++++++++ controllers/cms.go | 3 +-- 3 files changed, 41 insertions(+), 18 deletions(-) diff --git a/business/jxstore/cms/cms.go b/business/jxstore/cms/cms.go index 021ae5a05..998189002 100644 --- a/business/jxstore/cms/cms.go +++ b/business/jxstore/cms/cms.go @@ -83,6 +83,7 @@ func InitServiceInfo(version string, buildTime time.Time, gitCommit string) { "actStatusName": model.ActStatusName, "actCreateTypeName": model.ActCreateTypeName, "storeAuditStatusName": model.StoreAuditStatusName, + "configTypeList": model.ConfigTypeList, }, } Init() @@ -205,10 +206,16 @@ func checkConfig(configType, value string) (err error) { err = fmt.Errorf("配置:%s不合法", value) } } + case model.ConfigTypeBank: + if value != "" { + if model.BankName[value] == "" { + err = fmt.Errorf("些银行代码:%s不支持,请联系开发", value) + } + } default: - err = fmt.Errorf("当前只支持价格包配置:%s", model.ConfigTypePricePack) + err = fmt.Errorf("当前只支持配置:%s, 传入的配置类型:%s", utils.Format4Output(model.ConfigTypeList, true), configType) } - return + return err } func AddConfig(ctx *jxcontext.Context, key, configType, value string) (err error) { @@ -230,22 +237,25 @@ func DeleteConfig(ctx *jxcontext.Context, key, configType string) (err error) { if err = checkConfig(configType, ""); err != nil { return err } - db := dao.GetDB() - storeMapList, err := dao.GetStoresMapList(db, nil, nil, model.StoreStatusAll, model.StoreIsSyncYes, key) - if err != nil { - return err - } - if len(storeMapList) > 0 { - var storeInfo []string - for _, v := range storeMapList { - storeInfo = append(storeInfo, fmt.Sprintf("门店:%d, 平台:%s", v.StoreID, model.VendorChineseNames[v.VendorID])) + switch configType { + case model.ConfigTypePricePack: + db := dao.GetDB() + storeMapList, err := dao.GetStoresMapList(db, nil, nil, model.StoreStatusAll, model.StoreIsSyncYes, key) + if err != nil { + return err } - return fmt.Errorf("还有门店在使用价格包:%s,门店信息:%s", key, strings.Join(storeInfo, ",")) + if len(storeMapList) > 0 { + var storeInfo []string + for _, v := range storeMapList { + storeInfo = append(storeInfo, fmt.Sprintf("门店:%d, 平台:%s", v.StoreID, model.VendorChineseNames[v.VendorID])) + } + return fmt.Errorf("还有门店在使用价格包:%s,门店信息:%s", key, strings.Join(storeInfo, ",")) + } + _, err = dao.DeleteEntityLogically(db, &model.NewConfig{}, nil, ctx.GetUserName(), map[string]interface{}{ + "Key": key, + "Type": configType, + }) } - _, err = dao.DeleteEntityLogically(db, &model.NewConfig{}, nil, ctx.GetUserName(), map[string]interface{}{ - "Key": key, - "Type": configType, - }) return err } @@ -291,3 +301,7 @@ func UpdateConfig(ctx *jxcontext.Context, key, configType, value string) (err er dao.Commit(db) return err } + +func QueryConfigs(key, configType, keyword string) (configList []*model.NewConfig, err error) { + return dao.QueryConfigs(dao.GetDB(), key, configType, keyword) +} diff --git a/business/model/new_config.go b/business/model/new_config.go index 1fe554350..663664d48 100644 --- a/business/model/new_config.go +++ b/business/model/new_config.go @@ -3,6 +3,15 @@ package model const ( ConfigTypeSys = "Sys" ConfigTypePricePack = "PricePack" + ConfigTypeBank = "Bank" +) + +var ( + ConfigTypeList = []string{ + ConfigTypeSys, + ConfigTypePricePack, + ConfigTypeBank, + } ) type NewConfig struct { @@ -16,5 +25,6 @@ type NewConfig struct { func (*NewConfig) TableUnique() [][]string { return [][]string{ []string{"Key", "Type", "DeletedAt"}, + []string{"Type", "Key", "DeletedAt"}, } } diff --git a/controllers/cms.go b/controllers/cms.go index 59af6672d..0df74e736 100644 --- a/controllers/cms.go +++ b/controllers/cms.go @@ -6,7 +6,6 @@ import ( "git.rosy.net.cn/jx-callback/business/jxstore/cms" "git.rosy.net.cn/jx-callback/business/jxutils" "git.rosy.net.cn/jx-callback/business/jxutils/configindb" - "git.rosy.net.cn/jx-callback/business/model/dao" "git.rosy.net.cn/jx-callback/business/msghub" "git.rosy.net.cn/jx-callback/globals/api" "github.com/astaxie/beego" @@ -276,7 +275,7 @@ func (c *CmsController) UpdateConfig() { // @router /QueryConfigs [get] func (c *CmsController) QueryConfigs() { c.callQueryConfigs(func(params *tCmsQueryConfigsParams) (retVal interface{}, errCode string, err error) { - retVal, err = dao.QueryConfigs(dao.GetDB(), params.Key, params.Type, params.Keyword) + retVal, err = cms.QueryConfigs(params.Key, params.Type, params.Keyword) return retVal, "", err }) }