Party.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. namespace app\admin\model\party;
  3. use think\Model;
  4. class Party extends Model
  5. {
  6. // 表名
  7. protected $name = 'party';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'room_type_text',
  17. 'is_online_text',
  18. 'status_text',
  19. 'is_recommend_text',
  20. 'is_screen_text',
  21. 'on_model_text'
  22. ];
  23. public function getRoomTypeList()
  24. {
  25. return ['1' => __('Room_type 1'), '2' => __('Room_type 2')];
  26. }
  27. public function getIsOnlineList()
  28. {
  29. return ['1' => __('Is_online 1'), '0' => __('Is_online 0')];
  30. }
  31. public function getStatusList()
  32. {
  33. return ['-1' => __('Status -1'), '1' => __('Status 1')];
  34. }
  35. public function getIsRecommendList()
  36. {
  37. return ['1' => __('Is_recommend 1'), '0' => __('Is_recommend 0')];
  38. }
  39. public function getIsCloseList()
  40. {
  41. return ['1' => __('Is_close 1'), '0' => __('Is_close 0')];
  42. }
  43. public function getIsScreenList()
  44. {
  45. return ['1' => __('Is_screen 1'), '0' => __('Is_screen 0')];
  46. }
  47. public function getOnModelList()
  48. {
  49. return ['1' => __('On_model 1'), '2' => __('On_model 2')];
  50. }
  51. public function getRoomTypeTextAttr($value, $data)
  52. {
  53. $value = $value ? $value : (isset($data['room_type']) ? $data['room_type'] : '');
  54. $list = $this->getRoomTypeList();
  55. return isset($list[$value]) ? $list[$value] : '';
  56. }
  57. public function getIsOnlineTextAttr($value, $data)
  58. {
  59. $value = $value ? $value : (isset($data['is_online']) ? $data['is_online'] : '');
  60. $list = $this->getIsOnlineList();
  61. return isset($list[$value]) ? $list[$value] : '';
  62. }
  63. public function getStatusTextAttr($value, $data)
  64. {
  65. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  66. $list = $this->getStatusList();
  67. return isset($list[$value]) ? $list[$value] : '';
  68. }
  69. public function getIsRecommendTextAttr($value, $data)
  70. {
  71. $value = $value ? $value : (isset($data['is_recommend']) ? $data['is_recommend'] : '');
  72. $list = $this->getIsRecommendList();
  73. return isset($list[$value]) ? $list[$value] : '';
  74. }
  75. public function getIsScreenTextAttr($value, $data)
  76. {
  77. $value = $value ? $value : (isset($data['is_screen']) ? $data['is_screen'] : '');
  78. $list = $this->getIsScreenList();
  79. return isset($list[$value]) ? $list[$value] : '';
  80. }
  81. public function getOnModelTextAttr($value, $data)
  82. {
  83. $value = $value ? $value : (isset($data['on_model']) ? $data['on_model'] : '');
  84. $list = $this->getOnModelList();
  85. return isset($list[$value]) ? $list[$value] : '';
  86. }
  87. public function user()
  88. {
  89. return $this->belongsTo('app\admin\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
  90. }
  91. //关联派对类型表
  92. public function partyType()
  93. {
  94. return $this->hasOne(Type::class, 'id', 'party_type',[],'LEFT');
  95. }
  96. }