Detailed.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Detailed extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_detailed','detailed');
  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->detailed->find_all($where,'id,lowerlimit,includelower,upperlimit,includeupper,calculatemethod,customsval',$order_str,$start,$perpage);
  54. $total = $this->detailed->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('detailed',$this->data);
  61. }
  62. //添加
  63. public function _add()
  64. {
  65. $post = $this->input->post(NULL, TRUE);
  66. if(isset($post['lowerlimit']))
  67. {
  68. $post['lowerlimit'] = $this->input->post('lowerlimit',true);
  69. $post['includelower'] = $this->input->post('includelower',true);
  70. $post['upperlimit'] = $this->input->post('upperlimit',true);
  71. $post['includeupper'] = $this->input->post('includeupper',true);
  72. $post['calculatemethod'] = $this->input->post('calculatemethod',true);
  73. $post['customsval'] = $this->input->post('customsval',true);
  74. $post['time'] = time().rand(1000,1000);
  75. if($this->detailed->insert($post))
  76. {
  77. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  78. }
  79. else
  80. {
  81. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  82. }
  83. }
  84. }
  85. //修改
  86. public function _edit($arg_array)
  87. {
  88. $post = $this->input->post(NULL, TRUE);
  89. if(isset($post['id']))
  90. {
  91. $id = $this->input->post('id',true);
  92. $post['lowerlimit'] = $this->input->post('lowerlimit',true);
  93. $post['includelower'] = $this->input->post('includelower',true);
  94. $post['upperlimit'] = $this->input->post('upperlimit',true);
  95. $post['includeupper'] = $this->input->post('includeupper',true);
  96. $post['calculatemethod'] = $this->input->post('calculatemethod',true);
  97. $post['customsval'] = $this->input->post('customsval',true);
  98. if($this->detailed->save($post,$id))
  99. {
  100. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  101. }
  102. else
  103. {
  104. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  105. }
  106. }
  107. }
  108. //删除
  109. public function _del()
  110. {
  111. $post = $this->input->post(NULL, TRUE);
  112. if(isset($post['s']))
  113. {
  114. $id_arr = $this->input->post('s');
  115. $id_arr = explode(',',$id_arr);
  116. if(!$id_arr)
  117. {
  118. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  119. }
  120. //循环删除记录
  121. foreach ($id_arr as $v)
  122. {
  123. $this->detailed->remove($v);
  124. }
  125. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  126. }
  127. }
  128. }