feat: 新增平台客服配置及弹窗组件

- 新增客服电话、服务时间、企业微信客服配置项
- 新增客服弹窗组件支持微信在线客服和电话拨打
- 调整核销码为6位数字,修复相关提示文本
- 优化订单服务项目展示逻辑
- 完善抢单大厅加载动画和列表样式
这个提交包含在:
2026-11-18 18:08:22 +08:00
父节点 45a16c8bef
当前提交 31addddd5f
共有 35 个文件被更改,包括 1975 次插入 和 794 次删除

查看文件

@@ -10,7 +10,7 @@ use app\common\library\ProductPricing;
*/
class Home extends Base
{
protected $noNeedLogin = ['index', 'feed', 'cats', 'services', 'detail', 'calc', 'specs', 'masterCount', 'orderCase', 'agreement', 'agreementRead', 'systemGallery'];
protected $noNeedLogin = ['index', 'feed', 'cats', 'services', 'detail', 'calc', 'specs', 'masterCount', 'orderCase', 'agreement', 'agreementRead', 'systemGallery', 'serviceConfig'];
/**
* 首页聚合:类目 + 热门服务 + 我的角标
@@ -217,6 +217,9 @@ class Home extends Base
'assures' => $this->configList('home_assure'),
'tutorial' => $this->tutorial(),
'service_phone' => (string)(\think\Config::get('site.service_phone') ?: ''),
'service_work_time' => (string)(\think\Config::get('site.service_work_time') ?: ''),
'service_corp_id' => (string)(\think\Config::get('site.service_corp_id') ?: ''),
'service_kf_url' => (string)(\think\Config::get('site.service_kf_url') ?: ''),
'badge' => ['coupon' => 0, 'unread' => 0],
];
@@ -1826,4 +1829,17 @@ class Home extends Base
'services' => $services,
]);
}
/**
* 获取平台客服配置(客服电话、服务时间、企业微信客服参数)
*/
public function serviceConfig()
{
$this->success('', [
'service_phone' => trim((string)(\think\Config::get('site.service_phone') ?: '')),
'service_work_time' => trim((string)(\think\Config::get('site.service_work_time') ?: '')),
'service_corp_id' => trim((string)(\think\Config::get('site.service_corp_id') ?: '')),
'service_kf_url' => trim((string)(\think\Config::get('site.service_kf_url') ?: '')),
]);
}
}

查看文件

@@ -997,7 +997,7 @@ class Master extends Base
* 我的订单(师傅视角)
*/
/**
* 师傅端:输入客户 4 位验收核销码完成工单验收结算
* 师傅端:输入客户 6 位验收核销码完成工单验收结算
* @ApiMethod (POST)
*/
public function verifyCode()
@@ -1006,7 +1006,7 @@ class Master extends Base
$code = trim((string)$this->request->post('verify_code', ''));
if ($orderId <= 0 || $code === '') {
$this->error('请输入 4 位核销验证码');
$this->error('请输入 6 位核销验证码');
}
$master = $this->requireMaster();
@@ -1045,7 +1045,7 @@ class Master extends Base
$commission = $settleCalc['commission'];
$settleAmount = $settleCalc['settle_amount'];
$this->transit($lockedOrder, OrderStatus::COMPLETED, '师傅已录入客户 4 位验收核销码,核销完工', [
$this->transit($lockedOrder, OrderStatus::COMPLETED, '师傅已录入客户 6 位验收核销码,核销完工', [
'verify_time' => time(),
'settle_status' => 1,
'settle_amount' => $settleAmount,

查看文件

@@ -2,14 +2,12 @@
namespace app\api\controller;
use app\common\library\CommissionService;
use app\common\library\FinanceConfigService;
use app\common\library\InvoiceService;
use app\common\library\OrderStatus;
use think\Db;
/**
* 商家端(企业账号):入驻 / 资料 / 账单 / 开票 / 批量下单归属
* 商家端(企业账号):入驻 / 资料 / 账单 / 开票 / 团队成员 / 订单归属
*/
class Merchant extends Base
{
@@ -554,323 +552,6 @@ class Merchant extends Base
/**
* 当前用户商家档案:主账号直接匹配,关联账号通过绑定关系匹配
*/
/**
* 商户端:Excel 或结构化数据一键批量解析下单
* @ApiMethod (POST)
*/
public function importBatch()
{
$merchant = $this->requireMerchant();
$rawOrders = $this->request->post('orders', null, null);
if ($rawOrders === null || $rawOrders === '' || $rawOrders === []) {
$rawOrders = $this->request->post('items', [], null);
}
$items = [];
if (is_string($rawOrders)) {
$decoded = json_decode(htmlspecialchars_decode(trim($rawOrders)), true);
if (is_array($decoded)) {
$items = $decoded;
}
} elseif (is_array($rawOrders)) {
if (count($rawOrders) === 1 && isset($rawOrders[0]) && is_string($rawOrders[0])) {
$decoded = json_decode(htmlspecialchars_decode(trim($rawOrders[0])), true);
$items = is_array($decoded) ? $decoded : $rawOrders;
} else {
$items = $rawOrders;
}
}
if (empty($items) || !is_array($items)) {
$this->error('导入数据不能为空');
}
if (count($items) > 100) {
$this->error('单次批量导入最多支持 100 条订单');
}
$globalServiceId = (int)$this->request->post('service_id', 0);
$serviceCache = [];
$preparedRows = [];
foreach ($items as $idx => $item) {
if (is_string($item)) {
$decItem = json_decode(htmlspecialchars_decode(trim($item)), true);
if (is_array($decItem)) {
$item = $decItem;
}
}
if (!is_array($item)) {
continue;
}
$contact = trim((string)(isset($item['contact']) ? $item['contact'] : '买家'));
$mobile = preg_replace('/[^\d]/', '', trim((string)(isset($item['mobile']) ? $item['mobile'] : '')));
$address = trim((string)(isset($item['address']) ? $item['address'] : ''));
if ($mobile === '' && $address === '') {
continue;
}
$rowNo = $idx + 1;
if (!preg_match('/^1\d{10}$/', $mobile)) {
$this->error("第 {$rowNo} 条订单联系电话格式不正确");
}
if ($address === '') {
$this->error("第 {$rowNo} 条订单缺少详细服务地址");
}
$itemServiceId = !empty($item['service_id']) ? (int)$item['service_id'] : $globalServiceId;
if ($itemServiceId <= 0) {
$this->error("第 {$rowNo} 条订单未指定有效的服务项目");
}
if (!array_key_exists($itemServiceId, $serviceCache)) {
$serviceCache[$itemServiceId] = Db::name('service')
->where('id', $itemServiceId)
->where('status', 'normal')
->find() ?: null;
}
$svc = $serviceCache[$itemServiceId];
if (!$svc) {
$this->error("第 {$rowNo} 条订单关联的服务项目不存在或已下架");
}
if ($svc['price_type'] === 'quote') {
$this->error("第 {$rowNo} 条订单所选服务「{$svc['name']}」为师傅报价项目,不支持批量一口价导入");
}
$goodsNum = max(1, (int)(isset($item['goods_num']) ? $item['goods_num'] : (isset($item['num']) ? $item['num'] : 1)));
$floor = isset($item['floor']) ? max(1, (int)$item['floor']) : 1;
$hasElevator = isset($item['has_elevator'])
? (int)$item['has_elevator']
: (isset($item['elevator']) ? (int)$item['elevator'] : 1);
$urgent = !empty($item['urgent']) ? 1 : 0;
$specId = isset($item['spec_id']) ? (int)$item['spec_id'] : 0;
$reqServiceType = isset($item['service_type']) ? trim((string)$item['service_type']) : '';
// 严禁采信前端传入的 price,强制根据数据库 fa_service / fa_service_spec 与楼层规则计算真实金额
try {
$calc = Home::calcAmount($svc, [
'floor' => $floor,
'has_elevator' => $hasElevator ? 1 : 0,
'urgent' => $urgent,
'goods_num' => $goodsNum,
'spec_id' => $specId,
'service_type' => $reqServiceType,
'strict' => true,
], 0, $this->uid(), 'fixed', 0, []);
} catch (\InvalidArgumentException $e) {
$this->error("第 {$rowNo} 条订单计价校验失败:" . $e->getMessage());
return;
}
if ((float)$calc['pay_amount'] <= 0) {
$this->error("第 {$rowNo} 条订单计算金额异常");
}
$resolvedProvince = mb_substr(trim((string)(isset($item['province']) && $item['province'] !== '' ? $item['province'] : ($merchant['province'] ?: ''))), 0, 50);
$resolvedCity = mb_substr(trim((string)(isset($item['city']) && $item['city'] !== '' ? $item['city'] : ($merchant['city'] ?: ''))), 0, 50);
if ($resolvedProvince === '' || $resolvedCity === '') {
$this->error("第 {$rowNo} 条订单缺少服务省份或城市信息,请在Excel或表格中填写后再提交");
}
$preparedRows[] = [
'svc' => $svc,
'service_id' => (int)$svc['id'],
'cat_id' => (int)$svc['cat_id'],
'service_name' => (string)$svc['name'],
'service_img' => (string)$svc['image'],
'goods_model' => mb_substr(trim((string)(isset($item['goods_model']) ? $item['goods_model'] : '')), 0, 100),
'goods_num' => $goodsNum,
'contact' => mb_substr($contact ?: '买家', 0, 50),
'mobile' => $mobile,
'province' => $resolvedProvince,
'city' => $resolvedCity,
'district' => mb_substr(trim((string)(isset($item['district']) ? $item['district'] : ($merchant['district'] ?: ''))), 0, 50),
'address' => mb_substr($address, 0, 255),
'floor' => $floor,
'has_elevator' => $hasElevator ? 1 : 0,
'urgent' => $urgent,
'remark' => mb_substr(trim((string)(isset($item['remark']) ? $item['remark'] : '')), 0, 500),
'appoint_time' => !empty($item['appoint_time']) ? (int)$item['appoint_time'] : null,
'calc' => $calc,
];
}
if (empty($preparedRows)) {
$this->error('未解析到有效的导入订单数据');
}
$ordersCreated = [];
$orderIds = [];
$totalAmount = 0.00;
$isMonthly = false;
$batchNo = 'MB' . date('YmdHis') . mt_rand(1000, 9999);
$now = time();
// 事务外一次性预加载生效抽佣规则与默认兜底配置,循环内纯内存匹配快照(零额外 SQL)
$activeCommRules = CommissionService::getActiveRules();
$commDefaults = FinanceConfigService::getCommissionDefaults();
Db::startTrans();
try {
$lockedMerchant = Db::name('merchant')->where('id', (int)$merchant['id'])->lock(true)->find();
if (!$lockedMerchant || $lockedMerchant['verify_status'] !== 'pass') {
throw new \InvalidArgumentException('商家资质状态异常,无法批量发单');
}
$isMonthly = ($lockedMerchant['settle_type'] === 'monthly');
$initStatus = $isMonthly ? OrderStatus::PENDING_ACCEPT : OrderStatus::PENDING_PAY;
$initPayStatus = $isMonthly ? 1 : 0;
$initPayType = $isMonthly ? 'monthly' : '';
$initPayTime = $isMonthly ? $now : null;
foreach ($preparedRows as $pRow) {
$orderNo = $this->makeOrderNo();
$verifyCode = str_pad((string)mt_rand(0, 999999), 6, '0', STR_PAD_LEFT);
$calc = $pRow['calc'];
$payAmt = round((float)$calc['pay_amount'], 2);
$unitPrice = round((float)$calc['base_amount'] / max(1, (int)$pRow['goods_num']), 2);
$commMatch = CommissionService::matchOrderSnapshot([
'price_type' => 'fixed',
'customer_type' => 'merchant',
'cat_id' => (int)$pRow['cat_id'],
'urgent' => (int)$pRow['urgent'],
'order_amount' => $payAmt,
], $activeCommRules, $commDefaults);
$orderId = (int)Db::name('order')->insertGetId([
'order_no' => $orderNo,
'user_id' => $this->uid(),
'master_id' => 0,
'cat_id' => $pRow['cat_id'],
'service_id' => $pRow['service_id'],
'service_name' => $pRow['service_name'],
'service_image' => $pRow['service_img'],
'price_type' => 'fixed',
'goods_model' => $pRow['goods_model'],
'goods_num' => $pRow['goods_num'],
'contact' => $pRow['contact'],
'mobile' => $pRow['mobile'],
'province' => $pRow['province'],
'city' => $pRow['city'],
'district' => $pRow['district'],
'address' => $pRow['address'],
'floor' => $pRow['floor'],
'has_elevator' => $pRow['has_elevator'],
'urgent' => $pRow['urgent'],
'remark' => $pRow['remark'],
'appoint_time' => $pRow['appoint_time'],
'base_amount' => $calc['base_amount'],
'floor_amount' => $calc['floor_amount'],
'urgent_amount' => $calc['urgent_amount'],
'discount_amount' => 0.00,
'total_amount' => $calc['total_amount'],
'pay_amount' => $payAmt,
'commission_rate' => $commMatch['commission_rate'],
'commission_snapshot' => $commMatch['commission_snapshot'],
'status' => $initStatus,
'pay_status' => $initPayStatus,
'pay_type' => $initPayType,
'pay_time' => $initPayTime,
'transaction_id' => $isMonthly ? ('MONTHLY' . date('YmdHis', $now) . mt_rand(1000, 9999)) : '',
'verify_code' => $verifyCode,
'createtime' => $now,
'updatetime' => $now,
]);
Db::name('order_goods')->insert([
'order_id' => $orderId,
'service_id' => $pRow['service_id'],
'goods_name' => $pRow['service_name'],
'goods_model' => $pRow['goods_model'],
'goods_num' => $pRow['goods_num'],
'goods_image' => $pRow['service_img'],
'addon_services' => '',
'base_price' => $unitPrice,
'createtime' => $now,
]);
Db::name('merchant_order')->insert([
'merchant_id' => (int)$lockedMerchant['id'],
'order_id' => $orderId,
'batch_no' => $batchNo,
'createtime' => $now,
]);
$this->addLog(
$orderId,
$initStatus,
$isMonthly ? "企业批量导单(月结授信,批次 {$batchNo}),已进入接单大厅" : "企业批量导单创建(待支付,批次 {$batchNo})",
'user',
$this->uid()
);
$orderIds[] = $orderId;
$ordersCreated[] = [
'order_id' => $orderId,
'order_no' => $orderNo,
'contact' => $pRow['contact'],
'amount' => $payAmt,
];
$totalAmount = round($totalAmount + $payAmt, 2);
}
if ($isMonthly) {
Db::name('merchant')->where('id', (int)$lockedMerchant['id'])->update([
'order_count' => (int)$lockedMerchant['order_count'] + count($ordersCreated),
'total_amount' => round((float)$lockedMerchant['total_amount'] + $totalAmount, 2),
'updatetime' => $now,
]);
}
Db::commit();
} catch (\think\exception\HttpResponseException $e) {
Db::rollback();
throw $e;
} catch (\InvalidArgumentException $e) {
Db::rollback();
$this->error($e->getMessage());
return;
} catch (\Exception $e) {
Db::rollback();
\think\Log::error('[Merchant::importBatch] ' . $e->getMessage());
$this->error('批量导入失败:' . $e->getMessage());
return;
}
if ($isMonthly && !empty($orderIds)) {
try {
$masters = Db::name('master')
->where('verify_status', 'pass')
->where('work_status', 'on')
->where('user_id', '<>', $this->uid())
->limit(20)
->select();
$cnt = count($orderIds);
foreach ($masters as $m) {
$this->notify('master', (int)$m['id'], '企业批量新工单就绪', "商家刚发布了 {$cnt} 笔新工单进入接单大厅,请尽快前往查看抢单!", 'order', (int)$orderIds[0]);
}
} catch (\Exception $e) {
\think\Log::error('[Merchant::importBatch broadcast] ' . $e->getMessage());
}
}
$this->success($isMonthly ? '批量下单成功,已按月结授信进入接单大厅!' : '批量导入成功,请完成批次支付', [
'need_pay' => !$isMonthly,
'settle_type' => $isMonthly ? 'monthly' : 'prepay',
'batch_no' => $batchNo,
'count' => count($ordersCreated),
'total_amount' => round($totalAmount, 2),
'order_ids' => $orderIds,
'orders' => $ordersCreated,
]);
}
/**
* 商户端:预付商家按批次号支付待支付批量订单(严禁模拟免付兜底,预付订单须逐笔走真实微信支付)
* @ApiMethod (POST)
*/
public function payBatch()
{
$this->requireMerchant();
$this->error('系统已全面禁用模拟支付通道,企业预付工单请逐笔使用真实微信支付完成付款(月结授信企业导单时已直接授信进入大厅)');
}
protected function merchantInfo()
{
$merchant = Db::name('merchant')->where('user_id', $this->uid())->find();

查看文件

@@ -5,6 +5,7 @@ namespace app\api\controller;
use app\common\library\CommissionService;
use app\common\library\FinanceConfigService;
use app\common\library\OrderStatus;
use app\common\library\OrderServiceSnapshot;
use app\common\library\PaymentService;
use app\common\library\TiandituService;
use think\Db;
@@ -552,17 +553,7 @@ class Order extends Base
}
// 增项服务快照
$addonStr = '';
if (!empty($g['addon_services'])) {
$addonStr = is_array($g['addon_services']) ? json_encode($g['addon_services'], JSON_UNESCAPED_UNICODE) : (string)$g['addon_services'];
} elseif (!empty($g['extras']) && is_array($g['extras'])) {
$hitExtras = array_filter($g['extras'], function ($ex) {
return is_array($ex) && !empty($ex['num']) && (int)$ex['num'] > 0;
});
if (!empty($hitExtras)) {
$addonStr = json_encode(array_values($hitExtras), JSON_UNESCAPED_UNICODE);
}
}
$addonStr = OrderServiceSnapshot::format($g);
$gSid = isset($g['service_id']) ? (int)$g['service_id'] : (int)$serviceId;
$gUnitPrice = round((float)$amount['base_amount'] / max(1, (int)$goodsNum), 2);
@@ -818,9 +809,8 @@ class Order extends Base
$row['goods_list'] = $allGoods[$row['id']];
$firstG = $allGoods[$row['id']][0];
$row['goods_title'] = $firstG['goods_name'] . (!empty($firstG['goods_model']) ? ' (' . $firstG['goods_model'] . ')' : '') . ' x ' . $firstG['goods_num'] . '套';
if (!empty($firstG['addon_services'])) {
$row['service_items_text'] = '服务项目: ' . $firstG['addon_services'];
}
$row['service_items_text'] = !empty($firstG['addon_services'])
? '服务项目: ' . $firstG['addon_services'] : '';
if (!empty($firstG['goods_image'])) {
$row['goods_image_url'] = $firstG['goods_image'];
}
@@ -1132,7 +1122,7 @@ class Order extends Base
$gRow['images'] = $rowImgs;
$gRow['env_images'] = $normalizeUrlList($pg['envImages'] ?? ($pg['env_images'] ?? []));
$gRow['goods_videos'] = $normalizeUrlList($pg['videos'] ?? ($pg['goods_videos'] ?? []));
$gRow['service_type_name'] = isset($pg['service_type_name']) ? (string)$pg['service_type_name'] : '安装';
$gRow['service_type_name'] = isset($pg['service_type_name']) ? (string)$pg['service_type_name'] : '';
$gRow['goods_remark'] = isset($pg['remark']) ? trim((string)$pg['remark']) : '';
$gRow['unit'] = isset($pg['unit']) && $pg['unit'] !== '' ? (string)$pg['unit'] : '套';
}
@@ -1616,7 +1606,15 @@ class Order extends Base
} elseif ($status === OrderStatus::PENDING_ACCEPT) {
$statusTimelineText = '订单已进入接单大厅,正在匹配师傅';
} elseif ($status === OrderStatus::QUOTING) {
$statusTimelineText = '已有师傅进行报价,请比对选择';
$quoteCount = isset($row['quote_count'])
? (int)$row['quote_count']
: (int)Db::name('order_quote')
->where('order_id', (int)$row['id'])
->where('status', 'wait')
->count();
$statusTimelineText = $quoteCount > 0
? '已有 ' . $quoteCount . ' 位师傅进行报价,请比对选择'
: '订单已进入接单大厅,正在等待师傅报价';
} elseif ($status === OrderStatus::ACCEPTED) {
$statusTimelineText = '师傅已接单,请等待师傅联系并上门';
if (!empty($row['accept_time'])) $statusTime = (int)$row['accept_time'];