53 lines
1.7 KiB
PHP
53 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace app\api\model;
|
|
|
|
use app\common\library\DatabaseRoute;
|
|
use app\common\model\BaseModel;
|
|
use think\facade\Db;
|
|
|
|
class UserInfo extends BaseModel
|
|
{
|
|
public static function getUsersByNameAndCertNo($cert_name, $cert_no)
|
|
{
|
|
// 全表扫描username
|
|
// $dbmap = config('database.db_map');
|
|
$data = [];
|
|
// foreach ($dbmap as $dbname) {
|
|
// if(!in_array($dbname, config('database.unset_db_map'))) {
|
|
// $connect = Db::connect($dbname);
|
|
// $data_arr = $connect->name('user_info')->where(['cert_name' => $cert_name, 'cert_no' => $cert_no])->field('user_id')->select()->toArray();
|
|
// if($data_arr) {
|
|
// foreach ($data_arr as $k => $v) {
|
|
// $data[] = $v['user_id'];
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
|
|
$data_arr = DatabaseRoute::getAllDbData('user_info', function ($query) use ($cert_no, $cert_name) {
|
|
return $query->where(['cert_name' => $cert_name, 'cert_no' => $cert_no])->field('user_id');
|
|
})->select()->toArray();
|
|
if($data_arr) {
|
|
foreach ($data_arr as $k => $v) {
|
|
$data[] = $v['user_id'];
|
|
}
|
|
}
|
|
return $data;
|
|
|
|
}
|
|
|
|
public static function getByUserIdOrSave(int $userId)
|
|
{
|
|
$userInfo = DatabaseRoute::getDb('user_info', $userId)->find();
|
|
if (!$userInfo) {
|
|
$id = DatabaseRoute::getDb('user_info', $userId, true)->insertGetId([
|
|
'user_id' => $userId
|
|
]);
|
|
$userInfo['id'] = $id;
|
|
$userInfo['user_id'] = $userId;
|
|
}
|
|
return $userInfo;
|
|
}
|
|
} |