feat: 新增师傅入驻审核与接单状态联动功能

- 新增师傅资质审核模块及权限
- 未审核通过的师傅默认禁用接单状态
- 新增售后退款申诉功能与相关界面
- 新增用户钱包管理及充值功能
- 更新服务定价矩阵相关数据库结构
- 修复微信支付证书验证问题
这个提交包含在:
2026-11-17 10:28:01 +08:00
父节点 ad73da1db4
当前提交 0370cb9bd6
共有 107 个文件被更改,包括 13666 次插入 和 1447 次删除

查看文件

@@ -613,10 +613,15 @@ class Order extends Base
{
$orderId = (int)$this->request->post('order_id');
$wxCode = trim((string)$this->request->post('wx_code', ''));
$payType = trim((string)$this->request->post('pay_type', 'wechat'));
$order = $this->ownOrder($orderId, 'user');
try {
$res = PaymentService::createOrderJsapiPay($order, $this->uid(), 'order', 0, $wxCode);
if ($payType === 'balance') {
$res = PaymentService::payOrderByBalance($order, $this->uid(), 'order');
} else {
$res = PaymentService::createOrderJsapiPay($order, $this->uid(), 'order', 0, $wxCode);
}
} catch (\think\exception\HttpResponseException $e) {
throw $e;
} catch (\InvalidArgumentException $e) {
@@ -624,7 +629,7 @@ class Order extends Base
return;
} catch (\Throwable $e) {
\think\Log::error('[Order::pay] ' . $e->getMessage());
$this->error('发起微信支付失败:' . $e->getMessage());
$this->error('发起支付失败:' . $e->getMessage());
return;
}
@@ -680,10 +685,15 @@ class Order extends Base
{
$orderId = (int)$this->request->post('order_id');
$wxCode = trim((string)$this->request->post('wx_code', ''));
$payType = trim((string)$this->request->post('pay_type', 'wechat'));
$order = $this->ownOrder($orderId, 'user');
try {
$res = PaymentService::createOrderJsapiPay($order, $this->uid(), 'diff', 0, $wxCode);
if ($payType === 'balance') {
$res = PaymentService::payOrderByBalance($order, $this->uid(), 'diff');
} else {
$res = PaymentService::createOrderJsapiPay($order, $this->uid(), 'diff', 0, $wxCode);
}
} catch (\think\exception\HttpResponseException $e) {
throw $e;
} catch (\InvalidArgumentException $e) {
@@ -695,7 +705,8 @@ class Order extends Base
return;
}
$this->success('请完成增项补差价微信支付', $res);
$msg = !empty($res['paid']) ? '增项补差价支付成功' : '请完成增项补差价微信支付';
$this->success($msg, $res);
}
public function index()
@@ -1176,10 +1187,15 @@ class Order extends Base
$orderId = (int)$this->request->post('order_id');
$quoteId = (int)$this->request->post('quote_id');
$wxCode = trim((string)$this->request->post('wx_code', ''));
$payType = trim((string)$this->request->post('pay_type', 'wechat'));
$order = $this->ownOrder($orderId, 'user');
try {
$res = PaymentService::createOrderJsapiPay($order, $this->uid(), 'quote', $quoteId, $wxCode);
if ($payType === 'balance') {
$res = PaymentService::payOrderByBalance($order, $this->uid(), 'quote', $quoteId);
} else {
$res = PaymentService::createOrderJsapiPay($order, $this->uid(), 'quote', $quoteId, $wxCode);
}
} catch (\think\exception\HttpResponseException $e) {
throw $e;
} catch (\InvalidArgumentException $e) {
@@ -1323,6 +1339,131 @@ class Order extends Base
$this->success('订单已取消');
}
/**
* 用户售后退款申请(已完成订单可申请,提交后进入平台售后仲裁队列)
* @ApiMethod (POST)
* @ApiParams (name="order_id", type="integer", required=true, description="订单ID")
* @ApiParams (name="content", type="string", required=true, description="售后申请原因(10~300字)")
* @ApiParams (name="refund_expect", type="float", required=false, description="期望退款金额(元,留空或0=全额)")
* @ApiParams (name="images", type="string", required=false, description="举证图片,逗号分隔的附件URL")
*/
public function afterSaleApply()
{
$orderId = (int)$this->request->post('order_id');
$content = trim((string)$this->request->post('content', ''));
$refundExpect = round((float)$this->request->post('refund_expect', 0), 2);
$images = trim((string)$this->request->post('images', ''));
if ($content === '' || mb_strlen($content) < 10) {
$this->error('请填写至少 10 个字的售后申请原因,便于平台快速核实');
}
if (mb_strlen($content) > 300) {
$this->error('售后申请原因请控制在 300 字以内');
}
if ($refundExpect < 0) {
$this->error('期望退款金额不能为负数');
}
$order = $this->ownOrder($orderId, 'user');
// 仅已完成订单可发起售后退款申请;未完成履约请走"取消订单"通道(同样支持原路退款)
if ((int)$order['status'] !== OrderStatus::COMPLETED) {
$this->error('当前状态(' . OrderStatus::label($order['status']) . ')不支持售后申请,未完成订单请使用"取消订单"');
}
if ((int)$order['pay_status'] !== 1) {
$this->error('该订单不是已支付状态(支付状态:' . ((int)$order['pay_status'] === 2 ? '已退款' : '未支付') . '),无需申请售后退款');
}
if ((float)$order['pay_amount'] > 0 && $refundExpect > 0 && $refundExpect > (float)$order['pay_amount']) {
$this->error('期望退款金额不能超过订单实付金额 ¥' . $order['pay_amount']);
}
// 防重复:同订单同一用户存在待受理/处理中的售后申诉时禁止重复提交
$exists = Db::name('appeal')
->where('order_id', $orderId)
->where('user_id', $this->uid())
->where('type', 'aftersale')
->whereIn('status', ['wait', 'handling'])
->count();
if ($exists > 0) {
$this->error('该订单已有售后申请正在处理中,请耐心等待平台仲裁结果');
}
$now = time();
Db::name('appeal')->insert([
'order_id' => $orderId,
'master_id' => 0,
'user_id' => $this->uid(),
'type' => 'aftersale',
'content' => mb_substr($content, 0, 500),
'images' => mb_substr($images, 0, 1000),
'refund_amount' => $refundExpect > 0 ? $refundExpect : null,
'status' => 'wait',
'reply' => '',
'createtime' => $now,
'updatetime' => $now,
]);
// 通知平台运营侧(写入系统消息,便于后台待办跟进)
Db::name('message')->insert([
'receive_type' => 'user',
'receive_id' => $this->uid(),
'type' => 'order',
'order_id' => (string)$orderId,
'title' => '售后申请已提交',
'content' => '您对订单【' . $order['order_no'] . '】的售后退款申请已提交(' . ($refundExpect > 0 ? '期望退款 ¥' . $refundExpect : '期望全额退款') . '),平台将在 1~2 个工作日内完成仲裁,结果将通过站内消息通知您。',
'is_read' => 0,
'createtime' => $now,
]);
Db::name('order_log')->insert([
'order_id' => $orderId,
'status' => (int)$order['status'],
'remark' => mb_substr('用户提交售后退款申请:' . $content, 0, 255),
'operator_type' => 'user',
'operator_id' => $this->uid(),
'createtime' => $now,
]);
$this->success('售后申请已提交,等待平台仲裁');
}
/**
* 我的售后申请记录(含仲裁进度与平台答复)
* @ApiMethod (POST)
*/
public function myAfterSales()
{
$rows = Db::name('appeal')
->alias('a')
->join('order o', 'o.id = a.order_id', 'LEFT')
->where('a.user_id', $this->uid())
->where('a.type', 'aftersale')
->field('a.id, a.order_id, o.order_no, o.service_name, o.pay_amount, a.content, a.images, a.refund_amount, a.status, a.reply, a.createtime, a.updatetime')
->order('a.id desc')
->limit(50)
->select();
$statusText = ['wait' => '待平台受理', 'handling' => '核实处理中', 'done' => '处理已完结', 'reject' => '已驳回诉求'];
$list = [];
foreach ($rows as $r) {
$list[] = [
'id' => (int)$r['id'],
'order_id' => (int)$r['order_id'],
'order_no' => (string)($r['order_no'] ?? ''),
'service_name' => (string)($r['service_name'] ?? ''),
'pay_amount' => (float)($r['pay_amount'] ?? 0),
'content' => (string)$r['content'],
'images' => (string)$r['images'],
'refund_amount' => $r['refund_amount'] !== null ? (float)$r['refund_amount'] : null,
'status' => (string)$r['status'],
'status_text' => $statusText[$r['status']] ?? (string)$r['status'],
'reply' => (string)$r['reply'],
'createtime' => $r['createtime'] ? date('Y-m-d H:i', (int)$r['createtime']) : '',
];
}
$this->success('查询成功', ['list' => $list]);
}
/**
* 客户验收(验收码可选校验)→ 生成结算并给师傅入账
* @ApiMethod (POST)
@@ -2116,10 +2257,14 @@ class Order extends Base
$priceType = (string)$fs['price_type'];
$unit = (string)($fs['unit'] ?: $unit);
$specPrice = 0.0;
$specPricesMap = [];
if ($specId > 0 && !empty($fs['specs'])) {
foreach ($fs['specs'] as $spItem) {
if ((int)$spItem['id'] === $specId && (float)$spItem['base_price'] > 0) {
$specPrice = (float)$spItem['base_price'];
if ((int)$spItem['id'] === $specId) {
$specPrice = (float)($spItem['base_price'] ?? 0);
if (!empty($spItem['service_prices']) && is_array($spItem['service_prices'])) {
$specPricesMap = $spItem['service_prices'];
}
break;
}
}
@@ -2133,11 +2278,18 @@ class Order extends Base
}
}
foreach ($rawSt as $idx => $st) {
$sCode = (string)($st['code'] ?? '');
$isDef = !empty($st['is_default']) || (!$hasDef && $idx === 0);
$pVal = ($isDef && $specPrice > 0) ? $specPrice : (float)($st['price'] ?? 0);
if (isset($specPricesMap[$sCode]) && (float)$specPricesMap[$sCode] > 0) {
$pVal = (float)$specPricesMap[$sCode];
} elseif ($isDef && $specPrice > 0) {
$pVal = $specPrice;
} else {
$pVal = (float)($st['price'] ?? 0);
}
$st['price'] = $pVal;
$serviceTypes[] = $st;
if ((string)$st['code'] === (string)$r['service_type']) {
if ($sCode === (string)$r['service_type']) {
$basePrice = $pVal;
}
}