- make OnNewPromotionMsg asnyc

- set limit... in CreateJdPromotion
- correct limitPint to limitPin
This commit is contained in:
gazebo
2018-11-08 17:49:57 +08:00
parent 7f8a7e7820
commit 7ce06d275b
2 changed files with 83 additions and 125 deletions

View File

@@ -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,6 +887,7 @@ func OnNewPromotionMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackRespo
} }
func createLocalPromotionFromRemote(promotionInfoId int64) (retVal *jdapi.CallbackResponse) { func createLocalPromotionFromRemote(promotionInfoId int64) (retVal *jdapi.CallbackResponse) {
go func() {
result, err := api.JdAPI.QueryPromotionInfo(promotionInfoId) result, err := api.JdAPI.QueryPromotionInfo(promotionInfoId)
if err == nil { if err == nil {
db := dao.GetDB() db := dao.GetDB()
@@ -965,7 +920,8 @@ func createLocalPromotionFromRemote(promotionInfoId int64) (retVal *jdapi.Callba
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 *
@@ -973,7 +929,8 @@ func createLocalPromotionFromRemote(promotionInfoId int64) (retVal *jdapi.Callba
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)) jxStoreIDs := make([]int, len(storeMapList))
for k, v := range storeMapList { for k, v := range storeMapList {
@@ -1017,7 +974,8 @@ func createLocalPromotionFromRemote(promotionInfoId int64) (retVal *jdapi.Callba
} }
} }
} }
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) {

View File

@@ -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"`