Merge branch 'jdshop' of https://e.coding.net/rosydev/jx-callback into jdshop
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/platformapi/mtpsapi"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/dadaapi"
|
||||
@@ -42,6 +43,17 @@ var (
|
||||
"虞山街道": "虞山镇",
|
||||
"常福街道": "虞山镇",
|
||||
}
|
||||
complaintReasonsMap = map[int]string{
|
||||
1: "骑手态度恶劣",
|
||||
2: "骑手接单后未取货",
|
||||
3: "骑手取货太慢",
|
||||
4: "骑手送货太慢",
|
||||
5: "货品未送达",
|
||||
6: "货品有损坏",
|
||||
7: "骑手违规收取顾客其他费用",
|
||||
69: "骑手恶意取消订单",
|
||||
71: "骑手提前点击取货/送达",
|
||||
}
|
||||
)
|
||||
|
||||
type DeliveryHandler struct {
|
||||
@@ -176,12 +188,6 @@ func (c *DeliveryHandler) callbackMsg2Waybill(msg *dadaapi.CallbackMsg) (retVal
|
||||
}
|
||||
|
||||
func StoreDetail2ShopInfo(storeDetail *dao.StoreDetail2) (shopInfo *dadaapi.ShopInfo) {
|
||||
// 获取品牌名称
|
||||
brandInfo, err := dao.GetBrands(dao.GetDB(), "", storeDetail.BrandID, "", false, "")
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
lng := jxutils.IntCoordinate2Standard(storeDetail.Lng)
|
||||
lat := jxutils.IntCoordinate2Standard(storeDetail.Lat)
|
||||
cityName := storeDetail.CityName
|
||||
@@ -197,7 +203,7 @@ func StoreDetail2ShopInfo(storeDetail *dao.StoreDetail2) (shopInfo *dadaapi.Shop
|
||||
}
|
||||
shopInfo = &dadaapi.ShopInfo{
|
||||
OriginShopID: storeDetail.VendorStoreID,
|
||||
StationName: brandInfo[0].Name + "-" + storeDetail.Name,
|
||||
StationName: storeDetail.Name,
|
||||
Business: dadaapi.BusinessTypeConvStore, // 故意设置成这个的
|
||||
CityName: cityName,
|
||||
AreaName: districtName,
|
||||
@@ -546,14 +552,48 @@ func (c *DeliveryHandler) GetRiderInfo(orderId string, deliveryId int64, mtPeiso
|
||||
// 待接单,待取货(小于一分钟,大于十五分钟)不扣钱
|
||||
// 待取货1-15分钟内取消扣两元
|
||||
func (c *DeliveryHandler) GetDeliverLiquidatedDamages(orderId string, deliverId string) (money int64, err error) {
|
||||
orderStatus, err := orderman.FixedOrderManager.GetWayBillStatusList(orderId, deliverId, model.VendorIDDada)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
dadaOrder, err := api.DadaAPI.QueryOrderInfo(orderId)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// 本地状态兑换金额
|
||||
var localPrice int64 = 0
|
||||
for i := len(orderStatus) - 1; i >= 0; i-- {
|
||||
if orderStatus[i].VendorStatus == utils.Int2Str(dadaapi.OrderStatusCanceled) {
|
||||
continue
|
||||
}
|
||||
if orderStatus[i].VendorStatus == utils.Int2Str(dadaapi.OrderStatusFinished) || orderStatus[i].VendorStatus == utils.Int2Str(dadaapi.OrderStatusDelivering) || orderStatus[i].VendorStatus == utils.Int2Str(dadaapi.OrderStatusReturningInOrder) {
|
||||
localPrice = utils.Float64TwoInt64(dadaOrder.DeliveryFee * float64(100))
|
||||
break
|
||||
}
|
||||
if orderStatus[i].VendorStatus == utils.Int2Str(dadaapi.OrderStatusAccepted) {
|
||||
nowTime := time.Now().Unix()
|
||||
fetchTime := orderStatus[i].StatusTime.Unix()
|
||||
timeDiffer := nowTime - fetchTime
|
||||
if timeDiffer > 15*60 || timeDiffer < 60 {
|
||||
localPrice = 0
|
||||
} else {
|
||||
localPrice = 200
|
||||
}
|
||||
break
|
||||
}
|
||||
if orderStatus[i].VendorStatus == utils.Int2Str(dadaapi.OrderStatusWaitingForAccept) {
|
||||
localPrice = 0
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// 平台状态兑换金额
|
||||
var vendorPrice int64 = 0
|
||||
// 未接单不扣款
|
||||
if dadaOrder.AcceptTime == "" {
|
||||
return 0, nil
|
||||
vendorPrice = 0
|
||||
}
|
||||
|
||||
// 有了接单时间,订单变成了待取货
|
||||
@@ -562,20 +602,19 @@ func (c *DeliveryHandler) GetDeliverLiquidatedDamages(orderId string, deliverId
|
||||
fetchTime := utils.Str2Time(dadaOrder.AcceptTime).Unix()
|
||||
timeDiffer := nowTime - fetchTime
|
||||
if timeDiffer > 15*60 || timeDiffer < 60 {
|
||||
return 0, nil
|
||||
vendorPrice = 0
|
||||
}
|
||||
return 200, nil
|
||||
vendorPrice = 200
|
||||
}
|
||||
|
||||
// fetchTime 已经有时间了,代表已经取货.次数取消扣除此订单全部金额
|
||||
// 达达存在多个订单的运单违约金额统计在一起的情况
|
||||
if dadaOrder.FetchTime != "" {
|
||||
bill, err := partner.CurOrderManager.LoadWaybill(deliverId, model.VendorIDDada)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return bill.DesiredFee, nil
|
||||
vendorPrice = utils.Float64TwoInt64(dadaOrder.DeliveryFee * float64(100))
|
||||
}
|
||||
|
||||
return 0, err
|
||||
if localPrice > vendorPrice {
|
||||
return localPrice, nil
|
||||
}
|
||||
return vendorPrice, nil
|
||||
}
|
||||
|
||||
@@ -109,12 +109,6 @@ func (c *DeliveryHandler) IsErrStoreNotExist(err error) bool {
|
||||
}
|
||||
|
||||
func (c *DeliveryHandler) UpdateStore(ctx *jxcontext.Context, storeDetail *dao.StoreDetail2) (err error) {
|
||||
// 获取品牌名称
|
||||
brandInfo, err := dao.GetBrands(dao.GetDB(), "", storeDetail.BrandID, "", false, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 获取蜂鸟门店id
|
||||
fnStore, err := api.FnAPI.GetStore(storeDetail.VendorStoreID)
|
||||
if err != nil {
|
||||
@@ -139,7 +133,7 @@ func (c *DeliveryHandler) UpdateStore(ctx *jxcontext.Context, storeDetail *dao.S
|
||||
BusinessLicencePicHash: storeDetail.Licence,
|
||||
}
|
||||
if storeDetail.Name != fnStore.Name {
|
||||
updateStore.HeadShopName = brandInfo[0].Name + "-" + storeDetail.Name
|
||||
updateStore.HeadShopName = storeDetail.Name
|
||||
updateStore.BranchShopName = storeDetail.Name
|
||||
}
|
||||
if updateStore.OwnerName == "" {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/platformapi/mtpsapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -343,10 +344,10 @@ func (c *DeliveryHandler) OnWaybillExcept(msg *fnpsapi.AbnormalReportNotify) (re
|
||||
return retVal
|
||||
}
|
||||
|
||||
// 查询订单配送费
|
||||
// 查询订单配送费(蜂鸟加4毛)
|
||||
func GetDesiredFee(vendorOrderID string) (desiredFee, acuteFee int64) {
|
||||
if result, err := api.FnAPI.QueryOrder(vendorOrderID); err == nil {
|
||||
return result.OrderTotalAmountCent + int64(utils.WayBillDeliveryMarkUp), result.OrderActualAmountCent
|
||||
return result.OrderTotalAmountCent, result.OrderActualAmountCent
|
||||
}
|
||||
return desiredFee, acuteFee
|
||||
}
|
||||
@@ -415,16 +416,49 @@ func (c *DeliveryHandler) GetDeliverLiquidatedDamages(orderId string, deliverId
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// 本地状态兑换金额
|
||||
var localPrice int64 = 0
|
||||
orderStatus, err := orderman.FixedOrderManager.GetWayBillStatusList(orderId, deliverId, model.VendorIDFengNiao)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
for i := len(orderStatus) - 1; i >= 0; i-- {
|
||||
if orderStatus[i].VendorStatus == utils.Int2Str(fnpsapi.OrderStatusAcceptCacle) {
|
||||
continue
|
||||
}
|
||||
if orderStatus[i].VendorStatus == utils.Int2Str(fnpsapi.OrderStatusArrived) || orderStatus[i].VendorStatus == utils.Int2Str(fnpsapi.OrderStatusDelivering) || orderStatus[i].VendorStatus == utils.Int2Str(fnpsapi.OrderStatusDelivered) {
|
||||
localPrice = order.OrderTotalAmountCent
|
||||
break
|
||||
}
|
||||
if orderStatus[i].VendorStatus == utils.Int2Str(fnpsapi.OrderStatusAssigned) {
|
||||
nowTime := time.Now().Unix()
|
||||
fetchTime := orderStatus[i].StatusTime.Unix()
|
||||
timeDiffer := nowTime - fetchTime
|
||||
if timeDiffer > 15*60 || timeDiffer < 60 {
|
||||
localPrice = 0
|
||||
} else {
|
||||
localPrice = 200
|
||||
}
|
||||
break
|
||||
}
|
||||
if orderStatus[i].VendorStatus == utils.Int2Str(fnpsapi.OrderStatusAcceptCreate) || orderStatus[i].VendorStatus == utils.Int2Str(fnpsapi.OrderStatusAccept) {
|
||||
localPrice = 0
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// 已经分配骑手,且超过十五分钟,不扣款
|
||||
var vendorPrice int64 = 0
|
||||
if len(order.EventLogDetails) != model.NO {
|
||||
for i := len(order.EventLogDetails) - 1; i >= 0; i-- {
|
||||
switch order.EventLogDetails[i].OrderStatus {
|
||||
case fnpsapi.OrderStatusDelivered, fnpsapi.OrderStatusArrived, fnpsapi.OrderStatusDelivering: // 送达,到店,配送中 取消订单全额扣款
|
||||
return order.OrderTotalAmountCent, nil
|
||||
vendorPrice = order.OrderTotalAmountCent
|
||||
break
|
||||
case fnpsapi.OrderStatusAcceptCacle, fnpsapi.OrderStatusException: // 取消和异常状态,跳过查看上一状态
|
||||
continue
|
||||
case fnpsapi.OrderStatusAcceptCreate, fnpsapi.OrderStatusAccept: // 生成运单和系统接单取消不扣除费用
|
||||
return 0, nil
|
||||
vendorPrice = 0
|
||||
case fnpsapi.OrderStatusAssigned:
|
||||
if time.Now().UnixNano()/1e6-order.EventLogDetails[i].OccurTime > fnpsapi.WayBillPressureOrderTime {
|
||||
return 0, nil
|
||||
@@ -433,8 +467,9 @@ func (c *DeliveryHandler) GetDeliverLiquidatedDamages(orderId string, deliverId
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return 0, err
|
||||
if localPrice > vendorPrice {
|
||||
return localPrice, nil
|
||||
}
|
||||
return vendorPrice, nil
|
||||
}
|
||||
|
||||
@@ -71,12 +71,7 @@ func (c *DeliveryHandler) CreateStore(ctx *jxcontext.Context, storeDetail *dao.S
|
||||
if shopInfo.ShopLat <= 9999999 {
|
||||
shopInfo.ShopLat *= 10
|
||||
}
|
||||
// 获取品牌名称
|
||||
brandInfo, err := dao.GetBrands(dao.GetDB(), "", storeDetail.BrandID, "", false, "")
|
||||
if err != nil {
|
||||
return "", -1, err
|
||||
}
|
||||
shopInfo.ShopName = brandInfo[0].Name + "-" + storeDetail.Name
|
||||
|
||||
if globals.EnableStoreWrite {
|
||||
shopStatus, err = api.MtpsAPI.ShopCreate(shopInfo)
|
||||
if err == nil {
|
||||
@@ -174,7 +169,6 @@ func (c *DeliveryHandler) IsErrStoreExist(err error) bool {
|
||||
|
||||
func (c *DeliveryHandler) UpdateStore(ctx *jxcontext.Context, storeDetail *dao.StoreDetail2) (err error) {
|
||||
if globals.EnableStoreWrite {
|
||||
// err = api.MtpsAPI.PagePoiUpdate(storeDetail.VendorStoreID, storeDetail.PayeeName, storeDetail.Tel1, fakeContactEmail)
|
||||
shopInfo := &mtpsapi.ShopInfo{
|
||||
ShopID: utils.Int2Str(storeDetail.ID),
|
||||
ContactName: storeDetail.PayeeName,
|
||||
@@ -182,6 +176,7 @@ func (c *DeliveryHandler) UpdateStore(ctx *jxcontext.Context, storeDetail *dao.S
|
||||
ShopAddress: storeDetail.Address,
|
||||
ShopLat: storeDetail.Lat,
|
||||
ShopLng: storeDetail.Lng,
|
||||
ShopName: storeDetail.Name,
|
||||
}
|
||||
_, err = api.MtpsAPI.ShopUpdate(shopInfo)
|
||||
}
|
||||
|
||||
@@ -86,6 +86,17 @@ func (c *DeliveryHandler) OnWaybillExcept(msg *mtpsapi.CallbackOrderExceptionMsg
|
||||
|
||||
func (c *DeliveryHandler) onWaybillMsg(msg *mtpsapi.CallbackOrderMsg) (retVal *mtpsapi.CallbackResponse) {
|
||||
order := c.callbackMsg2Waybill(msg)
|
||||
// 多次取消,只处理第一次
|
||||
if msg.Status == mtpsapi.OrderStatusCanceled {
|
||||
bill, err := partner.CurOrderManager.LoadWaybill(msg.MtPeisongID, model.VendorIDMTPS)
|
||||
if err != nil {
|
||||
return mtpsapi.Err2CallbackResponse(err, fmt.Sprintf("%s", "获取订单状态错误"))
|
||||
}
|
||||
if bill.Status == model.OrderStatusCanceled {
|
||||
return mtpsapi.SuccessResponse
|
||||
}
|
||||
}
|
||||
|
||||
switch msg.Status {
|
||||
case mtpsapi.OrderStatusWaitingForSchedule:
|
||||
data, err := api.MtpsAPI.QueryOrderStatus(msg.DeliveryID, msg.MtPeisongID)
|
||||
@@ -493,29 +504,33 @@ func (c *DeliveryHandler) GetDeliverLiquidatedDamages(orderId string, deliverId
|
||||
return 0, err
|
||||
}
|
||||
|
||||
bill, err := partner.CurOrderManager.LoadWaybill(deliverId, model.VendorIDMTPS)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// 已经分配骑手,且超过十五分钟,不扣款
|
||||
if len(statusList) != model.NO {
|
||||
for i := len(statusList) - 1; i >= 0; i-- {
|
||||
switch statusList[i].VendorStatus {
|
||||
case utils.Int2Str(mtpsapi.OrderStatusWaitingForSchedule): // 待调度
|
||||
return 0, nil
|
||||
case utils.Int2Str(mtpsapi.OrderStatusCanceled): // 取消不管
|
||||
continue
|
||||
case utils.Int2Str(mtpsapi.OrderStatusDeliverred): // 送达
|
||||
continue
|
||||
case utils.Int2Str(mtpsapi.OrderStatusAccepted): // 接单
|
||||
// 接单取消扣凉快
|
||||
return 200, nil
|
||||
case utils.Int2Str(mtpsapi.OrderStatusPickedUp): // 取货
|
||||
bill, err := partner.CurOrderManager.LoadWaybill(deliverId, model.VendorIDMTPS)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return bill.DesiredFee, nil
|
||||
|
||||
}
|
||||
for i := len(statusList) - 1; i >= 0; i-- {
|
||||
// 取消不管
|
||||
if statusList[i].VendorStatus == utils.Int2Str(mtpsapi.OrderStatusCanceled) {
|
||||
continue
|
||||
}
|
||||
// 送达
|
||||
if statusList[i].VendorStatus == utils.Int2Str(mtpsapi.OrderStatusDeliverred) {
|
||||
return bill.DesiredFee, nil
|
||||
}
|
||||
// 到店
|
||||
if statusList[i].VendorStatus == utils.Int2Str(mtpsapi.OrderStatusPickedUp) {
|
||||
return bill.DesiredFee, nil
|
||||
}
|
||||
// 接单
|
||||
if statusList[i].VendorStatus == utils.Int2Str(mtpsapi.OrderStatusAccepted) {
|
||||
return 200, nil
|
||||
}
|
||||
// 待调度
|
||||
if statusList[i].VendorStatus == utils.Int2Str(mtpsapi.OrderStatusWaitingForSchedule) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -543,6 +543,11 @@ func GetVendorRiderInfo(wayBillVendorId, vendorId int, vendorOrderId, vendorWayb
|
||||
}
|
||||
|
||||
}
|
||||
if riderInfo.CourierName != "" && riderInfo.CourierPhone != "" {
|
||||
riderInfo.LogisticsContext = fmt.Sprintf(riderInfo.LogisticsContext, riderInfo.CourierName, riderInfo.CourierPhone)
|
||||
} else {
|
||||
riderInfo.LogisticsContext = fmt.Sprintf(riderInfo.LogisticsContext, "暂无", "暂无")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -404,3 +404,7 @@ func getReallyStoreID(storeID, jxStoreID int) int {
|
||||
return storeID
|
||||
}
|
||||
}
|
||||
|
||||
func (c *DeliveryHandler) UpdateStoreName(storeId, name string) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -5,14 +5,13 @@ import (
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/authz/autils"
|
||||
"git.rosy.net.cn/jx-callback/business/partner/delivery/dada"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
beego "github.com/astaxie/beego/server/web"
|
||||
|
||||
@@ -476,7 +475,7 @@ func getDataCityCodeFromOrder(order *model.GoodsOrder, db *dao.DaoDB) (retVal st
|
||||
}{}
|
||||
if err = dao.GetRow(db, codeInfo, sql, jxStoreID); err != nil {
|
||||
if err == nil {
|
||||
err = dada.ErrCanNotFindDadaCityCode
|
||||
err = errors.New("不能找到美团配送站点配置")
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -62,7 +62,6 @@ func pay4OrderByKs(ctx *jxcontext.Context, order *model.GoodsOrder, vendorPayTyp
|
||||
}
|
||||
// 预下单
|
||||
prePayInfo, err := api.KuaiShouApi.PreCreateOrder(param)
|
||||
globals.SugarLogger.Debugf("=======err : %v", err)
|
||||
if err == nil {
|
||||
orderPay = &model.OrderPay{
|
||||
PayOrderID: order.VendorOrderID, // 抖音订单id
|
||||
@@ -72,8 +71,8 @@ func pay4OrderByKs(ctx *jxcontext.Context, order *model.GoodsOrder, vendorPayTyp
|
||||
VendorID: order.VendorID,
|
||||
Status: 0,
|
||||
PayCreatedAt: time.Now(),
|
||||
PrepayID: "",
|
||||
CodeURL: prePayInfo, // 抖音支付token
|
||||
PrepayID: prePayInfo.OrderNo,
|
||||
CodeURL: prePayInfo.OrderInfoToken, // 抖音支付token
|
||||
TotalFee: int(order.ActualPayPrice),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user