From a039b31e39193bf43d901baa38fea546e2d20704 Mon Sep 17 00:00:00 2001 From: lyb Date: Fri, 10 Aug 2018 16:46:59 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E9=A5=BF=E4=BA=86=E4=B9=88=E5=8F=AF?= =?UTF-8?q?=E5=AE=9E=E6=97=B6=E8=8E=B7=E5=8F=96=E7=9A=84=E7=BB=93=E8=B4=A6?= =?UTF-8?q?=E5=BF=85=E8=A6=81=E4=BF=A1=E6=81=AF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/controller/elm/order.go | 26 +++++++++++++++++++++++++- business/model/const.go | 3 ++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/business/controller/elm/order.go b/business/controller/elm/order.go index 168a0ea52..db411da19 100644 --- a/business/controller/elm/order.go +++ b/business/controller/elm/order.go @@ -15,6 +15,7 @@ import ( "git.rosy.net.cn/jx-callback/business/jxutils" "git.rosy.net.cn/jx-callback/business/model" "git.rosy.net.cn/jx-callback/business/scheduler" + "git.rosy.net.cn/jx-callback/business/util" "git.rosy.net.cn/jx-callback/legacy/freshfood" ) @@ -179,7 +180,7 @@ func (c *OrderController) GetOrder(orderID string) (order *model.GoodsOrder, err VendorID: model.VendorIDELM, Count: int(utils.MustInterface2Int64(product["quantity"])), SkuID: int(utils.Str2Int64WithDefault(utils.Interface2String(product["extendCode"]), 0)), - VendorSkuID: utils.Int64ToStr(utils.MustInterface2Int64(product["skuId"])), + VendorSkuID: utils.Int64ToStr(utils.MustInterface2Int64(product["vfoodId"])), SkuName: product["name"].(string), SalePrice: jxutils.StandardPrice2Int(utils.MustInterface2Float64(product["price"])), Weight: int(math.Round(utils.Interface2FloatWithDefault(product["weight"], 0.0))), @@ -192,9 +193,32 @@ func (c *OrderController) GetOrder(orderID string) (order *model.GoodsOrder, err } } } + setOrederDetailFee(result, order) return order, err } +func setOrederDetailFee(result map[string]interface{}, order *model.GoodsOrder) { + var skuTotalPmFee, orderPmFee, skuTotalPmSubsidy, orderPmSubsidy int64 + orderActivities := result["orderActivities"].([]interface{}) + for _, value := range orderActivities { + activity := value.(map[string]interface{}) + categoryId := utils.MustInterface2Int64(activity["categoryId"]) + isHave, _ := util.ContainForInt64Arry(categoryId, model.ElmSkuPromotion) + if isHave == true { + skuTotalPmFee += -jxutils.StandardPrice2Int(utils.MustInterface2Float64(activity["restaurantPart"])) + skuTotalPmSubsidy += -jxutils.StandardPrice2Int(utils.MustInterface2Float64(activity["elemePart"])) + } else { + orderPmFee += -jxutils.StandardPrice2Int(utils.MustInterface2Float64(activity["restaurantPart"])) + orderPmSubsidy += -jxutils.StandardPrice2Int(utils.MustInterface2Float64(activity["elemePart"])) + } + } + order.SkuPmSubsidy = skuTotalPmSubsidy + order.SkuPmFee = skuTotalPmFee + order.OrderPmFee = orderPmFee + order.OrderPmSubsidy = orderPmSubsidy + order.PlatformFeeRate = int16(utils.MustInterface2Float64(result["serviceRate"])) +} + // func (c *OrderController) onOrderNew(msg map[string]interface{}) (response *elmapi.CallbackResponse) { // todo 这里应该可以直接用msg里的内容,而不用再次去查 diff --git a/business/model/const.go b/business/model/const.go index 7bed36380..f3803b4dc 100644 --- a/business/model/const.go +++ b/business/model/const.go @@ -125,7 +125,8 @@ const ( ) var ( - JdSkuPromotion = []int64{2, 3, 4, 6, 8, 1203, 8001, 9998, 9997, 9996} + JdSkuPromotion = []int64{2, 3, 4, 6, 8, 1203, 8001, 9998, 9997, 9996} + ElmSkuPromotion = []int64{11, 200} ) const ( From a6883fb56812e688d296cd558ed148e7bf4fb43c Mon Sep 17 00:00:00 2001 From: lyb Date: Fri, 10 Aug 2018 16:47:35 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E8=AE=BF=E9=97=AE=E4=BA=AC=E4=B8=9CAPI?= =?UTF-8?q?=EF=BC=8C=E8=8E=B7=E5=8F=96=E7=BB=93=E8=B4=A6=E5=BF=85=E8=A6=81?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/controller/elm/order_test.go | 32 +++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 business/controller/elm/order_test.go diff --git a/business/controller/elm/order_test.go b/business/controller/elm/order_test.go new file mode 100644 index 000000000..d0a3f8faf --- /dev/null +++ b/business/controller/elm/order_test.go @@ -0,0 +1,32 @@ +package elm + +import ( + "testing" + + "git.rosy.net.cn/jx-callback/globals" + "git.rosy.net.cn/jx-callback/globals/api" + "git.rosy.net.cn/jx-callback/globals/db" + "github.com/astaxie/beego" +) + +func init() { + //E:/goprojects/src/git.rosy.net.cn/jx-callback/conf/app.conf + ///Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf + beego.InitBeegoBeforeTest("Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf") + beego.BConfig.RunMode = "dev" // InitBeegoBeforeTest会将runmode设置为test + + globals.Init() + db.Init() + api.Init() +} + +func Test_GetOrder(t *testing.T) { + orderID := "3025427524410871880" + order, err := new(OrderController).GetOrder(orderID) + if err != nil { + panic(err.Error()) + } + if order.VendorOrderID != orderID { + panic(err.Error()) + } +} From 01d3221d3aadf7448ef29505654209d5c3f3ebe7 Mon Sep 17 00:00:00 2001 From: lyb Date: Fri, 10 Aug 2018 16:51:57 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E8=AE=BF=E9=97=AE=E9=A5=BF=E4=BA=86?= =?UTF-8?q?=E4=B9=88API=EF=BC=8C=E8=8E=B7=E5=8F=96=E7=BB=93=E8=B4=A6?= =?UTF-8?q?=E5=BF=85=E8=A6=81=E4=BF=A1=E6=81=AF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/util/Contain.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 business/util/Contain.go diff --git a/business/util/Contain.go b/business/util/Contain.go new file mode 100644 index 000000000..9966db076 --- /dev/null +++ b/business/util/Contain.go @@ -0,0 +1,15 @@ +package util + +import ( + "errors" +) + +// 判断obj是否在target中,target支持的类型arrary,slice +func ContainForInt64Arry(obj int64, target []int64) (bool, error) { + for _, value := range target { + if value == obj { + return true, nil + } + } + return false, errors.New("not in array") +} From aac9881f6a84c5355f07a0cf4a5553fbc02a8c10 Mon Sep 17 00:00:00 2001 From: lyb Date: Fri, 10 Aug 2018 17:30:07 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/controller/elm/order.go | 19 +++++++------------ business/model/const.go | 6 ++++-- business/util/Contain.go | 15 --------------- 3 files changed, 11 insertions(+), 29 deletions(-) delete mode 100644 business/util/Contain.go diff --git a/business/controller/elm/order.go b/business/controller/elm/order.go index db411da19..44a5efb4d 100644 --- a/business/controller/elm/order.go +++ b/business/controller/elm/order.go @@ -15,7 +15,6 @@ import ( "git.rosy.net.cn/jx-callback/business/jxutils" "git.rosy.net.cn/jx-callback/business/model" "git.rosy.net.cn/jx-callback/business/scheduler" - "git.rosy.net.cn/jx-callback/business/util" "git.rosy.net.cn/jx-callback/legacy/freshfood" ) @@ -198,24 +197,20 @@ func (c *OrderController) GetOrder(orderID string) (order *model.GoodsOrder, err } func setOrederDetailFee(result map[string]interface{}, order *model.GoodsOrder) { - var skuTotalPmFee, orderPmFee, skuTotalPmSubsidy, orderPmSubsidy int64 orderActivities := result["orderActivities"].([]interface{}) for _, value := range orderActivities { activity := value.(map[string]interface{}) categoryId := utils.MustInterface2Int64(activity["categoryId"]) - isHave, _ := util.ContainForInt64Arry(categoryId, model.ElmSkuPromotion) - if isHave == true { - skuTotalPmFee += -jxutils.StandardPrice2Int(utils.MustInterface2Float64(activity["restaurantPart"])) - skuTotalPmSubsidy += -jxutils.StandardPrice2Int(utils.MustInterface2Float64(activity["elemePart"])) + restaurantPart := -jxutils.StandardPrice2Int(utils.MustInterface2Float64(activity["restaurantPart"])) + elemePart := -jxutils.StandardPrice2Int(utils.MustInterface2Float64(activity["elemePart"])) + if _, isHave := model.ElmSkuPromotion[int(categoryId)]; isHave { + order.SkuPmFee += restaurantPart + order.SkuPmSubsidy += elemePart } else { - orderPmFee += -jxutils.StandardPrice2Int(utils.MustInterface2Float64(activity["restaurantPart"])) - orderPmSubsidy += -jxutils.StandardPrice2Int(utils.MustInterface2Float64(activity["elemePart"])) + order.OrderPmFee += restaurantPart + order.OrderPmSubsidy += elemePart } } - order.SkuPmSubsidy = skuTotalPmSubsidy - order.SkuPmFee = skuTotalPmFee - order.OrderPmFee = orderPmFee - order.OrderPmSubsidy = orderPmSubsidy order.PlatformFeeRate = int16(utils.MustInterface2Float64(result["serviceRate"])) } diff --git a/business/model/const.go b/business/model/const.go index f3803b4dc..69097d23e 100644 --- a/business/model/const.go +++ b/business/model/const.go @@ -125,8 +125,10 @@ const ( ) var ( - JdSkuPromotion = []int64{2, 3, 4, 6, 8, 1203, 8001, 9998, 9997, 9996} - ElmSkuPromotion = []int64{11, 200} + ElmSkuPromotion = map[int]string{ + 11: "1", + 200: "1", + } ) const ( diff --git a/business/util/Contain.go b/business/util/Contain.go deleted file mode 100644 index 9966db076..000000000 --- a/business/util/Contain.go +++ /dev/null @@ -1,15 +0,0 @@ -package util - -import ( - "errors" -) - -// 判断obj是否在target中,target支持的类型arrary,slice -func ContainForInt64Arry(obj int64, target []int64) (bool, error) { - for _, value := range target { - if value == obj { - return true, nil - } - } - return false, errors.New("not in array") -} From 1a647ea5f2fb7f673077b45449d84776b49a18af Mon Sep 17 00:00:00 2001 From: lyb Date: Fri, 10 Aug 2018 17:36:09 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/controller/elm/order.go | 2 +- business/controller/elm/order_test.go | 2 +- business/model/const.go | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/business/controller/elm/order.go b/business/controller/elm/order.go index 44a5efb4d..aef73b72d 100644 --- a/business/controller/elm/order.go +++ b/business/controller/elm/order.go @@ -203,7 +203,7 @@ func setOrederDetailFee(result map[string]interface{}, order *model.GoodsOrder) categoryId := utils.MustInterface2Int64(activity["categoryId"]) restaurantPart := -jxutils.StandardPrice2Int(utils.MustInterface2Float64(activity["restaurantPart"])) elemePart := -jxutils.StandardPrice2Int(utils.MustInterface2Float64(activity["elemePart"])) - if _, isHave := model.ElmSkuPromotion[int(categoryId)]; isHave { + if _, ok := model.ElmSkuPromotion[int(categoryId)]; ok { order.SkuPmFee += restaurantPart order.SkuPmSubsidy += elemePart } else { diff --git a/business/controller/elm/order_test.go b/business/controller/elm/order_test.go index d0a3f8faf..2968fa458 100644 --- a/business/controller/elm/order_test.go +++ b/business/controller/elm/order_test.go @@ -20,7 +20,7 @@ func init() { api.Init() } -func Test_GetOrder(t *testing.T) { +func TestGetOrder(t *testing.T) { orderID := "3025427524410871880" order, err := new(OrderController).GetOrder(orderID) if err != nil { diff --git a/business/model/const.go b/business/model/const.go index 69097d23e..cdd7b9599 100644 --- a/business/model/const.go +++ b/business/model/const.go @@ -125,9 +125,9 @@ const ( ) var ( - ElmSkuPromotion = map[int]string{ - 11: "1", - 200: "1", + ElmSkuPromotion = map[int]int{ + 11: 1, + 200: 1, } )