feat: reward verify is ready

This commit is contained in:
RockYang 2023-07-21 22:29:14 +08:00
parent dd88622c64
commit e02badf7bb
7 changed files with 109 additions and 9 deletions

View File

@ -152,7 +152,7 @@ func (h *ChatHandler) sendMessage(ctx context.Context, session types.ChatSession
}
if userVo.Calls <= 0 && userVo.ChatConfig.ApiKey == "" {
replyMessage(ws, "您的对话次数已经用尽,请联系管理员充值")
replyMessage(ws, "您的对话次数已经用尽,请联系管理员或者点击左下角菜单加入众筹获得100次对话")
replyMessage(ws, "![](/images/wx.png)")
return nil
}

View File

@ -24,7 +24,7 @@ func NewRewardHandler(server *core.AppServer, db *gorm.DB) *RewardHandler {
// Verify 打赏码核销
func (h *RewardHandler) Verify(c *gin.Context) {
var data struct {
TxId string
TxId string `json:"tx_id"`
}
if err := c.ShouldBindJSON(&data); err != nil {
resp.ERROR(c, types.InvalidArgs)
@ -34,12 +34,12 @@ func (h *RewardHandler) Verify(c *gin.Context) {
var item model.Reward
res := h.db.Where("tx_id = ?", data.TxId).First(&item)
if res.Error != nil {
resp.ERROR(c, "无效的打赏交易流水号!")
resp.ERROR(c, "无效的众筹交易流水号!")
return
}
if item.Status {
resp.ERROR(c, "当前打赏交易流水号已经被核销,请不要重复核销!")
resp.ERROR(c, "当前众筹交易流水号已经被核销,请不要重复核销!")
return
}
@ -50,7 +50,7 @@ func (h *RewardHandler) Verify(c *gin.Context) {
}
tx := h.db.Begin()
calls := (item.Amount + 0.01) * 10
calls := (item.Amount + 0.1) * 10
res = h.db.Model(&user).UpdateColumn("calls", gorm.Expr("calls + ?", calls))
if res.Error != nil {
resp.ERROR(c, "更新数据库失败!")

View File

@ -107,7 +107,9 @@ func main() {
fx.Invoke(func(bot *wexin.WeChatBot) {
go func() {
err := bot.Login()
if err != nil {
log.Fatal(err)
}
}()
}),
@ -188,7 +190,7 @@ func main() {
}),
fx.Invoke(func(s *core.AppServer, h *handler.RewardHandler) {
group := s.Engine.Group("/api/reward/")
group.GET("verify", h.Verify)
group.POST("verify", h.Verify)
}),
// 管理后台控制器

View File

@ -15,4 +15,5 @@ ALTER TABLE `chatgpt_rewards`
ALTER TABLE `chatgpt_rewards`
MODIFY `id` int NOT NULL AUTO_INCREMENT;
COMMIT;
update chatgpt_users set calls=0

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 261 KiB

View File

@ -0,0 +1,75 @@
<template>
<el-dialog
v-model="showDialog"
:close-on-click-modal="false"
:show-close="mobile !== ''"
:before-close="close"
:title="title"
>
<div class="form" id="bind-mobile-form">
<el-alert v-if="mobile !== ''" type="info" show-icon :closable="false" style="margin-bottom: 20px;">
<p>请输入您参与众筹的微信支付转账单号兑换相应的对话次数</p>
</el-alert>
<el-form :model="form" label-width="120px">
<el-form-item label="转账单号">
<el-input v-model="form.tx_id"/>
</el-form-item>
</el-form>
</div>
<template #footer>
<span class="dialog-footer">
<el-button type="primary" @click="save">
确认核销
</el-button>
</span>
</template>
</el-dialog>
</template>
<script setup>
import {computed, ref} from "vue";
import {ElMessage} from "element-plus";
import {httpPost} from "@/utils/http";
const props = defineProps({
show: Boolean,
mobile: String
});
const showDialog = computed(() => {
return props.show
})
const title = ref('众筹码核销')
const form = ref({
tx_id: '',
})
const emits = defineEmits(['hide']);
const save = () => {
if (form.value.tx_id === '') {
return ElMessage.error({message: "请输入微信支付转账单号"});
}
httpPost('/api/reward/verify', form.value).then(() => {
ElMessage.success({
message: '核销成功',
duration: 1000,
onClose: () => emits('hide', false)
})
}).catch(e => {
ElMessage.error({message: "核销失败:" + e.message});
})
}
const close = function () {
emits('hide', false);
}
</script>
<style scoped>
</style>

View File

@ -67,6 +67,20 @@
<span>绑定手机号</span>
</el-dropdown-item>
<el-dropdown-item @click="showRewardDialog = true">
<el-icon>
<Present/>
</el-icon>
<span>加入众筹</span>
</el-dropdown-item>
<el-dropdown-item @click="showRewardVerifyDialog = true">
<el-icon>
<Checked/>
</el-icon>
<span>众筹核销</span>
</el-dropdown-item>
<el-dropdown-item @click="clearAllChats">
<el-icon>
<Delete/>
@ -199,11 +213,14 @@
<bind-mobile v-if="isLogin" :show="showBindMobileDialog" :mobile="loginUser.mobile"
@hide="showBindMobileDialog = false"/>
<reward-verify v-if="isLogin" :show="showRewardVerifyDialog" @hide="showRewardVerifyDialog = false"/>
<el-dialog
v-model="showRewardDialog"
:show-close="true"
custom-class="donate-dialog"
width="400px"
top="5vh"
title="参与众筹"
>
<el-alert type="info" :closable="false">
@ -212,7 +229,7 @@
账单和服务器的费用</p>
</el-alert>
<p>
<el-image :src="donateImg"/>
<el-image :src="rewardImg"/>
</p>
</el-dialog>
</div>
@ -226,11 +243,13 @@ import ChatReply from "@/components/ChatReply.vue";
import {
ArrowDown,
Check,
Checked,
Close,
Delete,
Edit,
Iphone,
Plus,
Present,
Promotion,
RefreshRight,
Search,
@ -249,9 +268,11 @@ import ConfigDialog from "@/components/ConfigDialog.vue";
import PasswordDialog from "@/components/PasswordDialog.vue";
import {checkSession} from "@/action/session";
import BindMobile from "@/components/BindMobile.vue";
import RewardVerify from "@/components/RewardVerify.vue";
const title = ref('ChatGPT-智能助手');
const logo = 'images/logo.png';
const rewardImg = ref('images/reward.png')
const models = ref([])
const model = ref('gpt-3.5-turbo')
const chatData = ref([]);
@ -271,6 +292,7 @@ const showConfigDialog = ref(false);
const showPasswordDialog = ref(false);
const showBindMobileDialog = ref(false);
const showRewardDialog = ref(false);
const showRewardVerifyDialog = ref(false);
const isLogin = ref(false)
if (isMobile()) {