This commit is contained in:
solosw
2026-01-05 14:11:34 +08:00
parent 35ef825371
commit 99b11b04e4
658 changed files with 99266 additions and 0 deletions
+107
View File
@@ -0,0 +1,107 @@
package handlers
import (
"awesomeProject/internal/common"
"awesomeProject/internal/models"
"net/http"
"strconv"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
// UserPaymentHandler 用户收款方式处理器
type UserPaymentHandler struct{}
// GetPaymentInfo 获取用户收款方式信息
func (h *UserPaymentHandler) GetPaymentInfo(c *gin.Context) {
currentUser, _ := c.Get("current_user")
user := currentUser.(models.User)
// 返回收款方式信息
paymentInfo := map[string]interface{}{
"main_payment_qr_image": user.MainPaymentQrImage,
"sub_payment_qr_image": user.SubPaymentQrImage,
}
c.JSON(http.StatusOK, common.Success(paymentInfo))
}
// UpdatePaymentInfo 更新用户收款方式信息
func (h *UserPaymentHandler) UpdatePaymentInfo(c *gin.Context) {
currentUser, _ := c.Get("current_user")
user := currentUser.(models.User)
// 解析请求数据
var req struct {
MainPaymentQrImage string `json:"main_payment_qr_image"`
SubPaymentQrImage string `json:"sub_payment_qr_image"`
}
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusOK, common.Error(400, "请求参数错误"))
return
}
// 更新用户收款方式信息
updates := map[string]interface{}{}
if req.MainPaymentQrImage != "" {
updates["main_payment_qr_image"] = req.MainPaymentQrImage
}
if req.SubPaymentQrImage != "" {
updates["sub_payment_qr_image"] = req.SubPaymentQrImage
}
if len(updates) == 0 {
c.JSON(http.StatusOK, common.Error(400, "没有要更新的信息"))
return
}
if err := common.GetDB().Model(&user).Updates(updates).Error; err != nil {
c.JSON(http.StatusOK, common.Error(500, "更新收款方式失败"))
return
}
// 返回更新后的信息
var updatedUser models.User
common.GetDB().First(&updatedUser, user.ID)
paymentInfo := map[string]interface{}{
"main_payment_qr_image": updatedUser.MainPaymentQrImage,
"sub_payment_qr_image": updatedUser.SubPaymentQrImage,
}
c.JSON(http.StatusOK, common.Success(paymentInfo))
}
// GetSellerPaymentInfo 获取卖家收款方式信息
func (h *UserPaymentHandler) GetSellerPaymentInfo(c *gin.Context) {
sellerID, err := strconv.ParseUint(c.Param("id"), 10, 32)
if err != nil {
c.JSON(http.StatusOK, common.Error(400, "卖家ID无效"))
return
}
var seller models.User
err = common.GetDB().Select("main_payment_qr_image, sub_payment_qr_image").First(&seller, sellerID).Error
if err != nil {
if err == gorm.ErrRecordNotFound {
c.JSON(http.StatusOK, common.Error(404, "卖家不存在"))
} else {
c.JSON(http.StatusOK, common.Error(500, "查询卖家信息失败"))
}
return
}
// 返回卖家收款方式信息
paymentInfo := map[string]interface{}{
"main_payment_qr_image": seller.MainPaymentQrImage,
"sub_payment_qr_image": seller.SubPaymentQrImage,
}
c.JSON(http.StatusOK, common.Success(paymentInfo))
}
func (h *UserPaymentHandler) GetSellerInfo(c *gin.Context) {
}