- make OnNewPromotionMsg asnyc
- set limit... in CreateJdPromotion - correct limitPint to limitPin
This commit is contained in:
@@ -262,6 +262,10 @@ func CreateJdPromotion(ctx *jxcontext.Context, isIDJd bool, isAsync, isContinueW
|
|||||||
VendorID: model.VendorIDJD,
|
VendorID: model.VendorIDJD,
|
||||||
Type: params.Type,
|
Type: params.Type,
|
||||||
Status: model.PromotionStatusLocalCreated,
|
Status: model.PromotionStatusLocalCreated,
|
||||||
|
LimitDevice: int8(limitDevice),
|
||||||
|
LimitPin: int8(limitPin),
|
||||||
|
LimitCount: limitCount,
|
||||||
|
LimitDaily: int8(limitDaily),
|
||||||
BeginAt: params.BeginAt,
|
BeginAt: params.BeginAt,
|
||||||
EndAt: params.EndAt,
|
EndAt: params.EndAt,
|
||||||
CreateType: model.PromotionCreateTypeByJX,
|
CreateType: model.PromotionCreateTypeByJX,
|
||||||
@@ -482,56 +486,6 @@ func CreateJdPromotion(ctx *jxcontext.Context, isIDJd bool, isAsync, isContinueW
|
|||||||
return hint, err
|
return hint, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// func CreatePromotionByExcel(ctx *jxcontext.Context, isAsync bool, promotionType int, fileHeader *multipart.FileHeader, userName string) (hint string, err error) {
|
|
||||||
// file, err := fileHeader.Open()
|
|
||||||
// if err != nil {
|
|
||||||
// return "", err
|
|
||||||
// }
|
|
||||||
// contents := excel.Excel2Slice(file)
|
|
||||||
// file.Close()
|
|
||||||
// var promotionParams *PromotionParams
|
|
||||||
// for _, v := range contents {
|
|
||||||
// promotionParams = &PromotionParams{
|
|
||||||
// Name: v[1][colNameIndex],
|
|
||||||
// Type: promotionType,
|
|
||||||
// }
|
|
||||||
// if promotionParams.BeginAt, err = excelStr2Time(v[1][colBeginAtIndex]); err != nil {
|
|
||||||
// return "", err
|
|
||||||
// }
|
|
||||||
// if promotionParams.EndAt, err = excelStr2Time(v[1][colEndAtIndex]); err != nil {
|
|
||||||
// return "", err
|
|
||||||
// }
|
|
||||||
|
|
||||||
// for rowIndex, row := range v {
|
|
||||||
// if rowIndex > 0 {
|
|
||||||
// isBreak := true
|
|
||||||
// if row[colSkuIDIndex] != "" {
|
|
||||||
// isBreak = false
|
|
||||||
// jdSkuID := int(utils.Str2Int64(row[colSkuIDIndex]))
|
|
||||||
// promotionParams.SkuPrices = append(promotionParams.SkuPrices, &SkuPrice{
|
|
||||||
// SkuID: jdSkuID,
|
|
||||||
// PriceType: PriceTypePrice,
|
|
||||||
// Price: int(jxutils.StandardPrice2Int(utils.Str2Float64(row[colSkuPriceIndex]))),
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
// if row[colStoreIDIndex] != "" {
|
|
||||||
// isBreak = false
|
|
||||||
// jdStoreID := int(utils.Str2Int64(row[colStoreIDIndex]))
|
|
||||||
// promotionParams.StoreIDs = append(promotionParams.StoreIDs, jdStoreID)
|
|
||||||
// }
|
|
||||||
// if isBreak {
|
|
||||||
// break
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// break
|
|
||||||
// }
|
|
||||||
// // globals.SugarLogger.Debug(utils.Format4Output(promotionParams, false))
|
|
||||||
// // globals.SugarLogger.Debug(isAsync)
|
|
||||||
// return CreateJdPromotion(ctx, true, isAsync, promotionParams, userName)
|
|
||||||
// }
|
|
||||||
|
|
||||||
func GetJdPromotions(ctx *jxcontext.Context, keyword string, params map[string]interface{}, offset, pageSize int) (pagedInfo *model.PagedInfo, err error) {
|
func GetJdPromotions(ctx *jxcontext.Context, keyword string, params map[string]interface{}, offset, pageSize int) (pagedInfo *model.PagedInfo, err error) {
|
||||||
sql := `
|
sql := `
|
||||||
SELECT SQL_CALC_FOUND_ROWS
|
SELECT SQL_CALC_FOUND_ROWS
|
||||||
@@ -933,91 +887,95 @@ func OnNewPromotionMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackRespo
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createLocalPromotionFromRemote(promotionInfoId int64) (retVal *jdapi.CallbackResponse) {
|
func createLocalPromotionFromRemote(promotionInfoId int64) (retVal *jdapi.CallbackResponse) {
|
||||||
result, err := api.JdAPI.QueryPromotionInfo(promotionInfoId)
|
go func() {
|
||||||
if err == nil {
|
result, err := api.JdAPI.QueryPromotionInfo(promotionInfoId)
|
||||||
db := dao.GetDB()
|
if err == nil {
|
||||||
promotion := &model.Promotion{
|
db := dao.GetDB()
|
||||||
VendorPromotionID: utils.Int64ToStr(promotionInfoId),
|
promotion := &model.Promotion{
|
||||||
}
|
VendorPromotionID: utils.Int64ToStr(promotionInfoId),
|
||||||
if err = dao.GetEntity(db, promotion, "VendorPromotionID"); dao.IsNoRowsError(err) {
|
|
||||||
storeIDMap := make(map[int64]int)
|
|
||||||
skuIDMap := make(map[int64]int)
|
|
||||||
skuMap := make(map[int64]*jdapi.PromotionSkuResult)
|
|
||||||
// 注意,这样处理可能是有问题,我们假定的是门店信息与SKU信息的叉乘
|
|
||||||
for _, v := range result.SkuResultList {
|
|
||||||
storeIDMap[v.StationNo] = 1
|
|
||||||
skuIDMap[v.SkuId] = 1
|
|
||||||
skuMap[v.SkuId] = v
|
|
||||||
}
|
}
|
||||||
jdStoreIDs := make([]string, len(storeIDMap))
|
if err = dao.GetEntity(db, promotion, "VendorPromotionID"); dao.IsNoRowsError(err) {
|
||||||
index := 0
|
storeIDMap := make(map[int64]int)
|
||||||
for k := range storeIDMap {
|
skuIDMap := make(map[int64]int)
|
||||||
jdStoreIDs[index] = utils.Int64ToStr(k)
|
skuMap := make(map[int64]*jdapi.PromotionSkuResult)
|
||||||
index++
|
// 注意,这样处理可能是有问题,我们假定的是门店信息与SKU信息的叉乘
|
||||||
}
|
for _, v := range result.SkuResultList {
|
||||||
jdSkuIDs := jxutils.Int64Map2List(skuIDMap)
|
storeIDMap[v.StationNo] = 1
|
||||||
|
skuIDMap[v.SkuId] = 1
|
||||||
|
skuMap[v.SkuId] = v
|
||||||
|
}
|
||||||
|
jdStoreIDs := make([]string, len(storeIDMap))
|
||||||
|
index := 0
|
||||||
|
for k := range storeIDMap {
|
||||||
|
jdStoreIDs[index] = utils.Int64ToStr(k)
|
||||||
|
index++
|
||||||
|
}
|
||||||
|
jdSkuIDs := jxutils.Int64Map2List(skuIDMap)
|
||||||
|
|
||||||
var skuList []*model.Sku
|
var skuList []*model.Sku
|
||||||
var storeMapList []*model.StoreMap
|
var storeMapList []*model.StoreMap
|
||||||
if err = dao.GetRows(db, &storeMapList, `
|
if err = dao.GetRows(db, &storeMapList, `
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM store_map
|
FROM store_map
|
||||||
WHERE vendor_id = ? AND deleted_at = ? AND vendor_store_id IN (`+
|
WHERE vendor_id = ? AND deleted_at = ? AND vendor_store_id IN (`+
|
||||||
dao.GenQuestionMarks(len(jdStoreIDs))+")",
|
dao.GenQuestionMarks(len(jdStoreIDs))+")",
|
||||||
model.VendorIDJD, utils.DefaultTimeValue, jdStoreIDs); err != nil {
|
model.VendorIDJD, utils.DefaultTimeValue, jdStoreIDs); err != nil {
|
||||||
return jdapi.Err2CallbackResponse(err, "")
|
globals.SugarLogger.Warnf("createLocalPromotionFromRemote get storeMapList failed with error:%v", err)
|
||||||
}
|
return
|
||||||
if err = dao.GetRows(db, &skuList, `
|
}
|
||||||
|
if err = dao.GetRows(db, &skuList, `
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM sku
|
FROM sku
|
||||||
WHERE jd_id IN (`+
|
WHERE jd_id IN (`+
|
||||||
dao.GenQuestionMarks(len(jdSkuIDs))+")",
|
dao.GenQuestionMarks(len(jdSkuIDs))+")",
|
||||||
jdSkuIDs); err != nil {
|
jdSkuIDs); err != nil {
|
||||||
return jdapi.Err2CallbackResponse(err, "")
|
globals.SugarLogger.Warnf("createLocalPromotionFromRemote get skuList failed with error:%v", err)
|
||||||
}
|
return
|
||||||
jxStoreIDs := make([]int, len(storeMapList))
|
}
|
||||||
for k, v := range storeMapList {
|
jxStoreIDs := make([]int, len(storeMapList))
|
||||||
jxStoreIDs[k] = v.StoreID
|
for k, v := range storeMapList {
|
||||||
}
|
jxStoreIDs[k] = v.StoreID
|
||||||
priceList := make([]*SkuPrice, len(skuList))
|
}
|
||||||
var skuResult *jdapi.PromotionSkuResult
|
priceList := make([]*SkuPrice, len(skuList))
|
||||||
for k, v := range skuList {
|
var skuResult *jdapi.PromotionSkuResult
|
||||||
skuResult = skuMap[v.JdID]
|
for k, v := range skuList {
|
||||||
priceList[k] = &SkuPrice{
|
skuResult = skuMap[v.JdID]
|
||||||
SkuID: v.ID,
|
priceList[k] = &SkuPrice{
|
||||||
PriceType: PriceTypePrice,
|
SkuID: v.ID,
|
||||||
Price: skuResult.PromotionPrice,
|
PriceType: PriceTypePrice,
|
||||||
LimitSkuCount: 0,
|
Price: skuResult.PromotionPrice,
|
||||||
IsLock: 0,
|
LimitSkuCount: 0,
|
||||||
|
IsLock: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// globals.SugarLogger.Debugf("jxStoreIDs:%s", utils.Format4Output(jxStoreIDs, false))
|
||||||
|
// globals.SugarLogger.Debugf("priceList:%s", utils.Format4Output(priceList, false))
|
||||||
|
promotionParams := &PromotionParams{
|
||||||
|
Name: result.Source + "-" + utils.Int64ToStr(result.PromotionInfoId),
|
||||||
|
Advertising: "",
|
||||||
|
Type: result.PromotionType,
|
||||||
|
BeginAt: result.BeginTime,
|
||||||
|
EndAt: result.EndTime,
|
||||||
|
StoreIDs: jxStoreIDs,
|
||||||
|
SkuPrices: priceList,
|
||||||
|
}
|
||||||
|
mapData := map[string]interface{}{
|
||||||
|
keyPromotionStatus: jd2jxPromotionStatusMap[result.PromotionState],
|
||||||
|
keyPromotionSource: result.Source,
|
||||||
|
}
|
||||||
|
if skuResult != nil {
|
||||||
|
mapData[keyLimitDaily] = skuResult.LimitDaily
|
||||||
|
mapData[keyLimitDevice] = skuResult.LimitDevice
|
||||||
|
mapData[keyLimitPin] = skuResult.LimitPin
|
||||||
|
}
|
||||||
|
_, err = CreateJdPromotion(jxcontext.AdminCtx, false, true, false, utils.Int64ToStr(promotionInfoId), promotionParams, mapData)
|
||||||
|
if dao.IsDuplicateError(err) || err == ErrLimitDeviceIsInvalid {
|
||||||
|
err = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// globals.SugarLogger.Debugf("jxStoreIDs:%s", utils.Format4Output(jxStoreIDs, false))
|
|
||||||
// globals.SugarLogger.Debugf("priceList:%s", utils.Format4Output(priceList, false))
|
|
||||||
promotionParams := &PromotionParams{
|
|
||||||
Name: result.Source + "-" + utils.Int64ToStr(result.PromotionInfoId),
|
|
||||||
Advertising: "",
|
|
||||||
Type: result.PromotionType,
|
|
||||||
BeginAt: result.BeginTime,
|
|
||||||
EndAt: result.EndTime,
|
|
||||||
StoreIDs: jxStoreIDs,
|
|
||||||
SkuPrices: priceList,
|
|
||||||
}
|
|
||||||
mapData := map[string]interface{}{
|
|
||||||
keyPromotionStatus: jd2jxPromotionStatusMap[result.PromotionState],
|
|
||||||
keyPromotionSource: result.Source,
|
|
||||||
}
|
|
||||||
if skuResult != nil {
|
|
||||||
mapData[keyLimitDaily] = skuResult.LimitDaily
|
|
||||||
mapData[keyLimitDevice] = skuResult.LimitDevice
|
|
||||||
mapData[keyLimitPin] = skuResult.LimitPin
|
|
||||||
}
|
|
||||||
_, err = CreateJdPromotion(jxcontext.AdminCtx, false, true, false, utils.Int64ToStr(promotionInfoId), promotionParams, mapData)
|
|
||||||
if dao.IsDuplicateError(err) || err == ErrLimitDeviceIsInvalid {
|
|
||||||
err = nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}()
|
||||||
return jdapi.Err2CallbackResponse(err, "")
|
return jdapi.Err2CallbackResponse(nil, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func excelStr2Time(timeStr string) (tm time.Time, err error) {
|
func excelStr2Time(timeStr string) (tm time.Time, err error) {
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ type Promotion struct {
|
|||||||
Type int `json:"type"`
|
Type int `json:"type"`
|
||||||
Status int `json:"status"`
|
Status int `json:"status"`
|
||||||
LimitDevice int8 `json:"limitDevice"`
|
LimitDevice int8 `json:"limitDevice"`
|
||||||
LimitPint int8 `json:"limitPint"`
|
LimitPin int8 `json:"limitPin"`
|
||||||
LimitDaily int8 `json:"limitDaily"`
|
LimitDaily int8 `json:"limitDaily"`
|
||||||
LimitCount int `json:"limitCount"`
|
LimitCount int `json:"limitCount"`
|
||||||
Source string `orm:"size(255)" json:"source"`
|
Source string `orm:"size(255)" json:"source"`
|
||||||
|
|||||||
Reference in New Issue
Block a user