61 lines
2.0 KiB
Go
61 lines
2.0 KiB
Go
|
|
package handler
|
|||
|
|
|
|||
|
|
import (
|
|||
|
|
"net/http"
|
|||
|
|
|
|||
|
|
"soul-api/internal/database"
|
|||
|
|
"soul-api/internal/model"
|
|||
|
|
|
|||
|
|
"github.com/gin-gonic/gin"
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
// WithdrawPost POST /api/withdraw 创建提现申请(占位:仅返回成功,实际需对接微信打款)
|
|||
|
|
func WithdrawPost(c *gin.Context) {
|
|||
|
|
c.JSON(http.StatusOK, gin.H{"success": true})
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// WithdrawRecords GET /api/withdraw/records?userId= 当前用户提现记录(GORM)
|
|||
|
|
func WithdrawRecords(c *gin.Context) {
|
|||
|
|
userId := c.Query("userId")
|
|||
|
|
if userId == "" {
|
|||
|
|
c.JSON(http.StatusBadRequest, gin.H{"success": false, "message": "缺少 userId"})
|
|||
|
|
return
|
|||
|
|
}
|
|||
|
|
var list []model.Withdrawal
|
|||
|
|
if err := database.DB().Where("user_id = ?", userId).Order("created_at DESC").Limit(100).Find(&list).Error; err != nil {
|
|||
|
|
c.JSON(http.StatusOK, gin.H{"success": true, "data": gin.H{"list": []interface{}{}}})
|
|||
|
|
return
|
|||
|
|
}
|
|||
|
|
out := make([]gin.H, 0, len(list))
|
|||
|
|
for _, w := range list {
|
|||
|
|
st := ""
|
|||
|
|
if w.Status != nil {
|
|||
|
|
st = *w.Status
|
|||
|
|
}
|
|||
|
|
out = append(out, gin.H{
|
|||
|
|
"id": w.ID, "amount": w.Amount, "status": st,
|
|||
|
|
"createdAt": w.CreatedAt, "processedAt": w.ProcessedAt,
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
c.JSON(http.StatusOK, gin.H{"success": true, "data": gin.H{"list": out}})
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// WithdrawPendingConfirm GET /api/withdraw/pending-confirm?userId= 待确认收款列表(GORM)
|
|||
|
|
func WithdrawPendingConfirm(c *gin.Context) {
|
|||
|
|
userId := c.Query("userId")
|
|||
|
|
if userId == "" {
|
|||
|
|
c.JSON(http.StatusBadRequest, gin.H{"success": false, "message": "缺少 userId"})
|
|||
|
|
return
|
|||
|
|
}
|
|||
|
|
var list []model.Withdrawal
|
|||
|
|
if err := database.DB().Where("user_id = ? AND status = ?", userId, "pending_confirm").Order("created_at DESC").Find(&list).Error; err != nil {
|
|||
|
|
c.JSON(http.StatusOK, gin.H{"success": true, "data": gin.H{"list": []interface{}{}, "mch_id": "", "app_id": ""}})
|
|||
|
|
return
|
|||
|
|
}
|
|||
|
|
out := make([]gin.H, 0, len(list))
|
|||
|
|
for _, w := range list {
|
|||
|
|
out = append(out, gin.H{"id": w.ID, "amount": w.Amount, "createdAt": w.CreatedAt})
|
|||
|
|
}
|
|||
|
|
c.JSON(http.StatusOK, gin.H{"success": true, "data": gin.H{"list": out, "mchId": "", "appId": ""}})
|
|||
|
|
}
|