自动完成内部自提单
This commit is contained in:
@@ -2,10 +2,13 @@ package basesch
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/baseapi/utils/errlist"
|
"git.rosy.net.cn/baseapi/utils/errlist"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
"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"
|
||||||
@@ -13,6 +16,10 @@ import (
|
|||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
autoSelfTakeCode = "135246"
|
||||||
|
)
|
||||||
|
|
||||||
func (c *BaseScheduler) CreateWaybillOnProviders(ctx *jxcontext.Context, order *model.GoodsOrder, courierVendorIDs, excludeCourierVendorIDs []int, maxDeliveryFee int64, createOnlyOne bool) (bills []*model.Waybill, err error) {
|
func (c *BaseScheduler) CreateWaybillOnProviders(ctx *jxcontext.Context, order *model.GoodsOrder, courierVendorIDs, excludeCourierVendorIDs []int, maxDeliveryFee int64, createOnlyOne bool) (bills []*model.Waybill, err error) {
|
||||||
userName := ctx.GetUserName()
|
userName := ctx.GetUserName()
|
||||||
globals.SugarLogger.Infof("CreateWaybillOnProviders orderID:%s userName:%s, courierVendorIDs:%v, excludeCourierVendorIDs:%v", order.VendorOrderID, userName, courierVendorIDs, excludeCourierVendorIDs)
|
globals.SugarLogger.Infof("CreateWaybillOnProviders orderID:%s userName:%s, courierVendorIDs:%v, excludeCourierVendorIDs:%v", order.VendorOrderID, userName, courierVendorIDs, excludeCourierVendorIDs)
|
||||||
@@ -223,7 +230,7 @@ func (c *BaseScheduler) RefundOrder(ctx *jxcontext.Context, order *model.GoodsOr
|
|||||||
|
|
||||||
func (c *BaseScheduler) ConfirmSelfTake(ctx *jxcontext.Context, vendorOrderID string, vendorID int, selfTakeCode string) (err error) {
|
func (c *BaseScheduler) ConfirmSelfTake(ctx *jxcontext.Context, vendorOrderID string, vendorID int, selfTakeCode string) (err error) {
|
||||||
if vendorID == model.VendorIDJD {
|
if vendorID == model.VendorIDJD {
|
||||||
if selfTakeCode == "135246" {
|
if selfTakeCode == autoSelfTakeCode {
|
||||||
if selfTakeCode, err = jd.CurPurchaseHandler.GetSelfTakeCode(ctx, vendorOrderID); err != nil {
|
if selfTakeCode, err = jd.CurPurchaseHandler.GetSelfTakeCode(ctx, vendorOrderID); err != nil {
|
||||||
return fmt.Errorf("获取订单:%s自提货码失败,原始错误:%s", vendorOrderID, err.Error())
|
return fmt.Errorf("获取订单:%s自提货码失败,原始错误:%s", vendorOrderID, err.Error())
|
||||||
}
|
}
|
||||||
@@ -237,3 +244,37 @@ func (c *BaseScheduler) ConfirmSelfTake(ctx *jxcontext.Context, vendorOrderID st
|
|||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *BaseScheduler) ConfirmSelfTakeOrders(ctx *jxcontext.Context, vendorIDs []int, orderCreatedAfter, orderCreatedBefore time.Time, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||||
|
orderList, err := dao.GetPendingFakeOrders(dao.GetDB(), vendorIDs, orderCreatedAfter, orderCreatedBefore)
|
||||||
|
if err == nil {
|
||||||
|
if len(orderList) > 0 {
|
||||||
|
task := tasksch.NewParallelTask(fmt.Sprintf("自动完成内部自提单%v,%s", vendorIDs, utils.Time2Str(orderCreatedAfter)), tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||||
|
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||||
|
order := batchItemList[0].(*model.GoodsOrder)
|
||||||
|
if order.Status == model.OrderStatusAccepted {
|
||||||
|
if handler := partner.GetPurchaseOrderHandlerFromVendorID(order.VendorID); handler != nil {
|
||||||
|
err = handler.AcceptOrRefuseOrder(order, true, ctx.GetUserName())
|
||||||
|
time.Sleep(2 * time.Second)
|
||||||
|
}
|
||||||
|
if err == nil {
|
||||||
|
if err = c.ConfirmSelfTake(ctx, order.VendorOrderID, order.VendorID, autoSelfTakeCode); err == nil {
|
||||||
|
retVal = []int{1}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retVal, err
|
||||||
|
}, orderList)
|
||||||
|
tasksch.HandleTask(task, nil, true).Run()
|
||||||
|
if isAsync {
|
||||||
|
hint = task.GetID()
|
||||||
|
} else {
|
||||||
|
resultList, err2 := task.GetResult(0)
|
||||||
|
if err = err2; err == nil {
|
||||||
|
hint = utils.Int2Str(len(resultList))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return hint, err
|
||||||
|
}
|
||||||
|
|||||||
@@ -109,6 +109,7 @@ func Init() {
|
|||||||
|
|
||||||
ScheduleTimerFuncByInterval(func() {
|
ScheduleTimerFuncByInterval(func() {
|
||||||
RefreshRealMobile(jxcontext.AdminCtx, model.VendorIDEBAI, time.Now().Add(-24*time.Hour), utils.DefaultTimeValue, false, true)
|
RefreshRealMobile(jxcontext.AdminCtx, model.VendorIDEBAI, time.Now().Add(-24*time.Hour), utils.DefaultTimeValue, false, true)
|
||||||
|
// defsch.FixedScheduler.ConfirmSelfTakeOrders(jxcontext.AdminCtx, nil, time.Now().Add(-48*time.Hour), time.Now().Add(-30*time.Minute), true, true)
|
||||||
}, 5*time.Second, 1*time.Hour)
|
}, 5*time.Second, 1*time.Hour)
|
||||||
|
|
||||||
ScheduleTimerFunc("auto enable remote store", func() {
|
ScheduleTimerFunc("auto enable remote store", func() {
|
||||||
|
|||||||
@@ -986,3 +986,32 @@ func GetMyOrderCountInfo(db *DaoDB, userID string, fromDate, toDate time.Time, s
|
|||||||
err = GetRows(db, &countInfo, sql, sqlParams...)
|
err = GetRows(db, &countInfo, sql, sqlParams...)
|
||||||
return countInfo, err
|
return countInfo, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetPendingFakeOrders(db *DaoDB, vendorIDs []int, orderCreatedAfter, orderCreatedBefore time.Time) (orderList []*model.GoodsOrder, err error) {
|
||||||
|
sql := `
|
||||||
|
SELECT t1.*
|
||||||
|
FROM goods_order t1
|
||||||
|
JOIN new_config t2 ON t2.type = ? AND t2.key = ? AND t2.deleted_at = ?
|
||||||
|
AND LOCATE(IF(t1.consignee_mobile2 <> '', t1.consignee_mobile2, t1.consignee_mobile), t2.value) > 0
|
||||||
|
WHERE t1.order_created_at >= ? AND t1.order_created_at <= ?
|
||||||
|
AND t1.delivery_type = ?
|
||||||
|
AND t1.status >= ? AND t1.status < ?
|
||||||
|
`
|
||||||
|
sqlParams := []interface{}{
|
||||||
|
model.ConfigTypeSys,
|
||||||
|
model.ConfigSysFakeOrderMobiles,
|
||||||
|
utils.DefaultTimeValue,
|
||||||
|
orderCreatedAfter,
|
||||||
|
orderCreatedBefore,
|
||||||
|
model.OrderDeliveryTypeSelfTake,
|
||||||
|
model.OrderStatusAccepted,
|
||||||
|
model.OrderStatusEndBegin,
|
||||||
|
}
|
||||||
|
if len(vendorIDs) > 0 {
|
||||||
|
sql += " AND t1.vendor_id IN (" + GenQuestionMarks(len(vendorIDs)) + ")"
|
||||||
|
sqlParams = append(sqlParams, vendorIDs)
|
||||||
|
}
|
||||||
|
// globals.SugarLogger.Debug(sql)
|
||||||
|
err = GetRows(db, &orderList, sql, sqlParams...)
|
||||||
|
return orderList, err
|
||||||
|
}
|
||||||
|
|||||||
@@ -39,3 +39,11 @@ func TestGetStoreOrderSkuList(t *testing.T) {
|
|||||||
t.Log(utils.Format4Output(afsSkuList, false))
|
t.Log(utils.Format4Output(afsSkuList, false))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetPendingFakeOrders(t *testing.T) {
|
||||||
|
orderList, err := GetPendingFakeOrders(GetDB(), nil, time.Now().Add(-48*time.Hour), time.Now().Add(-30*time.Minute))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
t.Log(len(orderList))
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user