1
This commit is contained in:
@@ -58,7 +58,7 @@ func (w *OrderManager) LoadPendingWaybills() []*model.Waybill {
|
|||||||
return bills
|
return bills
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *OrderManager) onWaybillNew(bill2 *model.Waybill, db *dao.DaoDB) (isDuplicated bool, err error) {
|
func (w *OrderManager) OnWaybillNew(bill2 *model.Waybill, db *dao.DaoDB) (isDuplicated bool, err error) {
|
||||||
isDuplicated, err = addOrderOrWaybillStatus(model.Waybill2Status(bill2), db)
|
isDuplicated, err = addOrderOrWaybillStatus(model.Waybill2Status(bill2), db)
|
||||||
if err == nil && !isDuplicated {
|
if err == nil && !isDuplicated {
|
||||||
bill2.ID = 0
|
bill2.ID = 0
|
||||||
@@ -111,7 +111,7 @@ func (w *OrderManager) OnWaybillStatusChanged(bill *model.Waybill) (err error) {
|
|||||||
}()
|
}()
|
||||||
duplicatedCount := 0
|
duplicatedCount := 0
|
||||||
if bill.Status == model.WaybillStatusNew {
|
if bill.Status == model.WaybillStatusNew {
|
||||||
isDuplicated, err = w.onWaybillNew(bill, db)
|
isDuplicated, err = w.OnWaybillNew(bill, db)
|
||||||
if isDuplicated {
|
if isDuplicated {
|
||||||
duplicatedCount = 1
|
duplicatedCount = 1
|
||||||
}
|
}
|
||||||
@@ -127,7 +127,7 @@ func (w *OrderManager) OnWaybillStatusChanged(bill *model.Waybill) (err error) {
|
|||||||
existingBill = bill
|
existingBill = bill
|
||||||
billCopy := *bill
|
billCopy := *bill
|
||||||
billCopy.Status = model.WaybillStatusNew
|
billCopy.Status = model.WaybillStatusNew
|
||||||
if isDuplicated, err = w.onWaybillNew(&billCopy, db); err != nil {
|
if isDuplicated, err = w.OnWaybillNew(&billCopy, db); err != nil {
|
||||||
dao.Rollback(db, txDB)
|
dao.Rollback(db, txDB)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package defsch
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
||||||
"math"
|
"math"
|
||||||
"time"
|
"time"
|
||||||
@@ -23,14 +24,14 @@ func (s *DefScheduler) loadSavedOrderByID(vendorOrderID string, vendorID int, is
|
|||||||
}, isForceLoad)
|
}, isForceLoad)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DefScheduler) SelfDeliveringAndUpdateStatus(ctx *jxcontext.Context, vendorOrderID string, vendorID int, userName string) (err error) {
|
func (s *DefScheduler) SelfDeliveringAndUpdateStatus(ctx *jxcontext.Context, vendorOrderID string, vendorID int, userName, courierName, courierMobile string) (err error) {
|
||||||
var order *model.GoodsOrder
|
var order *model.GoodsOrder
|
||||||
jxutils.CallMsgHandler(func() {
|
jxutils.CallMsgHandler(func() {
|
||||||
err = func() (err error) {
|
err = func() (err error) {
|
||||||
savedOrderInfo := s.loadSavedOrderByID(vendorOrderID, vendorID, true)
|
savedOrderInfo := s.loadSavedOrderByID(vendorOrderID, vendorID, true)
|
||||||
if savedOrderInfo != nil {
|
if savedOrderInfo != nil {
|
||||||
order = savedOrderInfo.order
|
order = savedOrderInfo.order
|
||||||
if err = s.isPossibleSwitch2SelfDelivery(order); err == nil {
|
if err = s.isPossibleSwitch2SelfDelivery(order); err == nil { // 是否能转自送
|
||||||
err = s.cancelOtherWaybillsCheckOrderDeliveryFlag(savedOrderInfo, nil, partner.CancelWaybillReasonOther, partner.CancelWaybillReasonStrActive)
|
err = s.cancelOtherWaybillsCheckOrderDeliveryFlag(savedOrderInfo, nil, partner.CancelWaybillReasonOther, partner.CancelWaybillReasonStrActive)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if model.IsOrderDeliveryByStore(order) {
|
if model.IsOrderDeliveryByStore(order) {
|
||||||
@@ -76,6 +77,39 @@ func (s *DefScheduler) SelfDeliveringAndUpdateStatus(ctx *jxcontext.Context, ven
|
|||||||
remark = err.Error()
|
remark = err.Error()
|
||||||
}
|
}
|
||||||
partner.CurOrderManager.OnOrderMsg(order, vendorStatus, remark)
|
partner.CurOrderManager.OnOrderMsg(order, vendorStatus, remark)
|
||||||
|
// 上面是真的转自送,支持美团,饿百,京东,如果时抖店,抖店暂时全部是自送的!但是有骑手信息时,就是一个白嫖单子!
|
||||||
|
if order.VendorID == model.VendorIDDD && courierName != "" && courierMobile != "" {
|
||||||
|
timeNow := time.Now()
|
||||||
|
var randData = []int64{1, 2, 3, 4, 5}
|
||||||
|
randTime := time.Duration(randData[0]) * time.Minute
|
||||||
|
bill := &model.Waybill{
|
||||||
|
VendorWaybillID: order.VendorOrderID,
|
||||||
|
VendorWaybillID2: "",
|
||||||
|
WaybillVendorID: model.VendorJXFakeWL,
|
||||||
|
VendorOrderID: order.VendorOrderID,
|
||||||
|
OrderVendorID: model.VendorIDDD,
|
||||||
|
CourierName: courierName,
|
||||||
|
CourierMobile: courierMobile,
|
||||||
|
Status: model.OrderStatusNew,
|
||||||
|
VendorStatus: utils.Int2Str(model.OrderStatusNew),
|
||||||
|
ActualFee: 500,
|
||||||
|
DesiredFee: order.ActualPayPrice,
|
||||||
|
TipFee: 0,
|
||||||
|
DuplicatedCount: 0,
|
||||||
|
DeliveryFlag: 0,
|
||||||
|
WaybillCreatedAt: timeNow,
|
||||||
|
WaybillFinishedAt: utils.DefaultTimeValue,
|
||||||
|
StatusTime: timeNow,
|
||||||
|
ModelTimeInfo: model.ModelTimeInfo{
|
||||||
|
CreatedAt: timeNow,
|
||||||
|
UpdatedAt: timeNow.Add(randTime), // 下一次更新时间
|
||||||
|
},
|
||||||
|
OriginalData: "",
|
||||||
|
Remark: "自定义物流单",
|
||||||
|
VendorOrgCode: order.VendorOrgCode,
|
||||||
|
}
|
||||||
|
err = dao.CreateEntity(dao.GetDB(), bill)
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -186,6 +186,11 @@ func Init() {
|
|||||||
"22:00:00",
|
"22:00:00",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 每分钟轮询一次,推送抖店骑手信息
|
||||||
|
ScheduleTimerFuncByInterval(func() {
|
||||||
|
delivery.GetOrderRiderInfoToPlatform("", 0)
|
||||||
|
}, 10*time.Second, 1*time.Minute)
|
||||||
|
|
||||||
// 定时任务更新负责人信息
|
// 定时任务更新负责人信息
|
||||||
ScheduleTimerFunc("RefreshStoreOperator", func() {
|
ScheduleTimerFunc("RefreshStoreOperator", func() {
|
||||||
cms.UpdateStoreOperatorConfig()
|
cms.UpdateStoreOperatorConfig()
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ const (
|
|||||||
VendorIDDada = 101 // 达达配送
|
VendorIDDada = 101 // 达达配送
|
||||||
VendorIDMTPS = 102 // 美团配送
|
VendorIDMTPS = 102 // 美团配送
|
||||||
VendorIDFengNiao = 103 // 蜂鸟配送
|
VendorIDFengNiao = 103 // 蜂鸟配送
|
||||||
|
VendorJXFakeWL = 300 // 京西假物流
|
||||||
VendorIDJDWL = 401 //京东物流
|
VendorIDJDWL = 401 //京东物流
|
||||||
VendorIDDeliveryEnd = 500
|
VendorIDDeliveryEnd = 500
|
||||||
|
|
||||||
|
|||||||
@@ -1392,17 +1392,30 @@ func GetWaybills(db *DaoDB, vendorOrderID string) (waybills []*model.Waybill, er
|
|||||||
return waybills, err
|
return waybills, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetWayBillsByWayBillId 根据运单id获取运单id
|
// GetWayBillsByWayBillId 根据运单id获取运单id(专用于抖店查询,抖店返回的运单id实际就是订单id,本地存放的运单id为真实id)
|
||||||
func GetWayBillsByWayBillId(db *DaoDB, vendorWayBillId string) (waybills []*model.Waybill, err error) {
|
func GetWayBillsByWayBillId(db *DaoDB, vendorWayBillId string) (waybills []*model.Waybill, err error) {
|
||||||
sql := `SELECT *
|
sql := `SELECT *
|
||||||
FROM waybill
|
FROM waybill
|
||||||
WHERE vendor_waybill_id = ?
|
WHERE vendor_order_id = ? ORDER BY created_at desc
|
||||||
`
|
`
|
||||||
sqlParams := []interface{}{vendorWayBillId}
|
sqlParams := []interface{}{vendorWayBillId}
|
||||||
err = GetRows(db, &waybills, sql, sqlParams)
|
err = GetRows(db, &waybills, sql, sqlParams)
|
||||||
return waybills, err
|
return waybills, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetWayBillFakeOrder 获取当前系统未完成的假订单
|
||||||
|
func GetWayBillFakeOrder() (waybills []*model.Waybill, err error) {
|
||||||
|
sql := `
|
||||||
|
SELECT *
|
||||||
|
FROM waybill
|
||||||
|
WHERE waybill_vendor_id = ? AND status < ? AND waybill_created_at>= ? AND waybill_created_at< ?
|
||||||
|
`
|
||||||
|
|
||||||
|
sqlParams := []interface{}{model.VendorJXFakeWL, model.WaybillStatusFailed, time.Now().Add(-7 * 24 * time.Hour), time.Now()}
|
||||||
|
err = GetRows(GetDB(), &waybills, sql, sqlParams)
|
||||||
|
return waybills, err
|
||||||
|
}
|
||||||
|
|
||||||
func GetMatterChildOrders(db *DaoDB, vendorOrderID string) (goods []*model.GoodsOrder, err error) {
|
func GetMatterChildOrders(db *DaoDB, vendorOrderID string) (goods []*model.GoodsOrder, err error) {
|
||||||
sql := `SELECT *
|
sql := `SELECT *
|
||||||
FROM goods_order
|
FROM goods_order
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||||
"git.rosy.net.cn/jx-callback/business/partner"
|
"git.rosy.net.cn/jx-callback/business/partner"
|
||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
|
"math/rand"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -180,3 +181,91 @@ func UpdateOrder2Complete() {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateFakeWayBillToTiktok 轮询更新假订单到抖音
|
||||||
|
func UpdateFakeWayBillToTiktok() {
|
||||||
|
fakeWayBill, err := dao.GetWayBillFakeOrder()
|
||||||
|
if err != nil {
|
||||||
|
globals.SugarLogger.Debugf("Get Fake Order Err : %s", err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(fakeWayBill) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < len(fakeWayBill); i++ {
|
||||||
|
// 判断当前订单是否可以推送,UpdatedAt > 当前时间 就跳过
|
||||||
|
if fakeWayBill[i].ModelTimeInfo.UpdatedAt.After(time.Now()) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
riderInfo := &mtpsapi.RiderInfo{
|
||||||
|
OrderId: fakeWayBill[i].VendorOrderID,
|
||||||
|
ThirdCarrierOrderId: fakeWayBill[i].VendorOrderID,
|
||||||
|
CourierName: fakeWayBill[i].CourierName,
|
||||||
|
CourierPhone: fakeWayBill[i].CourierMobile,
|
||||||
|
LogisticsProviderCode: "10002",
|
||||||
|
LogisticsStatus: fakeWayBill[i].Status,
|
||||||
|
}
|
||||||
|
|
||||||
|
switch fakeWayBill[i].Status {
|
||||||
|
case 5: // 呼叫骑手
|
||||||
|
riderInfo.LogisticsContext = "呼叫骑手,新建运单"
|
||||||
|
riderInfo.LogisticsStatus = 0
|
||||||
|
riderInfo.CourierName = ""
|
||||||
|
riderInfo.CourierPhone = ""
|
||||||
|
riderInfo.OpCode = tiktok_api.TiktokLogisticsStatusCALLRIDER
|
||||||
|
|
||||||
|
// 下一状态以及推送时间
|
||||||
|
fakeWayBill[i].Status = model.WaybillStatusCourierAssigned
|
||||||
|
fakeWayBill[i].VendorStatus = utils.Int64ToStr(model.WaybillStatusCourierAssigned)
|
||||||
|
case 12: // 骑手接单
|
||||||
|
riderInfo.LogisticsContext = model.RiderWaitGetGoods
|
||||||
|
riderInfo.LogisticsStatus = 12
|
||||||
|
riderInfo.OpCode = tiktok_api.TiktokLogisticsORDERRECEIVED
|
||||||
|
// 下一状态以及推送时间
|
||||||
|
fakeWayBill[i].Status = model.WaybillStatusCourierArrived
|
||||||
|
fakeWayBill[i].VendorStatus = utils.Int64ToStr(model.WaybillStatusCourierArrived)
|
||||||
|
case 15: // 到店
|
||||||
|
riderInfo.LogisticsContext = model.RiderToStore
|
||||||
|
riderInfo.LogisticsStatus = 15
|
||||||
|
riderInfo.OpCode = tiktok_api.TiktokLogisticsRIDERARRIVED
|
||||||
|
// 下一状态以及推送时间
|
||||||
|
fakeWayBill[i].Status = model.WaybillStatusDelivering
|
||||||
|
fakeWayBill[i].VendorStatus = utils.Int64ToStr(model.WaybillStatusDelivering)
|
||||||
|
case 20: //配送中
|
||||||
|
riderInfo.LogisticsContext = model.RiderGetOrderDelivering
|
||||||
|
riderInfo.LogisticsStatus = 20
|
||||||
|
riderInfo.OpCode = tiktok_api.TiktokLogisticsRIDERPICKUP
|
||||||
|
// 下一状态以及推送时间
|
||||||
|
fakeWayBill[i].Status = model.WaybillStatusDelivered
|
||||||
|
fakeWayBill[i].VendorStatus = utils.Int64ToStr(model.WaybillStatusDelivered)
|
||||||
|
case 105: // 完成
|
||||||
|
riderInfo.LogisticsContext = model.RiderGetOrderDelivered
|
||||||
|
riderInfo.LogisticsStatus = 40
|
||||||
|
riderInfo.OpCode = tiktok_api.TiktokLogisticsDELIVERED
|
||||||
|
// 下一状态以及推送时间
|
||||||
|
fakeWayBill[i].Status = model.WaybillStatusFailed
|
||||||
|
fakeWayBill[i].VendorStatus = utils.Int64ToStr(model.WaybillStatusFailed)
|
||||||
|
default:
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// 推送骑手信息
|
||||||
|
paramsMap := utils.Struct2Map(riderInfo, "", true)
|
||||||
|
if handler := partner.GetPurchaseOrderHandlerFromVendorID(model.VendorIDDD); handler != nil {
|
||||||
|
if err := handler.GetOrderRider(fakeWayBill[i].VendorOrgCode, "", paramsMap); err != nil {
|
||||||
|
globals.SugarLogger.Errorf("Fake Pull Rider Info Err :%s--%s--%v", riderInfo.OrderId, riderInfo.ThirdCarrierOrderId, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var randNum = []int64{1, 2, 3, 4, 5}
|
||||||
|
fakeWayBill[i].ModelTimeInfo.UpdatedAt = time.Now().Add(time.Duration(randNum[rand.Int63n(5)]) * time.Minute)
|
||||||
|
|
||||||
|
// 更新假运单
|
||||||
|
if _, err := dao.UpdateEntity(dao.GetDB(), fakeWayBill[i], "Status", "VendorStatus", "UpdatedAt"); err != nil {
|
||||||
|
globals.SugarLogger.Errorf("Update Fake Way Bill Err:%s--%s--%v", riderInfo.OrderId, riderInfo.ThirdCarrierOrderId, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -52,12 +52,14 @@ func (c *OrderController) FinishedPickup() {
|
|||||||
// @Param token header string true "认证token"
|
// @Param token header string true "认证token"
|
||||||
// @Param vendorOrderID formData string true "订单ID"
|
// @Param vendorOrderID formData string true "订单ID"
|
||||||
// @Param vendorID formData int true "订单所属的厂商ID"
|
// @Param vendorID formData int true "订单所属的厂商ID"
|
||||||
|
// @Param courierName formData string false "骑手姓名-制作假配送"
|
||||||
|
// @Param courierMobile formData string false "骑手电话-制作假配送"
|
||||||
// @Success 200 {object} controllers.CallResult
|
// @Success 200 {object} controllers.CallResult
|
||||||
// @Failure 200 {object} controllers.CallResult
|
// @Failure 200 {object} controllers.CallResult
|
||||||
// @router /SelfDelivering [post]
|
// @router /SelfDelivering [post]
|
||||||
func (c *OrderController) SelfDelivering() {
|
func (c *OrderController) SelfDelivering() {
|
||||||
c.callSelfDelivering(func(params *tOrderSelfDeliveringParams) (retVal interface{}, errCode string, err error) {
|
c.callSelfDelivering(func(params *tOrderSelfDeliveringParams) (retVal interface{}, errCode string, err error) {
|
||||||
err = defsch.FixedScheduler.SelfDeliveringAndUpdateStatus(params.Ctx, params.VendorOrderID, params.VendorID, params.Ctx.GetUserName())
|
err = defsch.FixedScheduler.SelfDeliveringAndUpdateStatus(params.Ctx, params.VendorOrderID, params.VendorID, params.Ctx.GetUserName(), params.CourierName, params.CourierMobile)
|
||||||
return nil, "", err
|
return nil, "", err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,8 @@ func (c *LogisticsController) LogisticsRegister() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
globals.SugarLogger.Debugf("根据单号查询运单数据错误:%s", err)
|
globals.SugarLogger.Debugf("根据单号查询运单数据错误:%s", err)
|
||||||
}
|
}
|
||||||
if len(data) <= 0 {
|
|
||||||
|
if len(data) == 0 || err != nil {
|
||||||
c.Data["json"] = LogisticsRegisterResp{
|
c.Data["json"] = LogisticsRegisterResp{
|
||||||
Result: false,
|
Result: false,
|
||||||
ReturnCode: "1002",
|
ReturnCode: "1002",
|
||||||
@@ -154,15 +155,12 @@ func (c *LogisticsController) LogisticsQuery() {
|
|||||||
data, err := dao.GetWayBillsByWayBillId(dao.GetDB(), param.TrackNo)
|
data, err := dao.GetWayBillsByWayBillId(dao.GetDB(), param.TrackNo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
globals.SugarLogger.Debugf("根据单号查询运单数据错误:%s", err)
|
globals.SugarLogger.Debugf("根据单号查询运单数据错误:%s", err)
|
||||||
}
|
c.Data["json"] = LogisticsQueryRest{
|
||||||
if len(data) <= 0 {
|
|
||||||
c.Data["json"] = LogisticsRegisterResp{
|
|
||||||
Result: false,
|
Result: false,
|
||||||
ReturnCode: "1002",
|
ReturnCode: "1002",
|
||||||
Message: "单号不存在",
|
Message: "运单账号不存在",
|
||||||
}
|
}
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
returnParam := &LogisticsQueryRest{
|
returnParam := &LogisticsQueryRest{
|
||||||
|
|||||||
Reference in New Issue
Block a user