User.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. 'idcard_status_text'
  21. ];
  22. public function getStatusList()
  23. {
  24. return ['1' => __('Status 1'), '0' => __('Status 0'), '-1' => __('Status -1')];
  25. }
  26. public function getIdcardStatusList()
  27. {
  28. return ['-1' => __('Idcard_status -1'), '0' => __('Idcard_status 0'), '1' => __('Idcard_status 1'), '2' => __('Idcard_status 2')];
  29. }
  30. public function getPrevtimeTextAttr($value, $data)
  31. {
  32. $value = $value ? $value : (isset($data['prevtime']) ? $data['prevtime'] : '');
  33. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  34. }
  35. public function getLogintimeTextAttr($value, $data)
  36. {
  37. $value = $value ? $value : (isset($data['logintime']) ? $data['logintime'] : '');
  38. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  39. }
  40. public function getJointimeTextAttr($value, $data)
  41. {
  42. $value = $value ? $value : (isset($data['jointime']) ? $data['jointime'] : '');
  43. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  44. }
  45. public function getStatusTextAttr($value, $data)
  46. {
  47. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  48. $list = $this->getStatusList();
  49. return isset($list[$value]) ? $list[$value] : '';
  50. }
  51. public function getIdcardStatusTextAttr($value, $data)
  52. {
  53. $value = $value ? $value : (isset($data['idcard_status']) ? $data['idcard_status'] : '');
  54. $list = $this->getIdcardStatusList();
  55. return isset($list[$value]) ? $list[$value] : '';
  56. }
  57. protected function setPrevtimeAttr($value)
  58. {
  59. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  60. }
  61. protected function setLogintimeAttr($value)
  62. {
  63. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  64. }
  65. protected function setJointimeAttr($value)
  66. {
  67. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  68. }
  69. public function group()
  70. {
  71. return $this->belongsTo('UserGroup', 'group_id', 'id', [], 'LEFT')->setEagerlyType(0);
  72. }
  73. public function wallet()
  74. {
  75. return $this->belongsTo('Userwallet', 'id', 'user_id', [], 'LEFT')->setEagerlyType(0);
  76. }
  77. }