Skumaster.php 4.0 KB

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