Country.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Country extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_country','country');
  7. $this->load->_model('Model_typeclass','typeclass');
  8. $this->load->_model('Model_express','express');
  9. }
  10. //定义方法的调用规则 获取URI第二段值
  11. public function _remap($arg,$arg_array)
  12. {
  13. if($arg == 'add')//添加
  14. {
  15. $this->_add();
  16. }
  17. else if($arg == 'edit')//修改
  18. {
  19. $this->_edit($arg_array);
  20. }
  21. else if($arg == 'del')//修改
  22. {
  23. $this->_del();
  24. }
  25. else if($arg == 'rows')//获取数据
  26. {
  27. $this->_rows();
  28. }
  29. else
  30. {
  31. $this->_index();
  32. }
  33. }
  34. //管理
  35. public function _index()
  36. {
  37. $post = $this->input->post(NULL, TRUE);
  38. if(isset($post['page']))
  39. {
  40. $page = $this->input->post('page',true);
  41. $perpage = $this->input->post('perpage',true);
  42. $continent = $this->input->post('continent',true);
  43. $express = $this->input->post('express',true);
  44. $ename = $this->input->post('ename',true);
  45. $zname = $this->input->post('zname',true);
  46. $where = "1=1 ";
  47. if($continent)
  48. {
  49. $where .= " and continent = '$continent'";
  50. }
  51. if($express)
  52. {
  53. $where .= " and express = '$express'";
  54. }
  55. if($ename)
  56. {
  57. $where .= " and ename like '%$ename%'";
  58. }
  59. if($zname)
  60. {
  61. $where .= " and zname like '%$zname%'";
  62. }
  63. //数据排序
  64. $order_str = "id asc";
  65. if(empty($page))
  66. {
  67. $start = 0;
  68. $perpage = 1;
  69. }
  70. else
  71. {
  72. $start = ($page - 1)*$perpage;
  73. }
  74. //取得信息列表
  75. $info_list = $this->country->find_all($where,'id,name,ename,zname,continent,al,lb,threebitcode,express',$order_str,$start,$perpage);
  76. foreach ($info_list as $key=>$value)
  77. {
  78. if($value['express'] != 0)
  79. {
  80. $express = $this->express->read($value['express']);
  81. $info_list[$key]['express'] = $express['servicename'];
  82. }
  83. else
  84. {
  85. $info_list[$key]['express'] = "";
  86. }
  87. $class = $this->typeclass->read($value['continent']);
  88. $info_list[$key]['continent'] = $class['title'];
  89. }
  90. $total = $this->country->find_count($where);
  91. $pagenum = ceil($total/$perpage);
  92. $over = $total-($start+$perpage);
  93. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  94. echo json_encode($rows);exit;
  95. }
  96. $class = $this->typeclass->find_all('classid = 2','id,title');
  97. $this->data['class'] = $class;
  98. $express = $this->express->find_all();
  99. $this->data['express'] = $express;
  100. $this->_Template('country',$this->data);
  101. }
  102. //添加
  103. public function _add()
  104. {
  105. $post = $this->input->post(NULL, TRUE);
  106. if(isset($post['zname']))
  107. {
  108. if($this->country->insert($post))
  109. {
  110. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  111. }
  112. else
  113. {
  114. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  115. }
  116. }
  117. $class = $this->typeclass->find_all('classid = 2','id,title');
  118. $this->data['class'] = $class;
  119. $express = $this->express->find_all();
  120. $this->data['express'] = $express;
  121. $this->_Template('country_add',$this->data);
  122. }
  123. //修改
  124. public function _edit($arg_array)
  125. {
  126. $post = $this->input->post(NULL, TRUE);
  127. if(isset($post['id']))
  128. {
  129. $id = $this->input->post('id',true);
  130. if($this->country->save($post,$id))
  131. {
  132. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  133. }
  134. else
  135. {
  136. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  137. }
  138. }
  139. $arg_array = $arg_array[0];
  140. $country = $this->country->read($arg_array);
  141. $class = $this->typeclass->find_all('classid = 2','id,title');
  142. $this->data['class'] = $class;
  143. $this->data['country'] = $country;
  144. $express = $this->express->find_all();
  145. $this->data['express'] = $express;
  146. $this->_Template('country_edit',$this->data);
  147. }
  148. //删除
  149. public function _del()
  150. {
  151. $post = $this->input->post(NULL, TRUE);
  152. if(isset($post['s']))
  153. {
  154. $id_arr = $this->input->post('s');
  155. $id_arr = explode(',',$id_arr);
  156. if(!$id_arr)
  157. {
  158. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  159. }
  160. //循环删除记录
  161. foreach ($id_arr as $v)
  162. {
  163. $this->country->remove($v);
  164. }
  165. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  166. }
  167. }
  168. //删除
  169. public function _rows()
  170. {
  171. $this->load->library('pagination');
  172. $config['base_url'] = 'http://127.0.0.1/country/rows';
  173. $config['total_rows'] = 200;
  174. $config['per_page'] = 20;
  175. $this->pagination->initialize($config);
  176. echo $this->pagination->create_links();
  177. }
  178. }