@@ -3,10 +3,14 @@ package hdl | |||
import ( | |||
"applet/app/admin/lib/validate" | |||
"applet/app/admin/md" | |||
svc "applet/app/admin/svc/enterprise_manage" | |||
svc2 "applet/app/admin/svc/order" | |||
"applet/app/db" | |||
"applet/app/e" | |||
"applet/app/enum" | |||
"applet/app/utils" | |||
"applet/app/utils/logx" | |||
"errors" | |||
"github.com/gin-gonic/gin" | |||
) | |||
@@ -64,10 +68,6 @@ func CentralKitchenForSchoolOrderRefundList(c *gin.Context) { | |||
"name": enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditReject), | |||
"value": enum.CentralKitchenForSchoolUserRefundDayStateForAuditReject, | |||
}, | |||
{ | |||
"name": enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForRefunding), | |||
"value": enum.CentralKitchenForSchoolUserRefundDayStateForRefunding, | |||
}, | |||
{ | |||
"name": enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditComplete), | |||
"value": enum.CentralKitchenForSchoolUserRefundDayStateForAuditComplete, | |||
@@ -113,15 +113,95 @@ func CentralKitchenForSchoolOrderRefundAudit(c *gin.Context) { | |||
return | |||
} | |||
//go func() { | |||
err1 := svc2.CentralKitchenForSchoolOrderRefundAudit(req) | |||
if err1 != nil { | |||
logx.Error(err1) | |||
println("<<<<CentralKitchenForSchoolOrderRefundAudit>>>>>Error:::", err1.Error()) | |||
e.OutErr(c, e.ERR, err1.Error()) | |||
//限制500条 | |||
if len(req.Ids) > 500 { | |||
e.OutErr(c, e.ERR, errors.New("受理数据过长,请分批次处理")) | |||
return | |||
} | |||
//TODO::先将所有申请单改成 审核通过 状态 | |||
session := db.Db.NewSession() | |||
defer session.Close() | |||
session.Begin() | |||
centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{} | |||
centralKitchenForSchoolUserRefundDayDb.Set(0) | |||
centralKitchenForSchoolUserWithDayDb := db.CentralKitchenForSchoolUserWithDayDb{} | |||
centralKitchenForSchoolUserWithDayDb.Set(0) | |||
for _, v := range req.Ids { | |||
returnDay, err1 := centralKitchenForSchoolUserRefundDayDb.GetCentralKitchenForSchoolUserRefundDay(utils.StrToInt(v)) | |||
if err1 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err1.Error()) | |||
return | |||
} | |||
if returnDay.State != enum.CentralKitchenForSchoolUserRefundDayStateForAuditing { | |||
_ = session.Rollback() | |||
e.OutErr(c, e.ERR, errors.New("请勿重复审核申请单!")) | |||
return | |||
} | |||
//1、更新状态 | |||
if req.State == 1 { | |||
returnDay.State = enum.CentralKitchenForSchoolUserRefundDayStateForAuditPass | |||
} else { | |||
userWithDay, err3 := centralKitchenForSchoolUserWithDayDb.GetCentralKitchenForSchoolUserWithDay(returnDay.RecordsId) | |||
if err3 != nil { | |||
_ = session.Rollback() | |||
e.OutErr(c, e.ERR_DB_ORM, err3.Error()) | |||
return | |||
} | |||
returnDay.State = enum.CentralKitchenForSchoolUserRefundDayStateForAuditReject | |||
userWithDay.State = enum.CentralKitchenForSchoolUserWithDayStateForWait | |||
updateAck1, err4 := centralKitchenForSchoolUserWithDayDb.CentralKitchenForSchoolUserWithDayUpdate(userWithDay.Id, userWithDay, "state") | |||
if err4 != nil { | |||
_ = session.Rollback() | |||
e.OutErr(c, e.ERR_DB_ORM, err4.Error()) | |||
return | |||
} | |||
if updateAck1 <= 0 { | |||
_ = session.Rollback() | |||
e.OutErr(c, e.ERR_DB_ORM, errors.New("更新退款就餐记录状态失败2")) | |||
return | |||
} | |||
} | |||
returnDay.Memo = req.Memo | |||
updateAck, err2 := centralKitchenForSchoolUserRefundDayDb.CentralKitchenForSchoolUserRefundDayUpdate(returnDay.Id, returnDay, "state", "memo") | |||
if err2 != nil { | |||
_ = session.Rollback() | |||
e.OutErr(c, e.ERR_DB_ORM, err2.Error()) | |||
return | |||
} | |||
if updateAck <= 0 { | |||
_ = session.Rollback() | |||
e.OutErr(c, e.ERR_DB_ORM, errors.New("更新退款订单记录状态失败1")) | |||
return | |||
} | |||
//2、处理订单状态 | |||
err5 := svc.JudgePackageOrdOrdState(returnDay.OutTradeNo) | |||
if err5 != nil { | |||
_ = session.Rollback() | |||
e.OutErr(c, e.ERR, err5.Error()) | |||
return | |||
} | |||
} | |||
err = session.Commit() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
//}() | |||
go func() { | |||
err1 := svc2.CentralKitchenForSchoolOrderRefundAudit(req) | |||
if err1 != nil { | |||
logx.Error(err1) | |||
println("<<<<CentralKitchenForSchoolOrderRefundAudit>>>>>Error:::", err1.Error()) | |||
} | |||
}() | |||
e.OutSuc(c, "success", nil) | |||
return | |||
@@ -162,13 +162,6 @@ func CentralKitchenForSchoolOrderRefundAudit(req md.CentralKitchenForSchoolOrder | |||
defer session.Close() | |||
session.Begin() | |||
//限制30条 | |||
if len(req.Ids) > 500 { | |||
err = errors.New("受理数据过长,请分批次处理") | |||
_ = session.Rollback() | |||
return | |||
} | |||
centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{} | |||
centralKitchenForSchoolUserRefundDayDb.Set(0) | |||
centralKitchenForSchoolUserWithDayDb := db.CentralKitchenForSchoolUserWithDayDb{} | |||
@@ -181,24 +174,20 @@ func CentralKitchenForSchoolOrderRefundAudit(req md.CentralKitchenForSchoolOrder | |||
outRequestNoSuffix := "_" + utils.Int64ToStr(time.Now().Unix()) | |||
for _, v := range req.Ids { | |||
returnDay, err1 := centralKitchenForSchoolUserRefundDayDb.GetCentralKitchenForSchoolUserRefundDay(utils.StrToInt(v)) | |||
if err1 != nil { | |||
_ = session.Rollback() | |||
return err1 | |||
} | |||
if returnDay.State != enum.CentralKitchenForSchoolUserRefundDayStateForAuditing { | |||
_ = session.Rollback() | |||
return errors.New("请勿重复审核申请单!") | |||
} | |||
userWithDay, err3 := centralKitchenForSchoolUserWithDayDb.GetCentralKitchenForSchoolUserWithDay(returnDay.RecordsId) | |||
if err3 != nil { | |||
_ = session.Rollback() | |||
return err3 | |||
} | |||
//1、更新状态 | |||
if req.State == 1 { | |||
returnDay.State = enum.CentralKitchenForSchoolUserRefundDayStateForAuditPass | |||
returnDay, err1 := centralKitchenForSchoolUserRefundDayDb.GetCentralKitchenForSchoolUserRefundDay(utils.StrToInt(v)) | |||
if err1 != nil { | |||
_ = session.Rollback() | |||
return err1 | |||
} | |||
userWithDay, err3 := centralKitchenForSchoolUserWithDayDb.GetCentralKitchenForSchoolUserWithDay(returnDay.RecordsId) | |||
if err3 != nil { | |||
_ = session.Rollback() | |||
return err3 | |||
} | |||
userWithDay.State = enum.CentralKitchenForSchoolUserWithDayStateForCancel | |||
outRequestNo := "r_" + returnDay.OutTradeNo + outRequestNoSuffix | |||
dealReturnOrdMap[returnDay.OutTradeNo] = struct { | |||
@@ -212,40 +201,42 @@ func CentralKitchenForSchoolOrderRefundAudit(req md.CentralKitchenForSchoolOrder | |||
returnDay.OutRequestNo = outRequestNo | |||
returnDay.State = enum.CentralKitchenForSchoolUserRefundDayStateForAuditComplete | |||
returnDay.RefundDate = time.Now().Format("2006-01-02 15:04:05") | |||
} else { | |||
returnDay.State = enum.CentralKitchenForSchoolUserRefundDayStateForAuditReject | |||
userWithDay.State = enum.CentralKitchenForSchoolUserWithDayStateForWait | |||
} | |||
returnDay.Memo = req.Memo | |||
updateAck, err2 := centralKitchenForSchoolUserRefundDayDb.CentralKitchenForSchoolUserRefundDayUpdate(returnDay.Id, returnDay, "state", "memo", "refund_date", "out_request_no") | |||
if err2 != nil { | |||
_ = session.Rollback() | |||
return err2 | |||
} | |||
if updateAck <= 0 { | |||
_ = session.Rollback() | |||
err = errors.New("更新退款订单记录状态失败1") | |||
return | |||
} | |||
returnDay.Memo = req.Memo | |||
updateAck, err2 := centralKitchenForSchoolUserRefundDayDb.CentralKitchenForSchoolUserRefundDayUpdate(returnDay.Id, returnDay, "state", "memo", "refund_date", "out_request_no") | |||
if err2 != nil { | |||
_ = session.Rollback() | |||
return err2 | |||
} | |||
if updateAck <= 0 { | |||
_ = session.Rollback() | |||
err = errors.New("更新退款订单记录状态失败1") | |||
return | |||
} | |||
updateAck1, err4 := centralKitchenForSchoolUserWithDayDb.CentralKitchenForSchoolUserWithDayUpdate(userWithDay.Id, userWithDay, "state") | |||
if err4 != nil { | |||
_ = session.Rollback() | |||
return err4 | |||
} | |||
if updateAck1 <= 0 { | |||
_ = session.Rollback() | |||
err = errors.New("更新退款就餐记录状态失败2") | |||
return | |||
//2、处理订单状态 | |||
err5 := svc.JudgePackageOrdOrdState(returnDay.OutTradeNo) | |||
if err5 != nil { | |||
_ = session.Rollback() | |||
return err5 | |||
} | |||
} | |||
//else { | |||
// returnDay.State = enum.CentralKitchenForSchoolUserRefundDayStateForAuditReject | |||
// userWithDay.State = enum.CentralKitchenForSchoolUserWithDayStateForWait | |||
//} | |||
//updateAck1, err4 := centralKitchenForSchoolUserWithDayDb.CentralKitchenForSchoolUserWithDayUpdate(userWithDay.Id, userWithDay, "state") | |||
//if err4 != nil { | |||
// _ = session.Rollback() | |||
// return err4 | |||
//} | |||
//if updateAck1 <= 0 { | |||
// _ = session.Rollback() | |||
// err = errors.New("更新退款就餐记录状态失败2") | |||
// return | |||
//} | |||
//2、处理订单状态 | |||
err5 := svc.JudgePackageOrdOrdState(returnDay.OutTradeNo) | |||
if err5 != nil { | |||
_ = session.Rollback() | |||
return err5 | |||
} | |||
} | |||
//调用支付宝进行退款 | |||
@@ -270,7 +261,8 @@ func CentralKitchenForSchoolOrderRefundAudit(req md.CentralKitchenForSchoolOrder | |||
_ = session.Rollback() | |||
return err6 | |||
} | |||
time.Sleep(50 * time.Millisecond) //TODO::避免频繁调用 | |||
time.Sleep(200 * time.Millisecond) //TODO::避免频繁调用 | |||
} | |||
return session.Commit() | |||
} |
@@ -7,7 +7,6 @@ const ( | |||
CentralKitchenForSchoolUserRefundDayStateForAuditPass = 2 | |||
CentralKitchenForSchoolUserRefundDayStateForAuditReject = 3 | |||
CentralKitchenForSchoolUserRefundDayStateForAuditComplete = 4 | |||
CentralKitchenForSchoolUserRefundDayStateForRefunding = 5 | |||
) | |||
func (gt CentralKitchenForSchoolUserRefundDayState) String() string { | |||
@@ -20,8 +19,6 @@ func (gt CentralKitchenForSchoolUserRefundDayState) String() string { | |||
return "审核拒绝" | |||
case CentralKitchenForSchoolUserRefundDayStateForAuditComplete: | |||
return "退款已完成" | |||
case CentralKitchenForSchoolUserRefundDayStateForRefunding: | |||
return "退款中" | |||
default: | |||
return "未知" | |||
} | |||