- mtps, dada create waybill
- create legacy jxorder(not finished).
This commit is contained in:
@@ -59,7 +59,7 @@ func (c *OrderController) cancelRefundMsg2Status(msg *elmapi.CallbackOrderCancel
|
||||
VendorOrderID: msg.OrderID,
|
||||
VendorID: model.VendorIDELM,
|
||||
OrderType: model.OrderTypeOrder,
|
||||
VendorStatus: utils.Int2Str(msg.MsgType),
|
||||
VendorStatus: c.stateAndType2Str(msg.RefundStatus, msg.MsgType),
|
||||
StatusTime: utils.Timestamp2Time(msg.UpdateTime),
|
||||
}
|
||||
return orderStatus
|
||||
@@ -78,7 +78,11 @@ func (c *OrderController) onOrderStatusMsg(msg *elmapi.CallbackOrderStatusMsg) (
|
||||
globals.SugarLogger.Warnf("elm msg:%d not handled", msg.MsgType)
|
||||
return elmapi.SuccessResponse
|
||||
}
|
||||
return elmapi.Err2CallbackResponse(controller.OrderManager.OnOrderStatusChanged(status), status.VendorStatus)
|
||||
err := controller.OrderManager.OnOrderStatusChanged(status)
|
||||
if globals.HandleLegacyJxOrder && err == nil {
|
||||
c.legacyElmOrderStatusChanged(status)
|
||||
}
|
||||
return elmapi.Err2CallbackResponse(err, status.VendorStatus)
|
||||
}
|
||||
|
||||
func (c *OrderController) onOrderCancelRefundMsg(msg *elmapi.CallbackOrderCancelRefundMsg) (retVal *elmapi.CallbackResponse) {
|
||||
@@ -94,28 +98,32 @@ func (c *OrderController) onOrderCancelRefundMsg(msg *elmapi.CallbackOrderCancel
|
||||
return elmapi.Err2CallbackResponse(controller.OrderManager.OnOrderStatusChanged(status), status.VendorStatus)
|
||||
}
|
||||
|
||||
func (c *OrderController) getOrderInfo(msg *elmapi.CallbackOrderStatusMsg) (order *model.GoodsOrder, orderSkus []*model.OrderSku, err error) {
|
||||
result, err := api.ElmAPI.GetOrder(msg.OrderID)
|
||||
func (c *OrderController) getOrderInfo(orderID string) (order *model.GoodsOrder, err error) {
|
||||
result, err := api.ElmAPI.GetOrder(orderID)
|
||||
if err == nil {
|
||||
phoneList := result["phoneList"].([]interface{})
|
||||
consigneeMobile := ""
|
||||
if len(phoneList) > 0 {
|
||||
consigneeMobile = phoneList[0].(string)
|
||||
consigneeMobile = utils.Interface2String(phoneList[0])
|
||||
}
|
||||
|
||||
// globals.SugarLogger.Debug(result)
|
||||
order = &model.GoodsOrder{
|
||||
VendorOrderID: msg.OrderID,
|
||||
VendorID: model.VendorIDELM,
|
||||
VendorStoreID: utils.Int64ToStr(utils.MustInterface2Int64(result["shopId"])),
|
||||
StoreID: int(utils.Str2Int64WithDefault(utils.Interface2String(result["openId"]), 0)),
|
||||
StoreName: result["shopName"].(string),
|
||||
ConsigneeName: result["consignee"].(string),
|
||||
ConsigneeMobile: consigneeMobile,
|
||||
ConsigneeAddress: result["address"].(string),
|
||||
VendorStatus: msg.State,
|
||||
OrderCreatedAt: utils.Str2Time(result["createdAt"].(string)),
|
||||
OriginalData: string(utils.MustMarshal(result)),
|
||||
VendorOrderID: orderID,
|
||||
VendorID: model.VendorIDELM,
|
||||
VendorStoreID: utils.Int64ToStr(utils.MustInterface2Int64(result["shopId"])),
|
||||
StoreID: int(utils.Str2Int64WithDefault(utils.Interface2String(result["openId"]), 0)),
|
||||
StoreName: result["shopName"].(string),
|
||||
ConsigneeName: result["consignee"].(string),
|
||||
ConsigneeMobile: consigneeMobile,
|
||||
ConsigneeAddress: result["address"].(string),
|
||||
BuyerComment: utils.Interface2String(result["description"]),
|
||||
ExpectedDeliveredTime: utils.Str2TimeWithDefault(utils.Interface2String(result["deliverTime"]), utils.DefaultTimeValue),
|
||||
// 这里已经做了elm VendorStatus的状态组合了
|
||||
VendorStatus: c.stateAndType2Str(utils.Interface2String(result["status"]), elmapi.MsgTypeOrderValid),
|
||||
OrderCreatedAt: utils.Str2Time(result["createdAt"].(string)),
|
||||
OriginalData: string(utils.MustMarshal(result)),
|
||||
Skus: []*model.OrderSku{},
|
||||
}
|
||||
deliveryGeo := strings.Split(utils.Interface2String(result["deliveryGeo"]), ",")
|
||||
if len(deliveryGeo) == 2 {
|
||||
@@ -124,23 +132,22 @@ func (c *OrderController) getOrderInfo(msg *elmapi.CallbackOrderStatusMsg) (orde
|
||||
order.ConsigneeLat = controller.StandardCoordinate2Int(utils.Str2Float64(deliveryGeo[1]))
|
||||
}
|
||||
|
||||
orderSkus = []*model.OrderSku{}
|
||||
for _, group2 := range result["groups"].([]interface{}) {
|
||||
group := group2.(map[string]interface{})
|
||||
for _, product2 := range group["items"].([]interface{}) {
|
||||
product := product2.(map[string]interface{})
|
||||
sku := &model.OrderSku{
|
||||
VendorOrderID: msg.OrderID,
|
||||
VendorOrderID: orderID,
|
||||
VendorID: model.VendorIDELM,
|
||||
Count: int(utils.MustInterface2Int64(product["quantity"])),
|
||||
SkuID: int(utils.Str2Int64WithDefault(utils.Interface2String(product["extendCode"]), 0)),
|
||||
VendorSkuID: utils.Int64ToStr(utils.MustInterface2Int64(product["skuId"])),
|
||||
SkuName: product["name"].(string),
|
||||
SalePrice: int64(math.Round(utils.MustInterface2Float64(product["userPrice"]) * 100)),
|
||||
Weight: int(math.Round(utils.Interface2Float64(product["weight"]))),
|
||||
SalePrice: controller.StandardPrice2Int(utils.MustInterface2Float64(product["userPrice"])),
|
||||
Weight: int(math.Round(utils.Interface2FloatWithDefault(product["weight"], 0.0))),
|
||||
OrderCreatedAt: order.OrderCreatedAt,
|
||||
}
|
||||
orderSkus = append(orderSkus, sku)
|
||||
order.Skus = append(order.Skus, sku)
|
||||
order.SkuCount++
|
||||
order.GoodsCount += sku.Count
|
||||
order.SalePrice += sku.SalePrice
|
||||
@@ -148,20 +155,19 @@ func (c *OrderController) getOrderInfo(msg *elmapi.CallbackOrderStatusMsg) (orde
|
||||
}
|
||||
}
|
||||
}
|
||||
return order, orderSkus, err
|
||||
return order, err
|
||||
}
|
||||
|
||||
//
|
||||
func (c *OrderController) onOrderNew(msg map[string]interface{}) (response *elmapi.CallbackResponse) {
|
||||
// todo 这里应该可以直接用msg里的内容,而不用再次去查
|
||||
fakeOrderMsg := &elmapi.CallbackOrderStatusMsg{
|
||||
OrderID: msg["orderId"].(string),
|
||||
State: c.stateAndType2Str(msg["status"].(string), elmapi.MsgTypeOrderValid),
|
||||
}
|
||||
order, orderSkus, err := c.getOrderInfo(fakeOrderMsg)
|
||||
order, err := c.getOrderInfo(msg["orderId"].(string))
|
||||
if err == nil {
|
||||
order.Status = model.OrderStatusNew
|
||||
err = controller.OrderManager.OnOrderNew(order, orderSkus)
|
||||
err = controller.OrderManager.OnOrderNew(order)
|
||||
if globals.HandleLegacyJxOrder && err == nil {
|
||||
c.legacyWriteElmOrder(order)
|
||||
}
|
||||
}
|
||||
return elmapi.Err2CallbackResponse(err, "elm onOrderNew")
|
||||
}
|
||||
@@ -182,6 +188,18 @@ func (c *OrderController) stateAndType2Str(state string, msgType int) string {
|
||||
return fmt.Sprintf("%s-%d", state, msgType)
|
||||
}
|
||||
|
||||
func (c *OrderController) spliltCompositeState(compositeState string) (state string, msgType int) {
|
||||
index := strings.Index(compositeState, "-")
|
||||
if index >= 0 {
|
||||
msgType = int(utils.Str2Int64(compositeState[index+1:]))
|
||||
if msgType == 0 {
|
||||
globals.SugarLogger.Debug(compositeState)
|
||||
}
|
||||
return compositeState[:index], msgType
|
||||
}
|
||||
return compositeState, 0
|
||||
}
|
||||
|
||||
// PurchasePlatformHandler
|
||||
func (c *OrderController) AcceptOrRefuseOrder(order *model.GoodsOrder, isAcceptIt bool) (err error) {
|
||||
if isAcceptIt {
|
||||
|
||||
Reference in New Issue
Block a user