添加改价时的isScale
This commit is contained in:
@@ -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) {
|
||||
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))
|
||||
|
||||
var num int64
|
||||
db := dao.GetDB()
|
||||
skuIDs, err := updateStoresSkusWithoutSync(ctx, db, storeIDs, skuBindInfos)
|
||||
skuIDs, err := updateStoresSkusWithoutSync(ctx, db, storeIDs, skuBindInfos, isScale)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -836,7 +836,7 @@ func UpdateStoresSkusByBind(ctx *jxcontext.Context, skuBindInfos []*StoreSkuBind
|
||||
}
|
||||
}()
|
||||
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 {
|
||||
dao.Rollback(db)
|
||||
return "", err
|
||||
@@ -916,7 +916,7 @@ func uniqueStoreNameBind(skuBindInfos []*StoreSkuBindInfo) (outSkuBindInfos []*S
|
||||
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 {
|
||||
return nil, fmt.Errorf("门店商品信息大于%d", maxStoreNameBind2)
|
||||
}
|
||||
@@ -957,6 +957,12 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs
|
||||
dao.Rollback(db)
|
||||
return nil, err
|
||||
}
|
||||
scaleFactor := float64(1)
|
||||
if isScale {
|
||||
if storeDetail.PayPercentage > 0 {
|
||||
scaleFactor = float64(storeDetail.PayPercentage) / 100
|
||||
}
|
||||
}
|
||||
for _, skuBindInfo := range skuBindInfos {
|
||||
// 关注且没有给价时,需要尝试从store_sku_bind中得到已有的单价
|
||||
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 = int(float64(unitPrice) * scaleFactor)
|
||||
for _, v := range allBinds {
|
||||
var num int64
|
||||
inSkuBind := inSkuBinsMap[v.RealSkuID]
|
||||
@@ -1263,16 +1270,18 @@ func UpdateStoresSkusSale(ctx *jxcontext.Context, storeIDs []int, skuBindSkuInfo
|
||||
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 {
|
||||
return 0, fmt.Errorf("不支持的拷贝模式:%s", copyMode)
|
||||
}
|
||||
|
||||
db := dao.GetDB()
|
||||
if err = checkStoreExisting(db, fromStoreID); err != nil {
|
||||
fromStore, err := checkStoreExisting(db, fromStoreID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if err = checkStoreExisting(db, toStoreID); err != nil {
|
||||
toStore, err := checkStoreExisting(db, toStoreID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -1398,10 +1407,24 @@ func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode
|
||||
isModifyStatus = 0
|
||||
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中都存在的
|
||||
sql := `
|
||||
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 = ?
|
||||
JOIN store t01 ON t01.id = t0.store_id
|
||||
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 = ?*/
|
||||
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.updated_at = ?,
|
||||
t1.sub_store_id = 0,
|
||||
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.unit_price = IF(t0.unit_price * ? / 100 > 0, t0.unit_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.unit_price = IF(t0.unit_price * ? / 100 > 0, t0.unit_price * ? / 100, 1) * ?,
|
||||
t1.status = IF(? = 0, t1.status, t0.status),
|
||||
t1.jd_sync_status = t1.jd_sync_status | ?,
|
||||
t1.mtwm_sync_status = t1.mtwm_sync_status | ?,
|
||||
@@ -1428,10 +1451,13 @@ func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode
|
||||
now,
|
||||
pricePercentage,
|
||||
pricePercentage,
|
||||
scaleFactor,
|
||||
pricePercentage,
|
||||
pricePercentage,
|
||||
scaleFactor,
|
||||
pricePercentage,
|
||||
pricePercentage,
|
||||
scaleFactor,
|
||||
isModifyStatus,
|
||||
syncStatus,
|
||||
syncStatus,
|
||||
@@ -1454,7 +1480,9 @@ func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode
|
||||
jd_sync_status, ebai_sync_status, mtwm_sync_status)
|
||||
SELECT ?, ?, ?, ?, ?,
|
||||
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), ?, ?, ?
|
||||
FROM store_sku_bind t1
|
||||
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,
|
||||
pricePercentage,
|
||||
pricePercentage,
|
||||
scaleFactor,
|
||||
pricePercentage,
|
||||
pricePercentage,
|
||||
scaleFactor,
|
||||
pricePercentage,
|
||||
pricePercentage,
|
||||
scaleFactor,
|
||||
isModifyStatus,
|
||||
model.SkuStatusDontSale,
|
||||
model.SyncFlagNewMask,
|
||||
@@ -1648,7 +1679,7 @@ func AcceptStoreOpRequests(ctx *jxcontext.Context, reqIDs []int) (err error) {
|
||||
}
|
||||
}
|
||||
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
|
||||
if err2 != nil {
|
||||
subErrors[reqID] = err2
|
||||
@@ -1845,16 +1876,16 @@ func setStoreSkuBindStatus(skuBind *model.StoreSkuBind, status int8) {
|
||||
skuBind.MtwmSyncStatus |= status
|
||||
}
|
||||
|
||||
func checkStoreExisting(db *dao.DaoDB, storeID int) (err error) {
|
||||
store := &model.Store{}
|
||||
func checkStoreExisting(db *dao.DaoDB, storeID int) (store *model.Store, err error) {
|
||||
store = &model.Store{}
|
||||
store.ID = storeID
|
||||
if err = dao.GetEntity(db, store); err != nil {
|
||||
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) {
|
||||
|
||||
@@ -863,7 +863,7 @@ func UpdateJxPriceByWeimob(ctx *jxcontext.Context, storeIDs []int, isAsync, isCo
|
||||
for _, v := range storeSkuBindInfoList {
|
||||
skuBindInfos = append(skuBindInfos, v.(*cms.StoreSkuBindInfo))
|
||||
}
|
||||
cms.UpdateStoresSkus(ctx, storeIDs, skuBindInfos, isAsync, isContinueWhenError)
|
||||
cms.UpdateStoresSkus(ctx, storeIDs, skuBindInfos, false, isAsync, isContinueWhenError)
|
||||
case 2:
|
||||
WriteToExcel3(task, dataStoreSkusSuccess.dataStoreSkusSuccessList, dataFailed.dataFailedList)
|
||||
}
|
||||
|
||||
@@ -206,6 +206,7 @@ func (c *StoreSkuController) SyncStoresSkus() {
|
||||
// @Param token header string true "认证token"
|
||||
// @Param storeIDs formData string true "门店ID列表"
|
||||
// @Param payload formData string true "json数据,StoreSkuBindInfo对象数组"
|
||||
// @Param isScale formData bool false "是否按门店结算比例缩放"
|
||||
// @Param isContinueWhenError formData bool false "单个同步失败是否继续,缺省false"
|
||||
// @Param isAsync formData bool false "是否异步操作"
|
||||
// @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 {
|
||||
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
|
||||
})
|
||||
}
|
||||
@@ -252,12 +253,13 @@ func (c *StoreSkuController) UpdateStoresSkusByBind() {
|
||||
// @Param pricePercentage formData int false "价格调整百分比,缺省为100%"
|
||||
// @Param categoryIDs formData string false "json数据,skuName所属的类别,[1,2,3]"
|
||||
// @Param skuIDs formData string false "json数据,skuID列表,[1,2,3]"
|
||||
// @Param isScale formData bool false "是否按门店结算比例缩放"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @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.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
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user