From f87e7ce3ef64ce55e4572b365c0351adb861c3f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Thu, 30 Jul 2020 11:41:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E8=AE=A2=E5=8D=95=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxutils/weixinmsg/weixinmsg.go | 6 +- business/partner/purchase/jdshop/callback.go | 165 ++++++++++++++++--- 2 files changed, 146 insertions(+), 25 deletions(-) diff --git a/business/jxutils/weixinmsg/weixinmsg.go b/business/jxutils/weixinmsg/weixinmsg.go index cbdf4a3a6..16f5ba45f 100644 --- a/business/jxutils/weixinmsg/weixinmsg.go +++ b/business/jxutils/weixinmsg/weixinmsg.go @@ -181,7 +181,11 @@ func getOrderDetailBrief(order *model.GoodsOrder) (brief string) { if beego.BConfig.RunMode == "jxgy" { price = order.EarningPrice } else { - price = order.ShopPrice + if order.EarningType == model.EarningTypePoints { + price = order.ActualPayPrice + } else { + price = order.ShopPrice + } } sb.WriteString(jxutils.IntPrice2StandardString(price)) sb.WriteString("元") diff --git a/business/partner/purchase/jdshop/callback.go b/business/partner/purchase/jdshop/callback.go index 1ce845dbc..83190df89 100644 --- a/business/partner/purchase/jdshop/callback.go +++ b/business/partner/purchase/jdshop/callback.go @@ -1,39 +1,156 @@ package jdshop import ( + "fmt" + "math" + "time" + + "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" + + "git.rosy.net.cn/baseapi/platformapi/dingdingapi" "git.rosy.net.cn/baseapi/platformapi/jcqapi" "git.rosy.net.cn/baseapi/platformapi/jdshopapi" + "git.rosy.net.cn/baseapi/utils" + "git.rosy.net.cn/jx-callback/business/jxstore/common" + "git.rosy.net.cn/jx-callback/business/jxutils" + "git.rosy.net.cn/jx-callback/business/jxutils/ddmsg" + "git.rosy.net.cn/jx-callback/business/model" + "git.rosy.net.cn/jx-callback/business/model/dao" + "git.rosy.net.cn/jx-callback/business/partner" + "git.rosy.net.cn/jx-callback/globals" + "git.rosy.net.cn/jx-callback/globals/api" ) func OnCallbackMsg(msg *jdshopapi.CallBackResult) (err error) { msgType := msg.MsgType switch msgType { case jcqapi.TopicOrderPay: + jxutils.CallMsgHandler(func() { + SaveJdsOrders(msg) + }, jxutils.ComposeUniversalOrderID(msg.OrderID, model.VendorIDJDShop)) default: - return + return fmt.Errorf("暂不支持的topic类型!topic: %v", msgType) } - // if CurPurchaseHandler != nil { - // if msg.Cmd == mtwmapi.MsgTypeStoreStatusChanged { - // response = CurPurchaseHandler.onStoreStatusChanged(msg) - // } else if msg.Cmd == mtwmapi.MsgTypePrivateNumberDowngrade { - // response = CurPurchaseHandler.onNumberDowngrade(msg) - // } else { - // if orderID := GetOrderIDFromMsg(msg); orderID != "" { - // jxutils.CallMsgHandler(func() { - // switch msg.Cmd { - // case mtwmapi.MsgTypeWaybillStatus: - // response = CurPurchaseHandler.onWaybillMsg(msg) - // default: - // response = CurPurchaseHandler.onOrderMsg(msg) - // } - // }, jxutils.ComposeUniversalOrderID(orderID, model.VendorIDMTWM)) - // } - // /*if msg.Cmd == mtwmapi.MsgTypeOrderRefund || msg.Cmd == mtwmapi.MsgTypeOrderPartialRefund { - // utils.CallFuncAsync(func() { - // OnFinancialMsg(msg) - // }) - // } */ - // } - // } return err } + +func SaveJdsOrders(msg *jdshopapi.CallBackResult) (err error) { + order, err := result2Orders(msg) + order.StoreID = 102919 + order.JxStoreID = 102919 + order.StoreName = "商城模板(成都发货)" + order.VendorStoreID = model.JdShopMainVendorStoreID + partner.CurOrderManager.OnOrderNew(order, model.Order2Status(order)) + noticeMsg := fmt.Sprintf("京东商城新订单,订单号:[%v] ,将要发到的门店id:[%v] , 门店名:[%v]", order.VendorOrderID, order.StoreID, order.StoreName) + ddmsg.SendUserMessage(dingdingapi.MsgTyeText, "DDC5657B43EE11E9A9FF525400E86DC0", "京东商城来新订单了!", noticeMsg) + ddmsg.SendUserMessage(dingdingapi.MsgTyeText, "1439B3E07D3911EA881A525400E86DC0", "京东商城来新订单了!", noticeMsg) + return err +} + +func result2Orders(msg *jdshopapi.CallBackResult) (order *model.GoodsOrder, err error) { + //有可能是库里已经有这个订单了 + orderE, err := partner.CurOrderManager.LoadOrder(msg.OrderID+"000001", model.VendorIDJDShop) + if orderE != nil { + return order, fmt.Errorf("已经存在此订单!") + } + order = &model.GoodsOrder{ + VendorOrderID2: msg.OrderID, + VendorOrderID: msg.OrderID + "000001", + VendorID: model.VendorIDJDShop, + BaseFreightMoney: jxutils.StandardPrice2Int(utils.Str2Float64(msg.FreightPrice)), + VendorStatus: msg.OrderState, + VendorUserID: msg.Pin, + BuyerComment: msg.OrderRemark, + PickDeadline: utils.DefaultTimeValue, + OriginalData: string(utils.MustMarshal(msg)), + OrderCreatedAt: utils.Str2Time(msg.OrderStartTime), + ConsigneeAddress: Decrypt(msg.ConsigneeInfo.FullAddress), + ConsigneeName: Decrypt(msg.ConsigneeInfo.Fullname), + ConsigneeMobile: Decrypt(msg.ConsigneeInfo.Telephone), + ConsigneeMobile2: Decrypt(msg.ConsigneeInfo.Mobile), + ActualPayPrice: jxutils.StandardPrice2Int(utils.Str2Float64(msg.OrderPayment)), + Status: model.OrderStatusNew, + TotalShopMoney: utils.Float64TwoInt64(math.Round(float64(jxutils.StandardPrice2Int(utils.Str2Float64(msg.OrderPayment))) * jdshopapi.JdsPayPercentage)), + DeliveryFlag: model.OrderDeliveryFlagMaskScheduleDisabled, + DeliveryType: model.OrderDeliveryTypeStoreSelf, + StatusTime: utils.Str2Time(msg.OrderStartTime), + OrderSeq: 0, + } + if order.TotalShopMoney < 100 { + order.TotalShopMoney = 100 + } + if order.ConsigneeAddress != "" { + lng, lat, _ := api.AutonaviAPI.GetCoordinateFromAddress(order.ConsigneeAddress, "") + order.ConsigneeLng = jxutils.StandardCoordinate2Int(lng) + order.ConsigneeLat = jxutils.StandardCoordinate2Int(lat) + } + storeList, err := common.GetStoreListByLocation(jxcontext.AdminCtx, jxutils.IntCoordinate2Standard(order.ConsigneeLng), jxutils.IntCoordinate2Standard(order.ConsigneeLat), 5000, false, true) + if err != nil { + globals.SugarLogger.Debugf("jds GetStoreListByLocation error: %v", err.Error()) + return order, err + } + order.StoreID = storeList[0].ID + order.StoreName = storeList[0].Name + storeMaps, _ := dao.GetStoresMapList(dao.GetDB(), []int{model.VendorIDJDShop}, []int{order.StoreID}, nil, model.StoreStatusAll, model.StoreIsSyncAll, "", "") + if len(storeMaps) > 0 { + order.VendorStoreID = storeMaps[0].VendorStoreID + } + // 如果是暂停,表示是预订单 + if msg.OrderState == jdshopapi.OrderStatusPause || msg.OrderState == jdshopapi.OrderStatusPopPause { + order.BusinessType = model.BusinessTypeDingshida + // order.ExpectedDeliveredTime = utils.Str2Time(orderDetail.ExpectedDeliveredTime) + order.PickDeadline = order.ExpectedDeliveredTime.Add(-time.Hour) + globals.SugarLogger.Warnf("来暂停的订单了!%v", msg.OrderID) + return nil, err + } else if msg.OrderState == jdshopapi.OrderStatusWait { + order.ExpectedDeliveredTime = order.OrderCreatedAt.Add(time.Hour) + order.BusinessType = model.BusinessTypeImmediate + } + + //结算类型 + storeDetail, _ := dao.GetStoreDetail(dao.GetDB(), order.StoreID, model.VendorIDJDShop) + if storeDetail != nil { + if storeDetail.PayPercentage < 50 { + order.EarningType = model.EarningTypePoints + } else { + order.EarningType = model.EarningTypeQuote + } + } + setJdsOrderSeq(order) + for _, v := range msg.ItemInfoList { + sku := &model.OrderSku{ + VendorID: model.VendorIDJDShop, + VendorOrderID: order.VendorOrderID, + Count: utils.Str2Int(v.ItemTotal), + VendorSkuID: v.SkuID, + SkuName: v.SkuName, + VendorPrice: jxutils.StandardPrice2Int(utils.Str2Float64(v.JdPrice)), + SalePrice: jxutils.StandardPrice2Int(utils.Str2Float64(v.JdPrice)), + SkuID: utils.Str2Int(v.OuterSkuID), + } + _, _, _, specUnit, _, specQuality := jxutils.SplitSkuName(v.SkuName) + sku.Weight = jxutils.FormatSkuWeight(specQuality, specUnit) + order.Skus = append(order.Skus, sku) + } + return order, err +} + +func setJdsOrderSeq(order *model.GoodsOrder) (err error) { + type tCount struct { + Count int `json:"count"` + } + var count = &tCount{} + sql := ` + SELECT count(*) count FROM goods_order WHERE store_id = ? AND order_create_at >= ? AND order_create_at <= ? AND vendor_id = ? + ` + sqlParams := []interface{}{ + order.StoreID, utils.Time2Date(time.Now()), utils.Time2Date(time.Now().AddDate(0, 0, 1)), order.VendorID, + } + err = dao.GetRow(dao.GetDB(), &count, sql, sqlParams) + order.OrderSeq = count.Count + 1 + return err +} + +func Decrypt(p string) (result string) { + return result +}