HotelCanteenOrder.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class HotelCanteenOrder extends Model
  5. {
  6. // 表名
  7. protected $table = 'hotel_canteen_order';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = false;
  10. // 定义时间戳字段名
  11. protected $createTime = false;
  12. protected $updateTime = false;
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'sex_text',
  17. 'get_to_time_text',
  18. 'status_text',
  19. 'create_time_text',
  20. 'update_time_text'
  21. ];
  22. public function getSexList()
  23. {
  24. return ['1' => __('Sex 1'), '2' => __('Sex 2')];
  25. }
  26. public function getStatusList()
  27. {
  28. return ['1' => __('Status 1'), '0' => __('Status 0')];
  29. }
  30. public function getSexTextAttr($value, $data)
  31. {
  32. $value = $value ? $value : (isset($data['sex']) ? $data['sex'] : '');
  33. $list = $this->getSexList();
  34. return isset($list[$value]) ? $list[$value] : '';
  35. }
  36. public function getGetToTimeTextAttr($value, $data)
  37. {
  38. $value = $value ? $value : (isset($data['get_to_time']) ? $data['get_to_time'] : '');
  39. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  40. }
  41. public function getStatusTextAttr($value, $data)
  42. {
  43. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  44. $list = $this->getStatusList();
  45. return isset($list[$value]) ? $list[$value] : '';
  46. }
  47. public function getCreateTimeTextAttr($value, $data)
  48. {
  49. $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
  50. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  51. }
  52. public function getUpdateTimeTextAttr($value, $data)
  53. {
  54. $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : '');
  55. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  56. }
  57. protected function setGetToTimeAttr($value)
  58. {
  59. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  60. }
  61. protected function setCreateTimeAttr($value)
  62. {
  63. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  64. }
  65. protected function setUpdateTimeAttr($value)
  66. {
  67. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  68. }
  69. public function user()
  70. {
  71. return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
  72. }
  73. public function canteen()
  74. {
  75. return $this->belongsTo('app\admin\model\hotel\Canteen', 'canteen_id', 'id', [], 'LEFT')->setEagerlyType(0);
  76. }
  77. public function room()
  78. {
  79. return $this->belongsTo('app\admin\model\hotel\canteen\Room', 'canteen_id', 'id', [], 'LEFT')->setEagerlyType(0);
  80. }
  81. }