Logistics.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Logistics extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_logistics','logistics');
  7. $this->load->_model('Model_country','country');
  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
  26. {
  27. $this->_index();
  28. }
  29. }
  30. //管理
  31. public function _index()
  32. {
  33. $post = $this->input->post(NULL, TRUE);
  34. if(isset($post['page']))
  35. {
  36. $page = $this->input->post('page',true);
  37. $perpage = $this->input->post('perpage',true);
  38. $country = $this->input->post('country',true);
  39. $express = $this->input->post('express',true);
  40. $where = "1=1 ";
  41. if($country)
  42. {
  43. $where .= " and country = '$country'";
  44. }
  45. if($express)
  46. {
  47. $where .= " and express = '$express'";
  48. }
  49. //数据排序
  50. $order_str = "id asc";
  51. if(empty($page))
  52. {
  53. $start = 0;
  54. $perpage = 1;
  55. }
  56. else
  57. {
  58. $start = ($page - 1)*$perpage;
  59. }
  60. //取得信息列表
  61. $info_list = $this->logistics->find_all($where,'id,express,country,first,firstmoney,factfirstcost,addition,additionmoney,factaddition',$order_str,$start,$perpage);
  62. foreach ($info_list as $key=>$value)
  63. {
  64. $country = $this->country->read($value['country']);
  65. $info_list[$key]['country'] = $country['name'];
  66. $express = $this->express->read($value['express']);
  67. $info_list[$key]['express'] = $express['title'];
  68. }
  69. $total = $this->logistics->find_count($where);
  70. $pagenum = ceil($total/$perpage);
  71. $over = $total-($start+$perpage);
  72. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  73. echo json_encode($rows);exit;
  74. }
  75. $country = $this->country->find_all();
  76. $this->data['country'] = $country;
  77. $express = $this->express->find_all();
  78. $this->data['express'] = $express;
  79. $this->_Template('logistics',$this->data);
  80. }
  81. //添加
  82. public function _add()
  83. {
  84. $post = $this->input->post(NULL, TRUE);
  85. if(isset($post['express']))
  86. {
  87. $post['express'] = $this->input->post('express',true);
  88. $post['first'] = $this->input->post('first',true);
  89. $post['addition'] = $this->input->post('addition',true);
  90. $post['firstmoney'] = $this->input->post('firstmoney',true);
  91. $post['additionmoney'] = $this->input->post('additionmoney',true);
  92. $post['factfirstcost'] = $this->input->post('factfirstcost',true);
  93. $post['factaddition'] = $this->input->post('factaddition',true);
  94. $countryck = $this->input->post('country',true);
  95. if($countryck)
  96. {
  97. $countryck = explode(',',rtrim($countryck,','));
  98. foreach ($countryck as $key=>$value)
  99. {
  100. $post['country'] = $value;
  101. $this->logistics->insert($post);
  102. }
  103. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  104. }
  105. else
  106. {
  107. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  108. }
  109. }
  110. $country = $this->country->find_all();
  111. $this->data['country'] = $country;
  112. $express = $this->express->find_all();
  113. $this->data['express'] = $express;
  114. $this->_Template('logistics_add',$this->data);
  115. }
  116. //修改
  117. public function _edit($arg_array)
  118. {
  119. $post = $this->input->post(NULL, TRUE);
  120. if(isset($post['id']))
  121. {
  122. $id = $this->input->post('id',true);
  123. $post['express'] = $this->input->post('express',true);
  124. $post['first'] = $this->input->post('first',true);
  125. $post['addition'] = $this->input->post('addition',true);
  126. $post['firstmoney'] = $this->input->post('firstmoney',true);
  127. $post['additionmoney'] = $this->input->post('additionmoney',true);
  128. $post['factfirstcost'] = $this->input->post('factfirstcost',true);
  129. $post['factaddition'] = $this->input->post('factaddition',true);
  130. $post['country'] = $this->input->post('country',true);
  131. if($this->logistics->save($post,$id))
  132. {
  133. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  134. }
  135. else
  136. {
  137. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  138. }
  139. }
  140. $arg_array = $arg_array[0];
  141. $logistics = $this->logistics->read($arg_array);
  142. $this->data['logistics'] = $logistics;
  143. $country = $this->country->find_all();
  144. $this->data['country'] = $country;
  145. $express = $this->express->find_all();
  146. $this->data['express'] = $express;
  147. $this->_Template('logistics_edit',$this->data);
  148. }
  149. //删除
  150. public function _del()
  151. {
  152. $post = $this->input->post(NULL, TRUE);
  153. if(isset($post['s']))
  154. {
  155. $id_arr = $this->input->post('s');
  156. $id_arr = explode(',',$id_arr);
  157. if(!$id_arr)
  158. {
  159. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  160. }
  161. //循环删除记录
  162. foreach ($id_arr as $v)
  163. {
  164. $this->logistics->remove($v);
  165. }
  166. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  167. }
  168. }
  169. }