Packing.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Packing extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_packing','packing');
  7. $this->load->_model('Model_whlabel','whlabel');
  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 == 'del')//修改
  21. {
  22. $this->_del();
  23. }
  24. else if($arg == 'rows')//获取数据
  25. {
  26. $this->_rows();
  27. }
  28. else
  29. {
  30. $this->_index();
  31. }
  32. }
  33. //管理
  34. public function _index()
  35. {
  36. $post = $this->input->post(NULL, TRUE);
  37. if(isset($post['page']))
  38. {
  39. $page = $this->input->post('page',true);
  40. $perpage = $this->input->post('perpage',true);
  41. $where = "1=1 ";
  42. //数据排序
  43. $order_str = "id asc";
  44. if(empty($page))
  45. {
  46. $start = 0;
  47. $perpage = 1;
  48. }
  49. else
  50. {
  51. $start = ($page - 1)*$perpage;
  52. }
  53. //取得信息列表
  54. $info_list = $this->packing->find_all($where,'id,model,weightend,weight',$order_str,$start,$perpage);
  55. $total = $this->packing->find_count($where);
  56. $pagenum = ceil($total/$perpage);
  57. $over = $total-($start+$perpage);
  58. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  59. echo json_encode($rows);exit;
  60. }
  61. $this->_Template('packing',$this->data);
  62. }
  63. //添加
  64. public function _add()
  65. {
  66. $post = $this->input->post(NULL, TRUE);
  67. if(isset($post['model']))
  68. {
  69. $post['classid'] = 2;
  70. $post['model'] = $this->input->post('model',true);
  71. $post['weightend'] = $this->input->post('weightend',true);
  72. $post['weight'] = $this->input->post('weight',true);
  73. if($this->packing->insert($post))
  74. {
  75. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  76. }
  77. else
  78. {
  79. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  80. }
  81. }
  82. $this->_Template('packing_add',$this->data);
  83. }
  84. //修改
  85. public function _edit($arg_array)
  86. {
  87. $post = $this->input->post(NULL, TRUE);
  88. if(isset($post['id']))
  89. {
  90. $id = $this->input->post('id',true);
  91. $post['classid'] = 2;
  92. $post['model'] = $this->input->post('model',true);
  93. $post['weightend'] = $this->input->post('weightend',true);
  94. $post['weight'] = $this->input->post('weight',true);
  95. if($this->packing->save($post,$id))
  96. {
  97. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  98. }
  99. else
  100. {
  101. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  102. }
  103. }
  104. $arg_array = $arg_array[0];
  105. $packing = $this->packing->read($arg_array);
  106. $this->data['packing'] = $packing;
  107. $this->_Template('packing_edit',$this->data);
  108. }
  109. //删除
  110. public function _del()
  111. {
  112. $post = $this->input->post(NULL, TRUE);
  113. if(isset($post['s']))
  114. {
  115. $id_arr = $this->input->post('s');
  116. $id_arr = explode(',',$id_arr);
  117. if(!$id_arr)
  118. {
  119. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  120. }
  121. //循环删除记录
  122. foreach ($id_arr as $v)
  123. {
  124. $this->packing->remove($v);
  125. }
  126. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  127. }
  128. }
  129. }