Productdescription.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Productdescription extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_productdescription','productdescription');
  7. $this->load->_model('Model_country','country');
  8. $this->load->_model('Model_express','express');
  9. $this->load->_model('Model_typeclass','typeclass');
  10. }
  11. //定义方法的调用规则 获取URI第二段值
  12. public function _remap($arg,$arg_array)
  13. {
  14. if($arg == 'add')//添加
  15. {
  16. $this->_add();
  17. }
  18. else if($arg == 'edit')//修改
  19. {
  20. $this->_edit($arg_array);
  21. }
  22. else if($arg == 'del')//修改
  23. {
  24. $this->_del();
  25. }
  26. else
  27. {
  28. $this->_index();
  29. }
  30. }
  31. //管理
  32. public function _index()
  33. {
  34. $post = $this->input->post(NULL, TRUE);
  35. if(isset($post['page']))
  36. {
  37. $page = $this->input->post('page',true);
  38. $perpage = $this->input->post('perpage',true);
  39. $country = $this->input->post('country',true);
  40. $express = $this->input->post('express',true);
  41. $where = "1=1 ";
  42. if($country)
  43. {
  44. $where .= " and country = '$country'";
  45. }
  46. if($express)
  47. {
  48. $where .= " and express = '$express'";
  49. }
  50. //数据排序
  51. $order_str = "id asc";
  52. if(empty($page))
  53. {
  54. $start = 0;
  55. $perpage = 1;
  56. }
  57. else
  58. {
  59. $start = ($page - 1)*$perpage;
  60. }
  61. //取得信息列表
  62. $info_list = $this->productdescription->find_all($where,'id,express,country,description',$order_str,$start,$perpage);
  63. foreach ($info_list as $key=>$value)
  64. {
  65. $country = $this->country->read($value['country']);
  66. $info_list[$key]['country'] = $country['name'];
  67. $express = $this->express->read($value['express']);
  68. $info_list[$key]['express'] = $express['title'];
  69. $typeclass = $this->typeclass->read($value['description']);
  70. $info_list[$key]['description'] = $typeclass['title'];
  71. }
  72. $total = $this->productdescription->find_count($where);
  73. $pagenum = ceil($total/$perpage);
  74. $over = $total-($start+$perpage);
  75. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  76. echo json_encode($rows);exit;
  77. }
  78. $country = $this->country->find_all();
  79. $this->data['country'] = $country;
  80. $express = $this->express->find_all();
  81. $this->data['express'] = $express;
  82. $this->_Template('productdescription',$this->data);
  83. }
  84. //添加
  85. public function _add()
  86. {
  87. $post = $this->input->post(NULL, TRUE);
  88. if(isset($post['express']))
  89. {
  90. $post['express'] = $this->input->post('express',true);
  91. $post['description'] = $this->input->post('description',true);
  92. $countryck = $this->input->post('country',true);
  93. if($countryck)
  94. {
  95. $countryck = explode(',',rtrim($countryck,','));
  96. foreach ($countryck as $key=>$value)
  97. {
  98. $post['country'] = $value;
  99. $this->productdescription->insert($post);
  100. }
  101. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  102. }
  103. else
  104. {
  105. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  106. }
  107. }
  108. $country = $this->country->find_all();
  109. $this->data['country'] = $country;
  110. $express = $this->express->find_all();
  111. $this->data['express'] = $express;
  112. $typeclass = $this->typeclass->find_all('classid = 3');
  113. $this->data['description'] = $typeclass;
  114. $this->_Template('productdescription_add',$this->data);
  115. }
  116. //修改
  117. public function _edit($arg_array)
  118. {
  119. $post = $this->input->post(NULL, TRUE);
  120. if(isset($post['id']))
  121. {
  122. $id = $this->input->post('id',true);
  123. $post['express'] = $this->input->post('express',true);
  124. $post['description'] = $this->input->post('description',true);
  125. $post['country'] = $this->input->post('country',true);
  126. if($this->productdescription->save($post,$id))
  127. {
  128. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  129. }
  130. else
  131. {
  132. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  133. }
  134. }
  135. $arg_array = $arg_array[0];
  136. $productdescription = $this->productdescription->read($arg_array);
  137. $this->data['productdescription'] = $productdescription;
  138. $country = $this->country->find_all();
  139. $this->data['country'] = $country;
  140. $express = $this->express->find_all();
  141. $this->data['express'] = $express;
  142. $typeclass = $this->typeclass->find_all('classid = 3');
  143. $this->data['description'] = $typeclass;
  144. $this->_Template('productdescription_edit',$this->data);
  145. }
  146. //删除
  147. public function _del()
  148. {
  149. $post = $this->input->post(NULL, TRUE);
  150. if(isset($post['s']))
  151. {
  152. $id_arr = $this->input->post('s');
  153. $id_arr = explode(',',$id_arr);
  154. if(!$id_arr)
  155. {
  156. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  157. }
  158. //循环删除记录
  159. foreach ($id_arr as $v)
  160. {
  161. $this->productdescription->remove($v);
  162. }
  163. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  164. }
  165. }
  166. }