添加改价时的isScale

This commit is contained in:
gazebo
2019-12-04 17:49:45 +08:00
parent e6004bea32
commit 4d3eb5d94c
3 changed files with 54 additions and 21 deletions

View File

@@ -788,15 +788,15 @@ func UpdateStoreSku(ctx *jxcontext.Context, storeID int, skuBindInfo *StoreSkuBi
} }
func UpdateStoreSkus(ctx *jxcontext.Context, storeID int, skuBindInfos []*StoreSkuBindInfo, isAsync, isContinueWhenError bool) (hint string, err error) { func UpdateStoreSkus(ctx *jxcontext.Context, storeID int, skuBindInfos []*StoreSkuBindInfo, isAsync, isContinueWhenError bool) (hint string, err error) {
return UpdateStoresSkus(ctx, []int{storeID}, skuBindInfos, isAsync, isContinueWhenError) return UpdateStoresSkus(ctx, []int{storeID}, skuBindInfos, false, isAsync, isContinueWhenError)
} }
func UpdateStoresSkus(ctx *jxcontext.Context, storeIDs []int, skuBindInfos []*StoreSkuBindInfo, isAsync, isContinueWhenError bool) (hint string, err error) { func UpdateStoresSkus(ctx *jxcontext.Context, storeIDs []int, skuBindInfos []*StoreSkuBindInfo, isScale, isAsync, isContinueWhenError bool) (hint string, err error) {
globals.SugarLogger.Debugf("UpdateStoresSkus:%s, storeIDs:%v, skuBindInfos:%s", ctx.GetTrackInfo(), storeIDs, utils.Format4Output(skuBindInfos, true)) globals.SugarLogger.Debugf("UpdateStoresSkus:%s, storeIDs:%v, skuBindInfos:%s", ctx.GetTrackInfo(), storeIDs, utils.Format4Output(skuBindInfos, true))
var num int64 var num int64
db := dao.GetDB() db := dao.GetDB()
skuIDs, err := updateStoresSkusWithoutSync(ctx, db, storeIDs, skuBindInfos) skuIDs, err := updateStoresSkusWithoutSync(ctx, db, storeIDs, skuBindInfos, isScale)
if err != nil { if err != nil {
return "", err return "", err
} }
@@ -836,7 +836,7 @@ func UpdateStoresSkusByBind(ctx *jxcontext.Context, skuBindInfos []*StoreSkuBind
} }
}() }()
for _, storeID := range storeIDs { for _, storeID := range storeIDs {
skuIDs, err2 := updateStoresSkusWithoutSync(ctx, db, []int{storeID}, skuBindInfosMap[storeID]) skuIDs, err2 := updateStoresSkusWithoutSync(ctx, db, []int{storeID}, skuBindInfosMap[storeID], false)
if err = err2; err != nil { if err = err2; err != nil {
dao.Rollback(db) dao.Rollback(db)
return "", err return "", err
@@ -916,7 +916,7 @@ func uniqueStoreNameBind(skuBindInfos []*StoreSkuBindInfo) (outSkuBindInfos []*S
return outSkuBindInfos return outSkuBindInfos
} }
func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs []int, skuBindInfos []*StoreSkuBindInfo) (needSyncSkus []int, err error) { func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs []int, skuBindInfos []*StoreSkuBindInfo, isScale bool) (needSyncSkus []int, err error) {
if len(storeIDs)*len(skuBindInfos) > maxStoreNameBind2 { if len(storeIDs)*len(skuBindInfos) > maxStoreNameBind2 {
return nil, fmt.Errorf("门店商品信息大于%d", maxStoreNameBind2) return nil, fmt.Errorf("门店商品信息大于%d", maxStoreNameBind2)
} }
@@ -957,6 +957,12 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs
dao.Rollback(db) dao.Rollback(db)
return nil, err return nil, err
} }
scaleFactor := float64(1)
if isScale {
if storeDetail.PayPercentage > 0 {
scaleFactor = float64(storeDetail.PayPercentage) / 100
}
}
for _, skuBindInfo := range skuBindInfos { for _, skuBindInfo := range skuBindInfos {
// 关注且没有给价时需要尝试从store_sku_bind中得到已有的单价 // 关注且没有给价时需要尝试从store_sku_bind中得到已有的单价
needGetExistingUnitPrice := skuBindInfo.UnitPrice == 0 && skuBindInfo.IsFocus == 1 needGetExistingUnitPrice := skuBindInfo.UnitPrice == 0 && skuBindInfo.IsFocus == 1
@@ -1018,6 +1024,7 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs
unitPrice = allBinds[0].SkuNamePrice unitPrice = allBinds[0].SkuNamePrice
} }
} }
unitPrice = int(float64(unitPrice) * scaleFactor)
for _, v := range allBinds { for _, v := range allBinds {
var num int64 var num int64
inSkuBind := inSkuBinsMap[v.RealSkuID] inSkuBind := inSkuBinsMap[v.RealSkuID]
@@ -1263,16 +1270,18 @@ func UpdateStoresSkusSale(ctx *jxcontext.Context, storeIDs []int, skuBindSkuInfo
return hint, err return hint, err
} }
func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode string, params map[string]interface{}, userName string) (num int64, err error) { func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID 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)
} }
db := dao.GetDB() db := dao.GetDB()
if err = checkStoreExisting(db, fromStoreID); err != nil { fromStore, err := checkStoreExisting(db, fromStoreID)
if err != nil {
return 0, err return 0, err
} }
if err = checkStoreExisting(db, toStoreID); err != nil { toStore, err := checkStoreExisting(db, toStoreID)
if err != nil {
return 0, err return 0, err
} }
@@ -1398,10 +1407,24 @@ func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode
isModifyStatus = 0 isModifyStatus = 0
syncStatus = model.SyncFlagPriceMask syncStatus = model.SyncFlagPriceMask
} }
scaleFactor := float64(1)
if isScale {
fromPayPercentage := fromStore.PayPercentage
if fromPayPercentage <= 0 {
fromPayPercentage = 100
}
toPayPercentage := toStore.PayPercentage
if toPayPercentage <= 0 {
toPayPercentage = 100
}
scaleFactor = float64(fromPayPercentage) / float64(toPayPercentage)
}
// 处理toStore中与fromStore中都存在的 // 处理toStore中与fromStore中都存在的
sql := ` sql := `
UPDATE store_sku_bind t1 UPDATE store_sku_bind t1
JOIN store t11 ON t11.id = t1.store_id
LEFT JOIN store_sku_bind t0 ON t0.store_id = ? AND t0.sku_id = t1.sku_id AND t0.deleted_at = ? LEFT JOIN store_sku_bind t0 ON t0.store_id = ? AND t0.sku_id = t1.sku_id AND t0.deleted_at = ?
JOIN store t01 ON t01.id = t0.store_id
JOIN sku t2 ON t1.sku_id = t2.id/* AND t2.deleted_at = ?*/ JOIN sku t2 ON t1.sku_id = t2.id/* AND t2.deleted_at = ?*/
JOIN sku_name t3 ON t2.name_id = t3.id/* AND t3.deleted_at = ?*/ JOIN sku_name t3 ON t2.name_id = t3.id/* AND t3.deleted_at = ?*/
LEFT JOIN sku_category t4 ON t3.category_id = t4.id AND t4.deleted_at = ? LEFT JOIN sku_category t4 ON t3.category_id = t4.id AND t4.deleted_at = ?
@@ -1409,9 +1432,9 @@ func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode
t1.last_operator = ?, t1.last_operator = ?,
t1.updated_at = ?, t1.updated_at = ?,
t1.sub_store_id = 0, t1.sub_store_id = 0,
t1.price = IF(t0.price * ? / 100 > 0, t0.price * ? / 100, 1), t1.price = IF(t0.price * ? / 100 > 0, t0.price * ? / 100, 1) * ?,
t1.jx_price = IF(t0.jx_price * ? / 100 > 0, t0.jx_price * ? / 100, 1), t1.jx_price = IF(t0.jx_price * ? / 100 > 0, t0.jx_price * ? / 100, 1) * ?,
t1.unit_price = IF(t0.unit_price * ? / 100 > 0, t0.unit_price * ? / 100, 1), t1.unit_price = IF(t0.unit_price * ? / 100 > 0, t0.unit_price * ? / 100, 1) * ?,
t1.status = IF(? = 0, t1.status, t0.status), t1.status = IF(? = 0, t1.status, t0.status),
t1.jd_sync_status = t1.jd_sync_status | ?, t1.jd_sync_status = t1.jd_sync_status | ?,
t1.mtwm_sync_status = t1.mtwm_sync_status | ?, t1.mtwm_sync_status = t1.mtwm_sync_status | ?,
@@ -1428,10 +1451,13 @@ func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode
now, now,
pricePercentage, pricePercentage,
pricePercentage, pricePercentage,
scaleFactor,
pricePercentage, pricePercentage,
pricePercentage, pricePercentage,
scaleFactor,
pricePercentage, pricePercentage,
pricePercentage, pricePercentage,
scaleFactor,
isModifyStatus, isModifyStatus,
syncStatus, syncStatus,
syncStatus, syncStatus,
@@ -1454,7 +1480,9 @@ func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode
jd_sync_status, ebai_sync_status, mtwm_sync_status) jd_sync_status, ebai_sync_status, mtwm_sync_status)
SELECT ?, ?, ?, ?, ?, SELECT ?, ?, ?, ?, ?,
t1.sku_id, 0, t1.sku_id, 0,
IF(t1.price * ? / 100 > 0, t1.price * ? / 100, 1), IF(t1.jx_price * ? / 100 > 0, t1.jx_price * ? / 100, 1), IF(t1.unit_price * ? / 100 > 0, t1.unit_price * ? / 100, 1), IF(t1.price * ? / 100 > 0, t1.price * ? / 100, 1) * ?,
IF(t1.jx_price * ? / 100 > 0, t1.jx_price * ? / 100, 1) * ?,
IF(t1.unit_price * ? / 100 > 0, t1.unit_price * ? / 100, 1) * ?,
IF(? = 0, ?, t1.status), ?, ?, ? IF(? = 0, ?, t1.status), ?, ?, ?
FROM store_sku_bind t1 FROM store_sku_bind t1
JOIN sku t2 ON t1.sku_id = t2.id AND t2.deleted_at = ? JOIN sku t2 ON t1.sku_id = t2.id AND t2.deleted_at = ?
@@ -1467,10 +1495,13 @@ func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode
now, now, userName, utils.DefaultTimeValue, toStoreID, now, now, userName, utils.DefaultTimeValue, toStoreID,
pricePercentage, pricePercentage,
pricePercentage, pricePercentage,
scaleFactor,
pricePercentage, pricePercentage,
pricePercentage, pricePercentage,
scaleFactor,
pricePercentage, pricePercentage,
pricePercentage, pricePercentage,
scaleFactor,
isModifyStatus, isModifyStatus,
model.SkuStatusDontSale, model.SkuStatusDontSale,
model.SyncFlagNewMask, model.SyncFlagNewMask,
@@ -1648,7 +1679,7 @@ func AcceptStoreOpRequests(ctx *jxcontext.Context, reqIDs []int) (err error) {
} }
} }
if err2 == nil { if err2 == nil {
_, err2 := UpdateStoresSkus(ctx, []int{op.StoreID}, []*StoreSkuBindInfo{skuBindInfo}, false, false) _, err2 := UpdateStoresSkus(ctx, []int{op.StoreID}, []*StoreSkuBindInfo{skuBindInfo}, false, false, false)
isLocalSucess := true isLocalSucess := true
if err2 != nil { if err2 != nil {
subErrors[reqID] = err2 subErrors[reqID] = err2
@@ -1845,16 +1876,16 @@ func setStoreSkuBindStatus(skuBind *model.StoreSkuBind, status int8) {
skuBind.MtwmSyncStatus |= status skuBind.MtwmSyncStatus |= status
} }
func checkStoreExisting(db *dao.DaoDB, storeID int) (err error) { func checkStoreExisting(db *dao.DaoDB, storeID int) (store *model.Store, err error) {
store := &model.Store{} store = &model.Store{}
store.ID = storeID store.ID = storeID
if err = dao.GetEntity(db, store); err != nil { if err = dao.GetEntity(db, store); err != nil {
if err == orm.ErrNoRows { if err == orm.ErrNoRows {
return fmt.Errorf("门店:%d不存在", storeID) return nil, fmt.Errorf("门店:%d不存在", storeID)
} }
return err return nil, err
} }
return nil return store, nil
} }
func RefreshStoresSkuByVendor(ctx *jxcontext.Context, storeIDs []int, vendorID int, isAsync bool) (hint string, err error) { func RefreshStoresSkuByVendor(ctx *jxcontext.Context, storeIDs []int, vendorID int, isAsync bool) (hint string, err error) {

View File

@@ -863,7 +863,7 @@ func UpdateJxPriceByWeimob(ctx *jxcontext.Context, storeIDs []int, isAsync, isCo
for _, v := range storeSkuBindInfoList { for _, v := range storeSkuBindInfoList {
skuBindInfos = append(skuBindInfos, v.(*cms.StoreSkuBindInfo)) skuBindInfos = append(skuBindInfos, v.(*cms.StoreSkuBindInfo))
} }
cms.UpdateStoresSkus(ctx, storeIDs, skuBindInfos, isAsync, isContinueWhenError) cms.UpdateStoresSkus(ctx, storeIDs, skuBindInfos, false, isAsync, isContinueWhenError)
case 2: case 2:
WriteToExcel3(task, dataStoreSkusSuccess.dataStoreSkusSuccessList, dataFailed.dataFailedList) WriteToExcel3(task, dataStoreSkusSuccess.dataStoreSkusSuccessList, dataFailed.dataFailedList)
} }

View File

@@ -206,6 +206,7 @@ func (c *StoreSkuController) SyncStoresSkus() {
// @Param token header string true "认证token" // @Param token header string true "认证token"
// @Param storeIDs formData string true "门店ID列表" // @Param storeIDs formData string true "门店ID列表"
// @Param payload formData string true "json数据StoreSkuBindInfo对象数组" // @Param payload formData string true "json数据StoreSkuBindInfo对象数组"
// @Param isScale formData bool false "是否按门店结算比例缩放"
// @Param isContinueWhenError formData bool false "单个同步失败是否继续缺省false" // @Param isContinueWhenError formData bool false "单个同步失败是否继续缺省false"
// @Param isAsync formData bool false "是否异步操作" // @Param isAsync formData bool false "是否异步操作"
// @Success 200 {object} controllers.CallResult // @Success 200 {object} controllers.CallResult
@@ -218,7 +219,7 @@ func (c *StoreSkuController) UpdateStoresSkus() {
if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs, params.Payload, &skuBindInfos); err != nil { if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs, params.Payload, &skuBindInfos); err != nil {
return retVal, "", err return retVal, "", err
} }
retVal, err = cms.UpdateStoresSkus(params.Ctx, storeIDs, skuBindInfos, params.IsAsync, params.IsContinueWhenError) retVal, err = cms.UpdateStoresSkus(params.Ctx, storeIDs, skuBindInfos, params.IsScale, params.IsAsync, params.IsContinueWhenError)
return retVal, "", err return retVal, "", err
}) })
} }
@@ -252,12 +253,13 @@ func (c *StoreSkuController) UpdateStoresSkusByBind() {
// @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]"
// @Param skuIDs formData string false "json数据skuID列表[1,2,3]" // @Param skuIDs formData string false "json数据skuID列表[1,2,3]"
// @Param isScale formData bool false "是否按门店结算比例缩放"
// @Success 200 {object} controllers.CallResult // @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult // @Failure 200 {object} controllers.CallResult
// @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.MapData, params.Ctx.GetUserName()) retVal, err = cms.CopyStoreSkus(params.Ctx, params.FromStoreID, params.ToStoreID, params.CopyMode, params.IsScale, params.MapData, params.Ctx.GetUserName())
return retVal, "", err return retVal, "", err
}) })
} }