@@ -8,6 +8,7 @@ import (
"git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/globals/refutil"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/globals"
@@ -150,6 +151,28 @@ type StoreSkuNamesInfo struct {
SkuNames [ ] * StoreSkuNameExt ` json:"skuNames" `
}
type StoreSkuVendorInfo struct {
VendorID int ` orm:"column(vendor_id)" json:"vendorID" `
VendorSkuID string ` orm:"column(vendor_sku_id)" json:"vendorSkuID" `
SyncStatus int8 ` json:"syncStatus" `
VendorPrice int ` json:"vendorPrice" `
LockTime * time . Time ` json:"lockTime,omitempty" `
ActPrice int ` json:"actPrice" `
ActID int ` orm:"column(act_id)" json:"actID" `
ActType int ` orm:"column(act_type)" json:"actType" `
EarningPrice int ` json:"earningPrice" `
EarningActID int ` orm:"column(earning_act_id)" json:"earningActID" `
// 新活动信息
VendorActID string ` orm:"column(vendor_act_id);size(48)" json:"vendorActID" `
ActPercentage int ` json:"actPercentage" ` // 直降活动百分比
ActSyncStatus int8 ` orm:"default(2)" json:"actSyncStatus" `
VendorActPrice int64 ` json:"vendorActPrice" ` // 保存数据用,实际的活动价
}
type StoreSkuExt struct {
NameID int ` orm:"column(name_id)" json:"nameID" `
SkuID int ` orm:"column(sku_id)" json:"id" `
@@ -158,7 +181,6 @@ type StoreSkuExt struct {
SkuSpecQuality float32 ` json:"specQuality" `
SkuSpecUnit string ` orm:"size(8)" json:"specUnit" ` // 质量或容量
Weight int ` json:"weight" ` // 重量/质量, 单位为克, 当相应的SkuName的SpecUnit为g或kg时, 必须等于SpecQuality
JdID string ` orm:"column(sku_jd_id);null;index" json:"jdID" `
SkuStatus int ` json:"status" `
BindCreatedAt time . Time ` orm:"auto_now_add;type(datetime)" json:"createdAt" `
@@ -169,16 +191,24 @@ type StoreSkuExt struct {
BindPrice int ` json:"price" ` // 单位为分, 不用int64的原因是这里不需要累加
UnitPrice int ` json:"unitPrice" ` // 这个是一斤的门店商品价, 放在这里的原因是避免额外增加一张store sku_name表, 逻辑上要保证同一SKU NAME中的所有SKU这个字段的数据一致
StoreSkuStatus int ` json:"storeSkuStatus" `
AutoSaleAt time . Time ` orm:"type(datetime);null" json:"autoSaleAt" `
StatusSaleBegin int16 ` json:"statusSaleBegin" ` //商品可售时间范围
StatusSaleEnd int16 ` json:"statusSaleEnd" `
Count int ` json:"count" `
Times int ` json:"times" `
// VendorInfoMap用于替换其之下的所有信息
VendorInfoMap map [ int ] * StoreSkuVendorInfo ` json:"vendorInfoMap,omitempty" `
JdID string ` orm:"column(sku_jd_id);null;index" json:"jdID" `
EbaiID string ` orm:"column(ebai_id);index" json:"ebaiID" `
MtwmID string ` orm:"column(mtwm_id)" json:"mtwmID" ` // 这个也不是必须的, 只是为了DAO取数据语句一致
// WscID string `orm:"column(wsc_id);index" json:"wscID"` // 表示微盟skuId
// WscID2 string `orm:"column(wsc_id2);index" json:"wscID2"` // 表示微盟goodsId
JdSyncStatus int8 ` orm:"default(2)" json:"jdSyncStatus" `
EbaiSyncStatus int8 ` orm:"default(2)" json:"ebaiSyncStatus" `
MtwmSyncStatus int8 ` orm:"default(2)" json:"mtwmSyncStatus" `
// WscSyncStatus int8 `orm:"default(2)" json:"wscSyncStatus"`
JdPrice int ` json:"jdPrice" `
EbaiPrice int ` json:"ebaiPrice" `
@@ -190,22 +220,12 @@ type StoreSkuExt struct {
MtwmLockTime * time . Time ` orm:"null" json:"mtwmLockTime,omitempty" `
JxLockTime * time . Time ` orm:"null" json:"jxLockTime,omitempty" `
AutoSaleAt time . Time ` orm:"type(datetime);null" json:"autoSaleAt" `
ActPrice int ` json:"actPrice" `
ActID int ` orm:"column(act_id)" json:"actID" `
ActType int ` orm:"column(act_type)" json:"actType" `
EarningPrice int ` json:"earningPrice" `
EarningActID int ` orm:"column(earning_act_id)" json:"earningActID" `
// RealEarningPrice int `json:"realEarningPrice"`
StatusSaleBegin int16 ` json:"statusSaleBegin" ` //商品可售时间范围
StatusSaleEnd int16 ` json:"statusSaleEnd" `
Count int ` json:"count" `
Times int ` json:"times" `
}
type SkuNameAndPlace struct {
@@ -1199,13 +1219,33 @@ func SetStoreCatMapSyncStatus(storeCatMap *model.StoreSkuCategoryMap, vendorID i
// skuIDs为空, 会导致性能极低, 所以要skuIDs必须有值
func UpdateActPrice4StoreSkuNameNew ( db * DaoDB , storeIDs , skuIDs [ ] int , skuNamesInfo * StoreSkuNamesInfo , actVendorID int ) ( err error ) {
if len ( skuIDs ) == 0 {
if len ( storeIDs ) == 0 || len ( skuIDs) == 0 {
return nil
}
var vendorIDs [ ] int
var storeMapMap map [ int ] [ ] * model . StoreMap
var storeSkuActMap map [ int64 ] * model . StoreSkuAct
if ! globals . IsStoreSkuAct {
if actVendorID >= 0 {
vendorIDs = [ ] int { actVendorID }
}
} else {
storeMapList , err := GetStoresMapList ( db , nil , storeIDs , model . StoreStatusAll , model . StoreIsSyncAll , "" )
if err != nil {
return err
}
storeMapMap = StoreMapList2Map ( storeMapList )
storeSkuActList , err2 := GetStoresSkusAct ( db , storeIDs , skuIDs , nil , 0 , 0 )
if err = err2 ; err != nil {
return err
}
storeSkuActMap = make ( map [ int64 ] * model . StoreSkuAct )
for _ , v := range storeSkuActList {
storeSkuActMap [ jxutils . Combine2Int ( int ( jxutils . Combine2Int ( v . StoreID , v . SkuID ) ) , v . VendorID ) ] = v
}
}
actStoreSkuList , err := GetEffectiveActStoreSkuInfo ( db , 0 , vendorIDs , model . ActTypeAll , storeIDs , skuIDs , time . Now ( ) , time . Now ( ) )
if err != nil {
globals . SugarLogger . Errorf ( "updateActPrice4StoreSkuNameNew can not get sku promotion info for error:%v" , err )
@@ -1221,7 +1261,7 @@ func UpdateActPrice4StoreSkuNameNew(db *DaoDB, storeIDs, skuIDs []int, skuNamesI
v . ActPrice = int ( actStoreSku . ActualActPrice )
v . ActID = actStoreSku . ActID
v . ActType = actStoreSku . Type
v . EarningPrice = int ( jxutils . CaculateSkuEarningPrice ( int64 ( v . Act Price) , int64 ( v . ActPrice ) , skuName . PayPercentage ) )
v . EarningPrice = int ( jxutils . CaculateSkuEarningPrice ( int64 ( v . Bind Price) , int64 ( v . ActPrice ) , skuName . PayPercentage ) )
}
if actStoreSku := actStoreSkuMap4EarningPrice . GetActStoreSku ( skuName . StoreID , v . SkuID , - 1 ) ; actStoreSku != nil {
v . EarningPrice = int ( actStoreSku . EarningPrice )
@@ -1232,6 +1272,47 @@ func UpdateActPrice4StoreSkuNameNew(db *DaoDB, storeIDs, skuIDs []int, skuNamesI
v . EarningPrice = earningPrice
}
}
if globals . IsStoreSkuAct {
v . VendorInfoMap = make ( map [ int ] * StoreSkuVendorInfo )
for _ , storeMap := range storeMapMap [ skuName . StoreID ] {
vendorID := storeMap . VendorID
vendorInfo := & StoreSkuVendorInfo {
VendorID : vendorID ,
}
vendorInfo . VendorPrice = refutil . GetObjFieldByName ( v , GetVendorPriceStructField ( model . VendorNames [ vendorID ] ) ) . ( int )
lockTime , _ := refutil . GetObjFieldByName ( v , GetVendorLockTimeStructField ( model . VendorNames [ vendorID ] ) ) . ( * time . Time )
vendorInfo . LockTime = lockTime
if vendorID != model . VendorIDJX {
vendorInfo . VendorSkuID = refutil . GetObjFieldByName ( v , GetVendorThingIDStructField ( model . VendorNames [ vendorID ] ) ) . ( string )
vendorInfo . SyncStatus = refutil . GetObjFieldByName ( v , GetSyncStatusStructField ( model . VendorNames [ vendorID ] ) ) . ( int8 )
}
if storeSkuAct := storeSkuActMap [ jxutils . Combine2Int ( int ( jxutils . Combine2Int ( skuName . StoreID , v . SkuID ) ) , vendorID ) ] ; storeSkuAct != nil {
vendorInfo . VendorActID = storeSkuAct . VendorActID
vendorInfo . ActPercentage = storeSkuAct . ActPercentage
vendorInfo . ActSyncStatus = storeSkuAct . SyncStatus
vendorInfo . VendorActPrice = storeSkuAct . VendorActPrice
}
if actStoreSku := actStoreSkuMap4Act . GetActStoreSku ( skuName . StoreID , v . SkuID , vendorID ) ; actStoreSku != nil {
vendorInfo . ActPrice = int ( actStoreSku . ActualActPrice )
vendorInfo . ActID = actStoreSku . ActID
vendorInfo . VendorActID = actStoreSku . VendorActID
vendorInfo . ActType = actStoreSku . Type
vendorInfo . EarningPrice = int ( jxutils . CaculateSkuEarningPrice ( int64 ( v . BindPrice ) , int64 ( v . ActPrice ) , skuName . PayPercentage ) )
}
if actStoreSku := actStoreSkuMap4EarningPrice . GetActStoreSku ( skuName . StoreID , v . SkuID , vendorID ) ; actStoreSku != nil {
vendorInfo . EarningPrice = int ( actStoreSku . EarningPrice )
vendorInfo . EarningActID = actStoreSku . ActID
} else {
earningPrice := int ( jxutils . CaculateSkuEarningPrice ( int64 ( v . BindPrice ) , int64 ( v . BindPrice ) , skuName . PayPercentage ) )
if v . EarningPrice == 0 || earningPrice < v . EarningPrice {
vendorInfo . EarningPrice = earningPrice
}
}
v . VendorInfoMap [ vendorID ] = vendorInfo
}
}
}
} else {
skuName . UnitPrice = skuName . Price