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

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

查看文件

@@ -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();

查看文件

@@ -113,8 +113,11 @@ class Index extends Backend
Session::delete("referer");
$this->redirect($url);
}
$background = Config::get('fastadmin.login_background');
$background = Config::get('site.login_background') ?: Config::get('fastadmin.login_background');
$background = $background ? (stripos($background, 'http') === 0 ? $background : config('site.cdnurl') . $background) : '';
if (!$background) {
$background = '/assets/img/login_bg_modern.png';
}
$this->view->assign('keeyloginhours', $keeyloginhours);
$this->view->assign('background', $background);
$this->view->assign('title', __('Login'));

查看文件

@@ -170,8 +170,15 @@ class Master extends Backend
unset($params['city']);
}
if (isset($params['verify_status']) && $params['verify_status'] === 'reject' && empty(trim((string)($params['audit_msg'] ?? '')))) {
$this->error('驳回实名认证时请填写审核意见说明');
if (isset($params['verify_status']) && $params['verify_status'] === 'reject') {
if (empty(trim((string)($params['audit_msg'] ?? '')))) {
$this->error('驳回实名认证时请填写审核意见说明');
}
$params['work_status'] = 'off';
}
if (isset($params['verify_status']) && in_array($params['verify_status'], ['pass', 'reject'], true)) {
$params['audittime'] = time();
$params['audit_admin_id'] = (int)$this->auth->id;
}
$result = false;
Db::startTrans();
@@ -454,4 +461,201 @@ class Master extends Backend
return $this->view->fetch();
}
/**
* 师傅入驻资质审核
*/
public function audit($ids = null)
{
$id = (int)($ids ?: $this->request->param('ids'));
$row = $this->model->with(['user'])->where('master.id', $id)->find();
if (!$row) {
$this->error(__('No Results were found'));
}
if (false === $this->request->isPost()) {
// 查询关联服务技能
$skills = Db::name('master_skill')
->alias('s')
->join('service_cat c', 'c.id = s.cat_id', 'LEFT')
->where('s.master_id', $row['id'])
->field('s.*, c.name as cat_name')
->select();
// 查询技能证书
$certs = Db::name('master_cert')
->field('id,cert_name,is_custom,cert_image,expire_date,is_long_term,status,audit_msg')
->where('master_id', $row['id'])
->order('id desc')
->select();
// 证件防伪水印处理
if (!empty($row['idcard_front'])) {
$row['idcard_front_watermark'] = \app\common\library\TencentVerifyService::getWatermarkUrl($row['idcard_front']);
}
if (!empty($row['idcard_back'])) {
$row['idcard_back_watermark'] = \app\common\library\TencentVerifyService::getWatermarkUrl($row['idcard_back']);
}
$this->view->assign([
'row' => $row,
'skills' => $skills,
'certs' => $certs,
]);
return $this->view->fetch('audit');
}
$params = $this->request->post('row/a', []);
if (empty($params)) {
$this->error(__('Parameter %s can not be empty', ''));
}
$verifyStatus = trim((string)($params['verify_status'] ?? ''));
$auditMsg = trim((string)($params['audit_msg'] ?? ''));
$level = max(1, (int)($params['level'] ?? $row['level'] ?? 1));
if (!in_array($verifyStatus, ['pass', 'reject'], true)) {
$this->error('请选择有效的审核结果(通过或驳回)');
}
if ($verifyStatus === 'reject' && $auditMsg === '') {
$this->error('驳回入驻申请时,必须填写驳回原因说明');
}
$now = time();
$adminId = (int)$this->auth->id;
$updateData = [
'verify_status' => $verifyStatus,
'audit_msg' => $auditMsg,
'level' => $level,
'audittime' => $now,
'audit_admin_id' => $adminId,
'updatetime' => $now,
];
// 若驳回,出工状态必须设为 off
if ($verifyStatus === 'reject') {
$updateData['work_status'] = 'off';
}
Db::startTrans();
try {
Db::name('master')->where('id', $row['id'])->update($updateData);
// 发送审核结果通知给师傅和用户
$title = $verifyStatus === 'pass' ? '师傅入驻审核通过' : '师傅入驻审核未通过';
$content = $verifyStatus === 'pass'
? '恭喜您!您的师傅入驻与实名认证已审核通过,已获得接单资格,现在可开启听单承接同城订单。'
: ('您的师傅入驻认证申请未通过,原因:' . ($auditMsg ?: '证件材料不符合规范,请重新核对后提交。'));
Db::name('message')->insert([
'receive_type' => 'master',
'receive_id' => (int)$row['id'],
'type' => 'audit',
'title' => $title,
'content' => $content,
'order_id' => 0,
'is_read' => 0,
'createtime' => $now,
]);
if ((int)$row['user_id'] > 0) {
Db::name('message')->insert([
'receive_type' => 'user',
'receive_id' => (int)$row['user_id'],
'type' => 'audit',
'title' => $title,
'content' => $content,
'order_id' => 0,
'is_read' => 0,
'createtime' => $now,
]);
}
Db::commit();
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
$this->success('入驻审核处理成功');
}
/**
* 批量快捷审核通过
*/
public function batch_pass()
{
if (false === $this->request->isPost()) {
$this->error(__('Invalid parameters'));
}
$ids = $this->request->post('ids');
$idArr = array_values(array_filter(array_map('intval', explode(',', (string)$ids))));
if (!$idArr) {
$this->error(__('Parameter %s can not be empty', 'ids'));
}
$pendingMasters = Db::name('master')
->where('id', 'in', $idArr)
->where('verify_status', 'pending')
->select();
if (empty($pendingMasters)) {
$this->error('所选记录中没有待审核的师傅档案');
}
$now = time();
$adminId = (int)$this->auth->id;
Db::startTrans();
try {
$targetIds = array_column($pendingMasters, 'id');
Db::name('master')->where('id', 'in', $targetIds)->update([
'verify_status' => 'pass',
'audit_msg' => '管理员批量审核通过',
'audittime' => $now,
'audit_admin_id' => $adminId,
'updatetime' => $now,
]);
foreach ($pendingMasters as $m) {
$mId = (int)$m['id'];
$uId = (int)$m['user_id'];
$title = '师傅入驻审核通过';
$content = '恭喜您!您的师傅入驻与实名认证已审核通过,已获得接单资格,现在可开启听单承接同城订单。';
Db::name('message')->insert([
'receive_type' => 'master',
'receive_id' => $mId,
'type' => 'audit',
'title' => $title,
'content' => $content,
'order_id' => 0,
'is_read' => 0,
'createtime' => $now,
]);
if ($uId > 0) {
Db::name('message')->insert([
'receive_type' => 'user',
'receive_id' => $uId,
'type' => 'audit',
'title' => $title,
'content' => $content,
'order_id' => 0,
'is_read' => 0,
'createtime' => $now,
]);
}
}
Db::commit();
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
$this->success('已成功批量审核通过 ' . count($pendingMasters) . ' 位师傅');
}
}

查看文件

@@ -148,6 +148,23 @@ class Merchant extends Backend
if (Db::name('merchant')->where('user_id', $uid)->count() > 0) {
$this->error('该用户账号已绑定企业商家主体,请勿重复创建');
}
// 统一社会信用代码唯一性校验,防止同一企业重复建档(兼容历史数据大小写差异)
$licenseNo = strtoupper(trim((string)($params['license_no'] ?? '')));
$licenseRaw = trim((string)($params['license_no'] ?? ''));
if ($licenseNo !== '') {
$dupLicense = Db::name('merchant')
->where(function ($q) use ($licenseNo, $licenseRaw) {
$q->where('license_no', $licenseNo)->whereOr('license_no', $licenseRaw);
})
->order('id', 'asc')
->find();
if ($dupLicense) {
$this->error('统一社会信用代码已绑定企业【' . $dupLicense['name'] . '】,同一企业请勿重复建档');
}
}
if ($licenseNo !== '') {
$params['license_no'] = $licenseNo;
}
$params['order_count'] = 0;
$params['total_amount'] = 0.00;
if (($params['verify_status'] ?? '') === 'reject' && empty(trim((string)($params['audit_msg'] ?? '')))) {
@@ -228,6 +245,24 @@ class Merchant extends Backend
if (isset($params['verify_status']) && $params['verify_status'] === 'reject' && empty(trim((string)($params['audit_msg'] ?? '')))) {
$this->error('驳回企业入驻时请填写审核驳回原因');
}
// 统一社会信用代码唯一性校验(排除自身,兼容历史数据大小写差异)
if (array_key_exists('license_no', $params)) {
$licenseNo = strtoupper(trim((string)$params['license_no']));
$licenseRaw = trim((string)$params['license_no']);
if ($licenseNo !== '') {
$dupLicense = Db::name('merchant')
->where('id', '<>', (int)$row['id'])
->where(function ($q) use ($licenseNo, $licenseRaw) {
$q->where('license_no', $licenseNo)->whereOr('license_no', $licenseRaw);
})
->order('id', 'asc')
->find();
if ($dupLicense) {
$this->error('统一社会信用代码已绑定企业【' . $dupLicense['name'] . '】,同一企业请勿重复建档');
}
$params['license_no'] = $licenseNo;
}
}
$result = false;
Db::startTrans();
try {

查看文件

@@ -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'] . '(处理中的退款单请稍后在退款台账中同步确认)');
}
}

查看文件

@@ -0,0 +1,143 @@
<?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('支付流水为资金审计数据,禁止删除');
}
}

查看文件

@@ -0,0 +1,56 @@
<?php
namespace app\admin\controller;
use app\common\controller\Backend;
use app\common\library\FinanceConfigService;
/**
* 用户钱包充值配置中心
*
* 统一管理:
* 1. 用户钱包在线充值总开关与停服提示
* 2. 充值快捷面额选项与默认选中项
* 3. 单笔最低/最高充值限额与单日累计限额
* 4. 钱包主页安全保障提示与充值服务规则文案
*
* @icon fa fa-money
*/
class RechargeConfig extends Backend
{
protected $noNeedRight = [];
/**
* 充值配置首页
*/
public function index()
{
$cfg = FinanceConfigService::getRechargeConfig();
$this->view->assign('cfg', $cfg);
return $this->view->fetch();
}
/**
* 保存充值配置
*/
public function save()
{
if ($this->request->isPost()) {
$params = $this->request->post('row/a', []);
if (empty($params)) {
$this->error('未获取到需要保存的配置参数');
}
try {
FinanceConfigService::saveConfigs($params);
$this->success('充值配置已成功保存并即时生效');
} catch (\InvalidArgumentException $e) {
$this->error($e->getMessage());
} catch (\Throwable $e) {
\think\Log::error('[RechargeConfig::save] ' . $e->getMessage());
$this->error('保存配置失败:' . $e->getMessage());
}
}
$this->error('非法请求');
}
}

查看文件

@@ -46,17 +46,69 @@ class Service extends Backend
->order('weigh desc, id asc')
->select();
$this->view->assign('catList', $cats);
$catSearchList = [];
foreach ($cats as $c) {
$catSearchList[$c['id']] = $c['name'];
}
$this->view->assign('catSearchList', json_encode($catSearchList, JSON_UNESCAPED_UNICODE));
// 统计核心运营维度指标(明码标价体系,聚焦规格覆盖、增项覆盖与上下架状态)
$stats = [
'total' => (int)Db::name('service')->count(),
'normal' => (int)Db::name('service')->where('status', 'normal')->count(),
'has_spec' => (int)Db::name('service')->whereIn('id', function ($q) {
$q->name('service_spec')->where('status', 'normal')->field('service_id');
})->count(),
'has_addon' => (int)Db::name('service')->where('addons', '<>', '[]')->whereNotNull('addons')->where('addons', '<>', '')->count(),
'hidden' => (int)Db::name('service')->where('status', 'hidden')->count(),
];
$this->view->assign('stats', $stats);
return $this->view->fetch();
}
if ($this->request->request('keyField')) {
return $this->selectpage();
}
[$where, $sort, $order, $offset, $limit] = $this->buildparams();
$list = $this->model
->with(['cat'])
->where($where)
->order($sort, $order)
->paginate($limit);
$query = $this->model->with(['cat'])->where($where);
// 1. 扩展工项支持筛选(如 install/repair/remove 等)
$workCode = trim((string)$this->request->get('work_code', ''));
if ($workCode !== '') {
$query->where('service.service_types', 'like', '%"code":"' . addslashes($workCode) . '"%');
}
// 2. 计价模式筛选(fixed 一口价 / quote 师傅报价)
$priceType = trim((string)$this->request->get('price_type', ''));
if ($priceType !== '') {
$query->where('service.price_type', $priceType);
}
// 2. 细分规格配置状态筛选
$hasSpec = (string)$this->request->get('has_spec', '');
if ($hasSpec === '1') {
$query->whereIn('service.id', function ($q) {
$q->name('service_spec')->where('status', 'normal')->field('service_id');
});
} elseif ($hasSpec === '0') {
$query->whereNotIn('service.id', function ($q) {
$q->name('service_spec')->where('status', 'normal')->field('service_id');
});
}
// 3. 增值服务配置状态筛选
$hasAddon = (string)$this->request->get('has_addon', '');
if ($hasAddon === '1') {
$query->where('service.addons', '<>', '[]')->whereNotNull('service.addons')->where('service.addons', '<>', '');
} elseif ($hasAddon === '0') {
$query->where(function ($q) {
$q->whereNull('service.addons')->whereOr('service.addons', '[]')->whereOr('service.addons', '');
});
}
$list = $query->order($sort, $order)->paginate($limit);
$rows = $list->items();
if (!empty($rows)) {
@@ -66,7 +118,7 @@ class Service extends Backend
}
// 一次性批量查询当前页商品的细分规格,避免 N+1 查询
$allSpecs = Db::name('service_spec')
->field('id,service_id,name,base_price,description')
->field('id,service_id,name,base_price,service_prices,description')
->where('service_id', 'in', $serviceIds)
->where('status', 'normal')
->order('weigh desc, id asc')
@@ -77,8 +129,19 @@ class Service extends Backend
if (!isset($specMap[$sid])) {
$specMap[$sid] = [];
}
$pricesMap = !empty($sp['service_prices']) ? (json_decode($sp['service_prices'], true) ?: []) : [];
$spPrice = (float)$sp['base_price'];
$specMap[$sid][] = $spPrice > 0 ? ($sp['name'] . '(¥' . round($spPrice) . ')') : $sp['name'];
if (!empty($pricesMap)) {
$priceTips = [];
foreach ($pricesMap as $pCode => $pVal) {
$priceTips[] = $pCode . ':¥' . round($pVal);
}
$specMap[$sid][] = $sp['name'] . ' (' . implode(',', $priceTips) . ')';
} elseif ($spPrice > 0) {
$specMap[$sid][] = $sp['name'] . '(¥' . round($spPrice) . ')';
} else {
$specMap[$sid][] = $sp['name'];
}
}
foreach ($rows as &$r) {
$sid = (int)$r['id'];
@@ -144,6 +207,259 @@ class Service extends Backend
return $this->view->fetch();
}
/**
* 独立弹窗:配置主服务工项及基准价格与规格专属价格
*/
public function pricing_main($ids = null)
{
$row = $this->model->get($ids);
if (!$row) {
$this->error(__('No Results were found'));
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
if ($this->request->isPost()) {
$serviceTypesRaw = $this->request->post("service_types_raw");
$specPricesInput = $this->request->post("spec_prices/a", []);
$parsedTypes = [];
if ($serviceTypesRaw) {
$parsedTypes = is_string($serviceTypesRaw) ? (json_decode($serviceTypesRaw, true) ?: []) : $serviceTypesRaw;
}
if (empty($parsedTypes)) {
$this->error('请至少开启 1 项主服务工项');
}
$dictSupportMap = Db::name('service_type')->column('support_fixed', 'code');
$hasDefault = false;
foreach ($parsedTypes as &$pt) {
$code = isset($pt['code']) ? (string)$pt['code'] : '';
$supportFixed = isset($dictSupportMap[$code])
? (int)$dictSupportMap[$code]
: (isset($pt['support_fixed']) ? (int)$pt['support_fixed'] : 1);
$price = ($supportFixed === 1 && isset($pt['price'])) ? round((float)$pt['price'], 2) : 0.00;
$pt['price'] = $price;
$pt['support_fixed'] = $supportFixed;
if ($supportFixed === 1 && !empty($pt['is_default']) && !$hasDefault) {
$pt['is_default'] = 1;
$hasDefault = true;
} else {
$pt['is_default'] = 0;
}
}
unset($pt);
if (!$hasDefault && !empty($parsedTypes)) {
foreach ($parsedTypes as &$ptDef) {
if ((int)$ptDef['support_fixed'] === 1) {
$ptDef['is_default'] = 1;
$hasDefault = true;
break;
}
}
unset($ptDef);
if (!$hasDefault) {
$parsedTypes[0]['is_default'] = 1;
}
}
$defItem = $parsedTypes[0];
foreach ($parsedTypes as $pt) {
if (!empty($pt['is_default'])) {
$defItem = $pt;
break;
}
}
$supportFixed = isset($defItem['support_fixed']) ? (int)$defItem['support_fixed'] : 1;
$mainPrice = isset($defItem['price']) ? (float)$defItem['price'] : 0.00;
$priceType = ($supportFixed === 0 || $mainPrice <= 0) ? 'quote' : 'fixed';
Db::startTrans();
try {
// 更新商品主服务配置与基准价格
$row->save([
'service_types' => json_encode(array_values($parsedTypes), JSON_UNESCAPED_UNICODE),
'price_type' => $priceType,
'base_price' => $mainPrice,
'updatetime' => time(),
]);
// 更新各个细分规格的主服务专属定价字典
if (is_array($specPricesInput)) {
foreach ($specPricesInput as $specId => $pricesMap) {
$specId = (int)$specId;
if ($specId <= 0) continue;
$cleanPrices = [];
if (is_string($pricesMap)) {
$pricesMap = json_decode($pricesMap, true) ?: [];
}
if (is_array($pricesMap)) {
foreach ($pricesMap as $c => $v) {
$c = trim((string)$c);
$v = (float)$v;
if ($c !== '' && $v > 0) {
$cleanPrices[$c] = round($v, 2);
}
}
}
$servicePricesJson = !empty($cleanPrices) ? json_encode($cleanPrices, JSON_UNESCAPED_UNICODE) : null;
$specBasePrice = isset($cleanPrices[$defItem['code']]) ? $cleanPrices[$defItem['code']] : 0.00;
Db::name('service_spec')
->where('id', $specId)
->where('service_id', $row->id)
->update([
'service_prices' => $servicePricesJson,
'base_price' => $specBasePrice,
'updatetime' => time(),
]);
}
}
Db::commit();
$this->success('主服务定价配置保存成功');
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
}
$serviceTypes = [];
if (!empty($row->service_types)) {
$serviceTypes = is_array($row->service_types) ? $row->service_types : json_decode($row->service_types, true);
}
$specs = Db::name('service_spec')
->where('service_id', $row->id)
->where('status', 'normal')
->order('weigh desc, id asc')
->select();
foreach ($specs as &$sp) {
$sp['prices_map'] = !empty($sp['service_prices']) ? (json_decode($sp['service_prices'], true) ?: []) : [];
}
unset($sp);
$catName = Db::name('service_cat')->where('id', $row->cat_id)->value('name') ?: '未归类';
$this->view->assign([
'row' => $row,
'catName' => $catName,
'serviceTypes' => $serviceTypes ?: [],
'specs' => $specs ?: [],
]);
return $this->view->fetch();
}
/**
* 独立弹窗:配置增值服务工项及基准加价与规格专属加价
*/
public function pricing_addon($ids = null)
{
$row = $this->model->get($ids);
if (!$row) {
$this->error(__('No Results were found'));
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
if ($this->request->isPost()) {
$addonsRaw = $this->request->post("addons_raw");
$specAddonPricesInput = $this->request->post("spec_addon_prices/a", []);
$parsedAddons = [];
if ($addonsRaw) {
$parsedAddons = is_string($addonsRaw) ? (json_decode($addonsRaw, true) ?: []) : $addonsRaw;
}
$cleanAddons = [];
if (is_array($parsedAddons)) {
foreach ($parsedAddons as $idx => $ad) {
$adName = isset($ad['name']) ? trim((string)$ad['name']) : '';
$adPrice = isset($ad['price']) ? round((float)$ad['price'], 2) : 0.00;
if ($adName === '' || $adPrice <= 0) continue;
$cleanAddons[] = [
'id' => isset($ad['id']) ? (int)$ad['id'] : ($idx + 1),
'code' => isset($ad['code']) ? (string)$ad['code'] : ('addon_' . ($idx + 1)),
'name' => $adName,
'unit' => !empty($ad['unit']) ? (string)$ad['unit'] : '份',
'price' => $adPrice,
];
}
}
Db::startTrans();
try {
// 更新商品增值服务配置
$row->save([
'addons' => json_encode($cleanAddons, JSON_UNESCAPED_UNICODE),
'updatetime' => time(),
]);
// 更新各个细分规格的增值服务专属加价字典
if (is_array($specAddonPricesInput)) {
foreach ($specAddonPricesInput as $specId => $addonMap) {
$specId = (int)$specId;
if ($specId <= 0) continue;
$cleanAddonPrices = [];
if (is_string($addonMap)) {
$addonMap = json_decode($addonMap, true) ?: [];
}
if (is_array($addonMap)) {
foreach ($addonMap as $c => $v) {
$c = trim((string)$c);
$v = (float)$v;
if ($c !== '' && $v > 0) {
$cleanAddonPrices[$c] = round($v, 2);
}
}
}
$addonPricesJson = !empty($cleanAddonPrices) ? json_encode($cleanAddonPrices, JSON_UNESCAPED_UNICODE) : null;
Db::name('service_spec')
->where('id', $specId)
->where('service_id', $row->id)
->update([
'addon_prices' => $addonPricesJson,
'updatetime' => time(),
]);
}
}
Db::commit();
$this->success('增值服务加价配置保存成功');
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
}
$addons = [];
if (!empty($row->addons)) {
$addons = is_array($row->addons) ? $row->addons : json_decode($row->addons, true);
}
$specs = Db::name('service_spec')
->where('service_id', $row->id)
->where('status', 'normal')
->order('weigh desc, id asc')
->select();
foreach ($specs as &$sp) {
$sp['addon_prices_map'] = !empty($sp['addon_prices']) ? (json_decode($sp['addon_prices'], true) ?: []) : [];
}
unset($sp);
$catName = Db::name('service_cat')->where('id', $row->cat_id)->value('name') ?: '未归类';
$this->view->assign([
'row' => $row,
'catName' => $catName,
'assignedAddons' => $addons ?: [],
'specs' => $specs ?: [],
]);
return $this->view->fetch();
}
/**
* 编辑商品与关联服务定价
*/
@@ -195,12 +511,27 @@ class Service extends Backend
$addons = is_array($row->addons) ? $row->addons : json_decode($row->addons, true);
}
// 获取已有商品规格
// 获取已有商品规格并解析专属主服务与增值服务定价字典
$specs = Db::name('service_spec')
->where('service_id', $row->id)
->where('status', 'normal')
->order('weigh desc, id asc')
->select();
foreach ($specs as &$sp) {
$sp['prices_map'] = !empty($sp['service_prices']) ? (json_decode($sp['service_prices'], true) ?: []) : [];
$sp['addon_prices_map'] = !empty($sp['addon_prices']) ? (json_decode($sp['addon_prices'], true) ?: []) : [];
if (empty($sp['prices_map']) && (float)$sp['base_price'] > 0) {
$defCode = 'install';
foreach ($serviceTypes as $st) {
if (!empty($st['is_default']) && !empty($st['code'])) {
$defCode = (string)$st['code'];
break;
}
}
$sp['prices_map'][$defCode] = (float)$sp['base_price'];
}
}
unset($sp);
$catName = Db::name('service_cat')->where('id', $row->cat_id)->value('name') ?: '未归类';
@@ -233,6 +564,21 @@ class Service extends Backend
->where('status', 'normal')
->order('weigh desc, id asc')
->select();
foreach ($specs as &$sp) {
$sp['prices_map'] = !empty($sp['service_prices']) ? (json_decode($sp['service_prices'], true) ?: []) : [];
$sp['addon_prices_map'] = !empty($sp['addon_prices']) ? (json_decode($sp['addon_prices'], true) ?: []) : [];
if (empty($sp['prices_map']) && (float)$sp['base_price'] > 0) {
$defCode = 'install';
foreach ($serviceTypes as $st) {
if (!empty($st['is_default']) && !empty($st['code'])) {
$defCode = (string)$st['code'];
break;
}
}
$sp['prices_map'][$defCode] = (float)$sp['base_price'];
}
}
unset($sp);
$orderAgg = Db::name('order')
->field('COUNT(*) AS total_cnt, SUM(CASE WHEN pay_status = 1 THEN pay_amount ELSE 0 END) AS total_gmv')
@@ -338,21 +684,38 @@ class Service extends Backend
}
}
$supportFixed = isset($defItem['support_fixed']) ? (int)$defItem['support_fixed'] : 1;
$params['price_type'] = $supportFixed === 1 ? 'fixed' : 'quote';
$params['base_price'] = $supportFixed === 1 ? (float)$defItem['price'] : 0.00;
$mainPrice = isset($defItem['price']) ? (float)$defItem['price'] : 0.00;
// 若该工项本身不支持一口价(需现场勘验)或价格为0,则自动切换为师傅报价模式;否则为标准一口价
if ($supportFixed === 0 || $mainPrice <= 0) {
$params['price_type'] = 'quote';
$params['base_price'] = 0.00;
} else {
$params['price_type'] = 'fixed';
$params['base_price'] = $mainPrice;
}
}
return $params;
}
/**
* 同步商品规格型号表(支持特殊规格单独设价覆盖与规格参考图,同步联动系统图库)
* 同步商品规格型号表(支持一个规格一套专属价格,未单独设价的工项自动沿用父级基准价,并联动系统图库)
*/
protected function syncSpecs($serviceId, $specsInput)
{
if (empty($serviceId)) return;
$now = time();
$catId = (int)Db::name('service')->where('id', $serviceId)->value('cat_id');
$svcRow = Db::name('service')->field('cat_id,service_types')->where('id', $serviceId)->find();
$catId = (int)($svcRow['cat_id'] ?? 0);
$svcTypes = !empty($svcRow['service_types']) ? (json_decode($svcRow['service_types'], true) ?: []) : [];
$defaultCode = 'install';
foreach ($svcTypes as $st) {
if (!empty($st['is_default']) && !empty($st['code'])) {
$defaultCode = (string)$st['code'];
break;
}
}
$keepIds = [];
if (!empty($specsInput) && is_array($specsInput)) {
$idx = 0;
@@ -361,38 +724,77 @@ class Service extends Backend
if ($name === '') continue;
$specDesc = isset($item['description']) ? trim($item['description']) : '';
$specImage = isset($item['image']) ? trim((string)$item['image']) : '';
$specPrice = (isset($item['base_price']) && is_numeric($item['base_price']) && (float)$item['base_price'] > 0)
? round((float)$item['base_price'], 2)
: 0.00;
// 解析当前规格的工项专属定价字典 (JSON / 关联数组)
$cleanPricesMap = [];
if (isset($item['service_prices'])) {
$rawPrices = is_array($item['service_prices'])
? $item['service_prices']
: (json_decode($item['service_prices'], true) ?: []);
foreach ($rawPrices as $pCode => $pVal) {
$pCode = trim((string)$pCode);
$pNum = (float)$pVal;
if ($pCode !== '' && $pNum > 0) {
$cleanPricesMap[$pCode] = round($pNum, 2);
}
}
}
// base_price 保持向下兼容:优先取默认首选主服务的专属价,未设则取传入的 base_price,均无则存 0.00
$specPrice = 0.00;
if (isset($cleanPricesMap[$defaultCode])) {
$specPrice = $cleanPricesMap[$defaultCode];
} elseif (isset($item['base_price']) && is_numeric($item['base_price']) && (float)$item['base_price'] > 0) {
$specPrice = round((float)$item['base_price'], 2);
if (!isset($cleanPricesMap[$defaultCode])) {
$cleanPricesMap[$defaultCode] = $specPrice;
}
} elseif (!empty($cleanPricesMap)) {
$specPrice = reset($cleanPricesMap);
}
$pricesJson = !empty($cleanPricesMap) ? json_encode($cleanPricesMap, JSON_UNESCAPED_UNICODE) : null;
$specId = isset($item['id']) ? (int)$item['id'] : 0;
$weigh = max(0, 100 - $idx * 5);
$idx++;
if ($specId > 0) {
$updateData = [
'name' => $name,
'base_price' => $specPrice,
'description' => $specDesc,
'weigh' => $weigh,
'updatetime' => $now,
];
if (array_key_exists('image', $item)) {
$updateData['image'] = $specImage;
// 解析当前规格的增值服务专属加价字典 (JSON / 关联数组)
$cleanAddonPricesMap = [];
if (isset($item['addon_prices'])) {
$rawAddonPrices = is_array($item['addon_prices'])
? $item['addon_prices']
: (json_decode($item['addon_prices'], true) ?: []);
foreach ($rawAddonPrices as $aCode => $aVal) {
$aCode = trim((string)$aCode);
$aNum = (float)$aVal;
if ($aCode !== '' && $aNum > 0) {
$cleanAddonPricesMap[$aCode] = round($aNum, 2);
}
}
Db::name('service_spec')->where('id', $specId)->where('service_id', $serviceId)->update($updateData);
}
$addonPricesJson = !empty($cleanAddonPricesMap) ? json_encode($cleanAddonPricesMap, JSON_UNESCAPED_UNICODE) : null;
$saveData = [
'name' => $name,
'base_price' => $specPrice,
'service_prices' => $pricesJson,
'addon_prices' => $addonPricesJson,
'description' => $specDesc,
'weigh' => $weigh,
'updatetime' => $now,
];
if (array_key_exists('image', $item)) {
$saveData['image'] = $specImage;
}
if ($specId > 0) {
Db::name('service_spec')->where('id', $specId)->where('service_id', $serviceId)->update($saveData);
$keepIds[] = $specId;
} else {
$specId = (int)Db::name('service_spec')->insertGetId([
'service_id' => $serviceId,
'name' => $name,
'image' => $specImage,
'base_price' => $specPrice,
'description' => $specDesc,
'weigh' => $weigh,
'status' => 'normal',
'createtime' => $now,
'updatetime' => $now,
]);
$saveData['service_id'] = $serviceId;
$saveData['status'] = 'normal';
$saveData['createtime'] = $now;
$specId = (int)Db::name('service_spec')->insertGetId($saveData);
$keepIds[] = $specId;
}

查看文件

@@ -183,15 +183,23 @@ class User extends Backend
->limit(8)
->select();
$recentWalletLogs = Db::name('wallet_log')
->where('user_type', 'user')
->where('user_id', $uid)
->order('id desc')
->limit(6)
->select();
$this->view->assign([
'row' => $row,
'masterProfile' => $masterProfile,
'merchantProfile' => $merchantProfile,
'addressList' => $addressList,
'recentOrders' => $recentOrders,
'coupons' => $coupons,
'orderCount' => (int)($orderAgg['total_cnt'] ?? 0),
'totalSpent' => number_format((float)($orderAgg['total_spent'] ?? 0), 2, '.', ''),
'row' => $row,
'masterProfile' => $masterProfile,
'merchantProfile' => $merchantProfile,
'addressList' => $addressList,
'recentOrders' => $recentOrders,
'coupons' => $coupons,
'recentWalletLogs' => $recentWalletLogs,
'orderCount' => (int)($orderAgg['total_cnt'] ?? 0),
'totalSpent' => number_format((float)($orderAgg['total_spent'] ?? 0), 2, '.', ''),
]);
return $this->view->fetch();