SQL
CREATE TABLE `recharge` (
`id` int NOT NULL AUTO_INCREMENT COMMENT 'ID',
`money` decimal(10,2) DEFAULT NULL COMMENT '充值金额',
`user_id` int DEFAULT NULL COMMENT '充值人',
`type` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '支付方式',
`time` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '充值时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='充值记录';
开发后端接口
Recharge.java
package com.example.entity;
import java.math.BigDecimal;
public class Recharge {
/**ID */
private Integer id;
/**充值金额 */
private BigDecimal money;
/**充值人 */
private Integer userId;
private String userName;
/**支付方式 */
private String type;
/**充值时间 */
private String time;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public BigDecimal getMoney() {
return money;
}
public void setMoney(BigDecimal money) {
this.money = money;
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
}
RechargeMapper.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.mapper.RechargeMapper">
<select id="selectAll" resultType="com.example.entity.Recharge">
select recharge.*, user.name as userName from `recharge`
left join user on recharge.user_id = user.id
<where>
<if test="userName != null"> and user.name like concat('%', #{userName}, '%')</if>
<if test="time != null"> and recharge.time like concat('%', #{time}, '%')</if>
<if test="userId != null"> and recharge.user_id = #{userId}</if>
</where>
order by recharge.id desc
</select>
<select id="selectById" resultType="com.example.entity.Recharge">
select * from `recharge` where id = #{id}
</select>
<delete id="deleteById">
delete from `recharge` where id = #{id}
</delete>
<insert id="insert" parameterType="com.example.entity.Recharge" useGeneratedKeys="true">
insert into `recharge`
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="money != null">money,</if>
<if test="userId != null">user_id,</if>
<if test="type != null">type,</if>
<if test="time != null">time,</if>
</trim>
values
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="money != null">#{money},</if>
<if test="userId != null">#{userId},</if>
<if test="type != null">#{type},</if>
<if test="time != null">#{time},</if>
</trim>
</insert>
<update id="updateById" parameterType="com.example.entity.Recharge">
update `recharge`
<set>
<if test="money != null">money = #{money},</if>
<if test="userId != null">user_id = #{userId},</if>
<if test="type != null">type = #{type},</if>
<if test="time != null">time = #{time},</if>
</set>
where id = #{id}
</update>
</mapper>
开发前端页面


Recharge.vue 管理页面
<template>
<div>
<div class="card" style="margin-bottom: 5px;">
<el-input v-model="data.userName" style="width: 300px; margin-right: 10px" placeholder="请输入用户名称查询"></el-input>
<el-date-picker style="width: 300px; margin-right: 10px" v-model="data.time" type="date" placeholder="请输入日期查询" format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
<el-button type="primary" @click="load">查询</el-button>
<el-button type="info" style="margin: 0 10px" @click="reset">重置</el-button>
</div>
<div class="card" style="margin-bottom: 5px">
<el-table :data="data.tableData" stripe>
<el-table-column prop="money" label="充值金额">
<template #default="scope">
<b style="color: red">{{ scope.row.money }}元</b>
</template>
</el-table-column>
<el-table-column prop="userName" label="充值人"></el-table-column>
<el-table-column prop="type" label="支付方式"></el-table-column>
<el-table-column prop="time" label="充值时间"></el-table-column>
<el-table-column label="操作" align="center" width="100">
<template #default="scope">
<el-button type="danger" @click="handleDelete(scope.row.id)">删除</el-button>
</template>
</el-table-column>
</el-table>
</div>
<div class="card">
<el-pagination @current-change="load" background layout="total, prev, pager, next" v-model:page-size="data.pageSize" v-model:current-page="data.pageNum" :total="data.total"/>
</div>
</div>
</template>
<script setup>
import request from "@/utils/request";
import {reactive, ref} from "vue";
import {ElMessageBox, ElMessage} from "element-plus";
const formRef = ref()
const data = reactive({
pageNum: 1,
pageSize: 10,
total: 0,
formVisible: false,
form: {},
tableData: [],
userName: null,
time: null,
})
// 分页查询
const load = () => {
request.get('/recharge/selectPage', {
params: {
pageNum: data.pageNum,
pageSize: data.pageSize,
userName: data.userName,
time: data.time
}
}).then(res => {
data.tableData = res.data?.list
data.total = res.data?.total
})
}
load()
// 新增
const handleAdd = () => {
data.form = {}
data.formVisible = true
}
// 编辑
const handleEdit = (row) => {
data.form = JSON.parse(JSON.stringify(row))
data.formVisible = true
}
// 新增保存
const add = () => {
request.post('/recharge/add', data.form).then(res => {
if (res.code === '200') {
load()
ElMessage.success('操作成功')
data.formVisible = false
} else {
ElMessage.error(res.msg)
}
})
}
// 编辑保存
const update = () => {
request.put('/recharge/update', data.form).then(res => {
if (res.code === '200') {
load()
ElMessage.success('操作成功')
data.formVisible = false
} else {
ElMessage.error(res.msg)
}
})
}
// 弹窗保存
const save = () => {
formRef.value.validate(valid => {
if (valid) {
// data.form有id就是更新,没有就是新增
data.form.id ? update() : add()
}
})
}
// 删除
const handleDelete = (id) => {
ElMessageBox.confirm('删除后数据无法恢复,您确定删除吗?', '删除确认', { type: 'warning' }).then(res => {
request.delete('/recharge/delete/' + id).then(res => {
if (res.code === '200') {
load()
ElMessage.success('操作成功')
} else {
ElMessage.error(res.msg)
}
})
}).catch(err => {})
}
// 重置
const reset = () => {
data.userName = null
load()
}
</script>
用户充值管理页面 UserRecharge.vue
<template>
<div class="front-container">
<div style="font-size: 20px; font-weight: bold; margin-bottom: 20px">我的充值记录({{ data.total }})</div>
<div class="card" style="padding: 20px">
<div style="margin-bottom: 20px; display: flex; align-items: center">
<div style="flex: 1">
<el-date-picker style="width: 300px; margin-right: 10px" v-model="data.time" type="date" placeholder="请输入日期查询" format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
<el-button type="primary" @click="load">查询</el-button>
<el-button type="info" style="margin: 0 10px" @click="reset">重置</el-button>
</div>
<b style="margin-left: 20px; color: red">当前账户余额:{{ data.user.account }}元</b>
<el-button @click="handleAdd" type="primary" style="margin-left: 20px">发起充值</el-button>
</div>
<div>
<el-table :data="data.tableData" stripe>
<el-table-column prop="money" label="充值金额">
<template #default="scope">
<b style="color: red">{{ scope.row.money }}元</b>
</template>
</el-table-column>
<el-table-column prop="type" label="支付方式"></el-table-column>
<el-table-column prop="time" label="充值时间"></el-table-column>
</el-table>
</div>
<div style="margin-top: 20px">
<el-pagination @current-change="load" layout="total, prev, pager, next" v-model:page-size="data.pageSize" v-model:current-page="data.pageNum" :total="data.total"/>
</div>
</div>
<el-dialog title="用户充值" width="30%" v-model="data.formVisible" :close-on-click-modal="false" destroy-on-close>
<el-form ref="formRef" :model="data.form" :rules="data.rules" label-width="80px" style="padding-right: 30px; padding-top: 20px">
<el-form-item label="充值金额" prop="money">
<el-input-number style="width: 200px" :min="1" v-model="data.form.money" autocomplete="off" />
</el-form-item>
<el-form-item label="支付方式" prop="type" style="margin-top: 30px">
<el-radio-group v-model="data.form.type">
<el-radio value="微信支付"><img style="width: 100px; height: 40px" src="@/assets/imgs/wx.png" alt=""></el-radio>
<el-radio value="支付宝"><img style="width: 100px; height: 40px" src="@/assets/imgs/zfb.png" alt=""></el-radio>
</el-radio-group>
</el-form-item>
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button @click="data.formVisible = false">取 消</el-button>
<el-button type="primary" @click="save">保 存</el-button>
</span>
</template>
</el-dialog>
</div>
</template>
<script setup>
import request from "@/utils/request";
import {reactive, ref} from "vue";
import {ElMessageBox, ElMessage} from "element-plus";
const formRef = ref()
const data = reactive({
user: JSON.parse(localStorage.getItem('system-user') || '{}'),
pageNum: 1,
pageSize: 10,
total: 0,
formVisible: false,
form: {},
tableData: [],
time: null,
rules: {
money: [
{ required: true, message: '请输入金额', trigger: 'blur' }
],
type: [
{ required: true, message: '请选择支付方式', trigger: 'change' }
]
}
})
const loadAccount = () => {
request.get('/user/selectById/' + data.user.id).then(res => {
data.user.account = res.data.account
})
}
loadAccount()
// 分页查询
const load = () => {
request.get('/recharge/selectPage', {
params: {
pageNum: data.pageNum,
pageSize: data.pageSize,
userId: data.user.id,
time: data.time
}
}).then(res => {
data.tableData = res.data?.list
data.total = res.data?.total
})
}
load()
// 新增
const handleAdd = () => {
data.form = { money: 1, type: '微信支付' }
data.formVisible = true
}
// 编辑
const handleEdit = (row) => {
data.form = JSON.parse(JSON.stringify(row))
data.formVisible = true
}
// 新增保存
const add = () => {
data.form.userId = data.user.id
request.post('/recharge/add', data.form).then(res => {
if (res.code === '200') {
load()
loadAccount()
ElMessage.success('操作成功')
data.formVisible = false
} else {
ElMessage.error(res.msg)
}
})
}
// 编辑保存
const update = () => {
request.put('/recharge/update', data.form).then(res => {
if (res.code === '200') {
load()
ElMessage.success('操作成功')
data.formVisible = false
} else {
ElMessage.error(res.msg)
}
})
}
// 弹窗保存
const save = () => {
formRef.value.validate(valid => {
if (valid) {
// data.form有id就是更新,没有就是新增
data.form.id ? update() : add()
}
})
}
// 删除
const handleDelete = (id) => {
ElMessageBox.confirm('删除后数据无法恢复,您确定删除吗?', '删除确认', { type: 'warning' }).then(res => {
request.delete('/recharge/delete/' + id).then(res => {
if (res.code === '200') {
load()
ElMessage.success('操作成功')
} else {
ElMessage.error(res.msg)
}
})
}).catch(err => {})
}
// 重置
const reset = () => {
data.userName = null
load()
}
</script>