feat(admin): 新增师傅大厅筛选功能及表格布局组件

- 新增服务品类和服务类型筛选选项
- 新增订单距离筛选功能
- 新增admin-table-layout组件实现表格操作列固定
- 重构后台表格列布局,优化显示效果
- 新增位置相关工具函数及测试用例
- 升级版本号至1.0.89
这个提交包含在:
2026-11-19 14:39:28 +08:00
父节点 a608ef6506
当前提交 c37739656c
共有 50 个文件被更改,包括 572 次插入 和 405 次删除

查看文件

@@ -541,34 +541,6 @@ class Master extends Base
}
$type = $this->request->param('type', 'all'); // all / fixed 一口价 / quote 师傅报价 / custom 用户自主定价
$buildBase = function () use ($catIds) {
$q = Db::name('order')->where('master_id', 0)
->where('status', 'in', [OrderStatus::PENDING_ACCEPT, OrderStatus::QUOTING]);
if (!empty($catIds)) {
$q->where('cat_id', 'in', $catIds);
}
return $q;
};
$build = function () use ($buildBase, $type) {
$q = $buildBase();
if ($type === 'fixed') {
$q->where('status', OrderStatus::PENDING_ACCEPT)->where('price_type', 'fixed');
} elseif ($type === 'quote') {
$q->where('status', 'in', [OrderStatus::PENDING_ACCEPT, OrderStatus::QUOTING])->where('price_type', 'quote');
} elseif ($type === 'custom') {
$q->where('status', OrderStatus::PENDING_ACCEPT)->where('price_type', 'custom');
}
return $q;
};
$counts = [
'all' => (int)$buildBase()->count(),
'fixed' => (int)$buildBase()->where('status', OrderStatus::PENDING_ACCEPT)->where('price_type', 'fixed')->count(),
'quote' => (int)$buildBase()->where('status', 'in', [OrderStatus::PENDING_ACCEPT, OrderStatus::QUOTING])->where('price_type', 'quote')->count(),
'custom' => (int)$buildBase()->where('status', OrderStatus::PENDING_ACCEPT)->where('price_type', 'custom')->count(),
];
$masterRecord = $this->masterInfo();
$rawLat = $this->request->param('lat', '');
$rawLng = $this->request->param('lng', '');
@@ -603,6 +575,58 @@ class Master extends Base
$validCoordCond = $this->getValidOrderCoordSql();
$distFormula = $this->getDistanceSqlFormula();
// 选项来自真实启用字典;分类始终受师傅技能范围约束。
$categoryQuery = Db::name('service_cat')->field('id,name')->where('status', 'normal');
if (!empty($catIds)) {
$categoryQuery->where('id', 'in', $catIds);
}
$filterCategories = $categoryQuery->order('weigh desc,id asc')->select();
$filterTypes = Db::name('service_type')->field('code,name')->where('status', 'normal')->order('weigh desc,id asc')->select();
$categoryId = max(0, (int)$this->request->param('cat_id', 0));
$serviceType = trim((string)$this->request->param('service_type', ''));
$distanceRaw = $this->request->param('distance_km', '');
$distanceKm = $distanceRaw === '' ? 0 : (float)$distanceRaw;
$categoryAllowed = array_map('intval', array_column($filterCategories, 'id'));
$typeAllowed = array_column($filterTypes, 'code');
if ($categoryId && !in_array($categoryId, $categoryAllowed, true)) $this->error('所选服务品类不可用');
if ($serviceType !== '' && (!preg_match('/^[a-z0-9_]+$/', $serviceType) || !in_array($serviceType, $typeAllowed, true))) $this->error('所选服务类型不可用');
if ($distanceRaw !== '' && (!is_numeric($distanceRaw) || $distanceKm <= 0 || $distanceKm > 200)) $this->error('订单距离无效');
if ($distanceKm > 0 && !$hasLocation) $this->error('请先选择接单位置');
$distanceCondition = '';
if ($distanceKm > 0) {
$distanceExpression = str_replace([':h_lat1', ':h_lng1', ':h_lat2'], [(string)$userLat, (string)$userLng, (string)$userLat], $distFormula);
$distanceCondition = $validCoordCond . ' AND ' . $distanceExpression . ' <= ' . (string)$distanceKm;
}
$buildBase = function () use ($catIds, $categoryId, $serviceType, $distanceCondition) {
$q = Db::name('order')->where('master_id', 0)
->where('status', 'in', [OrderStatus::PENDING_ACCEPT, OrderStatus::QUOTING]);
if (!empty($catIds)) $q->where('cat_id', 'in', $catIds);
if ($categoryId) $q->where('cat_id', $categoryId);
if ($serviceType !== '') {
// 订单快照记录每个商品的真实工项;历史订单缺少快照时不猜测。
$q->whereRaw("CASE WHEN JSON_VALID(goods_images) THEN JSON_CONTAINS(JSON_EXTRACT(goods_images, '$.goods_list[*].service_type'), JSON_QUOTE('" . $serviceType . "')) = 1 ELSE 0 END");
}
if ($distanceCondition !== '') $q->whereRaw($distanceCondition);
return $q;
};
$build = function () use ($buildBase, $type) {
$q = $buildBase();
if ($type === 'fixed') {
$q->where('status', OrderStatus::PENDING_ACCEPT)->where('price_type', 'fixed');
} elseif ($type === 'quote') {
$q->where('status', 'in', [OrderStatus::PENDING_ACCEPT, OrderStatus::QUOTING])->where('price_type', 'quote');
} elseif ($type === 'custom') {
$q->where('status', OrderStatus::PENDING_ACCEPT)->where('price_type', 'custom');
}
return $q;
};
$counts = [
'all' => (int)$buildBase()->count(),
'fixed' => (int)$buildBase()->where('status', OrderStatus::PENDING_ACCEPT)->where('price_type', 'fixed')->count(),
'quote' => (int)$buildBase()->where('status', 'in', [OrderStatus::PENDING_ACCEPT, OrderStatus::QUOTING])->where('price_type', 'quote')->count(),
'custom' => (int)$buildBase()->where('status', OrderStatus::PENDING_ACCEPT)->where('price_type', 'custom')->count(),
];
// 真实定位场景下的当前所在城市识别:优先使用实时传入城市;若未传入,根据 35km 内最近已知坐标订单推断,绝不拿跨城注册地误判
$locationCity = '';
if ($hasLocation) {
@@ -741,9 +765,14 @@ class Master extends Base
$goodsName = '';
$addonServices = '';
$fallbackImg = '';
$serviceTypeNames = [];
if (!empty($row['goods_images'])) {
$parsed = json_decode((string)$row['goods_images'], true);
if (is_array($parsed) && !empty($parsed['goods_list']) && is_array($parsed['goods_list'])) {
foreach ($parsed['goods_list'] as $goodsItem) {
$itemType = is_array($goodsItem) ? trim((string)($goodsItem['service_type_name'] ?? '')) : '';
if ($itemType !== '') $serviceTypeNames[] = $itemType;
}
$firstItem = $parsed['goods_list'][0];
if (is_array($firstItem)) {
$goodsName = isset($firstItem['goods_name']) && is_string($firstItem['goods_name'])
@@ -773,7 +802,7 @@ class Master extends Base
$row['goods_name'] = $goodsName ?: $row['service_name'];
$row['addon_services'] = rtrim(str_replace(';', ' · ', (string)$addonServices), ' ·');
$row['goods_num'] = max(1, (int)($row['goods_num'] ?? 1));
$row['service_type_tag'] = (strpos((string)$row['service_name'], '修') !== false || strpos((string)$row['service_name'], '检') !== false) ? '维修' : '安装';
$row['service_type_tag'] = implode(' / ', array_unique($serviceTypeNames));
$img = !empty($row['service_image']) ? $row['service_image'] : $fallbackImg;
if (empty($img) && !empty($row['service_id']) && !empty($serviceImgMap[(int)$row['service_id']])) {
@@ -821,6 +850,7 @@ class Master extends Base
'location_source' => $reqHasValidCoord ? 'realtime' : ($dbHasValidCoord ? 'saved' : 'none'),
'location_city' => $locationCity,
'serve_radius' => $serveRadius,
'filter_options' => ['categories' => $filterCategories, 'service_types' => $filterTypes],
]);
}