京东商城订单补全

This commit is contained in:
苏尹岚
2020-06-03 11:16:49 +08:00
parent 1eb43ea9b9
commit 66ec7fc874
8 changed files with 309 additions and 246 deletions

View File

@@ -27,7 +27,6 @@ import (
"git.rosy.net.cn/jx-callback/business/jxutils/excel"
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
"git.rosy.net.cn/jx-callback/business/partner/purchase/jd"
"git.rosy.net.cn/jx-callback/business/partner/purchase/jdshop"
"git.rosy.net.cn/jx-callback/globals/api/apimanager"
"git.rosy.net.cn/jx-callback/business/partner"
@@ -4498,6 +4497,13 @@ func doStoreSkuAudit(ctx *jxcontext.Context, storeIDs []int, skuBindInfos []*Sto
// globals.SugarLogger.Debugf("doStoreSkuAudit return2 storeID : %v nameID: %v", storeID, skuBindInfo.NameID)
// return false, err
// }
dao.Begin(db)
defer func() {
if r := recover(); r != nil {
dao.Rollback(db)
panic(r)
}
}()
if ctx.GetLoginType() != weixin.AuthTypeMP && ctx.GetLoginType() != weixin.AuthTypeMini {
if len(storeAudits) > 0 {
storeAudits[0].DeletedAt = time.Now()
@@ -4541,6 +4547,7 @@ func doStoreSkuAudit(ctx *jxcontext.Context, storeIDs []int, skuBindInfos []*Sto
storeAudits[0].DeletedAt = time.Now()
dao.UpdateEntity(db, storeAudits[0], "DeletedAt")
}
globals.SugarLogger.Debugf("doStoreSkuAudit cover storeID : %v nameID: %v", storeID, skuBindInfo.NameID)
}
} else {
return false, fmt.Errorf("未查询到该门店商品价storeID: %v, nameID: %V", storeID, skuBindInfo.NameID)
@@ -4548,13 +4555,6 @@ func doStoreSkuAudit(ctx *jxcontext.Context, storeIDs []int, skuBindInfos []*Sto
storeSkuAudit.Type = model.StoreSkuAuditTypePrice
storeSkuAudit.OriginUnitPrice = int(storeSkus[0].UnitPrice)
}
dao.Begin(db)
defer func() {
if r := recover(); r != nil {
dao.Rollback(db)
panic(r)
}
}()
dao.WrapAddIDCULDEntity(storeSkuAudit, ctx.GetUserName())
err = dao.CreateEntity(db, storeSkuAudit)
dao.Commit(db)
@@ -4649,92 +4649,3 @@ func StoreSkuPriceAudit(ctx *jxcontext.Context, storeSkuAudits []*model.StoreSku
}
return hint, 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)
result2Orders(ctx, orderResult)
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,
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 := 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
}