Command.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Command extends Model
  5. {
  6. // 表名
  7. protected $name = 'command';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. // 追加属性
  14. protected $append = [
  15. 'executetime_text',
  16. 'type_text',
  17. 'status_text'
  18. ];
  19. public function getStatusList()
  20. {
  21. return ['successed' => __('Successed'), 'failured' => __('Failured')];
  22. }
  23. public function getExecutetimeTextAttr($value, $data)
  24. {
  25. $value = $value ? $value : $data['executetime'];
  26. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  27. }
  28. public function getTypeTextAttr($value, $data)
  29. {
  30. $value = $value ? $value : $data['type'];
  31. $list = ['crud' => '一键生成CRUD', 'menu' => '一键生成菜单', 'min' => '一键压缩打包', 'api' => '一键生成文档'];
  32. return $list[$value] ?? '';
  33. }
  34. public function getStatusTextAttr($value, $data)
  35. {
  36. $value = $value ? $value : $data['status'];
  37. $list = $this->getStatusList();
  38. return $list[$value] ?? '';
  39. }
  40. protected function setExecutetimeAttr($value)
  41. {
  42. return $value && !is_numeric($value) ? strtotime($value) : $value;
  43. }
  44. }