根据平台价刷新惊喜价
This commit is contained in:
@@ -178,6 +178,12 @@ type tStoreSkusSecKill struct {
|
|||||||
NoticeMsg string
|
NoticeMsg string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type JdStoreSkus struct {
|
||||||
|
JdStoreID int `json:"jdStoreID"`
|
||||||
|
JdSkuID int `json:"jdSkuID"`
|
||||||
|
Price int `json:"price"`
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
maxStoreNameBind = 10000 // 最大门店SkuName bind个数
|
maxStoreNameBind = 10000 // 最大门店SkuName bind个数
|
||||||
maxStoreNameBind2 = 10000 // 最大门店乘SkuName个数
|
maxStoreNameBind2 = 10000 // 最大门店乘SkuName个数
|
||||||
@@ -3536,3 +3542,94 @@ func SendSeckillSkusCountMsg(ctx *jxcontext.Context, vendorIDs []int, isAsync, i
|
|||||||
}
|
}
|
||||||
return hint, err
|
return hint, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RefreshJxPriceByVendor(ctx *jxcontext.Context, jdStoreSkus []*JdStoreSkus, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||||
|
var (
|
||||||
|
db = dao.GetDB()
|
||||||
|
jdMap = make(map[int][]*JdStoreSkus)
|
||||||
|
jxMap = make(map[int]map[int]int)
|
||||||
|
param []*StoreSkuBindInfo
|
||||||
|
)
|
||||||
|
taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||||
|
switch step {
|
||||||
|
case 0:
|
||||||
|
for _, v := range jdStoreSkus {
|
||||||
|
var (
|
||||||
|
pricePercentagePack []*model.PricePercentageItem
|
||||||
|
cats []*model.ThingMap
|
||||||
|
skus []*model.SkuAndName
|
||||||
|
)
|
||||||
|
sql := `
|
||||||
|
SELECT t1.*
|
||||||
|
FROM thing_map t1
|
||||||
|
WHERE t1.deleted_at = ? AND t1.thing_type = ?
|
||||||
|
AND t1.vendor_thing_id = ?
|
||||||
|
`
|
||||||
|
sqlParams := []interface{}{
|
||||||
|
utils.DefaultTimeValue,
|
||||||
|
model.ThingTypeSku,
|
||||||
|
v.JdSkuID,
|
||||||
|
}
|
||||||
|
err = dao.GetRows(db, &cats, sql, sqlParams...)
|
||||||
|
if len(cats) > 0 {
|
||||||
|
skus, err = dao.GetSkus(db, []int{int(cats[0].ThingID)}, nil, nil, nil)
|
||||||
|
if err != nil || len(skus) == 0 {
|
||||||
|
return result, fmt.Errorf("没有找到该京西skuID!,京西skuID :[%v]", cats[0].ThingID)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return result, fmt.Errorf("没有找到该京东skuID对应的京西skuID!,京东skuID :[%v]", v.JdSkuID)
|
||||||
|
}
|
||||||
|
store, err := dao.GetStoreDetailByVendorStoreID(db, utils.Int2Str(v.JdStoreID), model.VendorIDJD)
|
||||||
|
if err != nil || store == nil {
|
||||||
|
return result, fmt.Errorf("没有找到该京东门店对应的京西门店!,京东门店ID :[%v]", v.JdStoreID)
|
||||||
|
}
|
||||||
|
err = jxutils.Strings2Objs(store.PricePercentagePackStr, &pricePercentagePack)
|
||||||
|
jxPrice := jxutils.CaculateJxPriceByPricePack(pricePercentagePack, 0, v.Price)
|
||||||
|
jdMap[store.ID] = append(jdMap[store.ID], &JdStoreSkus{
|
||||||
|
JdSkuID: skus[0].NameID,
|
||||||
|
Price: jxPrice,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
for k, v := range jdMap {
|
||||||
|
var skuNameMap = make(map[int]int)
|
||||||
|
for _, vv := range v {
|
||||||
|
if skuNameMap[vv.JdSkuID] != 0 {
|
||||||
|
if skuNameMap[vv.JdSkuID] > vv.Price {
|
||||||
|
skuNameMap[vv.JdSkuID] = vv.Price
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
skuNameMap[vv.JdSkuID] = vv.Price
|
||||||
|
}
|
||||||
|
}
|
||||||
|
jxMap[k] = skuNameMap
|
||||||
|
}
|
||||||
|
for k, v := range jxMap {
|
||||||
|
for kk, vv := range v {
|
||||||
|
result, err := dao.GetStoreSkuBindByNameID(db, k, kk, model.SkuStatusNormal)
|
||||||
|
if len(result) > 0 && err == nil {
|
||||||
|
if result[0].UnitPrice > vv {
|
||||||
|
storeSkuBindInfo := &StoreSkuBindInfo{
|
||||||
|
StoreID: k,
|
||||||
|
NameID: kk,
|
||||||
|
UnitPrice: vv,
|
||||||
|
}
|
||||||
|
param = append(param, storeSkuBindInfo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case 1:
|
||||||
|
_, err = UpdateStoresSkusByBind(ctx, nil, param, isAsync, isContinueWhenError)
|
||||||
|
}
|
||||||
|
return result, err
|
||||||
|
}
|
||||||
|
taskSeq := tasksch.NewSeqTask2("根据京东平台价刷新京西平台价", ctx, isContinueWhenError, taskSeqFunc, 2)
|
||||||
|
tasksch.HandleTask(taskSeq, nil, true).Run()
|
||||||
|
if !isAsync {
|
||||||
|
_, err = taskSeq.GetResult(0)
|
||||||
|
hint = "1"
|
||||||
|
} else {
|
||||||
|
hint = taskSeq.GetID()
|
||||||
|
}
|
||||||
|
return hint, err
|
||||||
|
}
|
||||||
|
|||||||
@@ -668,3 +668,23 @@ func (c *StoreSkuController) SendSeckillSkusCountMsg() {
|
|||||||
return retVal, "", err
|
return retVal, "", err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Title 根据平台价反算京西价
|
||||||
|
// @Description 根据平台价反算京西价
|
||||||
|
// @Param token header string true "认证token"
|
||||||
|
// @Param payload formData string true "json数据,JdStoreSkus对象"
|
||||||
|
// @Param isAsync formData bool true "是否异步,缺省是同步"
|
||||||
|
// @Param isContinueWhenError formData bool true "单个同步失败是否继续,缺省false"
|
||||||
|
// @Success 200 {object} controllers.CallResult
|
||||||
|
// @Failure 200 {object} controllers.CallResult
|
||||||
|
// @router /RefreshJxPriceByVendor [put]
|
||||||
|
func (c *StoreSkuController) RefreshJxPriceByVendor() {
|
||||||
|
var skuBindInfos []*cms.JdStoreSkus
|
||||||
|
c.callRefreshJxPriceByVendor(func(params *tStoreSkuRefreshJxPriceByVendorParams) (retVal interface{}, errCode string, err error) {
|
||||||
|
if err = jxutils.Strings2Objs(params.Payload, &skuBindInfos); err != nil {
|
||||||
|
return retVal, "", err
|
||||||
|
}
|
||||||
|
retVal,err = cms.RefreshJxPriceByVendor(params.Ctx, skuBindInfos, params.IsAsync, params.IsContinueWhenError)
|
||||||
|
return retVal, "", err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -1863,6 +1863,15 @@ func init() {
|
|||||||
Filters: nil,
|
Filters: nil,
|
||||||
Params: nil})
|
Params: nil})
|
||||||
|
|
||||||
|
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"],
|
||||||
|
beego.ControllerComments{
|
||||||
|
Method: "RefreshJxPriceByVendor",
|
||||||
|
Router: `/RefreshJxPriceByVendor`,
|
||||||
|
AllowHTTPMethods: []string{"put"},
|
||||||
|
MethodParams: param.Make(),
|
||||||
|
Filters: nil,
|
||||||
|
Params: nil})
|
||||||
|
|
||||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"],
|
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"],
|
||||||
beego.ControllerComments{
|
beego.ControllerComments{
|
||||||
Method: "RefreshStoresSkuByVendor",
|
Method: "RefreshStoresSkuByVendor",
|
||||||
|
|||||||
Reference in New Issue
Block a user