Colourorderts.php 3.9 KB

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