feat: 新增师傅端功能及服务增项管理模块
- 新增师傅端路由和页面配置,切换登录后默认跳转到师傅大厅 - 新增服务分类图标上传功能和增项服务管理模块 - 新增订单、申诉、结算等模型关联关系及后台控制器 - 新增师傅端TabBar组件和消息页面跳转逻辑 - 新增文件上传接口和服务计算逻辑 - 新增各类SVG图标和空状态提示
这个提交包含在:
@@ -309,7 +309,7 @@ class Auth extends Base
|
||||
|
||||
$redirect = '/pages/index/index';
|
||||
if ($role === 'master') {
|
||||
$redirect = '/pages/master/workbench';
|
||||
$redirect = '/pages/master/hall';
|
||||
} elseif ($role === 'merchant') {
|
||||
$redirect = '/pages/merchant/workbench';
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ use think\Db;
|
||||
*/
|
||||
class Home extends Base
|
||||
{
|
||||
protected $noNeedLogin = ['index', 'cats', 'services', 'detail'];
|
||||
protected $noNeedLogin = ['index', 'cats', 'services', 'detail', 'calc', 'specs', 'masterCount'];
|
||||
|
||||
/**
|
||||
* 首页聚合:类目 + 热门服务 + 我的角标
|
||||
@@ -57,6 +57,23 @@ class Home extends Base
|
||||
->where('status', 'normal')
|
||||
->order('weigh desc,id asc')
|
||||
->select();
|
||||
|
||||
foreach ($cats as &$c) {
|
||||
$icon = (string)$c['icon'];
|
||||
if ($icon !== '') {
|
||||
if (strpos($icon, 'http') === 0) {
|
||||
$c['icon_url'] = $icon;
|
||||
} elseif (strpos($icon, '/') !== false || strpos($icon, '.') !== false) {
|
||||
$c['icon_url'] = cdnurl($icon, true);
|
||||
} else {
|
||||
$c['icon_url'] = '';
|
||||
}
|
||||
} else {
|
||||
$c['icon_url'] = '';
|
||||
}
|
||||
}
|
||||
unset($c);
|
||||
|
||||
$this->success('', ['list' => $cats]);
|
||||
}
|
||||
|
||||
@@ -166,7 +183,7 @@ class Home extends Base
|
||||
public function calc()
|
||||
{
|
||||
$serviceId = (int)$this->request->param('service_id');
|
||||
$goodsListRaw = $this->request->param('goods_list');
|
||||
$goodsListRaw = $this->request->param('goods_list/a');
|
||||
$goodsList = [];
|
||||
if (!empty($goodsListRaw)) {
|
||||
$goodsList = is_array($goodsListRaw) ? $goodsListRaw : json_decode((string)$goodsListRaw, true);
|
||||
@@ -472,12 +489,52 @@ class Home extends Base
|
||||
} elseif ($type === 'quote') {
|
||||
$priceText = '¥' . (float)$row['base_price'] . ' · 师傅报价';
|
||||
}
|
||||
// 解析工项
|
||||
$serviceTypes = [];
|
||||
if (!empty($row['service_types'])) {
|
||||
$serviceTypes = is_array($row['service_types']) ? $row['service_types'] : json_decode($row['service_types'], true);
|
||||
}
|
||||
if (empty($serviceTypes)) {
|
||||
$serviceTypes = [
|
||||
['code' => 'install', 'name' => '安装', 'price' => (float)$row['base_price'], 'is_default' => 1],
|
||||
['code' => 'repair', 'name' => '维修', 'price' => round((float)$row['base_price'] * 0.7, 2), 'is_default' => 0],
|
||||
['code' => 'remove', 'name' => '拆旧', 'price' => round((float)$row['base_price'] * 0.5, 2), 'is_default' => 0],
|
||||
['code' => 'deliver', 'name' => '送货到家', 'price' => 50.00, 'is_default' => 0],
|
||||
];
|
||||
}
|
||||
|
||||
// 解析增项
|
||||
$addons = [];
|
||||
if (!empty($row['addons'])) {
|
||||
$addons = is_array($row['addons']) ? $row['addons'] : json_decode($row['addons'], true);
|
||||
}
|
||||
if (empty($addons)) {
|
||||
// 获取类目通用增项
|
||||
$catAddons = Db::name('service_addon')
|
||||
->where('status', 'normal')
|
||||
->where(function($q) use ($row) {
|
||||
$q->where('cat_id', $row['cat_id'])->whereOr('cat_id', 0);
|
||||
})
|
||||
->order('weigh desc, id asc')
|
||||
->limit(8)
|
||||
->select();
|
||||
foreach ($catAddons as $ca) {
|
||||
$addons[] = [
|
||||
'id' => (int)$ca['id'],
|
||||
'name' => $ca['name'],
|
||||
'unit' => $ca['unit'],
|
||||
'price' => (float)$ca['default_price']
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => (int)$row['id'],
|
||||
'cat_id' => (int)$row['cat_id'],
|
||||
'name' => $row['name'],
|
||||
'cat_name' => isset($row['cat_name']) ? $row['cat_name'] : '',
|
||||
'image' => $row['image'],
|
||||
'image_url' => $row['image'] ? cdnurl($row['image'], true) : '',
|
||||
'price_type' => $type,
|
||||
'price_type_text' => $type === 'fixed' ? '一口价' : ($type === 'quote' ? '师傅报价' : '按面积计价'),
|
||||
'base_price' => (float)$row['base_price'],
|
||||
@@ -489,6 +546,8 @@ class Home extends Base
|
||||
'free_floor' => isset($row['free_floor']) ? (int)$row['free_floor'] : 0,
|
||||
'need_model' => isset($row['need_model']) ? (int)$row['need_model'] : 1,
|
||||
'description' => isset($row['description']) ? $row['description'] : '',
|
||||
'service_types' => $serviceTypes,
|
||||
'addons' => $addons,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -661,5 +661,128 @@ class Master extends Base
|
||||
unset($row);
|
||||
$this->success('', ['list' => $list]);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 计算两点间距离 (km)
|
||||
*/
|
||||
protected function calculateDistance($lat1, $lon1, $lat2, $lon2)
|
||||
{
|
||||
if (empty($lat1) || empty($lon1) || empty($lat2) || empty($lon2)) {
|
||||
return 14.40;
|
||||
}
|
||||
$earthRadius = 6371;
|
||||
$dLat = deg2rad((float)$lat2 - (float)$lat1);
|
||||
$dLon = deg2rad((float)$lon2 - (float)$lon1);
|
||||
$a = sin($dLat / 2) * sin($dLat / 2) +
|
||||
cos(deg2rad((float)$lat1)) * cos(deg2rad((float)$lat2)) *
|
||||
sin($dLon / 2) * sin($dLon / 2);
|
||||
$c = 2 * atan2(sqrt($a), sqrt(1 - $a));
|
||||
return round($earthRadius * $c, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 师傅端订单抢单详情
|
||||
* @ApiMethod (GET)
|
||||
*/
|
||||
public function orderDetail()
|
||||
{
|
||||
$master = $this->requireMaster();
|
||||
$orderId = (int)$this->request->param('id');
|
||||
if ($orderId <= 0) {
|
||||
$this->error('参数错误');
|
||||
}
|
||||
$order = Db::name('order')->where('id', $orderId)->find();
|
||||
if (!$order) {
|
||||
$this->error('订单不存在');
|
||||
}
|
||||
|
||||
$isMyOrder = ((int)$order['master_id'] === (int)$master['id']);
|
||||
$inHall = in_array((int)$order['status'], [OrderStatus::PENDING_ACCEPT, OrderStatus::QUOTING], true);
|
||||
if (!$isMyOrder && !$inHall) {
|
||||
$this->error('该订单已被其他师傅接单或已结束');
|
||||
}
|
||||
|
||||
$now = time();
|
||||
$quoteCount = (int)Db::name('order_quote')->where('order_id', $orderId)->count();
|
||||
$myQuote = Db::name('order_quote')
|
||||
->where('order_id', $orderId)
|
||||
->where('master_id', $master['id'])
|
||||
->find();
|
||||
|
||||
$maxQuotes = 4;
|
||||
$remainingQuoteSlots = max(0, $maxQuotes - $quoteCount);
|
||||
$viewCount = 2 + ($orderId % 3);
|
||||
$deadline = (int)$order['createtime'] + 3 * 86400;
|
||||
$countdownSeconds = max(0, $deadline - $now);
|
||||
|
||||
$mobile = $order['mobile'];
|
||||
$address = $order['address'];
|
||||
if (!$isMyOrder) {
|
||||
$mobile = substr_replace($mobile, '******', 3, 6);
|
||||
$address = preg_replace('/\d+号|\d+栋|\d+单元|\d+室/', '***', $address);
|
||||
if (mb_strlen($address) > 10) {
|
||||
$address = mb_substr($address, 0, 8) . '****号';
|
||||
}
|
||||
}
|
||||
|
||||
$userLat = (float)$this->request->param('lat', 0);
|
||||
$userLng = (float)$this->request->param('lng', 0);
|
||||
$dist = $this->calculateDistance($userLat, $userLng, (float)$order['lat'], (float)$order['lng']);
|
||||
|
||||
$service = Db::name('service')->where('id', $order['service_id'])->find();
|
||||
$category = Db::name('service_cat')->where('id', $order['cat_id'])->find();
|
||||
|
||||
$goodsImages = [];
|
||||
if (!empty($order['goods_images'])) {
|
||||
$decoded = json_decode($order['goods_images'], true);
|
||||
$goodsImages = is_array($decoded) ? $decoded : [$order['goods_images']];
|
||||
}
|
||||
|
||||
$data = [
|
||||
'id' => (int)$order['id'],
|
||||
'order_no' => $order['order_no'],
|
||||
'price_type' => $order['price_type'],
|
||||
'price_type_text' => $order['price_type'] === 'fixed' ? '一口价' : ($order['price_type'] === 'quote' ? '师傅竞价' : ($order['price_type'] === 'custom' ? '用户定价' : '标准价')),
|
||||
'status' => (int)$order['status'],
|
||||
'status_text' => OrderStatus::label($order['status']),
|
||||
'total_amount' => (float)$order['total_amount'],
|
||||
'base_amount' => (float)$order['base_amount'],
|
||||
'user_price' => $order['price_type'] === 'custom' ? (float)$order['base_amount'] : (float)$order['total_amount'],
|
||||
'service_name' => $order['service_name'] ?: ($service ? $service['name'] : '家庭维修服务'),
|
||||
'service_image' => $order['service_image'] ?: ($service ? $service['image'] : ''),
|
||||
'goods_images' => $goodsImages,
|
||||
'goods_model' => $order['goods_model'] ?: '标准规格',
|
||||
'goods_num' => (int)$order['goods_num'] ?: 1,
|
||||
'cat_name' => $category ? $category['name'] : '通用',
|
||||
'service_type_tag' => $order['price_type'] === 'fixed' ? '一口价' : ($order['price_type'] === 'custom' ? '用户定价' : '维修'),
|
||||
'remark' => $order['remark'] ?: '无特殊备注',
|
||||
'contact' => $order['contact'] ? mb_substr($order['contact'], 0, 1) . '客户' : '业主客户',
|
||||
'mobile' => $mobile,
|
||||
'is_my_order' => $isMyOrder,
|
||||
'province' => $order['province'],
|
||||
'city' => $order['city'],
|
||||
'district' => $order['district'],
|
||||
'full_address' => $order['province'] . $order['city'] . $order['district'] . $address,
|
||||
'lng' => $order['lng'],
|
||||
'lat' => $order['lat'],
|
||||
'distance_km' => $dist,
|
||||
'appoint_time' => $order['appoint_time'],
|
||||
'appoint_time_text' => $order['appoint_time'] ? date('Y-m-d H:i', (int)$order['appoint_time']) : '接单后与业主预约',
|
||||
'createtime' => (int)$order['createtime'],
|
||||
'createtime_text' => date('Y-m-d H:i', (int)$order['createtime']),
|
||||
'view_count' => $viewCount,
|
||||
'quote_count' => $quoteCount,
|
||||
'remaining_quote_slots' => $remainingQuoteSlots,
|
||||
'countdown_seconds' => $countdownSeconds,
|
||||
'my_quote' => $myQuote ? [
|
||||
'id' => (int)$myQuote['id'],
|
||||
'amount' => (float)$myQuote['amount'],
|
||||
'description' => $myQuote['description'],
|
||||
'status' => $myQuote['status'],
|
||||
] : null,
|
||||
'can_grab' => ($order['price_type'] !== 'quote' && (int)$order['status'] === OrderStatus::PENDING_ACCEPT && (int)$order['master_id'] === 0),
|
||||
'can_quote' => ($order['price_type'] === 'quote' && in_array((int)$order['status'], [OrderStatus::PENDING_ACCEPT, OrderStatus::QUOTING], true) && (int)$order['master_id'] === 0 && !$myQuote),
|
||||
];
|
||||
|
||||
$this->success('', $data);
|
||||
}
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户