文件
yjyf/server/application/admin/controller/PayOrder.php
MiAn 0370cb9bd6 feat: 新增师傅入驻审核与接单状态联动功能
- 新增师傅资质审核模块及权限
- 未审核通过的师傅默认禁用接单状态
- 新增售后退款申诉功能与相关界面
- 新增用户钱包管理及充值功能
- 更新服务定价矩阵相关数据库结构
- 修复微信支付证书验证问题
2026-11-17 10:28:01 +08:00

144 行
5.3 KiB
PHP

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<?php
namespace app\admin\controller;
use app\common\controller\Backend;
use app\common\library\PaymentService;
use think\Db;
use think\exception\PDOException;
/**
* 微信支付退款台账
*
* 展示全站微信支付流水(fa_pay_order)的支付/退款状态、网关回执与异常诊断,
* 提供人工同步微信退款状态与重发原路退款入口(复用 PaymentService 防资损校验)。
*
* @icon fa fa-undo
*/
class PayOrder extends Backend
{
/**
* PayOrder模型对象(只读台账,禁止新增/编辑/删除)
* @var \app\admin\model\PayOrder
*/
protected $model = null;
protected $relationSearch = true;
protected $searchFields = 'out_trade_no,refund_no,transaction_id,order.order_no,user.nickname,user.mobile';
protected $noNeedRight = [];
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\PayOrder;
$this->view->assign('statusList', $this->model->getStatusList());
$this->view->assign('refundStatusList', $this->model->getRefundStatusList());
$this->view->assign('sceneList', $this->model->getSceneList());
}
/**
* 退款台账列表(微信支付/退款流水全量)
*/
public function index()
{
$this->request->filter(['strip_tags', 'trim']);
if (false === $this->request->isAjax()) {
return $this->view->fetch();
}
[$where, $sort, $order, $offset, $limit] = $this->buildparams();
$list = $this->model
->with(['order', 'user'])
->where($where)
->order($sort, $order)
->paginate($limit);
$result = ['total' => $list->total(), 'rows' => $list->items()];
return json($result);
}
/**
* 主动向微信查询该笔流水的最新支付/退款状态并落库
*/
public function sync($ids = null)
{
$id = (int)$ids;
$po = Db::name('pay_order')->where('id', $id)->find();
if (!$po) {
$this->error(__('No Results were found'));
}
if (!in_array($po['status'], ['paid', 'refunding', 'refunded', 'refund_failed'], true)) {
$this->error('该流水当前状态(待支付/已关闭)无需同步');
}
try {
$after = PaymentService::syncRefundPayOrder($id);
} catch (\Throwable $e) {
$this->error('同步微信状态失败:' . $e->getMessage());
return;
}
$this->success('微信状态同步完成:' . PaymentService::payOrderStatusLabel($after['status'])
. '(退款' . PaymentService::refundStatusLabel($after['refund_status']) . ',累计已退 ¥' . $after['refund_amount'] . ')');
}
/**
* 对该笔流水重发/补发微信原路退款(自动退该笔剩余可退金额)
*/
public function retryrefund($ids = null)
{
$id = (int)$ids;
$po = Db::name('pay_order')->where('id', $id)->find();
if (!$po) {
$this->error(__('No Results were found'));
}
$left = round((float)$po['amount'] - (float)$po['refund_amount'], 2);
if ($left <= 0) {
$this->error('该流水可退余额为 0,无需再次退款');
}
try {
$after = PaymentService::refundSinglePayOrder($id, '平台人工重发原路退款(退款台账)');
} catch (\Throwable $e) {
$this->error('重发退款失败:' . $e->getMessage());
return;
}
$statusLabel = PaymentService::payOrderStatusLabel($after['status'] ?? '');
$refundLabel = PaymentService::refundStatusLabel($after['refund_status'] ?? 'none');
$this->success('退款请求已提交:' . $statusLabel . '(' . $refundLabel . ',累计已退 ¥' . $after['refund_amount'] . ')');
}
/**
* 流水详情弹窗(微信网关回执、异常诊断、关联订单)
*/
public function detail($ids = null)
{
$row = Db::name('pay_order')->where('id', (int)$ids)->find();
if (!$row) {
$this->error(__('No Results were found'));
}
$order = Db::name('order')->where('id', (int)$row['order_id'])->field('id,order_no,service_name,pay_amount,pay_type,status,user_id')->find();
$user = $order ? Db::name('user')->where('id', (int)$order['user_id'])->field('id,nickname,username,mobile')->find() : null;
$this->view->assign('row', $row);
$this->view->assign('order', $order ?: []);
$this->view->assign('user', $user ?: []);
$this->view->assign('statusText', PaymentService::payOrderStatusLabel($row['status']));
$this->view->assign('refundStatusText', PaymentService::refundStatusLabel($row['refund_status']));
return $this->view->fetch();
}
/**
* 台账为审计数据,禁止后台手工新增/编辑/删除
*/
public function add()
{
$this->error('支付流水由交易系统自动生成,禁止手工新增');
}
public function edit($ids = null)
{
$this->error('支付流水不可手工编辑,如需退款请使用行内"同步/重发退款"操作');
}
public function del($ids = null)
{
$this->error('支付流水为资金审计数据,禁止删除');
}
}