- orderUseNewTable except store feature related.

This commit is contained in:
gazebo
2018-10-17 14:28:49 +08:00
parent c5421213b2
commit 9f3624c777
10 changed files with 190 additions and 34 deletions

View File

@@ -9,6 +9,7 @@ import (
"git.rosy.net.cn/jx-callback/business/jxcallback/scheduler"
"git.rosy.net.cn/jx-callback/business/jxutils"
"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"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
@@ -167,6 +168,27 @@ func (c *DeliveryHandler) CancelWaybill(bill *model.Waybill, cancelReasonID int,
func (c *DeliveryHandler) getDataCityCodeFromOrder(order *model.GoodsOrder, db orm.Ormer) (retVal string, err error) {
var sql string
if globals.OrderUseNewTable {
jxStoreID := jxutils.GetJxStoreIDFromOrder(order)
sql = `
SELECT t2.tel_code
FROM store t1
JOIN place t2 on t1.city_code = t2.code
WHERE t1.id = ?
`
db2 := dao.WrapDB(db)
codeInfo := &struct {
TelCode string
}{}
if err = dao.GetRow(db2, 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 = ErrCanNotFindDadaCityCode
}
return "", err
}
return codeInfo.TelCode, nil
}
storeID := utils.Str2Int64(order.VendorStoreID)
if order.VendorID == model.VendorIDJD {
sql = `

View File

@@ -11,6 +11,7 @@ import (
"git.rosy.net.cn/jx-callback/business/jxcallback/scheduler"
"git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/model/dao"
"git.rosy.net.cn/jx-callback/business/model/legacymodel"
"git.rosy.net.cn/jx-callback/business/partner"
"git.rosy.net.cn/jx-callback/globals"
@@ -111,27 +112,49 @@ func (c *DeliveryHandler) callbackMsg2Waybill(msg *mtpsapi.CallbackOrderMsg) (re
}
func (c *DeliveryHandler) calculateOrderDeliveryFee(order *model.GoodsOrder, billTime time.Time, db orm.Ormer) (deliveryFee, addFee int64, err error) {
var lists []orm.ParamsList
if db == nil {
db = orm.NewOrm()
}
JxStoreID := jxutils.GetJxStoreIDFromOrder(order)
num, err := db.Raw(`
SELECT t2.price, t1.lng, t1.lat
FROM jxstore t1
JOIN mtpsdeliveryprice t2 ON t2.citycode = t1.area
WHERE t1.storeid = ?
`, JxStoreID).ValuesList(&lists)
if err == nil && num == 1 {
deliveryFee = utils.Str2Int64(lists[0][0].(string))
var lng, lat float64
if globals.OrderUseNewTable {
priceInfo := &struct {
Price int
Lng int
Lat int
}{}
db2 := dao.WrapDB(db)
if err = dao.GetRow(db2, priceInfo, `
SELECT t2.mtps_price price, t1.lng, t1.lat
FROM store t1
JOIN place t2 ON t1.city_code = t2.code
WHERE t1.id = ? AND t1.deleted_at = ?
`, JxStoreID, utils.DefaultTimeValue); err != nil {
return 0, 0, err
}
lng = jxutils.IntCoordinate2Standard(priceInfo.Lng)
lat = jxutils.IntCoordinate2Standard(priceInfo.Lat)
deliveryFee = int64(priceInfo.Price)
} else {
globals.SugarLogger.Warnf("calculateDeliveryFee can not calculate delivery fee for orderID:%s, num:%d, error:%v", order.VendorOrderID, num, err)
return 0, 0, ErrStoreNoPriceInfo
var lists []orm.ParamsList
num, err := db.Raw(`
SELECT t2.price, t1.lng, t1.lat
FROM jxstore t1
JOIN mtpsdeliveryprice t2 ON t2.citycode = t1.area
WHERE t1.storeid = ?
`, JxStoreID).ValuesList(&lists)
if err != nil || num == 0 {
globals.SugarLogger.Warnf("calculateDeliveryFee can not calculate delivery fee for orderID:%s, num:%d, error:%v", order.VendorOrderID, num, err)
if err != nil {
return 0, 0, err
}
return 0, 0, ErrStoreNoPriceInfo
}
lng = utils.Str2Float64(utils.Interface2String(lists[0][1]))
lat = utils.Str2Float64(utils.Interface2String(lists[0][2]))
deliveryFee = utils.Str2Int64(lists[0][0].(string))
}
lng := utils.Str2Float64(utils.Interface2String(lists[0][1]))
lat := utils.Str2Float64(utils.Interface2String(lists[0][2]))
if lng == 0 || lat == 0 {
globals.SugarLogger.Warnf("calculateDeliveryFee can not calculate delivery fee for orderID:%s, because no coordinate info", order.VendorOrderID)
return 0, 0, ErrStoreNoCoordinate