feat: 新增师傅入驻审核与接单状态联动功能
- 新增师傅资质审核模块及权限 - 未审核通过的师傅默认禁用接单状态 - 新增售后退款申诉功能与相关界面 - 新增用户钱包管理及充值功能 - 更新服务定价矩阵相关数据库结构 - 修复微信支付证书验证问题
这个提交包含在:
@@ -46,7 +46,7 @@ class Appeal extends Backend
|
||||
}
|
||||
[$where, $sort, $order, $offset, $limit] = $this->buildparams();
|
||||
$list = $this->model
|
||||
->with(['order', 'master'])
|
||||
->with(['order', 'master', 'user'])
|
||||
->where($where)
|
||||
->order($sort, $order)
|
||||
->paginate($limit);
|
||||
@@ -95,36 +95,111 @@ class Appeal extends Backend
|
||||
|
||||
$oldStatus = (string)$row['status'];
|
||||
$oldReply = (string)$row['reply'];
|
||||
$isAftersale = ($row['type'] === 'aftersale');
|
||||
|
||||
// 用户售后申诉仲裁通过(完结)时,按核定价款执行微信原路退款
|
||||
$refundAmount = null;
|
||||
if ($isAftersale && $status === 'done') {
|
||||
$refundAmount = $this->request->post('refund_amount/f', -1);
|
||||
if ($refundAmount < 0) {
|
||||
$this->error('请填写本次仲裁核定的售后退款金额(0 表示不予退款,仅答复)');
|
||||
}
|
||||
$refundAmount = round((float)$refundAmount, 2);
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
$row->allowField(['status', 'reply'])->save([
|
||||
'status' => $status,
|
||||
'reply' => mb_substr($reply, 0, 500),
|
||||
$row->allowField(['status', 'reply', 'refund_amount'])->save([
|
||||
'status' => $status,
|
||||
'reply' => mb_substr($reply, 0, 500),
|
||||
'refund_amount' => $refundAmount !== null ? $refundAmount : $row['refund_amount'],
|
||||
]);
|
||||
|
||||
// 状态流转或答复更新时,自动推送站内通知给申诉师傅
|
||||
if (($status !== $oldStatus || $reply !== $oldReply) && (int)$row['master_id'] > 0) {
|
||||
// 用户售后申诉仲裁完结且核定退款金额 > 0:执行微信原路退款(须在事务外调用微信接口,失败整体回滚申诉状态)
|
||||
if ($isAftersale && $status === 'done' && $refundAmount > 0) {
|
||||
try {
|
||||
$refundResult = \app\common\library\PaymentService::refundOrderPartial((int)$row['order_id'], $refundAmount, '售后仲裁退款(申诉单#' . $row['id'] . '):' . $reply);
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
$this->error('售后仲裁退款执行失败,仲裁结果未生效:' . $e->getMessage());
|
||||
return;
|
||||
}
|
||||
// 按流水真实退款状态同步订单退款字段
|
||||
$allRows = Db::name('pay_order')
|
||||
->where('order_id', (int)$row['order_id'])
|
||||
->whereIn('status', ['paid', 'refunding', 'refunded', 'refund_failed'])
|
||||
->select();
|
||||
$sumRefund = 0.00;
|
||||
$hasLeft = false;
|
||||
foreach ($allRows as $item) {
|
||||
$sumRefund = round($sumRefund + (float)$item['refund_amount'], 2);
|
||||
if (round((float)$item['amount'] - (float)$item['refund_amount'], 2) > 0) {
|
||||
$hasLeft = true;
|
||||
}
|
||||
}
|
||||
Db::name('order')->where('id', (int)$row['order_id'])->update([
|
||||
'pay_status' => $hasLeft ? 1 : 2,
|
||||
'refund_amount' => $sumRefund,
|
||||
'updatetime' => time(),
|
||||
]);
|
||||
Db::name('order_log')->insert([
|
||||
'order_id' => (int)$row['order_id'],
|
||||
'status' => 8,
|
||||
'remark' => mb_substr('售后仲裁完结并执行退款:申诉单#' . $row['id'] . '(本次 ¥' . $refundResult['refunded_total'] . ',订单累计已退 ¥' . $refundResult['order_refunded'] . ')。仲裁答复:' . $reply, 0, 255),
|
||||
'operator_type' => 'admin',
|
||||
'operator_id' => (int)$this->auth->id,
|
||||
'createtime' => time(),
|
||||
]);
|
||||
}
|
||||
|
||||
// 状态流转或答复更新时,自动推送站内通知(师傅申诉通知师傅 / 用户售后通知用户)
|
||||
if ($status !== $oldStatus || $reply !== $oldReply) {
|
||||
$statusText = $statusList[$status] ?? $status;
|
||||
$orderNo = '';
|
||||
if ((int)$row['order_id'] > 0) {
|
||||
$orderNo = (string)Db::name('order')->where('id', (int)$row['order_id'])->value('order_no');
|
||||
}
|
||||
$msgTitle = '申诉工单处理通知(' . $statusText . ')';
|
||||
$msgContent = ($orderNo !== '' ? '关联订单 ' . $orderNo . ' 的' : '您的') . '申诉状态已更新为「' . $statusText . '」';
|
||||
if ($reply !== '') {
|
||||
$msgContent .= '。平台答复:' . $reply;
|
||||
if ($isAftersale) {
|
||||
$msgTitle = '售后申请处理通知(' . $statusText . ')';
|
||||
$msgContent = ($orderNo !== '' ? '订单 ' . $orderNo . ' 的' : '您的') . '售后申请状态已更新为「' . $statusText . '」';
|
||||
if ($refundAmount !== null && $status === 'done') {
|
||||
$msgContent .= $refundAmount > 0
|
||||
? ',平台核定退款 ¥' . $refundAmount . ',已提交微信原路退回您的支付账户'
|
||||
: ',平台核定本次不予退款';
|
||||
}
|
||||
if ($reply !== '') {
|
||||
$msgContent .= '。平台答复:' . $reply;
|
||||
}
|
||||
$targetUid = (int)Db::name('user')->where('id', (int)$row['user_id'])->value('id');
|
||||
if ($targetUid > 0) {
|
||||
Db::name('message')->insert([
|
||||
'receive_type' => 'user',
|
||||
'receive_id' => $targetUid,
|
||||
'type' => 'order',
|
||||
'title' => mb_substr($msgTitle, 0, 100),
|
||||
'content' => mb_substr($msgContent, 0, 500),
|
||||
'order_id' => (int)$row['order_id'],
|
||||
'is_read' => 0,
|
||||
'createtime' => time(),
|
||||
]);
|
||||
}
|
||||
} elseif ((int)$row['master_id'] > 0) {
|
||||
$msgTitle = '申诉工单处理通知(' . $statusText . ')';
|
||||
$msgContent = ($orderNo !== '' ? '关联订单 ' . $orderNo . ' 的' : '您的') . '申诉状态已更新为「' . $statusText . '」';
|
||||
if ($reply !== '') {
|
||||
$msgContent .= '。平台答复:' . $reply;
|
||||
}
|
||||
Db::name('message')->insert([
|
||||
'receive_type' => 'master',
|
||||
'receive_id' => (int)$row['master_id'],
|
||||
'type' => 'audit',
|
||||
'title' => mb_substr($msgTitle, 0, 100),
|
||||
'content' => mb_substr($msgContent, 0, 500),
|
||||
'order_id' => (int)$row['order_id'],
|
||||
'is_read' => 0,
|
||||
'createtime' => time(),
|
||||
]);
|
||||
}
|
||||
Db::name('message')->insert([
|
||||
'receive_type' => 'master',
|
||||
'receive_id' => (int)$row['master_id'],
|
||||
'type' => 'audit',
|
||||
'title' => mb_substr($msgTitle, 0, 100),
|
||||
'content' => mb_substr($msgContent, 0, 500),
|
||||
'order_id' => (int)$row['order_id'],
|
||||
'is_read' => 0,
|
||||
'createtime' => time(),
|
||||
]);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
在新工单中引用
屏蔽一个用户