load->library('session'); $this->load->_model('Model_container','container'); $this->load->_model('Model_excel','excel'); } //定义方法的调用规则 获取URI第二段值 public function _remap($arg,$arg_array) { if($arg == 'add')//添加 { $this->_add(); } else if($arg == 'edit')//修改 { $this->_edit($arg_array); } else if($arg == 'see') { $this->_see($arg_array); } else if($arg == 'del') { $this->_del($arg_array); } else if($arg == 'excel') { $this->_excel(); } else { $this->_index($arg_array); } } //管理 public function _index($arg_array) { $post = $this->input->post(NULL, TRUE); if(isset($post['page'])) { $page = $this->input->post('page',true); $perpage = $this->input->post('perpage',true); $title = $this->input->post('title',true); $name = $this->input->post('name',true); $timetk = $this->input->post('timetk',true); $timetj = $this->input->post('timetj',true); $timetk = strtotime($timetk); $timetj = strtotime($timetj); $where = "1=1 "; //数据排序 $order_str = "id asc"; if(empty($page)) { $start = 0; $perpage = 1; } else { $start = ($page - 1)*$perpage; } if($title) { $where .= " and title like '%$title%'"; } if($name) { $where .= " and name like '%$name%'"; } if($timetk && $timetj) { $where .= " and time > '$timetk' and time < '$timetj'"; } //取得信息列表 $info_list = $this->container->find_all($where,'id,title,num,weight,zweight,volume,type,yt,name,time',$order_str,$start,$perpage); //格式化数据 foreach ($info_list as $key=>$value) { $info_list[$key]['time'] = date("Y-m-d H:i:s",$value['time']); if($value['type'] == 1) { $info_list[$key]['type'] = 'A-必须发'; } else if($value['type'] == 2) { $info_list[$key]['type'] = 'B-如果发不完可先发走一部分'; } else if($value['type'] == 3) { $info_list[$key]['type'] = 'C-拼箱用,可发可不发'; } } $total = $this->container->find_count($where); $pagenum = ceil($total/$perpage); $over = $total-($start+$perpage); $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list)); echo json_encode($rows);exit; } $this->_Template('container',$this->data); } //添加 public function _add() { $post = $this->input->post(NULL, TRUE); if(isset($post['title'])) { $post['time'] = time(); if($this->container->insert($post)) { echo json_encode(array('msg'=>'添加成功','success'=>true));exit; } else { echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit; } } $this->_Template('container_add',$this->data); } //修改 public function _edit($arg_array) { $post = $this->input->post(NULL, TRUE); if(isset($post['id'])) { $id = $this->input->post('id',true); if($this->container->save($post,$id)) { echo json_encode(array('msg'=>'修改成功','success'=>true));exit; } else { echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit; } } $arg_array = $arg_array[0]; $container = $this->container->read($arg_array); $this->data['container'] = $container; $this->_Template('container_edit',$this->data); } //删除 public function _del() { $post = $this->input->post(NULL, TRUE); if(isset($post['s'])) { $id_arr = $this->input->post('s'); $id_arr = explode(',',$id_arr); if(!$id_arr) { echo json_encode(array('msg'=>'参数错误!','success'=>false));exit; } //循环删除记录 foreach ($id_arr as $v) { $this->container->remove($v); } echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true)); } } public function _excel() { $post = $this->input->get(NULL, TRUE); if(isset($post['timetk'])) { $page = $this->input->get('page',true); $perpage = $this->input->get('perpage',true); $timetk = $this->input->get('timetk',true); $timetj = $this->input->get('timetj',true); $title = $this->input->get('title',true); $name = $this->input->get('name',true); $timetk = $this->input->get('timetk',true); $timetj = $this->input->get('timetj',true); $timetk = strtotime($timetk); $timetj = strtotime($timetj); $dowid = $this->input->get('a'); $wid = ""; if($dowid != "") { $id_arr = explode(',',rtrim($dowid,',')); $wid .= " id = 0 or"; foreach ($id_arr as $v) { $wid .= " id = '$v' or"; } $wid = " and".rtrim($wid,'or'); } $where = "1=1"; if($timetk && $timetj) { $where .= " and time > '$timetk' and time < '$timetj'"; } if($title) { $where .= " and title like '%$title%'"; } if($name) { $where .= " and name like '%$name%'"; } $info_list = $this->container->find_all($where.$wid,'title,num,weight,zweight,volume,type,yt,name,time','id desc'); foreach ($info_list as $key=>$value) { $info_list[$key]['time'] = date("Y-m-d H:i:s",$value['time']); if($value['type'] == 1) { $info_list[$key]['type'] = 'A-必须发'; } else if($value['type'] == 2) { $info_list[$key]['type'] = 'B-如果发不完可先发走一部分'; } else if($value['type'] == 3) { $info_list[$key]['type'] = 'C-拼箱用,可发可不发'; } } $title = '货柜物品'.date('Y-m-d',$timetk).'-'.date('Y-m-d',$timetj); $titlename = "
货物名称 数量 单位重量(千克) 总重量(千克) 预估体积(立方米) 优先级 用途 提交人 提交时间
"; $filename = $title.".xls"; $tail = "\n"; $this->excel->get_fz2($info_list,$titlename,$filename,$tail); } } }