78 lines
2.1 KiB
PHP
78 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace app\common\model;
|
|
|
|
|
|
use app\common\library\DatabaseRoute;
|
|
use extend\ba\Random;
|
|
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('think-orm.db_map');
|
|
foreach ($dbmap as $dbname) {
|
|
if(!in_array($dbname, config('think-orm.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();
|
|
}
|
|
}
|
|
|
|
|
|
} |