定时更改商品可售状态
This commit is contained in:
@@ -116,13 +116,15 @@ type StoreSkuBindSkuInfo struct {
|
||||
|
||||
// UpdateStoreSku用,API调用时
|
||||
type StoreSkuBindInfo struct {
|
||||
StoreID int `json:"storeID"`
|
||||
NameID int `json:"nameID"`
|
||||
UnitPrice int `json:"unitPrice"` // 对于是份的SKU就是单价(每斤价格),其它则为总价
|
||||
IsFocus int `json:"isFocus"` // -1:不关注,0:忽略,1:关注
|
||||
IsSale int `json:"isSale"` // -1:不可售,0:忽略,1:可售
|
||||
SubStoreID int `json:"subStoreID,omitempty"`
|
||||
Skus []*StoreSkuBindSkuInfo `json:"skus,omitempty"`
|
||||
StoreID int `json:"storeID"`
|
||||
NameID int `json:"nameID"`
|
||||
UnitPrice int `json:"unitPrice"` // 对于是份的SKU就是单价(每斤价格),其它则为总价
|
||||
IsFocus int `json:"isFocus"` // -1:不关注,0:忽略,1:关注
|
||||
IsSale int `json:"isSale"` // -1:不可售,0:忽略,1:可售
|
||||
SubStoreID int `json:"subStoreID,omitempty"`
|
||||
StatusSaleBegin int `json:"statusSaleBegin"` //商品可售时间范围
|
||||
StatusSaleEnd int `json:"statusSaleEnd"`
|
||||
Skus []*StoreSkuBindSkuInfo `json:"skus,omitempty"`
|
||||
}
|
||||
|
||||
type tStoreSkuBindAndSpec struct {
|
||||
@@ -1076,6 +1078,12 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs
|
||||
updateFieldMap["Price"] = 1
|
||||
updateFieldMap["JxPrice"] = 1
|
||||
}
|
||||
if skuBindInfo.StatusSaleBegin != 0 && skuBindInfo.StatusSaleEnd != 0 {
|
||||
updateFieldMap["StatusSaleBegin"] = skuBindInfo.StatusSaleBegin
|
||||
updateFieldMap["StatusSaleEnd"] = skuBindInfo.StatusSaleEnd
|
||||
skuBind.StatusSaleBegin = skuBindInfo.StatusSaleBegin
|
||||
skuBind.StatusSaleEnd = skuBindInfo.StatusSaleEnd
|
||||
}
|
||||
// todo 这里应该是不需处理这个信息的吧?
|
||||
// if inSkuBind != nil && inSkuBind.EbaiID != 0 {
|
||||
// skuBind.EbaiID = inSkuBind.EbaiID
|
||||
|
||||
@@ -659,20 +659,18 @@ func (v *VendorSync) ChangeStoreSkuSaleStatus(ctx *jxcontext.Context, isAsync, i
|
||||
storeIDs []int
|
||||
skuIDs []int
|
||||
)
|
||||
vendorIDs := partner.GetPurchasePlatformVendorIDs()
|
||||
db := dao.GetDB()
|
||||
storeSkuList, err := dao.GetStoresSkusInfoBySaleTime(db)
|
||||
if len(storeSkuList) < 1 || err != nil {
|
||||
return errors.New(fmt.Sprintf("未查询到设置了可售时间的商品 GetStoresSkusInfoBySaleTime!err : %v", err))
|
||||
}
|
||||
for _, v := range storeSkuList {
|
||||
storeIDs = append(storeIDs, v.StoreID)
|
||||
skuIDs = append(skuIDs, v.SkuID)
|
||||
setStoreSkuBindStatus(v, model.SyncFlagSaleMask)
|
||||
dao.UpdateEntity(db, v)
|
||||
}
|
||||
if len(storeSkuList) > 0 {
|
||||
v.SyncStoresSkus(ctx, db, vendorIDs, storeIDs, skuIDs, false, isAsync, isContinueWhenError)
|
||||
} else {
|
||||
return errors.New("未查询到设置了可售时间的商品!")
|
||||
}
|
||||
vendorIDs := partner.GetPurchasePlatformVendorIDs()
|
||||
dao.UpdateStoreSkuBindSyncStatus(db, vendorIDs)
|
||||
v.SyncStoresSkus(ctx, db, vendorIDs, storeIDs, skuIDs, false, isAsync, isContinueWhenError)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -329,9 +329,9 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo
|
||||
if reorderHandler != nil {
|
||||
reorderSkuMap = make(map[string][]*dao.StoreSkuSyncInfo)
|
||||
}
|
||||
now := time.Now().Hour()*100 + time.Now().Minute()
|
||||
now := jxutils.OperationTime2HourMinuteFormat(time.Now())
|
||||
for _, sku := range skus {
|
||||
if isUpdateSkuSaleStatus(sku, now) {
|
||||
if isUpdateSkuSaleStatus(sku, storeDetail, now) {
|
||||
sku.MergedStatus = model.SkuStatusDontSale
|
||||
} else {
|
||||
sku.MergedStatus = model.SkuStatusNormal
|
||||
@@ -802,12 +802,27 @@ func GetSensitiveWord(singleStoreHandler partner.ISingleStoreStoreSkuHandler, st
|
||||
return ""
|
||||
}
|
||||
|
||||
func isUpdateSkuSaleStatus(sku *dao.StoreSkuSyncInfo, now int) bool {
|
||||
func isUpdateSkuSaleStatus(sku *dao.StoreSkuSyncInfo, storeDetail *dao.StoreDetail, now int) bool {
|
||||
//商品可售时间的差集与门店营业时间的交集为不可售,其余为原本状态
|
||||
openTime := sku.OpenTime
|
||||
closeTime := sku.CloseTime
|
||||
var openTime int
|
||||
var closeTime int
|
||||
saleBeginTime := sku.StatusSaleBegin
|
||||
saleEndTime := sku.StatusSaleEnd
|
||||
if storeDetail.OpenTime2 != 0 && storeDetail.CloseTime2 != 0 {
|
||||
if storeDetail.OpenTime1 < storeDetail.OpenTime2 {
|
||||
openTime = int(storeDetail.OpenTime1)
|
||||
} else {
|
||||
openTime = int(storeDetail.OpenTime2)
|
||||
}
|
||||
if storeDetail.CloseTime1 > storeDetail.CloseTime2 {
|
||||
closeTime = int(storeDetail.CloseTime1)
|
||||
} else {
|
||||
closeTime = int(storeDetail.CloseTime2)
|
||||
}
|
||||
} else {
|
||||
openTime = int(storeDetail.OpenTime1)
|
||||
closeTime = int(storeDetail.CloseTime1)
|
||||
}
|
||||
beginAt1, endAt1 := GetTimeMixByInt(0, saleBeginTime, openTime, closeTime)
|
||||
beginAt2, endAt2 := GetTimeMixByInt(saleEndTime, 2400, openTime, closeTime)
|
||||
if beginAt1 != 0 && endAt1 != 0 {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cms
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
@@ -30,3 +31,14 @@ func TestFreeBatchStoreSkuInfo(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetTimeMixByInt(t *testing.T) {
|
||||
var (
|
||||
time1 = 1100
|
||||
time2 = 2300
|
||||
time3 = 1200
|
||||
time4 = 2400
|
||||
)
|
||||
a, b := GetTimeMixByInt(time1, time2, time3, time4)
|
||||
fmt.Println(a, b)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user