Version.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace app\admin\model\setting;
  3. use think\Model;
  4. use traits\model\SoftDelete;
  5. class Version extends Model
  6. {
  7. use SoftDelete;
  8. // 表名
  9. protected $name = 'app_version';
  10. // 自动写入时间戳字段
  11. protected $autoWriteTimestamp = 'int';
  12. // 定义时间戳字段名
  13. protected $createTime = 'create_time';
  14. protected $updateTime = 'update_time';
  15. protected $deleteTime = 'delete_time';
  16. // 追加属性
  17. protected $append = [
  18. 'platform_text',
  19. 'create_time_text',
  20. 'update_time_text',
  21. 'delete_time_text'
  22. ];
  23. public function getPlatformList()
  24. {
  25. return ['android' => __('Platform android'), 'ios' => __('Platform ios'), 'applets' => __('Platform applets'), 'h5' => __('Platform h5')];
  26. }
  27. public function getPlatformTextAttr($value, $data)
  28. {
  29. $value = $value ? $value : (isset($data['platform']) ? $data['platform'] : '');
  30. $list = $this->getPlatformList();
  31. return isset($list[$value]) ? $list[$value] : '';
  32. }
  33. public function getCreateTimeTextAttr($value, $data)
  34. {
  35. $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
  36. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  37. }
  38. public function getUpdateTimeTextAttr($value, $data)
  39. {
  40. $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : '');
  41. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  42. }
  43. public function getDeleteTimeTextAttr($value, $data)
  44. {
  45. $value = $value ? $value : (isset($data['delete_time']) ? $data['delete_time'] : '');
  46. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  47. }
  48. protected function setCreateTimeAttr($value)
  49. {
  50. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  51. }
  52. protected function setUpdateTimeAttr($value)
  53. {
  54. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  55. }
  56. protected function setDeleteTimeAttr($value)
  57. {
  58. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  59. }
  60. }