支付模块重构完成

This commit is contained in:
RockYang
2025-08-30 16:27:39 +08:00
parent 3a6f8ccc16
commit 3c065b99fb
17 changed files with 661 additions and 317 deletions

View File

@@ -11,9 +11,8 @@ type OrderStatus int
const ( const (
OrderNotPaid = OrderStatus(0) OrderNotPaid = OrderStatus(0)
OrderScanned = OrderStatus(1) // 已扫码 OrderPaidSuccess = OrderStatus(2) // 已支付
OrderPaidSuccess = OrderStatus(2) OrderPaidFailed = OrderStatus(3) // 已关闭
OrderPaidFailed = OrderStatus(3)
) )
type OrderRemark struct { type OrderRemark struct {

View File

@@ -81,19 +81,6 @@ func (h *ManagerHandler) Login(c *gin.Context) {
return return
} }
// if h.App.SysConfig.Base.EnabledVerify {
// var check bool
// if data.X != 0 {
// check = h.captcha.SlideCheck(data)
// } else {
// check = h.captcha.Check(data)
// }
// if !check {
// resp.ERROR(c, "请先完人机验证")
// return
// }
// }
var manager model.AdminUser var manager model.AdminUser
res := h.DB.Model(&model.AdminUser{}).Where("username = ?", data.Username).First(&manager) res := h.DB.Model(&model.AdminUser{}).Where("username = ?", data.Username).First(&manager)
if res.Error != nil { if res.Error != nil {

View File

@@ -15,9 +15,10 @@ import (
"geekai/store/vo" "geekai/store/vo"
"geekai/utils" "geekai/utils"
"geekai/utils/resp" "geekai/utils/resp"
"time"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"gorm.io/gorm" "gorm.io/gorm"
"time"
) )
type ProductHandler struct { type ProductHandler struct {
@@ -43,9 +44,7 @@ func (h *ProductHandler) Save(c *gin.Context) {
Id uint `json:"id"` Id uint `json:"id"`
Name string `json:"name"` Name string `json:"name"`
Price float64 `json:"price"` Price float64 `json:"price"`
Discount float64 `json:"discount"`
Enabled bool `json:"enabled"` Enabled bool `json:"enabled"`
Days int `json:"days"`
Power int `json:"power"` Power int `json:"power"`
CreatedAt int64 `json:"created_at"` CreatedAt int64 `json:"created_at"`
} }
@@ -57,8 +56,6 @@ func (h *ProductHandler) Save(c *gin.Context) {
item := model.Product{ item := model.Product{
Name: data.Name, Name: data.Name,
Price: data.Price, Price: data.Price,
Discount: data.Discount,
Days: data.Days,
Power: data.Power, Power: data.Power,
Enabled: data.Enabled} Enabled: data.Enabled}
item.Id = data.Id item.Id = data.Id

View File

@@ -15,7 +15,6 @@ import (
"geekai/store/vo" "geekai/store/vo"
"geekai/utils" "geekai/utils"
"geekai/utils/resp" "geekai/utils/resp"
"time"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"gorm.io/gorm" "gorm.io/gorm"
@@ -96,17 +95,8 @@ func (h *OrderHandler) Query(c *gin.Context) {
return return
} }
counter := 0
for {
time.Sleep(time.Second)
var item model.Order var item model.Order
h.DB.Where("order_no = ?", orderNo).First(&item) h.DB.Where("order_no = ?", orderNo).First(&item)
if counter >= 15 || item.Status == types.OrderPaidSuccess || item.Status != order.Status {
order.Status = item.Status
break
}
counter++
}
resp.SUCCESS(c, gin.H{"status": order.Status}) resp.SUCCESS(c, gin.H{"status": order.Status})
} }

View File

@@ -9,7 +9,6 @@ package handler
import ( import (
"embed" "embed"
"errors"
"fmt" "fmt"
"geekai/core" "geekai/core"
"geekai/core/middleware" "geekai/core/middleware"
@@ -77,17 +76,14 @@ func (h *PaymentHandler) RegisterRoutes() {
// 支付回调接口(公开) // 支付回调接口(公开)
rg.POST("notify/alipay", h.AlipayNotify) rg.POST("notify/alipay", h.AlipayNotify)
rg.GET("notify/geek", h.GeekPayNotify) rg.GET("notify/epay", h.EPayNotify)
rg.POST("notify/wechat", h.WechatPayNotify) rg.POST("notify/wxpay", h.WxpayNotify)
// 需要用户登录的接口 // 需要用户登录的接口
rg.Use(middleware.UserAuthMiddleware(h.App.Config.Session.SecretKey, h.App.Redis)) rg.Use(middleware.UserAuthMiddleware(h.App.Config.Session.SecretKey, h.App.Redis))
{ {
rg.POST("create", h.Pay) rg.POST("create", h.CreateOrder)
} }
// 同步订单状态
h.StartSyncOrders()
} }
func (h *PaymentHandler) StartSyncOrders() { func (h *PaymentHandler) StartSyncOrders() {
@@ -116,10 +112,11 @@ func (h *PaymentHandler) SyncOrders() error {
} }
for _, order := range orders { for _, order := range orders {
// 超时15分钟的订单直接标记为已关闭 //超时15分钟的订单直接标记为已关闭
if time.Now().After(order.CreatedAt.Add(time.Minute * 15)) { if time.Now().After(order.CreatedAt.Add(time.Minute * 15)) {
h.DB.Model(&model.Order{}).Where("id", order.Id).Update("checked", true) h.DB.Model(&model.Order{}).Where("id", order.Id).Update("checked", true)
return errors.New("订单超时") logger.Errorf("订单超时:%v", order)
continue
} }
// 查询订单状态 // 查询订单状态
var res payment.OrderInfo var res payment.OrderInfo
@@ -127,18 +124,22 @@ func (h *PaymentHandler) SyncOrders() error {
case payment.PayChannelEpay: case payment.PayChannelEpay:
res, err = h.epayService.Query(order.OrderNo) res, err = h.epayService.Query(order.OrderNo)
if err != nil { if err != nil {
return fmt.Errorf("error with query order info: %v", err) logger.Errorf("error with query order info: %v", err)
continue
} }
// 微信支付 // 微信支付
case payment.PayChannelWX: case payment.PayChannelWX:
res, err = h.wxpayService.Query(order.OrderNo) res, err = h.wxpayService.Query(order.OrderNo)
logger.Debugf("微信支付订单状态:%+v", res)
if err != nil { if err != nil {
return fmt.Errorf("error with query order info: %v", err) logger.Errorf("error with query order info: %v", err)
continue
} }
case payment.PayChannelAL: case payment.PayChannelAL:
res, err = h.alipayService.Query(order.OrderNo) res, err = h.alipayService.Query(order.OrderNo)
if err != nil { if err != nil {
return fmt.Errorf("error with query order info: %v", err) logger.Errorf("error with query order info: %v", err)
continue
} }
} }
@@ -148,24 +149,26 @@ func (h *PaymentHandler) SyncOrders() error {
"checked": true, "checked": true,
"status": types.OrderPaidFailed, "status": types.OrderPaidFailed,
}) })
return errors.New("订单已关闭") logger.Errorf("订单已关闭:%v", order)
continue
} }
// 订单未支付,不处理,继续轮询 // 订单未支付,不处理,继续轮询
if !res.Success() { if !res.Success() {
return nil continue
} }
// 订单支付成功 // 订单支付成功
err = h.paySuccess(res) err = h.paySuccess(res)
if err != nil { if err != nil {
return fmt.Errorf("error with deal order: %v", err) logger.Errorf("error with deal order: %v", err)
continue
} }
} }
return nil return nil
} }
func (h *PaymentHandler) Pay(c *gin.Context) { func (h *PaymentHandler) CreateOrder(c *gin.Context) {
var data struct { var data struct {
PayWay string `json:"pay_way,omitempty"` // 支付方式:支付宝,微信 PayWay string `json:"pay_way,omitempty"` // 支付方式:支付宝,微信
Pid int `json:"pid,omitempty"` Pid int `json:"pid,omitempty"`
@@ -210,7 +213,7 @@ func (h *PaymentHandler) Pay(c *gin.Context) {
if h.config.WxPay.Domain != "" { if h.config.WxPay.Domain != "" {
data.Domain = h.config.WxPay.Domain data.Domain = h.config.WxPay.Domain
} }
notifyURL = fmt.Sprintf("%s/api/payment/notify/wechat", data.Domain) notifyURL = fmt.Sprintf("%s/api/payment/notify/wxpay", data.Domain)
payURL, err = h.wxpayService.Pay(payment.PayRequest{ payURL, err = h.wxpayService.Pay(payment.PayRequest{
OutTradeNo: orderNo, OutTradeNo: orderNo,
TotalFee: fmt.Sprintf("%d", int(amount*100)), TotalFee: fmt.Sprintf("%d", int(amount*100)),
@@ -230,7 +233,7 @@ func (h *PaymentHandler) Pay(c *gin.Context) {
if h.config.Epay.Domain != "" { if h.config.Epay.Domain != "" {
data.Domain = h.config.Epay.Domain data.Domain = h.config.Epay.Domain
} }
notifyURL = fmt.Sprintf("%s/api/payment/notify/geek", data.Domain) notifyURL = fmt.Sprintf("%s/api/payment/notify/epay", data.Domain)
params := payment.PayRequest{ params := payment.PayRequest{
OutTradeNo: orderNo, OutTradeNo: orderNo,
Subject: product.Name, Subject: product.Name,
@@ -280,7 +283,7 @@ func (h *PaymentHandler) Pay(c *gin.Context) {
if h.config.Epay.Domain != "" { if h.config.Epay.Domain != "" {
data.Domain = h.config.Epay.Domain data.Domain = h.config.Epay.Domain
} }
notifyURL = fmt.Sprintf("%s/api/payment/notify/geek", data.Domain) notifyURL = fmt.Sprintf("%s/api/payment/notify/epay", data.Domain)
params := payment.PayRequest{ params := payment.PayRequest{
OutTradeNo: orderNo, OutTradeNo: orderNo,
Subject: product.Name, Subject: product.Name,
@@ -309,7 +312,6 @@ func (h *PaymentHandler) Pay(c *gin.Context) {
// 创建订单 // 创建订单
remark := types.OrderRemark{ remark := types.OrderRemark{
Days: product.Days,
Power: product.Power, Power: product.Power,
Name: product.Name, Name: product.Name,
Price: product.Price, Price: product.Price,
@@ -377,7 +379,7 @@ func (h *PaymentHandler) paySuccess(info payment.OrderInfo) error {
order.Status = types.OrderPaidSuccess order.Status = types.OrderPaidSuccess
order.TradeNo = info.TradeId order.TradeNo = info.TradeId
order.Checked = true order.Checked = true
err = h.DB.Updates(&order).Error err = h.DB.Debug().Updates(&order).Error
if err != nil { if err != nil {
return fmt.Errorf("error with update order info: %v", err) return fmt.Errorf("error with update order info: %v", err)
} }
@@ -418,14 +420,14 @@ func (h *PaymentHandler) AlipayNotify(c *gin.Context) {
c.String(http.StatusOK, "success") c.String(http.StatusOK, "success")
} }
// GeekPayNotify 支付异步回调 // EPayNotify 易支付支付异步回调
func (h *PaymentHandler) GeekPayNotify(c *gin.Context) { func (h *PaymentHandler) EPayNotify(c *gin.Context) {
var params = make(map[string]string) var params = make(map[string]string)
for k := range c.Request.URL.Query() { for k := range c.Request.URL.Query() {
params[k] = c.Query(k) params[k] = c.Query(k)
} }
logger.Infof("收到GeekPay订单支付回调:%+v", params) logger.Infof("收到易支付订单支付回调:%+v", params)
// 检查支付状态, 如果未支付,则返回成功 // 检查支付状态, 如果未支付,则返回成功
if params["trade_status"] != "TRADE_SUCCESS" { if params["trade_status"] != "TRADE_SUCCESS" {
c.String(http.StatusOK, "success") c.String(http.StatusOK, "success")
@@ -456,8 +458,8 @@ func (h *PaymentHandler) GeekPayNotify(c *gin.Context) {
c.String(http.StatusOK, "success") c.String(http.StatusOK, "success")
} }
// WechatPayNotify 微信商户支付异步回调 // WxpayNotify 微信商户支付异步回调
func (h *PaymentHandler) WechatPayNotify(c *gin.Context) { func (h *PaymentHandler) WxpayNotify(c *gin.Context) {
err := c.Request.ParseForm() err := c.Request.ParseForm()
if err != nil { if err != nil {
c.String(http.StatusOK, "fail") c.String(http.StatusOK, "fail")

View File

@@ -303,6 +303,7 @@ func main() {
}), }),
fx.Invoke(func(s *core.AppServer, h *handler.PaymentHandler) { fx.Invoke(func(s *core.AppServer, h *handler.PaymentHandler) {
h.RegisterRoutes() h.RegisterRoutes()
h.StartSyncOrders()
}), }),
fx.Invoke(func(s *core.AppServer, h *admin.ProductHandler) { fx.Invoke(func(s *core.AppServer, h *admin.ProductHandler) {
h.RegisterRoutes() h.RegisterRoutes()

View File

@@ -118,6 +118,18 @@ func (s *MigrationService) TableMigration() {
if s.db.Migrator().HasColumn(&model.ChatModel{}, "description") { if s.db.Migrator().HasColumn(&model.ChatModel{}, "description") {
s.db.Migrator().DropColumn(&model.ChatModel{}, "description") s.db.Migrator().DropColumn(&model.ChatModel{}, "description")
} }
if s.db.Migrator().HasColumn(&model.Product{}, "discount") {
s.db.Migrator().DropColumn(&model.Product{}, "discount")
}
if s.db.Migrator().HasColumn(&model.Product{}, "days") {
s.db.Migrator().DropColumn(&model.Product{}, "days")
}
if s.db.Migrator().HasColumn(&model.Product{}, "app_url") {
s.db.Migrator().DropColumn(&model.Product{}, "app_url")
}
if s.db.Migrator().HasColumn(&model.Product{}, "url") {
s.db.Migrator().DropColumn(&model.Product{}, "url")
}
} }
// 迁移配置数据 // 迁移配置数据

View File

@@ -74,6 +74,7 @@ func (s *WxPayService) Pay(params PayRequest) (string, error) {
bm.Set("total", utils.IntValue(params.TotalFee, 0)). bm.Set("total", utils.IntValue(params.TotalFee, 0)).
Set("currency", "CNY") Set("currency", "CNY")
}) })
logger.Debugf("wxpay params: %+v", bm)
if params.Device == "mobile" { if params.Device == "mobile" {
bm.SetBodyMap("scene_info", func(bm gopay.BodyMap) { bm.SetBodyMap("scene_info", func(bm gopay.BodyMap) {
bm.Set("payer_client_ip", params.ClientIP) bm.Set("payer_client_ip", params.ClientIP)

View File

@@ -17,7 +17,7 @@ type Order struct {
Amount float64 `gorm:"column:amount;type:decimal(10,2);not null;default:0.00;comment:订单金额" json:"amount"` Amount float64 `gorm:"column:amount;type:decimal(10,2);not null;default:0.00;comment:订单金额" json:"amount"`
Status types.OrderStatus `gorm:"column:status;type:tinyint(1);not null;default:0;comment:订单状态0待支付1已扫码2支付成功" json:"status"` Status types.OrderStatus `gorm:"column:status;type:tinyint(1);not null;default:0;comment:订单状态0待支付1已扫码2支付成功" json:"status"`
Remark string `gorm:"column:remark;type:varchar(255);not null;comment:备注" json:"remark"` Remark string `gorm:"column:remark;type:varchar(255);not null;comment:备注" json:"remark"`
PayTime int64 `gorm:"column:pay_time;type:int;comment:支付时间" json:"pay_time"` PayTime int64 `gorm:"column:pay_time;type:int(11);comment:支付时间" json:"pay_time"`
PayWay string `gorm:"column:pay_way;type:varchar(20);not null;comment:支付方式" json:"pay_way"` PayWay string `gorm:"column:pay_way;type:varchar(20);not null;comment:支付方式" json:"pay_way"`
Channel string `gorm:"column:channel;type:varchar(30);not null;comment:支付类型渠道:支付宝,微信,聚合支付"` // 支付类型渠道 Channel string `gorm:"column:channel;type:varchar(30);not null;comment:支付类型渠道:支付宝,微信,聚合支付"` // 支付类型渠道
CreatedAt time.Time `gorm:"column:created_at;type:datetime;not null" json:"created_at"` CreatedAt time.Time `gorm:"column:created_at;type:datetime;not null" json:"created_at"`

View File

@@ -9,16 +9,12 @@ type Product struct {
Id uint `gorm:"column:id;primaryKey;autoIncrement" json:"id"` Id uint `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
Name string `gorm:"column:name;type:varchar(30);not null;comment:名称" json:"name"` Name string `gorm:"column:name;type:varchar(30);not null;comment:名称" json:"name"`
Price float64 `gorm:"column:price;type:decimal(10,2);not null;default:0.00;comment:价格" json:"price"` Price float64 `gorm:"column:price;type:decimal(10,2);not null;default:0.00;comment:价格" json:"price"`
Discount float64 `gorm:"column:discount;type:decimal(10,2);not null;default:0.00;comment:优惠金额" json:"discount"`
Days int `gorm:"column:days;type:smallint;not null;default:0;comment:延长天数" json:"days"`
Power int `gorm:"column:power;type:int;not null;default:0;comment:增加算力值" json:"power"` Power int `gorm:"column:power;type:int;not null;default:0;comment:增加算力值" json:"power"`
Enabled bool `gorm:"column:enabled;type:tinyint(1);not null;default:0;comment:是否启动" json:"enabled"` Enabled bool `gorm:"column:enabled;type:tinyint(1);not null;default:0;comment:是否启动" json:"enabled"`
Sales int `gorm:"column:sales;type:int;not null;default:0;comment:销量" json:"sales"` Sales int `gorm:"column:sales;type:int;not null;default:0;comment:销量" json:"sales"`
SortNum int `gorm:"column:sort_num;type:tinyint;not null;default:0;comment:排序" json:"sort_num"` SortNum int `gorm:"column:sort_num;type:tinyint;not null;default:0;comment:排序" json:"sort_num"`
CreatedAt time.Time `gorm:"column:created_at;type:datetime;not null" json:"created_at"` CreatedAt time.Time `gorm:"column:created_at;type:datetime;not null" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at;type:datetime;not null" json:"updated_at"` UpdatedAt time.Time `gorm:"column:updated_at;type:datetime;not null" json:"updated_at"`
AppUrl string `gorm:"column:app_url;type:varchar(255);comment:App跳转地址" json:"app_url"`
Url string `gorm:"column:url;type:varchar(255);comment:跳转地址" json:"url"`
} }
func (m *Product) TableName() string { func (m *Product) TableName() string {

View File

@@ -17,8 +17,9 @@ import (
"time" "time"
"unicode" "unicode"
"golang.org/x/crypto/sha3"
rand2 "math/rand" rand2 "math/rand"
"golang.org/x/crypto/sha3"
) )
// RandString generate rand string with specified length // RandString generate rand string with specified length
@@ -72,7 +73,16 @@ func Str2stamp(str string) int64 {
return 0 return 0
} }
layout := "2006-01-02 15:04:05" var layout string
if strings.Contains(str, "T") {
layout = "2006-01-02T15:04:05-07:00"
} else {
if len(str) < 12 {
str = str + " 00:00:00"
}
layout = "2006-01-02 15:04:05"
}
t, err := time.ParseInLocation(layout, str, time.Local) t, err := time.ParseInLocation(layout, str, time.Local)
if err != nil { if err != nil {
return 0 return 0

View File

@@ -81,7 +81,8 @@
width: 100%; width: 100%;
height: 100%; height: 100%;
z-index: 0; z-index: 0;
background: url('data:image/svg+xml;utf8,<svg width="100%25" height="100%25" viewBox="0 0 400 200" fill="none" xmlns="http://www.w3.org/2000/svg"><circle cx="100" cy="100" r="80" fill="%23e0eaff"/><circle cx="300" cy="60" r="40" fill="%23f0f7ff"/><circle cx="320" cy="180" r="30" fill="%23e0eaff"/></svg>') no-repeat center/cover; background: url('data:image/svg+xml;utf8,<svg width="100%25" height="100%25" viewBox="0 0 400 200" fill="none" xmlns="http://www.w3.org/2000/svg"><circle cx="100" cy="100" r="80" fill="%23e0eaff"/><circle cx="300" cy="60" r="40" fill="%23f0f7ff"/><circle cx="320" cy="180" r="30" fill="%23e0eaff"/></svg>')
no-repeat center/cover;
opacity: 0.08; opacity: 0.08;
pointer-events: none; pointer-events: none;
} }
@@ -99,115 +100,259 @@
} }
.list-box { .list-box {
.product-col {
animation: fadeInUp 0.6s ease-out;
animation-fill-mode: both;
&:nth-child(1) {
animation-delay: 0.1s;
}
&:nth-child(2) {
animation-delay: 0.2s;
}
&:nth-child(3) {
animation-delay: 0.3s;
}
&:nth-child(4) {
animation-delay: 0.4s;
}
&:nth-child(5) {
animation-delay: 0.5s;
}
&:nth-child(6) {
animation-delay: 0.6s;
}
}
.product-item { .product-item {
// border: 1px solid #666666; background: linear-gradient(135deg, var(--panel-bg) 0%, var(--chat-bg) 100%);
background-color: var(--chat-bg); border-radius: 16px;
border-radius: 6px;
overflow: hidden; overflow: hidden;
cursor: pointer; cursor: pointer;
transition: all 0.3s ease; /* 添加过渡效果 */ transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
margin-bottom: 20px; margin-bottom: 24px;
border: 1px solid rgba(255, 255, 255, 0.1);
position: relative;
.product-header {
position: relative;
.image-container { .image-container {
position: relative;
display: flex; display: flex;
justify-content: center; justify-content: center;
padding: 20px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
.el-image { .el-image {
padding: 6px; width: 80px;
height: 80px;
border-radius: 50%;
overflow: hidden;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
transition: transform 0.3s ease;
.el-image__inner { &:hover {
border-radius: 10px; transform: scale(1.1);
}
}
.image-overlay {
position: absolute;
top: 10px;
right: 10px;
.vip-badge {
background: linear-gradient(135deg, #ffd700 0%, #ffed4e 100%);
color: #333;
padding: 4px 12px;
border-radius: 20px;
font-size: 12px;
font-weight: bold;
box-shadow: 0 4px 12px rgba(255, 215, 0, 0.4);
animation: pulse 2s infinite;
} }
} }
} }
.product-title { .product-title {
display: flex; padding: 20px 20px 0;
padding: 10px; text-align: center;
.name { .name {
width: 100%;
text-align: center;
font-size: 16px;
font-weight: bold;
color: var(--el-color-primary);
}
}
.product-info {
padding: 10px 20px;
font-size: 14px;
color: #999999;
.info-line {
display: flex;
width: 100%;
padding: 5px 0;
.label {
display: flex;
width: 100%;
}
.price, .expire, calls {
display: flex;
width: 90px;
justify-content: right;
}
.discount {
color: #f56c6c;
font-size: 20px; font-size: 20px;
} font-weight: 700;
.expire {
color: #409eff;
}
.power {
color: #f2cb51;
}
}
.pay-way {
padding: 10px 0;
display: flex;
justify-content: center;
flex-wrap: wrap;
.el-button {
margin: 10px 5px 0 5px;
height: 32px;
filter: none;
.icon-alipay, .icon-wechat-pay {
color: #ffffff;
}
.icon-qq {
color: #15a6e8;
font-size: 24px;
}
.icon-jd-pay {
color: var(--text-theme-color); color: var(--text-theme-color);
font-size: 24px; margin: 0 0 8px 0;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
} }
.icon-douyin {
color: #0a0a0a; .description {
font-size: 22px;
}
.icon-paypal {
font-size: 14px; font-size: 14px;
color: #009cde; color: var(--text-secondary-color, #666);
margin: 0;
line-height: 1.4;
}
}
}
.product-content {
padding: 20px;
.price-section {
text-align: center;
margin-bottom: 20px;
.price-info {
display: flex;
align-items: baseline;
justify-content: center;
margin-bottom: 8px;
.currency {
font-size: 18px;
color: #f56c6c;
font-weight: 600;
margin-right: 2px;
}
.price-value {
font-size: 32px;
font-weight: 800;
color: #f56c6c;
line-height: 1;
}
.price-unit {
font-size: 14px;
color: var(--text-secondary-color, #666);
margin-left: 4px;
}
}
.original-price {
font-size: 12px;
color: #999;
text-decoration: line-through;
}
}
.features-list {
.feature-item {
display: flex;
align-items: center;
margin-bottom: 8px;
font-size: 14px;
color: var(--text-secondary-color, #666);
i {
color: #67c23a;
margin-right: 8px;
font-size: 16px;
}
}
}
}
.product-actions {
padding: 0 20px 20px;
.payment-buttons {
display: flex;
gap: 12px;
.payment-btn {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
padding: 12px 16px;
border: none;
border-radius: 12px;
font-size: 14px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
position: relative;
overflow: hidden;
transform: translateZ(0);
&::before {
content: '';
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: linear-gradient(
90deg,
transparent,
rgba(255, 255, 255, 0.2),
transparent
);
transition: left 0.5s;
}
&:hover::before {
left: 100%;
}
&:active {
transform: translateY(1px) scale(0.98);
}
i {
font-size: 18px;
transition: transform 0.3s ease;
}
span {
font-weight: 600;
transition: transform 0.3s ease;
}
&:hover {
i,
span {
transform: scale(1.05);
}
}
&.wechat-btn {
background: linear-gradient(135deg, #07c160 0%, #06ad56 100%);
color: white;
box-shadow: 0 4px 16px rgba(7, 193, 96, 0.3);
&:hover {
transform: translateY(-2px);
box-shadow: 0 8px 24px rgba(7, 193, 96, 0.4);
background: linear-gradient(135deg, #06ad56 0%, #07c160 100%);
}
}
&.alipay-btn {
background: linear-gradient(135deg, #1677ff 0%, #0e5fd8 100%);
color: white;
box-shadow: 0 4px 16px rgba(22, 119, 255, 0.3);
&:hover {
transform: translateY(-2px);
box-shadow: 0 8px 24px rgba(22, 119, 255, 0.4);
background: linear-gradient(135deg, #0e5fd8 0%, #1677ff 100%);
}
} }
} }
} }
} }
&:hover { &:hover {
// box-shadow: 0 0 10px rgba(71, 255, 241, 0.6); /* 添加阴影效果 */ transform: translateY(-8px);
transform: translateY(-10px); /* 向上移动10像素 */ box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
box-shadow: 0 0 10px var(--shadow-color); border-color: rgba(102, 126, 234, 0.3);
background-color: var(--hover-deep-color);
} }
} }
} }
@@ -235,3 +380,167 @@
} }
} }
} }
// 添加动画效果
@keyframes pulse {
0%,
100% {
transform: scale(1);
opacity: 1;
}
50% {
transform: scale(1.05);
opacity: 0.8;
}
}
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(30px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
// 响应式优化
@media (max-width: 768px) {
.member {
.inner {
.product-box {
.list-box {
.el-col {
width: 100% !important;
margin-bottom: 16px;
}
.product-item {
.product-header {
.image-container {
padding: 16px;
.el-image {
width: 60px;
height: 60px;
}
}
.product-title {
padding: 16px 16px 0;
.name {
font-size: 18px;
}
}
}
.product-content {
padding: 16px;
.price-section {
.price-info {
.price-value {
font-size: 28px;
}
}
}
}
.product-actions {
padding: 0 16px 16px;
.payment-buttons {
flex-direction: column;
gap: 8px;
.payment-btn {
padding: 10px 14px;
}
}
}
}
}
}
}
}
}
@media (max-width: 480px) {
.member {
.inner {
padding: 10px 0 10px 10px;
.product-box {
padding: 0 10px;
.list-box {
.product-item {
margin-bottom: 16px;
.product-header {
.image-container {
padding: 12px;
.el-image {
width: 50px;
height: 50px;
}
}
.product-title {
padding: 12px 12px 0;
.name {
font-size: 16px;
}
.description {
font-size: 12px;
}
}
}
.product-content {
padding: 12px;
.price-section {
.price-info {
.price-value {
font-size: 24px;
}
.currency {
font-size: 16px;
}
}
}
.features-list {
.feature-item {
font-size: 12px;
}
}
}
.product-actions {
padding: 0 12px 12px;
.payment-buttons {
.payment-btn {
padding: 8px 12px;
font-size: 12px;
i {
font-size: 16px;
}
}
}
}
}
}
}
}
}
}

View File

@@ -18,7 +18,7 @@
<span>{{ scope.row.remark && scope.row.remark.power }}</span> <span>{{ scope.row.remark && scope.row.remark.power }}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column prop="pay_method" label="支付渠道" /> <el-table-column prop="channel_name" label="支付渠道" />
<el-table-column prop="pay_name" label="支付名称" /> <el-table-column prop="pay_name" label="支付名称" />
<el-table-column label="支付时间"> <el-table-column label="支付时间">
<template #default="scope"> <template #default="scope">

View File

@@ -340,7 +340,7 @@
<VideoPause /> <VideoPause />
</el-icon> </el-icon>
</el-button> </el-button>
<el-button @click="sendMessage" style="color: #754ff6" v-else> <el-button @click="sendMessage()" style="color: #754ff6" v-else>
<el-tooltip class="box-item" effect="dark" content="发送"> <el-tooltip class="box-item" effect="dark" content="发送">
<el-icon><Promotion /></el-icon> <el-icon><Promotion /></el-icon>
</el-tooltip> </el-tooltip>
@@ -832,7 +832,7 @@ const sendSSERequest = async (message) => {
} }
// 发送消息 // 发送消息
const sendMessage = (messageId) => { const sendMessage = (messageId = 0) => {
if (!isLogin.value) { if (!isLogin.value) {
console.log('未登录') console.log('未登录')
store.setShowLoginDialog(true) store.setShowLoginDialog(true)
@@ -895,7 +895,7 @@ const sendMessage = (messageId) => {
tools: toolSelected.value, tools: toolSelected.value,
stream: stream.value, stream: stream.value,
files: files.value, files: files.value,
last_msg_id: messageId, last_msg_id: messageId || 0,
}) })
prompt.value = '' prompt.value = ''

View File

@@ -35,69 +35,56 @@
<div class="profile-bg"></div> <div class="profile-bg"></div>
<div class="product-box"> <div class="product-box">
<!-- <div class="info" v-if="orderPayInfoText !== ''"> <el-row v-if="list.length > 0" :gutter="24" class="list-box">
<el-alert type="success" show-icon :closable="false" effect="dark"> <el-col
<strong>说明:</strong> {{ vipInfoText }} v-for="item in list"
</el-alert> :key="item"
</div> --> :xs="24"
:sm="12"
<el-row v-if="list.length > 0" :gutter="20" class="list-box"> :md="8"
<el-col v-for="item in list" :key="item" :span="6"> :lg="6"
class="product-col"
>
<div class="product-item"> <div class="product-item">
<div class="product-header">
<div class="image-container"> <div class="image-container">
<el-image :src="vipImg" fit="cover" /> <el-image :src="vipImg" fit="cover" />
<div class="image-overlay">
<div class="vip-badge">热销</div>
</div>
</div> </div>
<div class="product-title"> <div class="product-title">
<span class="name">{{ item.name }}</span> <h3 class="name">{{ item.name }}</h3>
<p class="description">{{ item.description || '全模型通用算力' }}</p>
</div> </div>
<div class="product-info">
<div class="info-line">
<span class="label">商品原价</span>
<span class="price"
><del>{{ item.price }}</del></span
>
</div>
<div class="info-line">
<span class="label">优惠价</span>
<span class="discount">{{ item.discount }}</span>
</div>
<div class="info-line">
<span class="label">有效期</span>
<span class="expire" v-if="item.days > 0">{{ item.days }}</span>
<span class="expire" v-else>长期有效</span>
</div> </div>
<div class="info-line"> <div class="product-content">
<span class="label">算力值</span> <div class="price-section">
<span class="power">{{ item.power }}</span> <div class="price-info">
<span class="currency"></span>
<span class="price-value">{{ item.price }}</span>
</div>
</div> </div>
<div class="pay-way"> <div class="features-list" v-if="item.features">
<span <div class="feature-item" v-for="feature in item.features" :key="feature">
type="primary" <i class="iconfont icon-check"></i>
v-for="payWay in payWays" <span>{{ feature }}</span>
@click="pay(item, payWay)" </div>
:key="payWay" </div>
> </div>
<el-button v-if="payWay.pay_type === 'alipay'" color="#15A6E8" circle>
<i class="iconfont icon-alipay"></i> <div class="product-actions">
</el-button> <div class="payment-buttons">
<el-button v-else-if="payWay.pay_type === 'qqpay'" circle> <button class="payment-btn wechat-btn" @click="wxPay(item)">
<i class="iconfont icon-qq"></i>
</el-button>
<el-button v-else-if="payWay.pay_type === 'paypal'" class="paypal" round>
<i class="iconfont icon-paypal"></i>
</el-button>
<el-button v-else-if="payWay.pay_type === 'jdpay'" color="#E1251B" circle>
<i class="iconfont icon-jd-pay"></i>
</el-button>
<el-button v-else-if="payWay.pay_type === 'douyin'" class="douyin" circle>
<i class="iconfont icon-douyin"></i>
</el-button>
<el-button v-else circle class="wechat" color="#67C23A">
<i class="iconfont icon-wechat-pay"></i> <i class="iconfont icon-wechat-pay"></i>
</el-button> <span>微信支付</span>
</span> </button>
<button class="payment-btn alipay-btn" @click="alipay(item)">
<i class="iconfont icon-alipay"></i>
<span>支付宝</span>
</button>
</div> </div>
</div> </div>
</div> </div>
@@ -154,23 +141,20 @@
</el-dialog> </el-dialog>
</div> </div>
<!--支付二维码-->
<el-dialog <el-dialog
v-model="showDialog" v-model="showQrCode"
:show-close="false" :show-close="true"
:close-on-click-modal="false" style="width: 334px; height: 368px"
hide-footer
width="auto"
class="pay-dialog" class="pay-dialog"
> >
<div v-if="qrImg !== ''"> <template #header>
<div class="product-info"> <div class="flex items-center justify-center text-base">
请使用微信扫码支付<span class="price">{{ price }}</span> <span style="color: var(--el-text-color-regular)">{{ title }}</span>
</div> </div>
<el-image :src="qrImg" fit="cover" /> </template>
</div> <div class="qr-container">
<div style="padding-bottom: 10px; text-align: center"> <el-image :src="qrImg" style="height: 300px; width: 300px" />
<el-button type="success" @click="payCallback(true)">支付成功</el-button>
<el-button type="danger" @click="payCallback(false)">支付失败</el-button>
</div> </div>
</el-dialog> </el-dialog>
</div> </div>
@@ -188,7 +172,9 @@ import { useSharedStore } from '@/store/sharedata'
import { httpGet, httpPost } from '@/utils/http' import { httpGet, httpPost } from '@/utils/http'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import QRCode from 'qrcode' import QRCode from 'qrcode'
import { onMounted, ref } from 'vue' import { onMounted, ref, onUnmounted } from 'vue'
import { showLoading, closeLoading } from '@/utils/dialog'
import { isMobile } from '@/utils/libs'
const list = ref([]) const list = ref([])
const vipImg = ref('/images/menu/member.png') const vipImg = ref('/images/menu/member.png')
@@ -203,15 +189,13 @@ const isLogin = ref(false)
const orderTimeout = ref(1800) const orderTimeout = ref(1800)
const loading = ref(true) const loading = ref(true)
const loadingText = ref('加载中...') const loadingText = ref('加载中...')
const orderPayInfoText = ref('')
const payWays = ref([])
const vipInfoText = ref('')
const store = useSharedStore() const store = useSharedStore()
const userOrderKey = ref(0) const userOrderKey = ref(0)
const showDialog = ref(false) const showQrCode = ref(false)
const qrImg = ref('') const qrImg = ref('')
const price = ref(0) const title = ref('')
const handler = ref(null)
onMounted(() => { onMounted(() => {
checkSession() checkSession()
@@ -236,68 +220,78 @@ onMounted(() => {
.then((res) => { .then((res) => {
rewardImg.value = res.data['reward_img'] rewardImg.value = res.data['reward_img']
enableReward.value = res.data['enabled_reward'] enableReward.value = res.data['enabled_reward']
orderPayInfoText.value = res.data['order_pay_info_text']
if (res.data['order_pay_timeout'] > 0) { if (res.data['order_pay_timeout'] > 0) {
orderTimeout.value = res.data['order_pay_timeout'] orderTimeout.value = res.data['order_pay_timeout']
} }
vipInfoText.value = res.data['vip_info_text']
}) })
.catch((e) => { .catch((e) => {
ElMessage.error('获取系统配置失败:' + e.message) ElMessage.error('获取系统配置失败:' + e.message)
}) })
httpGet('/api/payment/payWays')
.then((res) => {
payWays.value = res.data
})
.catch((e) => {
ElMessage.error('获取支付方式失败:' + e.message)
})
}) })
const pay = (product, payWay) => { const selectedPid = ref(0)
if (!isLogin.value) { const wxPay = (product) => {
store.setShowLoginDialog(true) selectedPid.value = product.id
return title.value = '请打开微信扫码支付'
} generateOrder('wxpay')
loading.value = true }
loadingText.value = '正在生成支付订单...'
let host = import.meta.env.VITE_API_HOST const alipay = (product) => {
if (host === '') { selectedPid.value = product.id
host = `${location.protocol}//${location.host}` title.value = '请打开支付宝扫码支付'
} generateOrder('alipay')
httpPost(`${import.meta.env.VITE_API_HOST}/api/payment/doPay`, { }
product_id: product.id,
pay_way: payWay.pay_way, const generateOrder = (payWay) => {
pay_type: payWay.pay_type, showLoading('正在生成支付订单...')
user_id: user.value.id, // 生成支付订单
host: host, httpPost('/api/payment/create', {
device: 'jump', pid: selectedPid.value,
pay_way: payWay,
domain: `${window.location.protocol}//${window.location.host}`,
device: isMobile() ? 'mobile' : 'pc',
}) })
.then((res) => { .then((res) => {
showDialog.value = true closeLoading()
loading.value = false
if (payWay.pay_way === 'wechat') { if (isMobile()) {
price.value = Number(product.discount) window.location.href = res.data.pay_url
QRCode.toDataURL(res.data, { width: 300, height: 300, margin: 2 }, (error, url) => { } else {
QRCode.toDataURL(res.data.pay_url, { width: 300, height: 300, margin: 2 }, (error, url) => {
if (error) { if (error) {
console.error(error) console.error(error)
} else { } else {
qrImg.value = url qrImg.value = url
} }
}) })
} else { // 查询订单状态
window.open(res.data, '_blank') if (handler.value) {
clearTimeout(handler.value)
}
handler.value = setTimeout(() => queryOrder(res.data.order_no), 3000)
showQrCode.value = true
} }
}) })
.catch((e) => { .catch((e) => {
setTimeout(() => { closeLoading()
ElMessage.error('生成支付订单失败:' + e.message) ElMessage.error('生成支付订单失败:' + e.message)
loading.value = false
}, 500)
}) })
} }
const queryOrder = async (orderNo) => {
const res = await httpGet('/api/order/query?order_no=' + orderNo)
if (res?.data.status === 2) {
// 订单支付成功
clearTimeout(handler.value)
ElMessage.success('支付成功')
showQrCode.value = false
// 更新用户积分
user.value.scores += res.data.credit
} else {
handler.value = setTimeout(() => queryOrder(orderNo), 3000)
}
}
const redeemCallback = (success) => { const redeemCallback = (success) => {
showRedeemVerifyDialog.value = false showRedeemVerifyDialog.value = false
@@ -306,15 +300,67 @@ const redeemCallback = (success) => {
} }
} }
const payCallback = (success) => { // 组件卸载时清理定时器
showDialog.value = false onUnmounted(() => {
if (success) { if (handler.value) {
userOrderKey.value += 1 clearTimeout(handler.value)
handler.value = null
} }
} })
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@use '../assets/css/custom-scroll.scss' as *; @use '@/assets/css/custom-scroll.scss' as *;
@use '../assets/css/member.scss' as *; @use '@/assets/css/member.scss' as *;
// 支付弹窗样式优化
.pay-dialog {
.qr-container {
text-align: center;
position: relative;
.qr-overlay {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(255, 255, 255, 0.9);
display: flex;
align-items: center;
justify-content: center;
.success-text {
background: #67c23a;
color: white;
border-radius: 4px;
font-size: 14px;
}
}
}
}
// 支付按钮样式
.pay-way {
.row {
margin: 0;
.col {
padding: 0 5px;
button {
border: none;
cursor: pointer;
transition: all 0.3s ease;
font-size: 14px;
font-weight: 500;
&:hover {
transform: translateY(-2px);
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}
}
}
}
}
</style> </style>

View File

@@ -42,14 +42,23 @@
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="支付时间"> <el-table-column label="订单状态">
<template #default="scope"> <template #default="{ row }">
<span v-if="scope.row['pay_time']">{{ dateFormat(scope.row['pay_time']) }}</span> <el-tag v-if="row.status === 2" type="success">已支付</el-tag>
<el-tag v-else>未支付</el-tag> <el-tag v-else-if="row.status === 3" type="danger">已关闭</el-tag>
<el-tag v-else type="warning">未支付</el-tag>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column prop="pay_method" label="支付渠道" />
<el-table-column prop="pay_name" label="支付名称" /> <!-- 支付时间 -->
<el-table-column label="支付时间">
<template #default="row">
<span>{{ dateFormat(row.pay_time) || '--' }}</span>
</template>
</el-table-column>
<el-table-column prop="pay_name" label="支付渠道" min-width="100" />
<el-table-column prop="channel_name" label="支付渠道" min-width="100" />
<el-table-column label="操作" width="180"> <el-table-column label="操作" width="180">
<template #default="scope"> <template #default="scope">

View File

@@ -14,14 +14,7 @@
</span> </span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column prop="price" label="商品" /> <el-table-column prop="price" label="商品价" />
<el-table-column prop="discount" label="优惠价" />
<el-table-column prop="days" label="有效期()">
<template #default="scope">
<el-tag v-if="scope.row.days === 0">长期有效</el-tag>
<span v-else>{{ scope.row.days }}</span>
</template>
</el-table-column>
<el-table-column prop="power" label="算力" /> <el-table-column prop="power" label="算力" />
<el-table-column prop="sales" label="销量" /> <el-table-column prop="sales" label="销量" />
<el-table-column prop="enabled" label="启用状态"> <el-table-column prop="enabled" label="启用状态">
@@ -55,18 +48,10 @@
<el-input v-model="item.name" autocomplete="off" /> <el-input v-model="item.name" autocomplete="off" />
</el-form-item> </el-form-item>
<el-form-item label="商品" prop="price"> <el-form-item label="商品价" prop="price">
<el-input v-model="item.price" autocomplete="off" /> <el-input v-model="item.price" autocomplete="off" />
</el-form-item> </el-form-item>
<el-form-item label="优惠价" prop="discount">
<el-input v-model="item.discount" autocomplete="off" />
</el-form-item>
<el-form-item label="有效期" prop="days">
<el-input v-model.number="item.days" autocomplete="off" placeholder="会员有效期()" />
</el-form-item>
<el-form-item label="算力" prop="power"> <el-form-item label="算力" prop="power">
<el-input v-model.number="item.power" autocomplete="off" placeholder="增加算力值" /> <el-input v-model.number="item.power" autocomplete="off" placeholder="增加算力值" />
</el-form-item> </el-form-item>