Crontab.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace app\admin\controller\general;
  3. use app\common\controller\Backend;
  4. /**
  5. * 定时任务
  6. *
  7. * @icon fa fa-tasks
  8. * @remark 类似于Linux的Crontab定时任务,可以按照设定的时间进行任务的执行,目前仅支持三种任务:请求URL、执行SQL、执行Shell
  9. */
  10. class Crontab extends Backend
  11. {
  12. protected $model = null;
  13. public function _initialize()
  14. {
  15. parent::_initialize();
  16. $this->model = model('Crontab');
  17. $this->view->assign('typedata', [
  18. 'url' => __('Request Url'),
  19. 'sql' => __('Execute Sql Script'),
  20. 'shell' => __('Execute Shell'),
  21. ]);
  22. }
  23. /**
  24. * 查看
  25. */
  26. public function index()
  27. {
  28. if ($this->request->isAjax())
  29. {
  30. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  31. $total = $this->model
  32. ->where($where)
  33. ->order($sort, $order)
  34. ->count();
  35. $list = $this->model
  36. ->where($where)
  37. ->order($sort, $order)
  38. ->limit($offset, $limit)
  39. ->select();
  40. $result = array("total" => $total, "rows" => $list);
  41. return json($result);
  42. }
  43. return $this->view->fetch();
  44. }
  45. }