Lave.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Lave extends Model
  5. {
  6. // 表名
  7. protected $name = 'lave';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = false;
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'is_open_text',
  17. 'is_ticket_text',
  18. 'paid_text',
  19. 'pay_type_text',
  20. 'paytime_text',
  21. 'type_text'
  22. ];
  23. public function getIsOpenList()
  24. {
  25. return ['0' => __('Is_open 0'), '1' => __('Is_open 1')];
  26. }
  27. public function getIsTicketList()
  28. {
  29. return ['0' => __('Is_ticket 0'), '1' => __('Is_ticket 1')];
  30. }
  31. public function getPaidList()
  32. {
  33. return ['0' => __('Paid 0'), '1' => __('Paid 1')];
  34. }
  35. public function getPayTypeList()
  36. {
  37. return ['0' => __('Pay_type 0'), '1' => __('Pay_type 1'), '2' => __('Pay_type 2'), '3' => __('Pay_type 3'), '4' => __('Pay_type 4')];
  38. }
  39. public function getTypeList()
  40. {
  41. return ['0' => __('Type 0'), '1' => __('Type 1')];
  42. }
  43. public function getIsOpenTextAttr($value, $data)
  44. {
  45. $value = $value ? $value : (isset($data['is_open']) ? $data['is_open'] : '');
  46. $list = $this->getIsOpenList();
  47. return isset($list[$value]) ? $list[$value] : '';
  48. }
  49. public function getIsTicketTextAttr($value, $data)
  50. {
  51. $value = $value ? $value : (isset($data['is_ticket']) ? $data['is_ticket'] : '');
  52. $list = $this->getIsTicketList();
  53. return isset($list[$value]) ? $list[$value] : '';
  54. }
  55. public function getPaidTextAttr($value, $data)
  56. {
  57. $value = $value ? $value : (isset($data['paid']) ? $data['paid'] : '');
  58. $list = $this->getPaidList();
  59. return isset($list[$value]) ? $list[$value] : '';
  60. }
  61. public function getPayTypeTextAttr($value, $data)
  62. {
  63. $value = $value ? $value : (isset($data['pay_type']) ? $data['pay_type'] : '');
  64. $list = $this->getPayTypeList();
  65. return isset($list[$value]) ? $list[$value] : '';
  66. }
  67. public function getPaytimeTextAttr($value, $data)
  68. {
  69. $value = $value ? $value : (isset($data['paytime']) ? $data['paytime'] : '');
  70. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  71. }
  72. public function getTypeTextAttr($value, $data)
  73. {
  74. $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
  75. $list = $this->getTypeList();
  76. return isset($list[$value]) ? $list[$value] : '';
  77. }
  78. protected function setPaytimeAttr($value)
  79. {
  80. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  81. }
  82. }