User.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace app\common\model;
  3. use ba\Random;
  4. use think\Model;
  5. use think\facade\Config;
  6. class User extends Model
  7. {
  8. protected $autoWriteTimestamp = 'int';
  9. protected $createTime = 'createtime';
  10. protected $updateTime = 'updatetime';
  11. public function getAvatarAttr($value)
  12. {
  13. return full_url(htmlspecialchars_decode($value), true, Config::get('buildadmin.default_avatar'));
  14. }
  15. public function resetPassword($uid, $newPassword)
  16. {
  17. $salt = Random::build('alnum', 16);
  18. $passwd = encrypt_password($newPassword, $salt);
  19. return $this->where(['id' => $uid])->update(['password' => $passwd, 'salt' => $salt]);
  20. }
  21. public function getMoneyAttr($value)
  22. {
  23. return bcdiv($value, 100, 2);
  24. }
  25. /**
  26. * 用户的余额是不可以直接进行修改的,请通过 UserMoneyLog 模型插入记录来实现自动修改余额
  27. * 此处定义上 money 的修改器仅为防止直接对余额的修改造成数据错乱
  28. */
  29. public function setMoneyAttr($value)
  30. {
  31. return bcmul($value, 100, 2);
  32. }
  33. }