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

@@ -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
}
// 用户保密信息脱敏