- 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,
|
||||
Type: params.Type,
|
||||
Status: model.PromotionStatusLocalCreated,
|
||||
LimitDevice: int8(limitDevice),
|
||||
LimitPin: int8(limitPin),
|
||||
LimitCount: limitCount,
|
||||
LimitDaily: int8(limitDaily),
|
||||
BeginAt: params.BeginAt,
|
||||
EndAt: params.EndAt,
|
||||
CreateType: model.PromotionCreateTypeByJX,
|
||||
@@ -482,56 +486,6 @@ func CreateJdPromotion(ctx *jxcontext.Context, isIDJd bool, isAsync, isContinueW
|
||||
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) {
|
||||
sql := `
|
||||
SELECT SQL_CALC_FOUND_ROWS
|
||||
@@ -933,91 +887,95 @@ func OnNewPromotionMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackRespo
|
||||
}
|
||||
|
||||
func createLocalPromotionFromRemote(promotionInfoId int64) (retVal *jdapi.CallbackResponse) {
|
||||
result, err := api.JdAPI.QueryPromotionInfo(promotionInfoId)
|
||||
if err == nil {
|
||||
db := dao.GetDB()
|
||||
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
|
||||
go func() {
|
||||
result, err := api.JdAPI.QueryPromotionInfo(promotionInfoId)
|
||||
if err == nil {
|
||||
db := dao.GetDB()
|
||||
promotion := &model.Promotion{
|
||||
VendorPromotionID: utils.Int64ToStr(promotionInfoId),
|
||||
}
|
||||
jdStoreIDs := make([]string, len(storeIDMap))
|
||||
index := 0
|
||||
for k := range storeIDMap {
|
||||
jdStoreIDs[index] = utils.Int64ToStr(k)
|
||||
index++
|
||||
}
|
||||
jdSkuIDs := jxutils.Int64Map2List(skuIDMap)
|
||||
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))
|
||||
index := 0
|
||||
for k := range storeIDMap {
|
||||
jdStoreIDs[index] = utils.Int64ToStr(k)
|
||||
index++
|
||||
}
|
||||
jdSkuIDs := jxutils.Int64Map2List(skuIDMap)
|
||||
|
||||
var skuList []*model.Sku
|
||||
var storeMapList []*model.StoreMap
|
||||
if err = dao.GetRows(db, &storeMapList, `
|
||||
var skuList []*model.Sku
|
||||
var storeMapList []*model.StoreMap
|
||||
if err = dao.GetRows(db, &storeMapList, `
|
||||
SELECT *
|
||||
FROM store_map
|
||||
WHERE vendor_id = ? AND deleted_at = ? AND vendor_store_id IN (`+
|
||||
dao.GenQuestionMarks(len(jdStoreIDs))+")",
|
||||
model.VendorIDJD, utils.DefaultTimeValue, jdStoreIDs); err != nil {
|
||||
return jdapi.Err2CallbackResponse(err, "")
|
||||
}
|
||||
if err = dao.GetRows(db, &skuList, `
|
||||
dao.GenQuestionMarks(len(jdStoreIDs))+")",
|
||||
model.VendorIDJD, utils.DefaultTimeValue, jdStoreIDs); err != nil {
|
||||
globals.SugarLogger.Warnf("createLocalPromotionFromRemote get storeMapList failed with error:%v", err)
|
||||
return
|
||||
}
|
||||
if err = dao.GetRows(db, &skuList, `
|
||||
SELECT *
|
||||
FROM sku
|
||||
WHERE jd_id IN (`+
|
||||
dao.GenQuestionMarks(len(jdSkuIDs))+")",
|
||||
jdSkuIDs); err != nil {
|
||||
return jdapi.Err2CallbackResponse(err, "")
|
||||
}
|
||||
jxStoreIDs := make([]int, len(storeMapList))
|
||||
for k, v := range storeMapList {
|
||||
jxStoreIDs[k] = v.StoreID
|
||||
}
|
||||
priceList := make([]*SkuPrice, len(skuList))
|
||||
var skuResult *jdapi.PromotionSkuResult
|
||||
for k, v := range skuList {
|
||||
skuResult = skuMap[v.JdID]
|
||||
priceList[k] = &SkuPrice{
|
||||
SkuID: v.ID,
|
||||
PriceType: PriceTypePrice,
|
||||
Price: skuResult.PromotionPrice,
|
||||
LimitSkuCount: 0,
|
||||
IsLock: 0,
|
||||
dao.GenQuestionMarks(len(jdSkuIDs))+")",
|
||||
jdSkuIDs); err != nil {
|
||||
globals.SugarLogger.Warnf("createLocalPromotionFromRemote get skuList failed with error:%v", err)
|
||||
return
|
||||
}
|
||||
jxStoreIDs := make([]int, len(storeMapList))
|
||||
for k, v := range storeMapList {
|
||||
jxStoreIDs[k] = v.StoreID
|
||||
}
|
||||
priceList := make([]*SkuPrice, len(skuList))
|
||||
var skuResult *jdapi.PromotionSkuResult
|
||||
for k, v := range skuList {
|
||||
skuResult = skuMap[v.JdID]
|
||||
priceList[k] = &SkuPrice{
|
||||
SkuID: v.ID,
|
||||
PriceType: PriceTypePrice,
|
||||
Price: skuResult.PromotionPrice,
|
||||
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) {
|
||||
|
||||
@@ -30,7 +30,7 @@ type Promotion struct {
|
||||
Type int `json:"type"`
|
||||
Status int `json:"status"`
|
||||
LimitDevice int8 `json:"limitDevice"`
|
||||
LimitPint int8 `json:"limitPint"`
|
||||
LimitPin int8 `json:"limitPin"`
|
||||
LimitDaily int8 `json:"limitDaily"`
|
||||
LimitCount int `json:"limitCount"`
|
||||
Source string `orm:"size(255)" json:"source"`
|
||||
|
||||
Reference in New Issue
Block a user