Files
jx-callback/business/partner/purchase/tiktok_store/waybill.go
richboo111 3bc119ab21 1
2023-01-05 18:31:08 +08:00

109 lines
4.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package tiktok_store
import (
"errors"
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/baseapi/utils/errlist"
"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, storeIDs []int64) (autoCallInfos map[int64]*superm_getStoreAutoCallRiderInfo_response.AutoCallInfo, err error) {
if len(storeIDs) == 0 {
return nil, errors.New("门店ID为空请检查")
}
errList := errlist.ErrList{}
for _, i := range storeIDs {
if autoCallInfo, err := getAPI(vendorOrgCode, 0, "").GetStoreAutoCallRiderInfo(i); err != nil {
errList.AddErr(err)
} else {
autoCallInfos[i] = autoCallInfo
}
}
if errList.GetErrListAsOne() != nil {
return nil, errList.GetErrListAsOne()
}
return autoCallInfos, nil
}