Lessonorder.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Lessonorder extends Model
  5. {
  6. // 表名
  7. protected $table = 'lesson_order';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'integer';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'order_status_text',
  17. 'paytype_text',
  18. 'paytime_text',
  19. 'finishtime_text',
  20. 'cancel_time_text'
  21. ];
  22. public function getOrderStatusList()
  23. {
  24. return ['0' => __('Order_status 0'), '10' => __('Order_status 10'), '20' => __('Order_status 20'), '30' => __('Order_status 30'), '40' => __('Order_status 40')];
  25. }
  26. public function getPaytypeList()
  27. {
  28. return ['1' => __('Paytype 1'), '2' => __('Paytype 2'), '3' => __('Paytype 3'), '4' => __('Paytype 4'), '5' => __('Paytype 5')];
  29. }
  30. public function getOrderStatusTextAttr($value, $data)
  31. {
  32. $value = $value ? $value : (isset($data['order_status']) ? $data['order_status'] : '');
  33. $list = $this->getOrderStatusList();
  34. return isset($list[$value]) ? $list[$value] : '';
  35. }
  36. public function getPaytypeTextAttr($value, $data)
  37. {
  38. $value = $value ? $value : (isset($data['paytype']) ? $data['paytype'] : '');
  39. $list = $this->getPaytypeList();
  40. return isset($list[$value]) ? $list[$value] : '';
  41. }
  42. public function getPaytimeTextAttr($value, $data)
  43. {
  44. $value = $value ? $value : (isset($data['paytime']) ? $data['paytime'] : '');
  45. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  46. }
  47. public function getFinishtimeTextAttr($value, $data)
  48. {
  49. $value = $value ? $value : (isset($data['finishtime']) ? $data['finishtime'] : '');
  50. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  51. }
  52. public function getCancelTimeTextAttr($value, $data)
  53. {
  54. $value = $value ? $value : (isset($data['cancel_time']) ? $data['cancel_time'] : '');
  55. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  56. }
  57. protected function setPaytimeAttr($value)
  58. {
  59. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  60. }
  61. protected function setFinishtimeAttr($value)
  62. {
  63. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  64. }
  65. protected function setCancelTimeAttr($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 slot()
  74. {
  75. return $this->belongsTo('Lessonslot', 'slot_id', 'id', [], 'LEFT')->setEagerlyType(0);
  76. }
  77. public function lesson()
  78. {
  79. return $this->belongsTo('Lesson', 'lesson_id', 'id', [], 'LEFT')->setEagerlyType(0);
  80. }
  81. public function coach()
  82. {
  83. return $this->belongsTo('Coach', 'slot.coach_ids', 'id', [], 'LEFT')->setEagerlyType(0);
  84. }
  85. public function packageorder()
  86. {
  87. return $this->belongsTo('Packageorder', 'package_order_id', 'id', [], 'LEFT')->setEagerlyType(0);
  88. }
  89. public function lessonpackage()
  90. {
  91. return $this->belongsTo('Lessonpackage', 'packageorder.package_id', 'id', [], 'LEFT')->setEagerlyType(0);
  92. }
  93. public function trylessonorder()
  94. {
  95. return $this->belongsTo('Trylessonorder', 'trylesson_order_id', 'id', [], 'LEFT')->setEagerlyType(0);
  96. }
  97. public function trylesson()
  98. {
  99. return $this->belongsTo('Trylesson', 'trylessonorder.trylesson_id', 'id', [], 'LEFT')->setEagerlyType(0);
  100. }
  101. }