feat: refactoring adjustments for reward page is ready

This commit is contained in:
RockYang 2024-03-18 18:28:34 +08:00
parent 30e6e963b3
commit e9a3510346
5 changed files with 32 additions and 18 deletions

View File

@ -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
}

View File

@ -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
}
}

View File

@ -12,5 +12,5 @@ type Reward struct {
}
type RewardExchange struct {
Power int `json:"calls"`
Power int `json:"power"`
}

View File

@ -17,15 +17,6 @@
<el-input v-model="form.tx_id"/>
</el-form-item>
</el-form>
<el-form :model="form">
<el-form-item label="兑换类别">
<el-radio-group v-model="form.type">
<el-radio label="chat" border>对话聊天</el-radio>
<el-radio label="img" border>AI绘图</el-radio>
</el-radio-group>
</el-form-item>
</el-form>
</div>
<template #footer>
@ -55,7 +46,6 @@ const showDialog = computed(() => {
const title = ref('众筹码核销')
const form = ref({
tx_id: '',
type: 'chat'
})
const emits = defineEmits(['hide']);

View File

@ -23,10 +23,7 @@
<el-table-column label="兑换详情">
<template #default="scope">
<el-tag v-if="scope.row['exchange']['calls'] > 0">聊天{{ scope.row['exchange']['calls'] }}</el-tag>
<el-tag v-else-if="scope.row['exchange']['img_calls'] > 0" type="success">
绘图{{ scope.row['exchange']['img_calls'] }}
</el-tag>
<span v-if="scope.row['exchange']['power'] > 0">增加{{ scope.row['exchange']['power'] }}算力</span>
</template>
</el-table-column>