<?php
/**
* +----------------------------------------------------------------------
* | TickyPHP [ This is a freeware ]
* +----------------------------------------------------------------------
* | Copyright (c) 2015 All rights reserved.
* +----------------------------------------------------------------------
* | Author: 罗敏贵 <e-mail:minguiluo@163.com> <QQ:271391233>
* +----------------------------------------------------------------------
* | SVN: $Id: Cron.php 71410 2018-10-30 09:12:08 luomingui $
* +----------------------------------------------------------------------
* | 文件功能:对应的表名:tky_cron
* +----------------------------------------------------------------------
*/
namespace application\admin\controller;
use ticky\request;
use ticky\response;
class cron extends auth {
public function index() {
$search = $this->search_frm();
$ret = $this->db->page('cron', $search['sql'], $this->p);
$this->assign('page', $ret['page']);
$this->assign('items', $ret['items']);
$this->assign('search', $search['arr']);
$this->display('cron/index');
}
public function manage() {
$cronid = request::get('id', 0);
if ($cronid <= 0) {
$this->assign('postUrl', '/admin/cron/add');
$this->assign('action', '添加');
} else {
$item = $this->db->table('cron')->where(['cronid' => $cronid])->find();
$this->assign('postUrl', '/admin/cron/update');
$this->assign('action', '修改');
$this->assign('item', $item);
}
$this->display('cron/manage');
}
public function add() {
$data = $this->post_frm();
$this->db->table('cron')->add($data);
if (request::isAjax()) {
response::ajax(['code' => 200, 'msg' => '添加成功']);
} else {
showmsg('添加成功', '/admin/cron');
}
}
public function update() {
$data = $this->post_frm();
$id = request::post('cronid', 0);
$this->db->table('cron')->where(['cronid' => $id])->update($data);
if (request::isAjax()) {
response::ajax(['code' => 200, 'msg' => '修改成功']);
} else {
showmsg('修改成功', '/admin/cron');
}
}
public function delete() {
$id = request::post('id', 0);
$result = $this->db->table('cron')->where(['cronid' => $id])->delete();
if (request::isAjax()) {
if ($result) {
response::ajax(['code' => 200, 'msg' => '删除成功!']);
} else {
response::ajax(['code' => 403, 'msg' => '删除失败! id=' . $id]);
}
} else {
showmsg('删除成功', '/admin/cron');
}
}
public function batchremove() {
$optype = request::post('optype', 'del');
$ids = request::post('ids', []);
if ($optype == "del") {
for ($i = 0; $i < count($ids); $i++) {
$id = $ids[$i];
$this->db->table('cron')->where(['cronid' => $id])->delete();
}
if (request::isAjax()) {
response::ajax(['code' => 200, 'msg' => '修改成功']);
} else {
showmsg('删除成功', '/admin/cron');
}
}
}
private function search_frm() {
$search = request::get('search', []);
$where = '1=1 ';
if ($cronid = trim($search['cronid'])) {
$where .= "and cronid = '{$cronid}' ";
}
if ($available = trim($search['available'])) {
$where .= "and available = '{$available}' ";
}
if ($type = trim($search['type'])) {
$where .= "and type = '{$type}' ";
}
if ($name = trim($search['name'])) {
$where .= "and name = '{$name}' ";
}
if ($filename = trim($search['filename'])) {
$where .= "and filename = '{$filename}' ";
}
if ($lastrun = trim($search['lastrun'])) {
$where .= "and lastrun = '{$lastrun}' ";
}
if ($nextrun = trim($search['nextrun'])) {
$where .= "and nextrun = '{$nextrun}' ";
}
if ($weekday = trim($search['weekday'])) {
$where .= "and weekday = '{$weekday}' ";
}
if ($day = trim($search['day'])) {
$where .= "and day = '{$day}' ";
}
if ($hour = trim($search['hour'])) {
$where .= "and hour = '{$hour}' ";
}
if ($minute = trim($search['minute'])) {
$where .= "and minute = '{$minute}' ";
}
return [
'arr' => $search,
'sql' => $where
];
}
private function post_frm() {
$arr = array();
$arr['available'] = request::post('available', '');
$arr['type'] = request::post('type', '');
$arr['name'] = request::post('name', '');
$arr['filename'] = request::post('filename', '');
$arr['lastrun'] = request::post('lastrun', '');
$arr['nextrun'] = request::post('nextrun', '');
$arr['weekday'] = request::post('weekday', '');
$arr['day'] = request::post('day', '');
$arr['hour'] = request::post('hour', '');
$arr['minute'] = request::post('minute', '');
return $arr;
}
}