This commit is contained in:
ASUS 2025-08-13 20:28:23 +08:00
parent 537426593a
commit 7f48675193
9 changed files with 92 additions and 29 deletions

View File

@ -54,6 +54,7 @@ class BaseController
$this->error('Token expiration', [], 409);
}
};
if ($needLogin) {
$this->error('Token expiration', [], 409);
}
@ -144,7 +145,7 @@ class BaseController
{
$data['code'] = $code;
$data['message'] = $msg;
$data['time'] = $this->request->server('REQUEST_TIME');
$data['time'] = time();
if(isset($data['data']['records'])) {
$data['data']['records'] = apiconvertToCamelCase($data['data']['records']);
}
@ -159,12 +160,7 @@ class BaseController
}
$result = $data;
$type = $type ?: $this->responseType;
$response = new Response();
$response->header('Content-Type', $type);
$response->withBody($result);
return $response;
throw new MyBusinessException(json_encode($result));
}

View File

@ -2,9 +2,9 @@
namespace app\common\library;
use app\api\model\TbUser;
use app\czg\app\model\TbUser;
use app\api\model\TbUserBlacklist;
use app\api\model\UserInfo;
use app\czg\app\model\UserInfo;
use app\common\model\Common;
use app\common\model\SysUser;
use app\utils\JwtUtils;
@ -160,6 +160,7 @@ class Auth
$where = $sale = ['user_id' => $userId];
$user_id_db_name = DatabaseRoute::getConnection('tb_user', $sale);
$this->model = Db::connect($user_id_db_name)->name('tb_user')->where($where)->find();
if (!$this->model) {
$this->setError('Account not exist');
return false;
@ -355,13 +356,10 @@ class Auth
// 验证密码
if(TbUser::CheckPassword($this->model['password'], $password)) {
// 实名认证信息
$userInfo = new UserInfo();
$where = ['user_id' => $this->model['user_id']];
$userInfo->setConnection($userInfo::findbefore($userInfo, $where));
$userInfo = $userInfo->where($where)->find();
if($userInfo && $userInfo->cert_no) {
$userInfo = DatabaseRoute::getDb('user_info', $this->model['user_id'])->find();
if($userInfo && $userInfo['cert_no']) {
// 继续查黑名单表
$userBlack = TbUserBlacklist::where(['id_card_no' => $userInfo->cert_no])->find();
$userBlack = \app\czg\app\model\TbUserBlacklist::where(['id_card_no' => $userInfo['cert_no']])->find();
if($userBlack) {
$this->setError('系统正在维护中,请稍后再试!');
return false;

View File

@ -5,7 +5,7 @@ use app\common\library\DatabaseRoute;
use think\db\BaseQuery;
use think\facade\Db;
use think\facade\Log;
use think\Model;
use support\think\Model;
use think\db\Query;
class BaseModel extends Model

View File

@ -0,0 +1,67 @@
<?php
namespace app\czg\app\controller;
use app\api\model\Msg;
use app\api\model\TbUser;
use app\common\controller\BaseController;
use app\common\model\SysUser;
use think\facade\Db;
use think\Request;
use Throwable;
use ba\Captcha;
use ba\ClickCaptcha;
use think\facade\Config;
use app\common\facade\Token;
use app\common\controller\Frontend;
use app\api\validate\User as UserValidate;
class LoginController extends BaseController
{
protected array $noNeedLogin = ['*'];
public function index()
{
$data = $this->request->post();
if(empty($data['phone']) || empty($data['password'])){
$this->n_error('参数不完整');
}
$res = $this->auth->newlogin($data['phone'], $data['password'], 0);
if (isset($res) && $res === true) {
$data = $this->auth->getUser();
$this->n_success([
'token' => $this->auth->getUserInfo()['token'],
'user' => apiconvertToCamelCase($data)
]);
} else {
$msg = $this->auth->getError();
$msg = $msg ?: __('Check in failed, please try again or contact the website administrator~');
$this->n_error($msg);
}
}
// 注册
public function register()
{
return $this->ApiDataReturn(TbUser::register($this->request->post()));
}
// 发送验证码
public function sendMsg()
{
$get = $this->request->route();
return $this->ApiDataReturn(Msg::sendMsg($get['phone'], $get['event']));
}
// 忘记密码
public function forgetPwd()
{
$post = $this->request->post();
return $this->ApiDataReturn(TbUser::forgetPwd($post['phone'], $post['pwd'], $post['msg']));
}
}

View File

@ -282,6 +282,7 @@ class Course extends Model
// 根据id查询短剧集数列表
public static function courseSets($get, $user, $sort = null)
{
try {
if(empty($get['courseId'])) {
return returnErrorData('参数不完整');

View File

@ -18,9 +18,9 @@ class TbUser extends BaseModel
public static function GetByusername($username, $field = 'phone')
{
// 全表扫描username
$dbmap = config('database.db_map');
$dbmap = config('think-orm.db_map');
foreach ($dbmap as $dbname) {
if(!in_array($dbname, config('database.unset_db_map'))) {
if(!in_array($dbname, config('think-orm.unset_db_map'))) {
$connect = Db::connect($dbname);
$data = $connect->name('tb_user')->where([$field => $username])->find();
if($data) {
@ -35,10 +35,10 @@ class TbUser extends BaseModel
public static function GetByuserInvite($inviter_code)
{
// // 全表扫描username
// $dbmap = config('database.db_map');
// $dbmap = config('think-orm.db_map');
// $count = 0;
// foreach ($dbmap as $dbname) {
// if(!in_array($dbname, config('database.unset_db_map'))) {
// if(!in_array($dbname, config('think-orm.unset_db_map'))) {
// $connect = Db::connect($dbname);
// $data = $connect->name('tb_user')->where(['inviter_code' => $inviter_code])->count();
// $count += $data;
@ -69,11 +69,11 @@ class TbUser extends BaseModel
return $data_list;
// $dbmap = config('database.db_map');
// $dbmap = config('think-orm.db_map');
// $data_list = [];
// foreach ($dbmap as $dbname) {
//
// if(!in_array($dbname, config('database.unset_db_map'))) {
// if(!in_array($dbname, config('think-orm.unset_db_map'))) {
// $connect = Db::connect($dbname);
// $data_arr = $connect->name('tb_user')->where(['inviter_code' => $invitation_code])->field('user_id,avatar,user_name,user_id')->limit(page($page, $limit), $limit)->select()->toArray();
// if($data_arr) {
@ -104,9 +104,9 @@ class TbUser extends BaseModel
public static function GetByinvitationCode($invitation_code)
{
// 全表扫描username
$dbmap = config('database.db_map');
$dbmap = config('think-orm.db_map');
foreach ($dbmap as $dbname) {
if(!in_array($dbname, config('database.unset_db_map'))) {
if(!in_array($dbname, config('think-orm.unset_db_map'))) {
$connect = Db::connect($dbname);
$data = $connect->name('tb_user')->where(['invitation_code' => $invitation_code])->find();
if($data) {
@ -121,9 +121,9 @@ class TbUser extends BaseModel
public static function GetByinviterCodeCount($inviter_code)
{
// 全表扫描username
$dbmap = config('database.db_map');
$dbmap = config('think-orm.db_map');
foreach ($dbmap as $dbname) {
if(!in_array($dbname, config('database.unset_db_map'))) {
if(!in_array($dbname, config('think-orm.unset_db_map'))) {
$connect = Db::connect($dbname);
$data = $connect->name('tb_user')->where(['inviter_code' => $inviter_code])->count();
if($data) {
@ -281,7 +281,7 @@ class TbUser extends BaseModel
public static function selectUserByIdNew($user)
{
$db = Db::connect(config('database.search_library'));
$db = Db::connect(config('think-orm.search_library'));
$userVip = $db->name('user_vip')->where(['user_id' => $user['user_id']])->find();
$db->close();
if ($userVip) {

View File

@ -1,6 +1,6 @@
<?php
namespace app\api\model;
namespace app\czg\app\model;
use app\common\library\DatabaseRoute;

View File

@ -1,6 +1,6 @@
<?php
namespace app\api\model;
namespace app\czg\app\model;
use app\common\library\DatabaseRoute;
use app\common\model\BaseModel;

View File

@ -265,6 +265,7 @@ if (!function_exists('action_in_arr')) {
function action_in_arr(array $arr = []): bool
{
$arr = is_array($arr) ? $arr : explode(',', $arr);
if (!$arr) {
return false;
}