Packageorder.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Packageorder extends Model
  5. {
  6. // 表名
  7. protected $table = 'package_order';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'integer';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'starttime_text',
  17. 'endtime_text',
  18. 'order_status_text',
  19. 'use_status_text',
  20. 'paytime_text',
  21. 'is_gift_text',
  22. 'notice_status_text'
  23. ];
  24. public function getOrderStatusList()
  25. {
  26. return ['0' => __('Order_status 0'), '1' => __('Order_status 1')];
  27. }
  28. public function getUseStatusList()
  29. {
  30. return ['0' => __('Use_status 0'), '1' => __('Use_status 1')];
  31. }
  32. public function getIsGiftList()
  33. {
  34. return ['0' => __('Is_gift 0'), '1' => __('Is_gift 1')];
  35. }
  36. public function getNoticeStatusList()
  37. {
  38. return ['0' => __('Notice_status 0'), '1' => __('Notice_status 1'), '2' => __('Notice_status 2'), '3' => __('Notice_status 3')];
  39. }
  40. public function getStarttimeTextAttr($value, $data)
  41. {
  42. $value = $value ? $value : (isset($data['starttime']) ? $data['starttime'] : '');
  43. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  44. }
  45. public function getEndtimeTextAttr($value, $data)
  46. {
  47. $value = $value ? $value : (isset($data['endtime']) ? $data['endtime'] : '');
  48. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  49. }
  50. public function getOrderStatusTextAttr($value, $data)
  51. {
  52. $value = $value ? $value : (isset($data['order_status']) ? $data['order_status'] : '');
  53. $list = $this->getOrderStatusList();
  54. return isset($list[$value]) ? $list[$value] : '';
  55. }
  56. public function getUseStatusTextAttr($value, $data)
  57. {
  58. $value = $value ? $value : (isset($data['use_status']) ? $data['use_status'] : '');
  59. $list = $this->getUseStatusList();
  60. return isset($list[$value]) ? $list[$value] : '';
  61. }
  62. public function getPaytimeTextAttr($value, $data)
  63. {
  64. $value = $value ? $value : (isset($data['paytime']) ? $data['paytime'] : '');
  65. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  66. }
  67. public function getIsGiftTextAttr($value, $data)
  68. {
  69. $value = $value ? $value : (isset($data['is_gift']) ? $data['is_gift'] : '');
  70. $list = $this->getIsGiftList();
  71. return isset($list[$value]) ? $list[$value] : '';
  72. }
  73. public function getNoticeStatusTextAttr($value, $data)
  74. {
  75. $value = $value ? $value : (isset($data['notice_status']) ? $data['notice_status'] : '');
  76. $list = $this->getNoticeStatusList();
  77. return isset($list[$value]) ? $list[$value] : '';
  78. }
  79. protected function setStarttimeAttr($value)
  80. {
  81. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  82. }
  83. protected function setEndtimeAttr($value)
  84. {
  85. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  86. }
  87. protected function setPaytimeAttr($value)
  88. {
  89. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  90. }
  91. public function user()
  92. {
  93. return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
  94. }
  95. public function package()
  96. {
  97. return $this->belongsTo('Lessonpackage', 'package_id', 'id', [], 'LEFT')->setEagerlyType(0);
  98. }
  99. }