新增用户确认收款功能,更新提现记录模型以支持用户确认时间,并在提现管理页面展示确认状态。同时,优化提现处理逻辑,确保在用户确认后记录相关信息,提升系统稳定性和用户体验。
This commit is contained in:
@@ -258,8 +258,10 @@ func WithdrawConfirmInfo(c *gin.Context) {
|
||||
if appId == "" {
|
||||
appId = "wxb8bbb2b10dec74aa"
|
||||
}
|
||||
// package 需由「用户确认模式」转账接口返回并落库,当前批量转账无 package,返回空;有值时可调 wx.requestMerchantTransfer
|
||||
packageInfo := ""
|
||||
if w.PackageInfo != nil && *w.PackageInfo != "" {
|
||||
packageInfo = *w.PackageInfo
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": true,
|
||||
"data": gin.H{
|
||||
@@ -293,8 +295,16 @@ func WithdrawPendingConfirm(c *gin.Context) {
|
||||
"amount": w.Amount,
|
||||
"createdAt": w.CreatedAt,
|
||||
}
|
||||
// 若有 package 信息(requestMerchantTransfer 用),一并返回;当前直接打款无 package,给空字符串
|
||||
item["package"] = ""
|
||||
if w.PackageInfo != nil && *w.PackageInfo != "" {
|
||||
item["package"] = *w.PackageInfo
|
||||
} else {
|
||||
item["package"] = ""
|
||||
}
|
||||
if w.UserConfirmedAt != nil && !w.UserConfirmedAt.IsZero() {
|
||||
item["userConfirmedAt"] = w.UserConfirmedAt.Format("2006-01-02 15:04:05")
|
||||
} else {
|
||||
item["userConfirmedAt"] = nil
|
||||
}
|
||||
out = append(out, item)
|
||||
}
|
||||
mchId := os.Getenv("WECHAT_MCH_ID")
|
||||
@@ -314,3 +324,41 @@ func WithdrawPendingConfirm(c *gin.Context) {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// WithdrawConfirmReceived POST /api/miniprogram/withdraw/confirm-received 用户确认收款(记录已点击确认)
|
||||
// body: { "withdrawalId": "xxx", "userId": "xxx" },仅本人可操作,更新 user_confirmed_at
|
||||
func WithdrawConfirmReceived(c *gin.Context) {
|
||||
var req struct {
|
||||
WithdrawalID string `json:"withdrawalId" binding:"required"`
|
||||
UserID string `json:"userId" binding:"required"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"success": false, "message": "缺少 withdrawalId 或 userId"})
|
||||
return
|
||||
}
|
||||
db := database.DB()
|
||||
var w model.Withdrawal
|
||||
if err := db.Where("id = ? AND user_id = ?", req.WithdrawalID, req.UserID).First(&w).Error; err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{"success": false, "message": "提现记录不存在或无权操作"})
|
||||
return
|
||||
}
|
||||
st := ""
|
||||
if w.Status != nil {
|
||||
st = *w.Status
|
||||
}
|
||||
// 仅处理中或已成功的可标记「用户已确认收款」
|
||||
if st != "processing" && st != "pending_confirm" && st != "success" {
|
||||
c.JSON(http.StatusOK, gin.H{"success": false, "message": "当前状态不可确认收款"})
|
||||
return
|
||||
}
|
||||
if w.UserConfirmedAt != nil && !w.UserConfirmedAt.IsZero() {
|
||||
c.JSON(http.StatusOK, gin.H{"success": true, "message": "已确认过"})
|
||||
return
|
||||
}
|
||||
now := time.Now()
|
||||
if err := db.Model(&w).Update("user_confirmed_at", now).Error; err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{"success": false, "message": "更新失败"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"success": true, "message": "已记录确认收款"})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user