Useraudit.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Useraudit extends Model
  5. {
  6. // 表名
  7. protected $name = 'user_audit';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = false;
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'status_text',
  17. 'audittime_text',
  18. 'type_text',
  19. 'gender_text',
  20. ];
  21. public function getStatusList()
  22. {
  23. return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2')];
  24. }
  25. public function getStatusTextAttr($value, $data)
  26. {
  27. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  28. $list = $this->getStatusList();
  29. return isset($list[$value]) ? $list[$value] : '';
  30. }
  31. public function getTypeList()
  32. {
  33. return ['photo_images' => __('Type photo_images'), 'avatar' => __('Type avatar'), 'audio_bio' => __('Type audio_bio'), 'video_bio' => __('Type video_bio')];
  34. }
  35. public function getGenderList()
  36. {
  37. return ['-1' => __('User.Gender -1'),'1' => __('User.Gender 1'), '0' => __('User.Gender 0')];
  38. }
  39. public function getGenderTextAttr($value, $data)
  40. {
  41. $value = $value ? $value : (isset($data['gender']) ? $data['gender'] : '');
  42. $list = $this->getGenderList();
  43. return isset($list[$value]) ? $list[$value] : '';
  44. }
  45. public function getTypeTextAttr($value, $data)
  46. {
  47. $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
  48. $list = $this->getTypeList();
  49. return isset($list[$value]) ? $list[$value] : '';
  50. }
  51. public function getAudittimeTextAttr($value, $data)
  52. {
  53. $value = $value ? $value : (isset($data['audittime']) ? $data['audittime'] : '');
  54. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  55. }
  56. protected function setAudittimeAttr($value)
  57. {
  58. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  59. }
  60. public function user()
  61. {
  62. return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
  63. }
  64. }