mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-11-10 03:03:43 +08:00
feat: order payment function is ready
This commit is contained in:
@@ -151,6 +151,7 @@ func authorizeMiddleware(s *AppServer, client *redis.Client) gin.HandlerFunc {
|
||||
c.Request.URL.Path == "/api/sd/jobs" ||
|
||||
strings.HasPrefix(c.Request.URL.Path, "/api/sms/") ||
|
||||
strings.HasPrefix(c.Request.URL.Path, "/api/captcha/") ||
|
||||
strings.HasPrefix(c.Request.URL.Path, "/api/payment/") ||
|
||||
strings.HasPrefix(c.Request.URL.Path, "/static/") ||
|
||||
c.Request.URL.Path == "/api/admin/config/get" {
|
||||
c.Next()
|
||||
|
||||
@@ -36,7 +36,7 @@ func NewDefaultConfig() *types.AppConfig {
|
||||
MjConfig: types.MidJourneyConfig{Enabled: false},
|
||||
SdConfig: types.StableDiffusionConfig{Enabled: false, Txt2ImgJsonPath: "res/text2img.json"},
|
||||
WeChatBot: false,
|
||||
AlipayConfig: types.AlipayConfig{SandBox: true},
|
||||
AlipayConfig: types.AlipayConfig{Enabled: false},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,6 @@ type AliYunSmsConfig struct {
|
||||
|
||||
type AlipayConfig struct {
|
||||
Enabled bool // 是否启用该服务
|
||||
SandBox bool // 是否沙箱环境
|
||||
Company string // 公司名称
|
||||
UserId string // 支付宝用户 ID
|
||||
AppId string // 支付宝 AppID
|
||||
|
||||
@@ -19,6 +19,11 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
PayWayAlipay = "支付宝"
|
||||
PayWayWechat = "微信支付"
|
||||
)
|
||||
|
||||
// PaymentHandler 支付服务回调 handler
|
||||
type PaymentHandler struct {
|
||||
BaseHandler
|
||||
@@ -110,6 +115,7 @@ func (h *PaymentHandler) OrderQuery(c *gin.Context) {
|
||||
func (h *PaymentHandler) AlipayQrcode(c *gin.Context) {
|
||||
var data struct {
|
||||
ProductId uint `json:"product_id"`
|
||||
UserId int `json:"user_id"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&data); err != nil {
|
||||
resp.ERROR(c, types.InvalidArgs)
|
||||
@@ -128,9 +134,10 @@ func (h *PaymentHandler) AlipayQrcode(c *gin.Context) {
|
||||
resp.ERROR(c, "error with generate trade no: "+err.Error())
|
||||
return
|
||||
}
|
||||
user, err := utils.GetLoginUser(c, h.db)
|
||||
if err != nil {
|
||||
resp.NotAuth(c)
|
||||
var user model.User
|
||||
res = h.db.First(&user, data.UserId)
|
||||
if res.Error != nil {
|
||||
resp.ERROR(c, "Invalid user ID")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -150,6 +157,7 @@ func (h *PaymentHandler) AlipayQrcode(c *gin.Context) {
|
||||
Subject: product.Name,
|
||||
Amount: product.Price - product.Discount,
|
||||
Status: types.OrderNotPaid,
|
||||
PayWay: PayWayAlipay,
|
||||
Remark: utils.JsonEncode(remark),
|
||||
}
|
||||
res = h.db.Create(&order)
|
||||
@@ -229,6 +237,7 @@ func (h *PaymentHandler) AlipayNotify(c *gin.Context) {
|
||||
user.ExpiredTime = time.Now().AddDate(0, 0, remark.Days).Unix()
|
||||
}
|
||||
user.Vip = true
|
||||
|
||||
} else if !user.Vip { // 充值点卡的非 VIP 用户
|
||||
user.ExpiredTime = time.Now().AddDate(0, 0, 30).Unix()
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import (
|
||||
|
||||
var logger = logger2.GetLogger()
|
||||
|
||||
//go:embed res/ip2region.xdb
|
||||
//go:embed res
|
||||
var xdbFS embed.FS
|
||||
|
||||
// AppLifecycle 应用程序生命周期
|
||||
|
||||
@@ -28,7 +28,7 @@ func NewAlipayService(appConfig *types.AppConfig) (*AlipayService, error) {
|
||||
return nil, fmt.Errorf("error with read App Private key: %v", err)
|
||||
}
|
||||
|
||||
xClient, err := alipay.New(config.AppId, priKey, !config.SandBox)
|
||||
xClient, err := alipay.New(config.AppId, priKey, false)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error with initialize alipay service: %v", err)
|
||||
}
|
||||
|
||||
@@ -17,5 +17,6 @@ type Order struct {
|
||||
Status types.OrderStatus
|
||||
Remark string
|
||||
PayTime int64
|
||||
PayWay string // 支付方式
|
||||
DeletedAt gorm.DeletedAt
|
||||
}
|
||||
|
||||
@@ -14,5 +14,6 @@ type Order struct {
|
||||
Amount float64 `json:"amount"`
|
||||
Status types.OrderStatus `json:"status"`
|
||||
PayTime int64 `json:"pay_time"`
|
||||
PayWay string `json:"pay_way"`
|
||||
Remark types.OrderRemark `json:"remark"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user