- fixed a bug in defsch.init, replace LoadOrder with GetOrder.
- dynamic table name for legacy order related table.
This commit is contained in:
@@ -1,13 +1,22 @@
|
||||
package dada
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/dadaapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/controller"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/scheduler"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
"github.com/astaxie/beego/orm"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrCanNotFindDadaCityCode = errors.New("不能找到美团配送站点配置")
|
||||
)
|
||||
|
||||
type WaybillController struct {
|
||||
@@ -72,7 +81,7 @@ func (c *WaybillController) CreateWaybill(order *model.GoodsOrder) (err error) {
|
||||
ReceiverAddress: order.ConsigneeAddress,
|
||||
ReceiverPhone: order.ConsigneeMobile,
|
||||
}
|
||||
if billParams.CityCode, err = controller.GetDataCityCodeFromOrder(order); err == nil {
|
||||
if billParams.CityCode, err = c.getDataCityCodeFromOrder(order); err == nil {
|
||||
billParams.ReceiverLng, billParams.ReceiverLat, _ = jxutils.IntCoordinate2MarsStandard(order.ConsigneeLng, order.ConsigneeLat, order.CoordinateType)
|
||||
addParams := map[string]interface{}{
|
||||
"info": order.BuyerComment,
|
||||
@@ -94,6 +103,41 @@ func (c *WaybillController) CancelWaybill(bill *model.Waybill) (err error) {
|
||||
reasonID = dadaapi.ReasonIDNobodyPickup
|
||||
reasonMsg = "ReasonIDNobodyPickup"
|
||||
}
|
||||
_, err = api.DadaAPI.CancelOrder(bill.VendorWaybillID, reasonID, reasonMsg)
|
||||
_, err = api.DadaAPI.CancelOrder(bill.VendorOrderID, reasonID, reasonMsg)
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *WaybillController) getDataCityCodeFromOrder(order *model.GoodsOrder) (retVal string, err error) {
|
||||
var sql string
|
||||
if order.VendorID == model.VendorIDJD {
|
||||
sql = `
|
||||
SELECT t2.tel_code
|
||||
FROM jxstoremap t0
|
||||
JOIN jxstore t1 ON t0.jxstoreid = t1.storeid
|
||||
JOIN city t2 ON t1.area = t2.citycode
|
||||
WHERE t0.jdstoreid = ?
|
||||
`
|
||||
} else if order.VendorID == model.VendorIDELM {
|
||||
sql = `
|
||||
SELECT t2.tel_code
|
||||
FROM jx_to_elm_store_map t0
|
||||
JOIN jxstore t1 ON t0.jx_store_id = t1.storeid
|
||||
JOIN city t2 ON t1.area = t2.citycode
|
||||
WHERE t0.elm_store_id = ?
|
||||
`
|
||||
} else {
|
||||
panic(fmt.Sprintf("wrong vendorid:%d", order.VendorID))
|
||||
}
|
||||
db := orm.NewOrm()
|
||||
var lists []orm.ParamsList
|
||||
num, err := db.Raw(sql, utils.Str2Int64(order.VendorStoreID)).ValuesList(&lists)
|
||||
if err == nil && num == 1 {
|
||||
retVal = lists[0][0].(string)
|
||||
} else {
|
||||
globals.SugarLogger.Errorf("GetDataCityCodeFromOrder can not find store info for vendorID:%d, store:%s, num:%d, error:%v", order.VendorID, order.VendorStoreID, num, err)
|
||||
if err == nil {
|
||||
err = ErrCanNotFindDadaCityCode
|
||||
}
|
||||
}
|
||||
return retVal, err
|
||||
}
|
||||
|
||||
45
business/controller/dada/waybill_test.go
Normal file
45
business/controller/dada/waybill_test.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package dada
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/controller"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
"git.rosy.net.cn/jx-callback/globals/db"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
func init() {
|
||||
beego.InitBeegoBeforeTest("/Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf")
|
||||
beego.BConfig.RunMode = "dev" // InitBeegoBeforeTest会将runmode设置为test
|
||||
|
||||
globals.Init()
|
||||
db.Init()
|
||||
api.Init()
|
||||
}
|
||||
|
||||
func TestCreateWaybill(t *testing.T) {
|
||||
orderID := "817540316000041"
|
||||
if order, err := controller.OrderManager.LoadOrder(orderID, model.VendorIDJD); err == nil {
|
||||
// globals.SugarLogger.Debug(order)
|
||||
c := new(WaybillController)
|
||||
if err = c.CreateWaybill(order); err == nil {
|
||||
time.Sleep(1 * time.Second)
|
||||
bill := &model.Waybill{
|
||||
VendorOrderID: orderID,
|
||||
WaybillVendorID: model.VendorIDDada,
|
||||
}
|
||||
err = c.CancelWaybill(bill)
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
} else {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
} else {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user