mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-09-18 01:06:39 +08:00
feat: 增加打赏核销功能
This commit is contained in:
parent
1e1bcd4a30
commit
aa28f87b0c
72
api/handler/reward_handler.go
Normal file
72
api/handler/reward_handler.go
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"chatplus/core"
|
||||||
|
"chatplus/core/types"
|
||||||
|
"chatplus/store/model"
|
||||||
|
"chatplus/utils"
|
||||||
|
"chatplus/utils/resp"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type RewardHandler struct {
|
||||||
|
BaseHandler
|
||||||
|
db *gorm.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewRewardHandler(server *core.AppServer, db *gorm.DB) *RewardHandler {
|
||||||
|
h := RewardHandler{db: db}
|
||||||
|
h.App = server
|
||||||
|
return &h
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify 打赏码核销
|
||||||
|
func (h *RewardHandler) Verify(c *gin.Context) {
|
||||||
|
var data struct {
|
||||||
|
TxId string
|
||||||
|
}
|
||||||
|
if err := c.ShouldBindJSON(&data); err != nil {
|
||||||
|
resp.ERROR(c, types.InvalidArgs)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var item model.Reward
|
||||||
|
res := h.db.Where("tx_id = ?", data.TxId).First(&item)
|
||||||
|
if res.Error != nil {
|
||||||
|
resp.ERROR(c, "无效的打赏交易流水号!")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if item.Status {
|
||||||
|
resp.ERROR(c, "当前打赏交易流水号已经被核销,请不要重复核销!")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
user, err := utils.GetLoginUser(c, h.db)
|
||||||
|
if err != nil {
|
||||||
|
resp.HACKER(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tx := h.db.Begin()
|
||||||
|
calls := (item.Amount + 0.01) * 10
|
||||||
|
res = h.db.Model(&user).UpdateColumn("calls", gorm.Expr("calls + ?", calls))
|
||||||
|
if res.Error != nil {
|
||||||
|
resp.ERROR(c, "更新数据库失败!")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新核销状态
|
||||||
|
item.Status = true
|
||||||
|
res = h.db.Updates(&item)
|
||||||
|
if res.Error != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
resp.ERROR(c, "更新数据库失败!")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tx.Commit()
|
||||||
|
resp.SUCCESS(c)
|
||||||
|
|
||||||
|
}
|
@ -13,7 +13,7 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 生成验证的控制器
|
// 短信验证码控制器
|
||||||
|
|
||||||
type VerifyHandler struct {
|
type VerifyHandler struct {
|
||||||
BaseHandler
|
BaseHandler
|
||||||
|
12
api/main.go
12
api/main.go
@ -104,8 +104,11 @@ func main() {
|
|||||||
|
|
||||||
// 创建微信机器人
|
// 创建微信机器人
|
||||||
fx.Provide(wexin.NewWeChatBot),
|
fx.Provide(wexin.NewWeChatBot),
|
||||||
fx.Invoke(func(bot *wexin.WeChatBot) error {
|
fx.Invoke(func(bot *wexin.WeChatBot) {
|
||||||
return bot.Login()
|
go func() {
|
||||||
|
err := bot.Login()
|
||||||
|
log.Fatal(err)
|
||||||
|
}()
|
||||||
}),
|
}),
|
||||||
|
|
||||||
// 创建函数
|
// 创建函数
|
||||||
@ -137,6 +140,7 @@ func main() {
|
|||||||
fx.Provide(handler.NewChatHandler),
|
fx.Provide(handler.NewChatHandler),
|
||||||
fx.Provide(handler.NewUploadHandler),
|
fx.Provide(handler.NewUploadHandler),
|
||||||
fx.Provide(handler.NewVerifyHandler),
|
fx.Provide(handler.NewVerifyHandler),
|
||||||
|
fx.Provide(handler.NewRewardHandler),
|
||||||
|
|
||||||
fx.Provide(admin.NewConfigHandler),
|
fx.Provide(admin.NewConfigHandler),
|
||||||
fx.Provide(admin.NewAdminHandler),
|
fx.Provide(admin.NewAdminHandler),
|
||||||
@ -182,6 +186,10 @@ func main() {
|
|||||||
group.GET("token", h.Token)
|
group.GET("token", h.Token)
|
||||||
group.POST("sms", h.SendMsg)
|
group.POST("sms", h.SendMsg)
|
||||||
}),
|
}),
|
||||||
|
fx.Invoke(func(s *core.AppServer, h *handler.RewardHandler) {
|
||||||
|
group := s.Engine.Group("/api/reward/")
|
||||||
|
group.GET("verify", h.Verify)
|
||||||
|
}),
|
||||||
|
|
||||||
// 管理后台控制器
|
// 管理后台控制器
|
||||||
fx.Invoke(func(s *core.AppServer, h *admin.ConfigHandler) {
|
fx.Invoke(func(s *core.AppServer, h *admin.ConfigHandler) {
|
||||||
|
BIN
web/public/images/reward.png
Normal file
BIN
web/public/images/reward.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 32 KiB |
@ -198,6 +198,23 @@
|
|||||||
|
|
||||||
<bind-mobile v-if="isLogin" :show="showBindMobileDialog" :mobile="loginUser.mobile"
|
<bind-mobile v-if="isLogin" :show="showBindMobileDialog" :mobile="loginUser.mobile"
|
||||||
@hide="showBindMobileDialog = false"/>
|
@hide="showBindMobileDialog = false"/>
|
||||||
|
|
||||||
|
<el-dialog
|
||||||
|
v-model="showRewardDialog"
|
||||||
|
:show-close="true"
|
||||||
|
custom-class="donate-dialog"
|
||||||
|
width="400px"
|
||||||
|
title="参与众筹"
|
||||||
|
>
|
||||||
|
<el-alert type="info" :closable="false">
|
||||||
|
<p>您好,ChatGPT-Plus 项目目前已经运行了快半年了,一直免费给大家使用的。然而免费服务始终难以维持,服务器即将到期,免费的
|
||||||
|
API KEY 也全部用完了,因此我们准备开启众筹模式,只需要打赏9.9元,就可以兑换 100 次对话,以此来覆盖我们的 OpenAI
|
||||||
|
账单和服务器的费用。</p>
|
||||||
|
</el-alert>
|
||||||
|
<p>
|
||||||
|
<el-image :src="donateImg"/>
|
||||||
|
</p>
|
||||||
|
</el-dialog>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
@ -253,6 +270,7 @@ const router = useRouter();
|
|||||||
const showConfigDialog = ref(false);
|
const showConfigDialog = ref(false);
|
||||||
const showPasswordDialog = ref(false);
|
const showPasswordDialog = ref(false);
|
||||||
const showBindMobileDialog = ref(false);
|
const showBindMobileDialog = ref(false);
|
||||||
|
const showRewardDialog = ref(false);
|
||||||
const isLogin = ref(false)
|
const isLogin = ref(false)
|
||||||
|
|
||||||
if (isMobile()) {
|
if (isMobile()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user