load->_model('Model_matching','matching'); $this->load->_model('Model_typeclass','typeclass'); $this->load->_model('Model_classid','classid'); } //定义方法的调用规则 获取URI第二段值 public function _remap($arg,$arg_array) { if($arg == 'add') { $this->_add(); } else if($arg == 'edit') { $this->_edit($arg_array); } else if($arg == 'del') { $this->_del(); } else if($arg == 'list') { $this->_list(); } else { $this->_index(); } } public function _index() { $post = $this->input->post(NULL, TRUE); if(isset($post['page'])) { $page = $this->input->post('page',true); $perpage = $this->input->post('perpage',true); $category = $this->input->post('category',true); $where = "1=1"; if($category) { $where .= " and category like '%$category%'"; } //数据排序 $order_str = "id desc"; if(empty($page)) { $start = 0; $perpage = 1; } else { $start = ($page - 1)*$perpage; } $typeclass = array(); $class = $this->typeclass->find_all(); foreach ($class as $v) { $v['spare'] = explode('|',$v['spare']); $typeclass[$v['id']] = array('spare'=>$v['spare'][0],'title'=>$v['title']); } $info_list = $this->matching->find_all($where,'id,category,listid,type,tdata,hdata',$order_str,$start,$perpage); foreach ($info_list as $key=>$value) { $info_list[$key]['category'] = $typeclass[$value['category']]['title']; $cl = $this->classid->read($value['listid']); $info_list[$key]['listid'] = $cl['title']; $info_list[$key]['tdata'] = ($value['tdata'])?$typeclass[$value['tdata']]['spare']:''; if($value['type'] == 1) { $info_list[$key]['type'] = '可适配'; } else if($value['type'] == 2) { $info_list[$key]['type'] = '可不包含此SKU'; } else if($value['type'] == 3) { $info_list[$key]['type'] = '类目可提档'; $info_list[$key]['listid'] = "长度提档"; } if($value['hdata']) { $hdata = explode(',',trim($value['hdata'],',')); $hlist = ''; foreach ($hdata as $v) { $hlist .= $typeclass[$v]['spare'].','; } $info_list[$key]['hdata'] = $hlist; } else { $info_list[$key]['hdata'] = ''; } } $total = $this->matching->find_count($where); $pagenum = ceil($total/$perpage); $over = $total-($start+$perpage); $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list)); echo json_encode($rows);exit; } $class = $this->classid->find_all("id = 10 or id = 13 or id = 15 or id = 18 or id = 9",'*','ckpx asc'); $this->data['class'] = $class; $this->_Template('matching',$this->data); } public function _add() { $post = $this->input->post(NULL, TRUE); if(isset($post['category'])) { $post['category'] = $this->input->post('category',true); $post['listid'] = $this->input->post('listid',true); $post['tdata'] = $this->input->post('tdata',true); $post['type'] = $this->input->post('type',true); $post['hdata'] = $this->input->post('hdata',true); if(!$post['category']) { echo json_encode(array('msg'=>'请选择类目','success'=>false));exit; } if(!$post['listid']) { echo json_encode(array('msg'=>'请选择类型','success'=>false));exit; } if(!$post['type']) { echo json_encode(array('msg'=>'请选择条件','success'=>false));exit; } if($post['type'] == 1 && (!$post['hdata'] || !$post['tdata'])) { echo json_encode(array('msg'=>'数据不完整','success'=>false));exit; } if($post['type'] == 2 && !$post['hdata']) { echo json_encode(array('msg'=>'请选择原始SKU','success'=>false));exit; } $post['tdata'] = rtrim($post['tdata'],','); if($this->matching->insert($post)) { echo json_encode(array('msg'=>'添加成功','success'=>true));exit; } else { echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit; } } $class = $this->classid->find_all("id = 10 or id = 13 or id = 15 or id = 18 or id = 9",'*','ckpx asc'); $this->data['class'] = $class; $this->_Template('matching_add',$this->data); } public function _edit($arg_array) { $post = $this->input->post(NULL, TRUE); if(isset($post['id'])) { $post['category'] = $this->input->post('category',true); $post['listid'] = $this->input->post('listid',true); $post['tdata'] = $this->input->post('tdata',true); $post['type'] = $this->input->post('type',true); $post['hdata'] = $this->input->post('hdata',true); if(!$post['category']) { echo json_encode(array('msg'=>'请选择类目','success'=>false));exit; } if(!$post['listid']) { echo json_encode(array('msg'=>'请选择类型','success'=>false));exit; } if(!$post['type']) { echo json_encode(array('msg'=>'请选择条件','success'=>false));exit; } if($post['type'] == 1 && (!$post['hdata'] || !$post['tdata'])) { echo json_encode(array('msg'=>'数据不完整','success'=>false));exit; } if($post['type'] == 2 && !$post['hdata']) { echo json_encode(array('msg'=>'请选择原始SKU','success'=>false));exit; } if($post['type'] == 3) { $post['tdata'] = ''; $post['hdata'] = ''; } $post['tdata'] = rtrim($post['tdata'],','); $id = $this->input->post('id',true); if($this->matching->save($post,$id)) { echo json_encode(array('msg'=>'修改成功','success'=>true));exit; } else { echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit; } } $arg_array = $arg_array[0]; $matching = $this->matching->read($arg_array); $this->data['matching'] = $matching; $class = $this->classid->find_all("id = 10 or id = 13 or id = 15 or id = 18 or id = 9",'*','ckpx asc'); $this->data['class'] = $class; $this->_Template('matching_edit',$this->data); } //删除 public function _del() { $post = $this->input->post(NULL, TRUE); if(isset($post['s'])) { $id_arr = $this->input->post('s'); $id_arr = explode(',',$id_arr); if(!$id_arr) { echo json_encode(array('msg'=>'参数错误!','success'=>false));exit; } //循环删除记录 foreach ($id_arr as $v) { $this->matching->remove($v); } echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true)); } } public function _list() { $post = $this->input->post(NULL, TRUE); if(isset($post['id'])) { $id = $this->input->post('id',true); $typeclass = $this->typeclass->find_all("classid = $id"); if($typeclass) { echo json_encode(array('data'=>$typeclass,'success'=>true));exit; } else { echo json_encode(array('msg'=>'没有找到数据!','success'=>false));exit; } } } }