jdsorder 大大运费
This commit is contained in:
@@ -9,8 +9,12 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/partner/delivery/dada"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"github.com/astaxie/beego"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/dadaapi"
|
||||
"git.rosy.net.cn/baseapi/platformapi/dingdingapi"
|
||||
"git.rosy.net.cn/baseapi/platformapi/jcqapi"
|
||||
"git.rosy.net.cn/baseapi/platformapi/jdshopapi"
|
||||
@@ -240,6 +244,12 @@ func result2Orders(msg *jdshopapi.CallBackResult) (order *model.GoodsOrder, err
|
||||
if order.OrderType == model.OrderTypeAddressErr {
|
||||
buildOrderTo102919(order)
|
||||
}
|
||||
billParams, _ := GetDaDaBillParams(dao.GetDB(), order)
|
||||
if result, err := api.DadaAPI.QueryDeliverFee(billParams); err == nil {
|
||||
if jxutils.StandardPrice2Int(result.Fee) > 10 {
|
||||
buildOrderTo102919(order)
|
||||
}
|
||||
}
|
||||
return order, err
|
||||
}
|
||||
|
||||
@@ -312,3 +322,83 @@ func getAllRealOrderID(orderID string) (orders []*model.GoodsOrder) {
|
||||
dao.GetRows(db, &orders, sql, sqlParams)
|
||||
return orders
|
||||
}
|
||||
|
||||
func GetDaDaBillParams(db *dao.DaoDB, order *model.GoodsOrder) (billParams *dadaapi.OperateOrderParams, err error) {
|
||||
billParams = &dadaapi.OperateOrderParams{
|
||||
OriginID: jxutils.ComposeUniversalOrderID(order.VendorOrderID, order.VendorID),
|
||||
CargoPrice: jxutils.IntPrice2Standard(limitOrderPrice(order.ActualPayPrice)),
|
||||
IsPrepay: 0,
|
||||
ReceiverName: utils.FilterMb4(order.ConsigneeName),
|
||||
ReceiverAddress: utils.FilterMb4(order.ConsigneeAddress),
|
||||
ReceiverPhone: order.ConsigneeMobile,
|
||||
}
|
||||
if billParams.ShopNo, err = getDadaShopID(order, db); err == nil {
|
||||
if billParams.CityCode, err = getDataCityCodeFromOrder(order, db); err == nil {
|
||||
// storeTel := ""
|
||||
// storeID := jxutils.GetSaleStoreIDFromOrder(order)
|
||||
// storeDeatail, _ := dao.GetStoreDetail(db, storeID, order.VendorID)
|
||||
// if storeDeatail.Tel2 != "" {
|
||||
// storeTel = ",门店电话:" + storeDeatail.Tel2
|
||||
// }
|
||||
billParams.ReceiverLng, billParams.ReceiverLat, _ = jxutils.IntCoordinate2MarsStandard(order.ConsigneeLng, order.ConsigneeLat, order.CoordinateType)
|
||||
billParams.Info = fmt.Sprintf("%s第%d号订单, %s", model.VendorChineseNames[order.VendorID], order.OrderSeq, utils.FilterMb4("客户电话:"+order.ConsigneeMobile+","+order.BuyerComment+"取货失败或配送遇到问题请联系18048531223,禁止未配送直接完成定单!"))
|
||||
billParams.CargoType = dadaapi.CargoTypeFresh
|
||||
billParams.CargoWeight = float64(jxutils.IntWeight2Float(limitOrderWeight(order.Weight)))
|
||||
billParams.CargoNum = order.GoodsCount
|
||||
}
|
||||
}
|
||||
return billParams, err
|
||||
}
|
||||
|
||||
func limitOrderPrice(price int64) int64 {
|
||||
var maxOrderPrice int64 = 6399
|
||||
if price > maxOrderPrice {
|
||||
return maxOrderPrice
|
||||
}
|
||||
return price
|
||||
}
|
||||
|
||||
func limitOrderWeight(weight int) int {
|
||||
maxOrderWeight := 5000 // 5公斤
|
||||
if weight > maxOrderWeight {
|
||||
return maxOrderWeight
|
||||
}
|
||||
return weight
|
||||
}
|
||||
|
||||
func getDadaShopID(order *model.GoodsOrder, db *dao.DaoDB) (retVal string, err error) {
|
||||
saleStoreID := jxutils.GetSaleStoreIDFromOrder(order)
|
||||
storeCourierList, err2 := dao.GetOpenedStoreCouriersByStoreID(db, saleStoreID, model.VendorIDDada)
|
||||
if err = err2; err != nil && !dao.IsNoRowsError(err) {
|
||||
return "", err
|
||||
}
|
||||
if len(storeCourierList) == 0 {
|
||||
return "", partner.ErrStoreHaveNoCourier
|
||||
}
|
||||
retVal = storeCourierList[0].VendorStoreID
|
||||
if beego.BConfig.RunMode == "dev" {
|
||||
retVal = "test_0001"
|
||||
}
|
||||
return retVal, nil
|
||||
}
|
||||
|
||||
func getDataCityCodeFromOrder(order *model.GoodsOrder, db *dao.DaoDB) (retVal string, err error) {
|
||||
jxStoreID := jxutils.GetSaleStoreIDFromOrder(order)
|
||||
sql := `
|
||||
SELECT t2.tel_code
|
||||
FROM store t1
|
||||
JOIN place t2 on t1.city_code = t2.code
|
||||
WHERE t1.id = ?
|
||||
`
|
||||
codeInfo := &struct {
|
||||
TelCode string
|
||||
}{}
|
||||
if err = dao.GetRow(db, codeInfo, sql, jxStoreID); err != nil {
|
||||
globals.SugarLogger.Errorf("GetDataCityCodeFromOrder can not find store info for vendorID:%d, store:%s, error:%v", order.VendorID, order.VendorStoreID, err)
|
||||
if err == nil {
|
||||
err = dada.ErrCanNotFindDadaCityCode
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
return codeInfo.TelCode, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user