feat: 完善协议管理、师傅资质认证、分账配置并完成测试环境全量部署与同步

这个提交包含在:
2026-11-12 17:19:49 +08:00
父节点 fafddceaf2
当前提交 72cea8445f
共有 179 个文件被更改,包括 29242 次插入 和 3340 次删除

查看文件

@@ -2,7 +2,6 @@
namespace app\api\controller;
use fast\Random;
use think\Db;
use think\Validate;
@@ -14,9 +13,7 @@ class Auth extends Base
protected $noNeedLogin = ['login', 'wxlogin', 'wxPhoneLogin'];
/**
* 手机号 + 验证码登录(兜底通道)
* 验证码来源由 .env 的 [sms] 段控制:mock=1 时使用 mock_code(联调用),
* 接入真实短信后置 mock=0 并在此处改为 Sms::check($mobile, $code, 'mobilelogin')
* 手机号 + 密码登录(仅支持账号密码或微信一键登录,短信验证码通道已移除)
* @ApiMethod (POST)
*/
public function login()
@@ -26,76 +23,45 @@ class Auth extends Base
$password = (string)$this->request->post('password', '');
$code = trim((string)$this->request->post('code', ''));
// 1. 手机号 + 密码登录(直连真实数据库)
if ($password !== '' || ($mobile !== '' && $code === '')) {
if ($mobile === '') {
$this->error('请填写手机号');
}
if (!preg_match('/^1[3-9]\d{9}$/', $mobile)) {
$this->error('手机号格式不正确');
}
if ($password === '') {
$this->error('请填写登录密码');
}
// 直接查询真实数据库 fa_user 表
$user = Db::name('user')->where('mobile', $mobile)->find();
if (!$user) {
// 若数据库中无此手机号:直连数据库插入注册新会员
$ret = $this->auth->register($mobile, $password, '', $mobile, []);
if (!$ret) {
$this->error($this->auth->getError() ?: '注册登录失败');
}
} else {
if ($user['status'] !== 'normal') {
$this->error('账号已被禁用');
}
if (empty($user['password'])) {
$this->error('该账号尚未设置登录密码,请使用验证码或微信登录后设置密码');
}
$encryptPassword = $this->auth->getEncryptPassword($password, $user['salt']);
if ($user['password'] !== $encryptPassword) {
$this->error('手机号或密码不正确');
}
$this->auth->direct($user['id']);
}
// 直查真实数据库返回用户完整信息
$this->success('登录成功', [
'token' => $this->auth->getToken(),
'expires' => 2592000,
'userinfo' => $this->profileData(),
]);
if ($password === '' && $code !== '') {
$this->error('短信验证码通道已移除,请使用手机号密码或微信一键登录', null, 2010);
}
// 2. 手机号 + 验证码登录(向下兼容)
if (!$mobile || !$code) {
$this->error('请填写手机号和验证码');
// 手机号 + 密码登录(直连真实数据库)
if ($mobile === '') {
$this->error('请填写手机号');
}
if (!Validate::regex($mobile, "^1\d{10}$")) {
if (!preg_match('/^1[3-9]\d{9}$/', $mobile)) {
$this->error('手机号格式不正确');
}
$mockOn = (int)\think\Env::get('sms.mock', 1);
$mockCode = (string)\think\Env::get('sms.mock_code', '123456');
if (!($mockOn === 1 && $mockCode !== '' && (string)$code === $mockCode)) {
$this->error('短信通道尚未接入,请联系管理员开通', ['sms_ready' => 0], 2010);
if ($password === '') {
$this->error('请填写登录密码');
}
$user = \app\common\model\User::getByMobile($mobile);
if ($user) {
// 直接查询真实数据库 fa_user 表
$user = Db::name('user')->where('mobile', $mobile)->find();
if (!$user) {
// 若数据库中无此手机号:直连数据库插入注册新会员
$ret = $this->auth->register($mobile, $password, '', $mobile, []);
if (!$ret) {
$this->error($this->auth->getError() ?: '注册登录失败');
}
} else {
if ($user['status'] !== 'normal') {
$this->error('账号已被禁用');
}
$this->auth->direct($user['id']);
} else {
$ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, []);
if (!$ret) {
$this->error($this->auth->getError() ?: '注册失败');
if (empty($user['password'])) {
$this->error('该账号尚未设置登录密码,请使用微信一键登录后设置密码');
}
$encryptPassword = $this->auth->getEncryptPassword($password, $user['salt']);
if ($user['password'] !== $encryptPassword) {
$this->error('手机号或密码不正确');
}
$this->auth->direct($user['id']);
}
// 直查真实数据库返回用户完整信息
$this->success('登录成功', [
'token' => $this->auth->getToken(),
'expires' => 2592000,
@@ -357,17 +323,20 @@ class Auth extends Base
$this->error('解析手机号失败');
}
// 2. 如果传了 login_code,换取 openid
// 2. 如果传了 login_code,换取 openid;失败时严禁静默忽略,需如实报错防止后续支付/转账漏绑 OpenID
$openid = '';
$sessionKey = '';
$unionid = '';
if ($loginCode !== '') {
$wx = \app\common\library\WxLogin::jscode2session($loginCode);
if (!isset($wx['error']) && !empty($wx['openid'])) {
$openid = $wx['openid'];
$sessionKey = isset($wx['session_key']) ? $wx['session_key'] : '';
$unionid = isset($wx['unionid']) ? $wx['unionid'] : '';
if (isset($wx['error']) || empty($wx['openid'])) {
$errMsg = isset($wx['error']) && $wx['error'] !== '' ? (string)$wx['error'] : '微信登录凭证换取 OpenID 失败,请重进小程序再试';
\think\Log::error('[Auth::wxPhoneLogin] jscode2session 失败: ' . $errMsg);
$this->error($errMsg, ['wx_errcode' => isset($wx['errcode']) ? (int)$wx['errcode'] : 0]);
}
$openid = $wx['openid'];
$sessionKey = isset($wx['session_key']) ? $wx['session_key'] : '';
$unionid = isset($wx['unionid']) ? $wx['unionid'] : '';
}
// 3. 落库与关联登录