diff --git a/business/jxstore/cms/sku.go b/business/jxstore/cms/sku.go index 0aa192ecf..aa963fb05 100644 --- a/business/jxstore/cms/sku.go +++ b/business/jxstore/cms/sku.go @@ -106,7 +106,8 @@ func UpdateCategory(ctx *jxcontext.Context, categoryID int, payload map[string]i } if num, err = dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, cat, valid, userName, nil, model.FieldJdSyncStatus, syncStatus); err == nil { SetStoreCategorySyncStatus2(db, nil, []int{categoryID}, model.SyncFlagModifiedMask) - if valid["jdCategoryID"] != nil || valid["ebaiCategoryID"] != nil || valid["mtwmCategoryID"] != nil { + if valid["jdCategoryID"] != nil || valid["ebaiCategoryID"] != nil || valid["mtwmCategoryID"] != nil || + valid["jdPricePercentage"] != nil || valid["ebaiPricePercentage"] != nil || valid["mtwmPricePercentage"] != nil { if skuList, err2 := dao.GetSkuByCats(db, []int{categoryID}); err2 == nil && len(skuList) > 0 { var skuIDs []int for _, sku := range skuList { @@ -115,14 +116,31 @@ func UpdateCategory(ctx *jxcontext.Context, categoryID int, payload map[string]i if valid["jdCategoryID"] != nil { dao.SetSkuSyncStatus(db, model.VendorIDJD, skuIDs, model.SyncFlagModifiedMask) } + + // todo 如下逻辑,在不同平台同时改pricePercentage与平台分类映射时,会不必要的打上多余的标记 var vendorIDs []int - if valid["ebaiCategoryID"] != nil { + syncStatus := model.SyncFlagModifiedMask + if valid["jdPricePercentage"] != nil { + vendorIDs = append(vendorIDs, model.VendorIDJD) + syncStatus |= model.SyncFlagPriceMask + } + + if valid["ebaiPricePercentage"] != nil { + vendorIDs = append(vendorIDs, model.VendorIDEBAI) + syncStatus |= model.SyncFlagPriceMask + } else if valid["ebaiCategoryID"] != nil { vendorIDs = append(vendorIDs, model.VendorIDEBAI) } - if valid["mtwmCategoryID"] != nil { + + if valid["mtwmPricePercentage"] != nil { + vendorIDs = append(vendorIDs, model.VendorIDMTWM) + syncStatus |= model.SyncFlagPriceMask + } else if valid["mtwmCategoryID"] != nil { vendorIDs = append(vendorIDs, model.VendorIDMTWM) } - SetStoreSkuSyncStatus2(db, nil, vendorIDs, skuIDs, model.SyncFlagModifiedMask) + if len(vendorIDs) > 0 { + SetStoreSkuSyncStatus2(db, nil, vendorIDs, skuIDs, syncStatus) + } } } _, err = CurVendorSync.SyncCategory(ctx, db, categoryID, false, userName) diff --git a/business/jxutils/jxutils_cms.go b/business/jxutils/jxutils_cms.go index 8b045aa36..a3af6230e 100644 --- a/business/jxutils/jxutils_cms.go +++ b/business/jxutils/jxutils_cms.go @@ -177,7 +177,14 @@ func GetSliceLen(list interface{}) int { return reflect.ValueOf(list).Len() } -func CaculateSkuVendorPrice(price int, percentage int) int { +func CaculateSkuVendorPrice(price, percentage, catPercentage int) int { + if percentage <= 10 || percentage >= 400 { + percentage = 100 + } + if catPercentage <= 10 || catPercentage >= 400 { + catPercentage = 100 + } + percentage = percentage * catPercentage / 100 storePrice := int(math.Round(float64(price*percentage) / 100)) if storePrice < 0 { storePrice = 0 diff --git a/business/model/dao/store_sku.go b/business/model/dao/store_sku.go index e22acbab4..69b3913a5 100644 --- a/business/model/dao/store_sku.go +++ b/business/model/dao/store_sku.go @@ -62,6 +62,8 @@ type StoreSkuSyncInfo struct { SkuCatSyncStatus int8 SkuVendorCatID string `orm:"column(sku_vendor_cat_id)"` + + CatPricePercentage int } // 单门店模式厂商适用 @@ -142,7 +144,7 @@ func GetStoreSkus(db *DaoDB, vendorID, storeID int, skuIDs []int) (skus []*Store SELECT t1.id bind_id, t1.price, t1.unit_price, t1.status store_sku_status, %s.%s_id vendor_sku_id, t1.%s_sync_status sku_sync_status, %s vendor_name_id, t2.*, t3.id name_id, t3.prefix, t3.name, t3.unit, t3.%s img, t3.upc, - t4.%s_category_id vendor_vendor_cat_id, + t4.%s_category_id vendor_vendor_cat_id, t4.%s_price_percentage cat_price_percentage, t5.%s_sync_status cat_sync_status, t5.%s_id vendor_cat_id, t5sku.%s_sync_status sku_cat_sync_status, t5sku.%s_id sku_vendor_cat_id FROM store_sku_bind t1 @@ -168,7 +170,8 @@ func GetStoreSkus(db *DaoDB, vendorID, storeID int, skuIDs []int) (skus []*Store sqlParams = append(sqlParams, skuIDs) } fieldPrefix := ConvertDBFieldPrefix(model.VendorNames[vendorID]) - sql = fmt.Sprintf(sql, tableName, fieldPrefix, fieldPrefix, vendorSkuNameField, GetImgFieldName(vendorID), fieldPrefix, fieldPrefix, fieldPrefix, fieldPrefix, fieldPrefix, fieldPrefix) + sql = fmt.Sprintf(sql, tableName, fieldPrefix, fieldPrefix, vendorSkuNameField, GetImgFieldName(vendorID), + fieldPrefix, fieldPrefix, fieldPrefix, fieldPrefix, fieldPrefix, fieldPrefix, fieldPrefix) sql += " ORDER BY t1.price" // globals.SugarLogger.Debug(sql) if err = GetRows(db, &skus, sql, sqlParams...); err != nil { diff --git a/business/model/sku.go b/business/model/sku.go index 5eeff8e19..b785d4bf9 100644 --- a/business/model/sku.go +++ b/business/model/sku.go @@ -131,6 +131,11 @@ type SkuCategory struct { Type int8 `json:"type"` // 类别类型,即是普通类别还是特殊用于做活动的类别 Seq int `json:"seq"` + JdPricePercentage int16 `orm:"default(100)" json:"jdPricePercentage"` + EbaiPricePercentage int16 `orm:"default(100)" json:"ebaiPricePercentage"` + MtwmPricePercentage int16 `orm:"default(100)" json:"mtwmPricePercentage"` + WscPricePercentage int16 `orm:"default(100)" json:"wscPricePercentage"` + JdCategoryID int64 `orm:"column(jd_category_id)" json:"jdCategoryID"` // 这个是指对应的京东商品类别 ElmCategoryID int64 `orm:"column(elm_category_id)" json:"elmCategoryID"` // 这个是指对应的饿了么商品类别 EbaiCategoryID int64 `orm:"column(ebai_category_id)" json:"ebaiCategoryID"` // 这个是指对应的饿百商品类别 diff --git a/business/partner/purchase/ebai/store_sku.go b/business/partner/purchase/ebai/store_sku.go index 164207f34..8cf87bdcd 100644 --- a/business/partner/purchase/ebai/store_sku.go +++ b/business/partner/purchase/ebai/store_sku.go @@ -54,7 +54,8 @@ type tStoreSkuFullInfo struct { EbaiCat2ID int64 `orm:"column(ebai_cat2_id)"` EbaiCat3ID int64 `orm:"column(ebai_cat3_id)"` - PricePercentage int + PricePercentage int + CatPricePercentage int } type tStoreCatInfo struct { @@ -82,7 +83,7 @@ func (p *PurchaseHandler) getDirtyStoreSkus(db *dao.DaoDB, storeID int, skuIDs [ sql := ` SELECT t8.price_percentage, t1.*, t2.id sku_id, t2.spec_quality, t2.spec_unit, t2.weight, t2.status sku_status, t3.id name_id, t3.prefix, t3.name, t2.comment, t3.is_global, t3.unit, IF(t3.img_ebai <> '', t3.img_ebai, t3.img) img, t3.upc, - t4.name cat_name, + t4.name cat_name, t4.ebai_price_percentage cat_price_percentage, t4.id cat_id, t4.level cat_level, t5.ebai_id cat_ebai_id, t4p.id parent_cat_id, t5p.ebai_id parent_cat_ebai_id, t5p.ebai_sync_status parent_cat_ebai_sync_status, cat1.vendor_category_id ebai_cat3_id, cat2.vendor_category_id ebai_cat2_id, cat2.parent_id ebai_cat1_id @@ -385,7 +386,7 @@ func (p *PurchaseHandler) RefreshStoresAllSkusID(ctx *jxcontext.Context, parentT /////////// func genSkuParamsFromStoreSkuInfo(storeSku *tStoreSkuFullInfo) (params map[string]interface{}) { - price := jxutils.CaculateSkuVendorPrice(storeSku.Price, storeSku.PricePercentage) + price := jxutils.CaculateSkuVendorPrice(storeSku.Price, storeSku.PricePercentage, storeSku.CatPricePercentage) params = map[string]interface{}{ "name": jxutils.ComposeSkuName(storeSku.Prefix, storeSku.Name, storeSku.Comment, storeSku.Unit, storeSku.SpecQuality, storeSku.SpecUnit, 0), "left_num": model.MaxStoreSkuStockQty, diff --git a/business/partner/purchase/jd/store_sku.go b/business/partner/purchase/jd/store_sku.go index 1009a71a6..e6622a217 100644 --- a/business/partner/purchase/jd/store_sku.go +++ b/business/partner/purchase/jd/store_sku.go @@ -17,9 +17,10 @@ import ( type tStoreSkuBindExt struct { model.StoreSkuBind - PricePercentage int - VendorStoreID string `orm:"column(vendor_store_id)"` - JdID int64 `orm:"column(jd_id)"` + PricePercentage int + CatPricePercentage int + VendorStoreID string `orm:"column(vendor_store_id)"` + JdID int64 `orm:"column(jd_id)"` } // 京东到家,以有库存表示关注(认领) @@ -39,10 +40,12 @@ func (p *PurchaseHandler) SyncStoreSkus(ctx *jxcontext.Context, parentTask tasks } sql := ` - SELECT t3.jd_id, t1.*, t2.price_percentage, t2.vendor_store_id + SELECT t3.jd_id, t1.*, t2.price_percentage, t2.vendor_store_id, t5.jd_price_percentage cat_price_percentage FROM store_sku_bind t1 JOIN store_map t2 ON t1.store_id = t2.store_id AND t2.vendor_id = ? AND t2.deleted_at = ? JOIN sku t3 ON t1.sku_id = t3.id AND t3.deleted_at = ? + JOIN sku_name t4 ON t4.id = t3.name_id + JOIN sku_category t5 ON t5.id = t4.category_id ` + sqlWhere + " ORDER BY t1.updated_at" var storeSkus []*tStoreSkuBindExt sqlParams := []interface{}{ @@ -83,7 +86,7 @@ func (p *PurchaseHandler) SyncStoreSkus(ctx *jxcontext.Context, parentTask tasks if storeSku.JdSyncStatus&(model.SyncFlagPriceMask|model.SyncFlagNewMask) != 0 { skuPriceInfoList = append(skuPriceInfoList, &jdapi.SkuPriceInfo{ OutSkuId: utils.Int2Str(storeSku.SkuID), - Price: constrainPrice(jxutils.CaculateSkuVendorPrice(storeSku.Price, storeSku.PricePercentage)), + Price: constrainPrice(jxutils.CaculateSkuVendorPrice(storeSku.Price, storeSku.PricePercentage, storeSku.CatPricePercentage)), }) } if storeSku.JdSyncStatus&(model.SyncFlagSaleMask|model.SyncFlagNewMask) != 0 { @@ -215,7 +218,7 @@ func (p *PurchaseHandler) syncStoreSkus(ctx *jxcontext.Context, parentTask tasks if storeSku.SkuSyncStatus&(model.SyncFlagPriceMask|model.SyncFlagNewMask) != 0 { skuPriceInfoList = append(skuPriceInfoList, &jdapi.SkuPriceInfo{ OutSkuId: utils.Int2Str(storeSku.ID), - Price: constrainPrice(jxutils.CaculateSkuVendorPrice(int(storeSku.Price), int(storeDetail.PricePercentage))), + Price: constrainPrice(jxutils.CaculateSkuVendorPrice(int(storeSku.Price), int(storeDetail.PricePercentage), storeSku.CatPricePercentage)), }) } if storeSku.SkuSyncStatus&(model.SyncFlagSaleMask|model.SyncFlagNewMask) != 0 { diff --git a/business/partner/purchase/mtwm/store_sku.go b/business/partner/purchase/mtwm/store_sku.go index 440cfc1e6..47d252afe 100644 --- a/business/partner/purchase/mtwm/store_sku.go +++ b/business/partner/purchase/mtwm/store_sku.go @@ -273,7 +273,7 @@ func (p *PurchaseHandler) SyncStoreSkus(ctx *jxcontext.Context, parentTask tasks globals.SugarLogger.Debugf("mtwm SyncStoreSkus3 skuID:%d, SkuSyncStatus:%d", skuItem.ID, skuItem.SkuSyncStatus) foodData["name"] = jxutils.ComposeSkuName(skuItem.Prefix, skuItem.Name, skuItem.Comment, skuItem.Unit, skuItem.SpecQuality, skuItem.SpecUnit, 30) foodData["description"] = skuItem.Comment - foodData["price"] = jxutils.IntPrice2Standard(int64(jxutils.CaculateSkuVendorPrice(int(skuItem.Price), int(storeDetail.PricePercentage)))) + foodData["price"] = jxutils.IntPrice2Standard(int64(jxutils.CaculateSkuVendorPrice(int(skuItem.Price), int(storeDetail.PricePercentage), skuItem.CatPricePercentage))) foodData["min_order_count"] = 1 foodData["unit"] = skuItem.Unit foodData["box_num"] = 0 diff --git a/business/partner/purchase/weimob/wsc/store_sku.go b/business/partner/purchase/weimob/wsc/store_sku.go index 9e7ef112c..f9dd0e7b2 100644 --- a/business/partner/purchase/weimob/wsc/store_sku.go +++ b/business/partner/purchase/weimob/wsc/store_sku.go @@ -208,7 +208,7 @@ func (p *PurchaseHandler) SyncStoreSkus(ctx *jxcontext.Context, parentTask tasks DeliveryTypeIdList: []int64{DefDeliveryTypeId}, B2cGoodsType: weimobapi.GoodsTypeNormal, } - salePrice := int64(jxutils.CaculateSkuVendorPrice(int(skuItem.Price), int(storeDetail.PricePercentage))) + salePrice := int64(jxutils.CaculateSkuVendorPrice(int(skuItem.Price), int(storeDetail.PricePercentage), skuItem.CatPricePercentage)) skuList := []map[string]interface{}{ map[string]interface{}{ weimobapi.KeyOuterSkuCode: utils.Int2Str(skuItem.ID),