Crontab.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. protected static function init()
  19. {
  20. self::afterInsert(function ($row) {
  21. $pk = $row->getPk();
  22. $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
  23. });
  24. }
  25. public static function getTypeList()
  26. {
  27. return [
  28. 'url' => __('Request Url'),
  29. 'sql' => __('Execute Sql Script'),
  30. 'shell' => __('Execute Shell'),
  31. ];
  32. }
  33. public function getTypeTextAttr($value, $data)
  34. {
  35. $typelist = self::getTypeList();
  36. $value = $value ? $value : $data['type'];
  37. return $value && isset($typelist[$value]) ? $typelist[$value] : $value;
  38. }
  39. protected function setBegintimeAttr($value)
  40. {
  41. return $value && !is_numeric($value) ? strtotime($value) : $value;
  42. }
  43. protected function setEndtimeAttr($value)
  44. {
  45. return $value && !is_numeric($value) ? strtotime($value) : $value;
  46. }
  47. protected function setExecutetimeAttr($value)
  48. {
  49. return $value && !is_numeric($value) ? strtotime($value) : $value;
  50. }
  51. }