User.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class User extends Model
  5. {
  6. // 表名
  7. protected $table = 'user';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'integer';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'prevtime_text',
  17. 'logintime_text',
  18. 'jointime_text',
  19. 'status_text',
  20. 'oldstatus_text',
  21. 'notice_email_text',
  22. 'notice_whatsapp_text',
  23. 'is_first_text'
  24. ];
  25. public function getStatusList()
  26. {
  27. return ['0' => __('Status 0'), '1' => __('Status 1')];
  28. }
  29. public function getOldStatusList()
  30. {
  31. return ['0' => __('Oldstatus 0'), '1' => __('Oldstatus 1')];
  32. }
  33. public function getNoticeEmailList()
  34. {
  35. return ['1' => __('Notice_email 1'), '0' => __('Notice_email 0')];
  36. }
  37. public function getNoticeWhatsappList()
  38. {
  39. return ['1' => __('Notice_whatsapp 1'), '0' => __('Notice_whatsapp 0')];
  40. }
  41. public function getIsFirstList()
  42. {
  43. return ['0' => __('Is_first 0'), '1' => __('Is_first 1')];
  44. }
  45. public function getPrevtimeTextAttr($value, $data)
  46. {
  47. $value = $value ? $value : (isset($data['prevtime']) ? $data['prevtime'] : '');
  48. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  49. }
  50. public function getLogintimeTextAttr($value, $data)
  51. {
  52. $value = $value ? $value : (isset($data['logintime']) ? $data['logintime'] : '');
  53. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  54. }
  55. public function getJointimeTextAttr($value, $data)
  56. {
  57. $value = $value ? $value : (isset($data['jointime']) ? $data['jointime'] : '');
  58. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  59. }
  60. public function getStatusTextAttr($value, $data)
  61. {
  62. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  63. $list = $this->getStatusList();
  64. return isset($list[$value]) ? $list[$value] : '';
  65. }
  66. public function getOldStatusTextAttr($value, $data)
  67. {
  68. $value = $value ? $value : (isset($data['oldstatus']) ? $data['oldstatus'] : '');
  69. $list = $this->getOldStatusList();
  70. return isset($list[$value]) ? $list[$value] : '';
  71. }
  72. public function getNoticeEmailTextAttr($value, $data)
  73. {
  74. $value = $value ? $value : (isset($data['notice_email']) ? $data['notice_email'] : '');
  75. $list = $this->getNoticeEmailList();
  76. return isset($list[$value]) ? $list[$value] : '';
  77. }
  78. public function getNoticeWhatsappTextAttr($value, $data)
  79. {
  80. $value = $value ? $value : (isset($data['notice_whatsapp']) ? $data['notice_whatsapp'] : '');
  81. $list = $this->getNoticeWhatsappList();
  82. return isset($list[$value]) ? $list[$value] : '';
  83. }
  84. public function getIsFirstTextAttr($value, $data)
  85. {
  86. $value = $value ? $value : (isset($data['is_first']) ? $data['is_first'] : '');
  87. $list = $this->getIsFirstList();
  88. return isset($list[$value]) ? $list[$value] : '';
  89. }
  90. protected function setPrevtimeAttr($value)
  91. {
  92. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  93. }
  94. protected function setLogintimeAttr($value)
  95. {
  96. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  97. }
  98. protected function setJointimeAttr($value)
  99. {
  100. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  101. }
  102. public function userwallet()
  103. {
  104. return $this->belongsTo('Userwallet', 'id', 'user_id', [], 'LEFT')->setEagerlyType(0);
  105. }
  106. }