add clear unpaid order functions

This commit is contained in:
RockYang 2024-08-07 18:00:28 +08:00
parent c9d0700fd9
commit 7a11a9ef15
4 changed files with 34 additions and 3 deletions

View File

@ -6,6 +6,7 @@
* Bug修复修复后台拖动排序组件 Bug * Bug修复修复后台拖动排序组件 Bug
* 功能优化:更新数据库失败时候显示具体的的报错信息 * 功能优化:更新数据库失败时候显示具体的的报错信息
* Bug修复修复管理后台对话详情页内容显示异常问题 * Bug修复修复管理后台对话详情页内容显示异常问题
* 功能优化:管理后台新增清空所有未支付订单的功能
## v4.1.1 ## v4.1.1
* Bug修复修复 GPT 模型 function call 调用后没有输出的问题 * Bug修复修复 GPT 模型 function call 调用后没有输出的问题

View File

@ -93,10 +93,20 @@ func (h *OrderHandler) Remove(c *gin.Context) {
} }
err := h.DB.Unscoped().Where("id = ?", id).Delete(&model.Order{}).Error err := h.DB.Unscoped().Where("id = ?", id).Delete(&model.Order{}).Error
if res.Error != nil { if err != nil {
resp.ERROR(c, err.Error()) resp.ERROR(c, err.Error())
return return
} }
} }
resp.SUCCESS(c) resp.SUCCESS(c)
} }
func (h *OrderHandler) Clear(c *gin.Context) {
err := h.DB.Unscoped().Where("status <> ?", 2).Where("pay_time", 0).Delete(&model.Order{}).Error
if err != nil {
resp.ERROR(c, err.Error())
return
}
resp.SUCCESS(c)
}

View File

@ -392,6 +392,7 @@ func main() {
group := s.Engine.Group("/api/admin/order/") group := s.Engine.Group("/api/admin/order/")
group.POST("list", h.List) group.POST("list", h.List)
group.GET("remove", h.Remove) group.GET("remove", h.Remove)
group.GET("clear", h.Clear)
}), }),
fx.Invoke(func(s *core.AppServer, h *handler.OrderHandler) { fx.Invoke(func(s *core.AppServer, h *handler.OrderHandler) {
group := s.Engine.Group("/api/order/") group := s.Engine.Group("/api/order/")

View File

@ -20,6 +20,7 @@
style="margin: 0 10px;width: 200px; position: relative;top:3px;" style="margin: 0 10px;width: 200px; position: relative;top:3px;"
/> />
<el-button type="primary" :icon="Search" @click="fetchData">搜索</el-button> <el-button type="primary" :icon="Search" @click="fetchData">搜索</el-button>
<el-button type="danger" :icon="Delete" @click="clearOrders">清空未支付订单</el-button>
</div> </div>
<el-row> <el-row>
@ -76,9 +77,9 @@
<script setup> <script setup>
import {onMounted, ref} from "vue"; import {onMounted, ref} from "vue";
import {httpGet, httpPost} from "@/utils/http"; import {httpGet, httpPost} from "@/utils/http";
import {ElMessage} from "element-plus"; import {ElMessage, ElMessageBox} from "element-plus";
import {dateFormat, removeArrayItem} from "@/utils/libs"; import {dateFormat, removeArrayItem} from "@/utils/libs";
import {Search} from "@element-plus/icons-vue"; import {Delete, Search} from "@element-plus/icons-vue";
// //
const items = ref([]) const items = ref([])
@ -123,6 +124,24 @@ const remove = function (row) {
ElMessage.error("删除失败:" + e.message) ElMessage.error("删除失败:" + e.message)
}) })
} }
const clearOrders = () => {
ElMessageBox.confirm(
'此操作将会删除所有未支付订单,继续操作吗?',
'删除提示',
{
confirmButtonText: '确认',
cancelButtonText: '取消',
type: 'warning',
}
).then(() => {
httpGet("/api/admin/order/clear").then(() => {
ElMessage.success("订单删除成功")
page.value = 0
fetchData()
})
})
}
</script> </script>
<style lang="stylus" scoped> <style lang="stylus" scoped>