diff --git a/business/jxcallback/orderman/order.go b/business/jxcallback/orderman/order.go index 248931811..4004cede6 100644 --- a/business/jxcallback/orderman/order.go +++ b/business/jxcallback/orderman/order.go @@ -352,7 +352,7 @@ func caculateOrderEarningPrice(order *model.GoodsOrder, storePayPercentage int) if skuEarningPrice == 0 { skuEarningPrice = jxutils.CaculateSkuEarningPrice(v.ShopPrice, v.SalePrice, storePayPercentage) } - order.EarningPrice += skuEarningPrice + order.EarningPrice += skuEarningPrice * int64(v.Count) } } diff --git a/business/jxstore/promotion/jd_promotion.go b/business/jxstore/promotion/jd_promotion.go index 7bd391e79..cab1b7c7b 100644 --- a/business/jxstore/promotion/jd_promotion.go +++ b/business/jxstore/promotion/jd_promotion.go @@ -298,79 +298,81 @@ func CreateJdPromotion(ctx *jxcontext.Context, vendorID int, isIDJd bool, isAsyn return "", err } if len(conflictPromotion) > 0 { - return "", fmt.Errorf("有冲突配置:%s", utils.Format4Output(conflictPromotion, true)) + return "", fmt.Errorf("有冲突配置:%s", utils.Format4Output(conflictPromotion, false)) } } - if vendorPromotionID == "" && vendorID == model.VendorIDJD { - sql := ` + if vendorPromotionID == "" { + if vendorID == model.VendorIDJD { + sql := ` SELECT t1.*, t2.jd_id, t3.vendor_store_id FROM store_sku_bind t1 JOIN sku t2 ON t1.sku_id = t2.id JOIN store_map t3 ON t1.store_id = t3.store_id AND t3.vendor_id = ? AND t3.deleted_at = ? WHERE t1.deleted_at = ? ` - sqlParam := []interface{}{ - model.VendorIDJD, - utils.DefaultTimeValue, - utils.DefaultTimeValue, - skuIDs, - } - if isIDJd { - sql += " AND t2.jd_id IN (" + dao.GenQuestionMarks(len(skuIDs)) + ") AND t3.vendor_store_id = ?" - } else { - sql += " AND t1.sku_id IN (" + dao.GenQuestionMarks(len(skuIDs)) + ") AND t1.store_id = ?" - } + sqlParam := []interface{}{ + model.VendorIDJD, + utils.DefaultTimeValue, + utils.DefaultTimeValue, + skuIDs, + } + if isIDJd { + sql += " AND t2.jd_id IN (" + dao.GenQuestionMarks(len(skuIDs)) + ") AND t3.vendor_store_id = ?" + } else { + sql += " AND t1.sku_id IN (" + dao.GenQuestionMarks(len(skuIDs)) + ") AND t1.store_id = ?" + } - errMsg := "" - index := 0 - for _, storeID := range params.StoreIDs { - var skuBinds []*tStoreSkuBindExt - if err = dao.GetRows(db, &skuBinds, sql, append(sqlParam, storeID)...); err != nil { - return "", err - } - for k, skuBind := range skuBinds { - if k == 0 { - jxStoreIDs = append(jxStoreIDs, skuBind.StoreID) + errMsg := "" + index := 0 + for _, storeID := range params.StoreIDs { + var skuBinds []*tStoreSkuBindExt + if err = dao.GetRows(db, &skuBinds, sql, append(sqlParam, storeID)...); err != nil { + return "", err } - mapSkuID := int64(skuBind.SkuID) - if isIDJd { - mapSkuID = skuBind.JdSkuID - } - promotionSkuPrice := skuPriceMap[mapSkuID] - if promotionSkuPrice.PriceType == PriceTypePercentage { - promotionSkuPrice.Price = skuBind.Price * promotionSkuPrice.Price / 100 - } - if vendorID != model.VendorIDJX && promotionSkuPrice.Price >= skuBind.Price { - errMsg += fmt.Sprintf("活动价大于等于原价,storeID:%d, skuID:%d\n", skuBind.StoreID, skuBind.SkuID) - } - if promotionSkuPrice.LimitSkuCount <= 0 { - promotionSkuPrice.LimitSkuCount = DefaultLimitSkuCount - } - if errMsg == "" { - if params.Type == PromotionTypeLimitedTime { - if skuBind.Price*PromotionLimitedTimeMinPercentage/100 < promotionSkuPrice.Price { - modifyPricesList[skuBind.StoreID] = append(modifyPricesList[skuBind.StoreID], &jdapi.SkuPriceInfo{ - OutSkuId: utils.Int2Str(skuBind.SkuID), - Price: promotionSkuPrice.Price*100/PromotionLimitedTimeMinPercentage + 5, - }) + for k, skuBind := range skuBinds { + if k == 0 { + jxStoreIDs = append(jxStoreIDs, skuBind.StoreID) + } + mapSkuID := int64(skuBind.SkuID) + if isIDJd { + mapSkuID = skuBind.JdSkuID + } + promotionSkuPrice := skuPriceMap[mapSkuID] + if promotionSkuPrice.PriceType == PriceTypePercentage { + promotionSkuPrice.Price = skuBind.Price * promotionSkuPrice.Price / 100 + } + if vendorID != model.VendorIDJX && promotionSkuPrice.Price >= skuBind.Price { + errMsg += fmt.Sprintf("活动价大于等于原价,storeID:%d, skuID:%d\n", skuBind.StoreID, skuBind.SkuID) + } + if promotionSkuPrice.LimitSkuCount <= 0 { + promotionSkuPrice.LimitSkuCount = DefaultLimitSkuCount + } + if errMsg == "" { + if params.Type == PromotionTypeLimitedTime { + if skuBind.Price*PromotionLimitedTimeMinPercentage/100 < promotionSkuPrice.Price { + modifyPricesList[skuBind.StoreID] = append(modifyPricesList[skuBind.StoreID], &jdapi.SkuPriceInfo{ + OutSkuId: utils.Int2Str(skuBind.SkuID), + Price: promotionSkuPrice.Price*100/PromotionLimitedTimeMinPercentage + 5, + }) + } } + promotionPrices[index] = &jdapi.PromotionSku{ + StationNo: utils.Str2Int64(skuBind.VendorStoreID), + SkuID: skuBind.JdSkuID, + PromotionPrice: int64(promotionSkuPrice.Price), + LimitSkuCount: promotionSkuPrice.LimitSkuCount, + } + index++ } - promotionPrices[index] = &jdapi.PromotionSku{ - StationNo: utils.Str2Int64(skuBind.VendorStoreID), - SkuID: skuBind.JdSkuID, - PromotionPrice: int64(promotionSkuPrice.Price), - LimitSkuCount: promotionSkuPrice.LimitSkuCount, - } - index++ } } - } - if errMsg != "" { - return "", errors.New(errMsg) - } - promotionPrices = promotionPrices[:index] - if len(promotionPrices) == 0 { - return "", ErrEmptySkus + if errMsg != "" { + return "", errors.New(errMsg) + } + promotionPrices = promotionPrices[:index] + if len(promotionPrices) == 0 { + return "", ErrEmptySkus + } } } else { promotion.VendorPromotionID = vendorPromotionID @@ -665,7 +667,7 @@ func CancelJdPromotion(ctx *jxcontext.Context, promotionID int) (err error) { if err = dao.GetEntity(db, promotion); err != nil { return err } - if promotion.Status != model.PromotionStatusCanceled { + if promotion.Status == model.PromotionStatusCanceled { return errors.New("当前状态已经是取消") } if promotion.Status == model.PromotionStatusRemoteCreated {