Gamepeople.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Gamepeople extends Model
  5. {
  6. // 表名
  7. protected $name = 'game_people';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'is_leader_text',
  17. 'starttime_text',
  18. 'endtime_text',
  19. 'status_text'
  20. ];
  21. public function getIsLeaderList()
  22. {
  23. return ['0' => __('Is_leader 0'), '1' => __('Is_leader 1')];
  24. }
  25. public function getStatusList()
  26. {
  27. return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2'), '3' => __('Status 3')];
  28. }
  29. public function getIsLeaderTextAttr($value, $data)
  30. {
  31. $value = $value ? $value : (isset($data['is_leader']) ? $data['is_leader'] : '');
  32. $list = $this->getIsLeaderList();
  33. return isset($list[$value]) ? $list[$value] : '';
  34. }
  35. public function getStarttimeTextAttr($value, $data)
  36. {
  37. $value = $value ? $value : (isset($data['starttime']) ? $data['starttime'] : '');
  38. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  39. }
  40. public function getEndtimeTextAttr($value, $data)
  41. {
  42. $value = $value ? $value : (isset($data['endtime']) ? $data['endtime'] : '');
  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. protected function setStarttimeAttr($value)
  52. {
  53. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  54. }
  55. protected function setEndtimeAttr($value)
  56. {
  57. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  58. }
  59. public function user()
  60. {
  61. return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
  62. }
  63. public function game()
  64. {
  65. return $this->belongsTo('Game', 'game_id', 'id', [], 'LEFT')->setEagerlyType(0);
  66. }
  67. public function place()
  68. {
  69. return $this->belongsTo('Gameplace', 'game_place_id', 'id', [], 'LEFT')->setEagerlyType(0);
  70. }
  71. }