PrizeRecord.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class PrizeRecord extends Model
  5. {
  6. // 表名
  7. protected $name = 'prize_record';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = false;
  10. // 定义时间戳字段名
  11. protected $createTime = false;
  12. protected $updateTime = false;
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'status_text',
  17. 'exchange_time_text',
  18. 'delivery_time_text',
  19. 'create_time_text',
  20. 'update_time_text',
  21. 'delete_time_text',
  22. 'zz_time_text'
  23. ];
  24. public function getStatusList()
  25. {
  26. return ['bag' => __('Status bag'), 'exchange' => __('Status exchange'), 'delivery' => __('Status delivery'), 'received' => __('Status received')];
  27. }
  28. public function getStatusTextAttr($value, $data)
  29. {
  30. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  31. $list = $this->getStatusList();
  32. return isset($list[$value]) ? $list[$value] : '';
  33. }
  34. public function getExchangeTimeTextAttr($value, $data)
  35. {
  36. $value = $value ? $value : (isset($data['exchange_time']) ? $data['exchange_time'] : '');
  37. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  38. }
  39. public function getDeliveryTimeTextAttr($value, $data)
  40. {
  41. $value = $value ? $value : (isset($data['delivery_time']) ? $data['delivery_time'] : '');
  42. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  43. }
  44. public function getCreateTimeTextAttr($value, $data)
  45. {
  46. $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
  47. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  48. }
  49. public function getUpdateTimeTextAttr($value, $data)
  50. {
  51. $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : '');
  52. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  53. }
  54. public function getDeleteTimeTextAttr($value, $data)
  55. {
  56. $value = $value ? $value : (isset($data['delete_time']) ? $data['delete_time'] : '');
  57. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  58. }
  59. public function getZzTimeTextAttr($value, $data)
  60. {
  61. $value = $value ? $value : (isset($data['zz_time']) ? $data['zz_time'] : '');
  62. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  63. }
  64. protected function setExchangeTimeAttr($value)
  65. {
  66. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  67. }
  68. protected function setDeliveryTimeAttr($value)
  69. {
  70. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  71. }
  72. protected function setCreateTimeAttr($value)
  73. {
  74. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  75. }
  76. protected function setUpdateTimeAttr($value)
  77. {
  78. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  79. }
  80. protected function setDeleteTimeAttr($value)
  81. {
  82. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  83. }
  84. protected function setZzTimeAttr($value)
  85. {
  86. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  87. }
  88. }