2022-06-19 16:07:34 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace app\common\model;
|
|
|
|
|
2022-06-23 11:52:18 +00:00
|
|
|
use ba\Random;
|
2022-06-19 16:07:34 +00:00
|
|
|
use think\Model;
|
|
|
|
use think\facade\Config;
|
|
|
|
|
2023-06-25 01:31:03 +00:00
|
|
|
/**
|
|
|
|
* 会员公共模型
|
|
|
|
* @property int $id 会员ID
|
|
|
|
* @property string $password 密码密文
|
|
|
|
* @property string $salt 密码盐
|
|
|
|
* @property int $login_failure 登录失败次数
|
|
|
|
* @property string $last_login_time 上次登录时间
|
|
|
|
* @property string $last_login_ip 上次登录IP
|
2023-06-25 18:36:53 +00:00
|
|
|
* @property string $email 会员邮箱
|
|
|
|
* @property string $mobile 会员手机号
|
2023-06-25 01:31:03 +00:00
|
|
|
*/
|
2022-06-19 16:07:34 +00:00
|
|
|
class User extends Model
|
|
|
|
{
|
2023-06-23 14:13:55 +00:00
|
|
|
protected $autoWriteTimestamp = true;
|
2022-06-19 16:07:34 +00:00
|
|
|
|
2023-06-25 20:18:52 +00:00
|
|
|
public function getAvatarAttr($value): string
|
2022-06-19 16:07:34 +00:00
|
|
|
{
|
2022-12-25 10:54:24 +00:00
|
|
|
return full_url(htmlspecialchars_decode($value), true, Config::get('buildadmin.default_avatar'));
|
2022-06-19 16:07:34 +00:00
|
|
|
}
|
2022-06-23 11:52:18 +00:00
|
|
|
|
2023-06-25 20:18:52 +00:00
|
|
|
public function resetPassword($uid, $newPassword): int|User
|
2022-06-23 11:52:18 +00:00
|
|
|
{
|
|
|
|
$salt = Random::build('alnum', 16);
|
|
|
|
$passwd = encrypt_password($newPassword, $salt);
|
2022-08-23 16:27:21 +00:00
|
|
|
return $this->where(['id' => $uid])->update(['password' => $passwd, 'salt' => $salt]);
|
2022-06-23 11:52:18 +00:00
|
|
|
}
|
2022-06-26 11:27:08 +00:00
|
|
|
|
2023-06-25 20:18:52 +00:00
|
|
|
public function getMoneyAttr($value): string
|
2022-06-26 11:27:08 +00:00
|
|
|
{
|
|
|
|
return bcdiv($value, 100, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 用户的余额是不可以直接进行修改的,请通过 UserMoneyLog 模型插入记录来实现自动修改余额
|
|
|
|
* 此处定义上 money 的修改器仅为防止直接对余额的修改造成数据错乱
|
|
|
|
*/
|
2023-06-25 20:18:52 +00:00
|
|
|
public function setMoneyAttr($value): string
|
2022-06-26 11:27:08 +00:00
|
|
|
{
|
|
|
|
return bcmul($value, 100, 2);
|
|
|
|
}
|
2022-06-19 16:07:34 +00:00
|
|
|
}
|