User.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. namespace app\admin\model\user;
  3. use think\Model;
  4. class User extends Model
  5. {
  6. // 表名
  7. protected $name = 'user';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'gender_text',
  17. 'logintime_text',
  18. 'wechat_time_text',
  19. 'auth_time_text',
  20. 'is_auth_text',
  21. 'is_goddess_text',
  22. 'vip_duetime_text',
  23. 'recharge_auth_text',
  24. 'invite_time_text'
  25. ];
  26. public function getGenderList()
  27. {
  28. return ['1' => __('Gender 1'), '0' => __('Gender -1')];
  29. }
  30. public function getIsAuthList()
  31. {
  32. return ['1' => __('Is_auth 1'), '0' => __('Is_auth 0')];
  33. }
  34. public function getIsGoddessList()
  35. {
  36. return ['1' => __('Is_goddess 1'), '0' => __('Is_goddess 0')];
  37. }
  38. public function getRechargeAuthList()
  39. {
  40. return ['1' => __('Recharge_auth 1'), '0' => __('Recharge_auth 0')];
  41. }
  42. public function getStatusList()
  43. {
  44. return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
  45. }
  46. public function getGenderTextAttr($value, $data)
  47. {
  48. $value = $value ? $value : (isset($data['gender']) ? $data['gender'] : '');
  49. $list = $this->getGenderList();
  50. return isset($list[$value]) ? $list[$value] : '';
  51. }
  52. public function getLogintimeTextAttr($value, $data)
  53. {
  54. $value = $value ? $value : (isset($data['logintime']) ? $data['logintime'] : '');
  55. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  56. }
  57. public function getWechatTimeTextAttr($value, $data)
  58. {
  59. $value = $value ? $value : (isset($data['wechat_time']) ? $data['wechat_time'] : '');
  60. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  61. }
  62. public function getAuthTimeTextAttr($value, $data)
  63. {
  64. $value = $value ? $value : (isset($data['auth_time']) ? $data['auth_time'] : '');
  65. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  66. }
  67. public function getIsAuthTextAttr($value, $data)
  68. {
  69. $value = $value ? $value : (isset($data['is_auth']) ? $data['is_auth'] : '');
  70. $list = $this->getIsAuthList();
  71. return isset($list[$value]) ? $list[$value] : '';
  72. }
  73. public function getIsGoddessTextAttr($value, $data)
  74. {
  75. $value = $value ? $value : (isset($data['is_goddess']) ? $data['is_goddess'] : '');
  76. $list = $this->getIsGoddessList();
  77. return isset($list[$value]) ? $list[$value] : '';
  78. }
  79. public function getVipDuetimeTextAttr($value, $data)
  80. {
  81. $value = $value ? $value : (isset($data['vip_duetime']) ? $data['vip_duetime'] : '');
  82. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  83. }
  84. public function getRechargeAuthTextAttr($value, $data)
  85. {
  86. $value = $value ? $value : (isset($data['recharge_auth']) ? $data['recharge_auth'] : '');
  87. $list = $this->getRechargeAuthList();
  88. return isset($list[$value]) ? $list[$value] : '';
  89. }
  90. public function getInviteTimeTextAttr($value, $data)
  91. {
  92. $value = $value ? $value : (isset($data['invite_time']) ? $data['invite_time'] : '');
  93. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  94. }
  95. protected function setLogintimeAttr($value)
  96. {
  97. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  98. }
  99. protected function setWechatTimeAttr($value)
  100. {
  101. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  102. }
  103. protected function setAuthTimeAttr($value)
  104. {
  105. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  106. }
  107. protected function setVipDuetimeAttr($value)
  108. {
  109. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  110. }
  111. protected function setInviteTimeAttr($value)
  112. {
  113. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  114. }
  115. }