| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571 | <?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');		$this->load->_model('Model_amazonbarcodeitems','amazonbarcodeitems');			}	//定义方法的调用规则 获取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 if($arg == 'outpage'){			$this->_outPage();		}else if($arg == 'outcount'){			$this->_outCount($arg_array);		}		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);			$batch_no = $this->input->post('batch_no',true);			$timetk = strtotime($timetk);			$timetj = strtotime($timetj);			$where = "1=1";			if($batch_no)            {                $where  .= " and batch_no = '$batch_no'";            }			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,batch_no,number,label,label2,num,out_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]['out_num'] = $value['out_num']*1;				if(empty($value['batch_no'])){					$info_list[$key]['batch_no'] = '';				}else if($value['batch_no'] == 'null'){					$info_list[$key]['batch_no'] = '';				}            }			$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(strlen($post['number']) > 25){				echo json_encode(array('msg'=>'条码超出25位无法有效打印!','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]);			if(strlen($data['number']) > 25){				echo json_encode(array('msg'=>'打印条码超过25位,系统不支持!','success'=>false));exit;			}			$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();			$laster_info = $this->amazonbarcode->find("","","id desc");			$batch_no = date('Ymd',time());			if(empty($laster_info['batch_no'])){				$batch_no = date('Ymd',time()).'-001';			}else{				$tmp_arr = explode('-',$laster_info['batch_no']);				if($tmp_arr[0] == $batch_no){					$tmp_num = ($tmp_arr[1]*1)+1;					if($tmp_num < 10){						$batch_no = date('Ymd',time()).'-00'.$tmp_num;					}elseif($tmp_num < 100){						$batch_no = date('Ymd',time()).'-0'.$tmp_num;					}else{							$batch_no = date('Ymd',time()).'-'.$tmp_num;					}				}else{					$batch_no = date('Ymd',time()).'-001';				}			}		    foreach ($list as $key=>$value)		    {				$time = time();				if($value['0'] == "")				{					continue;				}				$post['batch_no'] = $batch_no;				$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(strlen($value['0']) > 25){					$ed[] = array($value['0']."--".$key.' 行,条码字符数不可超过25!');					$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;			}		}	}	//出库计数	public function _outPage(){		$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);			$batch_no = $this->input->post('batch_no',true);			$timetk = strtotime($timetk);			$timetj = strtotime($timetj);			$where = "1=1";			if($batch_no)            {                $where  .= " and batch_no = '$batch_no'";            }			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,batch_no,number,num,out_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]['out_num'] = $value['out_num']*1;				if(empty($value['batch_no'])){					$info_list[$key]['batch_no'] = '';				}else if($value['batch_no'] == 'null'){					$info_list[$key]['batch_no'] = '';				}            }			$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_count',$this->data);	}	public function _outCount($arg_array){		$post = $this->input->post(NULL, TRUE);		if(isset($post['id']))		{			if(!empty($post['id'])){				$info = $this->amazonbarcode->read($post['id']);				if(empty($info)){				 	echo	json_encode([						"code"=>0,						"msg"=>"请求数据不存在",						"data"=>['num'=>0],					]);					exit;				}				if(empty($info['time'])){					echo	json_encode([						"code"=>0,						"msg"=>"该标签未打印不能出库",						"data"=>['num'=>0],					]);					exit;				}				if($info['number'] != $post['number']){					echo	json_encode([						"code"=>0,						"msg"=>"条码异常计数失败,扫描条码【".$post['number']."】",						"data"=>['num'=>0],					]);					exit;				}				$info['out_num'] = $info['out_num']*1 +1;				$this->amazonbarcode->save(array('out_num'=>$info['out_num']),$post['id']);				$this->amazonbarcodeitems->insert([					'aid'=>(int)$post['id'],					'number'=>$info['number'],					'addtime'=>time()				]);				echo	json_encode([					"code"=>1,					"msg"=>"ok",					"data"=>['num'=>$info['out_num']],				]);				exit;			}else{									echo json_encode([						"code"=>0,						"msg"=>"请求参数有无",						"data"=>['num'=>0],					]);					exit;							}								}		$arg_array = $arg_array[0];		$amazonbarcode = $this->amazonbarcode->read($arg_array);		$this->data['info'] = $amazonbarcode;		$this->_Template('amazonbarcode_check',$this->data);	}	}
 |