add
This commit is contained in:
80
app/common/model/SysUser.php
Normal file
80
app/common/model/SysUser.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\czg\model\SysCaptcha;
|
||||
use ba\Random;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Db;
|
||||
|
||||
class SysUser extends BaseModel
|
||||
{
|
||||
|
||||
public static function adda()
|
||||
{
|
||||
SysUser::create([
|
||||
'user_id' => rand(000000, 999999),
|
||||
'username' => '哎呀' . rand(000000, 999999),
|
||||
]);
|
||||
}
|
||||
|
||||
// 查询username
|
||||
public static function GetByusername($username)
|
||||
{
|
||||
// 全表扫描username
|
||||
$dbmap = config('database.db_map');
|
||||
foreach ($dbmap as $dbname) {
|
||||
if(!in_array($dbname, config('database.unset_db_map'))) {
|
||||
$connect = Db::connect($dbname);
|
||||
$data = $connect->name('sys_user')->where(['username' => $username])->find();
|
||||
if($data) {
|
||||
// 如果查到直接跳出循环并保存缓存
|
||||
Cache::set('admin_info_' . $username, $data['user_id']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
public static function GetByQrcode($qd_rcode)
|
||||
{
|
||||
// 全表扫描username
|
||||
return DatabaseRoute::getAllDbData('sys_user', function ($query) use ($qd_rcode) {
|
||||
return $query->where([
|
||||
'qd_code' => $qd_rcode
|
||||
]);
|
||||
})->find();
|
||||
}
|
||||
|
||||
public static function updateSysMoney($userId, $money, $type)
|
||||
{
|
||||
$count = Db::name('sys_user_money')->where([
|
||||
'user_id' => $userId
|
||||
])->count();
|
||||
if (!$count) {
|
||||
Db::name('sys_user_money')->where([
|
||||
'user_id' => $userId
|
||||
])->insert([
|
||||
'id' => Random::generateRandomPrefixedId(19),
|
||||
'user_id' => $userId,
|
||||
'money' => 0
|
||||
]);
|
||||
}
|
||||
$model = Db::name('sys_user_money');
|
||||
if ($type) {
|
||||
$model->inc('money', floatval($money))->where([
|
||||
'user_id' => $userId
|
||||
])->update();
|
||||
}else{
|
||||
$model->dec('money', floatval($money))->where([
|
||||
'user_id' => $userId
|
||||
])->update();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user