| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373 | <?php defined('BASEPATH') OR exit('No direct script access allowed');header("Access-Control-Allow-Origin: *");class Amazonbarcode extends Start_Controller {	public function __construct(){		parent::__construct();		$this->load->_model('Model_amazonbarcode','amazonbarcode');		$this->load->_model('Model_excel','excel');	}	//定义方法的调用规则 获取URI第二段值    public function _remap($arg,$arg_array)    {		if($arg == 'addexcel')        {             $this->_addexcel();        }		else if($arg == 'print')        {             $this->_print();        }		else if($arg == 'usaprint')        {             $this->_usaprint();        }		else if($arg == 'see')        {             $this->_see();        }		else if($arg == 'edit')        {             $this->_edit($arg_array);        }		else if($arg == 'del')        {             $this->_del();        }		else		{			 $this->_index();		}    }		public function _see()	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['page']))  		{		    $page = $this->input->post('page',true);		    $perpage = $this->input->post('perpage',true);			$timetk = $this->input->post('timetk',true);			$timetj = $this->input->post('timetj',true);			$number = $this->input->post('number',true);			$label = $this->input->post('label',true);			$print = $this->input->post('print',true);			$xztime = $this->input->post('xztime',true);			$timetk = strtotime($timetk);			$timetj = strtotime($timetj);			$where = "1=1";			if($number)            {                $where  .= " and number = '$number'";            }			if($label)            {				$where  .= " and label = '$label'";            }			if($print != '')            {                $where  .= " and print = '$print'";            }			if($timetk && $timetj)            {                $where  .= " and ".$xztime." > '$timetk' and ".$xztime." < '$timetj'";            }            //数据排序            $order_str = $xztime." desc";            if(empty($page))		    {                $start = 0;		    	$perpage = 1;            }		    else		    {                $start = ($page - 1)*$perpage;            }			$info_list = $this->amazonbarcode->find_all($where,'id,number,label,label2,num,time,addtime',$order_str,$start,$perpage);            foreach ($info_list as $key=>$value) 		    {				if($value['time'] != 0)				{				    $info_list[$key]['time'] = date('Y-m-d H:i',$value['time']);				}				else				{					$info_list[$key]['time'] = '';				}				if($value['addtime'] != 0)				{				    $info_list[$key]['addtime'] = date('Y-m-d H:i',$value['addtime']);				}				else				{					$info_list[$key]['addtime'] = '';				}				$info_list[$key]['cz'] = "<span class='amazonbarprint' data-id='".$value['id']."' data-num='".$value['num']."'>国内</span><span style='margin-left:10px;background: #2ca8a1;' class='usaamazonbarprint' data-id='".$value['id']."' data-num='".$value['num']."'>美仓</span>";            }			$total = $this->amazonbarcode->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;		}		$this->_Template('amazonbarcode_see',$this->data);	}		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);			$timetk = $this->input->post('timetk',true);			$timetj = $this->input->post('timetj',true);			$number = $this->input->post('number',true);			$label = $this->input->post('label',true);			$print = $this->input->post('print',true);			$xztime = $this->input->post('xztime',true);			$timetk = strtotime($timetk);			$timetj = strtotime($timetj);			$where = "1=1";			if($number)            {                $where  .= " and number = '$number'";            }			if($label)            {				$where  .= " and label = '$label'";            }			if($print != '')            {                $where  .= " and print = '$print'";            }			if($timetk && $timetj)            {                $where  .= " and ".$xztime." > '$timetk' and ".$xztime." < '$timetj'";            }            //数据排序            $order_str = $xztime." desc";            if(empty($page))		    {                $start = 0;		    	$perpage = 1;            }		    else		    {                $start = ($page - 1)*$perpage;            }			$info_list = $this->amazonbarcode->find_all($where,'id,number,label,label2,num,time,addtime',$order_str,$start,$perpage);            foreach ($info_list as $key=>$value) 		    {				if($value['time'] != 0)				{				    $info_list[$key]['time'] = date('Y-m-d H:i',$value['time']);				}				else				{					$info_list[$key]['time'] = '';				}				if($value['addtime'] != 0)				{				    $info_list[$key]['addtime'] = date('Y-m-d H:i',$value['addtime']);				}				else				{					$info_list[$key]['addtime'] = '';				}            }			$total = $this->amazonbarcode->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;		}		$this->_Template('amazonbarcode',$this->data);	}		public function _edit($arg_array)	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['id']))		{			$id = $this->input->post('id',true);			$data = $this->amazonbarcode->read($id);			if($data['time'] != 0)			{				echo json_encode(array('msg'=>'此单已打印,无法修改!','success'=>false));exit;			}			if($this->amazonbarcode->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];		$amazonbarcode = $this->amazonbarcode->read($arg_array);		$this->data['amazonbarcode'] = $amazonbarcode;		$this->_Template('amazonbarcode_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) 		    {				$data = $this->amazonbarcode->read($v);				if($data['time'] != 0)				{					//echo json_encode(array('msg'=>$data['title'].'<br>已打印,无法删除!','success'=>false));exit;				}                $this->amazonbarcode->remove($v);            }            echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));		}    }		public function _print()	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['s']))  		{			$v = $this->input->post('s');			$va = explode(',',rtrim($v,','));			$n = $this->input->post('n');			$sl = $this->input->post('sl');			$text = array();$text['data'] = array();$time = time();			$data = $this->amazonbarcode->read($va[$n]);			$rows = array('number'=>$data['number'],'label'=>$data['label'],'label2'=>$data['label2'],'num'=>$sl,'data'=>$v,'n'=>$n-1);			if($this->amazonbarcode->save(array('print'=>1,'time'=>$time),$data['id']))        	{         		echo json_encode(array('rows'=>($rows),'success'=>true));exit;       	 	}       		else        	{	           		echo json_encode(array('msg'=>'数据写入异常,请重新打印!','success'=>false));exit;        	}		}	}		public function _usaprint()	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['s']))  		{			$v = $this->input->post('s');			$va = explode(',',rtrim($v,','));			$n = $this->input->post('n');			$sl = $this->input->post('sl');			$text = array();$text['data'] = array();$time = time();			$data = $this->amazonbarcode->read($va[$n]);			$rows = array('number'=>$data['number'],'usanumber'=>str_replace(array('#','*'),array('',''),$data['number']),'label'=>$data['label'],'label2'=>$data['label2'],'num'=>$sl,'data'=>$v,'n'=>$n-1);			if($this->amazonbarcode->save(array('print'=>1,'time'=>$time),$data['id']))        	{         		echo json_encode(array('rows'=>($rows),'success'=>true));exit;       	 	}       		else        	{	           		echo json_encode(array('msg'=>'数据写入异常,请重新打印!','success'=>false));exit;        	}		}	}		public function _addexcel()	{		$dir = '/data/excel/'.date('Ymd',time()).'/';		$config['upload_path'] = '.'.$dir ;		$config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);        $config['allowed_types'] = 'xls|xlsx|csv';        $config['max_size'] = 10240;		$this->load->library('upload', $config);		$this->upload->initialize($config);        if ($this->upload->do_upload('userfile'))        {			$full_path = $dir.$this->upload->data('file_name');			$fileName = '.' . $full_path;            if (!file_exists($fileName)) 			{				echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;            }			else			{				libxml_use_internal_errors(true);				require_once "./data/excel/PHPExcel/IOFactory.php";				$phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件				$phpExcel->setActiveSheetIndex(0);// 设置为默认表				$sheetCount = $phpExcel->getSheetCount();// 获取表格数量				$row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数				$column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数				++$column;//如果列数大于26行				$list = array();				for ($i = 3; $i <= $row; $i++) // 行数循环				{					$data = array();                    for ($c = 'A'; $c != $column; $c++)  // 列数循环	                {						$data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();                    }					$list[] = $data;                }			}			$i = 0;$j = 0;$ed = array();$time = time();		    foreach ($list as $key=>$value)		    {				$time = time();				if($value['0'] == "")				{					continue;				}				$post['number'] =  $value['0'];				$post['label'] =  ($value['1'])?$value['1']:'';				$post['label2'] =  ($value['2'])?$value['2']:'';				$post['num'] =  $value['3'];				$post['addtime'] =  $time;				if(!is_numeric($post['num']))				{					$ed[] = array($key.' 行,非数字!');					$j++;					continue;				}				if($post['num'] < 1)				{					$ed[] = array($key.' 行,数量错误!');					$j++;					continue;				}				$this->amazonbarcode->insert($post);			}			if($j > 0)			{				$tt = date('Ymd',time());				$title = '库存导入错误信息-'.$tt;        		$titlename = "<table border=1><tr><td>错误详情</td></tr></table>";				$tail = "\n";        		$filename = $title.".xls";        		$ecl = $this->excel->get_fz3($ed,$titlename,$filename,$tail);				$dir = '/data/excel/'.$time.'/';				$file_name = 'error_'.$time.rand(1000,9999);				if(!is_dir('.'.$dir))mkdir('.'.$dir,0777);				$myfile = fopen(".".$dir.$file_name.".xls", "w") or die();				fwrite($myfile,$ecl);				fclose($myfile);				$error = $dir.$file_name.'.xls';				echo json_encode(array('msg'=>'导入成功,'.$j.'条异常,','error'=>$error,'success'=>true));exit;			}			else			{				echo json_encode(array('msg'=>'导入成功!','error'=>1,'success'=>true));exit;			}		}	}}
 |