控制台应用,yzncms本身基于tp5.1框架,里面的队列用不了,bug,坑
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Member.php 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Yzncms [ 御宅男工作室 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2018 http://yzncms.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 御宅男 <530765310@qq.com>
  10. // +----------------------------------------------------------------------
  11. // +----------------------------------------------------------------------
  12. // | 会员模型
  13. // +----------------------------------------------------------------------
  14. namespace app\admin\model\member;
  15. use think\Model;
  16. class Member extends Model
  17. {
  18. protected $autoWriteTimestamp = true;
  19. protected $updateTime = false;
  20. protected $createTime = 'reg_time';
  21. protected $insert = ['reg_ip', 'last_login_ip', 'last_login_time'];
  22. // 追加属性
  23. protected $append = [
  24. 'overduedate_text',
  25. 'groupname',
  26. ];
  27. protected function setRegIpAttr()
  28. {
  29. return request()->ip();
  30. }
  31. protected function setLastLoginIpAttr()
  32. {
  33. return request()->ip();
  34. }
  35. protected function setLastLoginTimeAttr()
  36. {
  37. return time();
  38. }
  39. protected function setBirthdayAttr($value)
  40. {
  41. return $value ? $value : null;
  42. }
  43. public function getGroupnameAttr($value, $data)
  44. {
  45. $group = cache("Member_Group");
  46. return isset($group[$data['groupid']]['name']) ? $group[$data['groupid']]['name'] : '';
  47. }
  48. public function getOverduedateTextAttr($value, $data)
  49. {
  50. $value = $value ?: ($data['overduedate'] ?? '');
  51. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  52. }
  53. /**
  54. * 获取头像
  55. * @param $value
  56. * @param $data
  57. * @return string
  58. */
  59. public function getAvatarAttr($value, $data)
  60. {
  61. $memberConfig = get_addon_config("member");
  62. if (!$value) {
  63. $value = $memberConfig['user_letter_avatar'] ? letter_avatar($data['nickname']) : config('public_url') . 'static/addons/member/img/avatar.png';
  64. }
  65. return cdnurl($value, true);
  66. }
  67. /**
  68. * 更新用户基本资料
  69. * @param $username 用户名
  70. * @param $oldpw 旧密码
  71. * @param string $newpw 新密码,如不修改为空
  72. * @param string $email 如不修改为空
  73. * @param int $ignoreoldpw 是否忽略旧密码
  74. * @param array $data 其他信息
  75. * @return bool
  76. */
  77. public function userEdit($username, $oldpw, $newpw = '', $email = '', $ignoreoldpw = 0, $data = [])
  78. {
  79. //验证旧密码是否正确
  80. if ($ignoreoldpw == 0) {
  81. $info = self::where(["username" => $username])->find();
  82. if (encrypt_password($oldpw, $info['encrypt']) != $info['password']) {
  83. $this->error = '旧密码错误!';
  84. return false;
  85. }
  86. }
  87. if ($newpw) {
  88. $passwordinfo = encrypt_password($newpw);
  89. $data = [
  90. "password" => $passwordinfo['password'],
  91. "encrypt" => $passwordinfo['encrypt'],
  92. ];
  93. } else {
  94. unset($data['password'], $data['encrypt']);
  95. }
  96. if ($email) {
  97. $data['email'] = $email;
  98. } else {
  99. unset($data['email']);
  100. }
  101. if (empty($data)) {
  102. return true;
  103. }
  104. if (self::allowField(true)->save($data, ["username" => $username]) !== false) {
  105. return true;
  106. } else {
  107. $this->error = '用户资料更新失败!';
  108. return false;
  109. }
  110. }
  111. public function group()
  112. {
  113. return $this->belongsTo('MemberGroup', 'groupid', 'id');
  114. }
  115. }