Crontab.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Crontab extends Model
  5. {
  6. // 开启自动写入时间戳字段
  7. protected $autoWriteTimestamp = 'int';
  8. // 定义时间戳字段名
  9. protected $createTime = 'createtime';
  10. protected $updateTime = 'updatetime';
  11. // 定义字段类型
  12. protected $type = [
  13. ];
  14. // 追加属性
  15. protected $append = [
  16. 'type_text'
  17. ];
  18. public static function getTypeList()
  19. {
  20. return [
  21. 'url' => __('Request Url'),
  22. 'sql' => __('Execute Sql Script'),
  23. 'shell' => __('Execute Shell'),
  24. ];
  25. }
  26. public function getTypeTextAttr($value, $data)
  27. {
  28. $typelist = self::getTypeList();
  29. $value = $value ? $value : $data['type'];
  30. return $value && isset($typelist[$value]) ? $typelist[$value] : $value;
  31. }
  32. protected function setBegintimeAttr($value)
  33. {
  34. return $value && !is_numeric($value) ? strtotime($value) : $value;
  35. }
  36. protected function setEndtimeAttr($value)
  37. {
  38. return $value && !is_numeric($value) ? strtotime($value) : $value;
  39. }
  40. protected function setExecutetimeAttr($value)
  41. {
  42. return $value && !is_numeric($value) ? strtotime($value) : $value;
  43. }
  44. }