- 租客在待交接状态取消订单不再自动退款,改为 refund_status=pending_review - 新增退款审核页面 /admin/orders/refund-review,客服可逐个审核 - 新增 POST /refund/approve 通过退款、POST /refund/reject 驳回退款 - 新增 GET /orders/refund-pending 查询待审核退款订单列表 - 优化状态标签表述:已取消→租客已取消、已关闭→客服已关闭、异常→客服介入 - 新增 refund_status: pending_review 及其前端标签「待客服审核退款」 - AdminOrderDetailView 退款状态改用统一 refundStatusLabel
161 lines
3.4 KiB
Go
161 lines
3.4 KiB
Go
package order
|
|
|
|
import (
|
|
"context"
|
|
|
|
"hfb_sys/backend/internal/middleware"
|
|
"hfb_sys/backend/pkg/response"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func (h *Handler) AdminList(c *gin.Context) {
|
|
query := parseAdminOrderQuery(c)
|
|
result, err := h.service.ListAdmin(c.Request.Context(), query)
|
|
if err != nil {
|
|
writeOrderError(c, err)
|
|
return
|
|
}
|
|
response.OK(c, result)
|
|
}
|
|
|
|
func (h *Handler) AdminDetail(c *gin.Context) {
|
|
id, ok := parseID(c)
|
|
if !ok {
|
|
return
|
|
}
|
|
item, err := h.service.FindAdmin(c.Request.Context(), id)
|
|
if err != nil {
|
|
writeOrderError(c, err)
|
|
return
|
|
}
|
|
response.OK(c, item)
|
|
}
|
|
|
|
func (h *Handler) AdminLatestByListing(c *gin.Context) {
|
|
id, ok := parseID(c)
|
|
if !ok {
|
|
return
|
|
}
|
|
item, err := h.service.FindLatestAdminByListing(c.Request.Context(), id)
|
|
if err != nil {
|
|
writeOrderError(c, err)
|
|
return
|
|
}
|
|
response.OK(c, item)
|
|
}
|
|
|
|
func (h *Handler) AdminHandoffRecords(c *gin.Context) {
|
|
id, ok := parseID(c)
|
|
if !ok {
|
|
return
|
|
}
|
|
items, err := h.service.HandoffRecordsAdmin(c.Request.Context(), id)
|
|
if err != nil {
|
|
writeOrderError(c, err)
|
|
return
|
|
}
|
|
response.OK(c, gin.H{"items": items})
|
|
}
|
|
|
|
func (h *Handler) AdminClose(c *gin.Context) {
|
|
h.adminAction(c, h.service.AdminClose, gin.H{"closed": true})
|
|
}
|
|
|
|
func (h *Handler) AdminMarkAbnormal(c *gin.Context) {
|
|
h.adminAction(c, h.service.AdminMarkAbnormal, gin.H{"abnormal": true})
|
|
}
|
|
|
|
func (h *Handler) AdminResetHandoff(c *gin.Context) {
|
|
h.adminAction(c, h.service.AdminResetHandoff, gin.H{"reset": true})
|
|
}
|
|
|
|
func (h *Handler) AdminRefund(c *gin.Context) {
|
|
orderID, ok := parseID(c)
|
|
if !ok {
|
|
return
|
|
}
|
|
item, err := h.service.AdminRefund(c.Request.Context(), orderID)
|
|
if err != nil {
|
|
writeOrderError(c, err)
|
|
return
|
|
}
|
|
response.OK(c, item)
|
|
}
|
|
|
|
func (h *Handler) AdminRefundStatus(c *gin.Context) {
|
|
orderID, ok := parseID(c)
|
|
if !ok {
|
|
return
|
|
}
|
|
item, err := h.service.AdminRefundStatus(c.Request.Context(), orderID)
|
|
if err != nil {
|
|
writeOrderError(c, err)
|
|
return
|
|
}
|
|
response.OK(c, item)
|
|
}
|
|
|
|
func (h *Handler) AdminApproveRefund(c *gin.Context) {
|
|
orderID, ok := parseID(c)
|
|
if !ok {
|
|
return
|
|
}
|
|
if err := h.service.AdminApproveRefund(c.Request.Context(), orderID); err != nil {
|
|
writeOrderError(c, err)
|
|
return
|
|
}
|
|
response.OK(c, gin.H{"approved": true})
|
|
}
|
|
|
|
func (h *Handler) AdminRejectRefund(c *gin.Context) {
|
|
orderID, ok := parseID(c)
|
|
if !ok {
|
|
return
|
|
}
|
|
if err := h.service.AdminRejectRefund(c.Request.Context(), orderID); err != nil {
|
|
writeOrderError(c, err)
|
|
return
|
|
}
|
|
response.OK(c, gin.H{"rejected": true})
|
|
}
|
|
|
|
func (h *Handler) ListPendingRefund(c *gin.Context) {
|
|
items, err := h.service.ListPendingRefund(c.Request.Context())
|
|
if err != nil {
|
|
writeOrderError(c, err)
|
|
return
|
|
}
|
|
response.OK(c, gin.H{"items": items})
|
|
}
|
|
|
|
func (h *Handler) adminAction(c *gin.Context, fn func(context.Context, uint64, uint64, AdminActionRequest, AuditMeta) error, okData gin.H) {
|
|
adminID, ok := currentAdminID(c)
|
|
if !ok {
|
|
response.Unauthorized(c, "缺少管理员上下文")
|
|
return
|
|
}
|
|
id, ok := parseID(c)
|
|
if !ok {
|
|
return
|
|
}
|
|
var req AdminActionRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
response.BadRequest(c, "操作原因不能为空")
|
|
return
|
|
}
|
|
if err := fn(c.Request.Context(), adminID, id, req, auditMeta(c)); err != nil {
|
|
writeOrderError(c, err)
|
|
return
|
|
}
|
|
response.OK(c, okData)
|
|
}
|
|
|
|
func auditMeta(c *gin.Context) AuditMeta {
|
|
return AuditMeta{
|
|
IP: c.ClientIP(),
|
|
UserAgent: c.GetHeader("User-Agent"),
|
|
RequestID: middleware.GetRequestID(c),
|
|
}
|
|
}
|