feat(lbs): 真实距离与按距离派单落地
- 数据库:orders/activities 新增 latitude/longitude(含存量表 ALTER 迁移) - 服务端:Haversine 计算 distanceKm/distanceText,派单池支持 lat/lng/radius 过滤并按距离升序;历史无坐标订单用腾讯地理编码兜底并回写缓存 - 新增 /api/lbs/reverse 逆地址解析(Key 仅服务端持有,登录 + 限流) - 小程序:雷达/接单大厅改用真实定位与真实距离,删除全部写死演示距离;下单页新增地图选点,组局页保存选点经纬度 - 修复接单大厅点接单会新建订单的问题,改为真正 claimOrder 认领 - 新增 lbs-distance 护栏(110 套件/729 用例全绿)
这个提交包含在:
@@ -58,6 +58,10 @@
|
||||
|
||||
<!-- 派单池订单列表 -->
|
||||
<view class="dispatch-list">
|
||||
<view v-if="filteredOrders.length === 0" class="hall-empty">
|
||||
<text class="hall-empty-title">暂无待接需求单</text>
|
||||
<text class="hall-empty-desc">开启定位并稍后刷新,附近新单会优先推给你</text>
|
||||
</view>
|
||||
<view
|
||||
v-for="order in filteredOrders"
|
||||
:key="order.id"
|
||||
@@ -227,7 +231,8 @@ import AppTabBar from '@/components/CustomTabBar.vue';
|
||||
import { ICONS } from '@/common/icons.js';
|
||||
import { getCurrentThemeKey, applyThemeToNativeUI } from '@/common/theme.js';
|
||||
import { isExpertCertified } from '@/common/role.js';
|
||||
import { createOrder, getOrdersPool, getExpertStats, claimOrder, updateCompanionProfile, getUserProfile } from '@/common/api.js';
|
||||
import { claimOrder, getOrdersPool, getExpertStats, updateCompanionProfile, getUserProfile } from '@/common/api.js';
|
||||
import { getUserLocation } from '@/common/location.js';
|
||||
import { getNavBarInfo } from '@/common/nav.js';
|
||||
|
||||
const currentThemeKey = ref(getCurrentThemeKey());
|
||||
@@ -289,6 +294,13 @@ const loadHallData = async () => {
|
||||
isOnline.value = uni.getStorageSync('EXPERT_RECEIVING_STATUS') !== '0';
|
||||
|
||||
// 2. 并行动态读取最新资料、经营数据与派单池
|
||||
let myCoords = { lat: null, lng: null };
|
||||
try {
|
||||
const pos = await getUserLocation();
|
||||
myCoords = { lat: pos.latitude, lng: pos.longitude };
|
||||
} catch (_) {
|
||||
// 未授权定位:距离显示「同城」,不影响大厅浏览
|
||||
}
|
||||
try {
|
||||
await Promise.allSettled([
|
||||
getUserProfile(uid).then((profile) => {
|
||||
@@ -317,8 +329,8 @@ const loadHallData = async () => {
|
||||
}
|
||||
}).catch(() => {}),
|
||||
|
||||
getOrdersPool().then((pool) => {
|
||||
if (pool && pool.length > 0) {
|
||||
getOrdersPool(myCoords).then((pool) => {
|
||||
if (Array.isArray(pool)) {
|
||||
orders.value = pool.map(p => {
|
||||
let typeClass = 'cat-food';
|
||||
if (p.category.includes('喝') || p.category.includes('咖啡')) typeClass = 'cat-drink';
|
||||
@@ -328,7 +340,7 @@ const loadHallData = async () => {
|
||||
...p,
|
||||
typeClass,
|
||||
timeSlot: p.timeSlot || '今日内随时可约',
|
||||
distance: '1.2km内',
|
||||
distance: p.distanceText || '同城',
|
||||
requirement: p.requirement || '按约定准时到场,文明健康社交。'
|
||||
};
|
||||
});
|
||||
@@ -382,64 +394,7 @@ const categories = ref([
|
||||
{ key: 'game', name: '线上电竞', count: 3, icon: ICONS.gameCrosshair }
|
||||
]);
|
||||
|
||||
const orders = ref([
|
||||
{
|
||||
id: 101,
|
||||
category: '同城美食陪吃',
|
||||
typeClass: 'cat-food',
|
||||
payMethod: 'AA制各付',
|
||||
reward: 120,
|
||||
title: '三里屯北京烤鸭探店·寻2位好脾气饭搭子',
|
||||
location: '朝阳区 · 三里屯SOHO商场',
|
||||
distance: '1.1km',
|
||||
timeSlot: '今日 18:30 - 20:30',
|
||||
requirement: '已提前订座,现场各自出示4位核销码,性格随和开朗。',
|
||||
userName: '小鹿斑比',
|
||||
userAvatar: 'https://images.unsplash.com/photo-1544005313-94ddf0286df2?w=100'
|
||||
},
|
||||
{
|
||||
id: 102,
|
||||
category: '线上电竞开黑',
|
||||
typeClass: 'cat-game',
|
||||
payMethod: '老板全包',
|
||||
reward: 70,
|
||||
title: '王者荣耀 · 微信区荣耀王者晋级双排',
|
||||
location: '线上远程开黑',
|
||||
distance: '全国',
|
||||
timeSlot: '接单后即刻开始 (2局)',
|
||||
requirement: '擅长射手或打野位,带飞晋级,游戏内清晰沟通不压力。',
|
||||
userName: '想赢一把好难',
|
||||
userAvatar: 'https://images.unsplash.com/photo-1500648767791-00dcc994a43e?w=100'
|
||||
},
|
||||
{
|
||||
id: 103,
|
||||
category: '同城下午茶陪喝',
|
||||
typeClass: 'cat-drink',
|
||||
payMethod: '房主买单',
|
||||
reward: 150,
|
||||
title: '工体精品手冲咖啡馆 · 倾听解压与交流',
|
||||
location: '朝阳区 · 工体北路',
|
||||
distance: '1.8km',
|
||||
timeSlot: '今日 15:00 - 17:00',
|
||||
requirement: '纯正规咖啡馆,工作压力大想倾诉,求善解人意的倾听导师。',
|
||||
userName: '风吹过的夏天',
|
||||
userAvatar: 'https://images.unsplash.com/photo-1524504388940-b1c1722653e1?w=100'
|
||||
},
|
||||
{
|
||||
id: 104,
|
||||
category: '同城KTV陪唱',
|
||||
typeClass: 'cat-sing',
|
||||
payMethod: 'AA分摊',
|
||||
reward: 200,
|
||||
title: '量贩纯K包厢麦霸欢唱 · 流行情歌对唱',
|
||||
location: '朝阳区 · 青年路大悦城店',
|
||||
distance: '3.2km',
|
||||
timeSlot: '今日 20:00 - 23:00',
|
||||
requirement: '爱唱歌、不跑调,会带动气氛,严禁任何违规,正规量贩KTV。',
|
||||
userName: '麦霸小王子',
|
||||
userAvatar: 'https://images.unsplash.com/photo-1519085360753-af0119f7cbe7?w=100'
|
||||
}
|
||||
]);
|
||||
const orders = ref([]);
|
||||
|
||||
const filteredOrders = computed(() => {
|
||||
if (activeCategory.value === 'all') return orders.value;
|
||||
@@ -476,20 +431,10 @@ const handleGrabOrder = (order) => {
|
||||
if (res.confirm) {
|
||||
uni.showLoading({ title: '正在锁定订单...' });
|
||||
try {
|
||||
await createOrder({
|
||||
buyerId: 2001,
|
||||
clientName: order.userName || '客户老板',
|
||||
await claimOrder(order.id, {
|
||||
expertId: expert.value.id || 2006,
|
||||
companionName: expert.value.nickname || '接单大神',
|
||||
expertAvatar: expert.value.avatar || DEFAULT_EXPERT_AVATAR,
|
||||
track: order.category || '同城生活',
|
||||
serviceTitle: order.title,
|
||||
hourlyRate: order.reward,
|
||||
durationHours: 2,
|
||||
amount: order.reward,
|
||||
location: order.location,
|
||||
expenseBurden: order.payMethod,
|
||||
status: '履约中'
|
||||
expertAvatar: expert.value.avatar || DEFAULT_EXPERT_AVATAR
|
||||
});
|
||||
} catch (err) {
|
||||
uni.hideLoading();
|
||||
@@ -802,6 +747,29 @@ const copyOrderNo = () => {
|
||||
flex-direction: column;
|
||||
gap: 20rpx;
|
||||
|
||||
.hall-empty {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 10rpx;
|
||||
padding: 60rpx 24rpx;
|
||||
border-radius: 24rpx;
|
||||
background: rgba(255, 255, 255, 0.03);
|
||||
border: 1rpx dashed rgba(255, 255, 255, 0.12);
|
||||
|
||||
.hall-empty-title {
|
||||
font-size: 28rpx;
|
||||
font-weight: 600;
|
||||
color: #E2E8F0;
|
||||
}
|
||||
|
||||
.hall-empty-desc {
|
||||
font-size: 24rpx;
|
||||
color: #94A3B8;
|
||||
}
|
||||
}
|
||||
|
||||
.dispatch-card {
|
||||
background: #151D30;
|
||||
border-radius: 24rpx;
|
||||
|
||||
在新工单中引用
屏蔽一个用户