From 15d16c41a69108f4bbef8113ee4959655904bad6 Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 25 Sep 2019 10:28:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=88=86=E7=B1=BB=E8=B0=83?= =?UTF-8?q?=E4=BB=B7=E6=AF=94=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/act/act.go | 4 ++-- business/jxstore/cms/store_sku.go | 4 ++-- business/jxstore/cms/sync_store_sku.go | 2 +- business/jxutils/jxutils_cms.go | 28 +++++++++----------------- business/model/dao/store_sku.go | 12 +++++------ business/model/sku.go | 16 ++++++--------- 6 files changed, 26 insertions(+), 40 deletions(-) diff --git a/business/jxstore/act/act.go b/business/jxstore/act/act.go index a680bc4ec..bc80de6b2 100644 --- a/business/jxstore/act/act.go +++ b/business/jxstore/act/act.go @@ -131,7 +131,7 @@ func ActStoreSkuParam2Model(ctx *jxcontext.Context, db *dao.DaoDB, act *model.Ac VendorID: vendorID, SyncStatus: model.SyncFlagNewMask, - VendorPrice: int64(jxutils.CaculateSkuVendorPrice(storeSkuInfo.Price, pricePercentage, 0)), + VendorPrice: int64(jxutils.CaculateSkuVendorPrice(storeSkuInfo.Price, pricePercentage)), } v.OriginalPrice = actSkuMap.VendorPrice if act.Type == model.ActSkuFake { @@ -144,7 +144,7 @@ func ActStoreSkuParam2Model(ctx *jxcontext.Context, db *dao.DaoDB, act *model.Ac if v.PricePercentage != 0 { percentage = v.PricePercentage } - actSkuMap.ActualActPrice = int64(jxutils.CaculateSkuVendorPrice(int(actSkuMap.VendorPrice), percentage, 0)) + actSkuMap.ActualActPrice = int64(jxutils.CaculateSkuVendorPrice(int(actSkuMap.VendorPrice), percentage)) if actSkuMap.ActualActPrice > 10 { actSkuMap.ActualActPrice = int64(math.Round(float64(actSkuMap.ActualActPrice)/10) * 10) } diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index df9db03e8..6c31da87c 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -1847,8 +1847,8 @@ func RefreshStoresSkuByVendor(ctx *jxcontext.Context, storeIDs []int, vendorID i for _, v := range storeSkuList { pricePercentage := jxutils.GetPricePercentageByVendorPrice(storeMap[v.StoreID].PricePercentagePackObj, v.Price, int(storeMap[v.StoreID].PricePercentage)) skuName := skuNameMap[skuMap[v.SkuID].NameID] - v.Price = jxutils.CaculateSkuPriceFromVendor(v.Price, pricePercentage, 0) - v.UnitPrice = jxutils.CaculateSkuPriceFromVendor(skuName.Price, pricePercentage, 0) + v.Price = jxutils.CaculateSkuPriceFromVendor(v.Price, pricePercentage) + v.UnitPrice = jxutils.CaculateSkuPriceFromVendor(skuName.Price, pricePercentage) dao.WrapAddIDCULDEntity(v, ctx.GetUserName()) setStoreSkuBindStatus(v, model.SyncFlagNewMask) v.JdSyncStatus = 0 diff --git a/business/jxstore/cms/sync_store_sku.go b/business/jxstore/cms/sync_store_sku.go index 80715e406..1f5e18885 100644 --- a/business/jxstore/cms/sync_store_sku.go +++ b/business/jxstore/cms/sync_store_sku.go @@ -203,7 +203,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 { // 避免重新计算 pricePercentage = jxutils.GetPricePercentage(pricePercentagePack, int(inSku.Price), pricePercentage) - inSku.VendorPrice = int64(jxutils.CaculateSkuVendorPrice(int(inSku.Price), pricePercentage, 0)) + inSku.VendorPrice = int64(jxutils.CaculateSkuVendorPrice(int(inSku.Price), pricePercentage)) if inSku.VendorPrice <= 0 { inSku.VendorPrice = 1 // 最少1分钱 } diff --git a/business/jxutils/jxutils_cms.go b/business/jxutils/jxutils_cms.go index 836ccf94e..1d155f553 100644 --- a/business/jxutils/jxutils_cms.go +++ b/business/jxutils/jxutils_cms.go @@ -197,6 +197,10 @@ func StringList2Map(strList []string) map[string]int { return retVal } +func GetSliceLen(list interface{}) int { + return reflect.ValueOf(list).Len() +} + func RegularizeSkuQuality(specQuality float32, specUnit string) (g int) { lowerSpecUnit := strings.ToLower(specUnit) if lowerSpecUnit == "kg" || lowerSpecUnit == "l" { @@ -235,40 +239,28 @@ func CaculateUnitPrice(skuPrice int, specQuality float32, specUnit string, skuNa // } else if specQuality2 < 500 { // unitPrice = unitPrice * 100 / 105 // } - if unitPrice <= 0 { + if unitPrice <= 1 { unitPrice = 1 } return unitPrice } -func GetSliceLen(list interface{}) int { - return reflect.ValueOf(list).Len() -} - -func CaculateSkuVendorPrice(price, percentage, catPercentage int) int { +func CaculateSkuVendorPrice(price, percentage int) (vendorPrice int) { if percentage <= 10 || percentage >= 400 { percentage = 100 } - if catPercentage <= 10 || catPercentage >= 400 { - catPercentage = 100 - } - percentage = percentage * catPercentage / 100 - vendorPrice := int(math.Round(float64(price*percentage) / 100)) + vendorPrice = int(math.Round(float64(price*percentage) / 100)) if vendorPrice < 0 { vendorPrice = 0 } return vendorPrice } -func CaculateSkuPriceFromVendor(vendorPrice, percentage, catPercentage int) int { +func CaculateSkuPriceFromVendor(vendorPrice, percentage int) (price int) { if percentage <= 10 || percentage >= 400 { percentage = 100 } - if catPercentage <= 10 || catPercentage >= 400 { - catPercentage = 100 - } - percentage = percentage * catPercentage / 100 - price := int(math.Round(float64(vendorPrice) * 100 / float64(percentage))) + price = int(math.Round(float64(vendorPrice) * 100 / float64(percentage))) if price < 0 { price = 0 } @@ -297,7 +289,7 @@ func GetPricePercentageByVendorPrice(l model.PricePercentagePack, vendorPrice in if len(l) > 0 { var lastItem *model.PricePercentageItem for _, v := range l { - if CaculateSkuVendorPrice(v.BeginPrice, v.PricePercentage, 0) > vendorPrice { + if CaculateSkuVendorPrice(v.BeginPrice, v.PricePercentage) > vendorPrice { break } lastItem = v diff --git a/business/model/dao/store_sku.go b/business/model/dao/store_sku.go index a9e847724..d08aa17d8 100644 --- a/business/model/dao/store_sku.go +++ b/business/model/dao/store_sku.go @@ -58,7 +58,7 @@ type StoreSkuSyncInfo struct { // 平台相关的图片信息 Img string - DescImg string + DescImg string // 饿百是SkuName中的DescImgEbai VendorVendorCatID int64 `orm:"column(vendor_vendor_cat_id)"` // 平台商品分类(叶子结点) @@ -75,8 +75,6 @@ type StoreSkuSyncInfo struct { StoreCatSyncStatus int8 VendorCatID string `orm:"column(vendor_cat_id)"` - CatPricePercentage int - VendorPrice int64 MergedStatus int SkuName string @@ -221,11 +219,11 @@ func GetStoreSkus2(db *DaoDB, vendorID, storeID int, skuIDs []int, isDirty bool) t1.%s_sync_status store_sku_sync_status, %s vendor_name_id, t1.store_id, t1.deleted_at bind_deleted_at, t2.*, t3.id name_id, t3.prefix, t3.name, t3.unit, IF(t3.%s <> '', t3.%s, t3.img) img, t3.upc, t3.%s desc_img, - t4.%s_category_id vendor_vendor_cat_id, t4.%s_price_percentage cat_price_percentage + t4.%s_category_id vendor_vendor_cat_id ` fmtParams := []interface{}{ - tableName, fieldPrefix, fieldPrefix, vendorSkuNameField, GetImgFieldName(vendorID), GetImgFieldName(vendorID), GetDescImgFieldName(vendorID), - fieldPrefix, fieldPrefix, + tableName, fieldPrefix, fieldPrefix, vendorSkuNameField, GetImgFieldName(vendorID), + GetImgFieldName(vendorID), GetDescImgFieldName(vendorID), fieldPrefix, } // if vendorID == model.VendorIDEBAI { // sql += `, @@ -312,7 +310,7 @@ func GetFullStoreSkus(db *DaoDB, vendorID, storeID int) (skus []*StoreSkuSyncInf SELECT t1.id bind_id, t1.price, t1.unit_price, t1.status store_sku_status, t2.%s_id vendor_sku_id, t1.%s_sync_status store_sku_sync_status, t1.store_id, t1.deleted_at bind_deleted_at, t2.*, t2.id sku_id, - t3.id name_id, t3.prefix, t3.name, t3.unit, IF(t3.%s <> '', t3.%s, t3.img) img, + t3.id name_id, t3.prefix, t3.name, t3.unit, IF(t3.%s <> '', t3.%s, t3.img) img, t3.upc, t3.desc_img, t4.%s_category_id vendor_vendor_cat_id, t4.%s_sync_status store_cat_sync_status, t4.%s_id vendor_cat_id, t5sku.%s_sync_status sku_store_cat_sync_status, t5sku.%s_id sku_vendor_cat_id diff --git a/business/model/sku.go b/business/model/sku.go index 4a6aa3d62..e1214522f 100644 --- a/business/model/sku.go +++ b/business/model/sku.go @@ -135,16 +135,12 @@ 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"` // 这个是指对应的饿百商品类别 MtwmCategoryID int64 `orm:"column(mtwm_category_id)" json:"mtwmCategoryID"` // 这个是指对应的美团外卖商品类别 - WscCategoryID int64 `orm:"column(wsc_category_id)" json:"wscCategoryID"` // 这个是指对应的美团外卖商品类别 + + ElmCategoryID int64 `orm:"column(elm_category_id)" json:"elmCategoryID"` // 这个是指对应的饿了么商品类别 + WscCategoryID int64 `orm:"column(wsc_category_id)" json:"wscCategoryID"` // 这个是指对应的美团外卖商品类别 JdID int64 `orm:"column(jd_id);null" json:"jdID"` // 这个是指商家自己的商品类别在京东平台上的ID JdSyncStatus int8 `orm:"default(2)" json:"jdSyncStatus"` @@ -201,13 +197,13 @@ type SkuName struct { ImgEbai string `orm:"size(255)" json:"imgEbai"` // 饿百图片地址 ImgHashCode string `orm:"size(255);index" json:"img_hash_code"` + DescImg string `orm:"size(255)" json:"descImg"` // 商品详情图片描述 + DescImgEbai string `orm:"size(255)" json:"descImgEbai"` // 饿百的商品详情图片描述RTF + Upc string `orm:"size(20);index"` Status int `orm:"default(1)" json:"status"` // skuname状态,取值同sku.Status IsSpu int8 `orm:"column(is_spu)" json:"isSpu"` // 用于指明是否SKUNAME当成SPU - DescImg string `orm:"size(255)" json:"descImg"` // 商品详情图片描述 - DescImgEbai string `orm:"size(255)" json:"descImgEbai"` // 饿百的商品详情图片描述RTF - JdID int64 `orm:"column(jd_id);null;index" json:"jdID"` JdSyncStatus int8 `orm:"default(2)" json:"jdSyncStatus"`