request->isAjax) { if (Yii::$app->request->isGet) { if (!\Yii::$app->request->isGet) { return $this->error('请求方式错误'); } $page = \Yii::$app->request->get('page') ?? 1; $limit = \Yii::$app->request->get('page_size') ?? $this->pageSize; $name = \Yii::$app->request->get('name'); $id = \Yii::$app->request->get('id'); $start_time = \Yii::$app->request->get('start_time'); $end_time = \Yii::$app->request->get('end_time'); $type = \Yii::$app->request->get('type'); // dd(strtotime($start_time), strtotime($end_time)); $where = [['<>','status',StatusEnum::DELETE]]; if (!empty($id)) { $where[] = ['id' => $id]; } if (!empty($name)) { $where[] = ['like', 'name', $name]; } if (!empty($start_time)) { $where[] = ['>=', 'created_at', strtotime($start_time)]; } if (!empty($end_time)) { $where[] = ['<=', 'created_at', strtotime($end_time)]; } if (!empty($type)) { $where[] = ['type' => $type]; } $params = [ 'select' => 'id,name,type,status,command,rule,created_at', 'where' => $where, 'order' => 'id desc', 'page' => $page, 'limit' => $limit, ]; $list = CrontabTask::listPage($params, false, true); // $list = CrontabTask::getStaticError(); return $this->success('操作成功', $list); } } return $this->render($this->action->id); } public function actionEdit() { if (Yii::$app->request->isAjax) { if (Yii::$app->request->isGet) { $get = Yii::$app->request->get(); $res = Yii::$app->services->validate->validate($get, [[['id'], 'integer']]); if ($res === false) { return $this->error(Yii::$app->services->validate->getErrorMessage()); } $info = CrontabTask::find() ->select('id,name,type,status,is_warning,command,rule,created_at') ->where(['id' => $get['id']]) ->andWhere(['!=', 'status', -1]) ->asArray() ->one(); // $info = CrontabTask::getStaticError(); return $this->success('操作成功', $info); } else { // 编辑任务 $form = Yii::$app->request->post(); $res = Yii::$app->services->validate->validate($form, [ [['id', 'type', 'name', 'rule', 'is_warning', 'status', 'command'], 'required'], ]); // dd($form); if ($res === false) { return $this->error(Yii::$app->services->validate->getErrorMessage()); } $res = CrontabTask::setData($form); if ($res === false) { return $this->error(CrontabTask::getStaticError()); } return $this->success('操作成功'); } } return $this->render($this->action->id); } public function actionDelete() { if (!\Yii::$app->request->isPost) { return $this->error('请求方式错误'); } $id = \Yii::$app->request->post('id'); if (empty($id) || !is_numeric($id)) { return $this->error('参数错误'); } $task = CrontabTask::findOne($id); $task->status = -1; $task->updated_at = time(); $res = $task->save(); if ($res) { return $this->success('删除成功'); } else { return $this->error('删除失败'); } } public function actionExecutedList() { if (Yii::$app->request->isAjax) { if (Yii::$app->request->isGet) { if (!\Yii::$app->request->isGet) { return $this->error('请求方式错误'); } $page = \Yii::$app->request->get('page') ?? 1; $limit = \Yii::$app->request->get('page_size') ?? $this->pageSize; $name = \Yii::$app->request->get('name'); $task_id = \Yii::$app->request->get('task_id'); $start_time = \Yii::$app->request->get('start_time'); $end_time = \Yii::$app->request->get('end_time'); $type = \Yii::$app->request->get('type'); $status = \Yii::$app->request->get('status'); // dd(strtotime($start_time), strtotime($end_time)); $where = []; if (!empty($task_id)) { $where[] = ['task_id' => $task_id]; } if (!empty($name)) { $where[] = ['like', 'name', $name]; } if (!empty($start_time)) { $where[] = ['>=', 'created_at', strtotime($start_time)]; } if (!empty($end_time)) { $where[] = ['<=', 'created_at', strtotime($end_time)]; } if (!empty($type)) { $where[] = ['type' => $type]; } if (!empty($status)) { $where[] = ['exec_process' => $status]; } $params = [ 'select' => 'id,name,command,type,start_time,execute_time,complete_time,running_time,exec_process,result,warning,created_at', 'where' => $where, 'order' => 'id desc', 'page' => $page, 'limit' => $limit, ]; $list = CrontabTaskExecute::listPage($params, false, true); // $list = CrontabTaskExecute::getStaticError(); return $this->success('操作成功', $list); } } return $this->render($this->action->id); } public function actionExecutedDetail() { if (\Yii::$app->request->isAjax) { if (!\Yii::$app->request->isGet) { return $this->error('请求方式错误'); } $id = \Yii::$app->request->get('id'); if (empty($id) || !is_numeric($id)) { return $this->error('参数错误'); } $info = CrontabTaskExecute::findOne($id); return $this->success('操作成功', $info); } else { return $this->render('executed-detail'); } } public function actionExecutedRecordDel() { if (!\Yii::$app->request->isPost) { return $this->error('请求方式错误'); } $id = \Yii::$app->request->post('id'); if (empty($id) || !is_numeric($id)) { return $this->error('参数错误'); } $record = CrontabTaskExecute::findOne($id); if ($record->delete()) { return $this->success('删除成功'); } else { return $this->error('删除失败'); } } }