feat: 新增平台客服配置及弹窗组件
- 新增客服电话、服务时间、企业微信客服配置项 - 新增客服弹窗组件支持微信在线客服和电话拨打 - 调整核销码为6位数字,修复相关提示文本 - 优化订单服务项目展示逻辑 - 完善抢单大厅加载动画和列表样式
这个提交包含在:
@@ -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();
|
||||
|
||||
在新工单中引用
屏蔽一个用户