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'] = "
已打印,无法删除!','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 = "
错误详情 |