load->library('session'); $this->load->_model('Model_country','country'); $this->load->_model('Model_typeclass','typeclass'); $this->load->_model('Model_express','express'); $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 == 'del')//修改 { $this->_del(); } else if($arg == 'rows')//获取数据 { $this->_rows(); } else if($arg == 'excel')//获取数据 { $this->_excel(); } else { $this->_index(); } } //管理 public function _index() { $post = $this->input->post(NULL, TRUE); if(isset($post['page'])) { $page = $this->input->post('page',true); $perpage = $this->input->post('perpage',true); $continent = $this->input->post('continent',true); $express = $this->input->post('express',true); $ename = $this->input->post('ename',true); $zname = $this->input->post('zname',true); $where = "1=1 "; if($continent) { $where .= " and continent = '$continent'"; } if($express) { $where .= " and express = '$express'"; } if($ename) { $where .= " and ename like '%$ename%'"; } if($zname) { $where .= " and zname like '%$zname%'"; } //数据排序 $order_str = "id asc"; if(empty($page)) { $start = 0; $perpage = 1; } else { $start = ($page - 1)*$perpage; } //取得信息列表 $info_list = $this->country->find_all($where,'id,name,ename,zname,continent,al,lb,threebitcode,express',$order_str,$start,$perpage); foreach ($info_list as $key=>$value) { if($value['express'] != 0) { $express = $this->express->read($value['express']); $info_list[$key]['express'] = $express['servicename']; } else { $info_list[$key]['express'] = ""; } $class = $this->typeclass->read($value['continent']); $info_list[$key]['continent'] = $class['title']; } $total = $this->country->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; } $class = $this->typeclass->find_all('classid = 2','id,title'); $this->data['class'] = $class; $express = $this->express->find_all(); $this->data['express'] = $express; $this->_Template('country',$this->data); } //添加 public function _add() { $post = $this->input->post(NULL, TRUE); if(isset($post['zname'])) { if($this->country->insert($post)) { echo json_encode(array('msg'=>'添加成功','success'=>true));exit; } else { echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit; } } $class = $this->typeclass->find_all('classid = 2','id,title'); $this->data['class'] = $class; $express = $this->express->find_all(); $this->data['express'] = $express; $this->_Template('country_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->country->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]; $country = $this->country->read($arg_array); $class = $this->typeclass->find_all('classid = 2','id,title'); $this->data['class'] = $class; $this->data['country'] = $country; $express = $this->express->find_all(); $this->data['express'] = $express; $this->_Template('country_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->country->remove($v); } echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true)); } } //删除 public function _rows() { $this->load->library('pagination'); $config['base_url'] = 'http://127.0.0.1/country/rows'; $config['total_rows'] = 200; $config['per_page'] = 20; $this->pagination->initialize($config); echo $this->pagination->create_links(); } public function _excel() { $post = $this->input->get(NULL, TRUE); if(isset($post['excel'])) { $express = $this->express->find_all(); $ex = array(); foreach ($express as $v) { $ex[$v['id']] = $v['servicename']; } $info_list = $this->country->find_all('1=1','name,zname,ename,threebitcode,al,lb,express','name asc'); foreach ($info_list as $key=>$value) { if($value['express'] > 0) { $info_list[$key]['express'] = $ex[$value['express']]; } else { $info_list[$key]['express'] = ''; } } $title = "国家信息"; $titlename = "

".$title."

国家名称 中文名称 英文名称 三字码 阿里编码 联邦编码 默认物流
"; $filename = $title.".xls"; $tail = "\n"; $this->excel->get_fz2($info_list,$titlename,$filename,$tail); } } }