| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 | <?php defined('BASEPATH') OR exit('No direct script access allowed');class Matching extends Start_Controller {	public function __construct(){		parent::__construct();		$this->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;			}		}	}}
 |