fix: 完善取消退款恢复与师傅端流程

这个提交包含在:
2026-11-19 17:53:12 +08:00
父节点 5dd04b2f24
当前提交 5db0e2240d
共有 29 个文件被更改,包括 594 次插入 和 94 次删除

查看文件

@@ -370,12 +370,6 @@ class Auth extends Base
if (!$master) {
$this->error('请先完成师傅入驻', ['need_apply' => 1], 2001);
}
if ($master['verify_status'] === 'pending') {
$this->error('师傅资质审核中,请耐心等待', ['verify_status' => 'pending'], 2002);
}
if ($master['verify_status'] === 'reject') {
$this->error('资质未通过:' . $master['audit_msg'], ['verify_status' => 'reject'], 2003);
}
}
if ($role === 'merchant') {

查看文件

@@ -51,20 +51,30 @@ class Base extends Api
}
/**
* 要求是已通过审核的师傅
* 要求拥有师傅档案,允许查看师傅端。
*/
protected function requireMaster()
protected function requireMasterProfile()
{
$master = $this->masterInfo();
if (!$master) {
$this->error('请先完成师傅入驻', ['need_apply' => 1], 2001);
}
return $master;
}
/** 要求师傅通过审核,供接单及敏感操作使用。 */
protected function requireMaster()
{
$master = $this->requireMasterProfile();
if ($master['verify_status'] === 'pending') {
$this->error('师傅资质审核中,请耐心等待', ['verify_status' => 'pending'], 2002);
}
if ($master['verify_status'] === 'reject') {
$this->error('资质未通过:' . $master['audit_msg'], ['verify_status' => 'reject'], 2003);
}
if ($master['verify_status'] !== 'pass') {
$this->error('师傅资质尚未审核通过,无法接单');
}
return $master;
}
@@ -145,7 +155,10 @@ class Base extends Api
'status' => (int)$to,
'updatetime' => time(),
]);
Db::name('order')->where('id', (int)$order['id'])->update($data);
$updated = Db::name('order')->where('id', (int)$order['id'])->where('status', $from)->update($data);
if (!$updated) {
$this->error('订单状态已变更,请刷新后重试');
}
$this->addLog((int)$order['id'], (int)$to, $remark, $operatorType, $operatorId);
return array_merge($order, $data);
}

查看文件

@@ -4,6 +4,7 @@ namespace app\api\controller;
use app\common\library\CommissionService;
use app\common\library\FinanceConfigService;
use app\common\library\FinishImageUrls;
use app\common\library\OrderStatus;
use app\common\library\PaymentService;
use app\common\library\TiandituService;
@@ -98,11 +99,9 @@ class Master extends Base
}
// 若是驳回后重提且未修改脱敏展示号,沿用原存储的完整身份证号;否则校验完整身份证号并真实入库
$needVerify = true;
if (strpos($rawIdcard, '*') !== false) {
if ($exist && !empty($exist['idcard_no']) && strpos((string)$exist['idcard_no'], '*') === false) {
$finalIdcard = (string)$exist['idcard_no'];
$needVerify = false;
} else {
$this->error('请填写真实完整的18位身份证号码');
return;
@@ -125,12 +124,10 @@ class Master extends Base
}
// 腾讯云公安权威二要素实名核验(姓名 + 身份证号)
if ($needVerify) {
$verifyRes = TencentVerifyService::verifyIdCard($realname, $finalIdcard);
if (!$verifyRes['pass']) {
$this->error('实名核验未通过:' . $verifyRes['msg']);
return;
}
$verifyRes = TencentVerifyService::verifyIdCard($realname, $finalIdcard);
if (!$verifyRes['pass']) {
$this->error('实名核验未通过:' . $verifyRes['msg']);
return;
}
$catNameMap = Db::name('service_cat')->where('id', 'in', $skillCatIds)->column('name', 'id');
@@ -144,9 +141,10 @@ class Master extends Base
'cert_images' => $certImages,
'city' => $normalizedCity,
'work_status' => 'off',
'verify_status' => 'pass',
'audit_msg' => '腾讯云二要素实名核验通过',
'audittime' => time(),
'verify_status' => 'pending',
'audit_msg' => '',
'audittime' => null,
'audit_admin_id' => 0,
'updatetime' => time(),
];
@@ -180,7 +178,7 @@ class Master extends Base
$this->error('提交失败:' . $e->getMessage());
}
$this->success('实名认证成功,已获得接单资格!', ['master_id' => (int)$masterId]);
$this->success('申请已提交,请等待后台审核', ['master_id' => (int)$masterId, 'verify_status' => 'pending']);
}
/**
@@ -312,7 +310,7 @@ class Master extends Base
*/
public function updateLocation()
{
$master = $this->requireMaster();
$master = $this->requireMasterProfile();
$rawLat = $this->request->post('lat', '');
$rawLng = $this->request->post('lng', '');
if (!$this->isValidCoord($rawLat, $rawLng)) {
@@ -389,7 +387,7 @@ class Master extends Base
*/
public function searchLocation()
{
$this->requireMaster();
$this->requireMasterProfile();
$keyword = trim((string)$this->request->param('keyword', ''));
if (mb_strlen($keyword) < 2) {
$this->success('', ['list' => []]);
@@ -410,7 +408,7 @@ class Master extends Base
*/
public function locationContext()
{
$master = $this->requireMaster();
$master = $this->requireMasterProfile();
$rawLat = $this->request->param('lat', '');
$rawLng = $this->request->param('lng', '');
$category = trim((string)$this->request->param('category', 'all'));
@@ -473,7 +471,7 @@ class Master extends Base
*/
public function locationOrderStats()
{
$master = $this->requireMaster();
$master = $this->requireMasterProfile();
$rawLat = $this->request->param('lat', '');
$rawLng = $this->request->param('lng', '');
$city = trim((string)$this->request->param('city', ''));
@@ -496,7 +494,7 @@ class Master extends Base
*/
public function locateCity()
{
$this->requireMaster();
$this->requireMasterProfile();
$city = trim((string)$this->request->param('city', ''));
if ($city === '') {
$this->error('请提供城市名称');
@@ -529,7 +527,7 @@ class Master extends Base
*/
public function hall()
{
$master = $this->requireMaster();
$master = $this->requireMasterProfile();
$this->recycleExpired();
$catIds = $this->getMasterSkillCatIds((int)$master['id']);
@@ -989,7 +987,7 @@ class Master extends Base
public function finish()
{
$order = $this->ownOrder((int)$this->request->post('order_id'), 'master');
$images = (array)$this->request->post('images/a', []);
$images = FinishImageUrls::normalize((array)$this->request->post('images/a', []));
$damage = trim((string)$this->request->post('damage_remark', ''));
Db::startTrans();
@@ -1142,7 +1140,7 @@ class Master extends Base
public function orders()
{
$master = $this->requireMaster();
$master = $this->requireMasterProfile();
$status = $this->request->param('status', 'active');
$page = max(1, (int)$this->request->param('page', 1));
$limit = min(30, max(1, (int)$this->request->param('limit', 10)));
@@ -1198,7 +1196,7 @@ class Master extends Base
*/
public function income()
{
$master = $this->requireMaster();
$master = $this->requireMasterProfile();
// 顺带轻量同步最新 3 笔处理中的微信转账提现单(如师傅上次已确认收款但未回调或超时自动退回)
$syncCandidates = Db::name('withdraw')
@@ -1637,7 +1635,7 @@ class Master extends Base
*/
public function credit()
{
$master = $this->requireMaster();
$master = $this->requireMasterProfile();
$mid = (int)$master['id'];
$reviewTotal = (int)Db::name('review')->where('master_id', $mid)->where('status', 'normal')->count();
@@ -1671,7 +1669,7 @@ class Master extends Base
*/
public function appeals()
{
$master = $this->requireMaster();
$master = $this->requireMasterProfile();
$list = Db::name('appeal')->where('master_id', $master['id'])->order('id desc')->limit(30)->select();
$typeText = ['misjudge' => '误判申诉', 'review' => '恶意评价', 'deduct' => '扣款申诉', 'other' => '其他'];
$statusText = ['wait' => '待处理', 'handling' => '处理中', 'done' => '已处理', 'reject' => '已驳回'];
@@ -1749,7 +1747,7 @@ class Master extends Base
*/
public function quotes()
{
$master = $this->requireMaster();
$master = $this->requireMasterProfile();
$list = Db::name('order_quote')->alias('q')
->join('order o', 'o.id = q.order_id', 'LEFT')
->field('q.*, o.order_no, o.service_name, o.pay_amount as order_amount, o.status as order_status')
@@ -1994,7 +1992,7 @@ class Master extends Base
public function orderDetail()
{
$master = $this->requireMaster();
$master = $this->requireMasterProfile();
$masterId = (int)$master['id'];
$orderId = (int)$this->request->param('id') ?: (int)$this->request->param('order_id');
if ($orderId <= 0) {
@@ -2579,7 +2577,7 @@ class Master extends Base
*/
public function saveSkills()
{
$master = $this->requireMaster();
$master = $this->requireMasterProfile();
$masterId = (int)$master['id'];
// 同时兼容 skill_ids(ID 数组/逗号串/JSON串)与 selected_skills(名称数组/逗号串/JSON串)

查看文件

@@ -1309,18 +1309,6 @@ class Order extends Base
$this->error('该订单已开具发票,如需取消退款请联系客服办理发票冲红');
}
// 若订单已支付,先在数据库事务外部调用微信支付 APIv3 逐笔发起原路退款(无有效流水严格拦截,严禁静默跳过)
$refundedAmount = 0.00;
if ((int)$order['pay_status'] === 1) {
try {
$refundedAmount = PaymentService::refundOrder($orderId, '用户取消:' . $reason);
} catch (\Throwable $re) {
\think\Log::error('[Order::cancel refund] order_id=' . $orderId . ' reason=' . $re->getMessage());
$this->error('申请微信原路退款失败:' . $re->getMessage());
return;
}
}
$prevMasterId = 0;
Db::startTrans();
try {
@@ -1328,12 +1316,18 @@ class Order extends Base
if (!$lockedOrder || !OrderStatus::canCancelByUser($lockedOrder['status'])) {
throw new \InvalidArgumentException('当前状态不可取消,请刷新重试');
}
if (isset($lockedOrder['invoice_status']) && in_array($lockedOrder['invoice_status'], ['wait', 'issued'], true)) {
throw new \InvalidArgumentException('订单开票状态已变更,请刷新后重试');
}
if ((int)$lockedOrder['pay_status'] === 1 && (float)$lockedOrder['pay_amount'] > 0) {
$paymentAmount = (float)Db::name('pay_order')->where('order_id', $orderId)
->whereIn('status', ['paid', 'refunding', 'refunded', 'refund_failed'])->sum('amount');
if ($paymentAmount + 0.005 < (float)$lockedOrder['pay_amount']) {
throw new \InvalidArgumentException('支付流水金额不足,请联系客服核实后取消');
}
}
$prevMasterId = (int)$lockedOrder['master_id'];
$extra = ['cancel_reason' => mb_substr($reason, 0, 255)];
if ((int)$lockedOrder['pay_status'] === 1) {
$extra['pay_status'] = 2;
$extra['refund_amount'] = $refundedAmount > 0 ? $refundedAmount : (float)$lockedOrder['pay_amount'];
}
$this->transit($lockedOrder, OrderStatus::CANCELLED, '用户取消:' . $reason, $extra, 'user', $this->uid());
if ((int)$lockedOrder['coupon_id'] > 0) {
@@ -1370,6 +1364,19 @@ class Order extends Base
return;
}
if ((int)$lockedOrder['pay_status'] === 1 && (float)$lockedOrder['pay_amount'] > 0) {
try {
PaymentService::refundOrder($orderId, '用户取消:' . $reason);
PaymentService::syncCancelledOrderRefund($orderId);
} catch (\Throwable $re) {
\think\Log::error('[Order::cancel refund] order_id=' . $orderId . ' reason=' . $re->getMessage());
PaymentService::syncCancelledOrderRefund($orderId);
$this->success('订单已取消,退款申请异常,请联系客服处理');
return;
}
$this->success('订单已取消,退款已申请,请留意退款进度');
return;
}
$this->success('订单已取消');
}
@@ -1614,7 +1621,16 @@ class Order extends Base
$statusTimelineText = OrderStatus::tip($status);
$statusTime = !empty($row['updatetime']) ? (int)$row['updatetime'] : (int)$row['createtime'];
if ($status === OrderStatus::CANCELLED) {
$statusTimelineText = ((int)$row['pay_status'] === 0) ? '订单未支付,您已取消订单' : '订单已取消,退款处理中';
$refundRows = Db::name('pay_order')->where('order_id', (int)$row['id'])
->whereIn('status', ['paid', 'refunding', 'refunded', 'refund_failed'])->select();
$refundSummary = \app\common\library\CancelRefundSummary::summarize($refundRows);
if ($refundSummary['state'] === 'missing') {
$statusTimelineText = ((int)$row['pay_status'] === 0 || (float)$row['pay_amount'] <= 0)
? '订单已取消' : '订单已取消,退款异常,请联系客服';
} else {
$refundTips = ['success' => '订单已取消,退款成功', 'processing' => '订单已取消,退款处理中', 'failed' => '订单已取消,退款异常,请联系客服'];
$statusTimelineText = $refundTips[$refundSummary['state']];
}
} elseif ($status === OrderStatus::PENDING_PAY) {
$statusTimelineText = '订单待支付,请尽快完成支付';
} elseif ($status === OrderStatus::PENDING_ACCEPT) {

查看文件

@@ -74,9 +74,11 @@ class Wxpay extends Api
try {
PaymentService::applyWxRefundResult($po, $data);
PaymentService::syncCancelledOrderRefund((int)$po['order_id']);
} catch (\Throwable $refundEx) {
// 若微信已下发明确退款异常/关闭终态,系统已完整落库记录原因并写入告警日志,向微信回传成功避免重复轰炸
if (in_array($refStatus, ['ABNORMAL', 'CLOSED'], true)) {
if (in_array($refStatus, ['ABNORMAL', 'CLOSED'], true) && (int)$refundEx->getCode() === 10001) {
PaymentService::syncCancelledOrderRefund((int)$po['order_id']);
Log::error("[Wxpay::refundNotify] 退款终态异常已落库 out_trade_no={$po['out_trade_no']}, status={$refStatus}, reason=" . $refundEx->getMessage());
return $this->wxResponse(true);
}