122 lines
3.7 KiB
PHP
122 lines
3.7 KiB
PHP
<?php
|
|
namespace Admin\Controller;
|
|
use Think\Controller;
|
|
class TaskController extends AdminController{
|
|
public function __construct(){
|
|
parent::__construct();
|
|
$this->table=D("task");
|
|
}
|
|
|
|
public function index(){
|
|
//搜索
|
|
$where=array();
|
|
$where['is_sub'] = 0;
|
|
//产品名称
|
|
$task_name=I("get.task_name");
|
|
if($task_name){
|
|
$where['task_name'] = array('LIKE','%'.$task_name.'%');
|
|
}
|
|
$task_start = I('task_start');
|
|
$task_end = I('task_end');
|
|
|
|
if($task_start){
|
|
$task_start = strtotime($task_start) ;
|
|
}
|
|
else{
|
|
$task_start = 0;
|
|
}
|
|
if($task_end){
|
|
$task_end = strtotime($task_end) + 86400;
|
|
}
|
|
else{
|
|
$task_end = time();
|
|
}
|
|
$where['task_time_add'] = array('between',array($task_start,$task_end));
|
|
|
|
$listRows=C("display.admin_shownum");//每页显示多少条
|
|
$total=$this->table->where($where)->count();
|
|
$page = new \Think\Page($total, $listRows);
|
|
$data=$this->table->where($where)->relation(true)->order("task_id desc")->limit($page->firstRow, $page->listRows)->select();
|
|
foreach ($data as $k=>$v){
|
|
$data[$k]['used'] = false;
|
|
if(D('task_sub')->where(array('task_id'=>$v['task_id']))->find()){
|
|
$data[$k]['used'] = true;
|
|
}
|
|
}
|
|
$listpage = $page->show();
|
|
$this->assign("listpage", $listpage);
|
|
$this->data=$data;
|
|
$this->display();
|
|
}
|
|
|
|
public function add(){
|
|
if(IS_POST){
|
|
$data=$this->table->create();
|
|
|
|
if (!$data){//验证
|
|
$this->error($this->table->getError());
|
|
}
|
|
//数据添加
|
|
$result=$this->table->data_add();
|
|
if(!$result){
|
|
$this->error($this->table->getError());
|
|
}
|
|
D("UserLog")->add("add",$this->table->getTableName(),$result);
|
|
$this->success($data);
|
|
}
|
|
else{
|
|
$this->product = D('product')->field('product_id as value,product_type as name')->select();
|
|
$this->display();
|
|
}
|
|
}
|
|
//
|
|
public function editor(){
|
|
if(IS_POST){
|
|
$data=$this->table->create();
|
|
|
|
if (!$data){//验证
|
|
$this->error($this->table->getError());
|
|
}
|
|
$result=$this->table->data_save();
|
|
if(!$result){
|
|
$this->error($this->table->getError());
|
|
}
|
|
D("UserLog")->add("update",$this->table->getTableName(),$result);
|
|
$this->success($data);
|
|
}
|
|
else{
|
|
$task_id = I('task_id');
|
|
$data= $this->table->find($task_id);
|
|
$this->data = $data;
|
|
$this->product = D('product')->field('product_id as value,product_type as name')->select();
|
|
$this->display();
|
|
}
|
|
}
|
|
|
|
|
|
//删除
|
|
public function delete(){
|
|
$task_id=I('task_id');
|
|
$data = $this->table->find($task_id);
|
|
if($data['task_who_add']!=UID){
|
|
$this->error('没有权限删除别人的资料');
|
|
}
|
|
$this->table->delete($task_id);
|
|
D("UserLog")->add("delete",$this->table->getTableName(),$task_id);
|
|
D('task_flow')->where(array('task_id'=>$task_id))->delete();
|
|
$this->success("操作成功");
|
|
}
|
|
|
|
|
|
public function changeStatus(){
|
|
$task_id = I('task_id');
|
|
$status = I('status');
|
|
D('task')->where(array('task_id'=>$task_id))->save(array('status'=>$status));
|
|
if($status != 1){
|
|
$status = 0;
|
|
}
|
|
D('task_flow')->where(array('task_id'=>$task_id))->save(array('status'=>$status));
|
|
$this->success('success');
|
|
}
|
|
|
|
} |