feat: 用户端与师傅端双小程序架构解耦,新增师傅独立认证及超时自动关单机制

1. 账号体系与数据库解耦:
   - 师傅表 fa_master 解除对 fa_user.id 的外键依赖,升级为独立认证账号主表;
   - 新增师傅端独立支撑表:fa_master_security、fa_master_token、fa_master_wechat、fa_master_agreement_read;
   - 新增工单超时未接单自动关闭与原路退款配置(order_unaccepted_close_days)。

2. 服务端(Server):
   - 新增师傅端独立 API 控制器与认证库(MasterAuth, MasterBase, MasterMessage, MasterSecurity, MasterToken);
   - WxLogin 支持双小程序端(user/master)独立换取 session_key、openid 与 access_token;
   - 新增控制台调度命令 php think order:autoclose,支持订单超时自动关闭与售后退款闭环;
   - 修复 PHP 8.5 兼容性问题(Request.php 的 (bool) 强制转换);
   - 系统业务配置全面收敛至数据库 fa_config 及 site.php。

3. 小程序端:
   - yjyf-app(用户端):彻底剥离师傅端路由、组件及静态资源,增加隐私授权弹窗与评价模块;
   - yjyf-master-app(师傅端):全新独立微信小程序工程(wx140d90ceda786107),实现工作台、接单大厅、资质认证、工单协同与钱包提现完整闭环。
这个提交包含在:
2026-11-23 15:10:30 +08:00
父节点 d3cd6ba342
当前提交 14533eadb7
共有 270 个文件被更改,包括 9757 次插入 和 1392 次删除

查看文件

@@ -108,6 +108,74 @@ class PaymentService
throw new \InvalidArgumentException('未获取到当前微信授权信息(OpenID 缺失),请在微信小程序内打开并登录后再操作');
}
/**
* 解析并严格校验当前操作师傅的师傅端小程序 OpenID(操作 fa_master_wechat,与用户端完全隔离)
*
* @param int $masterId 当前登录师傅 ID
* @param string $wxCode 师傅端小程序实时获取的 wx.login code
* @return string
*/
public static function resolveMasterOpenid($masterId, $wxCode = '')
{
$masterId = (int)$masterId;
$wxCode = trim((string)$wxCode);
if ($wxCode !== '') {
$wx = WxLogin::jscode2session($wxCode, 'master');
if (!is_array($wx) || !empty($wx['error']) || empty($wx['openid'])) {
$errMsg = (is_array($wx) && !empty($wx['error']))
? (string)$wx['error']
: '获取师傅端微信身份标识(OpenID)失败,请在师傅端小程序内重新登录后再试';
Log::error("[PaymentService::resolveMasterOpenid] jscode2session 失败 master_id={$masterId}: {$errMsg}");
throw new \RuntimeException($errMsg);
}
$liveOpenid = trim((string)$wx['openid']);
$unionid = isset($wx['unionid']) ? trim((string)$wx['unionid']) : '';
$sessionKey = isset($wx['session_key']) ? trim((string)$wx['session_key']) : '';
$now = time();
$existByOpenid = Db::name('master_wechat')->where('openid', $liveOpenid)->find();
if ($existByOpenid) {
$boundMid = (int)$existByOpenid['master_id'];
if ($boundMid > 0 && $boundMid !== $masterId) {
Log::error("[PaymentService::resolveMasterOpenid] OpenID归属冲突 current_mid={$masterId}, bound_mid={$boundMid}");
throw new \InvalidArgumentException('当前微信号已绑定其他师傅账号(师傅ID:' . $boundMid . '),请确认登录账号与微信号一致后再操作');
}
Db::name('master_wechat')->where('id', (int)$existByOpenid['id'])->update([
'master_id' => $masterId,
'unionid' => $unionid !== '' ? $unionid : (string)$existByOpenid['unionid'],
'session_key' => $sessionKey !== '' ? $sessionKey : (string)$existByOpenid['session_key'],
'updatetime' => $now,
]);
} else {
Db::name('master_wechat')->insert([
'master_id' => $masterId,
'openid' => $liveOpenid,
'unionid' => $unionid,
'session_key' => $sessionKey,
'createtime' => $now,
'updatetime' => $now,
]);
}
return $liveOpenid;
}
if ($masterId > 0) {
$bind = Db::name('master_wechat')
->where('master_id', $masterId)
->where('openid', '<>', '')
->order('updatetime desc, id desc')
->find();
if ($bind && !empty($bind['openid'])) {
return trim((string)$bind['openid']);
}
}
throw new \InvalidArgumentException('未获取到师傅端微信授权信息(OpenID 缺失),请在师傅端微信小程序内打开并登录后再操作');
}
/**
* 用户端统一发起微信 JSAPI 支付(覆盖 order 首单支付 / quote 选师傅报价支付 / diff 施工增项补差价支付)
*
@@ -1219,11 +1287,11 @@ class PaymentService
throw new \InvalidArgumentException('提现师傅档案不存在');
}
// 解析收款师傅微信 OpenID(优先读提现单快照,其次查微信绑定表)
// 解析收款师傅微信 OpenID(优先读提现单快照,其次查师傅端独立绑定表 fa_master_wechat)
$openid = trim((string)($wd['openid'] ?? ''));
if ($openid === '' && (int)$master['user_id'] > 0) {
$bind = Db::name('user_wechat')
->where('user_id', (int)$master['user_id'])
if ($openid === '') {
$bind = Db::name('master_wechat')
->where('master_id', (int)$master['id'])
->where('openid', '<>', '')
->order('updatetime desc, id desc')
->find();
@@ -1232,7 +1300,7 @@ class PaymentService
}
}
if ($openid === '') {
$msg = '该师傅尚未绑定微信小程序授权(缺少收款 OpenID),请提醒师傅在微信小程序内登录打开「我的钱包」后再试';
$msg = '该师傅尚未绑定师傅端微信小程序授权(缺少收款 OpenID),请提醒师傅在师傅端小程序内登录打开「我的钱包」后再试';
self::recordWithdrawFailure($withdrawId, 'OPENID_MISSING', $msg);
throw new \InvalidArgumentException($msg);
}
@@ -1269,9 +1337,9 @@ class PaymentService
]);
}
// 事务外调用微信支付 APIv3 发起商家转账(动态读取独立配置中心报备参数)
// 事务外调用微信支付 APIv3 发起商家转账(使用师傅端 AppID 与配置)
$wdCfg = FinanceConfigService::getWithdrawConfig();
$wxSvc = new WxPayV3Service();
$wxSvc = new WxPayV3Service(['side' => 'master']);
try {
$resp = $wxSvc->createTransferBill([
'out_bill_no' => $outBillNo,
@@ -1385,9 +1453,9 @@ class PaymentService
$arrStr = number_format((float)$lockedWd['arrive_amount'], 2, '.', '');
self::sendMasterAndUserMessage(
(int)$master['id'],
(int)$master['user_id'],
0,
'提现已汇出,请确认收款',
"您的提现申请 ¥{$amtStr}(实际到账 ¥{$arrStr})已通过审核并发起微信转账,请在 24 小时内打开小程序「我的钱包」点击「确认收款」入账微信零钱。"
"您的提现申请 ¥{$amtStr}(实际到账 ¥{$arrStr})已通过审核并发起微信转账,请在 24 小时内打开师傅端小程序「我的钱包」点击「确认收款」入账微信零钱。"
);
Db::commit();
@@ -1424,7 +1492,7 @@ class PaymentService
}
if ($wxBillData === null) {
$wxSvc = new WxPayV3Service();
$wxSvc = new WxPayV3Service(['side' => 'master']);
try {
$wxBillData = $wxSvc->queryTransferBill($outBillNo);
} catch (\Throwable $qe) {
@@ -1512,7 +1580,7 @@ class PaymentService
]);
self::sendMasterAndUserMessage(
$masterId,
(int)$master['user_id'],
0,
'提现已到账微信零钱',
'您的提现 ¥' . $amount . '(实到 ¥' . $lockedWd['arrive_amount'] . ')已成功确认收款并入账微信零钱。'
);
@@ -1565,7 +1633,7 @@ class PaymentService
]);
self::sendMasterAndUserMessage(
$masterId,
(int)$master['user_id'],
0,
'提现未完成退回余额通知',
'您的提现申请 ¥' . $amount . ' 未完成入账(原因:' . $reasonText . '),资金已自动解冻退回您的钱包可用余额,可随时重新发起提现。'
);
@@ -1685,7 +1753,7 @@ class PaymentService
]);
self::sendMasterAndUserMessage(
$masterId,
(int)$master['user_id'],
0,
'提现申请已驳回',
'您的提现申请 ¥' . $amount . ' 未通过财务审核:' . $auditMsg . ',申请金额已退回钱包余额。'
);
@@ -1699,7 +1767,7 @@ class PaymentService
// 2. 已存在商户转账单号时:先实时向微信查单,确认为已失败/已撤销/微信侧不存在后,方可解冻退款(严防双重资损)
$outBillNo = (string)$wd['out_bill_no'];
$wxSvc = new WxPayV3Service();
$wxSvc = new WxPayV3Service(['side' => 'master']);
try {
$wxBill = $wxSvc->queryTransferBill($outBillNo);
} catch (\Throwable $qe) {
@@ -1818,7 +1886,7 @@ class PaymentService
]);
self::sendMasterAndUserMessage(
$masterId,
(int)$master['user_id'],
0,
'提现申请已退回余额',
'您的提现申请 ¥' . $amount . ' 已驳回退回(批注:' . $auditMsg . '),申请金额已全额退回钱包可用余额。'
);
@@ -2146,12 +2214,27 @@ class PaymentService
protected static function broadcastNewOrderToMasters(array $order)
{
try {
$masters = Db::name('master')
$excludeMobiles = [];
$orderMobile = trim((string)($order['mobile'] ?? ''));
if ($orderMobile !== '') {
$excludeMobiles[] = $orderMobile;
}
if ((int)($order['user_id'] ?? 0) > 0) {
$posterMobile = trim((string)Db::name('user')->where('id', (int)$order['user_id'])->value('mobile'));
if ($posterMobile !== '') {
$excludeMobiles[] = $posterMobile;
}
}
$q = Db::name('master')
->where('verify_status', 'pass')
->where('work_status', 'on')
->where('user_id', '<>', (int)$order['user_id'])
->limit(20)
->select();
->where('status', 'normal');
if (!empty($excludeMobiles)) {
$q->where(function ($sub) use ($excludeMobiles) {
$sub->whereNull('mobile')->whereOr('mobile', 'not in', array_values(array_unique($excludeMobiles)));
});
}
$masters = $q->limit(20)->select();
foreach ($masters as $m) {
self::sendNotify('master', (int)$m['id'], '新工单就绪通知', '同城有新工单【' . $order['order_no'] . '】进入接单大厅,请尽快前往抢单!', 'order', (int)$order['id']);
}
@@ -2205,18 +2288,6 @@ class PaymentService
'createtime' => $now,
];
}
if ((int)$userId > 0) {
$rows[] = [
'receive_type' => 'user',
'receive_id' => (int)$userId,
'type' => 'system',
'title' => mb_substr((string)$title, 0, 100),
'content' => mb_substr((string)$content, 0, 500),
'order_id' => 0,
'is_read' => 0,
'createtime' => $now,
];
}
if ($rows) {
Db::name('message')->insertAll($rows);
}