+ConstrainPayPercentage

This commit is contained in:
gazebo
2019-12-04 18:17:44 +08:00
parent 4d3eb5d94c
commit 5cecffc501
3 changed files with 177 additions and 154 deletions

View File

@@ -15,6 +15,7 @@ import (
"git.rosy.net.cn/jx-callback/business/partner" "git.rosy.net.cn/jx-callback/business/partner"
"git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/baseapi/utils/errlist"
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin" "git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin"
"git.rosy.net.cn/jx-callback/business/jxutils" "git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
@@ -959,9 +960,7 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs
} }
scaleFactor := float64(1) scaleFactor := float64(1)
if isScale { if isScale {
if storeDetail.PayPercentage > 0 { scaleFactor = float64(jxutils.ConstrainPayPercentage(storeDetail.PayPercentage) / 100)
scaleFactor = float64(storeDetail.PayPercentage) / 100
}
} }
for _, skuBindInfo := range skuBindInfos { for _, skuBindInfo := range skuBindInfos {
// 关注且没有给价时需要尝试从store_sku_bind中得到已有的单价 // 关注且没有给价时需要尝试从store_sku_bind中得到已有的单价
@@ -1270,7 +1269,7 @@ func UpdateStoresSkusSale(ctx *jxcontext.Context, storeIDs []int, skuBindSkuInfo
return hint, err return hint, err
} }
func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode string, isScale bool, params map[string]interface{}, userName string) (num int64, err error) { func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID int, toStoreIDs []int, copyMode string, isScale bool, params map[string]interface{}, userName string) (num int64, err error) {
if copyMode != CopyStoreSkuModeFresh && copyMode != CopyStoreSkuModeUpdate && copyMode != CopyStoreSkuModeUpdatePrice { if copyMode != CopyStoreSkuModeFresh && copyMode != CopyStoreSkuModeUpdate && copyMode != CopyStoreSkuModeUpdatePrice {
return 0, fmt.Errorf("不支持的拷贝模式:%s", copyMode) return 0, fmt.Errorf("不支持的拷贝模式:%s", copyMode)
} }
@@ -1280,11 +1279,6 @@ func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode
if err != nil { if err != nil {
return 0, err return 0, err
} }
toStore, err := checkStoreExisting(db, toStoreID)
if err != nil {
return 0, err
}
sqlCatAndSku := "" sqlCatAndSku := ""
sqlCatAndSkuParams := make([]interface{}, 0) sqlCatAndSkuParams := make([]interface{}, 0)
if params["categoryIDs"] != nil { if params["categoryIDs"] != nil {
@@ -1311,7 +1305,13 @@ func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode
if params["pricePercentage"] != nil { if params["pricePercentage"] != nil {
pricePercentage = params["pricePercentage"].(int) pricePercentage = params["pricePercentage"].(int)
} }
errList := errlist.New()
for _, toStoreID := range toStoreIDs {
toStore, err := checkStoreExisting(db, toStoreID)
if err != nil {
errList.AddErr(err)
break
}
now := time.Now() now := time.Now()
if fromStoreID == toStoreID { if fromStoreID == toStoreID {
sql := ` sql := `
@@ -1346,13 +1346,18 @@ func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode
} }
sql += sqlCatAndSku sql += sqlCatAndSku
sqlParams = append(sqlParams, sqlCatAndSkuParams) sqlParams = append(sqlParams, sqlCatAndSkuParams)
num, err = dao.ExecuteSQL(db, sql, sqlParams) num2, err2 := dao.ExecuteSQL(db, sql, sqlParams)
return num, err if err2 != nil {
errList.AddErr(err2)
} else {
num += num2
}
break
} }
dao.Begin(db) dao.Begin(db)
defer func() { defer func() {
dao.Rollback(db)
if r := recover(); r != nil { if r := recover(); r != nil {
dao.Rollback(db)
panic(r) panic(r)
} }
}() }()
@@ -1396,10 +1401,14 @@ func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode
sqlDelete += sqlCatAndSku sqlDelete += sqlCatAndSku
sqlDeleteParams = append(sqlDeleteParams, sqlCatAndSkuParams) sqlDeleteParams = append(sqlDeleteParams, sqlCatAndSkuParams)
// globals.SugarLogger.Debug(sqlDelete) // globals.SugarLogger.Debug(sqlDelete)
if num, err = dao.ExecuteSQL(db, sqlDelete, sqlDeleteParams); err != nil { num2, err2 := dao.ExecuteSQL(db, sqlDelete, sqlDeleteParams)
return 0, err if err = err2; err != nil {
errList.AddErr(err)
dao.Rollback(db)
break
} }
globals.SugarLogger.Debugf("CopyStoreSkus trackInfo:%s num1:%d", ctx.GetTrackInfo(), num) num += num2
globals.SugarLogger.Debugf("CopyStoreSkus fromStoreID:%d, toStoreID:%d, trackInfo:%s num1:%d", fromStoreID, toStoreID, ctx.GetTrackInfo(), num2)
} }
isModifyStatus := 1 isModifyStatus := 1
syncStatus := model.SyncFlagStoreSkuOnlyMask syncStatus := model.SyncFlagStoreSkuOnlyMask
@@ -1409,14 +1418,8 @@ func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode
} }
scaleFactor := float64(1) scaleFactor := float64(1)
if isScale { if isScale {
fromPayPercentage := fromStore.PayPercentage fromPayPercentage := jxutils.ConstrainPayPercentage(fromStore.PayPercentage)
if fromPayPercentage <= 0 { toPayPercentage := jxutils.ConstrainPayPercentage(toStore.PayPercentage)
fromPayPercentage = 100
}
toPayPercentage := toStore.PayPercentage
if toPayPercentage <= 0 {
toPayPercentage = 100
}
scaleFactor = float64(fromPayPercentage) / float64(toPayPercentage) scaleFactor = float64(fromPayPercentage) / float64(toPayPercentage)
} }
// 处理toStore中与fromStore中都存在的 // 处理toStore中与fromStore中都存在的
@@ -1468,12 +1471,14 @@ func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode
sql += sqlCatAndSku sql += sqlCatAndSku
sqlParams = append(sqlParams, sqlCatAndSkuParams) sqlParams = append(sqlParams, sqlCatAndSkuParams)
// globals.SugarLogger.Debug(sql) // globals.SugarLogger.Debug(sql)
num, err = dao.ExecuteSQL(db, sql, sqlParams) num2, err2 := dao.ExecuteSQL(db, sql, sqlParams)
globals.SugarLogger.Debugf("CopyStoreSkus trackInfo:%s num2:%d", ctx.GetTrackInfo(), num) globals.SugarLogger.Debugf("CopyStoreSkus fromStoreID:%d, toStoreID:%d, trackInfo:%s num2:%d", fromStoreID, toStoreID, ctx.GetTrackInfo(), num2)
if err != nil { if err = err2; err != nil {
return 0, err errList.AddErr(err)
dao.Rollback(db)
break
} }
num += num2
// 添加toStore中不存在但fromStore存在的 // 添加toStore中不存在但fromStore存在的
sql = ` sql = `
INSERT INTO store_sku_bind(created_at, updated_at, last_operator, deleted_at, store_id, sku_id, sub_store_id, price, jx_price, unit_price, status, INSERT INTO store_sku_bind(created_at, updated_at, last_operator, deleted_at, store_id, sku_id, sub_store_id, price, jx_price, unit_price, status,
@@ -1517,13 +1522,17 @@ func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode
} }
sql += sqlCatAndSku + " AND t0.id IS NULL" sql += sqlCatAndSku + " AND t0.id IS NULL"
sqlParams = append(sqlParams, sqlCatAndSkuParams) sqlParams = append(sqlParams, sqlCatAndSkuParams)
num, err = dao.ExecuteSQL(db, sql, sqlParams) num2, err = dao.ExecuteSQL(db, sql, sqlParams)
if err != nil { if err != nil {
return 0, err errList.AddErr(err)
dao.Rollback(db)
break
} }
globals.SugarLogger.Debugf("CopyStoreSkus trackInfo:%s num3:%d", ctx.GetTrackInfo(), num) num += num2
globals.SugarLogger.Debugf("CopyStoreSkus fromStoreID:%d, toStoreID:%d, trackInfo:%s num3:%d", fromStoreID, toStoreID, ctx.GetTrackInfo(), num2)
dao.Commit(db) dao.Commit(db)
return num, err }
return num, errList.GetErrListAsOne()
} }
func shouldPendingStorePriceChange(ctx *jxcontext.Context, storeID int, skuBindInfo *StoreSkuBindInfo) (shouldPending bool, err error) { func shouldPendingStorePriceChange(ctx *jxcontext.Context, storeID int, skuBindInfo *StoreSkuBindInfo) (shouldPending bool, err error) {

View File

@@ -326,6 +326,13 @@ func CaculatePriceByPricePack(l model.PricePercentagePack, defPricePercentage, p
return CaculateSkuVendorPrice(price, pricePercentage, priceAdd) return CaculateSkuVendorPrice(price, pricePercentage, priceAdd)
} }
func ConstrainPayPercentage(payPerCentage int) int {
if payPerCentage <= 50 {
payPerCentage = 70
}
return payPerCentage
}
func IsSkuSpecial(specQuality float32, specUnit string) bool { func IsSkuSpecial(specQuality float32, specUnit string) bool {
return int(specQuality) == model.SpecialSpecQuality && (specUnit == model.SpecialSpecUnit || specUnit == model.SpecialSpecUnit2) return int(specQuality) == model.SpecialSpecQuality && (specUnit == model.SpecialSpecUnit || specUnit == model.SpecialSpecUnit2)
} }

View File

@@ -249,6 +249,7 @@ func (c *StoreSkuController) UpdateStoresSkusByBind() {
// @Param token header string true "认证token" // @Param token header string true "认证token"
// @Param fromStoreID formData int true "源门店ID" // @Param fromStoreID formData int true "源门店ID"
// @Param toStoreID formData int true "目标门店ID" // @Param toStoreID formData int true "目标门店ID"
// @Param toStoreIDs formData string false "目标门店ID列表"
// @Param copyMode formData string true "拷贝模式fresh:目标门店数据全部清除后拷贝update:确保指定的源数据全部拷贝,已有的忽略" // @Param copyMode formData string true "拷贝模式fresh:目标门店数据全部清除后拷贝update:确保指定的源数据全部拷贝,已有的忽略"
// @Param pricePercentage formData int false "价格调整百分比缺省为100%" // @Param pricePercentage formData int false "价格调整百分比缺省为100%"
// @Param categoryIDs formData string false "json数据skuName所属的类别[1,2,3]" // @Param categoryIDs formData string false "json数据skuName所属的类别[1,2,3]"
@@ -259,7 +260,13 @@ func (c *StoreSkuController) UpdateStoresSkusByBind() {
// @router /CopyStoreSkus [post] // @router /CopyStoreSkus [post]
func (c *StoreSkuController) CopyStoreSkus() { func (c *StoreSkuController) CopyStoreSkus() {
c.callCopyStoreSkus(func(params *tStoreSkuCopyStoreSkusParams) (retVal interface{}, errCode string, err error) { c.callCopyStoreSkus(func(params *tStoreSkuCopyStoreSkusParams) (retVal interface{}, errCode string, err error) {
retVal, err = cms.CopyStoreSkus(params.Ctx, params.FromStoreID, params.ToStoreID, params.CopyMode, params.IsScale, params.MapData, params.Ctx.GetUserName()) var toStoreIDs []int
if err = jxutils.Strings2Objs(params.ToStoreIDs, &toStoreIDs); err == nil {
if params.ToStoreID > 0 {
toStoreIDs = append(toStoreIDs, params.ToStoreID)
}
retVal, err = cms.CopyStoreSkus(params.Ctx, params.FromStoreID, toStoreIDs, params.CopyMode, params.IsScale, params.MapData, params.Ctx.GetUserName())
}
return retVal, "", err return retVal, "", err
}) })
} }