Trylessonorder.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Trylessonorder extends Model
  5. {
  6. // 表名
  7. protected $table = 'trylesson_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. 'paytime_text',
  18. 'starttime_text',
  19. 'endtime_text',
  20. 'pay_type_text'
  21. ];
  22. public function getOrderStatusList()
  23. {
  24. return ['0' => __('Order_status 0'), '10' => __('Order_status 10'), '20' => __('Order_status 20')];
  25. }
  26. public function getPayTypeList()
  27. {
  28. return ['1' => __('Pay_type 1'), '2' => __('Pay_type 2')];
  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 getPaytimeTextAttr($value, $data)
  37. {
  38. $value = $value ? $value : (isset($data['paytime']) ? $data['paytime'] : '');
  39. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  40. }
  41. public function getStarttimeTextAttr($value, $data)
  42. {
  43. $value = $value ? $value : (isset($data['starttime']) ? $data['starttime'] : '');
  44. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  45. }
  46. public function getEndtimeTextAttr($value, $data)
  47. {
  48. $value = $value ? $value : (isset($data['endtime']) ? $data['endtime'] : '');
  49. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  50. }
  51. public function getPayTypeTextAttr($value, $data)
  52. {
  53. $value = $value ? $value : (isset($data['pay_type']) ? $data['pay_type'] : '');
  54. $list = $this->getPayTypeList();
  55. return isset($list[$value]) ? $list[$value] : '';
  56. }
  57. protected function setPaytimeAttr($value)
  58. {
  59. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  60. }
  61. protected function setStarttimeAttr($value)
  62. {
  63. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  64. }
  65. protected function setEndtimeAttr($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 trylesson()
  74. {
  75. return $this->belongsTo('Trylesson', 'trylesson_id', 'id', [], 'LEFT')->setEagerlyType(0);
  76. }
  77. }