- 平台门店调价价格包实现初始版本

This commit is contained in:
gazebo
2019-07-16 11:36:28 +08:00
parent bdee4269d5
commit f133ccb290
13 changed files with 292 additions and 22 deletions

View File

@@ -1,7 +1,9 @@
package cms
import (
"fmt"
"strconv"
"strings"
"time"
"git.rosy.net.cn/jx-callback/business/jxutils/msg"
@@ -186,3 +188,96 @@ func SendMsg2Somebody(ctx *jxcontext.Context, msgType, msgContent string) (err e
}
return err
}
func checkConfig(configType, value string) (err error) {
switch configType {
case model.ConfigTypePricePack:
if value != "" {
pricePack := dao.PricePercentagePack2Obj(value)
if pricePack == nil {
err = fmt.Errorf("配置:%s不合法", value)
}
}
default:
err = fmt.Errorf("当前只支持价格包配置:%s", model.ConfigTypePricePack)
}
return
}
func AddConfig(ctx *jxcontext.Context, key, configType, value string) (err error) {
if err = checkConfig(configType, value); err != nil {
return err
}
db := dao.GetDB()
conf := &model.NewConfig{
Key: key,
Type: configType,
Value: value,
}
dao.WrapAddIDCULDEntity(conf, ctx.GetUserName())
return dao.CreateEntity(db, conf)
}
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]))
}
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,
})
return err
}
func UpdateConfig(ctx *jxcontext.Context, key, configType, value string) (err error) {
if err = checkConfig(configType, value); err != nil {
return err
}
db := dao.GetDB()
configList, err := dao.QueryConfigs(db, key, configType, "")
if err != nil {
return err
}
storeMapList, err := dao.GetStoresMapList(db, nil, nil, model.StoreStatusAll, model.StoreIsSyncYes, key)
if err != nil {
return err
}
dao.Begin(db)
defer func() {
if r := recover(); r != nil || err != nil {
dao.Rollback(db)
if r != nil {
panic(r)
}
}
}()
if _, err = dao.UpdateEntityLogically(db, configList[0], map[string]interface{}{
"Value": value,
}, ctx.GetUserName(), nil); err != nil {
return err
}
for _, v := range storeMapList {
if _, err = dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, &model.StoreSkuBind{}, nil, ctx.GetUserName(), map[string]interface{}{
model.FieldStoreID: v.StoreID,
}, dao.GetSyncStatusStructField(model.VendorNames[v.VendorID]), model.SyncFlagPriceMask); err != nil {
return err
}
}
dao.Commit(db)
return err
}