京东商城订单补全
This commit is contained in:
@@ -7,9 +7,13 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/common"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/partner/purchase/jdshop"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
|
||||
"git.rosy.net.cn/baseapi"
|
||||
"git.rosy.net.cn/baseapi/platformapi/jdshopapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/scheduler"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
@@ -995,3 +999,99 @@ func GetOrderSimpleInfo(ctx *jxcontext.Context, vendorOrderID string) (getOrderS
|
||||
|
||||
return getOrderSimpleInfoResult, err
|
||||
}
|
||||
|
||||
func SaveJdsOrders(ctx *jxcontext.Context, orderCreatedStart, orderCreatedEnd time.Time) (err error) {
|
||||
var (
|
||||
pageNo = 1
|
||||
pageSize = 10
|
||||
)
|
||||
orderResult, err := jdshop.CurPurchaseHandler.GetJdsOrders(ctx, utils.Time2Str(orderCreatedStart), utils.Time2Str(orderCreatedEnd), pageNo, pageSize)
|
||||
orders, err := result2Orders(ctx, orderResult)
|
||||
if err != nil {
|
||||
globals.SugarLogger.Errorf("SaveJdsOrders : %v", err)
|
||||
}
|
||||
for _, order := range orders {
|
||||
partner.CurOrderManager.OnOrderNew(order, model.Order2Status(order))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func result2Orders(ctx *jxcontext.Context, result *jdshopapi.AllOrdersResult) (orders []*model.GoodsOrder, err error) {
|
||||
for _, jdsOrder := range result.OrderList {
|
||||
if jdsOrder.OrderStatus == jdshopapi.JdsOrderStatusWaittingPay {
|
||||
continue
|
||||
}
|
||||
orderDetail, err := api.JdShopAPI.OrderDetail(utils.Int64ToStr(jdsOrder.OrderID))
|
||||
if err != nil {
|
||||
globals.SugarLogger.Debugf("jds OrderDetail error: %v", err.Error())
|
||||
continue
|
||||
}
|
||||
order := &model.GoodsOrder{
|
||||
VendorOrderID: utils.Int64ToStr(jdsOrder.OrderID),
|
||||
VendorID: model.VendorIDJDShop,
|
||||
BaseFreightMoney: jxutils.StandardPrice2Int(jdsOrder.Freight),
|
||||
VendorStatus: utils.Int2Str(jdsOrder.OrderStatus),
|
||||
VendorUserID: jdsOrder.UserPin,
|
||||
BuyerComment: jdsOrder.UserRemark,
|
||||
PickDeadline: utils.DefaultTimeValue,
|
||||
OriginalData: string(utils.MustMarshal(jdsOrder)),
|
||||
StoreName: jdsOrder.StoreName,
|
||||
OrderCreatedAt: utils.Str2Time(jdsOrder.OrderCreateTime + ":00"),
|
||||
ConsigneeAddress: orderDetail.ConsigneeAddress,
|
||||
ConsigneeMobile: orderDetail.ConsigneeMobile,
|
||||
ConsigneeName: orderDetail.ConsigneeName,
|
||||
ActualPayPrice: orderDetail.ActualPayPrice,
|
||||
Status: model.OrderStatusNew,
|
||||
TotalShopMoney: utils.Float64TwoInt64(math.Round(utils.Int64ToFloat64(orderDetail.ActualPayPrice) * jdshopapi.JdsPayPercentage)),
|
||||
}
|
||||
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)
|
||||
}
|
||||
if order.StoreName != "" {
|
||||
storeMaps, _ := dao.GetStoresMapList(dao.GetDB(), []int{model.VendorIDJDShop}, nil, nil, model.StoreStatusAll, model.StoreIsSyncAll, "", order.StoreName)
|
||||
if len(storeMaps) > 0 {
|
||||
order.StoreID = storeMaps[0].StoreID
|
||||
order.VendorStoreID = storeMaps[0].VendorStoreID
|
||||
}
|
||||
} else {
|
||||
storeList, err := common.GetStoreListByLocation(ctx, jxutils.IntCoordinate2Standard(order.ConsigneeLng), jxutils.IntCoordinate2Standard(order.ConsigneeLat), 5000, false)
|
||||
if err != nil {
|
||||
globals.SugarLogger.Debugf("jds GetStoreListByLocation error: %v", err.Error())
|
||||
continue
|
||||
}
|
||||
order.StoreID = storeList[0].ID
|
||||
order.StoreName = storeList[0].Name
|
||||
}
|
||||
//如果是暂停,表示是预订单
|
||||
if jdsOrder.OrderStatus == jdshopapi.JdsOrderStatusPause {
|
||||
order.BusinessType = model.BusinessTypeDingshida
|
||||
order.ExpectedDeliveredTime = utils.Str2Time(orderDetail.ExpectedDeliveredTime)
|
||||
} else if jdsOrder.OrderStatus == jdshopapi.JdsOrderStatusWaittingExport {
|
||||
order.ExpectedDeliveredTime = order.CreatedAt.Add(time.Hour)
|
||||
order.BusinessType = model.BusinessTypeImmediate
|
||||
} else {
|
||||
globals.SugarLogger.Errorf("未知的京东商城订单状态!status : %v", jdsOrder.OrderStatus)
|
||||
}
|
||||
for _, v := range jdsOrder.OrderItems {
|
||||
sku := &model.OrderSku{
|
||||
VendorID: model.VendorIDJDShop,
|
||||
VendorOrderID: utils.Int64ToStr(jdsOrder.OrderID),
|
||||
Count: v.SkuNum,
|
||||
VendorSkuID: utils.Int64ToStr(v.SkuID),
|
||||
SkuName: v.SkuName,
|
||||
VendorPrice: jxutils.StandardPrice2Int(v.JdPrice),
|
||||
SalePrice: jxutils.StandardPrice2Int(v.JdPrice),
|
||||
}
|
||||
_, _, _, specUnit, _, specQuality := jxutils.SplitSkuName(v.SkuName)
|
||||
sku.Weight = jxutils.FormatSkuWeight(specQuality, specUnit)
|
||||
order.Skus = append(order.Skus, sku)
|
||||
}
|
||||
orders = append(orders, order)
|
||||
}
|
||||
return orders, err
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/partner/purchase/jdshop"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/dingdingapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/baseapi/utils/errlist"
|
||||
@@ -41,13 +43,12 @@ func (c *BaseScheduler) CreateWaybillOnProviders(ctx *jxcontext.Context, order *
|
||||
courierVendorID := storeCourier.VendorID
|
||||
bill, err2 := c.CreateWaybill(courierVendorID, order, maxDeliveryFee)
|
||||
if err = err2; err == nil {
|
||||
// stores, _ := dao.GetStoreList(dao.GetDB(), []int{order.StoreID}, nil, nil, nil, "")
|
||||
// if len(stores) > 0 {
|
||||
// if stores[0].PayPercentage <= 50 {
|
||||
// order.NewEarningPrice = (order.TotalShopMoney - bill.DesiredFee) * int64((100 - stores[0].PayPercentage/2)) / 100
|
||||
// dao.UpdateEntity(dao.GetDB(), order, "NewEarningPrice")
|
||||
// }
|
||||
// }
|
||||
if order.VendorID == model.VendorIDJDShop {
|
||||
err = jdshop.CurPurchaseHandler.OrderExport(ctx, bill.VendorOrderID, bill.VendorWaybillID)
|
||||
if err != nil {
|
||||
errList.AddErr(fmt.Errorf("平台:%s,%s", jxutils.GetVendorName(courierVendorID), err.Error()))
|
||||
}
|
||||
}
|
||||
globals.SugarLogger.Debugf("CreateWaybillOnProviders orderID:%s userName:%s vendorID:%d bill:%v", order.VendorOrderID, userName, courierVendorID, bill)
|
||||
bills = append(bills, bill)
|
||||
if createOnlyOne {
|
||||
|
||||
@@ -721,6 +721,10 @@ func (s *DefScheduler) createWaybillOn3rdProviders(savedOrderInfo *WatchOrderInf
|
||||
// if order.VendorID == model.VendorIDJX {
|
||||
// excludeVendorIDs = append(excludeVendorIDs, model.VendorIDMTPS)
|
||||
// }
|
||||
//京东商城订单目前不发美团配送
|
||||
if order.VendorID == model.VendorIDJDShop {
|
||||
excludeVendorIDs = append(excludeVendorIDs, model.VendorIDMTPS)
|
||||
}
|
||||
if _, err = s.CreateWaybillOnProviders4SavedOrder(jxcontext.AdminCtx, savedOrderInfo, nil, excludeVendorIDs, false, maxDeliveryFee); err == nil {
|
||||
savedOrderInfo.retryCount++
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user