diff --git a/CHANGELOG.md b/CHANGELOG.md index 5305970e..cdfced91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ * 功能优化:移除PayJS支付渠道支持,PayJs已经关闭注册服务,请使用其他支付方式。 * 功能新增:新增GeeK易支付支付渠道,支持支付宝,微信支付,QQ钱包,京东支付,抖音支付,Paypal支付等支付方式 * Bug修复:修复注册页面 tab 组件没有自动选中问题 [#6](https://github.com/yangjian102621/geekai-plus/issues/6) +* 功能优化:Luma生成视频任务增加自动翻译功能 ## v4.1.3 * 功能优化:重构用户登录模块,给所有的登录组件增加行为验证码功能,支持用户绑定手机,邮箱和微信 diff --git a/api/core/types/config.go b/api/core/types/config.go index 6fae56b1..046d0657 100644 --- a/api/core/types/config.go +++ b/api/core/types/config.go @@ -58,7 +58,6 @@ type AlipayConfig struct { AlipayPublicKey string // 支付宝公钥文件路径 RootCert string // Root 秘钥路径 NotifyURL string // 异步通知地址 - ReturnURL string // 同步回调地址 } type WechatPayConfig struct { @@ -69,7 +68,6 @@ type WechatPayConfig struct { PrivateKey string // 用户私钥文件路径 ApiV3Key string // API V3 秘钥 NotifyURL string // 异步通知地址 - ReturnURL string // 同步回调地址 } type HuPiPayConfig struct { //虎皮椒第四方支付配置 @@ -78,7 +76,6 @@ type HuPiPayConfig struct { //虎皮椒第四方支付配置 AppSecret string // app 密钥 ApiURL string // 支付网关 NotifyURL string // 异步通知地址 - ReturnURL string // 同步回调地址 } // GeekPayConfig GEEK支付配置 @@ -88,7 +85,6 @@ type GeekPayConfig struct { PrivateKey string // 私钥 ApiURL string // API 网关 NotifyURL string // 异步通知地址 - ReturnURL string // 同步回调地址 Methods []string // 支付方式 } diff --git a/api/core/types/order.go b/api/core/types/order.go index 90cc0cb1..c0dd13ac 100644 --- a/api/core/types/order.go +++ b/api/core/types/order.go @@ -22,3 +22,18 @@ type OrderRemark struct { Price float64 `json:"price"` Discount float64 `json:"discount"` } + +var PayMethods = map[string]string{ + "alipay": "支付宝商号", + "wechat": "微信商号", + "hupi": "虎皮椒", + "geek": "易支付", +} +var PayNames = map[string]string{ + "alipay": "支付宝", + "wxpay": "微信支付", + "qqpay": "QQ钱包", + "jdpay": "京东支付", + "douyin": "抖音支付", + "paypal": "PayPal支付", +} diff --git a/api/handler/admin/order_handler.go b/api/handler/admin/order_handler.go index 510255f4..536d79c4 100644 --- a/api/handler/admin/order_handler.go +++ b/api/handler/admin/order_handler.go @@ -67,6 +67,16 @@ func (h *OrderHandler) List(c *gin.Context) { order.Id = item.Id order.CreatedAt = item.CreatedAt.Unix() order.UpdatedAt = item.UpdatedAt.Unix() + payMethod, ok := types.PayMethods[item.PayWay] + if !ok { + payMethod = item.PayWay + } + payName, ok := types.PayNames[item.PayType] + if !ok { + payName = item.PayWay + } + order.PayMethod = payMethod + order.PayName = payName list = append(list, order) } else { logger.Error(err) diff --git a/api/handler/order_handler.go b/api/handler/order_handler.go index 55348e1b..a9ee42f3 100644 --- a/api/handler/order_handler.go +++ b/api/handler/order_handler.go @@ -48,6 +48,16 @@ func (h *OrderHandler) List(c *gin.Context) { order.Id = item.Id order.CreatedAt = item.CreatedAt.Unix() order.UpdatedAt = item.UpdatedAt.Unix() + payMethod, ok := types.PayMethods[item.PayWay] + if !ok { + payMethod = item.PayWay + } + payName, ok := types.PayNames[item.PayType] + if !ok { + payName = item.PayWay + } + order.PayMethod = payMethod + order.PayName = payName list = append(list, order) } else { logger.Error(err) diff --git a/api/handler/payment_handler.go b/api/handler/payment_handler.go index 43ddf5d2..72718fa4 100644 --- a/api/handler/payment_handler.go +++ b/api/handler/payment_handler.go @@ -97,6 +97,76 @@ func (h *PaymentHandler) Pay(c *gin.Context) { resp.NotAuth(c) return } + + amount, _ := decimal.NewFromFloat(product.Price).Sub(decimal.NewFromFloat(product.Discount)).Float64() + var payURL string + if payWay == "alipay" { // 支付宝 + returnURL := fmt.Sprintf("%s/payReturn", utils.GetBaseURL(h.App.Config.AlipayConfig.NotifyURL)) + money := fmt.Sprintf("%.2f", amount) + payURL, err = h.alipayService.PayPC(payment.AlipayParams{ + OutTradeNo: orderNo, + Subject: product.Name, + TotalFee: money, + ReturnURL: returnURL, + NotifyURL: h.App.Config.AlipayConfig.NotifyURL, + }) + if err != nil { + resp.ERROR(c, "error with generate pay url: "+err.Error()) + return + } + } else if payWay == "hupi" { // 虎皮椒支付 + returnURL := fmt.Sprintf("%s/payReturn", utils.GetBaseURL(h.App.Config.HuPiPayConfig.NotifyURL)) + r, err := h.huPiPayService.Pay(payment.HuPiPayParams{ + Version: "1.1", + TradeOrderId: orderNo, + TotalFee: fmt.Sprintf("%f", amount), + Title: product.Name, + NotifyURL: h.App.Config.HuPiPayConfig.NotifyURL, + ReturnURL: returnURL, + WapName: "GeekAI助手", + }) + if err != nil { + resp.ERROR(c, err.Error()) + return + } + + payURL = r.URL + } else if payWay == "wechat" { + payURL, err = h.wechatPayService.PayUrlNative(payment.WechatPayParams{ + OutTradeNo: orderNo, + TotalFee: int(amount * 100), + Subject: product.Name, + NotifyURL: h.App.Config.WechatPayConfig.NotifyURL, + }) + if err != nil { + resp.ERROR(c, err.Error()) + return + } + } else if payWay == "geek" { + returnURL := fmt.Sprintf("%s/payReturn", utils.GetBaseURL(h.App.Config.GeekPayConfig.NotifyURL)) + if device == "wechat" { + returnURL = fmt.Sprintf("%s/mobile/profile", utils.GetBaseURL(h.App.Config.GeekPayConfig.NotifyURL)) + } + params := payment.GeekPayParams{ + OutTradeNo: orderNo, + Method: "web", + Name: product.Name, + Money: fmt.Sprintf("%f", amount), + ClientIP: c.ClientIP(), + Device: device, + Type: payType, + ReturnURL: returnURL, + NotifyURL: h.App.Config.GeekPayConfig.NotifyURL, + } + + res, err := h.geekPayService.Pay(params) + if err != nil { + resp.ERROR(c, err.Error()) + return + } + payURL = res.PayURL + } + // 创建订单 remark := types.OrderRemark{ Days: product.Days, @@ -105,9 +175,6 @@ func (h *PaymentHandler) Pay(c *gin.Context) { Price: product.Price, Discount: product.Discount, } - - amount, _ := decimal.NewFromFloat(product.Price).Sub(decimal.NewFromFloat(product.Discount)).Float64() - order := model.Order{ UserId: user.Id, Username: user.Username, @@ -125,78 +192,6 @@ func (h *PaymentHandler) Pay(c *gin.Context) { resp.ERROR(c, "error with create order: "+err.Error()) return } - - var payURL string - if payWay == "alipay" { // 支付宝 - money := fmt.Sprintf("%.2f", order.Amount) - if device == "mobile" { - payURL, err = h.alipayService.PayMobile(payment.AlipayParams{ - OutTradeNo: orderNo, - Subject: product.Name, - TotalFee: money, - NotifyURL: h.App.Config.AlipayConfig.NotifyURL, - }) - } else { - payURL, err = h.alipayService.PayPC(payment.AlipayParams{ - OutTradeNo: orderNo, - Subject: product.Name, - TotalFee: money, - ReturnURL: h.App.Config.AlipayConfig.ReturnURL, - NotifyURL: h.App.Config.AlipayConfig.NotifyURL, - }) - } - if err != nil { - resp.ERROR(c, "error with generate pay url: "+err.Error()) - return - } - } else if order.PayWay == "hupi" { // 虎皮椒支付 - r, err := h.huPiPayService.Pay(payment.HuPiPayParams{ - Version: "1.1", - TradeOrderId: orderNo, - TotalFee: fmt.Sprintf("%f", order.Amount), - Title: order.Subject, - NotifyURL: h.App.Config.HuPiPayConfig.NotifyURL, - ReturnURL: h.App.Config.HuPiPayConfig.ReturnURL, - WapName: "GeekAI助手", - }) - if err != nil { - resp.ERROR(c, err.Error()) - return - } - - payURL = r.URL - } else if order.PayWay == "wechat" { - payURL, err = h.wechatPayService.PayUrlNative(payment.WechatPayParams{ - OutTradeNo: orderNo, - TotalFee: int(order.Amount * 100), - Subject: order.Subject, - NotifyURL: h.App.Config.WechatPayConfig.NotifyURL, - ReturnURL: h.App.Config.WechatPayConfig.ReturnURL, - }) - if err != nil { - resp.ERROR(c, err.Error()) - return - } - } else if order.PayWay == "geek" { - params := payment.GeekPayParams{ - OutTradeNo: orderNo, - Method: "web", - Name: order.Subject, - Money: fmt.Sprintf("%f", order.Amount), - ClientIP: c.ClientIP(), - Device: device, - Type: payType, - ReturnURL: h.App.Config.GeekPayConfig.ReturnURL, - NotifyURL: h.App.Config.GeekPayConfig.NotifyURL, - } - - res, err := h.geekPayService.Pay(params) - if err != nil { - resp.ERROR(c, err.Error()) - return - } - payURL = res.PayURL - } resp.SUCCESS(c, payURL) } diff --git a/api/service/video/luma.go b/api/service/video/luma.go index 2c12c627..2b1f250d 100644 --- a/api/service/video/luma.go +++ b/api/service/video/luma.go @@ -82,6 +82,17 @@ func (s *Service) Run() { logger.Errorf("taking task with error: %v", err) continue } + + // translate prompt + if utils.HasChinese(task.Prompt) { + content, err := utils.OpenAIRequest(s.db, fmt.Sprintf(service.TranslatePromptTemplate, task.Prompt), "gpt-4o-mini") + if err == nil { + task.Prompt = content + } else { + logger.Warnf("error with translate prompt: %v", err) + } + } + var r LumaRespVo r, err = s.LumaCreate(task) if err != nil { diff --git a/api/store/vo/order.go b/api/store/vo/order.go index 39693649..8ec4f2f9 100644 --- a/api/store/vo/order.go +++ b/api/store/vo/order.go @@ -17,5 +17,7 @@ type Order struct { PayTime int64 `json:"pay_time"` PayWay string `json:"pay_way"` PayType string `json:"pay_type"` + PayMethod string `json:"pay_method"` + PayName string `json:"pay_name"` Remark types.OrderRemark `json:"remark"` } diff --git a/api/utils/net.go b/api/utils/net.go index 74c1cb4b..d88a36c1 100644 --- a/api/utils/net.go +++ b/api/utils/net.go @@ -9,6 +9,7 @@ package utils import ( "encoding/json" + "fmt" "geekai/core/types" logger2 "geekai/logger" "io" @@ -76,3 +77,11 @@ func DownloadImage(imageURL string, proxy string) ([]byte, error) { return imageBytes, nil } + +func GetBaseURL(strURL string) string { + u, err := url.Parse(strURL) + if err != nil { + return "" + } + return fmt.Sprintf("%s://%s", u.Scheme, u.Host) +} diff --git a/web/src/components/UserOrder.vue b/web/src/components/UserOrder.vue index 13432f27..ffbbc4e5 100644 --- a/web/src/components/UserOrder.vue +++ b/web/src/components/UserOrder.vue @@ -22,7 +22,8 @@ {{ scope.row.remark?.power }} - + + - + +