京东商城订单补全
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++
|
||||
}
|
||||
|
||||
@@ -78,55 +78,6 @@ type StoreExt struct {
|
||||
OrderCount int `json:"orderCount"`
|
||||
}
|
||||
|
||||
type Store4User struct {
|
||||
model.ModelIDCULD
|
||||
|
||||
OriginalName string `orm:"-" json:"originalName"`
|
||||
Name string `orm:"size(255)" json:"name"`
|
||||
OpenTime1 int16 `json:"openTime1"` // 930就表示9点半,用两个的原因是为了支持中午休息,1与2的时间段不能交叉,为0表示没有
|
||||
CloseTime1 int16 `json:"closeTime1"` // 格式同上
|
||||
OpenTime2 int16 `json:"openTime2"` // 格式同上
|
||||
CloseTime2 int16 `json:"closeTime2"` // 格式同上
|
||||
Status int `json:"status"`
|
||||
CityCode int `orm:"default(0);null" json:"cityCode"` // todo ?
|
||||
DistrictCode int `orm:"default(0);null" json:"districtCode"` // todo ?
|
||||
Address string `orm:"size(255)" json:"address"`
|
||||
Tel1 string `orm:"size(32);index" json:"tel1"`
|
||||
Tel2 string `orm:"size(32);index" json:"tel2"`
|
||||
Lng int `json:"-"` // 乘了10的6次方
|
||||
Lat int `json:"-"` // 乘了10的6次方
|
||||
DeliveryRangeType int8 `json:"-"` // 参见相关常量定义
|
||||
DeliveryRange string `orm:"type(text)" json:"-"` // 如果DeliveryRangeType为DeliveryRangeTypePolygon,则为逗号分隔坐标,分号分隔的坐标点(坐标与Lng和Lat一样,都是整数),比如 121361504,31189308;121420555,31150238。否则为半径,单位为米
|
||||
|
||||
FloatLng float64 `json:"lng"`
|
||||
FloatLat float64 `json:"lat"`
|
||||
CityName string `json:"cityName"`
|
||||
DistrictName string `json:"districtName"`
|
||||
|
||||
Distance int `json:"distance"`
|
||||
WalkDistance int `json:"walkDistance"`
|
||||
}
|
||||
|
||||
type Store4UserList []*Store4User
|
||||
|
||||
func (x Store4UserList) Len() int {
|
||||
return len(x)
|
||||
}
|
||||
|
||||
func (x Store4UserList) Less(i, j int) bool {
|
||||
if x[i].Status != x[j].Status {
|
||||
return x[i].Status > x[j].Status
|
||||
}
|
||||
if x[i].WalkDistance != x[j].WalkDistance {
|
||||
return x[i].WalkDistance < x[j].WalkDistance
|
||||
}
|
||||
return x[i].Distance < x[j].Distance
|
||||
}
|
||||
|
||||
func (x Store4UserList) Swap(i, j int) {
|
||||
x[i], x[j] = x[j], x[i]
|
||||
}
|
||||
|
||||
type StoresInfo struct {
|
||||
TotalCount int `json:"totalCount"`
|
||||
MapCenterLng float64 `json:"mapCenterLng"`
|
||||
@@ -2482,97 +2433,6 @@ func SyncStoresQualify(ctx *jxcontext.Context, storeIDs []int, isAsync, isContin
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func GetStoreListByLocation(ctx *jxcontext.Context, lng, lat float64, maxRadius int, needWalkDistance bool) (storeList []*Store4User, err error) {
|
||||
const (
|
||||
maxStoreCount4User = 5
|
||||
)
|
||||
|
||||
lng2, _ := jxutils.ConvertDistanceToLogLat(lng, lat, float64(maxRadius), 90)
|
||||
_, lat2 := jxutils.ConvertDistanceToLogLat(lng, lat, float64(maxRadius), 0)
|
||||
lng1 := lng - (lng2 - lng)
|
||||
lat1 := lat - (lat2 - lat)
|
||||
// globals.SugarLogger.Debugf("%f,%f,%f,%f\n", lng1, lng2, lat1, lat2)
|
||||
sql := `
|
||||
SELECT t1.*,
|
||||
city.name city_name
|
||||
FROM store t1
|
||||
JOIN place city ON city.code = t1.city_code
|
||||
JOIN store_map sm ON sm.store_id = t1.id AND sm.vendor_id = ? AND sm.deleted_at = ? AND sm.status <> ?
|
||||
WHERE t1.deleted_at = ? AND t1.status <> ? AND t1.lng > ? AND t1.lng < ? AND t1.lat > ? AND t1.lat < ?
|
||||
AND sm.is_order <> ?
|
||||
AND t1.id <> ?
|
||||
ORDER BY t1.id
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
model.VendorIDJX, utils.DefaultTimeValue, model.StoreStatusDisabled,
|
||||
utils.DefaultTimeValue, model.StoreStatusDisabled, jxutils.StandardCoordinate2Int(lng1), jxutils.StandardCoordinate2Int(lng2), jxutils.StandardCoordinate2Int(lat1), jxutils.StandardCoordinate2Int(lat2),
|
||||
model.YES,
|
||||
model.MatterStoreID,
|
||||
}
|
||||
var storeList1 []*Store4User
|
||||
if err = dao.GetRows(dao.GetDB(), &storeList1, sql, sqlParams...); err == nil {
|
||||
var storeList2 []*Store4User
|
||||
for _, v := range storeList1 {
|
||||
distance := jxutils.Point2StoreDistance(lng, lat, v.Lng, v.Lat, v.DeliveryRangeType, v.DeliveryRange)
|
||||
if distance > 0 || (lng == jxutils.IntCoordinate2Standard(v.Lng) && lat == jxutils.IntCoordinate2Standard(v.Lat)) {
|
||||
v.Distance = distance
|
||||
storeList2 = append(storeList2, v)
|
||||
}
|
||||
}
|
||||
|
||||
// 为了审核用
|
||||
if len(storeList2) == 0 {
|
||||
sql2 := `
|
||||
SELECT t1.*,
|
||||
city.name city_name
|
||||
FROM store t1
|
||||
JOIN place city ON city.code = t1.city_code
|
||||
WHERE t1.deleted_at = ? AND t1.status <> ? AND t1.id = ?
|
||||
`
|
||||
sqlParams2 := []interface{}{
|
||||
// model.VendorIDJX, utils.DefaultTimeValue, model.StoreStatusDisabled,
|
||||
utils.DefaultTimeValue,
|
||||
model.StoreStatusDisabled,
|
||||
// jxutils.StandardCoordinate2Int(0),
|
||||
// jxutils.StandardCoordinate2Int(10000),
|
||||
// jxutils.StandardCoordinate2Int(0),
|
||||
// jxutils.StandardCoordinate2Int(10000),
|
||||
// model.YES,
|
||||
102919, //商城模板店
|
||||
}
|
||||
dao.GetRows(dao.GetDB(), &storeList2, sql2, sqlParams2...)
|
||||
// if len(storeList2) > 1 {
|
||||
// storeList2 = storeList2[:1]
|
||||
// }
|
||||
}
|
||||
|
||||
// 如果要求以步行距离来算
|
||||
if needWalkDistance {
|
||||
var coordList []*autonavi.Coordinate
|
||||
for _, v := range storeList2 {
|
||||
coordList = append(coordList, &autonavi.Coordinate{
|
||||
Lng: v.FloatLng,
|
||||
Lat: v.FloatLat,
|
||||
})
|
||||
}
|
||||
if distanceList, err2 := api.AutonaviAPI.BatchWalkingDistance(lng, lat, coordList); err2 == nil {
|
||||
for k, v := range storeList2 {
|
||||
v.WalkDistance = int(distanceList[k])
|
||||
}
|
||||
} else {
|
||||
return nil, err2
|
||||
}
|
||||
}
|
||||
|
||||
sort.Sort(Store4UserList(storeList2))
|
||||
storeList = storeList2
|
||||
if len(storeList) > maxStoreCount4User {
|
||||
storeList = storeList[:maxStoreCount4User]
|
||||
}
|
||||
}
|
||||
return storeList, err
|
||||
}
|
||||
|
||||
func JdStoreInfoCoordinateRecover(ctx *jxcontext.Context, vendorOrgCode string, files []*multipart.FileHeader) (err error) {
|
||||
if len(files) == 0 {
|
||||
return errors.New("没有文件上传!")
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
153
business/jxstore/common/common.go
Normal file
153
business/jxstore/common/common.go
Normal file
@@ -0,0 +1,153 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/autonavi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
type Store4User struct {
|
||||
model.ModelIDCULD
|
||||
|
||||
OriginalName string `orm:"-" json:"originalName"`
|
||||
Name string `orm:"size(255)" json:"name"`
|
||||
OpenTime1 int16 `json:"openTime1"` // 930就表示9点半,用两个的原因是为了支持中午休息,1与2的时间段不能交叉,为0表示没有
|
||||
CloseTime1 int16 `json:"closeTime1"` // 格式同上
|
||||
OpenTime2 int16 `json:"openTime2"` // 格式同上
|
||||
CloseTime2 int16 `json:"closeTime2"` // 格式同上
|
||||
Status int `json:"status"`
|
||||
CityCode int `orm:"default(0);null" json:"cityCode"` // todo ?
|
||||
DistrictCode int `orm:"default(0);null" json:"districtCode"` // todo ?
|
||||
Address string `orm:"size(255)" json:"address"`
|
||||
Tel1 string `orm:"size(32);index" json:"tel1"`
|
||||
Tel2 string `orm:"size(32);index" json:"tel2"`
|
||||
Lng int `json:"-"` // 乘了10的6次方
|
||||
Lat int `json:"-"` // 乘了10的6次方
|
||||
DeliveryRangeType int8 `json:"-"` // 参见相关常量定义
|
||||
DeliveryRange string `orm:"type(text)" json:"-"` // 如果DeliveryRangeType为DeliveryRangeTypePolygon,则为逗号分隔坐标,分号分隔的坐标点(坐标与Lng和Lat一样,都是整数),比如 121361504,31189308;121420555,31150238。否则为半径,单位为米
|
||||
|
||||
FloatLng float64 `json:"lng"`
|
||||
FloatLat float64 `json:"lat"`
|
||||
CityName string `json:"cityName"`
|
||||
DistrictName string `json:"districtName"`
|
||||
|
||||
Distance int `json:"distance"`
|
||||
WalkDistance int `json:"walkDistance"`
|
||||
}
|
||||
|
||||
type Store4UserList []*Store4User
|
||||
|
||||
func (x Store4UserList) Len() int {
|
||||
return len(x)
|
||||
}
|
||||
|
||||
func (x Store4UserList) Less(i, j int) bool {
|
||||
if x[i].Status != x[j].Status {
|
||||
return x[i].Status > x[j].Status
|
||||
}
|
||||
if x[i].WalkDistance != x[j].WalkDistance {
|
||||
return x[i].WalkDistance < x[j].WalkDistance
|
||||
}
|
||||
return x[i].Distance < x[j].Distance
|
||||
}
|
||||
|
||||
func (x Store4UserList) Swap(i, j int) {
|
||||
x[i], x[j] = x[j], x[i]
|
||||
}
|
||||
|
||||
func GetStoreListByLocation(ctx *jxcontext.Context, lng, lat float64, maxRadius int, needWalkDistance bool) (storeList []*Store4User, err error) {
|
||||
const (
|
||||
maxStoreCount4User = 5
|
||||
)
|
||||
|
||||
lng2, _ := jxutils.ConvertDistanceToLogLat(lng, lat, float64(maxRadius), 90)
|
||||
_, lat2 := jxutils.ConvertDistanceToLogLat(lng, lat, float64(maxRadius), 0)
|
||||
lng1 := lng - (lng2 - lng)
|
||||
lat1 := lat - (lat2 - lat)
|
||||
// globals.SugarLogger.Debugf("%f,%f,%f,%f\n", lng1, lng2, lat1, lat2)
|
||||
sql := `
|
||||
SELECT t1.*,
|
||||
city.name city_name
|
||||
FROM store t1
|
||||
JOIN place city ON city.code = t1.city_code
|
||||
JOIN store_map sm ON sm.store_id = t1.id AND sm.vendor_id = ? AND sm.deleted_at = ? AND sm.status <> ?
|
||||
WHERE t1.deleted_at = ? AND t1.status <> ? AND t1.lng > ? AND t1.lng < ? AND t1.lat > ? AND t1.lat < ?
|
||||
AND sm.is_order <> ?
|
||||
AND t1.id <> ?
|
||||
ORDER BY t1.id
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
model.VendorIDJX, utils.DefaultTimeValue, model.StoreStatusDisabled,
|
||||
utils.DefaultTimeValue, model.StoreStatusDisabled, jxutils.StandardCoordinate2Int(lng1), jxutils.StandardCoordinate2Int(lng2), jxutils.StandardCoordinate2Int(lat1), jxutils.StandardCoordinate2Int(lat2),
|
||||
model.YES,
|
||||
model.MatterStoreID,
|
||||
}
|
||||
var storeList1 []*Store4User
|
||||
if err = dao.GetRows(dao.GetDB(), &storeList1, sql, sqlParams...); err == nil {
|
||||
var storeList2 []*Store4User
|
||||
for _, v := range storeList1 {
|
||||
distance := jxutils.Point2StoreDistance(lng, lat, v.Lng, v.Lat, v.DeliveryRangeType, v.DeliveryRange)
|
||||
if distance > 0 || (lng == jxutils.IntCoordinate2Standard(v.Lng) && lat == jxutils.IntCoordinate2Standard(v.Lat)) {
|
||||
v.Distance = distance
|
||||
storeList2 = append(storeList2, v)
|
||||
}
|
||||
}
|
||||
|
||||
// 为了审核用
|
||||
if len(storeList2) == 0 {
|
||||
sql2 := `
|
||||
SELECT t1.*,
|
||||
city.name city_name
|
||||
FROM store t1
|
||||
JOIN place city ON city.code = t1.city_code
|
||||
WHERE t1.deleted_at = ? AND t1.status <> ? AND t1.id = ?
|
||||
`
|
||||
sqlParams2 := []interface{}{
|
||||
// model.VendorIDJX, utils.DefaultTimeValue, model.StoreStatusDisabled,
|
||||
utils.DefaultTimeValue,
|
||||
model.StoreStatusDisabled,
|
||||
// jxutils.StandardCoordinate2Int(0),
|
||||
// jxutils.StandardCoordinate2Int(10000),
|
||||
// jxutils.StandardCoordinate2Int(0),
|
||||
// jxutils.StandardCoordinate2Int(10000),
|
||||
// model.YES,
|
||||
102919, //商城模板店
|
||||
}
|
||||
dao.GetRows(dao.GetDB(), &storeList2, sql2, sqlParams2...)
|
||||
// if len(storeList2) > 1 {
|
||||
// storeList2 = storeList2[:1]
|
||||
// }
|
||||
}
|
||||
|
||||
// 如果要求以步行距离来算
|
||||
if needWalkDistance {
|
||||
var coordList []*autonavi.Coordinate
|
||||
for _, v := range storeList2 {
|
||||
coordList = append(coordList, &autonavi.Coordinate{
|
||||
Lng: v.FloatLng,
|
||||
Lat: v.FloatLat,
|
||||
})
|
||||
}
|
||||
if distanceList, err2 := api.AutonaviAPI.BatchWalkingDistance(lng, lat, coordList); err2 == nil {
|
||||
for k, v := range storeList2 {
|
||||
v.WalkDistance = int(distanceList[k])
|
||||
}
|
||||
} else {
|
||||
return nil, err2
|
||||
}
|
||||
}
|
||||
|
||||
sort.Sort(Store4UserList(storeList2))
|
||||
storeList = storeList2
|
||||
if len(storeList) > maxStoreCount4User {
|
||||
storeList = storeList[:maxStoreCount4User]
|
||||
}
|
||||
}
|
||||
return storeList, err
|
||||
}
|
||||
@@ -1,11 +1,14 @@
|
||||
package jdshop
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/jdshopapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
@@ -42,9 +45,16 @@ func (p *PurchaseHandler) GetOrderStatus(vendorOrgCode, vendorOrderID string) (s
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) AcceptOrRefuseOrder(order *model.GoodsOrder, isAcceptIt bool, userName string) (err error) {
|
||||
return err
|
||||
var status int
|
||||
if isAcceptIt {
|
||||
status = model.OrderStatusAccepted
|
||||
} else {
|
||||
status = model.OrderStatusCanceled
|
||||
}
|
||||
return changeOrderStatus(order.VendorOrderID, status, "")
|
||||
}
|
||||
func (p *PurchaseHandler) PickupGoods(order *model.GoodsOrder, isSelfDelivery bool, userName string) (err error) {
|
||||
err = changeOrderStatus(order.VendorOrderID, model.OrderStatusFinishedPickup, "")
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -105,3 +115,26 @@ func (p *PurchaseHandler) GetJdsOrders(ctx *jxcontext.Context, orderCreatedStart
|
||||
})
|
||||
return orderResult, err
|
||||
}
|
||||
|
||||
func changeOrderStatus(vendorOrderID string, status int, remark string) (err error) {
|
||||
orderStatus := &model.OrderStatus{
|
||||
VendorOrderID: vendorOrderID,
|
||||
VendorID: model.VendorIDJDShop,
|
||||
OrderType: model.OrderTypeOrder,
|
||||
RefVendorOrderID: vendorOrderID,
|
||||
RefVendorID: model.VendorIDJDShop,
|
||||
VendorStatus: utils.Int2Str(status),
|
||||
Status: status,
|
||||
StatusTime: time.Now(),
|
||||
Remark: remark,
|
||||
}
|
||||
jxutils.CallMsgHandlerAsync(func() {
|
||||
err = partner.CurOrderManager.OnOrderStatusChanged("", orderStatus)
|
||||
}, jxutils.ComposeUniversalOrderID(vendorOrderID, model.VendorIDJDShop))
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) OrderExport(ctx *jxcontext.Context, vendorOrderID, vendorWaybillID string) (err error) {
|
||||
err = api.JdShopAPI.OrderShipment(utils.Str2Int64(vendorOrderID), "", vendorWaybillID)
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user