This commit is contained in:
richboo111
2024-01-09 16:40:19 +08:00
parent 73daf2448e
commit b9438d317c

View File

@@ -3,9 +3,12 @@ package sfps
import (
"errors"
"fmt"
"net/http"
"strings"
"time"
beego "github.com/astaxie/beego/server/web"
tao "git.rosy.net.cn/baseapi/platformapi/tao_vegetable"
"git.rosy.net.cn/jx-callback/business/partner/purchase/tao_vegetable"
@@ -371,7 +374,14 @@ func (c *DeliveryHandler) UpdateWaybillTip(ctx *jxcontext.Context, vendorOrgCode
// OnWaybillMsg 配送状态更改回调
func OnWaybillMsg(urlIndex string, msg interface{}) (resp *sfps2.CallbackResponse) {
order := GetWaybillByStatus(urlIndex, msg)
order, goodsOrder := GetWaybillByStatus(urlIndex, msg)
//判断是否是果园
if goodsOrder == nil && beego.BConfig.RunMode != "jxgy" {
globals.SugarLogger.Debugf("sfsfsf 我在这里")
pushCallbackToGy(urlIndex, msg)
return sfps2.SuccessResponse
}
//多次取消回调只取第一次
tempStatus := utils.Str2Int(order.VendorStatus)
if tempStatus == sfps2.OrderStatusOrderCancel || tempStatus == sfps2.OrderStatusRiderCancel {
@@ -400,13 +410,7 @@ func OnWaybillMsg(urlIndex string, msg interface{}) (resp *sfps2.CallbackRespons
sfActualPrice := utils.Float64TwoInt64(sfOrder.RealPayMoney)
globals.SugarLogger.Debugf("SFPS OnWaybillMsg,sfTotalPrice=%d,sfActualPrice=%d", sfTotalPrice, sfActualPrice)
var good *model.GoodsOrder
sql := `SELECT * FROM goods_order WHERE vendor_order_id = ? ORDER BY order_created_at DESC LIMIT 1 OFFSET 0`
sqlParams := []interface{}{order.VendorOrderID}
dao.GetRow(dao.GetDB(), &good, sql, sqlParams)
order.OrderVendorID = good.VendorID
store, _ := dao.GetStoreDetail(dao.GetDB(), good.JxStoreID, good.VendorID, good.VendorOrgCode)
store, _ := dao.GetStoreDetail(dao.GetDB(), goodsOrder.JxStoreID, goodsOrder.VendorID, goodsOrder.VendorOrgCode)
sfTotalPrice += store.FreightMarkup
orderStatus := utils.Str2Int64(order.VendorStatus)
@@ -443,16 +447,40 @@ func OnWaybillMsg(urlIndex string, msg interface{}) (resp *sfps2.CallbackRespons
switch order.OrderVendorID {
case model.VendorIDDD:
Lng, Lat, _ := partner.GetRidderPositionGetter(order.WaybillVendorID).GetRidderPosition(nil, order.VendorOrderID, order.VendorOrderID, order.VendorWaybillID, order.VendorWaybillID2)
tiktokStatusPush(order, orderStatus, utils.Float64ToStr(Lng), utils.Float64ToStr(Lat), good.VendorOrgCode)
tiktokStatusPush(order, orderStatus, utils.Float64ToStr(Lng), utils.Float64ToStr(Lat), goodsOrder.VendorOrgCode)
case model.VendorIDTaoVegetable, model.VendorIDMTWM:
delivery.GetOrderRiderInfoToPlatform(order.VendorOrderID, order.Status) // 骑手位置更新
if good.VendorID == model.VendorIDTaoVegetable && orderStatus == sfps2.OrderStatusTakeOrder {
tao_vegetable.PushDelivererChangeInfo(good, order, tao.TaoDeliveryTypeSF)
if goodsOrder.VendorID == model.VendorIDTaoVegetable && orderStatus == sfps2.OrderStatusTakeOrder {
tao_vegetable.PushDelivererChangeInfo(goodsOrder, order, tao.TaoDeliveryTypeSF)
}
}
return sfps2.Err2CallbackResponse(nil)
}
//转发到果园
func pushCallbackToGy(urlIndex string, msg interface{}) {
var (
err error
client = http.Client{}
request *http.Request
param = make(map[string]interface{})
)
param = msg.(map[string]interface{})
globals.SugarLogger.Debugf("sfsfsf pushCallbackToGy param=%s", utils.Format4Output(param, false))
switch urlIndex {
case sfps2.UrlIndexRiderException:
request, err = http.NewRequest(http.MethodPost, "http://callback-jxgy.jxc4.com/SFPS/SfAbnormal", strings.NewReader(utils.Map2URLValues(param).Encode()))
default:
request, err = http.NewRequest(http.MethodPost, "http://callback-jxgy.jxc4.com/SFPS/SfOrder", strings.NewReader(utils.Map2URLValues(param).Encode()))
}
if err != nil {
return
}
request.Header.Set("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
client.Do(request)
}
func tiktokStatusPush(order *model.Waybill, orderStatus int64, lng, lat, vendorOrgCode string) {
result := &utils.RiderInfo{
OrderId: order.VendorOrderID,
@@ -513,11 +541,29 @@ func OnWaybillExceptSF(msg *sfps2.RiderException) (retVal *sfps2.CallbackRespons
return retVal
}
// GetWaybillByStatus 根据orderStatus 获取waybill结构
func GetWaybillByStatus(urlIndex string, msg interface{}) *model.Waybill {
// GetWaybillByStatus 根据orderStatus 获取waybill和goodsOrder结构
func GetWaybillByStatus(urlIndex string, msg interface{}) (waybill *model.Waybill, good2 *model.GoodsOrder) {
globals.SugarLogger.Debugf("GetWaybillByStatus msg=%s", utils.Format4Output(msg, false))
waybill := &model.Waybill{}
waybill = getWaybillByStatus(urlIndex, msg)
//获取系统订单
var good *model.GoodsOrder
sql := `SELECT * FROM goods_order WHERE vendor_order_id = ? ORDER BY order_created_at DESC LIMIT 1 OFFSET 0`
sqlParams := []interface{}{waybill.VendorOrderID}
err := dao.GetRow(dao.GetDB(), &good, sql, sqlParams)
if err != nil || good == nil || good.VendorOrderID == "" {
waybill.OrderVendorID = 0
} else {
waybill.OrderVendorID = good.VendorID
waybill.VendorOrderID = good.VendorOrderID
}
return waybill, good
}
//转换顺丰回调信息
func getWaybillByStatus(urlIndex string, msg interface{}) (waybill *model.Waybill) {
waybill = &model.Waybill{}
switch urlIndex {
case sfps2.UrlIndexRiderStatus:
retVal := msg.(sfps2.RiderStatus)
@@ -578,7 +624,6 @@ func GetWaybillByStatus(urlIndex string, msg interface{}) *model.Waybill {
default:
return nil
}
return waybill
}