feat: 新增师傅入驻审核与接单状态联动功能
- 新增师傅资质审核模块及权限 - 未审核通过的师傅默认禁用接单状态 - 新增售后退款申诉功能与相关界面 - 新增用户钱包管理及充值功能 - 更新服务定价矩阵相关数据库结构 - 修复微信支付证书验证问题
这个提交包含在:
@@ -720,4 +720,130 @@ class Order extends Backend
|
||||
$refundLabel = \app\common\library\PaymentService::refundStatusLabel($after['refund_status'] ?? 'none');
|
||||
$this->success('微信原路退款请求已提交,当前状态:' . $statusLabel . '(' . $refundLabel . ')');
|
||||
}
|
||||
|
||||
/**
|
||||
* 售后退款工作台:展示订单支付流水与可退余额,支持全额/指定金额微信原路退款
|
||||
* GET 渲染弹窗表单;POST 执行退款(必须在数据库事务外部远程调用微信接口)
|
||||
*/
|
||||
public function aftersale($ids = null)
|
||||
{
|
||||
$orderId = (int)$ids;
|
||||
$order = $this->model->with(['user', 'master'])->where('order.id', $orderId)->find();
|
||||
if (!$order) {
|
||||
$this->error(__('No Results were found'));
|
||||
}
|
||||
|
||||
$payRows = Db::name('pay_order')
|
||||
->where('order_id', $orderId)
|
||||
->whereIn('status', ['paid', 'refunding', 'refunded', 'refund_failed'])
|
||||
->order('id asc')
|
||||
->select();
|
||||
|
||||
$orderRefunded = 0.00;
|
||||
$orderRefundable = 0.00;
|
||||
foreach ($payRows as &$po) {
|
||||
$po['status_text'] = \app\common\library\PaymentService::payOrderStatusLabel($po['status']);
|
||||
$po['refund_total'] = round((float)$po['refund_amount'], 2);
|
||||
$po['refund_left'] = round((float)$po['amount'] - (float)$po['refund_amount'], 2);
|
||||
$orderRefunded = round($orderRefunded + $po['refund_total'], 2);
|
||||
$orderRefundable = round($orderRefundable + max($po['refund_left'], 0), 2);
|
||||
}
|
||||
unset($po);
|
||||
|
||||
// mock/月结等线下渠道订单无微信支付流水:可退余额按订单实付额展示,但执行阶段仍拦截(无法线上原路退款)
|
||||
$hasWxPayRows = !empty($payRows);
|
||||
if (!$hasWxPayRows) {
|
||||
$orderRefundable = round((float)$order['pay_amount'], 2);
|
||||
}
|
||||
|
||||
if (!$this->request->isPost()) {
|
||||
// 前置资损校验(展示阶段即告知不可退原因)
|
||||
$blockReason = '';
|
||||
if ((int)$order['pay_status'] !== 1) {
|
||||
$blockReason = (int)$order['pay_status'] === 2 ? '该订单已完成退款' : '该订单尚未支付,无需退款';
|
||||
} elseif ((int)$order['settle_status'] === 1) {
|
||||
$blockReason = '该工单已完成向师傅结算分账,不允许售后退款(请先与师傅线下协商追回)';
|
||||
} elseif (!$hasWxPayRows) {
|
||||
$blockReason = '该订单为 mock/月结等线下渠道支付,无微信支付流水,无法线上原路退款,请联系财务线下人工处理并登记';
|
||||
} elseif ($orderRefundable <= 0) {
|
||||
$blockReason = '该订单的支付流水已全部退款,无可退余额';
|
||||
}
|
||||
$this->view->assign('row', $order);
|
||||
$this->view->assign('payRows', $payRows);
|
||||
$this->view->assign('orderRefunded', $orderRefunded);
|
||||
$this->view->assign('orderRefundable', $orderRefundable);
|
||||
$this->view->assign('blockReason', $blockReason);
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
if ((int)$order['settle_status'] === 1) {
|
||||
$this->error('该工单已完成向师傅结算分账,不允许售后退款(请先与师傅线下协商追回)');
|
||||
}
|
||||
if (!$hasWxPayRows) {
|
||||
$this->error('该订单为 mock/月结等线下渠道支付,无微信支付流水,无法线上原路退款,请线下人工处理并登记');
|
||||
}
|
||||
if ($orderRefundable <= 0) {
|
||||
$this->error('该订单的支付流水已全部退款,无可退余额');
|
||||
}
|
||||
|
||||
$refundAmount = $this->request->post('refund_amount/f', 0);
|
||||
$refundAmount = round((float)$refundAmount, 2);
|
||||
if ($refundAmount < 0) {
|
||||
$this->error('退款金额不能为负数');
|
||||
}
|
||||
if ($refundAmount > 0 && $refundAmount > $orderRefundable) {
|
||||
$this->error('退款金额不得超过当前可退余额 ¥' . $orderRefundable);
|
||||
}
|
||||
$reason = trim($this->request->post('reason/s', ''));
|
||||
if ($reason === '') {
|
||||
$this->error('请填写售后退款原因(将同步微信退款备注与工单日志)');
|
||||
}
|
||||
|
||||
try {
|
||||
$result = \app\common\library\PaymentService::refundOrderPartial($orderId, $refundAmount > 0 ? $refundAmount : null, '平台售后退款:' . $reason);
|
||||
} catch (\Throwable $e) {
|
||||
$this->error('售后退款执行失败:' . $e->getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
// 按流水真实退款状态汇总订单退款字段(全部有效流水退满才置为已退款)
|
||||
$allRows = Db::name('pay_order')
|
||||
->where('order_id', $orderId)
|
||||
->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', $orderId)->update([
|
||||
'pay_status' => $hasLeft ? (int)$order['pay_status'] : 2,
|
||||
'refund_amount' => $sumRefund,
|
||||
'updatetime' => time(),
|
||||
]);
|
||||
|
||||
Db::name('order_log')->insert([
|
||||
'order_id' => $orderId,
|
||||
'status' => (int)$order['status'],
|
||||
'remark' => mb_substr('平台售后退款:' . $reason . '(本次 ¥' . $result['refunded_total'] . ',累计已退 ¥' . $result['order_refunded'] . ')', 0, 255),
|
||||
'operator_type' => 'admin',
|
||||
'operator_id' => (int)$this->auth->id,
|
||||
'createtime' => time(),
|
||||
]);
|
||||
Db::name('message')->insert([
|
||||
'receive_type' => 'user',
|
||||
'receive_id' => (int)$order['user_id'],
|
||||
'type' => 'order',
|
||||
'order_id' => (string)$orderId,
|
||||
'title' => '售后退款处理通知',
|
||||
'content' => '您的订单【' . $order['order_no'] . '】平台已处理售后退款:本次退款 ¥' . $result['refunded_total'] . ',将按微信原路退回您的支付账户(累计已退 ¥' . $result['order_refunded'] . ')。退款原因:' . mb_substr($reason, 0, 120),
|
||||
'is_read' => 0,
|
||||
'createtime' => time(),
|
||||
]);
|
||||
|
||||
$this->success('售后退款已提交微信原路退回:本次 ¥' . $result['refunded_total'] . ',订单累计已退 ¥' . $result['order_refunded'] . '(处理中的退款单请稍后在退款台账中同步确认)');
|
||||
}
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户