Container.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Container extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_container','container');
  7. $this->load->_model('Model_excel','excel');
  8. }
  9. //定义方法的调用规则 获取URI第二段值
  10. public function _remap($arg,$arg_array)
  11. {
  12. if($arg == 'add')//添加
  13. {
  14. $this->_add();
  15. }
  16. else if($arg == 'edit')//修改
  17. {
  18. $this->_edit($arg_array);
  19. }
  20. else if($arg == 'see')
  21. {
  22. $this->_see($arg_array);
  23. }
  24. else if($arg == 'del')
  25. {
  26. $this->_del($arg_array);
  27. }
  28. else if($arg == 'excel')
  29. {
  30. $this->_excel();
  31. }
  32. else
  33. {
  34. $this->_index($arg_array);
  35. }
  36. }
  37. //管理
  38. public function _index($arg_array)
  39. {
  40. $post = $this->input->post(NULL, TRUE);
  41. if(isset($post['page']))
  42. {
  43. $page = $this->input->post('page',true);
  44. $perpage = $this->input->post('perpage',true);
  45. $title = $this->input->post('title',true);
  46. $name = $this->input->post('name',true);
  47. $timetk = $this->input->post('timetk',true);
  48. $timetj = $this->input->post('timetj',true);
  49. $timetk = strtotime($timetk);
  50. $timetj = strtotime($timetj);
  51. $where = "1=1 ";
  52. //数据排序
  53. $order_str = "id asc";
  54. if(empty($page))
  55. {
  56. $start = 0;
  57. $perpage = 1;
  58. }
  59. else
  60. {
  61. $start = ($page - 1)*$perpage;
  62. }
  63. if($title)
  64. {
  65. $where .= " and title like '%$title%'";
  66. }
  67. if($name)
  68. {
  69. $where .= " and name like '%$name%'";
  70. }
  71. if($timetk && $timetj)
  72. {
  73. $where .= " and time > '$timetk' and time < '$timetj'";
  74. }
  75. //取得信息列表
  76. $info_list = $this->container->find_all($where,'id,title,num,weight,zweight,volume,type,yt,name,time',$order_str,$start,$perpage);
  77. //格式化数据
  78. foreach ($info_list as $key=>$value)
  79. {
  80. $info_list[$key]['time'] = date("Y-m-d H:i:s",$value['time']);
  81. if($value['type'] == 1)
  82. {
  83. $info_list[$key]['type'] = 'A-必须发';
  84. }
  85. else if($value['type'] == 2)
  86. {
  87. $info_list[$key]['type'] = 'B-如果发不完可先发走一部分';
  88. }
  89. else if($value['type'] == 3)
  90. {
  91. $info_list[$key]['type'] = 'C-拼箱用,可发可不发';
  92. }
  93. }
  94. $total = $this->container->find_count($where);
  95. $pagenum = ceil($total/$perpage);
  96. $over = $total-($start+$perpage);
  97. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  98. echo json_encode($rows);exit;
  99. }
  100. $this->_Template('container',$this->data);
  101. }
  102. //添加
  103. public function _add()
  104. {
  105. $post = $this->input->post(NULL, TRUE);
  106. if(isset($post['title']))
  107. {
  108. $post['time'] = time();
  109. if($this->container->insert($post))
  110. {
  111. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  112. }
  113. else
  114. {
  115. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  116. }
  117. }
  118. $this->_Template('container_add',$this->data);
  119. }
  120. //修改
  121. public function _edit($arg_array)
  122. {
  123. $post = $this->input->post(NULL, TRUE);
  124. if(isset($post['id']))
  125. {
  126. $id = $this->input->post('id',true);
  127. if($this->container->save($post,$id))
  128. {
  129. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  130. }
  131. else
  132. {
  133. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  134. }
  135. }
  136. $arg_array = $arg_array[0];
  137. $container = $this->container->read($arg_array);
  138. $this->data['container'] = $container;
  139. $this->_Template('container_edit',$this->data);
  140. }
  141. //删除
  142. public function _del()
  143. {
  144. $post = $this->input->post(NULL, TRUE);
  145. if(isset($post['s']))
  146. {
  147. $id_arr = $this->input->post('s');
  148. $id_arr = explode(',',$id_arr);
  149. if(!$id_arr)
  150. {
  151. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  152. }
  153. //循环删除记录
  154. foreach ($id_arr as $v)
  155. {
  156. $this->container->remove($v);
  157. }
  158. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  159. }
  160. }
  161. public function _excel()
  162. {
  163. $post = $this->input->get(NULL, TRUE);
  164. if(isset($post['timetk']))
  165. {
  166. $page = $this->input->get('page',true);
  167. $perpage = $this->input->get('perpage',true);
  168. $timetk = $this->input->get('timetk',true);
  169. $timetj = $this->input->get('timetj',true);
  170. $title = $this->input->get('title',true);
  171. $name = $this->input->get('name',true);
  172. $timetk = $this->input->get('timetk',true);
  173. $timetj = $this->input->get('timetj',true);
  174. $timetk = strtotime($timetk);
  175. $timetj = strtotime($timetj);
  176. $dowid = $this->input->get('a');
  177. $wid = "";
  178. if($dowid != "")
  179. {
  180. $id_arr = explode(',',rtrim($dowid,','));
  181. $wid .= " id = 0 or";
  182. foreach ($id_arr as $v)
  183. {
  184. $wid .= " id = '$v' or";
  185. }
  186. $wid = " and".rtrim($wid,'or');
  187. }
  188. $where = "1=1";
  189. if($timetk && $timetj)
  190. {
  191. $where .= " and time > '$timetk' and time < '$timetj'";
  192. }
  193. if($title)
  194. {
  195. $where .= " and title like '%$title%'";
  196. }
  197. if($name)
  198. {
  199. $where .= " and name like '%$name%'";
  200. }
  201. $info_list = $this->container->find_all($where.$wid,'title,num,weight,zweight,volume,type,yt,name,time','id desc');
  202. foreach ($info_list as $key=>$value)
  203. {
  204. $info_list[$key]['time'] = date("Y-m-d H:i:s",$value['time']);
  205. if($value['type'] == 1)
  206. {
  207. $info_list[$key]['type'] = 'A-必须发';
  208. }
  209. else if($value['type'] == 2)
  210. {
  211. $info_list[$key]['type'] = 'B-如果发不完可先发走一部分';
  212. }
  213. else if($value['type'] == 3)
  214. {
  215. $info_list[$key]['type'] = 'C-拼箱用,可发可不发';
  216. }
  217. }
  218. $title = '货柜物品'.date('Y-m-d',$timetk).'-'.date('Y-m-d',$timetj);
  219. $titlename = "<table border=1>
  220. <tr>
  221. <td>货物名称</td>
  222. <td>数量</td>
  223. <td>单位重量(千克)</td>
  224. <td>总重量(千克)</td>
  225. <td>预估体积(立方米)</td>
  226. <td>优先级</td>
  227. <td>用途</td>
  228. <td>提交人</td>
  229. <td>提交时间</td>
  230. </tr>
  231. </table>";
  232. $filename = $title.".xls";
  233. $tail = "\n";
  234. $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
  235. }
  236. }
  237. }