- mtps, dada create waybill
- create legacy jxorder(not finished).
This commit is contained in:
@@ -4,9 +4,12 @@ import (
|
||||
"git.rosy.net.cn/baseapi/platformapi/mtpsapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/controller"
|
||||
"git.rosy.net.cn/jx-callback/business/legacyorder"
|
||||
"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"
|
||||
)
|
||||
|
||||
type WaybillController struct {
|
||||
@@ -76,10 +79,69 @@ func (c *WaybillController) callbackMsg2Waybill(msg *mtpsapi.CallbackOrderMsg) (
|
||||
}
|
||||
|
||||
//
|
||||
func (c *WaybillController) CreateWaybill(bill *model.Waybill) (err error) {
|
||||
return nil
|
||||
func (c *WaybillController) CreateWaybill(order *model.GoodsOrder) (err error) {
|
||||
db := orm.NewOrm()
|
||||
// 忽略坐标转换错误,即使是转换出错,也只能当成转换成功来处理,底层会有错误日志输出
|
||||
lngFloat, latFloat, _ := controller.IntCoordinate2MarsStandard(order.ConsigneeLng, order.ConsigneeLat, order.CoordinateType)
|
||||
billParams := &mtpsapi.CreateOrderByShopParam{
|
||||
OrderID: controller.ComposeUniversalOrderID(order.VendorOrderID, order.VendorID),
|
||||
DeliveryServiceCode: mtpsapi.DeliveryServiceCodeRapid,
|
||||
ReceiverName: order.ConsigneeName,
|
||||
ReceiverAddress: order.ConsigneeAddress,
|
||||
ReceiverPhone: order.ConsigneeMobile,
|
||||
CoordinateType: model.CoordinateTypeMars,
|
||||
ReceiverLng: controller.StandardCoordinate2Int(lngFloat),
|
||||
ReceiverLat: controller.StandardCoordinate2Int(latFloat),
|
||||
GoodsValue: controller.IntPrice2Standard(order.SalePrice), // todo 超价处理
|
||||
GoodsWeight: float64(order.Weight) / 1000,
|
||||
ExpectedDeliveryTime: order.ExpectedDeliveredTime.Unix(),
|
||||
OrderType: mtpsapi.OrderTypeASAP,
|
||||
}
|
||||
if billParams.DeliveryID, err = c.getDeliveryID(order, db); err == nil {
|
||||
if billParams.ShopID, err = c.getMTPSShopID(order, db); err == nil {
|
||||
goods := &mtpsapi.GoodsDetail{
|
||||
Goods: []*mtpsapi.GoodsItem{},
|
||||
}
|
||||
for _, sku := range order.Skus {
|
||||
goodItem := &mtpsapi.GoodsItem{
|
||||
GoodCount: sku.Count,
|
||||
GoodName: sku.SkuName,
|
||||
GoodPrice: controller.IntPrice2Standard(sku.SalePrice),
|
||||
GoodUnit: "", //这个应该不是必须的,商品名里已经有UNIT的字样了
|
||||
}
|
||||
goods.Goods = append(goods.Goods, goodItem)
|
||||
}
|
||||
addParams := utils.Params2Map("note", order.BuyerComment, "good_detail", string(utils.MustMarshal(goods)))
|
||||
_, err = api.MtpsAPI.CreateOrderByShop(billParams, addParams)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *WaybillController) CancelWaybill(bill *model.Waybill) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 生成mtps deliveryid,为了兼容,现在取jxorder中的id
|
||||
func (c *WaybillController) getDeliveryID(order *model.GoodsOrder, db orm.Ormer) (retVal int64, err error) {
|
||||
jxorder := &legacyorder.Jxorder2{
|
||||
OrderId: utils.Str2Int64(order.VendorOrderID),
|
||||
}
|
||||
err = utils.CallFuncLogError(func() error {
|
||||
err2 := db.Read(order, "OrderId")
|
||||
return err2
|
||||
}, "getDeliveryID")
|
||||
return int64(jxorder.Id), err
|
||||
}
|
||||
|
||||
func (c *WaybillController) getMTPSShopID(order *model.GoodsOrder, db orm.Ormer) (retVal string, err error) {
|
||||
sql := "SELECT zs_store_id FROM jx_to_zs_store_map WHERE jx_store_id = ?"
|
||||
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("can not find mtps store info for store:%d", order.JxStoreID)
|
||||
}
|
||||
return retVal, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user