京东物流超重验证

This commit is contained in:
苏尹岚
2020-10-28 17:02:08 +08:00
parent 3e44f00a25
commit 53fcb9f57f
6 changed files with 78 additions and 13 deletions

View File

@@ -2,6 +2,7 @@ package cms
import (
"fmt"
"math"
"strings"
"time"
@@ -26,6 +27,8 @@ import (
const (
AcceptMaxCount = 2
CancelMaxCount = 5
waybillKgPrice = 200
)
var (
@@ -634,7 +637,7 @@ func CancelJdDelivery(ctx *jxcontext.Context, vendorWaybillID, reason string) (e
)
err = dao.GetEntity(db, dOrder, "VendorWaybillID")
userBill, err := dao.GetUserBill(db, ctx.GetUserID(), "")
dOrders, err := dao.GetDeliveryOrdersNoPage(db, []string{ctx.GetUserID()}, []int{model.OrderStatusCanceled}, DayTimeBegin, DayTimeEnd)
dOrders, err := dao.GetDeliveryOrdersNoPage(db, []string{ctx.GetUserID()}, []int{model.OrderStatusCanceled}, DayTimeBegin, DayTimeEnd, nil)
if err != nil {
return err
}
@@ -674,13 +677,56 @@ func CancelJdDelivery(ctx *jxcontext.Context, vendorWaybillID, reason string) (e
}
func GetJdDelivery(ctx *jxcontext.Context, status int, fromTime, toTime string, pageSize, offset int) (pagedInfo *model.PagedInfo, err error) {
return dao.GetDeliveryOrders(dao.GetDB(), []string{ctx.GetUserID()}, []int{status}, utils.Str2Time(fromTime), utils.Str2Time(toTime), pageSize, offset)
var (
db = dao.GetDB()
)
return dao.GetDeliveryOrders(db, []string{ctx.GetUserID()}, []int{status}, utils.Str2Time(fromTime), utils.Str2Time(toTime), pageSize, offset)
}
func GetJdDeliveryDetail(ctx *jxcontext.Context, vendorWaybillID string) (queryDynamicTraceInfo []*jdeclpapi.QueryDynamicTraceInfoResult, err error) {
return api.JdEclpAPI.QueryDynamicTraceInfo(vendorWaybillID)
}
func CheckJdDeliveryWeight(ctx *jxcontext.Context) (err error) {
var (
db = dao.GetDB()
)
userBill, err := dao.GetUserBill(db, ctx.GetUserID(), "")
if userBill.AccountBalance < 0 {
return fmt.Errorf("您有京东物流订单实际超重,请支付欠款!")
}
deliveryOrders, err := dao.GetDeliveryOrdersNoPage(db, []string{ctx.GetUserID()}, nil, utils.ZeroTimeValue, utils.ZeroTimeValue, []int{0})
if err != nil {
return err
}
task := tasksch.NewParallelTask("CheckJdDeliveryWeight", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(true), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
deliveryOrder := batchItemList[0].(*model.DeliveryOrder)
waybill, err := api.JdEclpAPI.WaybillQuery(deliveryOrder.VendorWaybillID)
if err == nil {
return retVal, err
}
if waybill.DeliveryID == "" {
return retVal, err
}
if waybill.DeliveryID == deliveryOrder.VendorWaybillID {
if waybill.Weight > 3 && math.Floor(deliveryOrder.Weight) < math.Floor(waybill.Weight) {
diffPrice := (math.Floor(waybill.Weight) - math.Floor(deliveryOrder.Weight)) * waybillKgPrice
if err != nil {
return retVal, err
}
if err = financial.AddExpendUpdateAccount(db, userBill, model.BillTypeJdWaybillOverWeight, utils.Float64TwoInt(diffPrice)); err != nil {
return retVal, err
}
}
}
return retVal, err
}, deliveryOrders)
tasksch.HandleTask(task, nil, true).Run()
task.GetID()
return err
}
func ResetJobTimers() {
var (
db = dao.GetDB()

View File

@@ -11,6 +11,8 @@ const (
BillTypeQuitGroup = 30 //退群
BillTypeJdWaybillOverWeight = 40 //京东物流超重扣款
BillTypeCash = 8 //提现
BillTypeInvest = 6 //充值
)

View File

@@ -9,7 +9,7 @@ import (
"git.rosy.net.cn/jx-callback/business/model"
)
func GetDeliveryOrdersNoPage(db *DaoDB, userIDs []string, statuss []int, fromTime, toTime time.Time) (dOrders []*model.DeliveryOrder, err error) {
func GetDeliveryOrdersNoPage(db *DaoDB, userIDs []string, statuss []int, fromTime, toTime time.Time, isWeights []int) (dOrders []*model.DeliveryOrder, err error) {
sql := `
SELECT *
FROM delivery_order
@@ -24,6 +24,10 @@ func GetDeliveryOrdersNoPage(db *DaoDB, userIDs []string, statuss []int, fromTim
sql += ` AND a.status IN (` + GenQuestionMarks(len(statuss)) + `)`
sqlParams = append(sqlParams, statuss)
}
if len(isWeights) > 0 {
sql += ` AND a.is_weight IN (` + GenQuestionMarks(len(isWeights)) + `)`
sqlParams = append(sqlParams, isWeights)
}
if fromTime != utils.ZeroTimeValue {
sql += ` AND a.created_at >= ?`
sqlParams = append(sqlParams, fromTime)

View File

@@ -2,12 +2,6 @@ package model
import "time"
const (
OrderDeliveryTypePlatform = "platform" // 平台负责配送
OrderDeliveryTypeStoreSelf = "store" // 门店自送
OrderDeliveryTypeSelfTake = "self" // 用户自提
)
const (
PayTypeWX = 1 // 微信支付
PayTypeTL = 2 // 通联宝支付
@@ -22,9 +16,6 @@ const (
RefundStatusYes = 1
RefundStatusFailed = 2
EarningTypeQuote = 1 //报价模式
EarningTypePoints = 2 //扣点模式
VendorPayTypeCompanyPay = "companyPay" //企业付款
)

View File

@@ -277,7 +277,20 @@ func (c *JobController) GetJdDelivery() {
// @router /GetJdDeliveryDetail [get]
func (c *JobController) GetJdDeliveryDetail() {
c.callGetJdDeliveryDetail(func(params *tJobGetJdDeliveryDetailParams) (retVal interface{}, errCode string, err error) {
retVal, err = cms.GetJdDeliveryDetail(params.Ctx, params.VendorWaybillID)
return retVal, "", err
})
}
// @Title 京东快递物流超重验证
// @Description 京东快递物流超重验证
// @Param token header string true "认证token"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /CheckJdDeliveryWeight [post]
func (c *JobController) CheckJdDeliveryWeight() {
c.callCheckJdDeliveryWeight(func(params *tJobCheckJdDeliveryWeightParams) (retVal interface{}, errCode string, err error) {
err = cms.CheckJdDeliveryWeight(params.Ctx)
return retVal, "", err
})
}

View File

@@ -313,6 +313,15 @@ func init() {
Filters: nil,
Params: nil})
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:JobController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:JobController"],
beego.ControllerComments{
Method: "CheckJdDeliveryWeight",
Router: `/CheckJdDeliveryWeight`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Filters: nil,
Params: nil})
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:JobController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:JobController"],
beego.ControllerComments{
Method: "GetJdDelivery",