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

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
}

View File

@@ -791,6 +791,12 @@ func UpdateStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendor
return 0, err
}
valid := dao.StrictMakeMapByStructObject(payload, storeMap, userName)
if valid["pricePercentagePack"] != nil {
_, err2 := dao.QueryConfigs(db, model.ConfigTypePricePack, utils.Interface2String(valid["pricePercentagePack"]), "")
if err = err2; err != nil {
return 0, err
}
}
if vendorStoreID := utils.Interface2String(valid["vendorStoreID"]); vendorStoreID != "" {
vendorStoreInfo, err2 := storeHandler.ReadStore(vendorStoreID)
if err = err2; err == nil {
@@ -817,7 +823,7 @@ func UpdateStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendor
})
}
if err == nil && num > 0 {
if valid["pricePercentage"] != nil {
if valid["pricePercentage"] != nil || valid["pricePercentagePack"] != nil {
storeSkuBind := &model.StoreSkuBind{}
if num, err = dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, storeSkuBind, nil, userName, map[string]interface{}{
model.FieldStoreID: storeID,
@@ -1127,7 +1133,7 @@ func composeDadaStoreName(storeDetail *dao.StoreDetail2) (storeName string) {
func ExportShopsHealthInfo(ctx *jxcontext.Context, vendorIDs, storeIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
db := dao.GetDB()
vendorID := model.VendorIDEBAI
storeMapList, err := dao.GetStoresMapList(db, []int{vendorID}, storeIDs, model.StoreStatusAll, model.StoreIsSyncYes)
storeMapList, err := dao.GetStoresMapList(db, []int{vendorID}, storeIDs, model.StoreStatusAll, model.StoreIsSyncYes, "")
if err != nil {
return "", err
}
@@ -1214,7 +1220,7 @@ func GetCorporationInfo(ctx *jxcontext.Context, licenceCode string) (corporation
func GetStoresVendorSnapshot(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorIDs, storeIDs []int) (vendorStoreSnapshotList []*model.VendorStoreSnapshot, err error) {
db := dao.GetDB()
storeMapList, err := dao.GetStoresMapList(db, vendorIDs, storeIDs, model.StoreStatusAll, model.StoreIsSyncYes)
storeMapList, err := dao.GetStoresMapList(db, vendorIDs, storeIDs, model.StoreStatusAll, model.StoreIsSyncYes, "")
if err != nil {
return nil, err
}
@@ -1256,7 +1262,7 @@ func getCurrentSnapshotAt(now time.Time) (snapshotAt time.Time) {
}
func updateVendorStoreStatusBySnapshot(db *dao.DaoDB, curSnapshotList []*model.VendorStoreSnapshot) (err error) {
storeMapList, err := dao.GetStoresMapList(db, nil, nil, model.StoreStatusAll, model.StoreIsSyncAll)
storeMapList, err := dao.GetStoresMapList(db, nil, nil, model.StoreStatusAll, model.StoreIsSyncAll, "")
if err != nil {
return err
}

View File

@@ -819,7 +819,7 @@ func GetStoresSkusOld(ctx *jxcontext.Context, storeIDs, skuIDs []int, isFocus bo
}
func getValidStoreVendorMap(db *dao.DaoDB, storeIDs []int) (realVendorMap map[int]int, err error) {
storeMapList, err := dao.GetStoresMapList(db, nil, storeIDs, model.StoreStatusAll, model.StoreIsSyncYes)
storeMapList, err := dao.GetStoresMapList(db, nil, storeIDs, model.StoreStatusAll, model.StoreIsSyncYes, "")
if err != nil {
return nil, err
}
@@ -1968,19 +1968,22 @@ func RefreshStoresSkuByVendor(ctx *jxcontext.Context, storeIDs []int, vendorID i
return "", fmt.Errorf("此功能当前只支持京东到家平台")
}
db := dao.GetDB()
storeMapList, err := dao.GetStoresMapList(db, nil, storeIDs, model.StoreStatusAll, model.StoreIsSyncAll)
storeMapList, err := dao.GetStoresMapList(db, nil, storeIDs, model.StoreStatusAll, model.StoreIsSyncAll, "")
if err != nil {
return "", err
}
if len(storeMapList) != len(storeIDs) {
return "", fmt.Errorf("门店绑定信息不匹配,请确定门店绑定且只绑定了京东平台")
}
storeMap := make(map[int]*model.StoreMap)
storeMap := make(map[int]*dao.StoreDetail)
for _, v := range storeMapList {
if v.VendorID != vendorID {
return "", fmt.Errorf("门店%d绑定的不是京东", v.StoreID)
}
storeMap[v.StoreID] = v
storeMap[v.StoreID], err = dao.GetStoreDetail(db, v.StoreID, v.VendorID)
if err != nil {
return "", err
}
}
handler := partner.GetPurchasePlatformFromVendorID(vendorID)

View File

@@ -541,7 +541,7 @@ func (v *VendorSync) PruneMissingStoreSkus(ctx *jxcontext.Context, vendorIDs []i
func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, db *dao.DaoDB, taskName string, isAsync, isManageIt bool, vendorIDs []int, storeIDs []int, handler tasksch.WorkFunc, isContinueWhenError bool) (task tasksch.ITask, hint string, err error) {
var storeMapList []*model.StoreMap
if storeMapList, err = dao.GetStoresMapList(db, vendorIDs, storeIDs, model.StoreStatusAll, model.StoreIsSyncYes); err != nil {
if storeMapList, err = dao.GetStoresMapList(db, vendorIDs, storeIDs, model.StoreStatusAll, model.StoreIsSyncYes, ""); err != nil {
return nil, "", err
}
if len(storeMapList) == 0 {