Vipuser.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Vipuser 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. 'prevtime_text',
  17. 'logintime_text',
  18. 'jointime_text',
  19. 'status_text',
  20. 'gender_text',
  21. 'invite_time_text',
  22. 'experiencetime_text',
  23. 'freenumbertime_text'
  24. ];
  25. public function getStatusList()
  26. {
  27. return ['1' => __('Status 1'), '2' => __('Status 2')];
  28. }
  29. public function getGenderList()
  30. {
  31. return ['1' => __('Gender 1'), '2' => __('Gender 2')];
  32. }
  33. public function getPrevtimeTextAttr($value, $data)
  34. {
  35. $value = $value ? $value : (isset($data['prevtime']) ? $data['prevtime'] : '');
  36. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  37. }
  38. public function getLogintimeTextAttr($value, $data)
  39. {
  40. $value = $value ? $value : (isset($data['logintime']) ? $data['logintime'] : '');
  41. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  42. }
  43. public function getJointimeTextAttr($value, $data)
  44. {
  45. $value = $value ? $value : (isset($data['jointime']) ? $data['jointime'] : '');
  46. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  47. }
  48. public function getStatusTextAttr($value, $data)
  49. {
  50. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  51. $list = $this->getStatusList();
  52. return isset($list[$value]) ? $list[$value] : '';
  53. }
  54. public function getGenderTextAttr($value, $data)
  55. {
  56. $value = $value ? $value : (isset($data['gender']) ? $data['gender'] : '');
  57. $list = $this->getGenderList();
  58. return isset($list[$value]) ? $list[$value] : '';
  59. }
  60. public function getInviteTimeTextAttr($value, $data)
  61. {
  62. $value = $value ? $value : (isset($data['invite_time']) ? $data['invite_time'] : '');
  63. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  64. }
  65. public function getExperiencetimeTextAttr($value, $data)
  66. {
  67. $value = $value ? $value : (isset($data['experiencetime']) ? $data['experiencetime'] : '');
  68. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  69. }
  70. public function getFreenumbertimeTextAttr($value, $data)
  71. {
  72. $value = $value ? $value : (isset($data['freenumbertime']) ? $data['freenumbertime'] : '');
  73. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  74. }
  75. protected function setPrevtimeAttr($value)
  76. {
  77. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  78. }
  79. protected function setLogintimeAttr($value)
  80. {
  81. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  82. }
  83. protected function setJointimeAttr($value)
  84. {
  85. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  86. }
  87. protected function setInviteTimeAttr($value)
  88. {
  89. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  90. }
  91. protected function setExperiencetimeAttr($value)
  92. {
  93. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  94. }
  95. protected function setFreenumbertimeAttr($value)
  96. {
  97. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  98. }
  99. }