From 53fcb9f57f22012480d24e74a35d1f15e4e3032c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Wed, 28 Oct 2020 17:02:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=AC=E4=B8=9C=E7=89=A9=E6=B5=81=E8=B6=85?= =?UTF-8?q?=E9=87=8D=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/job.go | 50 +++++++++++++++++++++++++-- business/model/bill.go | 2 ++ business/model/dao/dao_order.go | 6 +++- business/model/order.go | 9 ----- controllers/job_controller.go | 15 +++++++- routers/commentsRouter_controllers.go | 9 +++++ 6 files changed, 78 insertions(+), 13 deletions(-) diff --git a/business/jxstore/cms/job.go b/business/jxstore/cms/job.go index ddb0ad2d0..0d89a07cc 100644 --- a/business/jxstore/cms/job.go +++ b/business/jxstore/cms/job.go @@ -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() diff --git a/business/model/bill.go b/business/model/bill.go index bb6117966..5e8cec24c 100644 --- a/business/model/bill.go +++ b/business/model/bill.go @@ -11,6 +11,8 @@ const ( BillTypeQuitGroup = 30 //退群 + BillTypeJdWaybillOverWeight = 40 //京东物流超重扣款 + BillTypeCash = 8 //提现 BillTypeInvest = 6 //充值 ) diff --git a/business/model/dao/dao_order.go b/business/model/dao/dao_order.go index 5785612d3..984628a2f 100644 --- a/business/model/dao/dao_order.go +++ b/business/model/dao/dao_order.go @@ -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) diff --git a/business/model/order.go b/business/model/order.go index bc81f96f4..69f6d7571 100644 --- a/business/model/order.go +++ b/business/model/order.go @@ -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" //企业付款 ) diff --git a/controllers/job_controller.go b/controllers/job_controller.go index bc5881574..ae6d12ad5 100644 --- a/controllers/job_controller.go +++ b/controllers/job_controller.go @@ -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 }) } diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index fa02b38a0..5bcdd0c60 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -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",