fix: 审批流程三个bug修复

1. 点通过不再重复创建审批记录(后端无NULL记录时返回400而非自动创建)
2. 非提交人不再显示撤销按钮(列表页增加applicant_id校验)
3. 已审批工单不再显示通过/拒绝按钮(is_approver只计算pending记录)
4. 前端审批失败时弹出错误提示而非静默忽略
This commit is contained in:
logan committed 2026-06-03 17:17:12 +08:00
1 parent 3a6dd99633
commit 74748e4914
2 files changed
+19 -21

No files matched your search

+8 -17
View File
@@ -138,7 +138,8 @@ func ListTickets(c *gin.Context) {
model.DB.Model(&model.TicketApproval{}).Where("ticket_id = ? AND step_type = 'execute'", t.ID).Count(&execCount)
var isExec, isAppr int64
model.DB.Model(&model.TicketApproval{}).Where("ticket_id = ? AND step_type = 'execute' AND approver_id = ?", t.ID, userID).Count(&isExec)
model.DB.Model(&model.TicketApproval{}).Where("ticket_id = ? AND step_type != 'execute' AND step_type != 'submit' AND approver_id = ?", t.ID, userID).Count(&isAppr)
// Only count PENDING approvals (action IS NULL) — already-approved records should not show approve button
model.DB.Model(&model.TicketApproval{}).Where("ticket_id = ? AND step_type != 'execute' AND step_type != 'submit' AND approver_id = ? AND action IS NULL", t.ID, userID).Count(&isAppr)
result = append(result, TicketWithMeta{
Ticket: t,
HasAuditStep: auditCount > 0,
@@ -496,24 +497,14 @@ func ApproveTicket(c *gin.Context) {
now := time.Now()
// Update approval record — auto-create if missing (legacy tickets)
// Find PENDING approval for this user (action IS NULL)
var approval model.TicketApproval
if err := model.DB.Where("ticket_id = ? AND approver_id = ? AND action IS NULL", id, userID).First(&approval).Error; err != nil {
// No approval record — authorized role can create one
stepName := "审核"
stepType := "audit"
approverRole := userRole
approval = model.TicketApproval{
TicketID: ticket.ID,
StepNumber: 1,
StepName: &stepName,
StepType: &stepType,
ApproverID: &userID,
ApproverRole: &approverRole,
}
model.DB.Create(&approval)
if err := model.DB.Where("ticket_id = ? AND approver_id = ? AND action IS NULL AND step_type != 'execute'", id, userID).First(&approval).Error; err != nil {
// Already approved or no pending approval for this user
c.JSON(http.StatusBadRequest, gin.H{"detail": "没有待处理的审批记录(你可能已经审批过了)"})
return
}
approval.Action = &input.Action
approval.Comment = input.Comment
approval.ActualApproverID = &userID