add
This commit is contained in:
33
app/admin/model/SysUserMoney.php
Normal file
33
app/admin/model/SysUserMoney.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model;
|
||||
|
||||
use app\common\library\DatabaseRoute;
|
||||
use ba\Random;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Db;
|
||||
use think\Model;
|
||||
use think\model\relation\BelongsTo;
|
||||
|
||||
|
||||
class SysUserMoney extends Model
|
||||
{
|
||||
|
||||
public static function selectSysUserMoneyByUserId($userId):array
|
||||
{
|
||||
$db = Db::connect(get_slave_connect_name());
|
||||
// 查询用户钱包信息
|
||||
$userMoney = $db->name('sys_user_money')->where('user_id', $userId)->find();
|
||||
// 若不存在,则创建新记录
|
||||
if (is_null($userMoney)) {
|
||||
$userMoney = [
|
||||
'user_id' => $userId,
|
||||
'money' => 0.00,
|
||||
'id' => Random::generateRandomPrefixedId(19),
|
||||
];
|
||||
$id = Db::connect(get_master_connect_name())->name('sys_user_money')->insert($userMoney);
|
||||
}
|
||||
return $db->name('sys_user_money')->where('user_id', $userId)->find();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user