Files
jx-callback/business/partner/purchase/tiktok_store/waybill.go
richboo111 adad91cd52 1
2023-01-04 18:32:37 +08:00

97 lines
4.0 KiB
Go

package tiktok_store
import (
superm_getStoreAutoCallRiderInfo_response "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/superm_getStoreAutoCallRiderInfo/response"
superm_setStoreAutoCallRider_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/superm_setStoreAutoCallRider/request"
"git.rosy.net.cn/baseapi/platformapi/tiktok_shop/tiktok_api"
"git.rosy.net.cn/baseapi/utils"
"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"
)
var (
VendorWaybillStatus2StatusMap = map[int]int{
tiktok_api.ShipmentStatusCalling: model.WaybillStatusNew,
tiktok_api.ShipmentStatusReceived: model.WaybillStatusAccepted,
tiktok_api.ShipmentStatusArrived: model.WaybillStatusCourierArrived,
tiktok_api.ShipmentStatusDelivering: model.WaybillStatusDelivering,
tiktok_api.ShipmentStatusRejected: model.WaybillStatusRejected,
tiktok_api.ShipmentStatusReturning: model.WaybillStatusReturning,
tiktok_api.ShipmentStatusReturned: model.WaybillStatusReturned,
tiktok_api.ShipmentStatusDelivered: model.WaybillStatusCanceled,
tiktok_api.ShipmentStatusCanceled: model.WaybillStatusDelivered,
}
)
func (p *PurchaseHandler) GetWaybillStatusFromVendorStatus(vendorStatus string) int {
if status, ok := VendorWaybillStatus2StatusMap[utils.Str2Int(vendorStatus)]; ok {
return status
}
return model.WaybillStatusUnknown
}
func (c *PurchaseHandler) onWaybillMsg(tag, orderId string, data interface{}) *tiktok_api.CallbackResponse {
waybill := c.callbackMsg2Waybill(tag, orderId, data)
if localOrder, _, err := dao.GetOrders(dao.GetDB(), nil, false, false, "", "", false, []int{0}, false, "",
map[string]interface{}{
"vendorOrderID": waybill.VendorOrderID,
}, 0, 0); err == nil {
err := partner.CurOrderManager.OnWaybillStatusChanged(waybill)
if err == nil && waybill.Status == model.WaybillStatusDelivering {
c.postFakeMsg(waybill.VendorOrderID, FakeMsgType, utils.Int2Str(tiktok_api.ShipmentStatusDelivering), localOrder[0].VendorStoreID)
}
return tiktok_api.Err2CallbackResponse(err, "")
}
return tiktok_api.Err2CallbackResponse(nil, "")
}
func (c *PurchaseHandler) callbackMsg2Waybill(tag, orderId string, data interface{}) (retVal *model.Waybill) {
req := data.(tiktok_api.ShipmentInfoData)
vendorOrgCode, _ := dao.GetStoreDetailForDD(dao.GetDB(), 0, model.VendorIDDD, utils.Int64ToStr(req.ShopID), "")
return &model.Waybill{
VendorOrderID: utils.Int64ToStr(req.ShopOrderID),
OrderVendorID: model.VendorIDDD,
VendorWaybillID: req.TrackNo,
WaybillVendorID: model.VendorIDDYPS,
CourierName: req.RiderName,
CourierMobile: req.RiderPhone,
VendorStatus: utils.Int64ToStr(req.ShipmentStatus),
Status: c.GetWaybillStatusFromVendorStatus(utils.Int64ToStr(req.ShipmentStatus)),
StatusTime: getTimeFromTimestamp(utils.Str2Int64(req.OccurredTime)),
Remark: "",
VendorOrgCode: vendorOrgCode.VendorOrgCode,
}
}
//设置自动呼叫运力
func SetStoreAutoCallRider(vendorOrgCode, opType string, storeID int64) error {
if opType == tiktok_api.AutoCallRiderOpen {
if err := getAPI(vendorOrgCode, 0, "").SetStoreAutoCallRider(&superm_setStoreAutoCallRider_request.SupermSetStoreAutoCallRiderParam{
StoreID: storeID,
OpType: opType,
ServiceType: tiktok_api.ServiceTypeDelayCall,
DelayTime: tiktok_api.AutoCallDelayTime15,
}); err != nil {
return err
}
} else {
if err := getAPI(vendorOrgCode, 0, "").SetStoreAutoCallRider(&superm_setStoreAutoCallRider_request.SupermSetStoreAutoCallRiderParam{
StoreID: storeID,
OpType: opType,
}); err != nil {
return err
}
}
return nil
}
//查询查询自动呼叫运力配置
func GetStoreAutoCallRiderInfo(vendorOrgCode string, storeID int64) (autoCallInfo *superm_getStoreAutoCallRiderInfo_response.AutoCallInfo, err error) {
if autoCallInfo, err = getAPI(vendorOrgCode, 0, "").GetStoreAutoCallRiderInfo(storeID); err != nil {
return nil, err
} else {
return autoCallInfo, err
}
}