From b6303b70134221809e57aacfd0a45ab552588fb9 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 18 Jun 2019 17:19:25 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E6=B7=BB=E5=8A=A0=E4=BA=AC=E8=A5=BF?= =?UTF-8?q?=E6=B4=BB=E5=8A=A8=EF=BC=8C=E7=94=A8=E4=BA=8E=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E6=B4=BB=E5=8A=A8=E5=95=86=E5=93=81=E7=BB=93=E7=AE=97=E4=BB=B7?= =?UTF-8?q?=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxcallback/orderman/order.go | 41 +++++++++++++++++++ business/jxcallback/orderman/orderman_ext.go | 5 ++- business/jxstore/promotion/jd_promotion.go | 43 +++++++++++++++++--- business/model/const.go | 2 +- business/model/order.go | 1 + business/model/promotion.go | 2 + conf/app.conf | 4 +- controllers/promotion.go | 24 ++++++++++- routers/commentsRouter_controllers.go | 9 ++++ 9 files changed, 120 insertions(+), 11 deletions(-) diff --git a/business/jxcallback/orderman/order.go b/business/jxcallback/orderman/order.go index eb031d6d7..fb9a9a441 100644 --- a/business/jxcallback/orderman/order.go +++ b/business/jxcallback/orderman/order.go @@ -236,6 +236,29 @@ func (c *OrderManager) SaveOrder(order *model.GoodsOrder, isAdjust bool, db *dao return isDuplicated, err } +func getPromotionSkuPriceMap(db *dao.DaoDB, storeID int, skuIDs []int) (skuPriceMap map[int64]*model.PromotionSku, err error) { + sql := ` + SELECT t3.* + FROM promotion t1 + JOIN promotion_store t2 ON t2.promotion_id = t1.id AND t2.store_id = ? + JOIN promotion_sku t3 ON t3.promotion_id = t1.id AND t3.sku_id IN (` + dao.GenQuestionMarks(len(skuIDs)) + `) AND t3.earning_price > 0 + WHERE t1.deleted_at = ? AND (t1.status = ? OR t1.status = ?) AND (t1.begin_at <= NOW() AND t1.end_at >= NOW()) AND t1.vendor_id = ?` + var skuPriceList []*model.PromotionSku + if err = dao.GetRows(db, &skuPriceList, sql, storeID, skuIDs, utils.DefaultTimeValue, model.PromotionStatusLocalCreated, model.PromotionStatusRemoteCreated, model.VendorIDJX); err != nil { + return nil, err + } + skuPriceMap = make(map[int64]*model.PromotionSku) + for _, v := range skuPriceList { + if v.EarningPrice > 0 { + index := jxutils.Combine2Int(v.SkuID, v.Price) + if skuPriceMap[index] == nil || v.EarningPrice < skuPriceMap[index].EarningPrice { + skuPriceMap[index] = v + } + } + } + return skuPriceMap, err +} + func (c *OrderManager) updateOrderSkuOtherInfo(order *model.GoodsOrder, db *dao.DaoDB) (err error) { globals.SugarLogger.Debugf("updateOrderSkuOtherInfo orderID:%s, VendorStoreID:%s", order.VendorOrderID, order.VendorStoreID) jxStoreID := jxutils.GetShowStoreIDFromOrder(order) @@ -253,11 +276,16 @@ func (c *OrderManager) updateOrderSkuOtherInfo(order *model.GoodsOrder, db *dao. orderSkus := order.Skus vendorSkuIDs := make([]int64, 0) + skuIDMap := make(map[int]int) for _, v := range orderSkus { intVendorSkuID := utils.Str2Int64WithDefault(v.VendorSkuID, 0) if intVendorSkuID != 0 { vendorSkuIDs = append(vendorSkuIDs, intVendorSkuID) } + + if skuID := jxutils.GetSkuIDFromOrderSku(v); skuID > 0 { + skuIDMap[skuID] = 1 + } } if len(vendorSkuIDs) > 0 { tableName := "t2" @@ -281,6 +309,12 @@ func (c *OrderManager) updateOrderSkuOtherInfo(order *model.GoodsOrder, db *dao. skumapper[v.VendorSkuID] = v } + skuPriceMap, err2 := getPromotionSkuPriceMap(db, jxStoreID, jxutils.IntMap2List(skuIDMap)) + if err = err2; err != nil { + globals.SugarLogger.Errorf("updateOrderSkuOtherInfo can not get sku promotion info for orderID:%s, error:%v", order.VendorOrderID, err) + return err + } + for _, v := range orderSkus { v.VendorOrderID = order.VendorOrderID v.VendorID = order.VendorID @@ -300,6 +334,13 @@ func (c *OrderManager) updateOrderSkuOtherInfo(order *model.GoodsOrder, db *dao. } } } + + if skuID := jxutils.GetSkuIDFromOrderSku(v); skuID > 0 && v.StoreSubName != "" { + index := jxutils.Combine2Int(jxStoreID, int(v.SalePrice)) + if skuPriceMap[index] != nil { + v.EarningPrice = int64(skuPriceMap[index].EarningPrice) + } + } } } return nil diff --git a/business/jxcallback/orderman/orderman_ext.go b/business/jxcallback/orderman/orderman_ext.go index 064aa27e9..8eca3932f 100644 --- a/business/jxcallback/orderman/orderman_ext.go +++ b/business/jxcallback/orderman/orderman_ext.go @@ -88,6 +88,7 @@ func (c *OrderManager) GetOrderSkuInfo(ctx *jxcontext.Context, vendorOrderID str t1.sku_name, IF(t1.shop_price = 0, t1.sale_price, t1.shop_price) shop_price, t1.sale_price, + t1.earning_price, t1.weight, t1.sku_type, t1.promotion_type, @@ -116,6 +117,7 @@ func (c *OrderManager) GetOrderSkuInfo(ctx *jxcontext.Context, vendorOrderID str t1.sku_name, IF(t1.shop_price = 0, t1.sale_price, t1.shop_price) shop_price, t1.sale_price, + t1.earning_price, t1.weight, t1.sku_type, t1.promotion_type, @@ -145,6 +147,7 @@ func (c *OrderManager) GetOrderSkuInfo(ctx *jxcontext.Context, vendorOrderID str t1.sku_name, IF(t1.shop_price = 0, t1.sale_price, t1.shop_price) shop_price, t1.sale_price, + t1.earning_price, t1.weight, t1.sku_type, t1.promotion_type, @@ -285,7 +288,7 @@ func (c *OrderManager) getOrders(ctx *jxcontext.Context, isIncludeSku bool, from t2.actual_fee, t2.desired_fee, t2.waybill_created_at, t2.waybill_finished_at` if isIncludeSku { sql += `, - t3.sku_id, t3.count sku_count2, t3.shop_price sku_shop_price, t3.sale_price sku_sale_price` + t3.sku_id, t3.count sku_count2, t3.shop_price sku_shop_price, IF(t3.earning_price <> 0, t3.earning_price, t3.sale_price) sku_sale_price` } sql += ` FROM goods_order t1 diff --git a/business/jxstore/promotion/jd_promotion.go b/business/jxstore/promotion/jd_promotion.go index 93ff15499..9bcc4610c 100644 --- a/business/jxstore/promotion/jd_promotion.go +++ b/business/jxstore/promotion/jd_promotion.go @@ -72,6 +72,8 @@ type SkuPrice struct { Price int `json:"price"` // 分,这个不是单价,是这个sku的活动价 LimitSkuCount int `json:"limitSkuCount"` IsLock int8 `json:"isLock"` + + EarningPrice int `json:"earningPrice"` // 活动商品设置,结算给门店老板的钱 } type tPromotionItemInfo struct { @@ -230,10 +232,13 @@ func Init() { // scheduleRoutine(true) } -func CreateJdPromotion(ctx *jxcontext.Context, isIDJd bool, isAsync, isContinueWhenError bool, vendorPromotionID string, params *PromotionParams, mapData map[string]interface{}) (hint string, err error) { +func CreateJdPromotion(ctx *jxcontext.Context, vendorID int, isIDJd bool, isAsync, isContinueWhenError bool, vendorPromotionID string, params *PromotionParams, mapData map[string]interface{}) (hint string, err error) { if vendorPromotionID != "" && len(vendorPromotionID) != len("14863853") { return "", fmt.Errorf("%s看起来不像是一个有效的京东活动ID,请仔细检查一下", vendorPromotionID) } + if vendorID != model.VendorIDJD && vendorID != model.VendorIDJX { + return "", fmt.Errorf("当前只支持京西与京东活动") + } if len(params.SkuPrices) == 0 { return "", ErrEmptySkus } @@ -265,7 +270,7 @@ func CreateJdPromotion(ctx *jxcontext.Context, isIDJd bool, isAsync, isContinueW promotion := &model.Promotion{ Name: params.Name, Advertising: params.Advertising, - VendorID: model.VendorIDJD, + VendorID: vendorID, Type: params.Type, Status: model.PromotionStatusLocalCreated, LimitDevice: int8(limitDevice), @@ -323,7 +328,7 @@ func CreateJdPromotion(ctx *jxcontext.Context, isIDJd bool, isAsync, isContinueW if promotionSkuPrice.PriceType == PriceTypePercentage { promotionSkuPrice.Price = skuBind.Price * promotionSkuPrice.Price / 100 } - if promotionSkuPrice.Price >= skuBind.Price { + if vendorID != model.VendorIDJX && promotionSkuPrice.Price >= skuBind.Price { errMsg += fmt.Sprintf("活动价大于等于原价,storeID:%d, skuID:%d\n", skuBind.StoreID, skuBind.SkuID) } if promotionSkuPrice.LimitSkuCount <= 0 { @@ -407,7 +412,7 @@ func CreateJdPromotion(ctx *jxcontext.Context, isIDJd bool, isAsync, isContinueW } } - if vendorPromotionID == "" { + if vendorID != model.VendorIDJX && vendorPromotionID == "" { promotionHandler := getPromotionHander(params.Type) if promotionHandler == nil { return "", errors.New("非法的活动类型") @@ -879,6 +884,34 @@ func LockPromotionSkus(ctx *jxcontext.Context, promotionID int, isLock int, skuI return num, err } +func UpdatePromotionSkusEarningPrice(ctx *jxcontext.Context, promotionID int, skuPriceList []*SkuPrice) (num int64, err error) { + db := dao.GetDB() + dao.Begin(db) + defer func() { + if r := recover(); r != nil || err != nil { + dao.Rollback(db) + if r != nil { + panic(r) + } + } + }() + for _, v := range skuPriceList { + var tmpNum int64 + if tmpNum, err = dao.UpdateEntityLogically(db, &model.PromotionSku{}, map[string]interface{}{ + "EarningPrice": v.EarningPrice, + }, ctx.GetUserName(), map[string]interface{}{ + "PromotionID": promotionID, + model.FieldSkuID: v.SkuID, + model.FieldDeletedAt: utils.DefaultTimeValue, + }); err != nil { + return 0, err + } + num += tmpNum + } + dao.Commit(db) + return num, err +} + func OnStoreStockMsg(msg *jdapi.CallbackStoreStockMsg) (retVal *jdapi.CallbackResponse) { var err error // globals.SugarLogger.Debugf("OnStoreStockMsg IsJdStoreSkuLocked:%t", storeskulock.IsJdStoreSkuLocked(msg.StationNo, msg.SkuId)) @@ -1000,7 +1033,7 @@ func createLocalPromotionFromRemote(promotionInfoId int64) (retVal *jdapi.Callba mapData[keyLimitDevice] = skuResult.LimitDevice mapData[keyLimitPin] = skuResult.LimitPin } - _, err = CreateJdPromotion(jxcontext.AdminCtx, false, true, false, utils.Int64ToStr(promotionInfoId), promotionParams, mapData) + _, err = CreateJdPromotion(jxcontext.AdminCtx, model.VendorIDJD, false, true, false, utils.Int64ToStr(promotionInfoId), promotionParams, mapData) if dao.IsDuplicateError(err) || err == ErrLimitDeviceIsInvalid { err = nil } diff --git a/business/model/const.go b/business/model/const.go index 482089873..b46de96e6 100644 --- a/business/model/const.go +++ b/business/model/const.go @@ -14,9 +14,9 @@ const ( VendorIDMTWM = 1 VendorIDELM = 2 VendorIDEBAI = 3 - VendorIDJX = 9 // 这是一个假的京西VendorID VendorIDWSC = 11 // 微盟微商城 VendorIDPurchaseEnd = 11 + VendorIDJX = 99 // 这是一个假的京西VendorID VendorIDDeliveryBegin = 101 VendorIDDada = 101 diff --git a/business/model/order.go b/business/model/order.go index 2d27ac8d9..bbde7a557 100644 --- a/business/model/order.go +++ b/business/model/order.go @@ -91,6 +91,7 @@ type OrderSku struct { ShopPrice int64 `json:"shopPrice"` // 京西价 VendorPrice int64 `json:"vendorPrice"` // 平台价 SalePrice int64 `json:"salePrice"` // 售卖价 + EarningPrice int64 `json:"earningPrice"` // 活动商品设置,结算给门店老板的钱 Weight int `json:"weight"` // 单位为克 SkuType int `json:"skuType"` // 当前如果为gift就为1,否则缺省为0 PromotionType int `json:"promotionType"` // todo 当前是用于记录京东的PromotionType(生成jxorder用),没有做转换 diff --git a/business/model/promotion.go b/business/model/promotion.go index 2d33f2101..0b79d5b34 100644 --- a/business/model/promotion.go +++ b/business/model/promotion.go @@ -75,6 +75,8 @@ type PromotionSku struct { Price int `json:"price"` // 分,活动价,这个不是单价 LimitSkuCount int `json:"limitSkuCount"` IsLock int8 `json:"isLock"` // 是否锁定门店商品信息 + + EarningPrice int `json:"earningPrice"` // 活动商品设置,结算给门店老板的钱 } func (*PromotionSku) TableUnique() [][]string { diff --git a/conf/app.conf b/conf/app.conf index 15f5ae65e..54dc6320c 100644 --- a/conf/app.conf +++ b/conf/app.conf @@ -283,8 +283,8 @@ elmToken = "" elmAppKey = "KLRDcOZGrk" elmSecret = "1fc221f8265506531da36fb613d5f5ad673f2e9a" -ebaiSource = "62289" -ebaiSecret = "d3ec2358d6a819ea" +ebaiSource = "34665" +ebaiSecret = "c3db75b754ea2d89" mtpsAppKey = "3c0a05d464c247c19d7ec13accc78605" mtpsSecret = "b1M}9?:sTbsB[OF2gNORnN(|(iy9rB8(`7]|[wGLnbmt`evfM>E:A90DjHAW:UPE" diff --git a/controllers/promotion.go b/controllers/promotion.go index fb44be4c9..ef8321bd2 100644 --- a/controllers/promotion.go +++ b/controllers/promotion.go @@ -3,6 +3,8 @@ package controllers import ( "errors" + "git.rosy.net.cn/jx-callback/business/jxutils" + "github.com/astaxie/beego" "git.rosy.net.cn/baseapi/utils" @@ -17,7 +19,7 @@ type PromotionController struct { // @Title 创建活动 // @Description 创建活动 // @Param token header string true "认证token" -// @Param vendorID formData int true "厂商ID,当前只支持京东:0 " +// @Param vendorID formData int true "厂商ID,当前只支持,京东:0,京西(用于记录活动信息):99" // @Param name formData string true "活动名,必须唯一(所以名子上最好带上日期)" // @Param beginAt formData string true "开始日期" // @Param endAt formData string true "结束日期" @@ -57,7 +59,7 @@ func (c *PromotionController) CreatePromotion() { } if err = utils.UnmarshalUseNumber([]byte(params.StoreIDs), &promotionParams.StoreIDs); err == nil { if err = utils.UnmarshalUseNumber([]byte(params.SkuPrices), &promotionParams.SkuPrices); err == nil { - retVal, err = promotion.CreateJdPromotion(params.Ctx, false, params.IsAsync, params.IsContinueWhenError, params.VendorPromotionID, promotionParams, params.MapData) + retVal, err = promotion.CreateJdPromotion(params.Ctx, params.VendorID, false, params.IsAsync, params.IsContinueWhenError, params.VendorPromotionID, promotionParams, params.MapData) } } return retVal, "", err @@ -177,6 +179,24 @@ func (c *PromotionController) LockPromotionSkus() { }) } +// @Title 修改活动商品门店结算价 +// @Description 修改活动商品门店结算价 +// @Param token header string true "认证token" +// @Param promotionID formData int true "活动id" +// @Param skuPrices formData string true "json数据,价格信息列表(只有EarningPrice有效)" +// @Success 200 {object} controllers.CallResult +// @Failure 200 {object} controllers.CallResult +// @router /UpdatePromotionSkusEarningPrice [put] +func (c *PromotionController) UpdatePromotionSkusEarningPrice() { + c.callUpdatePromotionSkusEarningPrice(func(params *tPromotionUpdatePromotionSkusEarningPriceParams) (retVal interface{}, errCode string, err error) { + var skuPriceList []*promotion.SkuPrice + if err = jxutils.Strings2Objs(params.SkuPrices, &skuPriceList); err == nil { + retVal, err = promotion.UpdatePromotionSkusEarningPrice(params.Ctx, params.PromotionID, skuPriceList) + } + return retVal, "", err + }) +} + // @Title 从远程更新活动状态 // @Description 从远程更新活动状态 // @Param token header string true "认证token" diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index 4b0f5bcc1..82f7e70ae 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -862,6 +862,15 @@ func init() { Filters: nil, Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:PromotionController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:PromotionController"], + beego.ControllerComments{ + Method: "UpdatePromotionSkusEarningPrice", + Router: `/UpdatePromotionSkusEarningPrice`, + AllowHTTPMethods: []string{"put"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SkuController"], beego.ControllerComments{ Method: "AddCategory",