支持提号完成后财务调整
This commit is contained in:
@@ -112,6 +112,67 @@ func (h *Handler) UpdateProfit(c *gin.Context) {
|
||||
response.OK(c, item)
|
||||
}
|
||||
|
||||
// CreateFinancialAdjustment 为已完成提号创建利润或打款调整。
|
||||
func (h *Handler) CreateFinancialAdjustment(c *gin.Context) {
|
||||
adminID, ok := currentAdminID(c)
|
||||
if !ok {
|
||||
response.Unauthorized(c, "缺少管理员上下文")
|
||||
return
|
||||
}
|
||||
id, ok := parseID(c)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
var req FinancialAdjustmentRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.BadRequest(c, "调整金额或原因不正确")
|
||||
return
|
||||
}
|
||||
item, err := h.service.CreateFinancialAdjustment(c.Request.Context(), id, req, adminID, auditMeta(c))
|
||||
if err != nil {
|
||||
writePickupError(c, err)
|
||||
return
|
||||
}
|
||||
response.OK(c, item)
|
||||
}
|
||||
|
||||
// ListFinancialAdjustments 返回提号完成后的财务调整历史。
|
||||
func (h *Handler) ListFinancialAdjustments(c *gin.Context) {
|
||||
id, ok := parseID(c)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
items, err := h.service.ListFinancialAdjustments(c.Request.Context(), id)
|
||||
if err != nil {
|
||||
writePickupError(c, err)
|
||||
return
|
||||
}
|
||||
response.OK(c, items)
|
||||
}
|
||||
|
||||
// SettleFinancialAdjustment 确认代管提号的补款或追回调整已线下处理。
|
||||
func (h *Handler) SettleFinancialAdjustment(c *gin.Context) {
|
||||
adminID, ok := currentAdminID(c)
|
||||
if !ok {
|
||||
response.Unauthorized(c, "缺少管理员上下文")
|
||||
return
|
||||
}
|
||||
id, ok := parseID(c)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
var req FinancialAdjustmentSettlementRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.BadRequest(c, "确认备注格式不正确")
|
||||
return
|
||||
}
|
||||
if err := h.service.SettleFinancialAdjustment(c.Request.Context(), id, req, adminID, auditMeta(c)); err != nil {
|
||||
writePickupError(c, err)
|
||||
return
|
||||
}
|
||||
response.OK(c, gin.H{"settled": true})
|
||||
}
|
||||
|
||||
// Cancel 取消提号(管理员)
|
||||
func (h *Handler) Cancel(c *gin.Context) {
|
||||
adminID, ok := currentAdminID(c)
|
||||
@@ -221,6 +282,12 @@ func writePickupError(c *gin.Context, err error) {
|
||||
response.BadRequest(c, "利润金额不正确")
|
||||
case errors.Is(err, ErrOfflineSettlementCannotMark):
|
||||
response.BadRequest(c, "当前提号不可确认线下结算")
|
||||
case errors.Is(err, ErrFinancialAdjustmentInvalid):
|
||||
response.BadRequest(c, "调整金额、状态或原因不正确")
|
||||
case errors.Is(err, ErrFinancialAdjustmentNotFound):
|
||||
response.Error(c, http.StatusNotFound, "pickup_financial_adjustment_not_found", "财务调整记录不存在")
|
||||
case errors.Is(err, ErrFinancialAdjustmentCannotSettle):
|
||||
response.BadRequest(c, "当前调整不可确认处理")
|
||||
default:
|
||||
response.Error(c, http.StatusInternalServerError, "pickup_error", err.Error())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user