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),实现工作台、接单大厅、资质认证、工单协同与钱包提现完整闭环。
62 行
2.4 KiB
PHP
62 行
2.4 KiB
PHP
<?php
|
||
|
||
namespace app\common\library;
|
||
|
||
use think\Db;
|
||
|
||
/**
|
||
* 师傅端独立安全凭证校验与防暴力破解锁定(读写 fa_master_security 与 fa_master)
|
||
*/
|
||
class MasterSecurity
|
||
{
|
||
public static function ensure($masterId)
|
||
{
|
||
$prefix = config('database.prefix');
|
||
if (!preg_match('/^[A-Za-z0-9_]+$/', $prefix)) {
|
||
throw new \RuntimeException('数据库配置错误');
|
||
}
|
||
Db::execute("INSERT IGNORE INTO `{$prefix}master_security` (`master_id`) VALUES (?)", [(int)$masterId]);
|
||
}
|
||
|
||
public static function verify($masterId, $kind, $password)
|
||
{
|
||
if (!in_array($kind, ['login', 'payment'], true)) {
|
||
throw new \InvalidArgumentException('验证类型错误');
|
||
}
|
||
$masterId = (int)$masterId;
|
||
$attemptsField = $kind === 'payment' ? 'payment_failed_attempts' : 'failed_attempts';
|
||
$lockedField = $kind === 'payment' ? 'payment_locked_until' : 'locked_until';
|
||
|
||
self::ensure($masterId);
|
||
Db::startTrans();
|
||
try {
|
||
$row = Db::name('master_security')->where('master_id', $masterId)->lock(true)->find();
|
||
if ((int)$row[$lockedField] > time()) {
|
||
throw new \RuntimeException('密码错误次数过多,请15分钟后重试');
|
||
}
|
||
if ($kind === 'login') {
|
||
$master = Db::name('master')->field('password,salt')->where('id', $masterId)->find();
|
||
$correct = $master && $master['password'] !== '' && hash_equals((string)$master['password'], md5(md5($password) . $master['salt']));
|
||
} else {
|
||
if ($row['payment_password_hash'] === '') {
|
||
throw new \RuntimeException('请先在账号安全中设置支付密码');
|
||
}
|
||
$correct = password_verify($password, $row['payment_password_hash']);
|
||
}
|
||
$failures = $correct ? 0 : (int)$row[$attemptsField] + 1;
|
||
Db::name('master_security')->where('master_id', $masterId)->update([
|
||
$attemptsField => $failures >= 5 ? 0 : $failures,
|
||
$lockedField => $failures >= 5 ? time() + 900 : 0,
|
||
]);
|
||
Db::commit();
|
||
} catch (\Throwable $e) {
|
||
Db::rollback();
|
||
throw $e;
|
||
}
|
||
if (!$correct) {
|
||
throw new \RuntimeException($failures >= 5 ? '密码错误次数过多,请15分钟后重试' : '密码不正确');
|
||
}
|
||
return true;
|
||
}
|
||
}
|