155 lines
6.2 KiB
Go
155 lines
6.2 KiB
Go
package tiktok_store
|
||
|
||
import (
|
||
"errors"
|
||
"fmt"
|
||
|
||
superm_getShipmentInfo_response "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/superm_getShipmentInfo/response"
|
||
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.WaybillStatusDelivered,
|
||
tiktok_api.ShipmentStatusCanceled: model.WaybillStatusCanceled,
|
||
}
|
||
)
|
||
|
||
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)
|
||
tempRemark := ""
|
||
if req.ShipmentStatus == tiktok_api.ShipmentStatusReceived {
|
||
tempRemark = req.RiderName + "," + req.RiderPhone
|
||
}
|
||
return &model.Waybill{
|
||
VendorOrderID: utils.Int64ToStr(req.ShopOrderID),
|
||
OrderVendorID: model.VendorIDDD,
|
||
VendorWaybillID: req.TrackNo,
|
||
WaybillVendorID: model.VendorIDDD,
|
||
CourierName: req.RiderName,
|
||
CourierMobile: req.RiderPhone,
|
||
VendorStatus: utils.Int64ToStr(req.ShipmentStatus),
|
||
Status: c.GetWaybillStatusFromVendorStatus(utils.Int64ToStr(req.ShipmentStatus)),
|
||
StatusTime: utils.Str2Time(req.OccurredTime),
|
||
//StatusTime: getTimeFromTimestamp(utils.Str2Int64(req.OccurredTime)),
|
||
Remark: tempRemark,
|
||
VendorOrgCode: utils.Int64ToStr(req.ShopID), //为抖音账号ID
|
||
}
|
||
}
|
||
|
||
//设置自动呼叫运力
|
||
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) (map[int64]*superm_getStoreAutoCallRiderInfo_response.AutoCallInfo, error) {
|
||
if len(storeIDs) == 0 {
|
||
return nil, errors.New("门店ID为空,请检查")
|
||
}
|
||
errList := errlist.ErrList{}
|
||
tAutoCallInfos := make(map[int64]*superm_getStoreAutoCallRiderInfo_response.AutoCallInfo, 0)
|
||
for _, i := range storeIDs {
|
||
if autoCallInfo, err := getAPI(vendorOrgCode, 0, "").GetStoreAutoCallRiderInfo(i); err != nil {
|
||
errList.AddErr(err)
|
||
} else {
|
||
tAutoCallInfos[i] = &superm_getStoreAutoCallRiderInfo_response.AutoCallInfo{
|
||
ServiceStatus: autoCallInfo.ServiceStatus,
|
||
ServiceType: autoCallInfo.ServiceType,
|
||
DelayTime: autoCallInfo.DelayTime,
|
||
}
|
||
}
|
||
}
|
||
if errList.GetErrListAsOne() != nil {
|
||
return nil, errList.GetErrListAsOne()
|
||
}
|
||
return tAutoCallInfos, nil
|
||
}
|
||
|
||
//取消自动运力
|
||
func (c *PurchaseHandler) CancelWaybill(bill *model.Waybill, cancelReasonID int, cancelReason string) (err error) {
|
||
params := make(map[string]interface{}, 0)
|
||
params["vendorOrderID"] = bill.VendorOrderID
|
||
if localOrder, _, err := dao.GetOrders(dao.GetDB(), nil, false, false, "", "", false, []int{0}, false, "", params, 0, 0); err != nil {
|
||
return errors.New("取消运单时,获取平台门店ID失败,请重试")
|
||
} else {
|
||
if err = getAPI(bill.VendorOrgCode, 0, "").ShopOrderDispatcher(utils.Str2Int64(localOrder[0].VendorStoreID), bill.VendorOrderID, tiktok_api.DispatcherFeeTypeCancel); err != nil {
|
||
return fmt.Errorf("抖音配送取消运力失败:%v", err)
|
||
}
|
||
bill.Status = model.WaybillStatusCanceled
|
||
bill.Remark = cancelReason
|
||
partner.CurOrderManager.OnWaybillStatusChanged(bill)
|
||
}
|
||
return err
|
||
}
|
||
|
||
//查询运力状态
|
||
func (c *PurchaseHandler) GetDYPSRiderInfo(orderId string) (*superm_getShipmentInfo_response.ShipmentInfo, error) {
|
||
params := map[string]interface{}{
|
||
"vendorOrderID": orderId,
|
||
}
|
||
orderInfo, _, err := dao.GetOrders(dao.GetDB(), nil, false, false, "", "", false, nil, false, "", params, 0, 0)
|
||
if err != nil {
|
||
return nil, errors.New("获取本地门店账号信息失败,请重试")
|
||
}
|
||
if waybill, err := getAPI(orderInfo[0].VendorOrgCode, 0, "").GetShipmentInfo(utils.Str2Int64(orderId), 0, tiktok_api.ShipmentTypeInvoice); err != nil {
|
||
return nil, err
|
||
} else {
|
||
return waybill, nil
|
||
}
|
||
}
|