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;
|
|
|
|
|
|
|
|
class User extends Model
|
|
|
|
{
|
|
|
|
protected $autoWriteTimestamp = 'int';
|
|
|
|
|
|
|
|
protected $createTime = 'createtime';
|
|
|
|
protected $updateTime = 'updatetime';
|
|
|
|
|
|
|
|
public function getAvatarAttr($value)
|
|
|
|
{
|
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
|
|
|
|
|
|
|
public function resetPassword($uid, $newPassword)
|
|
|
|
{
|
|
|
|
$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
|
|
|
|
|
|
|
public function getMoneyAttr($value)
|
|
|
|
{
|
|
|
|
return bcdiv($value, 100, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 用户的余额是不可以直接进行修改的,请通过 UserMoneyLog 模型插入记录来实现自动修改余额
|
|
|
|
* 此处定义上 money 的修改器仅为防止直接对余额的修改造成数据错乱
|
|
|
|
*/
|
|
|
|
public function setMoneyAttr($value)
|
|
|
|
{
|
|
|
|
return bcmul($value, 100, 2);
|
|
|
|
}
|
2022-06-19 16:07:34 +00:00
|
|
|
}
|