User.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. 'birthday_text',
  17. 'prevtime_text',
  18. 'logintime_text',
  19. 'jointime_text',
  20. 'status_text',
  21. 'oldstatus_text',
  22. 'notice_email_text',
  23. 'notice_whatsapp_text',
  24. 'notice_phonecall_text',
  25. 'is_first_text'
  26. ];
  27. public function getStatusList()
  28. {
  29. return ['-1' => __('Status -1'), '0' => __('Status 0'), '1' => __('Status 1')];
  30. }
  31. public function getOldstatusList()
  32. {
  33. return ['0' => __('Oldstatus 0'), '1' => __('Oldstatus 1')];
  34. }
  35. public function getNoticeEmailList()
  36. {
  37. return ['1' => __('Notice_email 1'), '0' => __('Notice_email 0')];
  38. }
  39. public function getNoticeWhatsappList()
  40. {
  41. return ['1' => __('Notice_whatsapp 1'), '0' => __('Notice_whatsapp 0')];
  42. }
  43. public function getNoticePhonecallList()
  44. {
  45. return ['1' => __('Notice_phonecall 1'), '0' => __('Notice_phonecall 0')];
  46. }
  47. public function getIsFirstList()
  48. {
  49. return ['0' => __('Is_first 0'), '1' => __('Is_first 1')];
  50. }
  51. public function getPrevtimeTextAttr($value, $data)
  52. {
  53. $value = $value ? $value : (isset($data['prevtime']) ? $data['prevtime'] : '');
  54. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  55. }
  56. public function getBirthdayTextAttr($value, $data)
  57. {
  58. $value = $value ? $value : (isset($data['birthday']) ? $data['birthday'] : '');
  59. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  60. }
  61. public function getLogintimeTextAttr($value, $data)
  62. {
  63. $value = $value ? $value : (isset($data['logintime']) ? $data['logintime'] : '');
  64. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  65. }
  66. public function getJointimeTextAttr($value, $data)
  67. {
  68. $value = $value ? $value : (isset($data['jointime']) ? $data['jointime'] : '');
  69. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  70. }
  71. public function getStatusTextAttr($value, $data)
  72. {
  73. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  74. $list = $this->getStatusList();
  75. return isset($list[$value]) ? $list[$value] : '';
  76. }
  77. public function getOldstatusTextAttr($value, $data)
  78. {
  79. $value = $value ? $value : (isset($data['oldstatus']) ? $data['oldstatus'] : '');
  80. $list = $this->getOldstatusList();
  81. return isset($list[$value]) ? $list[$value] : '';
  82. }
  83. public function getNoticeEmailTextAttr($value, $data)
  84. {
  85. $value = $value ? $value : (isset($data['notice_email']) ? $data['notice_email'] : '');
  86. $list = $this->getNoticeEmailList();
  87. return isset($list[$value]) ? $list[$value] : '';
  88. }
  89. public function getNoticeWhatsappTextAttr($value, $data)
  90. {
  91. $value = $value ? $value : (isset($data['notice_whatsapp']) ? $data['notice_whatsapp'] : '');
  92. $list = $this->getNoticeWhatsappList();
  93. return isset($list[$value]) ? $list[$value] : '';
  94. }
  95. public function getNoticePhonecallTextAttr($value, $data)
  96. {
  97. $value = $value ? $value : (isset($data['notice_phonecall']) ? $data['notice_phonecall'] : '');
  98. $list = $this->getNoticePhonecallList();
  99. return isset($list[$value]) ? $list[$value] : '';
  100. }
  101. public function getIsFirstTextAttr($value, $data)
  102. {
  103. $value = $value ? $value : (isset($data['is_first']) ? $data['is_first'] : '');
  104. $list = $this->getIsFirstList();
  105. return isset($list[$value]) ? $list[$value] : '';
  106. }
  107. protected function setPrevtimeAttr($value)
  108. {
  109. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  110. }
  111. protected function setBirthdayAttr($value)
  112. {
  113. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  114. }
  115. protected function setLogintimeAttr($value)
  116. {
  117. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  118. }
  119. protected function setJointimeAttr($value)
  120. {
  121. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  122. }
  123. public function userwallet()
  124. {
  125. return $this->belongsTo('Userwallet', 'id', 'user_id', [], 'LEFT')->setEagerlyType(0);
  126. }
  127. }