- prevent modify promotion sku
This commit is contained in:
@@ -61,8 +61,9 @@ type SkuPrice struct {
|
|||||||
|
|
||||||
type tPromotionItemInfo struct {
|
type tPromotionItemInfo struct {
|
||||||
model.PromotionSku
|
model.PromotionSku
|
||||||
EndAt time.Time
|
EndAt time.Time
|
||||||
StoreID int `orm:"column(store_id)"`
|
JdStoreID string `orm:"column(vendor_store_id)"`
|
||||||
|
JdSkuID int64 `orm:"column(jd_id)"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type tSimpleStore struct {
|
type tSimpleStore struct {
|
||||||
@@ -604,14 +605,18 @@ func CancelJdPromotion(ctx *jxcontext.Context, promotionID int) (err error) {
|
|||||||
// 每晚凌晨运行一次
|
// 每晚凌晨运行一次
|
||||||
func RefreshJdLockStoreSku() (err error) {
|
func RefreshJdLockStoreSku() (err error) {
|
||||||
sql := `
|
sql := `
|
||||||
SELECT t1.end_at, t2.store_id, t3.*
|
SELECT t1.end_at, t22.vendor_store_id, t32.jd_id, t3.*
|
||||||
FROM promotion t1
|
FROM promotion t1
|
||||||
JOIN promotion_store t2 ON t1.id = t2.promotion_id
|
JOIN promotion_store t2 ON t1.id = t2.promotion_id
|
||||||
|
JOIN store_map t22 ON t2.store_id = t22.store_id AND t22.vendor_id = ? AND t22.deleted_at = ?
|
||||||
JOIN promotion_sku t3 ON t1.id = t3.promotion_id
|
JOIN promotion_sku t3 ON t1.id = t3.promotion_id
|
||||||
|
JOIN sku t32 ON t3.sku_id = t32.id
|
||||||
WHERE t1.deleted_at = ? AND t1.vendor_id = ? AND t1.status = ? AND (t1.beginAt <= ? AND t1.endAt >= ?)
|
WHERE t1.deleted_at = ? AND t1.vendor_id = ? AND t1.status = ? AND (t1.beginAt <= ? AND t1.endAt >= ?)
|
||||||
`
|
`
|
||||||
nowDate := utils.GetCurDate()
|
nowDate := utils.GetCurDate()
|
||||||
sqlParams := []interface{}{
|
sqlParams := []interface{}{
|
||||||
|
model.VendorIDJD,
|
||||||
|
utils.DefaultTimeValue,
|
||||||
utils.DefaultTimeValue,
|
utils.DefaultTimeValue,
|
||||||
model.VendorIDJD,
|
model.VendorIDJD,
|
||||||
model.PromotionStatusRemoteCreated,
|
model.PromotionStatusRemoteCreated,
|
||||||
@@ -651,9 +656,9 @@ func RefreshJdPromotionItemListLockStatus(promotionItemList []*tPromotionItemInf
|
|||||||
expire := promotionItemList[0].EndAt.Add(24 * time.Hour)
|
expire := promotionItemList[0].EndAt.Add(24 * time.Hour)
|
||||||
for _, item := range promotionItemList {
|
for _, item := range promotionItemList {
|
||||||
if item.IsLock != 0 {
|
if item.IsLock != 0 {
|
||||||
storeskulock.LockJdStoreSku(item.StoreID, item.SkuID, expire)
|
storeskulock.LockJdStoreSku(item.JdStoreID, item.JdSkuID, expire)
|
||||||
} else {
|
} else {
|
||||||
storeskulock.UnlockJdStoreSku(item.StoreID, item.SkuID)
|
storeskulock.UnlockJdStoreSku(item.JdStoreID, item.JdSkuID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -662,14 +667,18 @@ func RefreshJdPromotionItemListLockStatus(promotionItemList []*tPromotionItemInf
|
|||||||
|
|
||||||
func RefreshJdPromotionLockStatus(promotionID int) (err error) {
|
func RefreshJdPromotionLockStatus(promotionID int) (err error) {
|
||||||
sql := `
|
sql := `
|
||||||
SELECT t1.end_at, t2.store_id, t3.*, IF(t1.begin_at <= ? AND t1.end_at >= ? AND t1.status = ?, t3.is_lock, 0) is_lock
|
SELECT t1.end_at, t22.vendor_store_id, t32.jd_id, IF(t1.begin_at <= ? AND t1.end_at >= ? AND t1.status = ?, t3.is_lock, 0) is_lock, t3.*
|
||||||
FROM promotion t1
|
FROM promotion t1
|
||||||
JOIN promotion_store t2 ON t1.id = t2.promotion_id
|
JOIN promotion_store t2 ON t1.id = t2.promotion_id
|
||||||
|
JOIN store_map t22 ON t2.store_id = t22.store_id AND t22.vendor_id = ? AND t22.deleted_at = ?
|
||||||
JOIN promotion_sku t3 ON t1.id = t3.promotion_id
|
JOIN promotion_sku t3 ON t1.id = t3.promotion_id
|
||||||
|
JOIN sku t32 ON t3.sku_id = t32.id
|
||||||
WHERE t1.id = ?
|
WHERE t1.id = ?
|
||||||
`
|
`
|
||||||
nowDate := utils.GetCurDate()
|
nowDate := utils.GetCurDate()
|
||||||
sqlParams := []interface{}{
|
sqlParams := []interface{}{
|
||||||
|
model.VendorIDJD,
|
||||||
|
utils.DefaultTimeValue,
|
||||||
nowDate,
|
nowDate,
|
||||||
nowDate,
|
nowDate,
|
||||||
model.PromotionStatusRemoteCreated,
|
model.PromotionStatusRemoteCreated,
|
||||||
@@ -685,6 +694,38 @@ func RefreshJdPromotionLockStatus(promotionID int) (err error) {
|
|||||||
return RefreshJdPromotionItemListLockStatus(promotionItemList)
|
return RefreshJdPromotionItemListLockStatus(promotionItemList)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func OnStoreStockMsg(msg *jdapi.CallbackStoreStockMsg) (retVal *jdapi.CallbackResponse) {
|
||||||
|
var err error
|
||||||
|
if (msg.Vendibility == 1 || !msg.Have) && storeskulock.IsJdStoreSkuLocked(msg.StationNo, msg.SkuId) {
|
||||||
|
db := dao.GetDB()
|
||||||
|
if msg.Vendibility == 1 {
|
||||||
|
sku := &model.Sku{}
|
||||||
|
sku.JdID = msg.SkuId
|
||||||
|
if err = dao.GetEntity(db, sku); err == nil {
|
||||||
|
if msg.Vendibility == 1 {
|
||||||
|
vendibility := &jdapi.StockVendibility{
|
||||||
|
OutSkuId: utils.Int2Str(sku.ID),
|
||||||
|
DoSale: true,
|
||||||
|
}
|
||||||
|
_, err = api.JdAPI.BatchUpdateVendibility("", msg.StationNo, []*jdapi.StockVendibility{
|
||||||
|
vendibility,
|
||||||
|
}, "prevent")
|
||||||
|
}
|
||||||
|
if !msg.Have {
|
||||||
|
stock := &jdapi.SkuStock{
|
||||||
|
OutSkuId: utils.Int2Str(sku.ID),
|
||||||
|
StockQty: model.MaxStoreSkuStockQty,
|
||||||
|
}
|
||||||
|
_, err = api.JdAPI.BatchUpdateCurrentQtys("", msg.StationNo, []*jdapi.SkuStock{
|
||||||
|
stock,
|
||||||
|
}, "prevent")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return jdapi.Err2CallbackResponse(err, "")
|
||||||
|
}
|
||||||
|
|
||||||
func excelStr2Time(timeStr string) (tm time.Time, err error) {
|
func excelStr2Time(timeStr string) (tm time.Time, err error) {
|
||||||
return time.ParseInLocation("2006年1月2日15点4分5秒", timeStr, time.Local)
|
return time.ParseInLocation("2006年1月2日15点4分5秒", timeStr, time.Local)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,22 +11,22 @@ const (
|
|||||||
cacheKeyPrefix = "jdpromotion"
|
cacheKeyPrefix = "jdpromotion"
|
||||||
)
|
)
|
||||||
|
|
||||||
func LockJdStoreSku(storeID, skuID int, expire time.Time) {
|
func LockJdStoreSku(jdStoreID string, jdSkuID int64, expire time.Time) {
|
||||||
globals.SugarLogger.Debug(expire, " ", time.Now())
|
globals.SugarLogger.Debug(expire, " ", time.Now())
|
||||||
duration := expire.Sub(time.Now())
|
duration := expire.Sub(time.Now())
|
||||||
if duration > 0 {
|
if duration > 0 {
|
||||||
globals.Cacher.Set(genCacheKey(storeID, skuID), 1, duration)
|
globals.Cacher.Set(genCacheKey(jdStoreID, jdSkuID), 1, duration)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func UnlockJdStoreSku(storeID, skuID int) {
|
func UnlockJdStoreSku(jdStoreID string, jdSkuID int64) {
|
||||||
globals.Cacher.Del(genCacheKey(storeID, skuID))
|
globals.Cacher.Del(genCacheKey(jdStoreID, jdSkuID))
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsJdStoreSkuLocked(storeID, skuID int) bool {
|
func IsJdStoreSkuLocked(jdStoreID string, jdSkuID int64) bool {
|
||||||
return globals.Cacher.Get(genCacheKey(storeID, skuID)) != nil
|
return globals.Cacher.Get(genCacheKey(jdStoreID, jdSkuID)) != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func genCacheKey(storeID, skuID int) string {
|
func genCacheKey(jdStoreID string, jdSkuID int64) string {
|
||||||
return fmt.Sprintf("%s.%d.%d", cacheKeyPrefix, storeID, skuID)
|
return fmt.Sprintf("%s.%s.%d", cacheKeyPrefix, jdStoreID, jdSkuID)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ type tStoreSkuBindExt struct {
|
|||||||
model.StoreSkuBind
|
model.StoreSkuBind
|
||||||
PricePercentage int
|
PricePercentage int
|
||||||
VendorStoreID string `orm:"column(vendor_store_id)"`
|
VendorStoreID string `orm:"column(vendor_store_id)"`
|
||||||
|
JdID int64 `orm:"column(jd_id)"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// 京东到家,以有库存表示关注(认领)
|
// 京东到家,以有库存表示关注(认领)
|
||||||
@@ -36,9 +37,10 @@ func (p *PurchaseHandler) SyncStoreSkus(ctx *jxcontext.Context, parentTask tasks
|
|||||||
}
|
}
|
||||||
|
|
||||||
sql := `
|
sql := `
|
||||||
SELECT t1.*, t2.price_percentage, t2.vendor_store_id
|
SELECT t3.jd_id, t1.*, t2.price_percentage, t2.vendor_store_id
|
||||||
FROM store_sku_bind t1
|
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 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
|
||||||
` + sqlWhere + " ORDER BY t1.updated_at"
|
` + sqlWhere + " ORDER BY t1.updated_at"
|
||||||
var storeSkus []*tStoreSkuBindExt
|
var storeSkus []*tStoreSkuBindExt
|
||||||
sqlParams := []interface{}{
|
sqlParams := []interface{}{
|
||||||
@@ -70,7 +72,7 @@ func (p *PurchaseHandler) SyncStoreSkus(ctx *jxcontext.Context, parentTask tasks
|
|||||||
} else {
|
} else {
|
||||||
alreadyAddStock = true
|
alreadyAddStock = true
|
||||||
}
|
}
|
||||||
if stock.StockQty != 0 || !storeskulock.IsJdStoreSkuLocked(storeID, storeSku.SkuID) {
|
if stock.StockQty != 0 || !storeskulock.IsJdStoreSkuLocked(stationNo, storeSku.JdID) {
|
||||||
skuStockList = append(skuStockList, stock)
|
skuStockList = append(skuStockList, stock)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -94,7 +96,7 @@ func (p *PurchaseHandler) SyncStoreSkus(ctx *jxcontext.Context, parentTask tasks
|
|||||||
}
|
}
|
||||||
skuStockList = append(skuStockList, stock)
|
skuStockList = append(skuStockList, stock)
|
||||||
}
|
}
|
||||||
if vendibility.DoSale || !storeskulock.IsJdStoreSkuLocked(storeID, storeSku.SkuID) {
|
if vendibility.DoSale || !storeskulock.IsJdStoreSkuLocked(stationNo, storeSku.JdID) {
|
||||||
skuVendibilityList = append(skuVendibilityList, vendibility)
|
skuVendibilityList = append(skuVendibilityList, vendibility)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/platformapi/jdapi"
|
"git.rosy.net.cn/baseapi/platformapi/jdapi"
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/jxstore/promotion"
|
||||||
"git.rosy.net.cn/jx-callback/business/partner/purchase/jd"
|
"git.rosy.net.cn/jx-callback/business/partner/purchase/jd"
|
||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
"git.rosy.net.cn/jx-callback/globals/api"
|
"git.rosy.net.cn/jx-callback/globals/api"
|
||||||
@@ -99,7 +101,16 @@ func (c *DjswController) Token() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *DjswController) StockIsHave() {
|
func (c *DjswController) StockIsHave() {
|
||||||
globals.SugarLogger.Info(string(c.Ctx.Input.RequestBody))
|
// globals.SugarLogger.Info(string(c.Ctx.Input.RequestBody))
|
||||||
c.Data["json"] = jdapi.Err2CallbackResponse(nil, "")
|
if c.Ctx.Input.Method() == http.MethodPost {
|
||||||
c.ServeJSON()
|
obj, callbackResponse := api.JdAPI.GetStoreStockCallbackMsg(c.Ctx.Input.RequestBody)
|
||||||
|
if callbackResponse == nil {
|
||||||
|
globals.SugarLogger.Debugf("StockIsHave, obj:%s", utils.Format4Output(obj, false))
|
||||||
|
callbackResponse = promotion.OnStoreStockMsg(obj)
|
||||||
|
}
|
||||||
|
c.Data["json"] = callbackResponse
|
||||||
|
c.ServeJSON()
|
||||||
|
} else {
|
||||||
|
c.Abort("404")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user