123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428 |
- <?php defined('BASEPATH') OR exit('No direct script access allowed');
- class Systemwigs extends Start_Controller {
- public function __construct(){
- parent::__construct();
- $this->load->library('session');
- $this->load->_model('Model_systemwigs','systemwigs');
- $this->load->_model('Model_excel','excel');
- $this->load->_model('Model_shop','shop');
- $this->load->_model('Model_warehouse','warehouse');
- $this->load->_model('Model_fullorder','fullorder');
- $this->load->_model('Model_fullordertt','fullordertt');
- $this->load->_model('Model_fullordersmt','fullordersmt');
- $this->load->_model('Model_typeclass','typeclass');
- }
- //定义方法的调用规则 获取URI第二段值
- public function _remap($arg,$arg_array)
- {
- if($arg == 'data')
- {
- $this->_data();
- }
- else if($arg == 'out')
- {
- $this->_out();
- }
- else if($arg == 'del')
- {
- $this->_del();
- }
- else if($arg == 'add')
- {
- $this->_add();
- }
- else if($arg == 'excel')
- {
- $this->_excel();
- }
- else if($arg == 'barcode')
- {
- $this->_barcode($arg_array);
- }
- else if($arg == 'hb')
- {
- $this->_hb();
- }
- else
- {
- $this->_index();
- }
- }
-
- public function _index()
- {
- $this->_Template('systemwigs',$this->data);
- }
-
- public function _data()
- {
- $post = $this->input->post(NULL, TRUE);
- if(isset($post['page']))
- {
- $page = $this->input->post('page',true);
- $perpage = $this->input->post('perpage',true);
- $number = $this->input->post('number',true);
- $type = $this->input->post('type',true);
- $timetk = $this->input->post('timetk',true);
- $timetk = strtotime($timetk);
- $where = "type != 0";
- if($timetk)
- {
- $where .= " and gtime like '%".date('Ymd',$timetk)."%'";
- }
- if($type)
- {
- $where .= " and type = '$type'";
- }
- //数据排序
- $order_str = "id desc";
- if(empty($page))
- {
- $start = 0;
- $perpage = 1;
- }
- else
- {
- $start = ($page - 1)*$perpage;
- }
- //取得信息列表
- $info_list = $this->systemwigs->find_all($where,'id,number,shipremarks,outtime,num',$order_str,$start,$perpage);
- //格式化数据
- foreach ($info_list as $key=>$value)
- {
- $outtime = explode('|',trim($value['outtime'],'|'));
- $num = explode('|',trim($value['num'],'|'));
- $info_list[$key]['outtime'] = '';
- $info_list[$key]['num'] = '';
- foreach ($outtime as $v)
- {
- $info_list[$key]['outtime'] .= date('Y-m-d H:i:s',$v).'<br>';
- }
- foreach ($num as $v)
- {
- $info_list[$key]['num'] .= $v.'<br>';
- }
- $info_list[$key]['outtime'] = trim($info_list[$key]['outtime'],'<br>');
- $info_list[$key]['num'] = trim($info_list[$key]['num'],'<br>');
- }
- $total = $this->systemwigs->find_count($where);
- $pagenum = ceil($total/$perpage);
- $over = $total-($start+$perpage);
- $exdata = 0;
- $count = $this->systemwigs->find_all($where." and gtime like '%".date('Ymd',time())."%' ");
- foreach ($count as $v)
- {
- $gtime = explode('|',trim($v['gtime'],'|'));
- $num = explode('|',trim($v['num'],'|'));
- $gtime = array_flip($gtime);
- $exdata += $num[$gtime[date('Ymd',time())]];
- }
- $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'datacount'=>$exdata);
- echo json_encode($rows);exit;
- }
- }
-
- public function _out()
- {
- $post = $this->input->post(NULL, TRUE);
- if(isset($post['number']))
- {
- $number = $this->input->post('number',true);
- $type = $this->input->post('type',true);
- $time = time();
- if(!$number)
- {
- echo json_encode(array('msg'=>'未扫入数据!','success'=>false));exit;
- }
- if(!$type)
- {
- echo json_encode(array('msg'=>'请选择需要录入数据的仓库!','success'=>false));exit;
- }
- $nu = $this->fullorder->get_number($number);
- if(!$nu)
- {
- $nu = $this->fullordersmt->get_number($number);
- }
- if(!$nu)
- {
- echo json_encode(array('msg'=>'错误!未找到此编号的订单','success'=>false));exit;
- }
- $systemwigs = $this->systemwigs->get_num($number);
- if($systemwigs)
- {
- $gtime = explode('|',trim($systemwigs['gtime'],'|'));
- $gtime = array_flip($gtime);
- if(isset($gtime[date('Ymd',$time)]))
- {
- $num = explode('|',trim($systemwigs['num'],'|'));
- $num[$gtime[date('Ymd',$time)]] += 1;
- $num = '|'.implode('|',$num);
- if($this->systemwigs->save(array('num'=>$num),$systemwigs['id']))
- {
- echo json_encode(array('music'=>'1','success'=>true));exit;
- }
- else
- {
- echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
- }
- }
- else
- {
- if($this->systemwigs->save(array('num'=>'|1'.$systemwigs['num'],'gtime'=>'|'.date('Ymd',$time).$systemwigs['gtime'],'outtime'=>'|'.$time.$systemwigs['outtime']),$systemwigs['id']))
- {
- echo json_encode(array('music'=>'1','success'=>true));exit;
- }
- else
- {
- echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
- }
- }
- }
- else
- {
- if($this->systemwigs->insert(array('number'=>$number,'type'=>$type,'shipremarks'=>$nu['shipremarks'],'fpdata'=>$nu['fpdata'],'outtime'=>'|'.$time,'gtime'=>'|'.date('Ymd',$time),'num'=>'|1')))
- {
- echo json_encode(array('music'=>'1','success'=>true));exit;
- }
- else
- {
- echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
- }
- }
- }
- }
-
- public function _del()
- {
- $post = $this->input->post(NULL, TRUE);
- if(isset($post['delarr']))
- {
- $number = $this->input->post('number',true);
- $type = $this->input->post('type',true);
- $timetk = $this->input->post('timetk',true);
- $timetj = $this->input->post('timetj',true);
- $timetk = strtotime($timetk);
- $timetj = strtotime($timetj);
- $where = "type != 0";
- if(isset($_SESSION['api']))
- {
- if($type)
- {
- $where .= " and type = '$type'";
- }
- else
- {
- $uw = '';
- $u = $this->user->get_api($_SESSION['api']);
- $u['warehouse'] = explode('|',trim($u['warehouse'],'|'));
- foreach ($u['warehouse'] as $v)
- {
- $uw .= " type = '$v' or";
- }
- $uw = rtrim($uw,'or');
- $uw = " and (".ltrim($uw,' ').")";
- $where .= $uw;
- }
- }
- if($timetk && $timetj)
- {
- $where .= " and time > '$timetk' and time < '$timetj'";
- }
- if($number)
- {
- $where .= " and number = '$number'";
- }
- $id_arr = $this->input->post('delarr');
- $id_arr = explode(',',rtrim($id_arr,','));
- if(!$id_arr)
- {
- echo json_encode(array('msg'=>'未选择需要删除的内容!','success'=>false));exit;
- }
- //循环删除记录
- $a=0;
- foreach ($id_arr as $v)
- {
- if($this->systemwigs->remove($v))
- {
- $a++;
- }
-
- }
- if($a == count($id_arr))
- {
- $data = 0;
- $count = $this->systemwigs->find_all($where);
- foreach ($count as $v)
- {
- $data += $v['quantity'];
- }
- echo json_encode(array('del'=>$id_arr,'data'=>$data-$a,'msg'=>'删除成功!','success'=>true));
- }
- else
- {
- echo json_encode(array('del'=>$id_arr,'msg'=>'部分记录删除失败,请查询确认!','success'=>true));
- }
- }
- }
-
- public function _excel()
- {
- /* 匹配ID加入 */
- $tc = array();$ztc = array();$tclass = array();
- $typeclass = $this->typeclass->find_all();
- foreach ($typeclass as $v)
- {
- $ztc[$v['id']] = $v['zh'];
- $tc[$v['id']] = $v['title'];
- $tclass[$v['id']] = $v['classid'];
- }
-
- $timetk = $this->input->get('timetk',true);
- $timetk = strtotime($timetk);
- $dcdata = array();
- $list = $this->systemwigs->find_all("gtime like '%".date('Ymd',$timetk)."%'");
- foreach ($list as $key=>$value)
- {
- $thisnumber = $value;$thisshipremarks = array();
- if(stripos($thisnumber['fpdata'],';') !== false)
- {
- $fpdata = explode(';',rtrim($thisnumber['fpdata'],';'));
- foreach ($fpdata as $ke=>$va)
- {
- $title = '';
- $fg = explode('|',$va);
- $fg[0] = str_replace(array('163-','164-','165-','166-','-0-'),array('','','','','-'),$fg[0]);
- $cp = explode('-',rtrim($fg[0],'-'));
- if(isset($cp[5]))
- {
- $tt = $ztc[$cp[5]];
- }
- else
- {
- $tt = '';
- }
- $md = '';
- foreach ($cp as $v)
- {
- if(!isset($tclass[$v]))
- {
- continue;
- }
- if($tclass[$v] == '10')
- {
- $md = $tc[$v];
- }
- }
- if(isset($cp[4]))
- {
- $dchx = $tc[$cp[4]];
- }
- else
- {
- $dchx = ' ';
- }
- $thisshipremarks[] = array($tt,$tc[$cp[3]],$md,$dchx,$fg[5],$fg[2]);//头套种类,颜色,密度,花型,尺寸,数量
- }
- }
- $thisnumber['shipremarks'] = str_replace(array('<','>'),array('<','>'),$thisnumber['shipremarks']);
- $dcdata[] = array('number'=>$thisnumber['number'],'shipremarks'=>$thisnumber['shipremarks'],'fpdata'=>$thisshipremarks);
- }
- $title = date('Y-m-d H:i:s',time())." 产品详细信息";
- $titlename = "<table border=1>
- <tr><th colspan='29' align='left'><h3>".$title."<h3></th></tr>
- <tr>
- <td>订单编号</td>
- <td>仓库品名</td>
- <td>
- <table border=1>
- <tr><td colspan='4' align='center'>订单产品信息</td></tr>
- <tr>
- <td>种类</td>
- <td>颜色</td>
- <td>密度</td>
- <td>花型</td>
- <td>尺寸</td>
- <td>数量</td>
- </tr>
- </table>
- </td>
- <td>总条数</td>
- </tr>
- </table>";
- $filename = $title.".xls";
- $tail = "\n";
- $downexcel = $this->excel->get_fz($dcdata,$titlename,$filename,$tail);
- $time = date('Ymd',time());
- $dir = '/data/excel/'.$time.'/';
- $file_name = $title;
- if(!is_dir('.'.$dir))mkdir('.'.$dir,0777);
- $myfile = fopen(".".$dir.$file_name.".xls", "w") or die();
- fwrite($myfile,$downexcel);
- fclose($myfile);
- $goexcel = $dir.$file_name.'.xls';
- echo json_encode(array('msg'=>'操作成功 ','goexcel'=>$goexcel,'success'=>true));exit;
- }
-
- public function get_fz($info_list,$titlename,$filename,$tail)
- {
- $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">
- <head>
- <!--[if gte mso 9]><xml>
- <x:ExcelWorkbook>
- <x:ExcelWorksheets>
- <x:ExcelWorksheet>
- <x:Name>EXCEL</x:Name>
- <x:WorksheetOptions>
- <x:Print>
- <x:ValidPrinterInfo />
- </x:Print>
- </x:WorksheetOptions>
- </x:ExcelWorksheet>
- </x:ExcelWorksheets>
- </x:ExcelWorkbook>
- </xml>
- <![endif]-->
- </head><body>";
- $str .= $titlename;
- $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
- foreach ($info_list as $key=>$value)
- {
- if($value['fpdata'] == '')
- {
- continue;
- }
- $str .= "<tr>";
- foreach ($value as $ke=>$va)
- {
- if($ke == 'orderinfo' || $ke == 'waybill')
- {
- $str .= "<td align='left' style='vnd.ms-excel.numberformat:@'>".$va."</td>";
- }
- else if($ke != 'fpdata' && $ke != 'hl' && $ke != 'currencytitle')
- {
- $str .= "<td align='left'>".$va."</td>";
- }
- }
- $str .= "<td><table border=1>";
- $a = 0;
- foreach ($value['fpdata'] as $k=>$v)
- {
- $vd = '';
- foreach ($v as $vv)
- {
- $vd .= "<td>".$vv."</td>";
- }
- $str .= "<tr>".$vd."</tr>";
- $endv = is_numeric(end($v))?end($v):0;
- $a = $a + $endv;
- }
- $str .= "</table></td>";
- $str .= "<td>".$a."</td>";
- $str .= "</tr>\n";
- }
- $str .= $tail;
- $str .= "</table></body></html>";
- return $str;
- //return $str;
- }
- }
|