123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652 |
- <?php defined('BASEPATH') OR exit('No direct script access allowed');
- class Whlabeltransport extends Start_Controller {
- public function __construct(){
- parent::__construct();
- $this->load->_model('Model_whlabel','whlabel');
- $this->load->_model('Model_warehouse','warehouse');
- $this->load->_model('Model_excel','excel');
- $this->load->_model('Model_whlabeltransport','whlabeltransport');
- }
- //定义方法的调用规则 获取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 == 'zj')//修改
- {
- $this->_zj();
- }
- else if($arg == 'list')//修改
- {
- $this->_list();
- }
- else if($arg == 'presetou')//修改
- {
- $this->_presetout($arg_array);
- }
- else if($arg == 'excel')
- {
- $this->_excel();
- }
- else if($arg == 'excelzh')
- {
- $this->_excelzh();//整合数据
- }
- 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);
- $warehouse = $this->input->post('warehouse',true);
- $sku = $this->input->post('sku',true);
- $text = $this->input->post('text',true);
- $cz = $this->input->post('cz',true);
- $xztime = $this->input->post('xztime',true);
- $timetk = $this->input->post('timetk',true);
- $timetj = $this->input->post('timetj',true);
- $timetk = strtotime($timetk);
- $timetj = strtotime($timetj);
- $where = "1=1 ";
- if($warehouse)
- {
- $where .= " and warehouse = '$warehouse'";
- }
- if($sku)
- {
- $where .= " and sku = '$sku'";
- }
- if($text)
- {
- $where .= " and text like '%$text%'";
- }
- if($cz != '')
- {
- $where .= " and cz = '$cz'";
- }
- 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->whlabeltransport->find_all($where,'id,warehouse,sku,title,num,enter,stime,time,text,cz',$order_str,$start,$perpage);
- foreach ($info_list as $key=>$value)
- {
- $warehouse = $this->warehouse->read($value['warehouse']);
- $info_list[$key]['warehouse'] = $warehouse['title'];
- $info_list[$key]['enter'] = date('Y-m-d H:i:s',$value['enter']);
- $info_list[$key]['stime'] = date('Y-m-d',$value['stime']);
- if($value['time'] > 0)
- {
- $info_list[$key]['time'] = date('Y-m-d H:i:s',$value['time']);
- }
- else
- {
- $info_list[$key]['time'] = "<p class='wc'><p>";
- }
- if($value['cz'] == '0')
- {
- $info_list[$key]['cz'] = "<p class='cz'><span class='ztwc' data-id='".$value['id']."'>点击完成</span><p>";
- }
- else if($value['cz'] == '1')
- {
- $info_list[$key]['cz'] = "<p class='cz'><font>已完成</font><p>";
- }
- }
- $total = $this->whlabeltransport->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('whlabeltransport',$this->data);
- }
- //添加
- public function _add()
- {
- $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 = 2; $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();
- foreach ($list as $key=>$value)
- {
- $time = time();
- if($value['0'] == "")
- {
- continue;
- }
- $warehouse = $this->warehouse->get_title($value['0']);
- //$d = $this->whlabel->get_sku($value['1']);//针对各个仓库
- $d = $this->whlabel->get_warehousesku(5,$value['1']);//针对各个仓库
- if($value['2'] =='' || $value['2'] < 1)
- {
- continue;
- }
- if(!$d)//如果没有这个SKU
- {
- $ed[] = array($value['1'].'-库存中不存在此SKU');
- $j++;
- continue;
- }
- if(!isset($warehouse['id']))
- {
- $ed[] = array($value['1'].'-仓库名错误!');
- $j++;
- continue;
- }
- if($value['3'] == '')
- {
- $ed[] = array($value['1'].'-没有填写预达日期!');
- $j++;
- continue;
- }
- $post['sku'] = $value['1'];
- $post['num'] = $value['2'];//数量
- $post['stime'] = strtotime($value['3']);//预计到达日期
- $post['text'] = $value['4'];//备注
- $post['enter'] = $time;//添加时间
- $post['shop'] = $d['shop'];
- $post['warehouse'] = $warehouse['id'];
- $post['purchase'] = $d['purchase'];
- $post['title'] = $d['title'];
- $post['number'] = $d['number'];
- $post['features'] = $d['features'];
- $post['retreatwarehouse'] = $d['retreatwarehouse'];
- $this->whlabeltransport->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 _edit($arg_array)
- {
- $post = $this->input->post(NULL, TRUE);
- if(isset($post['id']))
- {
- $id = $this->input->post('id',true);
- $data = $this->whlabeltransport->read($id);
- if($data['cz'] == '1')
- {
- echo json_encode(array('msg'=>'已完成的数据无法修改!','success'=>false));exit;
- }
- $post['num'] = $this->input->post('num',true);
- $post['text'] = $this->input->post('text',true);
- $stime = $this->input->post('stime',true);
- $post['stime'] = strtotime($stime);
- $post['edit'] = time();
- if($this->whlabeltransport->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];
- $whlabeltransport = $this->whlabeltransport->read($arg_array);
- $this->data['whlabeltransport'] = $whlabeltransport;
- $this->_Template('whlabeltransport_edit',$this->data);
- }
-
- public function _zj()
- {
- $post = $this->input->post(NULL, TRUE);
- if(isset($post['id']))
- {
- $id = $this->input->post('id',true);
- $data = $this->whlabeltransport->read($id);
- if($data['cz'] == '0')
- {
- $list = array();$num = "";$title = "";$features = "";
- $order = $this->input->post('order',true);
- $shop = $this->input->post('shop',true);
- $label['shop'] = $data['shop'];
- $label['sku'] = $data['sku'];
- $label['warehouse'] = $data['warehouse'];
- $label['purchase'] = $data['purchase'];
- $label['retreatwarehouse'] = $data['retreatwarehouse'];
- $label['state'] = 0;
- $time = time();
- $label['title'] = $data['title'];
- $label['number'] = $data['number'];
- $label['features'] = $data['features'];
- $label['enter'] = $time;
- $label['time'] = $time;//操作时间
- if($label['warehouse'] == '5')
- {
- $yza = $this->whlabel->find_all("sku = '".$label['sku']."' and warehouse = '".$label['warehouse']."'",'*','id desc');
- if($yza)
- {
- if($label['features'] != $yza[0]['features'])
- {
- echo json_encode(array('msg'=>'此SKU的产品信息和现有不一致!- 1','success'=>false));exit;
- }
- }
- /**
- $yzb = $this->whlabel->find_all("features = '".$label['features']."' and warehouse = '".$label['warehouse']."'",'*','id desc');
- if($yzb)
- {
- if($label['sku'] != $yzb[0]['sku'])
- {
- echo json_encode(array('msg'=>'此产品信息的SKU和现有不一致! - 2','success'=>false));exit;
- }
- }
- **/
- }
- $this->db->trans_begin();
- for($i=0;$i<$data['num'];$i++)
- {
- $label['label'] = time().rand(100,999).$i;//产品标签 辨别各个产品,暂不使用
- $label['cs'] = $id;//前期增加这个是在途库存添加的数据
- $label['rktype'] = 1;
- $this->whlabel->insert($label);
- }
- $this->whlabeltransport->save(array('time'=>$time,'cz'=>1),$data['id']);
- if ($this->db->trans_status() === TRUE)
- {
- $this->db->trans_commit();
- echo json_encode(array('msg'=>'入库成功!','id'=>$id,'time'=>date('Y-m-d H:i:s',$time),'success'=>true));exit;
- }
- else
- {
- $this->db->trans_rollback();
- echo json_encode(array('msg'=>'入库失败,请重试!','success'=>false));exit;
- }
- }
- else
- {
- echo json_encode(array('msg'=>'错误!已操作入库','success'=>false));exit;
- }
- }
- }
- //导出模板
- public function _presetout()
- {
- if(isset($_GET['excel']))
- {
- $where = "sku != 'Preset'";
- //数据排序
- $order_str = "id desc";
- if(empty($page))
- {
- $start = 0;
- $perpage = 1;
- }
- else
- {
- $start = ($page - 1)*$perpage;
- }
- $warehouse = $this->input->get('warehouse',true);
- if($warehouse)
- {
- $where .= " and warehouse = '".$warehouse."'";
- }
- //取得信息列表
- $info_list = $this->whlabel->find_pc($where,'warehouse,sku','*');
- $rows = array();$list = array();
- foreach ($info_list as $value)
- {
- $warehouse = $this->warehouse->read($value['warehouse']);
- $number = $value['number'];$ftime = time()-15*24*3600;
- $list[] = array($warehouse['title'],$value['sku'],'0','','');
- }
- $title = "在途模板";
- $titlename = "<table border=1>
- <tr align='center'>
- <td>仓库</td>
- <td>SKU</td>
- <td>数量</td>
- <td>预达日期(格式:2022-01-01)</td>
- <td>备注</td>
- </tr>
- </table>";
- $filename = $title.".xls";
- $tail = "";
- $this->excel->get_fz2($list,$titlename,$filename,$tail);
- }
- }
-
- public function _excel()
- {
- if(isset($_GET['excel']))
- {
- $warehouse = $this->input->get('warehouse',true);
- $sku = $this->input->get('sku',true);
- $cz = $this->input->get('cz',true);
- $text = $this->input->post('text',true);
- $xztime = $this->input->get('xztime',true);
- $timetk = $this->input->get('timetk',true);
- $timetj = $this->input->get('timetj',true);
- $timetk = strtotime($timetk);
- $timetj = strtotime($timetj);
- $where = "1=1 ";
- if($warehouse)
- {
- $where .= " and warehouse = '$warehouse'";
- }
- if($sku)
- {
- $where .= " and sku = '$sku'";
- }
- if($text)
- {
- $where .= " and text like '%$text%'";
- }
- if($cz != '')
- {
- $where .= " and cz = '$cz'";
- }
- if($timetk && $timetj)
- {
- $where .= " and ".$xztime." > '$timetk' and ".$xztime." < '$timetj'";
- }
- //数据排序
- $order_str = $xztime." desc";
- //取得信息列表
- $info_list = $this->whlabeltransport->find_all($where,'warehouse,sku,title,num,enter,stime,time,text');
- foreach ($info_list as $key=>$value)
- {
- $warehouse = $this->warehouse->read($value['warehouse']);
- $info_list[$key]['warehouse'] = $warehouse['title'];
- $info_list[$key]['enter'] = date('Y-m-d H:i:s',$value['enter']);
- $info_list[$key]['stime'] = date('Y-m-d',$value['stime']);
- if($value['time'] > 0)
- {
- $info_list[$key]['time'] = date('Y-m-d H:i:s',$value['time']);
- }
- else
- {
- $info_list[$key]['time'] = "<p class='wc'><p>";
- }
- }
- $title = "在途数据".date('Y-m-d',time());
- $titlename = "<table border=1>
- <tr align='center'>
- <td>仓库</td>
- <td>SKU</td>
- <td>名称</td>
- <td>数量</td>
- <td>添加日期</td>
- <td>预达日期</td>
- <td>完成日期</td>
- <td>备注</td>
- </tr>
- </table>";
- $filename = $title.".xls";
- $tail = "";
- $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
- }
- }
-
- public function _excelzh()
- {
- if(isset($_GET['excel']))
- {
- $warehouse = $this->input->get('warehouse',true);
- $sku = $this->input->get('sku',true);
- $cz = $this->input->get('cz',true);
- $text = $this->input->post('text',true);
- $xztime = $this->input->get('xztime',true);
- $timetk = $this->input->get('timetk',true);
- $timetj = $this->input->get('timetj',true);
- $timetk = strtotime($timetk);
- $timetj = strtotime($timetj);
- $where = "time = '0' ";
- if($warehouse)
- {
- $where .= " and warehouse = '$warehouse'";
- }
- if($sku)
- {
- $where .= " and sku = '$sku'";
- }
- if($text)
- {
- $where .= " and text like '%$text%'";
- }
- if($cz != '')
- {
- $where .= " and cz = '$cz'";
- }
- if($timetk && $timetj)
- {
- $where .= " and ".$xztime." > '$timetk' and ".$xztime." < '$timetj'";
- }
- //数据排序
- $order_str = $xztime." desc";
- //取得信息列表
- $zh = array();
- $info_list = $this->whlabeltransport->find_all($where,'warehouse,sku,title,num,features,enter,stime,text');
- foreach ($info_list as $v)
- {
- $c = $this->whlabel->find_count('state = 0 and warehouse = "'.$v['warehouse'].'" and features = "'.$v['features'].'"');
- $warehouse = $this->warehouse->read($v['warehouse']);
- $v['warehouse'] = $warehouse['title'];
- $v['enter'] = date('Y-m-d H:i:s',$v['enter']);
- $v['stime'] = date('Y-m-d',$v['stime']);
- if(isset($zh[$v['features']]))
- {
- $zh[$v['features']]['num'] += $v['num'];
- }
- else
- {
- $zh[$v['features']] = $v;
- }
- $zh[$v['features']]['features'] = $c;
- }
- $title = "在途数据".date('Y-m-d',time());
- $titlename = "<table border=1>
- <tr align='center'>
- <td>仓库</td>
- <td>SKU</td>
- <td>名称</td>
- <td>在途数量</td>
- <td>库存数量</td>
- <td>添加在途日期</td>
- <td>预达日期</td>
- <td>备注</td>
- </tr>
- </table>";
- $filename = $title.".xls";
- $tail = "";
- $this->excel->get_fz2($zh,$titlename,$filename,$tail);
- }
- }
-
- //批量完成
- public function _list()
- {
- $post = $this->input->post(NULL, TRUE);
- if(isset($post['s']))
- {
- $cw = '';$i = 0;
- $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)
- {
- $id = $v;
- $data = $this->whlabeltransport->read($id);
- if($data['cz'] == '0')
- {
- $list = array();$num = "";$title = "";$features = "";
- $order = $this->input->post('order',true);
- $shop = $this->input->post('shop',true);
- $label['shop'] = $data['shop'];
- $label['sku'] = $data['sku'];
- $label['warehouse'] = $data['warehouse'];
- $label['purchase'] = $data['purchase'];
- $label['retreatwarehouse'] = $data['retreatwarehouse'];
- $label['state'] = 0;
- $time = time();
- $label['title'] = $data['title'];
- $label['number'] = $data['number'];
- $label['features'] = $data['features'];
- $label['enter'] = $time;
- $label['time'] = $time;//操作时间
- if($label['warehouse'] == '5')
- {
- $yza = $this->whlabel->find_all("sku = '".$label['sku']."' and warehouse = '".$label['warehouse']."'");
- if($yza)
- {
- if($label['features'] != $yza[0]['features'])
- {
- echo json_encode(array('msg'=>'此SKU的产品信息和现有不一致!','success'=>false));exit;
- }
- }
- $yzb = $this->whlabel->find_all("features = '".$label['features']."' and warehouse = '".$label['warehouse']."'");
- if($yzb)
- {
- if($label['sku'] != $yzb[0]['sku'])
- {
- echo json_encode(array('msg'=>'此产品信息的SKU和现有不一致!','success'=>false));exit;
- }
- }
- }
- $this->db->trans_begin();
- for($i=0;$i<$data['num'];$i++)
- {
- $label['label'] = time().rand(100,999).$i;//产品标签 辨别各个产品,暂不使用
- $label['cs'] = 1;//前期增加这个是在途库存添加的数据
- $label['rktype'] = 1;
- $this->whlabel->insert($label);
- }
- $this->whlabeltransport->save(array('time'=>$time,'cz'=>1),$data['id']);
- if ($this->db->trans_status() === TRUE)
- {
- $this->db->trans_commit();
- $i++;
- }
- else
- {
- $this->db->trans_rollback();
- $cw .= $data['sku'].' | ';
- }
- }
- }
- if(count($id_arr) == $i)
- {
- echo json_encode(array('msg'=>'入库成功!','success'=>true));exit;
- }
- else
- {
- echo json_encode(array('msg'=>'有入库失败数据:'.$cw,'success'=>false));exit;
- }
- }
- }
-
- //删除
- 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->whlabeltransport->read($v);
- if($data['cz'] == '0')
- {
- $this->whlabeltransport->remove($v);
- }
- else
- {
- echo json_encode(array('msg'=>'有已完成数据!无法继续删除','success'=>false));exit;
- }
- }
- echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
- }
- }
- }
|