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),实现工作台、接单大厅、资质认证、工单协同与钱包提现完整闭环。
112 行
2.9 KiB
PHP
112 行
2.9 KiB
PHP
<?php
|
||
|
||
namespace app\common\library;
|
||
|
||
use think\Config;
|
||
use think\Db;
|
||
|
||
/**
|
||
* 师傅端独立 Token 操作类(物理隔离于用户端 fa_user_token,读写 fa_master_token)
|
||
*/
|
||
class MasterToken
|
||
{
|
||
/**
|
||
* 计算加密后的 Token
|
||
*/
|
||
protected static function encrypt($token)
|
||
{
|
||
$config = Config::get('token');
|
||
$algo = !empty($config['hashalgo']) ? $config['hashalgo'] : 'ripemd160';
|
||
$key = isset($config['key']) ? (string)$config['key'] : '';
|
||
return hash_hmac($algo, (string)$token, $key);
|
||
}
|
||
|
||
/**
|
||
* 清理过期 Token(每天至多清理一次)
|
||
*/
|
||
protected static function gc()
|
||
{
|
||
$time = time();
|
||
$lastGc = cache('master_tokentime');
|
||
if (!$lastGc || $lastGc < $time - 86400) {
|
||
cache('master_tokentime', $time);
|
||
Db::name('master_token')->where('expiretime', '<', $time)->where('expiretime', '>', 0)->delete();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 写入师傅 Token
|
||
*/
|
||
public static function set($token, $masterId, $expire = 2592000)
|
||
{
|
||
self::gc();
|
||
$encrypted = self::encrypt($token);
|
||
$exists = Db::name('master_token')->where('token', $encrypted)->count();
|
||
if ($exists) {
|
||
return false;
|
||
}
|
||
$expiretime = !is_null($expire) && (int)$expire !== 0 ? time() + (int)$expire : 0;
|
||
Db::name('master_token')->insert([
|
||
'token' => $encrypted,
|
||
'master_id' => (int)$masterId,
|
||
'createtime' => time(),
|
||
'expiretime' => $expiretime,
|
||
]);
|
||
return true;
|
||
}
|
||
|
||
/**
|
||
* 读取师傅 Token 数据
|
||
*/
|
||
public static function get($token)
|
||
{
|
||
if (!$token) {
|
||
return [];
|
||
}
|
||
$data = Db::name('master_token')->where('token', self::encrypt($token))->find();
|
||
if (!$data) {
|
||
return [];
|
||
}
|
||
if (!$data['expiretime'] || (int)$data['expiretime'] > time()) {
|
||
$data['token'] = $token;
|
||
$data['expires_in'] = $data['expiretime'] ? max(0, (int)$data['expiretime'] - time()) : 365 * 86400;
|
||
return $data;
|
||
}
|
||
self::delete($token);
|
||
return [];
|
||
}
|
||
|
||
/**
|
||
* 校验 Token 是否属于指定师傅
|
||
*/
|
||
public static function check($token, $masterId)
|
||
{
|
||
$data = self::get($token);
|
||
return $data && (int)$data['master_id'] === (int)$masterId;
|
||
}
|
||
|
||
/**
|
||
* 删除单个 Token
|
||
*/
|
||
public static function delete($token)
|
||
{
|
||
if (!$token) {
|
||
return false;
|
||
}
|
||
Db::name('master_token')->where('token', self::encrypt($token))->delete();
|
||
return true;
|
||
}
|
||
|
||
/**
|
||
* 清除指定师傅全部 Token
|
||
*/
|
||
public static function clear($masterId)
|
||
{
|
||
if ((int)$masterId <= 0) {
|
||
return false;
|
||
}
|
||
Db::name('master_token')->where('master_id', (int)$masterId)->delete();
|
||
return true;
|
||
}
|
||
}
|