User.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. namespace app\admin\model;
  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. 'onlinetime_text',
  19. 'is_live_text',
  20. 'is_online_text',
  21. 'has_info_text',
  22. 'is_auth_text',
  23. 'is_guild_text',
  24. 'status_text',
  25. 'is_cool_text',
  26. 'is_manager_text'
  27. ];
  28. public function getGenderList()
  29. {
  30. return ['1' => __('Gender 1'), '0' => __('Gender 0')];
  31. }
  32. public function getIsLiveList()
  33. {
  34. return ['1' => __('Is_live 1'), '0' => __('Is_live 0')];
  35. }
  36. public function getIsOnlineList()
  37. {
  38. return ['1' => __('Is_online 1'), '0' => __('Is_online 0')];
  39. }
  40. public function getHasInfoList()
  41. {
  42. return ['1' => __('Has_info 1'), '0' => __('Has_info 0')];
  43. }
  44. public function getIsAuthList()
  45. {
  46. return ['1' => __('Is_auth 1'), '0' => __('Is_auth 0'), '-1' => __('Is_auth -1'), '2' => __('Is_auth 2')];
  47. }
  48. public function getIsGuildList()
  49. {
  50. return ['1' => __('Is_guild 1'), '0' => __('Is_guild 0'), '-1' => __('Is_guild -1'), '2' => __('Is_guild 2'), '3' => __('Is_guild 3')];
  51. }
  52. public function getStatusList()
  53. {
  54. return ['1' => __('Status 1'), '0' => __('Status 0'), '-1' => __('Status -1')];
  55. }
  56. public function getIsCoolList()
  57. {
  58. return ['0' => __('Is_cool 0'), '1' => __('Is_cool 1')];
  59. }
  60. public function getIsManagerList()
  61. {
  62. return ['0' => __('Is_manager 0'), '1' => __('Is_manager 1')];
  63. }
  64. public function getGenderTextAttr($value, $data)
  65. {
  66. $value = $value ? $value : (isset($data['gender']) ? $data['gender'] : '');
  67. $list = $this->getGenderList();
  68. return isset($list[$value]) ? $list[$value] : '';
  69. }
  70. public function getLogintimeTextAttr($value, $data)
  71. {
  72. $value = $value ? $value : (isset($data['logintime']) ? $data['logintime'] : '');
  73. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  74. }
  75. public function getOnlinetimeTextAttr($value, $data)
  76. {
  77. $value = $value ? $value : (isset($data['onlinetime']) ? $data['onlinetime'] : '');
  78. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  79. }
  80. public function getIsLiveTextAttr($value, $data)
  81. {
  82. $value = $value ? $value : (isset($data['is_live']) ? $data['is_live'] : '');
  83. $list = $this->getIsLiveList();
  84. return isset($list[$value]) ? $list[$value] : '';
  85. }
  86. public function getIsOnlineTextAttr($value, $data)
  87. {
  88. $value = $value ? $value : (isset($data['is_online']) ? $data['is_online'] : '');
  89. $list = $this->getIsOnlineList();
  90. return isset($list[$value]) ? $list[$value] : '';
  91. }
  92. public function getHasInfoTextAttr($value, $data)
  93. {
  94. $value = $value ? $value : (isset($data['has_info']) ? $data['has_info'] : '');
  95. $list = $this->getHasInfoList();
  96. return isset($list[$value]) ? $list[$value] : '';
  97. }
  98. public function getIsAuthTextAttr($value, $data)
  99. {
  100. $value = $value ? $value : (isset($data['is_auth']) ? $data['is_auth'] : '');
  101. $list = $this->getIsAuthList();
  102. return isset($list[$value]) ? $list[$value] : '';
  103. }
  104. public function getIsGuildTextAttr($value, $data)
  105. {
  106. $value = $value ? $value : (isset($data['is_guild']) ? $data['is_guild'] : '');
  107. $list = $this->getIsGuildList();
  108. return isset($list[$value]) ? $list[$value] : '';
  109. }
  110. public function getStatusTextAttr($value, $data)
  111. {
  112. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  113. $list = $this->getStatusList();
  114. return isset($list[$value]) ? $list[$value] : '';
  115. }
  116. public function getIsCoolTextAttr($value, $data)
  117. {
  118. $value = $value ? $value : (isset($data['is_cool']) ? $data['is_cool'] : '');
  119. $list = $this->getIsCoolList();
  120. return isset($list[$value]) ? $list[$value] : '';
  121. }
  122. public function getIsManagerTextAttr($value, $data)
  123. {
  124. $value = $value ? $value : (isset($data['is_manager']) ? $data['is_manager'] : '');
  125. $list = $this->getIsManagerList();
  126. return isset($list[$value]) ? $list[$value] : '';
  127. }
  128. protected function setLogintimeAttr($value)
  129. {
  130. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  131. }
  132. protected function setOnlinetimeAttr($value)
  133. {
  134. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  135. }
  136. public function userwallet()
  137. {
  138. return $this->belongsTo('Userwallet', 'id', 'user_id', [], 'LEFT')->setEagerlyType(0);
  139. }
  140. }