From e9a35103464769d38c7b84876d08bd348bb3188a Mon Sep 17 00:00:00 2001 From: RockYang Date: Mon, 18 Mar 2024 18:28:34 +0800 Subject: [PATCH] feat: refactoring adjustments for reward page is ready --- api/handler/payment_handler.go | 31 +++++++++++++++++++++++++++-- api/service/wx/tranaction.go | 2 +- api/store/vo/reward.go | 2 +- web/src/components/RewardVerify.vue | 10 ---------- web/src/views/admin/Reward.vue | 5 +---- 5 files changed, 32 insertions(+), 18 deletions(-) diff --git a/api/handler/payment_handler.go b/api/handler/payment_handler.go index a33ad0e..9564b58 100644 --- a/api/handler/payment_handler.go +++ b/api/handler/payment_handler.go @@ -11,6 +11,7 @@ import ( "embed" "encoding/base64" "fmt" + "github.com/shopspring/decimal" "math" "net/http" "net/url" @@ -207,13 +208,15 @@ func (h *PaymentHandler) PayQrcode(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, ProductId: product.Id, OrderNo: orderNo, Subject: product.Name, - Amount: product.Price - product.Discount, + Amount: amount, Status: types.OrderNotPaid, PayWay: payWay, Remark: utils.JsonEncode(remark), @@ -308,20 +311,28 @@ func (h *PaymentHandler) notify(orderNo string, tradeNo string) error { return err } + var opt string + var power int if user.Vip { // 已经是 VIP 用户 if remark.Days > 0 { // 只延期 VIP,不增加调用次数 user.ExpiredTime = time.Unix(user.ExpiredTime, 0).AddDate(0, 0, remark.Days).Unix() } else { // 充值点卡,直接增加次数即可 user.Power += remark.Power + opt = "点卡充值" + power = remark.Power } - } else { // 非 VIP 用户 + } else { // 非 VIP 用户 if remark.Days > 0 { // vip 套餐:days > 0, power == 0 user.ExpiredTime = time.Now().AddDate(0, 0, remark.Days).Unix() user.Power += h.App.SysConfig.VipMonthPower user.Vip = true + opt = "VIP充值" + power = h.App.SysConfig.VipMonthPower } else { //点卡:days == 0, calls > 0 user.Power += remark.Power + opt = "点卡充值" + power = remark.Power } } @@ -346,6 +357,22 @@ func (h *PaymentHandler) notify(orderNo string, tradeNo string) error { // 更新产品销量 h.db.Model(&model.Product{}).Where("id = ?", order.ProductId).UpdateColumn("sales", gorm.Expr("sales + ?", 1)) + + // 记录算力充值日志 + if opt != "" { + h.db.Create(&model.PowerLog{ + UserId: user.Id, + Username: user.Username, + Type: types.PowerRecharge, + Amount: power, + Balance: user.Power, + Mark: types.PowerAdd, + Model: "", + Remark: fmt.Sprintf("%s,金额:%f,订单号:%s", opt, order.Amount, order.OrderNo), + CreatedAt: time.Now(), + }) + } + return nil } diff --git a/api/service/wx/tranaction.go b/api/service/wx/tranaction.go index 7f8c7e4..ca1383a 100644 --- a/api/service/wx/tranaction.go +++ b/api/service/wx/tranaction.go @@ -41,7 +41,7 @@ func parseTransactionMessage(xmlData string) *Message { } if se.Name.Local == "weapp_path" || se.Name.Local == "url" { if err := decoder.DecodeElement(&value, &se); err == nil { - if strings.Contains(value, "trans_id=") { + if strings.Contains(value, "?trans_id=") || strings.Contains(value, "?id=") { message.Url = value } } diff --git a/api/store/vo/reward.go b/api/store/vo/reward.go index ab443ec..b3c5ac1 100644 --- a/api/store/vo/reward.go +++ b/api/store/vo/reward.go @@ -12,5 +12,5 @@ type Reward struct { } type RewardExchange struct { - Power int `json:"calls"` + Power int `json:"power"` } diff --git a/web/src/components/RewardVerify.vue b/web/src/components/RewardVerify.vue index 141e8c0..3968716 100644 --- a/web/src/components/RewardVerify.vue +++ b/web/src/components/RewardVerify.vue @@ -17,15 +17,6 @@ - - - - - 对话聊天 - AI绘图 - - -