Matching.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Matching extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->_model('Model_matching','matching');
  6. $this->load->_model('Model_typeclass','typeclass');
  7. $this->load->_model('Model_classid','classid');
  8. }
  9. //定义方法的调用规则 获取URI第二段值
  10. public function _remap($arg,$arg_array)
  11. {
  12. if($arg == 'add')
  13. {
  14. $this->_add();
  15. }
  16. else if($arg == 'edit')
  17. {
  18. $this->_edit($arg_array);
  19. }
  20. else if($arg == 'del')
  21. {
  22. $this->_del();
  23. }
  24. else if($arg == 'list')
  25. {
  26. $this->_list();
  27. }
  28. else
  29. {
  30. $this->_index();
  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. $category = $this->input->post('category',true);
  41. $where = "1=1";
  42. if($category)
  43. {
  44. $where .= " and category like '%$category%'";
  45. }
  46. //数据排序
  47. $order_str = "id desc";
  48. if(empty($page))
  49. {
  50. $start = 0;
  51. $perpage = 1;
  52. }
  53. else
  54. {
  55. $start = ($page - 1)*$perpage;
  56. }
  57. $typeclass = array();
  58. $class = $this->typeclass->find_all();
  59. foreach ($class as $v)
  60. {
  61. $v['spare'] = explode('|',$v['spare']);
  62. $typeclass[$v['id']] = array('spare'=>$v['spare'][0],'title'=>$v['title']);
  63. }
  64. $info_list = $this->matching->find_all($where,'id,category,listid,type,tdata,hdata',$order_str,$start,$perpage);
  65. foreach ($info_list as $key=>$value)
  66. {
  67. $info_list[$key]['category'] = $typeclass[$value['category']]['title'];
  68. $cl = $this->classid->read($value['listid']);
  69. $info_list[$key]['listid'] = $cl['title'];
  70. $info_list[$key]['tdata'] = ($value['tdata'])?$typeclass[$value['tdata']]['spare']:'';
  71. if($value['type'] == 1)
  72. {
  73. $info_list[$key]['type'] = '可适配';
  74. }
  75. else if($value['type'] == 2)
  76. {
  77. $info_list[$key]['type'] = '可不包含此SKU';
  78. }
  79. else if($value['type'] == 3)
  80. {
  81. $info_list[$key]['type'] = '类目可提档';
  82. $info_list[$key]['listid'] = "长度提档";
  83. }
  84. if($value['hdata'])
  85. {
  86. $hdata = explode(',',trim($value['hdata'],','));
  87. $hlist = '';
  88. foreach ($hdata as $v)
  89. {
  90. $hlist .= $typeclass[$v]['spare'].',';
  91. }
  92. $info_list[$key]['hdata'] = $hlist;
  93. }
  94. else
  95. {
  96. $info_list[$key]['hdata'] = '';
  97. }
  98. }
  99. $total = $this->matching->find_count($where);
  100. $pagenum = ceil($total/$perpage);
  101. $over = $total-($start+$perpage);
  102. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  103. echo json_encode($rows);exit;
  104. }
  105. $class = $this->classid->find_all("id = 10 or id = 13 or id = 15 or id = 18 or id = 9",'*','ckpx asc');
  106. $this->data['class'] = $class;
  107. $this->_Template('matching',$this->data);
  108. }
  109. public function _add()
  110. {
  111. $post = $this->input->post(NULL, TRUE);
  112. if(isset($post['category']))
  113. {
  114. $post['category'] = $this->input->post('category',true);
  115. $post['listid'] = $this->input->post('listid',true);
  116. $post['tdata'] = $this->input->post('tdata',true);
  117. $post['type'] = $this->input->post('type',true);
  118. $post['hdata'] = $this->input->post('hdata',true);
  119. if(!$post['category'])
  120. {
  121. echo json_encode(array('msg'=>'请选择类目','success'=>false));exit;
  122. }
  123. if(!$post['listid'])
  124. {
  125. echo json_encode(array('msg'=>'请选择类型','success'=>false));exit;
  126. }
  127. if(!$post['type'])
  128. {
  129. echo json_encode(array('msg'=>'请选择条件','success'=>false));exit;
  130. }
  131. if($post['type'] == 1 && (!$post['hdata'] || !$post['tdata']))
  132. {
  133. echo json_encode(array('msg'=>'数据不完整','success'=>false));exit;
  134. }
  135. if($post['type'] == 2 && !$post['hdata'])
  136. {
  137. echo json_encode(array('msg'=>'请选择原始SKU','success'=>false));exit;
  138. }
  139. $post['tdata'] = rtrim($post['tdata'],',');
  140. if($this->matching->insert($post))
  141. {
  142. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  143. }
  144. else
  145. {
  146. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  147. }
  148. }
  149. $class = $this->classid->find_all("id = 10 or id = 13 or id = 15 or id = 18 or id = 9",'*','ckpx asc');
  150. $this->data['class'] = $class;
  151. $this->_Template('matching_add',$this->data);
  152. }
  153. public function _edit($arg_array)
  154. {
  155. $post = $this->input->post(NULL, TRUE);
  156. if(isset($post['id']))
  157. {
  158. $post['category'] = $this->input->post('category',true);
  159. $post['listid'] = $this->input->post('listid',true);
  160. $post['tdata'] = $this->input->post('tdata',true);
  161. $post['type'] = $this->input->post('type',true);
  162. $post['hdata'] = $this->input->post('hdata',true);
  163. if(!$post['category'])
  164. {
  165. echo json_encode(array('msg'=>'请选择类目','success'=>false));exit;
  166. }
  167. if(!$post['listid'])
  168. {
  169. echo json_encode(array('msg'=>'请选择类型','success'=>false));exit;
  170. }
  171. if(!$post['type'])
  172. {
  173. echo json_encode(array('msg'=>'请选择条件','success'=>false));exit;
  174. }
  175. if($post['type'] == 1 && (!$post['hdata'] || !$post['tdata']))
  176. {
  177. echo json_encode(array('msg'=>'数据不完整','success'=>false));exit;
  178. }
  179. if($post['type'] == 2 && !$post['hdata'])
  180. {
  181. echo json_encode(array('msg'=>'请选择原始SKU','success'=>false));exit;
  182. }
  183. if($post['type'] == 3)
  184. {
  185. $post['tdata'] = '';
  186. $post['hdata'] = '';
  187. }
  188. $post['tdata'] = rtrim($post['tdata'],',');
  189. $id = $this->input->post('id',true);
  190. if($this->matching->save($post,$id))
  191. {
  192. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  193. }
  194. else
  195. {
  196. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  197. }
  198. }
  199. $arg_array = $arg_array[0];
  200. $matching = $this->matching->read($arg_array);
  201. $this->data['matching'] = $matching;
  202. $class = $this->classid->find_all("id = 10 or id = 13 or id = 15 or id = 18 or id = 9",'*','ckpx asc');
  203. $this->data['class'] = $class;
  204. $this->_Template('matching_edit',$this->data);
  205. }
  206. //删除
  207. public function _del()
  208. {
  209. $post = $this->input->post(NULL, TRUE);
  210. if(isset($post['s']))
  211. {
  212. $id_arr = $this->input->post('s');
  213. $id_arr = explode(',',$id_arr);
  214. if(!$id_arr)
  215. {
  216. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  217. }
  218. //循环删除记录
  219. foreach ($id_arr as $v)
  220. {
  221. $this->matching->remove($v);
  222. }
  223. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  224. }
  225. }
  226. public function _list()
  227. {
  228. $post = $this->input->post(NULL, TRUE);
  229. if(isset($post['id']))
  230. {
  231. $id = $this->input->post('id',true);
  232. $typeclass = $this->typeclass->find_all("classid = $id");
  233. if($typeclass)
  234. {
  235. echo json_encode(array('data'=>$typeclass,'success'=>true));exit;
  236. }
  237. else
  238. {
  239. echo json_encode(array('msg'=>'没有找到数据!','success'=>false));exit;
  240. }
  241. }
  242. }
  243. }