Admin.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace app\admin\model;
  3. use think\db\Query;
  4. use think\Model;
  5. use think\Session;
  6. /**
  7. *@method static Query|static proxy()
  8. *@method static Query|static sub()
  9. * @property bool is_seller
  10. */
  11. class Admin extends Model
  12. {
  13. // 开启自动写入时间戳字段
  14. protected $autoWriteTimestamp = 'int';
  15. // 定义时间戳字段名
  16. protected $createTime = 'createtime';
  17. protected $updateTime = 'updatetime';
  18. protected $readonly=['user_type'];
  19. protected $append=[];
  20. protected $hidden=['salt','password','token'];
  21. const UT_ADMIN=0;
  22. const UT_SELLER=1;
  23. /**
  24. * 重置用户密码
  25. * @author baiyouwen
  26. */
  27. public function resetPassword($uid, $NewPassword)
  28. {
  29. $passwd = $this->encryptPassword($NewPassword);
  30. $ret = $this->where(['id' => $uid])->update(['password' => $passwd]);
  31. return $ret;
  32. }
  33. // 密码加密
  34. protected static function encryptPassword($password, $salt = '', $encrypt = 'md5')
  35. {
  36. return $encrypt($password . $salt);
  37. }
  38. protected static function init()
  39. {
  40. self::beforeUpdate(function (self $admin){
  41. $data=$admin->getChangedData();
  42. if(isset($data['status']) && $data['status']=='normal'){
  43. $admin['logintime']=strtotime('-20days');
  44. }
  45. });
  46. self::beforeWrite(function (self $admin){
  47. });
  48. self::beforeInsert(function (self $admin){
  49. });
  50. self::beforeUpdate(function (self $admin){
  51. });
  52. }
  53. public function getIsManagerAttr($_,$admin){
  54. return !$admin['user_type']==self::UT_ADMIN;
  55. }
  56. public function getIsSellerAttr($_,$admin){
  57. return $admin['user_type']==self::UT_SELLER;
  58. }
  59. public function moneyLog(){
  60. return $this->hasMany(AdminMoneyLog::class);
  61. }
  62. public function getShareLinkAttr($_m,$model){
  63. return str_replace('{frommanager}',$model['id'],config('site.sell_share_url')?:'');
  64. return sprintf('%s/register',request()->domain(),);
  65. }
  66. }