逻辑修改
This commit is contained in:
parent
d341e859dc
commit
16402987ca
|
|
@ -38,6 +38,10 @@
|
|||
<el-icon><User /></el-icon>
|
||||
<template #title>跑腿管理</template>
|
||||
</el-menu-item>
|
||||
<el-menu-item index="/users">
|
||||
<el-icon><UserFilled /></el-icon>
|
||||
<template #title>用户管理</template>
|
||||
</el-menu-item>
|
||||
<el-menu-item index="/reviews">
|
||||
<el-icon><Star /></el-icon>
|
||||
<template #title>评价管理</template>
|
||||
|
|
@ -95,7 +99,7 @@
|
|||
import { ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { ElMessageBox } from 'element-plus'
|
||||
import { Monitor, Fold, Expand, ArrowDown, Picture, Grid, Shop, Stamp, User, Star, Bell, List, Setting, Money } from '@element-plus/icons-vue'
|
||||
import { Monitor, Fold, Expand, ArrowDown, Picture, Grid, Shop, Stamp, User, UserFilled, Star, Bell, List, Setting, Money } from '@element-plus/icons-vue'
|
||||
|
||||
const router = useRouter()
|
||||
const isCollapse = ref(false)
|
||||
|
|
|
|||
|
|
@ -54,6 +54,12 @@ const routes = [
|
|||
component: () => import('../views/Runners.vue'),
|
||||
meta: { title: '跑腿管理' }
|
||||
},
|
||||
{
|
||||
path: 'users',
|
||||
name: 'Users',
|
||||
component: () => import('../views/Users.vue'),
|
||||
meta: { title: '用户管理' }
|
||||
},
|
||||
{
|
||||
path: 'reviews',
|
||||
name: 'Reviews',
|
||||
|
|
|
|||
|
|
@ -5,6 +5,22 @@
|
|||
<el-tabs v-model="activeTab">
|
||||
<!-- 佣金规则 -->
|
||||
<el-tab-pane label="佣金规则" name="commission">
|
||||
<el-alert
|
||||
type="info"
|
||||
:closable="false"
|
||||
show-icon
|
||||
style="margin-bottom: 16px;"
|
||||
>
|
||||
<template #title>
|
||||
<span>佣金规则说明</span>
|
||||
</template>
|
||||
<div style="line-height: 1.8; font-size: 13px;">
|
||||
根据跑腿佣金金额匹配对应区间,计算平台抽成。最高金额留空或为0表示无上限。<br/>
|
||||
· 百分比类型:抽成值填百分比数值,如填 <b>10</b> 表示抽成 <b>10%</b>(1元佣金抽0.1元)<br/>
|
||||
· 固定金额类型:抽成值填固定金额,如填 <b>2</b> 表示固定抽 <b>2元</b>(不超过佣金本身)<br/>
|
||||
· 跑腿实得 = 跑腿佣金 - 平台抽成
|
||||
</div>
|
||||
</el-alert>
|
||||
<div style="margin-bottom: 12px;">
|
||||
<el-button type="primary" size="small" @click="addRule">添加区间</el-button>
|
||||
</div>
|
||||
|
|
|
|||
139
admin/src/views/Users.vue
Normal file
139
admin/src/views/Users.vue
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
<template>
|
||||
<div class="users-page">
|
||||
<div class="page-header">
|
||||
<h2>用户管理</h2>
|
||||
<div class="header-actions">
|
||||
<el-input
|
||||
v-model="keyword"
|
||||
placeholder="搜索昵称/手机号/ID"
|
||||
clearable
|
||||
style="width: 240px"
|
||||
@keyup.enter="fetchList"
|
||||
@clear="fetchList"
|
||||
>
|
||||
<template #append>
|
||||
<el-button @click="fetchList" :icon="Search" />
|
||||
</template>
|
||||
</el-input>
|
||||
<el-tag type="info" size="large" style="margin-left: 12px">共 {{ list.length }} 名用户</el-tag>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<el-table :data="list" v-loading="loading" stripe style="width: 100%">
|
||||
<el-table-column prop="id" label="ID" width="80" align="center" />
|
||||
<el-table-column label="头像" width="70" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-avatar :size="36" :src="row.avatarUrl" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="nickname" label="昵称" min-width="120" show-overflow-tooltip />
|
||||
<el-table-column prop="phone" label="手机号" min-width="130">
|
||||
<template #default="{ row }">{{ row.phone || '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="角色" width="100" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="getRoleType(row.role)" size="small" round>{{ getRoleLabel(row.role) }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="下单数" width="90" align="center" prop="orderCount" />
|
||||
<el-table-column label="状态" width="90" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.isBanned ? 'danger' : 'success'" round size="small">
|
||||
{{ row.isBanned ? '已封禁' : '正常' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="注册时间" min-width="170">
|
||||
<template #default="{ row }">{{ formatTime(row.createdAt) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="120" fixed="right" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-popconfirm
|
||||
v-if="!row.isBanned"
|
||||
title="确定封禁该用户?"
|
||||
confirm-button-text="封禁"
|
||||
confirm-button-type="danger"
|
||||
@confirm="toggleBan(row, true)"
|
||||
>
|
||||
<template #reference>
|
||||
<el-button size="small" type="danger" plain>封禁</el-button>
|
||||
</template>
|
||||
</el-popconfirm>
|
||||
<el-popconfirm
|
||||
v-else
|
||||
title="确定解封该用户?"
|
||||
confirm-button-text="解封"
|
||||
@confirm="toggleBan(row, false)"
|
||||
>
|
||||
<template #reference>
|
||||
<el-button size="small" type="success" plain>解封</el-button>
|
||||
</template>
|
||||
</el-popconfirm>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { Search } from '@element-plus/icons-vue'
|
||||
import request from '../utils/request'
|
||||
|
||||
const loading = ref(false)
|
||||
const list = ref([])
|
||||
const keyword = ref('')
|
||||
|
||||
async function fetchList() {
|
||||
loading.value = true
|
||||
try {
|
||||
const params = keyword.value ? { keyword: keyword.value } : {}
|
||||
list.value = await request.get('/admin/users', { params })
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function toggleBan(row, isBanned) {
|
||||
const label = isBanned ? '封禁' : '解封'
|
||||
await request.put(`/admin/users/${row.id}/ban`, { isBanned })
|
||||
ElMessage.success(`已${label}`)
|
||||
fetchList()
|
||||
}
|
||||
|
||||
function getRoleLabel(role) {
|
||||
const map = { User: '普通用户', Admin: '管理员' }
|
||||
return map[role] || role
|
||||
}
|
||||
|
||||
function getRoleType(role) {
|
||||
return role === 'Admin' ? 'warning' : ''
|
||||
}
|
||||
|
||||
function formatTime(str) {
|
||||
if (!str) return '-'
|
||||
const d = new Date(str)
|
||||
const pad = n => String(n).padStart(2, '0')
|
||||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`
|
||||
}
|
||||
|
||||
onMounted(fetchList)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.page-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.page-header h2 {
|
||||
margin: 0;
|
||||
font-size: 20px;
|
||||
}
|
||||
.header-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -101,8 +101,20 @@ export default {
|
|||
const sysInfo = uni.getSystemInfoSync()
|
||||
this.statusBarHeight = sysInfo.statusBarHeight || 0
|
||||
this.loadBanner()
|
||||
this.restoreFormData()
|
||||
},
|
||||
methods: {
|
||||
/** 恢复登录前保存的表单数据 */
|
||||
restoreFormData() {
|
||||
const saved = uni.getStorageSync('loginFormData')
|
||||
if (saved) {
|
||||
try {
|
||||
const data = JSON.parse(saved)
|
||||
Object.assign(this.form, data)
|
||||
} catch (e) {}
|
||||
uni.removeStorageSync('loginFormData')
|
||||
}
|
||||
},
|
||||
goBack() { uni.navigateBack() },
|
||||
async loadBanner() {
|
||||
try {
|
||||
|
|
@ -137,12 +149,18 @@ export default {
|
|||
if (!this.form.phone.trim()) {
|
||||
uni.showToast({ title: '请输入手机号', icon: 'none' }); return false
|
||||
}
|
||||
if (!/^1\d{10}$/.test(this.form.phone.trim())) {
|
||||
uni.showToast({ title: '请输入正确的11位手机号', icon: 'none' }); return false
|
||||
}
|
||||
return this.validateCommission()
|
||||
},
|
||||
async onSubmit() {
|
||||
if (!this.validateForm()) return
|
||||
const token = uni.getStorageSync('token')
|
||||
if (!token) {
|
||||
// 保存表单数据,登录后恢复
|
||||
uni.setStorageSync('loginFormData', JSON.stringify(this.form))
|
||||
uni.setStorageSync('loginRedirect', '/pages/delivery/delivery')
|
||||
uni.navigateTo({ url: '/pages/login/login' }); return
|
||||
}
|
||||
this.submitting = true
|
||||
|
|
|
|||
|
|
@ -142,6 +142,10 @@ export default {
|
|||
uni.showToast({ title: '请输入手机号', icon: 'none' })
|
||||
return false
|
||||
}
|
||||
if (!/^1\d{10}$/.test(this.form.phone.trim())) {
|
||||
uni.showToast({ title: '请输入正确的11位手机号', icon: 'none' })
|
||||
return false
|
||||
}
|
||||
return this.validateCommission()
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -99,8 +99,20 @@
|
|||
const sysInfo = uni.getSystemInfoSync()
|
||||
this.statusBarHeight = sysInfo.statusBarHeight || 0
|
||||
this.loadBanner()
|
||||
this.restoreFormData()
|
||||
},
|
||||
methods: {
|
||||
/** 恢复登录前保存的表单数据 */
|
||||
restoreFormData() {
|
||||
const saved = uni.getStorageSync('loginFormData')
|
||||
if (saved) {
|
||||
try {
|
||||
const data = JSON.parse(saved)
|
||||
Object.assign(this.form, data)
|
||||
} catch (e) {}
|
||||
uni.removeStorageSync('loginFormData')
|
||||
}
|
||||
},
|
||||
goBack() {
|
||||
uni.navigateBack()
|
||||
},
|
||||
|
|
@ -153,6 +165,13 @@
|
|||
})
|
||||
return false
|
||||
}
|
||||
if (!/^1\d{10}$/.test(this.form.phone.trim())) {
|
||||
uni.showToast({
|
||||
title: '请输入正确的11位手机号',
|
||||
icon: 'none'
|
||||
})
|
||||
return false
|
||||
}
|
||||
if (!this.form.goodsAmount) {
|
||||
uni.showToast({
|
||||
title: '请输入商品总金额',
|
||||
|
|
@ -177,6 +196,9 @@
|
|||
// 未登录跳转登录页
|
||||
const token = uni.getStorageSync('token')
|
||||
if (!token) {
|
||||
// 保存表单数据,登录后恢复
|
||||
uni.setStorageSync('loginFormData', JSON.stringify(this.form))
|
||||
uni.setStorageSync('loginRedirect', '/pages/help/help')
|
||||
uni.navigateTo({
|
||||
url: '/pages/login/login'
|
||||
})
|
||||
|
|
|
|||
|
|
@ -88,7 +88,14 @@ async function onWxLogin() {
|
|||
if (res.token && res.userInfo) {
|
||||
userStore.setLoginInfo(res.token, res.userInfo)
|
||||
uni.showToast({ title: '登录成功', icon: 'success' })
|
||||
uni.reLaunch({ url: '/pages/index/index' })
|
||||
// 检查是否有登录前的回跳页面
|
||||
const redirect = uni.getStorageSync('loginRedirect')
|
||||
if (redirect) {
|
||||
uni.removeStorageSync('loginRedirect')
|
||||
uni.navigateTo({ url: redirect })
|
||||
} else {
|
||||
uni.reLaunch({ url: '/pages/index/index' })
|
||||
}
|
||||
} else {
|
||||
tipText.value = '登录失败,请重试'
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -11,7 +11,10 @@
|
|||
<!-- 用户信息卡片 -->
|
||||
<view class="user-card" @click="onUserClick">
|
||||
<image class="user-avatar" :src="userInfo.avatarUrl || '/static/logo.png'" mode="aspectFill"></image>
|
||||
<text class="user-name">{{ isLoggedIn ? (userInfo.nickname || '用户') : '点击注册/登录' }}</text>
|
||||
<view class="user-info">
|
||||
<text class="user-name">{{ isLoggedIn ? (userInfo.nickname || '用户') : '点击注册/登录' }}</text>
|
||||
<text class="user-uid" v-if="isLoggedIn">UID:{{ userInfo.id }}</text>
|
||||
</view>
|
||||
<image class="arrow-icon" src="/static/ic_arrow.png" mode="aspectFit"></image>
|
||||
</view>
|
||||
|
||||
|
|
@ -216,13 +219,24 @@ export default {
|
|||
background-color: #f0f0f0;
|
||||
}
|
||||
|
||||
.user-name {
|
||||
.user-info {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.user-name {
|
||||
font-size: 32rpx;
|
||||
color: #333;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.user-uid {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
margin-top: 6rpx;
|
||||
}
|
||||
|
||||
.arrow-icon {
|
||||
width: 32rpx;
|
||||
height: 32rpx;
|
||||
|
|
|
|||
|
|
@ -296,6 +296,12 @@
|
|||
},
|
||||
/** 点击接单 */
|
||||
async onAcceptClick(order) {
|
||||
// 未登录跳转登录页
|
||||
const token = uni.getStorageSync('token')
|
||||
if (!token) {
|
||||
uni.navigateTo({ url: '/pages/login/login' })
|
||||
return
|
||||
}
|
||||
try {
|
||||
if (this.certStatus === null) {
|
||||
const res = await getCertificationStatus()
|
||||
|
|
|
|||
|
|
@ -50,6 +50,11 @@
|
|||
<text class="info-value">{{ order.remark }}</text>
|
||||
</view>
|
||||
|
||||
<view class="info-row" v-if="order.phone">
|
||||
<text class="info-label">联系方式</text>
|
||||
<text class="info-value">{{ order.phone }}</text>
|
||||
</view>
|
||||
|
||||
<view class="info-row" v-if="order.goodsAmount">
|
||||
<text class="info-label">商品金额</text>
|
||||
<text class="info-value price">¥{{ order.goodsAmount }}</text>
|
||||
|
|
@ -60,6 +65,16 @@
|
|||
<text class="info-value price">¥{{ order.commission }}</text>
|
||||
</view>
|
||||
|
||||
<view class="info-row" v-if="order.platformFee != null">
|
||||
<text class="info-label">平台抽成</text>
|
||||
<text class="info-value">-¥{{ order.platformFee }}</text>
|
||||
</view>
|
||||
|
||||
<view class="info-row" v-if="order.netEarning != null">
|
||||
<text class="info-label">跑腿实得</text>
|
||||
<text class="info-value highlight">¥{{ order.netEarning }}</text>
|
||||
</view>
|
||||
|
||||
<view class="info-row">
|
||||
<text class="info-label">支付总额</text>
|
||||
<text class="info-value price">¥{{ order.totalAmount }}</text>
|
||||
|
|
@ -536,6 +551,11 @@ export default {
|
|||
font-weight: bold;
|
||||
}
|
||||
|
||||
.info-value.highlight {
|
||||
color: #52c41a;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* 完成凭证 */
|
||||
.proof-image {
|
||||
width: 100%;
|
||||
|
|
|
|||
|
|
@ -101,8 +101,20 @@ export default {
|
|||
const sysInfo = uni.getSystemInfoSync()
|
||||
this.statusBarHeight = sysInfo.statusBarHeight || 0
|
||||
this.loadBanner()
|
||||
this.restoreFormData()
|
||||
},
|
||||
methods: {
|
||||
/** 恢复登录前保存的表单数据 */
|
||||
restoreFormData() {
|
||||
const saved = uni.getStorageSync('loginFormData')
|
||||
if (saved) {
|
||||
try {
|
||||
const data = JSON.parse(saved)
|
||||
Object.assign(this.form, data)
|
||||
} catch (e) {}
|
||||
uni.removeStorageSync('loginFormData')
|
||||
}
|
||||
},
|
||||
goBack() { uni.navigateBack() },
|
||||
async loadBanner() {
|
||||
try {
|
||||
|
|
@ -140,6 +152,9 @@ export default {
|
|||
if (!this.form.phone.trim()) {
|
||||
uni.showToast({ title: '请输入手机号', icon: 'none' }); return false
|
||||
}
|
||||
if (!/^1\d{10}$/.test(this.form.phone.trim())) {
|
||||
uni.showToast({ title: '请输入正确的11位手机号', icon: 'none' }); return false
|
||||
}
|
||||
return this.validateCommission()
|
||||
},
|
||||
async onSubmit() {
|
||||
|
|
@ -148,6 +163,9 @@ export default {
|
|||
// 未登录跳转登录页
|
||||
const token = uni.getStorageSync('token')
|
||||
if (!token) {
|
||||
// 保存表单数据,登录后恢复
|
||||
uni.setStorageSync('loginFormData', JSON.stringify(this.form))
|
||||
uni.setStorageSync('loginRedirect', '/pages/pickup/pickup')
|
||||
uni.navigateTo({ url: '/pages/login/login' })
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,8 +114,20 @@
|
|||
const sysInfo = uni.getSystemInfoSync()
|
||||
this.statusBarHeight = sysInfo.statusBarHeight || 0
|
||||
this.loadBanner()
|
||||
this.restoreFormData()
|
||||
},
|
||||
methods: {
|
||||
/** 恢复登录前保存的表单数据 */
|
||||
restoreFormData() {
|
||||
const saved = uni.getStorageSync('loginFormData')
|
||||
if (saved) {
|
||||
try {
|
||||
const data = JSON.parse(saved)
|
||||
Object.assign(this.form, data)
|
||||
} catch (e) {}
|
||||
uni.removeStorageSync('loginFormData')
|
||||
}
|
||||
},
|
||||
goBack() {
|
||||
uni.navigateBack()
|
||||
},
|
||||
|
|
@ -180,6 +192,13 @@
|
|||
});
|
||||
return false
|
||||
}
|
||||
if (!/^1\d{10}$/.test(this.form.phone.trim())) {
|
||||
uni.showToast({
|
||||
title: '请输入正确的11位手机号',
|
||||
icon: 'none'
|
||||
});
|
||||
return false
|
||||
}
|
||||
if (!this.form.goodsAmount) {
|
||||
uni.showToast({
|
||||
title: '请输入商品总金额',
|
||||
|
|
@ -201,6 +220,9 @@
|
|||
if (!this.validateForm()) return
|
||||
const token = uni.getStorageSync('token')
|
||||
if (!token) {
|
||||
// 保存表单数据,登录后恢复
|
||||
uni.setStorageSync('loginFormData', JSON.stringify(this.form))
|
||||
uni.setStorageSync('loginRedirect', '/pages/purchase/purchase')
|
||||
uni.navigateTo({
|
||||
url: '/pages/login/login'
|
||||
});
|
||||
|
|
|
|||
BIN
miniapp/static/ic_commodity.png
Normal file
BIN
miniapp/static/ic_commodity.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
BIN
miniapp/static/ic_complete.png
Normal file
BIN
miniapp/static/ic_complete.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
BIN
miniapp/static/ic_errand.png
Normal file
BIN
miniapp/static/ic_errand.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.6 KiB |
BIN
miniapp/static/ic_picture.png
Normal file
BIN
miniapp/static/ic_picture.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 3.9 KiB After Width: | Height: | Size: 392 KiB |
|
|
@ -88,6 +88,11 @@ export function getOrderDetail(id) {
|
|||
return request({ url: `/api/orders/${id}` })
|
||||
}
|
||||
|
||||
/** 根据聊天对方用户ID查找关联订单 */
|
||||
export function getOrderByChatUser(targetUserId) {
|
||||
return request({ url: `/api/orders/by-chat-user/${targetUserId}` })
|
||||
}
|
||||
|
||||
// ==================== 美食街 ====================
|
||||
|
||||
/** 获取门店列表 */
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
// API 基础地址,按环境切换
|
||||
const BASE_URL = 'http://localhost:5099'
|
||||
// const BASE_URL = 'http://api.zwz.shhmkjgs.cn'
|
||||
|
||||
/**
|
||||
* 获取本地存储的 token
|
||||
|
|
|
|||
|
|
@ -85,6 +85,10 @@ public class OrderResponse
|
|||
public int? RunnerUid { get; set; }
|
||||
/// <summary>跑腿手机号(认证时填写的手机号,仅单主可见)</summary>
|
||||
public string? RunnerPhone { get; set; }
|
||||
/// <summary>平台抽成(订单完成后可见)</summary>
|
||||
public decimal? PlatformFee { get; set; }
|
||||
/// <summary>跑腿实得佣金(订单完成后可见)</summary>
|
||||
public decimal? NetEarning { get; set; }
|
||||
public List<FoodOrderItemResponse>? FoodItems { get; set; }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -671,6 +671,31 @@ app.MapPost("/api/orders", async (CreateOrderRequest request, HttpContext httpCo
|
|||
});
|
||||
}).RequireAuthorization();
|
||||
|
||||
// 根据对方用户ID查找最近的关联订单(用于聊天页显示订单卡片)
|
||||
app.MapGet("/api/orders/by-chat-user/{targetUserId}", async (int targetUserId, HttpContext httpContext, AppDbContext db) =>
|
||||
{
|
||||
var userIdClaim = httpContext.User.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier);
|
||||
if (userIdClaim == null) return Results.Unauthorized();
|
||||
var currentUserId = int.Parse(userIdClaim.Value);
|
||||
|
||||
// 查找当前用户与目标用户之间最近的订单(当前用户是单主对方是跑腿,或反过来)
|
||||
var order = await db.Orders
|
||||
.Where(o =>
|
||||
(o.OwnerId == currentUserId && o.RunnerId == targetUserId) ||
|
||||
(o.OwnerId == targetUserId && o.RunnerId == currentUserId))
|
||||
.OrderByDescending(o => o.CreatedAt)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (order == null)
|
||||
return Results.Ok(new { found = false });
|
||||
|
||||
return Results.Ok(new
|
||||
{
|
||||
found = true,
|
||||
orderId = order.Id
|
||||
});
|
||||
}).RequireAuthorization();
|
||||
|
||||
// 获取订单详情(含手机号隐藏逻辑和按状态显示字段)
|
||||
app.MapGet("/api/orders/{id}", async (int id, HttpContext httpContext, AppDbContext db) =>
|
||||
{
|
||||
|
|
@ -765,6 +790,27 @@ app.MapGet("/api/orders/{id}", async (int id, HttpContext httpContext, AppDbCont
|
|||
RunnerPhone = runnerPhone
|
||||
};
|
||||
|
||||
// 查询佣金抽成信息(有 Earning 记录用实际值,否则实时计算预估值)
|
||||
if (order.RunnerId.HasValue)
|
||||
{
|
||||
var earning = await db.Earnings
|
||||
.Where(e => e.OrderId == order.Id)
|
||||
.FirstOrDefaultAsync();
|
||||
if (earning != null)
|
||||
{
|
||||
response.PlatformFee = earning.PlatformFee;
|
||||
response.NetEarning = earning.NetEarning;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 未完成订单:实时计算预估抽成
|
||||
var rules = await db.CommissionRules.OrderBy(r => r.MinAmount).ToListAsync();
|
||||
var fee = CalculatePlatformFee(order.Commission, rules);
|
||||
response.PlatformFee = fee;
|
||||
response.NetEarning = order.Commission - fee;
|
||||
}
|
||||
}
|
||||
|
||||
// 美食街订单附带菜品详情
|
||||
if (order.OrderType == OrderType.Food && order.FoodOrderItems.Count > 0)
|
||||
{
|
||||
|
|
@ -864,9 +910,7 @@ app.MapGet("/api/orders/hall", async (
|
|||
}).ToList();
|
||||
|
||||
return Results.Ok(result);
|
||||
}).RequireAuthorization();
|
||||
|
||||
// 接取订单
|
||||
}).AllowAnonymous();
|
||||
app.MapPost("/api/orders/{id}/accept", async (int id, HttpContext httpContext, AppDbContext db) =>
|
||||
{
|
||||
// 获取当前用户
|
||||
|
|
@ -2488,6 +2532,59 @@ app.MapPost("/api/admin/notifications", async (CreateNotificationRequest request
|
|||
});
|
||||
}).RequireAuthorization("AdminOnly");
|
||||
|
||||
// ========== 用户管理接口 ==========
|
||||
|
||||
// 管理端获取用户列表
|
||||
app.MapGet("/api/admin/users", async (string? keyword, AppDbContext db) =>
|
||||
{
|
||||
var query = db.Users.AsQueryable();
|
||||
|
||||
// 关键词搜索(昵称、手机号、ID)
|
||||
if (!string.IsNullOrWhiteSpace(keyword))
|
||||
{
|
||||
var kw = keyword.Trim();
|
||||
if (int.TryParse(kw, out var uid))
|
||||
{
|
||||
query = query.Where(u => u.Id == uid || u.Nickname.Contains(kw) || u.Phone.Contains(kw));
|
||||
}
|
||||
else
|
||||
{
|
||||
query = query.Where(u => u.Nickname.Contains(kw) || u.Phone.Contains(kw));
|
||||
}
|
||||
}
|
||||
|
||||
var users = await query.OrderByDescending(u => u.CreatedAt)
|
||||
.Select(u => new
|
||||
{
|
||||
u.Id,
|
||||
u.Nickname,
|
||||
u.AvatarUrl,
|
||||
u.Phone,
|
||||
Role = u.Role.ToString(),
|
||||
u.RunnerScore,
|
||||
u.IsBanned,
|
||||
u.CreatedAt,
|
||||
// 查询该用户的订单数
|
||||
OrderCount = db.Orders.Count(o => o.OwnerId == u.Id)
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
return Results.Ok(users);
|
||||
}).RequireAuthorization("AdminOnly");
|
||||
|
||||
// 管理端封禁/解封用户
|
||||
app.MapPut("/api/admin/users/{id}/ban", async (int id, BanRunnerRequest request, AppDbContext db) =>
|
||||
{
|
||||
var user = await db.Users.FindAsync(id);
|
||||
if (user == null)
|
||||
return Results.NotFound(new { code = 404, message = "用户不存在" });
|
||||
|
||||
user.IsBanned = request.IsBanned;
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
return Results.Ok(new { user.Id, user.IsBanned });
|
||||
}).RequireAuthorization("AdminOnly");
|
||||
|
||||
// ========== 跑腿管理接口 ==========
|
||||
|
||||
// 管理端获取跑腿列表
|
||||
|
|
@ -2884,6 +2981,20 @@ using (var scope = app.Services.CreateScope())
|
|||
{
|
||||
db.Database.Migrate();
|
||||
}
|
||||
|
||||
// 初始化默认佣金规则(如果为空)
|
||||
if (!db.CommissionRules.Any())
|
||||
{
|
||||
db.CommissionRules.Add(new CommissionRule
|
||||
{
|
||||
MinAmount = 0m,
|
||||
MaxAmount = null,
|
||||
RateType = CommissionRateType.Percentage,
|
||||
Rate = 10m // 默认抽成 10%
|
||||
});
|
||||
db.SaveChanges();
|
||||
Console.WriteLine("[初始化] 已创建默认佣金规则:10% 抽成");
|
||||
}
|
||||
}
|
||||
|
||||
// 注册后台定时任务:每10分钟执行一次自动确认和解冻
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user