This commit is contained in:
Your Name
2026-03-13 14:08:52 +08:00
parent 08dd9cd307
commit eb283f008b
667 changed files with 8425 additions and 27053 deletions
@@ -24,7 +24,7 @@ use app\adminapi\validate\LoginValidate;
*/
class LoginController extends BaseAdminController
{
public array $notNeedLogin = ['account'];
public array $notNeedLogin = ['account', 'workWechatConfig', 'workWechatLogin', 'checkDbColumn'];
/**
* @notes 账号登录
@@ -41,6 +41,66 @@ class LoginController extends BaseAdminController
return $this->data((new LoginLogic())->login($params));
}
/**
* @notes 获取企业微信登录配置(前端构造OAuth URL/扫码用)
*/
public function workWechatConfig()
{
$corpId = env('work_wechat.corp_id', '');
$agentId = env('work_wechat.agent_id', '');
if (empty($corpId) || empty($agentId)) {
return $this->data(['enabled' => false]);
}
return $this->data([
'enabled' => true,
'corp_id' => $corpId,
'agent_id' => $agentId,
]);
}
/**
* @notes 企业微信授权登录(用 code 换 token
*/
public function workWechatLogin()
{
$code = $this->request->post('code', '');
if (empty($code)) {
return $this->fail('缺少授权code');
}
$terminal = $this->request->post('terminal', 1);
$result = (new LoginLogic())->workWechatLogin([
'code' => $code,
'terminal' => $terminal,
]);
if ($result === false) {
return $this->fail(LoginLogic::getError());
}
return $this->data($result);
}
/**
* @notes 临时调试:检查 admin 表是否有 work_wechat_userid 列(确认后请删除此方法)
*/
public function checkDbColumn()
{
$dbName = env('database.database', '');
$prefix = env('database.prefix', '');
$tableName = $prefix . 'admin';
$columns = \think\facade\Db::query("SHOW COLUMNS FROM `{$tableName}` LIKE 'work_wechat_userid'");
return $this->data([
'database' => $dbName,
'table' => $tableName,
'column_exists' => !empty($columns),
'columns_result' => $columns,
]);
}
/**
* @notes 退出登录
* @return \think\response\Json
@@ -18,7 +18,9 @@ use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\auth\AdminLists;
use app\adminapi\validate\auth\AdminValidate;
use app\adminapi\logic\auth\AdminLogic;
use app\adminapi\logic\LoginLogic;
use app\adminapi\validate\auth\editSelfValidate;
use app\common\model\auth\Admin;
/**
* 管理员控制器
@@ -131,4 +133,74 @@ class AdminController extends BaseAdminController
return $this->success('操作成功', [], 1, 1);
}
/**
* @notes 企业微信扫码绑定(用 code 换取 userid 并保存到当前管理员)
*/
public function bindWorkWechat()
{
$code = $this->request->post('code', '');
if (empty($code)) {
return $this->fail('缺少授权code');
}
$corpId = env('work_wechat.corp_id', '');
$secret = env('work_wechat.secret', '');
if (empty($corpId) || empty($secret)) {
return $this->fail('企业微信未配置');
}
$accessToken = LoginLogic::getWorkWechatAccessTokenStatic($corpId, $secret);
if (!$accessToken) {
return $this->fail('获取企业微信凭证失败');
}
$url = "https://qyapi.weixin.qq.com/cgi-bin/auth/getuserinfo?access_token={$accessToken}&code={$code}";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$result = curl_exec($ch);
curl_close($ch);
$response = json_decode($result, true);
if (!$response || ($response['errcode'] ?? -1) != 0) {
return $this->fail('企业微信授权失败: ' . ($response['errmsg'] ?? '未知错误'));
}
$wxUserId = $response['userid'] ?? '';
if (empty($wxUserId)) {
return $this->fail('未获取到企业微信用户身份');
}
// 检查是否已被其他管理员绑定
$exists = Admin::where('work_wechat_userid', $wxUserId)
->where('id', '<>', $this->adminId)
->find();
if ($exists) {
return $this->fail('该企业微信账号已被其他管理员绑定');
}
Admin::update([
'id' => $this->adminId,
'work_wechat_userid' => $wxUserId,
]);
return $this->success('绑定成功', ['work_wechat_userid' => $wxUserId]);
}
/**
* @notes 解绑企业微信
*/
public function unbindWorkWechat()
{
Admin::update([
'id' => $this->adminId,
'work_wechat_userid' => '',
]);
return $this->success('解绑成功');
}
}
@@ -102,6 +102,29 @@ class DiagnosisController extends BaseAdminController
return $this->data($result);
}
/**
* @notes 诊单详情(患者端)
* @return \think\response\Json
*/
public function diagnosisDetail()
{
$params = $this->request->get();
if (empty($params['id'])) {
return $this->fail('诊单ID不能为空');
}
if (empty($params['user_id'])) {
return $this->fail('用户ID不能为空');
}
$result = DiagnosisLogic::diagnosisDetail($params);
if ($result) {
return $this->data($result);
}
return $this->fail(DiagnosisLogic::getError());
}
/**
* @notes 检查手机号是否重复
* @return \think\response\Json