From 5357400fc5c25ac88522f5bb24cf18d058157d04 Mon Sep 17 00:00:00 2001 From: richboo111 Date: Thu, 22 Dec 2022 14:16:41 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E7=AC=AC=E4=B8=89=E6=96=B9=E9=85=8D?= =?UTF-8?q?=E9=80=81=E5=A2=9E=E5=8A=A0=E6=8A=96=E9=9F=B3=E8=BF=90=E5=8A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/model/api_config.go | 1 + business/model/dao/common.go | 2 +- business/partner/delivery/rider.go | 2 +- .../partner/delivery/tiktok_store/waybill.go | 193 ++++++++++++++++-- .../partner/purchase/tiktok_store/order.go | 7 +- controllers/dyps_callback.go | 32 +++ 6 files changed, 219 insertions(+), 18 deletions(-) create mode 100644 controllers/dyps_callback.go diff --git a/business/model/api_config.go b/business/model/api_config.go index ac3b6f7c9..350a2a7b9 100644 --- a/business/model/api_config.go +++ b/business/model/api_config.go @@ -30,6 +30,7 @@ const ( VendorIDDada = 101 // 达达配送 VendorIDMTPS = 102 // 美团配送 VendorIDFengNiao = 103 // 蜂鸟配送 + VendorIDDYPS = 104 // 抖音配送 VendorJXFakeWL = 300 // 京西假物流 VendorIDJDWL = 401 // 京东物流 VendorIDTotalWl = 402 // (综合物流[京东,圆通,申通....]) diff --git a/business/model/dao/common.go b/business/model/dao/common.go index e3cb5941f..a52f13d03 100644 --- a/business/model/dao/common.go +++ b/business/model/dao/common.go @@ -35,7 +35,7 @@ func GetNeedUploadDataResource(db *DaoDB) (dataResList []*model.DataResource, er func GetVendorOrgCode(db *DaoDB, vendorID int, vendorOrgCode, vendorType string) (vendorOrgs []*model.VendorOrgCode, err error) { sql := ` SELECT * - FROM vendor_org_code + FROM vendor_org_code WHERE deleted_at = ? ` sqlParams := []interface{}{utils.DefaultTimeValue} diff --git a/business/partner/delivery/rider.go b/business/partner/delivery/rider.go index 48f927eab..f108273bb 100644 --- a/business/partner/delivery/rider.go +++ b/business/partner/delivery/rider.go @@ -66,7 +66,7 @@ func GetOrderRiderInfoToPlatform(orderId string, wayBillStatus int) { riderInfo := &mtpsapi.RiderInfo{} if handlerInfo := partner.GetDeliveryPlatformFromVendorID(v.WaybillVendorID); handlerInfo != nil { - if v.WaybillVendorID == model.VendorIDDada || v.WaybillVendorID == model.VendorIDFengNiao { + if v.WaybillVendorID == model.VendorIDDada || v.WaybillVendorID == model.VendorIDFengNiao || v.WaybillVendorID == model.VendorIDDD { riderInfo, err = handlerInfo.Handler.GetRiderInfo(v.VendorOrderID, 0, v.VendorWaybillID) if err != nil { globals.SugarLogger.Debug("Get Order waybill rider info err FN/DADA :%v", err) diff --git a/business/partner/delivery/tiktok_store/waybill.go b/business/partner/delivery/tiktok_store/waybill.go index 8b4b7885e..38938aa7e 100644 --- a/business/partner/delivery/tiktok_store/waybill.go +++ b/business/partner/delivery/tiktok_store/waybill.go @@ -1,12 +1,20 @@ package tiktok_store import ( + "errors" "git.rosy.net.cn/baseapi/platformapi/mtpsapi" + shop_getStoreDetail_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/shop_getStoreDetail/request" + superm_createVirtualMobile_response "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/superm_createVirtualMobile/response" + "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/tiktok_api" + "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" "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/business/partner/delivery" + "git.rosy.net.cn/jx-callback/globals" "git.rosy.net.cn/jx-callback/globals/api" + "time" ) var ( @@ -28,13 +36,34 @@ func (c *DeliveryHandler) GetVendorID() int { } func (c *DeliveryHandler) CreateStore(ctx *jxcontext.Context, storeDetail *dao.StoreDetail2) (vendorStoreID string, status int, err error) { - //TODO implement me - panic("implement me") + return "", 0, errors.New("抖店暂不支持此操作") } func (c *DeliveryHandler) GetStore(ctx *jxcontext.Context, storeID int, vendorStoreID string) (storeDetail *dao.StoreDetail2, err error) { - //TODO implement me - panic("implement me") + relInfo, err := dao.GetStoreDetail(dao.GetDB(), storeID, model.VendorIDDD, "") + if err != nil { + return nil, errors.New("获取抖音平台账号信息失败,请重试") + } + apiObj := getAPI(relInfo.VendorOrgCode) + if storeInfo, err := apiObj.GetStoreDetail(&shop_getStoreDetail_request.ShopGetStoreDetailParam{ + //if storeInfo, err := api.TiktokStore.GetStoreDetail(&shop_getStoreDetail_request.ShopGetStoreDetailParam{ + StoreId: vendorStoreID, + }); err == nil { + storeDetail = &dao.StoreDetail2{ + Store: model.Store{ + Name: storeInfo.StoreDetail.Store.Name, + Tel1: storeInfo.StoreDetail.Store.Contact, + Address: storeInfo.StoreDetail.Store.Address, + Lng: utils.Str2Int(storeInfo.StoreDetail.Store.Longitude), + Lat: utils.Str2Int(storeInfo.StoreDetail.Store.Latitude), + }, + VendorID: model.VendorIDDYPS, + VendorStoreID: utils.Int64ToStr(storeInfo.StoreDetail.Store.StoreId), + CourierStatus: int(storeInfo.StoreDetail.Store.State), + } + } + globals.SugarLogger.Debugf("DYPS GetStore storeDetail====%s", utils.Format4Output(storeDetail, false)) + return storeDetail, err } func (c *DeliveryHandler) IsErrStoreNotExist(err error) bool { @@ -47,27 +76,161 @@ func (c *DeliveryHandler) IsErrStoreExist(err error) bool { panic("implement me") } +// 呼叫运力并发货 func (c *DeliveryHandler) CreateWaybill(order *model.GoodsOrder, maxDeliveryFee int64) (bill *model.Waybill, err error) { - //TODO implement me - panic("implement me") + relInfo, err := dao.GetStoreDetail(dao.GetDB(), order.JxStoreID, model.VendorIDDD, "") + if err != nil { + return nil, errors.New("获取抖音平台账号信息失败,请重试") + } + apiObj := getAPI(relInfo.VendorOrgCode) + if order.VendorID != model.VendorIDDYPS { + return nil, errors.New("非抖音平台店铺不可发抖音配送") + } + bill = &model.Waybill{ + VendorOrderID: order.VendorOrderID, + OrderVendorID: order.VendorID, + VendorWaybillID: order.VendorOrderID, //抖音配送订单号即运单号 + WaybillVendorID: model.VendorIDDYPS, + } + if dispatcherFee, err := apiObj.GetDispatcherInfo(int64(order.StoreID), utils.Str2Int64(order.VendorOrderID), tiktok_api.DispatcherFeeTypeCall); err == nil { + bill.DesiredFee = dispatcherFee + } + if err := apiObj.OrderDispatcher(utils.Str2Int64(order.VendorStoreID), utils.Str2Int64(order.VendorOrderID), tiktok_api.DispatcherFeeTypeCall); err != nil { + return nil, err + } + delivery.OnWaybillCreated(bill) + globals.SugarLogger.Debugf("DYPS CreateWaybill bill======%s", utils.Format4Output(bill, false)) + return bill, nil } func (c *DeliveryHandler) CancelWaybill(bill *model.Waybill, cancelReasonID int, cancelReason string) (err error) { - //TODO implement me - panic("implement me") + err = getAPI(bill.VendorOrgCode).CancelPlatformPickUp(utils.Str2Int64(bill.VendorOrderID)) + bill.Status = model.WaybillStatusCanceled + bill.Remark = cancelReason + partner.CurOrderManager.OnWaybillStatusChanged(bill) + globals.SugarLogger.Debugf("DYPS CancelWaybill err======%s", err) + return err } func (c *DeliveryHandler) GetWaybillFee(order *model.GoodsOrder) (deliveryFeeInfo *partner.WaybillFeeInfo, err error) { - //TODO implement me - panic("implement me") + relInfo, err := dao.GetStoreDetail(dao.GetDB(), order.JxStoreID, model.VendorIDDD, "") + if err != nil { + return nil, errors.New("获取抖音平台账号信息失败,请重试") + } + if dispatcherFee, err := getAPI(relInfo.VendorOrgCode).GetDispatcherInfo(int64(order.StoreID), utils.Str2Int64(order.VendorOrderID), tiktok_api.DispatcherFeeTypeCall); err == nil { + deliveryFeeInfo = &partner.WaybillFeeInfo{} + deliveryFeeInfo.DeliveryFee = dispatcherFee + } + globals.SugarLogger.Debugf("DYPS GetWaybillFee deliveryFeeInfo======%s", utils.Format4Output(deliveryFeeInfo, false)) + return deliveryFeeInfo, err +} +func getDispatcherFee(storeID, vendorOrderID int64, dispatcherType int32) int64 { + if relInfo, err := dao.GetStoreDetail(dao.GetDB(), int(storeID), model.VendorIDDD, ""); err != nil { + return 0 + } else { + if dispatcherFee, err := getAPI(relInfo.VendorOrgCode).GetDispatcherInfo(storeID, vendorOrderID, dispatcherType); err == nil { + return 0 + } else { + return dispatcherFee + } + } } - func (c *DeliveryHandler) ComplaintRider(bill *model.Waybill, resonID int, resonContent string) (err error) { - //TODO implement me - panic("implement me") + return errors.New("抖店配送暂不支持此操作") } func (c *DeliveryHandler) GetRiderInfo(orderId string, deliveryId int64, mtPeisongId string) (rider *mtpsapi.RiderInfo, err error) { - //TODO implement me - panic("implement me") + orderInfo, _, err := dao.GetOrders(dao.GetDB(), []int64{utils.Str2Int64(orderId)}, false, false, "", "", false, []int{0}, false, "", nil, 0, 0) + if err != nil { + return nil, errors.New("获取本地门店账号信息失败,请重试") + } + if waybill, err := getAPI(orderInfo[0].VendorOrgCode).GetShipmentInfo(utils.Str2Int64(orderId), deliveryId, tiktok_api.ShipmentTypeInvoice); err != nil { + return nil, err + } else { + rider = &mtpsapi.RiderInfo{ + OrderId: orderId, + ThirdCarrierOrderId: mtPeisongId, + CourierName: waybill.RiderName, + CourierPhone: waybill.RiderPhone, + LogisticsProviderCode: mtpsapi.DYPsCode, + LogisticsStatus: int(waybill.ShipmentStatus), + LogisticsContext: tiktok_api.ShipmentStatus[waybill.ShipmentStatus], + Latitude: waybill.RiderLatitude, + Longitude: waybill.RiderLongitude, + } + } + globals.SugarLogger.Debugf("DYPS GetRiderInfo rider======%s", utils.Format4Output(rider, false)) + return rider, nil +} + +func CreateVirtualMobile(shopOrderID int64) (*superm_createVirtualMobile_response.SupermCreateVirtualMobileData, error) { + if orderInfo, _, err := dao.GetOrders(dao.GetDB(), []int64{shopOrderID}, false, false, "", "", false, []int{0}, false, "", nil, 0, 0); err != nil { + return nil, errors.New("获取本地门店账号信息失败,请重试") + } else { + if visMobile, err := getAPI(orderInfo[0].VendorOrgCode).CreateVirtualMobile(shopOrderID); err != nil { + return nil, err + } else { + return visMobile, nil + } + } +} + +//订单状态回调 +func OnWaybillMsg(tag, orderId string, data interface{}) (response *tiktok_api.CallbackResponse) { + req := data.(tiktok_api.ShipmentInfoData) + globals.SugarLogger.Debugf("DYPS OnWaybillMsg req============%s", utils.Format4Output(req, false)) + param := &model.Waybill{ + VendorOrderID: utils.Int64ToStr(req.ShopOrderID), + VendorWaybillID: req.TrackNo, + VendorWaybillID2: utils.Int64ToStr(req.AfterSaleID), + WaybillVendorID: model.VendorIDDD, + CourierName: req.RiderName, + CourierMobile: req.RiderPhone, + VendorStatus: tiktok_api.ShipmentStatus[req.ShipmentStatus], + StatusTime: utils.Str2Time(req.OccurredTime), + Remark: "", + } + if req.OccurredTime == "" { + param.StatusTime = time.Now() + } + globals.SugarLogger.Debugf("DYPS OnWaybillMsg param============%s", utils.Format4Output(param, false)) + dispatcherFee := getDispatcherFee(req.ShopID, req.ShopOrderID, tiktok_api.DispatcherFeeTypeCall) + switch req.ShipmentStatus { + case tiktok_api.ShipmentStatusCalling: //1 骑手呼叫中 + param.DesiredFee = dispatcherFee + param.Status = model.WaybillStatusNew //5 待调度 + case tiktok_api.ShipmentStatusReceived: //2 骑手已接单 + param.DesiredFee = dispatcherFee + param.Status = model.WaybillStatusCourierAssigned + param.Remark = req.RiderName + "," + req.RiderPhone + case tiktok_api.ShipmentStatusArrived: //3 骑手已到达取货点 + param.DesiredFee = dispatcherFee + param.Status = model.WaybillStatusCourierArrived //80 到店 + param.Remark = tiktok_api.ShipmentStatus[req.ShipmentStatus] + case tiktok_api.ShipmentStatusDelivering: //4 配送中 + param.Status = model.WaybillStatusDelivering + param.Remark = tiktok_api.ShipmentStatus[req.ShipmentStatus] + case tiktok_api.ShipmentStatusRejected, tiktok_api.ShipmentStatusReturning, tiktok_api.ShipmentStatusReturned: //5 收货人已拒收,6 返回中,7 返回完成 + param.Status = model.WaybillStatusDeliverFailed + param.Remark = tiktok_api.ShipmentStatus[req.ShipmentStatus] + case tiktok_api.ShipmentStatusDelivered: // 8 订单妥投 + param.Status = model.WaybillStatusDelivered + param.Remark = tiktok_api.ShipmentStatus[req.ShipmentStatus] + case tiktok_api.ShipmentStatusCanceled: //9 订单取消 + param.Status = model.WaybillStatusCanceled + param.Remark = tiktok_api.ShipmentStatus[req.ShipmentStatus] + default: + globals.SugarLogger.Warnf("onWaybillMsg unknown shipmentStatus:%v", req.ShipmentStatus) + } + if err := partner.CurOrderManager.OnWaybillStatusChanged(param); err != nil { + return tiktok_api.CallbackResponseErr(false) + } + + return nil +} + +//以下为辅助函数 +func getAPI(appOrgCode string) (apiObj *tiktok_api.API) { + apiObj = partner.CurAPIManager.GetAPI(model.VendorIDDD, appOrgCode).(*tiktok_api.API) + return apiObj } diff --git a/business/partner/purchase/tiktok_store/order.go b/business/partner/purchase/tiktok_store/order.go index 9603b66d4..6221920ef 100644 --- a/business/partner/purchase/tiktok_store/order.go +++ b/business/partner/purchase/tiktok_store/order.go @@ -8,6 +8,7 @@ import ( order_logisticsAdd_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/order_logisticsAdd/request" order_orderDetail_response "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/order_orderDetail/response" tiktokShop "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/tiktok_api" + "git.rosy.net.cn/jx-callback/business/partner/delivery/tiktok_store" "regexp" "strings" "time" @@ -262,7 +263,11 @@ func (c *PurchaseHandler) onOrderMsg(msgId, orderId string, msg interface{}) (re response = c.OnAfsOrderMsg(msgId, orderId, msg) return response } - + //抖音运单处理 + if msgId == tiktokShop.CallbackShipmentInfoChange { + //msgId-骑手运单号 orderId-抖音店铺ID msg-回调运单参数 + return tiktok_store.OnWaybillMsg(msgId, orderId, msg) + } // 待支付订单将不做处理/支付订单待处理(抖音风控) if msgId == tiktokShop.CallbackCreatedOrderMsgTagId || msgId == tiktokShop.CallbackWaitOrderMsgTagId { return tiktokShop.Err2CallbackResponse(nil, "") diff --git a/controllers/dyps_callback.go b/controllers/dyps_callback.go new file mode 100644 index 000000000..bd15e50af --- /dev/null +++ b/controllers/dyps_callback.go @@ -0,0 +1,32 @@ +package controllers + +import ( + "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/tiktok_api" + "git.rosy.net.cn/jx-callback/globals/api" + "github.com/astaxie/beego/server/web" + "net/http" + "strings" +) + +type DYPSController struct { + web.Controller +} + +//抖音运力配送 回调 +func (d *DYPSController) CallbackDYPSDeliveryMsg() { + resp, byteList := api.TiktokStore.EventSignChange(d.Ctx.Request) + if resp.Code != 0 { + d.Data["json"] = resp + d.ServeJSON() + return + } + if strings.Contains(string(byteList), "\"msg_id\":\"0\"") { + d.Data["json"] = tiktok_api.CallbackResponse{Code: tiktok_api.CallbackSuccessCode, Msg: tiktok_api.CallbackSuccess} + d.ServeJSON() + return + } + + if d.Ctx.Input.Method() == http.MethodPost { + //msg,callbaskResponse:=api.TiktokStore. + } +} From b06772dbaec52f6837658ec7159200bce9648819 Mon Sep 17 00:00:00 2001 From: richboo111 Date: Thu, 22 Dec 2022 15:03:24 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E7=AC=AC=E4=B8=89=E6=96=B9=E9=85=8D?= =?UTF-8?q?=E9=80=81=E5=A2=9E=E5=8A=A0=E6=8A=96=E9=9F=B3=E8=BF=90=E5=8A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/partner/delivery/tiktok_store/waybill.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/business/partner/delivery/tiktok_store/waybill.go b/business/partner/delivery/tiktok_store/waybill.go index 38938aa7e..7b63cae19 100644 --- a/business/partner/delivery/tiktok_store/waybill.go +++ b/business/partner/delivery/tiktok_store/waybill.go @@ -32,7 +32,7 @@ func init() { } func (c *DeliveryHandler) GetVendorID() int { - return model.VendorIDDD + return model.VendorIDDYPS } func (c *DeliveryHandler) CreateStore(ctx *jxcontext.Context, storeDetail *dao.StoreDetail2) (vendorStoreID string, status int, err error) { From fb25aa59d0c7f8ebb532f48ef5481b2fb968d0cc Mon Sep 17 00:00:00 2001 From: richboo111 Date: Thu, 22 Dec 2022 15:12:06 +0800 Subject: [PATCH 3/3] add vendorID --- business/model/api_config.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/business/model/api_config.go b/business/model/api_config.go index 350a2a7b9..d72dd4cab 100644 --- a/business/model/api_config.go +++ b/business/model/api_config.go @@ -101,6 +101,7 @@ var ( VendorIDDada: "Dada", VendorIDMTPS: "Mtps", VendorIDFengNiao: "Fn", + VendorIDDYPS: "DYPS", VendorIDFeiE: "Feie", VendorIDXiaoWM: "XiaoWM", @@ -133,6 +134,7 @@ var ( VendorIDMTPS: "美团配送", VendorIDJDWL: "京东物流", VendorIDFengNiao: "蜂鸟配送", + VendorIDDYPS: "抖音配送", VendorIDFeiE: "飞鹅", VendorIDXiaoWM: "外卖管家",