aa
This commit is contained in:
@@ -449,6 +449,17 @@ func CancelAcceptJob(ctx *jxcontext.Context, jobID int, jobOrderID int64) (err e
|
||||
}
|
||||
}
|
||||
}
|
||||
//一件代发任务要退钱给用户
|
||||
if job.JobCategoryID == model.JobCategoryIDDropShipping {
|
||||
userBill, err := dao.GetUserBill(db, jobOrder.UserID, "")
|
||||
if userBill == nil {
|
||||
return fmt.Errorf("未查询到该用户的账单!")
|
||||
}
|
||||
if err = financial.AddIncomeUpdateAccount(db, userBill, model.BillTypeJobCancelOverdue, jobOrder.UserActualPrice, jobID); err != nil {
|
||||
dao.Rollback(db)
|
||||
return err
|
||||
}
|
||||
}
|
||||
//3、任务订单状态被取消
|
||||
jobOrder.Status = model.JobOrderStatusCancel
|
||||
if _, err = dao.UpdateEntity(db, jobOrder, "Status"); err != nil {
|
||||
@@ -525,7 +536,7 @@ func UpdateLimitAuditJobOrders(db *dao.DaoDB, timer *time.Timer, jobID int, jobO
|
||||
jobOrder := &model.JobOrder{JobOrderID: jobOrderID}
|
||||
if err := dao.GetEntity(db, jobOrder, "JobOrderID"); err == nil {
|
||||
if jobOrder.Status == model.JobOrderStatusWaitAudit {
|
||||
err := AuditJob(jxcontext.AdminCtx, int(jobOrderID), model.JobOrderStatusAuditPass, "超时系统通过")
|
||||
err := AuditJob(jxcontext.AdminCtx, int(jobOrderID), model.JobOrderStatusAuditPass, "超时系统通过", "")
|
||||
if err != nil {
|
||||
globals.SugarLogger.Debugf("checkLimitAuditJobOrders err: %v jobID: %v, jobOrderID: %v", err, jobID, jobOrderID)
|
||||
} else {
|
||||
@@ -546,10 +557,24 @@ func UpdateDropShippingJobOrders(db *dao.DaoDB, timer *time.Timer, jobID int, jo
|
||||
if err := dao.GetEntity(db, job); err == nil {
|
||||
//如果限时内还没发货
|
||||
if jobOrder.Status < model.JobOrderStatusFinish {
|
||||
|
||||
userBill, err := dao.GetUserBill(db, jobOrder.UserID, "")
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
if err = financial.AddIncomeUpdateAccount(db, userBill, model.BillTypeDropShippingDeposit, job.AvgPrice, job.ID); err != nil {
|
||||
dao.Rollback(db)
|
||||
return
|
||||
}
|
||||
dao.Commit(db)
|
||||
}
|
||||
}
|
||||
}
|
||||
jobTimer.Status = model.JobTimerStatusFinish
|
||||
dao.UpdateEntity(db, jobTimer, "Status")
|
||||
}
|
||||
|
||||
func SubmitJob(ctx *jxcontext.Context, jobOrder *model.JobOrder) (err error) {
|
||||
@@ -618,7 +643,7 @@ func SubmitJob(ctx *jxcontext.Context, jobOrder *model.JobOrder) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func AuditJob(ctx *jxcontext.Context, jobOrderID, status int, comment string) (err error) {
|
||||
func AuditJob(ctx *jxcontext.Context, jobOrderID, status int, comment, vendorWaybillID string) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
@@ -631,6 +656,12 @@ func AuditJob(ctx *jxcontext.Context, jobOrderID, status int, comment string) (e
|
||||
if ctx.GetUserID() != job.UserID && ctx.GetUserName() != "jxadmin" {
|
||||
return fmt.Errorf("任务发起人才能审核!")
|
||||
}
|
||||
if job.JobCategoryID == model.JobCategoryIDDropShipping && vendorWaybillID == "" {
|
||||
return fmt.Errorf("一件代发任务发货请输入运单号!")
|
||||
}
|
||||
if job.JobCategoryID == model.JobCategoryIDDropShipping && status != model.JobOrderStatusAuditPass {
|
||||
return fmt.Errorf("一件代发任务发货参数有误!")
|
||||
}
|
||||
//固定返现
|
||||
//1、审核时,若此任务已过期或者已取消,不通过则应将此任务保证金退还给发起人,通过则应将单次任务保证金给接受人
|
||||
//2、若此任务未过期,不通过则此任务剩余数量将+1,通过则应将单次任务保证金给接受人
|
||||
@@ -651,56 +682,66 @@ func AuditJob(ctx *jxcontext.Context, jobOrderID, status int, comment string) (e
|
||||
return
|
||||
}
|
||||
if status == model.JobOrderStatusAuditPass {
|
||||
var price int
|
||||
if job.CashbackType == model.JobCashbackPrice {
|
||||
price = job.AvgPrice
|
||||
} else {
|
||||
price = jobOrder.UserActualPrice * job.Percentage / 100
|
||||
if price > job.AvgPrice {
|
||||
if job.JobCategoryID != model.JobCategoryIDDropShipping {
|
||||
var price int
|
||||
if job.CashbackType == model.JobCashbackPrice {
|
||||
price = job.AvgPrice
|
||||
} else {
|
||||
price = jobOrder.UserActualPrice * job.Percentage / 100
|
||||
if price > job.AvgPrice {
|
||||
price = job.AvgPrice
|
||||
}
|
||||
}
|
||||
}
|
||||
//若完成任务的人在某个群组中,则要向群主分成
|
||||
if messageGroupMembers, err := dao.GetMessageGroupMembers(db, 0, model.GroupTypeMulit, jobOrder.UserID); err == nil {
|
||||
if len(messageGroupMembers) > 1 {
|
||||
return fmt.Errorf("审核异常,该任务提交人加入了多个群组!")
|
||||
} else if len(messageGroupMembers) == 1 {
|
||||
if messageGroupsResult, err := dao.GetMessageGroups(db, "", messageGroupMembers[0].GroupID, model.GroupTypeMulit, false, ""); err == nil {
|
||||
if len(messageGroupsResult) == 1 {
|
||||
//不分成
|
||||
if messageGroupsResult[0].DividePercentage != 0 {
|
||||
if userBillGroupMaster, err := dao.GetUserBill(db, messageGroupsResult[0].UserID, ""); err == nil {
|
||||
if err = financial.AddIncomeUpdateAccount(db, userBillGroupMaster, model.BillTypeDivide, price*messageGroupsResult[0].DividePercentage/100, job.ID); err != nil {
|
||||
//若完成任务的人在某个群组中,则要向群主分成
|
||||
if messageGroupMembers, err := dao.GetMessageGroupMembers(db, 0, model.GroupTypeMulit, jobOrder.UserID); err == nil {
|
||||
if len(messageGroupMembers) > 1 {
|
||||
return fmt.Errorf("审核异常,该任务提交人加入了多个群组!")
|
||||
} else if len(messageGroupMembers) == 1 {
|
||||
if messageGroupsResult, err := dao.GetMessageGroups(db, "", messageGroupMembers[0].GroupID, model.GroupTypeMulit, false, ""); err == nil {
|
||||
if len(messageGroupsResult) == 1 {
|
||||
//不分成
|
||||
if messageGroupsResult[0].DividePercentage != 0 {
|
||||
if userBillGroupMaster, err := dao.GetUserBill(db, messageGroupsResult[0].UserID, ""); err == nil {
|
||||
if err = financial.AddIncomeUpdateAccount(db, userBillGroupMaster, model.BillTypeDivide, price*messageGroupsResult[0].DividePercentage/100, job.ID); err != nil {
|
||||
dao.Rollback(db)
|
||||
return err
|
||||
}
|
||||
}
|
||||
//接收人账户收入
|
||||
if err = financial.AddIncomeUpdateAccount(db, userBillJobOrder, model.BillTypeJobDivide, price*(100-messageGroupsResult[0].DividePercentage)/100, job.ID); err != nil {
|
||||
dao.Rollback(db)
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
//接收人账户收入
|
||||
if err = financial.AddIncomeUpdateAccount(db, userBillJobOrder, model.BillTypeJob, price, job.ID); err != nil {
|
||||
dao.Rollback(db)
|
||||
return err
|
||||
}
|
||||
}
|
||||
//接收人账户收入
|
||||
if err = financial.AddIncomeUpdateAccount(db, userBillJobOrder, model.BillTypeJobDivide, price*(100-messageGroupsResult[0].DividePercentage)/100, job.ID); err != nil {
|
||||
dao.Rollback(db)
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
//接收人账户收入
|
||||
if err = financial.AddIncomeUpdateAccount(db, userBillJobOrder, model.BillTypeJob, price, job.ID); err != nil {
|
||||
dao.Rollback(db)
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if len(messageGroupMembers) == 0 { //若没有在某个群组,则得到全部
|
||||
//接收人账户收入
|
||||
if err = financial.AddIncomeUpdateAccount(db, userBillJobOrder, model.BillTypeJob, price, job.ID); err != nil {
|
||||
dao.Rollback(db)
|
||||
return err
|
||||
} else if len(messageGroupMembers) == 0 { //若没有在某个群组,则得到全部
|
||||
//接收人账户收入
|
||||
if err = financial.AddIncomeUpdateAccount(db, userBillJobOrder, model.BillTypeJob, price, job.ID); err != nil {
|
||||
dao.Rollback(db)
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
jobOrder.Status = model.JobOrderStatusFinish
|
||||
if _, err = dao.UpdateEntity(db, jobOrder, "Status"); err != nil {
|
||||
dao.Rollback(db)
|
||||
return err
|
||||
jobOrder.Status = model.JobOrderStatusFinish
|
||||
if _, err = dao.UpdateEntity(db, jobOrder, "Status"); err != nil {
|
||||
dao.Rollback(db)
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
//一件代发处理
|
||||
jobOrder.VendorWaybillID = vendorWaybillID
|
||||
jobOrder.Status = model.JobOrderStatusFinish
|
||||
if _, err = dao.UpdateEntity(db, jobOrder, "Status", "VendorWaybillID"); err != nil {
|
||||
dao.Rollback(db)
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if job.Status < 0 {
|
||||
@@ -1118,8 +1159,14 @@ func GetJdDelivery(ctx *jxcontext.Context, status int, fromTime, toTime string,
|
||||
return dao.GetDeliveryOrders(db, []string{ctx.GetUserID()}, statuss, 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 GetDeliveryDetail(ctx *jxcontext.Context, vendorWaybillID string) (result interface{}, err error) {
|
||||
//如果是京东快递
|
||||
if strings.Contains(vendorWaybillID, "JDVD") {
|
||||
return api.JdEclpAPI.QueryDynamicTraceInfo(vendorWaybillID)
|
||||
} else {
|
||||
//如果是一件代发
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func CheckJdDeliveryWeight(ctx *jxcontext.Context) (err error) {
|
||||
@@ -1190,6 +1237,8 @@ func ResetJobTimers() {
|
||||
UpdateLimitJobOrders(db, timer, jobTimer.JobID, jobOrders[0].JobOrderID, jobTimer)
|
||||
case model.JobTimerTypeSubmit:
|
||||
UpdateLimitAuditJobOrders(db, timer, jobTimer.JobID, jobOrders[0].JobOrderID, jobTimer)
|
||||
case model.JobTimerTypeDropShipping:
|
||||
UpdateDropShippingJobOrders(db, timer, jobTimer.JobID, jobOrders[0].JobOrderID, jobTimer)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user