User.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. 'notice_email_text',
  21. 'notice_whatsapp_text',
  22. 'is_first_text'
  23. ];
  24. public function getStatusList()
  25. {
  26. return ['0' => __('Status 0'), '1' => __('Status 1')];
  27. }
  28. public function getNoticeEmailList()
  29. {
  30. return ['1' => __('Notice_email 1'), '0' => __('Notice_email 0')];
  31. }
  32. public function getNoticeWhatsappList()
  33. {
  34. return ['1' => __('Notice_whatsapp 1'), '0' => __('Notice_whatsapp 0')];
  35. }
  36. public function getIsFirstList()
  37. {
  38. return ['0' => __('Is_first 0'), '1' => __('Is_first 1')];
  39. }
  40. public function getPrevtimeTextAttr($value, $data)
  41. {
  42. $value = $value ? $value : (isset($data['prevtime']) ? $data['prevtime'] : '');
  43. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  44. }
  45. public function getLogintimeTextAttr($value, $data)
  46. {
  47. $value = $value ? $value : (isset($data['logintime']) ? $data['logintime'] : '');
  48. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  49. }
  50. public function getJointimeTextAttr($value, $data)
  51. {
  52. $value = $value ? $value : (isset($data['jointime']) ? $data['jointime'] : '');
  53. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  54. }
  55. public function getStatusTextAttr($value, $data)
  56. {
  57. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  58. $list = $this->getStatusList();
  59. return isset($list[$value]) ? $list[$value] : '';
  60. }
  61. public function getNoticeEmailTextAttr($value, $data)
  62. {
  63. $value = $value ? $value : (isset($data['notice_email']) ? $data['notice_email'] : '');
  64. $list = $this->getNoticeEmailList();
  65. return isset($list[$value]) ? $list[$value] : '';
  66. }
  67. public function getNoticeWhatsappTextAttr($value, $data)
  68. {
  69. $value = $value ? $value : (isset($data['notice_whatsapp']) ? $data['notice_whatsapp'] : '');
  70. $list = $this->getNoticeWhatsappList();
  71. return isset($list[$value]) ? $list[$value] : '';
  72. }
  73. public function getIsFirstTextAttr($value, $data)
  74. {
  75. $value = $value ? $value : (isset($data['is_first']) ? $data['is_first'] : '');
  76. $list = $this->getIsFirstList();
  77. return isset($list[$value]) ? $list[$value] : '';
  78. }
  79. protected function setPrevtimeAttr($value)
  80. {
  81. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  82. }
  83. protected function setLogintimeAttr($value)
  84. {
  85. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  86. }
  87. protected function setJointimeAttr($value)
  88. {
  89. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  90. }
  91. }