+ StoreMap.PricePercentagePack

This commit is contained in:
gazebo
2019-07-15 15:37:45 +08:00
parent 598a9738e8
commit ae4dff1b2d
5 changed files with 96 additions and 14 deletions

View File

@@ -2025,7 +2025,7 @@ func RefreshStoresSkuByVendor(ctx *jxcontext.Context, storeIDs []int, vendorID i
}
}
for _, v := range storeSkuList {
pricePercentage := int(storeMap[v.StoreID].PricePercentage)
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)

View File

@@ -243,6 +243,40 @@ func CaculateSkuPriceFromVendor(vendorPrice, percentage, catPercentage int) int
return price
}
func GetPricePercentage(l model.PricePercentagePack, price int, defPricePercentage int) (pricePercentage int) {
pricePercentage = defPricePercentage
// if len(l) > 0 {
// var lastItem *model.PricePercentageItem
// for _, v := range l {
// lastItem = v
// if v.BeginPrice > price {
// break
// }
// }
// if lastItem != nil {
// pricePercentage = lastItem.PricePercentage
// }
// }
return pricePercentage
}
func GetPricePercentageByVendorPrice(l model.PricePercentagePack, vendorPrice int, defPricePercentage int) (pricePercentage int) {
pricePercentage = defPricePercentage
// if len(l) > 0 {
// var lastItem *model.PricePercentageItem
// for _, v := range l {
// lastItem = v
// if CaculateSkuVendorPrice(v.BeginPrice, v.PricePercentage, 0) > vendorPrice {
// break
// }
// }
// if lastItem != nil {
// pricePercentage = lastItem.PricePercentage
// }
// }
return pricePercentage
}
func IsSkuSpecial(specQuality float32, specUnit string) bool {
return int(specQuality) == model.SpecialSpecQuality && (specUnit == model.SpecialSpecUnit || specUnit == model.SpecialSpecUnit2)
}

View File

@@ -15,11 +15,14 @@ type StoreDetail struct {
DeliveryFee int `json:"deliveryFee"`
SyncStatus int8 `orm:"default(2)" json:"syncStatus"`
PricePercentage int16 `orm:"default(100)" json:"pricePercentage"` // todo 厂商价格相对于本地价格的百分比,这个字段的修改会比较特殊,因为可能需要刷新厂商价格
AutoPickup int8 `orm:"default(1)" json:"autoPickup"` // 是否自动拣货
DeliveryType int8 `orm:"default(0)" json:"deliveryType"` // 配送类型
DeliveryCompetition int8 `orm:"default(1)" json:"deliveryCompetition"` // 是否支持配送竞争
IsSync int8 `orm:"default(1)" json:"isSync"` // 是否同步
PricePercentage int16 `orm:"default(100)" json:"pricePercentage"` // todo 厂商价格相对于本地价格的百分比,这个字段的修改会比较特殊,因为可能需要刷新厂商价格
PricePercentagePack string `orm:"size(4096)" json:"pricePercentagePack"` //
PricePercentagePackObj model.PricePercentagePack `orm:"-" json:"-"`
AutoPickup int8 `orm:"default(1)" json:"autoPickup"` // 是否自动拣货
DeliveryType int8 `orm:"default(0)" json:"deliveryType"` // 配送类型
DeliveryCompetition int8 `orm:"default(1)" json:"deliveryCompetition"` // 是否支持配送竞争
IsSync int8 `orm:"default(1)" json:"isSync"` // 是否同步
model.Place // district info
DistrictName string `json:"-"`
@@ -35,11 +38,15 @@ type StoreDetail2 struct {
CityName string
}
func (s *StoreDetail) GetPricePerentage(price int) (pricePercentage int) {
return pricePercentage
}
func getStoreDetail(db *DaoDB, storeID, vendorID int, vendorStoreID string) (storeDetail *StoreDetail, err error) {
sql := `
SELECT t1.*,
t2.vendor_store_id, t2.status vendor_status, t2.delivery_fee, t2.sync_status,
t2.price_percentage, t2.auto_pickup, t2.delivery_type, t2.delivery_competition, t2.is_sync,
t2.price_percentage, t2.price_percentage_pack, t2.auto_pickup, t2.delivery_type, t2.delivery_competition, t2.is_sync,
district.code, district.name district_name, district.parent_code, district.level, district.tel_code,
district.jd_code, district.ebai_code, district.enabled, district.mtps_price,
city.name city_name
@@ -65,6 +72,9 @@ func getStoreDetail(db *DaoDB, storeID, vendorID int, vendorStoreID string) (sto
storeDetail = &StoreDetail{}
if err = GetRow(db, storeDetail, sql, sqlParams...); err == nil {
storeDetail.Place.Name = storeDetail.DistrictName
if storeDetail.PricePercentagePack != "" {
utils.UnmarshalUseNumber([]byte(storeDetail.PricePercentagePack), &storeDetail.PricePercentagePackObj)
}
return storeDetail, nil
}
return nil, err

View File

@@ -227,11 +227,14 @@ type StoreMap struct {
VendorStoreID string `orm:"column(vendor_store_id);size(48)" json:"vendorStoreID"`
Status int `json:"status"` // 取值同Store.Status
PricePercentage int16 `orm:"default(100)" json:"pricePercentage"` // todo 厂商价格相对于本地价格的百分比,这个字段的修改会比较特殊,因为可能需要刷新厂商价格
AutoPickup int8 `orm:"default(1)" json:"autoPickup"` // 是否自动拣货
DeliveryType int8 `orm:"default(0)" json:"deliveryType"` // 配送类型
DeliveryFee int `json:"deliveryFee"`
DeliveryCompetition int8 `orm:"default(1)" json:"deliveryCompetition"` // 是否支持配送竞争
PricePercentage int16 `orm:"default(100)" json:"pricePercentage"` // todo 厂商价格相对于本地价格的百分比,这个字段的修改会比较特殊,因为可能需要刷新厂商价格
PricePercentagePack string `orm:"size(4096)" json:"pricePercentagePack"` //
PricePercentagePackObj PricePercentagePack `orm:"-" json:"-"`
AutoPickup int8 `orm:"default(1)" json:"autoPickup"` // 是否自动拣货
DeliveryType int8 `orm:"default(0)" json:"deliveryType"` // 配送类型
DeliveryFee int `json:"deliveryFee"`
DeliveryCompetition int8 `orm:"default(1)" json:"deliveryCompetition"` // 是否支持配送竞争
SyncStatus int8 `orm:"default(2)" json:"syncStatus"`
IsSync int8 `orm:"default(1)" json:"isSync"` // 是否同步
@@ -303,3 +306,27 @@ func (v *VendorStoreSnapshot) CompareOperationTime(s2 *VendorStoreSnapshot) int
}
return 1
}
type PricePercentageItem struct {
BeginPrice int `json:"beginPrice"` // 启始价格区间(包括)
PricePercentage int `json:"pricePercentage"` // 调价比例
}
type PricePercentagePack []*PricePercentageItem
func (l PricePercentagePack) Len() int {
return len(l)
}
// Less reports whether the element with
// index i should sort before the element with index j.
func (l PricePercentagePack) Less(i, j int) bool {
return l[i].BeginPrice < l[j].BeginPrice
}
// Swap swaps the elements with indexes i and j.
func (l PricePercentagePack) Swap(i, j int) {
tmp := l[i]
l[i] = l[j]
l[j] = tmp
}

View File

@@ -55,7 +55,10 @@ type tStoreSkuFullInfo struct {
EbaiCat2ID int64 `orm:"column(ebai_cat2_id)"`
EbaiCat3ID int64 `orm:"column(ebai_cat3_id)"`
PricePercentage int
PricePercentage int
PricePercentagePack string `orm:"size(4096)" json:"pricePercentagePack"` //
PricePercentagePackObj model.PricePercentagePack `orm:"-" json:"-"`
CatPricePercentage int
}
@@ -82,7 +85,8 @@ var (
func (p *PurchaseHandler) getDirtyStoreSkus(db *dao.DaoDB, storeID int, skuIDs []int) (storeSkuInfoList []*tStoreSkuFullInfo, err error) {
sql := `
SELECT t8.price_percentage, t1.*, t2.spec_quality, t2.spec_unit, t2.weight, t2.status sku_status,
SELECT t8.price_percentage, t8.price_percentage_pack,
t1.*, 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, t3.desc_img_ebai,
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,
@@ -119,6 +123,13 @@ func (p *PurchaseHandler) getDirtyStoreSkus(db *dao.DaoDB, storeID int, skuIDs [
}
sql += " ORDER BY t1.price DESC"
err = dao.GetRows(db, &storeSkuInfoList, sql, sqlParams...)
if err == nil {
for _, v := range storeSkuInfoList {
if v.PricePercentagePack != "" {
utils.UnmarshalUseNumber([]byte(v.PricePercentagePack), &v.PricePercentagePackObj)
}
}
}
return storeSkuInfoList, err
}