+ConstrainPayPercentage
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
|
||||
"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/jxutils"
|
||||
"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)
|
||||
if isScale {
|
||||
if storeDetail.PayPercentage > 0 {
|
||||
scaleFactor = float64(storeDetail.PayPercentage) / 100
|
||||
}
|
||||
scaleFactor = float64(jxutils.ConstrainPayPercentage(storeDetail.PayPercentage) / 100)
|
||||
}
|
||||
for _, skuBindInfo := range skuBindInfos {
|
||||
// 关注且没有给价时,需要尝试从store_sku_bind中得到已有的单价
|
||||
@@ -1270,7 +1269,7 @@ func UpdateStoresSkusSale(ctx *jxcontext.Context, storeIDs []int, skuBindSkuInfo
|
||||
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 {
|
||||
return 0, fmt.Errorf("不支持的拷贝模式:%s", copyMode)
|
||||
}
|
||||
@@ -1280,11 +1279,6 @@ func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
toStore, err := checkStoreExisting(db, toStoreID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
sqlCatAndSku := ""
|
||||
sqlCatAndSkuParams := make([]interface{}, 0)
|
||||
if params["categoryIDs"] != nil {
|
||||
@@ -1311,7 +1305,13 @@ func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode
|
||||
if params["pricePercentage"] != nil {
|
||||
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()
|
||||
if fromStoreID == toStoreID {
|
||||
sql := `
|
||||
@@ -1346,13 +1346,18 @@ func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode
|
||||
}
|
||||
sql += sqlCatAndSku
|
||||
sqlParams = append(sqlParams, sqlCatAndSkuParams)
|
||||
num, err = dao.ExecuteSQL(db, sql, sqlParams)
|
||||
return num, err
|
||||
num2, err2 := dao.ExecuteSQL(db, sql, sqlParams)
|
||||
if err2 != nil {
|
||||
errList.AddErr(err2)
|
||||
} else {
|
||||
num += num2
|
||||
}
|
||||
break
|
||||
}
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
dao.Rollback(db)
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
@@ -1396,10 +1401,14 @@ func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode
|
||||
sqlDelete += sqlCatAndSku
|
||||
sqlDeleteParams = append(sqlDeleteParams, sqlCatAndSkuParams)
|
||||
// globals.SugarLogger.Debug(sqlDelete)
|
||||
if num, err = dao.ExecuteSQL(db, sqlDelete, sqlDeleteParams); err != nil {
|
||||
return 0, err
|
||||
num2, err2 := dao.ExecuteSQL(db, sqlDelete, sqlDeleteParams)
|
||||
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
|
||||
syncStatus := model.SyncFlagStoreSkuOnlyMask
|
||||
@@ -1409,14 +1418,8 @@ func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode
|
||||
}
|
||||
scaleFactor := float64(1)
|
||||
if isScale {
|
||||
fromPayPercentage := fromStore.PayPercentage
|
||||
if fromPayPercentage <= 0 {
|
||||
fromPayPercentage = 100
|
||||
}
|
||||
toPayPercentage := toStore.PayPercentage
|
||||
if toPayPercentage <= 0 {
|
||||
toPayPercentage = 100
|
||||
}
|
||||
fromPayPercentage := jxutils.ConstrainPayPercentage(fromStore.PayPercentage)
|
||||
toPayPercentage := jxutils.ConstrainPayPercentage(toStore.PayPercentage)
|
||||
scaleFactor = float64(fromPayPercentage) / float64(toPayPercentage)
|
||||
}
|
||||
// 处理toStore中与fromStore中都存在的
|
||||
@@ -1468,12 +1471,14 @@ func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode
|
||||
sql += sqlCatAndSku
|
||||
sqlParams = append(sqlParams, sqlCatAndSkuParams)
|
||||
// globals.SugarLogger.Debug(sql)
|
||||
num, err = dao.ExecuteSQL(db, sql, sqlParams)
|
||||
globals.SugarLogger.Debugf("CopyStoreSkus trackInfo:%s num2:%d", ctx.GetTrackInfo(), num)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
num2, err2 := dao.ExecuteSQL(db, sql, sqlParams)
|
||||
globals.SugarLogger.Debugf("CopyStoreSkus fromStoreID:%d, toStoreID:%d, trackInfo:%s num2:%d", fromStoreID, toStoreID, ctx.GetTrackInfo(), num2)
|
||||
if err = err2; err != nil {
|
||||
errList.AddErr(err)
|
||||
dao.Rollback(db)
|
||||
break
|
||||
}
|
||||
|
||||
num += num2
|
||||
// 添加toStore中不存在,但fromStore存在的
|
||||
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,
|
||||
@@ -1517,13 +1522,17 @@ func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode
|
||||
}
|
||||
sql += sqlCatAndSku + " AND t0.id IS NULL"
|
||||
sqlParams = append(sqlParams, sqlCatAndSkuParams)
|
||||
num, err = dao.ExecuteSQL(db, sql, sqlParams)
|
||||
num2, err = dao.ExecuteSQL(db, sql, sqlParams)
|
||||
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)
|
||||
return num, err
|
||||
}
|
||||
return num, errList.GetErrListAsOne()
|
||||
}
|
||||
|
||||
func shouldPendingStorePriceChange(ctx *jxcontext.Context, storeID int, skuBindInfo *StoreSkuBindInfo) (shouldPending bool, err error) {
|
||||
|
||||
@@ -326,6 +326,13 @@ func CaculatePriceByPricePack(l model.PricePercentagePack, defPricePercentage, p
|
||||
return CaculateSkuVendorPrice(price, pricePercentage, priceAdd)
|
||||
}
|
||||
|
||||
func ConstrainPayPercentage(payPerCentage int) int {
|
||||
if payPerCentage <= 50 {
|
||||
payPerCentage = 70
|
||||
}
|
||||
return payPerCentage
|
||||
}
|
||||
|
||||
func IsSkuSpecial(specQuality float32, specUnit string) bool {
|
||||
return int(specQuality) == model.SpecialSpecQuality && (specUnit == model.SpecialSpecUnit || specUnit == model.SpecialSpecUnit2)
|
||||
}
|
||||
|
||||
@@ -249,6 +249,7 @@ func (c *StoreSkuController) UpdateStoresSkusByBind() {
|
||||
// @Param token header string true "认证token"
|
||||
// @Param fromStoreID formData int true "源门店ID"
|
||||
// @Param toStoreID formData int true "目标门店ID"
|
||||
// @Param toStoreIDs formData string false "目标门店ID列表"
|
||||
// @Param copyMode formData string true "拷贝模式,fresh:目标门店数据全部清除后拷贝,update:确保指定的源数据全部拷贝,已有的忽略"
|
||||
// @Param pricePercentage formData int false "价格调整百分比,缺省为100%"
|
||||
// @Param categoryIDs formData string false "json数据,skuName所属的类别,[1,2,3]"
|
||||
@@ -259,7 +260,13 @@ func (c *StoreSkuController) UpdateStoresSkusByBind() {
|
||||
// @router /CopyStoreSkus [post]
|
||||
func (c *StoreSkuController) CopyStoreSkus() {
|
||||
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
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user