StoreSkuBind添加JxPrice
This commit is contained in:
@@ -354,7 +354,11 @@ func UpdateConfig(ctx *jxcontext.Context, key, configType, value string) (hint s
|
||||
vendorStoreMap[v.VendorID] = append(vendorStoreMap[v.VendorID], v.StoreID)
|
||||
}
|
||||
for vendorID, storeIDs := range vendorStoreMap {
|
||||
dao.SetStoreSkuSyncStatus(db, vendorID, storeIDs, nil, model.SyncFlagPriceMask)
|
||||
if vendorID != model.VendorIDJX {
|
||||
dao.SetStoreSkuSyncStatus(db, vendorID, storeIDs, nil, model.SyncFlagPriceMask)
|
||||
} else {
|
||||
ReCalculateJxPrice(ctx, storeIDs)
|
||||
}
|
||||
}
|
||||
// for _, v := range storeMapList {
|
||||
// if _, err = dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, &model.StoreSkuBind{}, nil, ctx.GetUserName(), map[string]interface{}{
|
||||
|
||||
@@ -66,7 +66,7 @@ type StoreSkuExt struct {
|
||||
JdPrice int `json:"jdPrice"`
|
||||
EbaiPrice int `json:"ebaiPrice"`
|
||||
MtwmPrice int `json:"mtwmPrice"`
|
||||
// WscPrice int `json:"wscPrice"`
|
||||
JxPrice int `json:"jxPrice"`
|
||||
|
||||
AutoSaleAt time.Time `orm:"type(datetime);null" json:"autoSaleAt"`
|
||||
|
||||
@@ -198,7 +198,8 @@ func getGetStoresSkusBaseSQL(db *dao.DaoDB, storeIDs, skuIDs []int, isFocus bool
|
||||
sql += `
|
||||
JOIN (
|
||||
SELECT t2.store_id, t2.sku_id,
|
||||
MIN(IF(t3.actual_act_price = 0, NULL, t3.actual_act_price)) actual_act_price, MIN(IF(t2.earning_price = 0, NULL, t2.earning_price)) earning_price /*non-zero min value*/
|
||||
MIN(IF(t3.actual_act_price <= 0, NULL, t3.actual_act_price)) actual_act_price, /*non-zero min value*/
|
||||
MIN(IF(t2.earning_price <= 0, NULL, t2.earning_price)) earning_price /*non-zero min value*/
|
||||
FROM act t1
|
||||
JOIN act_store_sku t2 ON t2.act_id = t1.id AND t2.deleted_at = ?
|
||||
JOIN act_store_sku_map t3 ON t3.bind_id = t2.id AND t3.act_id = t1.id AND (t3.sync_status & ? = 0 OR t1.type = ?)
|
||||
@@ -443,7 +444,7 @@ func GetStoresSkusNew(ctx *jxcontext.Context, storeIDs, skuIDs []int, isFocus bo
|
||||
t4.sub_store_id, t4.price bind_price, IF(t4.unit_price IS NOT NULL, t4.unit_price, t1.price) unit_price, t4.status store_sku_status, t4.auto_sale_at,
|
||||
t4.ebai_id, t4.mtwm_id,
|
||||
t4.jd_sync_status, t4.ebai_sync_status, t4.mtwm_sync_status,
|
||||
t4.jd_price, t4.ebai_price, t4.mtwm_price
|
||||
t4.jd_price, t4.ebai_price, t4.mtwm_price, t4.jx_price
|
||||
` + sql
|
||||
var tmpList []*tGetStoresSkusInfo
|
||||
beginTime := time.Now()
|
||||
@@ -924,6 +925,12 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs
|
||||
}
|
||||
}()
|
||||
for _, storeID := range storeIDs {
|
||||
// todo 可以考虑在需要更新价格再获取
|
||||
storeDetail, err := dao.GetStoreDetail(dao.GetDB(), storeID, model.VendorIDJX)
|
||||
if err != nil {
|
||||
dao.Rollback(db)
|
||||
return nil, err
|
||||
}
|
||||
for _, skuBindInfo := range skuBindInfos {
|
||||
// 关注且没有给价时,需要尝试从store_sku_bind中得到已有的单价
|
||||
needGetExistingUnitPrice := skuBindInfo.UnitPrice == 0 && skuBindInfo.IsFocus == 1
|
||||
@@ -1001,6 +1008,7 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs
|
||||
Price: jxutils.CaculateSkuPrice(unitPrice, v.SpecQuality, v.SpecUnit, v.SkuNameUnit),
|
||||
Status: model.StoreSkuBindStatusDontSale, // 缺省不可售?
|
||||
}
|
||||
skuBind.JxPrice = jxutils.CaculatePriceByPricePack(storeDetail.PricePercentagePackObj, int(storeDetail.PricePercentage), skuBind.Price)
|
||||
if tmpStatus := getSkuSaleStatus(inSkuBind, skuBindInfo); tmpStatus != model.StoreSkuBindStatusNA {
|
||||
skuBind.Status = tmpStatus
|
||||
}
|
||||
@@ -1048,9 +1056,11 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs
|
||||
if skuBindInfo.UnitPrice != 0 && isCanChangePrice { // 这里是否需要加此条件限制
|
||||
skuBind.UnitPrice = unitPrice
|
||||
skuBind.Price = jxutils.CaculateSkuPrice(unitPrice, v.SpecQuality, v.SpecUnit, v.SkuNameUnit)
|
||||
skuBind.JxPrice = jxutils.CaculatePriceByPricePack(storeDetail.PricePercentagePackObj, int(storeDetail.PricePercentage), skuBind.Price)
|
||||
setStoreSkuBindStatus(skuBind, model.SyncFlagPriceMask)
|
||||
updateFieldMap["UnitPrice"] = 1
|
||||
updateFieldMap["Price"] = 1
|
||||
updateFieldMap["JxPrice"] = 1
|
||||
}
|
||||
// todo 这里应该是不需处理这个信息的吧?
|
||||
// if inSkuBind != nil && inSkuBind.EbaiID != 0 {
|
||||
@@ -1267,6 +1277,7 @@ func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode
|
||||
SET t1.last_operator = ?,
|
||||
t1.updated_at = ?,
|
||||
t1.price = t1.price * ? / 100,
|
||||
t1.jx_price = t1.jx_price * ? / 100,
|
||||
t1.unit_price = t1.unit_price * ? / 100,
|
||||
t1.jd_sync_status = t1.jd_sync_status | ?,
|
||||
t1.mtwm_sync_status = t1.mtwm_sync_status | ?,
|
||||
@@ -1281,6 +1292,7 @@ func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode
|
||||
now,
|
||||
pricePercentage,
|
||||
pricePercentage,
|
||||
pricePercentage,
|
||||
model.SyncFlagPriceMask,
|
||||
model.SyncFlagPriceMask,
|
||||
model.SyncFlagPriceMask,
|
||||
@@ -1307,13 +1319,14 @@ func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode
|
||||
JOIN sku t2 ON t1.sku_id = t2.id/* AND t2.deleted_at = ?*/
|
||||
JOIN sku_name t3 ON t2.name_id = t3.id/* AND t2.deleted_at = ?*/
|
||||
LEFT JOIN sku_category t4 ON t3.category_id = t4.id AND t2.deleted_at = ?
|
||||
SET t1.deleted_at = ?,
|
||||
t1.updated_at = ?,
|
||||
t1.last_operator = ?,
|
||||
t1.status = ?,
|
||||
t1.jd_sync_status = IF((t1.jd_sync_status & ?) <> 0, 0, ?),
|
||||
t1.mtwm_sync_status = IF((t1.mtwm_sync_status & ?) <> 0, 0, ?),
|
||||
t1.ebai_sync_status = IF((t1.ebai_sync_status & ?) <> 0, 0, ?)
|
||||
SET
|
||||
t1.deleted_at = ?,
|
||||
t1.updated_at = ?,
|
||||
t1.last_operator = ?,
|
||||
t1.status = ?,
|
||||
t1.jd_sync_status = IF((t1.jd_sync_status & ?) <> 0, 0, ?),
|
||||
t1.mtwm_sync_status = IF((t1.mtwm_sync_status & ?) <> 0, 0, ?),
|
||||
t1.ebai_sync_status = IF((t1.ebai_sync_status & ?) <> 0, 0, ?)
|
||||
WHERE t1.store_id = ? AND t1.deleted_at = ? AND t0.id IS NULL
|
||||
`
|
||||
sqlDeleteParams := []interface{}{
|
||||
@@ -1356,10 +1369,12 @@ func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode
|
||||
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 = ?
|
||||
SET t1.last_operator = ?,
|
||||
SET
|
||||
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.status = IF(? = 0, t1.status, t0.status),
|
||||
t1.jd_sync_status = t1.jd_sync_status | ?,
|
||||
@@ -1379,6 +1394,8 @@ func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode
|
||||
pricePercentage,
|
||||
pricePercentage,
|
||||
pricePercentage,
|
||||
pricePercentage,
|
||||
pricePercentage,
|
||||
isModifyStatus,
|
||||
syncStatus,
|
||||
syncStatus,
|
||||
@@ -1397,10 +1414,11 @@ func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode
|
||||
|
||||
// 添加toStore中不存在,但fromStore存在的
|
||||
sql = `
|
||||
INSERT INTO store_sku_bind(created_at, updated_at, last_operator, deleted_at, store_id, sku_id, sub_store_id, 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,
|
||||
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.unit_price * ? / 100 > 0, t1.unit_price * ? / 100, 1),
|
||||
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(? = 0, ?, t1.status), ?, ?, ?
|
||||
FROM store_sku_bind t1
|
||||
JOIN sku t2 ON t1.sku_id = t2.id AND t2.deleted_at = ?
|
||||
@@ -1415,6 +1433,8 @@ func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode
|
||||
pricePercentage,
|
||||
pricePercentage,
|
||||
pricePercentage,
|
||||
pricePercentage,
|
||||
pricePercentage,
|
||||
isModifyStatus,
|
||||
model.SkuStatusDontSale,
|
||||
model.SyncFlagNewMask,
|
||||
@@ -2045,3 +2065,22 @@ func AutoSaleStoreSku(ctx *jxcontext.Context, storeIDs []int, isNeedSync bool) (
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func ReCalculateJxPrice(ctx *jxcontext.Context, storeIDs []int) (err error) {
|
||||
db := dao.GetDB()
|
||||
for _, storeID := range storeIDs {
|
||||
if storeDetail, err := dao.GetStoreDetail(db, storeID, model.VendorIDJX); err == nil {
|
||||
if storeSkuList, err := dao.GetStoresSkusInfo(db, []int{storeID}, nil); err == nil {
|
||||
for _, skuBind := range storeSkuList {
|
||||
skuBind.JxPrice = jxutils.CaculatePriceByPricePack(storeDetail.PricePercentagePackObj, int(storeDetail.PricePercentage), skuBind.Price)
|
||||
dao.UpdateEntity(db, skuBind)
|
||||
}
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -213,8 +213,7 @@ func storeSkuSyncInfo2Bare(inSku *dao.StoreSkuSyncInfo) (outSku *partner.StoreSk
|
||||
|
||||
func calVendorPrice4StoreSku(inSku *dao.StoreSkuSyncInfo, pricePercentagePack model.PricePercentagePack, pricePercentage int) (outSku *dao.StoreSkuSyncInfo) {
|
||||
if inSku.VendorPrice <= 0 { // 避免重新计算
|
||||
pricePercentage2, priceAdd2 := jxutils.GetPricePercentage(pricePercentagePack, int(inSku.Price), pricePercentage)
|
||||
inSku.VendorPrice = int64(jxutils.CaculateSkuVendorPrice(int(inSku.Price), pricePercentage2, priceAdd2))
|
||||
inSku.VendorPrice = int64(jxutils.CaculatePriceByPricePack(pricePercentagePack, pricePercentage, int(inSku.Price)))
|
||||
if inSku.VendorPrice <= 0 {
|
||||
inSku.VendorPrice = 1 // 最少1分钱
|
||||
}
|
||||
@@ -348,7 +347,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo
|
||||
calVendorPrice4StoreSku(sku, storeDetail.PricePercentagePackObj, int(storeDetail.PricePercentage))
|
||||
if singleStoreHandler == nil {
|
||||
sku.StoreSkuSyncStatus |= model.SyncFlagSaleMask | model.SyncFlagPriceMask
|
||||
bareSku = storeSkuSyncInfo2Bare(calVendorPrice4StoreSku(sku, storeDetail.PricePercentagePackObj, int(storeDetail.PricePercentage)))
|
||||
bareSku = storeSkuSyncInfo2Bare(sku)
|
||||
stockList = append(stockList, bareSku)
|
||||
priceList = append(priceList, bareSku)
|
||||
if sku.MergedStatus == model.SkuStatusNormal {
|
||||
|
||||
Reference in New Issue
Block a user