Allocation.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Allocation extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_allocation','allocation');
  7. $this->load->_model('Model_typeclass','typeclass');
  8. $this->load->_model('Model_warehouse','warehouse');
  9. }
  10. //定义方法的调用规则 获取URI第二段值
  11. public function _remap($arg,$arg_array)
  12. {
  13. if($arg == 'list')
  14. {
  15. $this->_list();
  16. }
  17. else if($arg == 'add')//添加
  18. {
  19. $this->_add();
  20. }
  21. else if($arg == 'edit')//修改
  22. {
  23. $this->_edit($arg_array);
  24. }
  25. else if($arg == 'del')//修改
  26. {
  27. $this->_del();
  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. $ktime = $this->input->post('ktime',true);
  43. $jtime = $this->input->post('jtime',true);
  44. $cwarehouse = $this->input->post('cwarehouse',true);
  45. $type = $this->input->post('type',true);
  46. $order = $this->input->post('order',true);
  47. $ktime = strtotime($ktime);
  48. $jtime = strtotime($jtime)+24*3600;
  49. $where = "1=1 ";
  50. if($cwarehouse)
  51. {
  52. $where .= " and cwarehouse = '$cwarehouse'";
  53. }
  54. if($type)
  55. {
  56. $where .= " and type = '$type'";
  57. }
  58. if($order)
  59. {
  60. $where .= " and order = '$order'";
  61. }
  62. if($ktime && $jtime)
  63. {
  64. $where .= " and addtime > '$ktime' and addtime < '$jtime'";
  65. }
  66. //数据排序
  67. $order_str = "id asc";
  68. if(empty($page))
  69. {
  70. $start = 0;
  71. $perpage = 1;
  72. }
  73. else
  74. {
  75. $start = ($page - 1)*$perpage;
  76. }
  77. //取得信息列表
  78. $info_list = $this->allocation->find_all($where,'id, order,title,cwarehouse,rwarehouse,addtime,name,type',$order_str,$start,$perpage);
  79. foreach ($info_list as $key=>$value)
  80. {
  81. if($value['type'] == 1)
  82. {
  83. $info_list[$key]['type'] = "未调出";
  84. }
  85. else if($value['type'] == 2)
  86. {
  87. $info_list[$key]['type'] = "已调出";
  88. }
  89. else if($value['type'] == 3)
  90. {
  91. $info_list[$key]['type'] = "已调入";
  92. }
  93. else if($value['type'] == 4)
  94. {
  95. $info_list[$key]['type'] = "已结束";
  96. }
  97. $cwarehouse = $this->warehouse->read($value['cwarehouse']);
  98. $info_list[$key]['cwarehouse'] = $cwarehouse['title'];
  99. $rwarehouse = $this->warehouse->read($value['rwarehouse']);
  100. $info_list[$key]['rwarehouse'] = $rwarehouse['title'];
  101. $info_list[$key]['addtime'] = date('Y-m-d',$value['addtime']);
  102. }
  103. $total = $this->allocation->find_count($where);
  104. $pagenum = ceil($total/$perpage);
  105. $over = $total-($start+$perpage);
  106. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  107. echo json_encode($rows);exit;
  108. }
  109. $this->_Template('allocation',$this->data);
  110. }
  111. //管理
  112. public function _list()
  113. {
  114. $post = $this->input->post(NULL, TRUE);
  115. if(isset($post['page']))
  116. {
  117. $page = $this->input->post('page',true);
  118. $perpage = $this->input->post('perpage',true);
  119. $ktime = $this->input->post('ktime',true);
  120. $jtime = $this->input->post('jtime',true);
  121. $cwarehouse = $this->input->post('cwarehouse',true);
  122. $type = $this->input->post('type',true);
  123. $order = $this->input->post('order',true);
  124. $ktime = strtotime($ktime);
  125. $jtime = strtotime($jtime)+24*3600;
  126. $where = "1=1 ";
  127. if($cwarehouse)
  128. {
  129. $where .= " and cwarehouse = '$cwarehouse'";
  130. }
  131. if($type)
  132. {
  133. $where .= " and type = '$type'";
  134. }
  135. if($order)
  136. {
  137. $where .= " and order = '$order'";
  138. }
  139. if($ktime && $jtime)
  140. {
  141. $where .= " and addtime > '$ktime' and addtime < '$jtime'";
  142. }
  143. //数据排序
  144. $order_str = "id asc";
  145. if(empty($page))
  146. {
  147. $start = 0;
  148. $perpage = 1;
  149. }
  150. else
  151. {
  152. $start = ($page - 1)*$perpage;
  153. }
  154. //取得信息列表
  155. $info_list = $this->allocation->find_all($where,'id, order,title,cwarehouse,rwarehouse,addtime,name,type,time',$order_str,$start,$perpage);
  156. foreach ($info_list as $key=>$value)
  157. {
  158. if($value['type'] == 1)
  159. {
  160. $info_list[$key]['type'] = "未调出";
  161. $info_list[$key]['time'] = "<p><b class='allocation' data-id='".$value['id']."'>订单已调出</b></p>";
  162. }
  163. else if($value['type'] == 2)
  164. {
  165. $info_list[$key]['type'] = "已调出";
  166. $info_list[$key]['time'] = "<p><b class='allocation' data-id='".$value['id']."'>订单已调入</b></p>";
  167. }
  168. else if($value['type'] == 3)
  169. {
  170. $info_list[$key]['type'] = "已调入";
  171. $info_list[$key]['time'] = "<p><b class='allocation' data-id='".$value['id']."'>订单已验收</b></p>";
  172. }
  173. else if($value['type'] == 4)
  174. {
  175. $info_list[$key]['type'] = "已结束";
  176. $info_list[$key]['time'] = "<p></p>";
  177. }
  178. $cwarehouse = $this->warehouse->read($value['cwarehouse']);
  179. $info_list[$key]['cwarehouse'] = $cwarehouse['title'];
  180. $rwarehouse = $this->warehouse->read($value['rwarehouse']);
  181. $info_list[$key]['rwarehouse'] = $rwarehouse['title'];
  182. $info_list[$key]['addtime'] = date('Y-m-d',$value['addtime']);
  183. }
  184. $total = $this->allocation->find_count($where);
  185. $pagenum = ceil($total/$perpage);
  186. $over = $total-($start+$perpage);
  187. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  188. echo json_encode($rows);exit;
  189. }
  190. $this->_Template('allocation_list',$this->data);
  191. }
  192. //添加
  193. public function _add()
  194. {
  195. $post = $this->input->post(NULL, TRUE);
  196. if(isset($post['title']))
  197. {
  198. $post['title'] = $this->input->post('title',true);
  199. $post['name'] = $this->input->post('name',true);
  200. $time = $this->input->post('time',true);
  201. $post['time'] = strtotime($time);
  202. $post['cwarehouse'] = $this->input->post('cwarehouse',true);
  203. $post['rwarehouse'] = $this->input->post('rwarehouse',true);
  204. $post['order'] = date('Ymd',time()).rand(100,999);
  205. $user = $this->user->get_api($_SESSION['api']);
  206. $post['name'] = $user['name'];
  207. $post['type'] = 1;
  208. $post['addtime'] = time();
  209. if($post['cwarehouse'] == $post['rwarehouse'])
  210. {
  211. echo json_encode(array('msg'=>'调入仓库和调出仓库不能相同!','success'=>false));exit;
  212. }
  213. if($this->allocation->insert($post))
  214. {
  215. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  216. }
  217. else
  218. {
  219. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  220. }
  221. }
  222. $class = $this->typeclass->find_all('classid = 200');
  223. $this->data['class'] = $class;
  224. $this->_Template('allocation_add',$this->data);
  225. }
  226. //修改
  227. public function _edit($arg_array)
  228. {
  229. $post = $this->input->post(NULL, TRUE);
  230. if(isset($post['id']))
  231. {
  232. $id = $this->input->post('id',true);
  233. $a = $this->allocation->read($id);
  234. if($a['type'] == 1)
  235. {
  236. $type = 2;
  237. $z = "已调出";
  238. $c = "<b class='allocation' data-id='".$id."'>订单已调入</b>";
  239. }
  240. else if($a['type'] == 2)
  241. {
  242. $type = 3;
  243. $z = "已调入";
  244. $c = "<b class='allocation' data-id='".$id."'>订单已验收</b>";
  245. }
  246. else if($a['type'] == 3)
  247. {
  248. $type = 4;
  249. $z = "已结束";
  250. $c = "";
  251. }
  252. if($this->allocation->save(array('type'=>$type),$id))
  253. {
  254. echo json_encode(array('msg'=>'修改成功','z'=>$z,'c'=>$c,'id'=>$id,'success'=>true));exit;
  255. }
  256. else
  257. {
  258. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  259. }
  260. }
  261. }
  262. //删除
  263. public function _del()
  264. {
  265. $post = $this->input->post(NULL, TRUE);
  266. if(isset($post['s']))
  267. {
  268. $id_arr = $this->input->post('s');
  269. $id_arr = explode(',',$id_arr);
  270. if(!$id_arr)
  271. {
  272. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  273. }
  274. //循环删除记录
  275. foreach ($id_arr as $v)
  276. {
  277. $this->allocation->remove($v);
  278. }
  279. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  280. }
  281. }
  282. }