Describecode.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Describecode extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_describecode','describecode');
  7. }
  8. //定义方法的调用规则 获取URI第二段值
  9. public function _remap($arg,$arg_array)
  10. {
  11. if($arg == 'add')//添加
  12. {
  13. $this->_add();
  14. }
  15. else if($arg == 'edit')//修改
  16. {
  17. $this->_edit($arg_array);
  18. }
  19. else if($arg == 'del')//修改
  20. {
  21. $this->_del();
  22. }
  23. else if($arg == 'rows')//获取数据
  24. {
  25. $this->_rows();
  26. }
  27. else
  28. {
  29. $this->_index();
  30. }
  31. }
  32. //管理
  33. public function _index()
  34. {
  35. $post = $this->input->post(NULL, TRUE);
  36. if(isset($post['page']))
  37. {
  38. $page = $this->input->post('page',true);
  39. $perpage = $this->input->post('perpage',true);
  40. $where = "1=1 ";
  41. //数据排序
  42. $order_str = "id asc";
  43. if(empty($page))
  44. {
  45. $start = 0;
  46. $perpage = 1;
  47. }
  48. else
  49. {
  50. $start = ($page - 1)*$perpage;
  51. }
  52. //取得信息列表
  53. $info_list = $this->describecode->find_all($where,'id,product,expresscode',$order_str,$start,$perpage);
  54. $total = $this->describecode->find_count($where);
  55. $pagenum = ceil($total/$perpage);
  56. $over = $total-($start+$perpage);
  57. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  58. echo json_encode($rows);exit;
  59. }
  60. $this->_Template('describecode',$this->data);
  61. }
  62. //添加
  63. public function _add()
  64. {
  65. $post = $this->input->post(NULL, TRUE);
  66. if(isset($post['describecodename']))
  67. {
  68. $post['product'] = $this->input->post('product',true);
  69. $post['expresscode'] = $this->input->post('expresscode',true);
  70. $post['time'] = time().rand(1000,9999);
  71. if($this->describecode->insert($post))
  72. {
  73. $data = $this->describecode->get_time($post['time']);
  74. echo json_encode(array('msg'=>'添加成功','data'=>$data,'success'=>true));exit;
  75. }
  76. else
  77. {
  78. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  79. }
  80. }
  81. }
  82. //修改
  83. public function _edit($arg_array)
  84. {
  85. $post = $this->input->post(NULL, TRUE);
  86. if(isset($post['id']))
  87. {
  88. $id = $this->input->post('id',true);
  89. $post['class'] = $this->input->post('class',true);
  90. $post['product'] = $this->input->post('product',true);
  91. $post['expresscode'] = $this->input->post('expresscode',true);
  92. if($this->describecode->save($post,$id))
  93. {
  94. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  95. }
  96. else
  97. {
  98. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  99. }
  100. }
  101. }
  102. //删除
  103. public function _del()
  104. {
  105. $post = $this->input->post(NULL, TRUE);
  106. if(isset($post['s']))
  107. {
  108. $id_arr = $this->input->post('s');
  109. $id_arr = explode(',',$id_arr);
  110. if(!$id_arr)
  111. {
  112. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  113. }
  114. //循环删除记录
  115. foreach ($id_arr as $v)
  116. {
  117. $this->describecode->remove($v);
  118. }
  119. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  120. }
  121. }
  122. }