Merge branch 'jdshop' of https://e.coding.net/rosydev/jx-callback into jdshop

This commit is contained in:
richboo111
2022-11-04 10:57:31 +08:00
10 changed files with 186 additions and 20 deletions

View File

@@ -58,7 +58,7 @@ func (w *OrderManager) LoadPendingWaybills() []*model.Waybill {
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)
if err == nil && !isDuplicated {
bill2.ID = 0
@@ -111,7 +111,7 @@ func (w *OrderManager) OnWaybillStatusChanged(bill *model.Waybill) (err error) {
}()
duplicatedCount := 0
if bill.Status == model.WaybillStatusNew {
isDuplicated, err = w.onWaybillNew(bill, db)
isDuplicated, err = w.OnWaybillNew(bill, db)
if isDuplicated {
duplicatedCount = 1
}
@@ -127,7 +127,7 @@ func (w *OrderManager) OnWaybillStatusChanged(bill *model.Waybill) (err error) {
existingBill = bill
billCopy := *bill
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)
return err
}

View File

@@ -2,8 +2,10 @@ package defsch
import (
"fmt"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
"math"
"math/rand"
"time"
"git.rosy.net.cn/jx-callback/business/model/dao"
@@ -23,14 +25,14 @@ func (s *DefScheduler) loadSavedOrderByID(vendorOrderID string, vendorID int, is
}, 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
jxutils.CallMsgHandler(func() {
err = func() (err error) {
savedOrderInfo := s.loadSavedOrderByID(vendorOrderID, vendorID, true)
if savedOrderInfo != nil {
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)
if err == nil {
if model.IsOrderDeliveryByStore(order) {
@@ -76,6 +78,43 @@ func (s *DefScheduler) SelfDeliveringAndUpdateStatus(ctx *jxcontext.Context, ven
remark = err.Error()
}
partner.CurOrderManager.OnOrderMsg(order, vendorStatus, remark)
// 上面是真的转自送,支持美团,饿百,京东,如果时抖店,抖店暂时全部是自送的!但是有骑手信息时,就是一个白嫖单子!
if order.VendorID == model.VendorIDDD && courierName != "" && courierMobile != "" {
timeNow := time.Now()
rand.Seed(timeNow.UnixNano())
randNumber := rand.Int63n(481)
if randNumber < 60 {
randNumber += 60
}
randTime := time.Duration(randNumber) * time.Second
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
}

View File

@@ -186,6 +186,11 @@ func Init() {
"22:00:00",
})
// 每分钟轮询一次,推送抖店骑手信息
ScheduleTimerFuncByInterval(func() {
delivery.UpdateFakeWayBillToTiktok()
}, 10*time.Second, 10*time.Minute)
// 定时任务更新负责人信息
ScheduleTimerFunc("RefreshStoreOperator", func() {
cms.UpdateStoreOperatorConfig()

View File

@@ -30,6 +30,7 @@ const (
VendorIDDada = 101 // 达达配送
VendorIDMTPS = 102 // 美团配送
VendorIDFengNiao = 103 // 蜂鸟配送
VendorJXFakeWL = 300 // 京西假物流
VendorIDJDWL = 401 //京东物流
VendorIDDeliveryEnd = 500

View File

@@ -358,8 +358,8 @@ const (
)
const (
BusinessTypeImmediate = 1
BusinessTypeDingshida = 2
BusinessTypeImmediate = 1 // 立即达
BusinessTypeDingshida = 2 // 定时达
)
var (

View File

@@ -1392,17 +1392,30 @@ func GetWaybills(db *DaoDB, vendorOrderID string) (waybills []*model.Waybill, er
return waybills, err
}
// GetWayBillsByWayBillId 根据运单id获取运单id
// GetWayBillsByWayBillId 根据运单id获取运单id(专用于抖店查询,抖店返回的运单id实际就是订单id,本地存放的运单id为真实id)
func GetWayBillsByWayBillId(db *DaoDB, vendorWayBillId string) (waybills []*model.Waybill, err error) {
sql := `SELECT *
FROM waybill
WHERE vendor_waybill_id = ?
WHERE vendor_order_id = ? ORDER BY created_at desc
`
sqlParams := []interface{}{vendorWayBillId}
err = GetRows(db, &waybills, sql, sqlParams)
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) {
sql := `SELECT *
FROM goods_order

View File

@@ -1,6 +1,7 @@
package delivery
import (
"crypto/rand"
"fmt"
"git.rosy.net.cn/baseapi/platformapi/mtpsapi"
"git.rosy.net.cn/baseapi/platformapi/tiktok_shop/tiktok_api"
@@ -9,6 +10,7 @@ import (
"git.rosy.net.cn/jx-callback/business/model/dao"
"git.rosy.net.cn/jx-callback/business/partner"
"git.rosy.net.cn/jx-callback/globals"
"math/big"
"time"
)
@@ -98,8 +100,6 @@ func GetOrderRiderInfoToPlatform(orderId string, wayBillStatus int) {
switch riderInfo.LogisticsStatus {
case 5: // 呼叫骑手
riderInfo.LogisticsStatus = 0
riderInfo.CourierName = ""
riderInfo.CourierPhone = ""
riderInfo.OpCode = tiktok_api.TiktokLogisticsStatusCALLRIDER
case 12: // 骑手接单
riderInfo.LogisticsStatus = 12
@@ -117,6 +117,8 @@ func GetOrderRiderInfoToPlatform(orderId string, wayBillStatus int) {
riderInfo.LogisticsStatus = 40
riderInfo.OpCode = tiktok_api.TiktokLogisticsDELIVERED
case 115: // 取消
riderInfo.CourierName = ""
riderInfo.CourierPhone = ""
riderInfo.LogisticsStatus = 100
riderInfo.OpCode = tiktok_api.TiktokLogisticsCANCELDELIVERY
case 22, 0, 120: // 异常配送
@@ -125,6 +127,11 @@ func GetOrderRiderInfoToPlatform(orderId string, wayBillStatus int) {
default:
continue
}
if v.VendorID == model.VendorIDDD && (riderInfo.LogisticsStatus == 100 || riderInfo.LogisticsStatus == 0 || riderInfo.LogisticsStatus == 20) {
riderInfo.CourierName = ""
riderInfo.CourierPhone = ""
}
if riderInfo.LogisticsStatus != 22 && riderInfo.LogisticsStatus != 120 && riderInfo.LogisticsStatus != 0 {
riderInfo.LogisticsContext += fmt.Sprintf("[%s:%s]", riderInfo.CourierName, riderInfo.CourierPhone)
}
@@ -180,3 +187,104 @@ func UpdateOrder2Complete() {
}
return
}
// UpdateFakeWayBillToTiktok 轮询更新假订单到抖音
func UpdateFakeWayBillToTiktok() {
globals.SugarLogger.Debugf("当前轮询时间 : %v", time.Now())
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
}
riderInfo.LogisticsContext += fmt.Sprintf("[%s:%s]", riderInfo.CourierName, riderInfo.CourierPhone)
// 推送骑手信息
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)
}
}
randNumber, _ := rand.Int(rand.Reader, big.NewInt(640))
randTime := randNumber.Int64()
if randTime < 66 {
randTime += 60
}
fakeWayBill[i].ModelTimeInfo.UpdatedAt = time.Now().Add(time.Duration(randTime) * time.Second)
// 更新假运单
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)
}
// 更新运单为完成状态
if fakeWayBill[i].Status == model.WaybillStatusDelivered {
sql := `UPDATE goods_order g SET g.status = ?,g.vendor_status = ? WHERE g.vendor_order_id = ? `
_, err := dao.ExecuteSQL(dao.GetDB(), sql, []interface{}{model.OrderStatusFinished, model.OrderStatusFinished, fakeWayBill[i].VendorOrderID}...)
if err != nil {
globals.SugarLogger.Debugf("UPDATA goods_order Err :%s", err.Error())
}
}
}
}

View File

@@ -188,9 +188,9 @@ func (p *PurchaseHandler) getOrder(vendorOrgCode, vendorOrderID, vendorStoreID s
h, m, _ := order.ExpectedDeliveredTime.Clock()
if order.ExpectedDeliveredTime.Day() == time.Now().Day() && utils.Str2Int16(fmt.Sprintf("%d%d", h, m)) >= openTime && utils.Str2Int16(fmt.Sprintf("%d%d", h, m)) < closeTime && localStore.Status == model.StoreStatusOpened {
order.BusinessType = model.BusinessTypeDingshida
} else {
order.BusinessType = model.BusinessTypeImmediate
} else {
order.BusinessType = model.BusinessTypeDingshida
}
// 用户保密信息脱敏

View File

@@ -52,12 +52,14 @@ func (c *OrderController) FinishedPickup() {
// @Param token header string true "认证token"
// @Param vendorOrderID formData string true "订单ID"
// @Param vendorID formData int true "订单所属的厂商ID"
// @Param courierName formData string false "骑手姓名-制作假配送"
// @Param courierMobile formData string false "骑手电话-制作假配送"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /SelfDelivering [post]
func (c *OrderController) SelfDelivering() {
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
})
}

View File

@@ -59,7 +59,8 @@ func (c *LogisticsController) LogisticsRegister() {
if err != nil {
globals.SugarLogger.Debugf("根据单号查询运单数据错误:%s", err)
}
if len(data) <= 0 {
if len(data) == 0 || err != nil {
c.Data["json"] = LogisticsRegisterResp{
Result: false,
ReturnCode: "1002",
@@ -154,15 +155,12 @@ func (c *LogisticsController) LogisticsQuery() {
data, err := dao.GetWayBillsByWayBillId(dao.GetDB(), param.TrackNo)
if err != nil {
globals.SugarLogger.Debugf("根据单号查询运单数据错误:%s", err)
}
if len(data) <= 0 {
c.Data["json"] = LogisticsRegisterResp{
c.Data["json"] = LogisticsQueryRest{
Result: false,
ReturnCode: "1002",
Message: "号不存在",
Message: "运单账号不存在",
}
c.ServeJSON()
return
}
returnParam := &LogisticsQueryRest{