load->library('session'); $this->load->_model('Model_whlabel','whlabel'); $this->load->_model('Model_warehouse','warehouse'); $this->load->_model('Model_productprice','productprice'); $this->load->_model('Model_excel','excel'); $this->load->_model('Model_fullorder','fullorder'); $this->load->_model('Model_fullordertt','fullordertt'); $this->load->_model('Model_express','express'); $this->load->_model('Model_shop','shop'); $this->load->_model('Model_typeclass','typeclass'); $this->load->_model('Model_country','country'); $this->load->_model('Model_warehouse','warehouse'); $this->load->_model('Model_kdniao','kdniao'); $this->load->_model('Model_notice','notice'); $this->load->_model('Model_dhl','dhl'); $this->load->_model('Model_shop','shop'); $this->load->_model('Model_user','user'); } //定义方法的调用规则 获取URI第二段值 public function _remap($arg,$arg_array) { if($arg == 'fout')//出库页 { $this->_fout(); } else if($arg == 'printing')//打印操作 { $this->_printing(); } else if($arg == 'print')//打印操作 { $this->_print(); } else if($arg == 'fhd')//发货单 { $this->_fhd($arg_array); } else if($arg == 'fhddata')//发货单 { $this->_fhddata(); } else if($arg == 'fpdata')//发货单 { $this->_fpdata(); } else if($arg == 'shop')//发货单 { $this->_shop(); } else if($arg == 'express')//发货单 { $this->_express(); } else if($arg == 'retreat')//发货单 { $this->_retreat(); } else if($arg == 'excel')//发货单 { $this->_excel(); } else { $this->_index(); } } //管理 public function _index() { $post = $this->input->post(NULL, TRUE); if(isset($post['userid'])) { $userid = $this->input->post('userid',true); $userpass = $this->input->post('userpass',true); $password = sha1($userpass); $user = $this->user->get_uid($userid); if($user) { if($user['type'] == 2) { echo json_encode(array('msg'=>"账户已停用",'success'=>false));exit; } if($user['userpass'] == $password) { $this->user->get_land($user); //更新登录数据 echo json_encode(array('url'=>'?id='.$user['api'],'success'=>true));exit; } else { echo json_encode(array('msg'=>"用户或密码不正确",'success'=>false));exit; } } else { echo json_encode(array('msg'=>"用户不正确",'success'=>false));exit; } } } //出库 public function _fout() { $post = $this->input->post(NULL, TRUE); if(isset($post['order'])) { $time = time(); $order = $this->input->post('order',true); $y = $this->fullorder->get_waybill($order); if(!$y) { $y = $this->fullorder->get_number($order); if(!$y) { echo json_encode(array('msg'=>'无此数据','success'=>false));exit; } } if($y['libraryconfirm'] == 1) { echo json_encode(array('msg'=>$y['librarynot'],'success'=>false));exit; } if($y['library'] == 2) { echo json_encode(array('msg'=>'此数据 '.date('Y-m-d H:i:s',$y['librarytime']).' 已操作','success'=>false));exit; } if($this->fullorder->save(array('library'=>2,'librarytime'=>$time),$y['id'])) { echo json_encode(array('success'=>true));exit; } else { echo json_encode(array('msg'=>'出库失败,请重试','success'=>false));exit; } } 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); $shop = $this->input->post('shop',true); $source = $this->input->post('source',true); $orderinfo = $this->input->post('orderinfo',true); $number = $this->input->post('number',true); $library = $this->input->post('library',true); $waybill = $this->input->post('waybill',true); $express = $this->input->post('express',true); $timetk = strtotime($timetk); $timetj = strtotime($timetj); $where = "library!=3 and libraryconfirm=2 and mergeid = 0 and print = 3"; if($timetk && $timetj && $library == 2) { $where .= " and librarytime > '$timetk' and librarytime < '$timetj'"; } if($shop) { $where .= " and shop = '$shop'"; } if($number) { $where .= " and number = '$number'"; } if($library) { $where .= " and library = '$library'"; } if($waybill) { $where .= " and waybill = '$waybill'"; } if($express) { $where .= " and express = '$express'"; } if($orderinfo) { $where .= " and orderinfo = '$orderinfo'"; } //数据排序 $order_str = "librarytime desc"; if(empty($page)) { $start = 0; $perpage = 1; } else { $start = ($page - 1)*$perpage; } //取得信息列表 $info_list = $this->fullorder->find_all($where,'id,shop,type,orderinfo,number,waybill,express,print,library,librarytime',$order_str,$start,$perpage); //格式化数据 foreach ($info_list as $key=>$value) { $shop = $this->shop->read($value['shop']); $info_list[$key]['shop'] = $shop['shopname']; if($value['waybill'] == 0) { $info_list[$key]['waybill'] = ""; } $express = $this->express->read($value['express']); $info_list[$key]['express'] = $express['servicename']; $warehouse = $this->warehouse->read($value['type']); $info_list[$key]['type'] = $warehouse['title']; if($value['print'] == 1) { $info_list[$key]['print'] = '不可打印'; } else if($value['print'] == 2) { $info_list[$key]['print'] = '未打印'; } else if($value['print'] == 3) { $info_list[$key]['print'] = '已打印'; } if($value['library'] == 1) { $info_list[$key]['library'] = '未出库'; } else if($value['library'] == 2) { $info_list[$key]['library'] = '已出库'; } else if($value['library'] == 3) { $info_list[$key]['library'] = '已退库'; } if($value['librarytime'] == '0') { $info_list[$key]['librarytime'] = ''; } else { $info_list[$key]['librarytime'] = ''.date('Y-m-d H:i:s',$value['librarytime']).''; } } $total = $this->fullorder->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->data['express'] = $this->express->find_all(); $this->_Template('whlabel_fout',$this->data); } //退库 public function _retreat() { $post = $this->input->post(NULL, TRUE); if(isset($post['order'])) { $time = time(); $order = $this->input->post('order',true); $y = $this->fullorder->get_waybill($order); if(!$y) { $y = $this->fullorder->get_number($order); if(!$y) { echo json_encode(array('msg'=>'无此数据','success'=>false));exit; } } if($y['library'] == 3) { echo json_encode(array('msg'=>'此数据 '.date('Y-m-d H:i:s',$y['retreattime']).' 已操作','success'=>false));exit; } if($y['library'] == 1) { echo json_encode(array('msg'=>'此数据未出库','success'=>false));exit; } if($this->fullorder->save(array('library'=>3,'retreattime'=>$time),$y['id'])) { echo json_encode(array('success'=>true));exit; } else { echo json_encode(array('msg'=>'退库失败,请重试','success'=>false));exit; } } 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); $shop = $this->input->post('shop',true); $source = $this->input->post('source',true); $orderinfo = $this->input->post('orderinfo',true); $number = $this->input->post('number',true); $waybill = $this->input->post('waybill',true); $express = $this->input->post('express',true); $timetk = strtotime($timetk); $timetj = strtotime($timetj); $where = "library=3 and gtime > 20190127"; if($timetk && $timetj) { $where .= " and retreattime > '$timetk' and retreattime < '$timetj'"; } if($shop) { $where .= " and shop = '$shop'"; } if($orderinfo) { $where .= " and orderinfo = '$orderinfo'"; } if($number) { $where .= " and number = '$number'"; } if($waybill) { $where .= " and waybill = '$waybill'"; } if($express) { $where .= " and express = '$express'"; } if($orderinfo) { $where .= " and orderinfo = '$orderinfo'"; } //数据排序 $order_str = "retreattime desc"; if(empty($page)) { $start = 0; $perpage = 1; } else { $start = ($page - 1)*$perpage; } //取得信息列表 $info_list = $this->fullorder->find_all($where,'id,shop,type,orderinfo,number,waybill,express,print,state,retreattime',$order_str,$start,$perpage); //格式化数据 foreach ($info_list as $key=>$value) { $shop = $this->shop->read($value['shop']); $info_list[$key]['shop'] = $shop['shopname']; if($value['waybill'] == 0) { $info_list[$key]['waybill'] = ""; } $express = $this->express->read($value['express']); $info_list[$key]['express'] = $express['servicename']; $warehouse = $this->warehouse->read($value['type']); $info_list[$key]['type'] = $warehouse['title']; $typeclass = $this->typeclass->read($value['state']); $info_list[$key]['state'] = $typeclass['spare']; if($value['print'] == 1) { $info_list[$key]['print'] = '不可打印'; } else if($value['print'] == 2) { $info_list[$key]['print'] = '未打印'; } else if($value['print'] == 3) { $info_list[$key]['print'] = '已打印'; } if($value['retreattime'] == '0') { $info_list[$key]['retreattime'] = ''; } else { $info_list[$key]['retreattime'] = ''.date('Y-m-d H:i:s',$value['retreattime']).''; } } $total = $this->fullorder->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->data['express'] = $this->express->find_all(); $this->_Template('whlabel_fout',$this->data); } //打印页面 public function _print() { $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); $shop = $this->input->post('shop',true); $print = $this->input->post('print',true); $express = $this->input->post('express',true); $waybill = $this->input->post('waybill',true); $printtype = $this->input->post('printtype',true); $orderinfo = $this->input->post('orderinfo',true); $number = $this->input->post('number',true); $timetk = strtotime($timetk); $timetj = strtotime($timetj); $where = "type = 1 and express != 0 and printtype > 0 and printtype < 3 and print != 1 and review > 4"; if($timetk && $timetj && $print == 3) { $where .= " and printtime > '$timetk' and printtime < '$timetj'"; } if($shop) { $where .= " and shop = '$shop'"; } if($print) { if($print == 2) { $where .= " and state = 207 and print = '$print'"; } else { $where .= " and print = '$print'"; } } if($express) { $where .= " and express = '$express'"; } if($printtype) { $where .= " and printtype = '$printtype'"; } if($orderinfo) { $where .= " and orderinfo = '$orderinfo'"; } if($number) { $where .= " and number = '$number'"; } if($waybill) { $where .= " and waybill = '$waybill'"; } //数据排序 $order_str = "id desc"; if(empty($page)) { $start = 0; $perpage = 1; } else { $start = ($page - 1)*$perpage; } //取得信息列表 $info_list = $this->fullorder->find_all($where,'id,shop,orderinfo,number,express,waybill,print,printtype,printnumber,printtime',$order_str,$start,$perpage); //格式化数据 foreach ($info_list as $key=>$value) { $shop = $this->shop->read($value['shop']); $info_list[$key]['shop'] = $shop['shopname']; $express = $this->express->read($value['express']); if($express) { $info_list[$key]['express'] = $express['servicename']; } else { $info_list[$key]['express'] = '未选择'; } if($value['printtime'] != 0) { $info_list[$key]['printtime'] = date('Y-m-d H:i:s',$value['printtime']); } else { $info_list[$key]['printtime'] = '无'; } if($value['print'] == 1) { $info_list[$key]['print'] = "禁止打印"; } else if($value['print'] == 2) { $info_list[$key]['print'] = "未打印"; } else if($value['print'] == 3) { $info_list[$key]['print'] = "已打印"; } if($value['printtype'] == 1) { $info_list[$key]['printtype'] = "运单"; } else if($value['printtype'] == 2) { $info_list[$key]['printtype'] = "发货单"; } else if($value['printtype'] == 0) { $info_list[$key]['printtype'] = "未选择"; } } $total = $this->fullorder->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('whlabel_print',$this->data); } //打印 public function _printing() { $post = $this->input->post(NULL, TRUE); $dhlover = 1; if(isset($post['s'])) { $v = $this->input->post('s'); $va = explode(',',rtrim($v,',')); $n = $this->input->post('n'); $fullorder = $this->fullorder->read($va[$n]); $exp = $this->express->read($fullorder['express']);//获取快递信息 if($fullorder['printtype'] == 1) { //获取所用相关信息 $warehouse = $this->warehouse->read($fullorder['type']); $al = $this->country->read($warehouse['country']); foreach ($warehouse as $kk=>$vv) { $warehouse['al'] = $al['lb']; } $fullorder['baddress'] = explode(',',$fullorder['baddress']); $fullorder['baddress'] = array_reverse($fullorder['baddress']); $country = $this->country->get_al($fullorder['baddress'][1]); $fullorder['baddress'][1] = $country['ename']; $fcountry = $this->country->read($warehouse['country']); $warehouse['country'] = $fcountry['ename']; $fullorder['warehouse'] = $warehouse; $fullorder['al'] = $country['lb'];//收货加改联邦名 此项过完春节口可以去掉,之前订单同步没添加此项 $fullorder['country'] = $country['ename']; //获取完毕 if($exp['servicecode'] == "DHLGF")//如果打印过那么重新获取运单 { $barcode = $this->dhl->get_data($fullorder);//获取DHL快递信息 if(isset($barcode['AirwayBillNumber'])) { $Hwaybill = $barcode['AirwayBillNumber']; $Hfp = $this->_pdf($barcode['LabelImage']['MultiLabels']['MultiLabel']['DocImageVal'],'f'.$Hwaybill); $Hyd = $this->_pdf($barcode['LabelImage']['OutputImage'],'y'.$Hwaybill); } else if(isset($barcode['Response']['Status']['Condition']['ConditionData'])) { $dhlover = $barcode['Response']['Status']['Condition']['ConditionData']; } else if(isset($barcode['Response']['Status']['Condition'][0]['ConditionData'])) { $dhlover = $barcode['Response']['Status']['Condition'][0]['ConditionData']; } else { $dhlover = "错误!"; } } if(isset($Hfp) && isset($Hyd) && isset($Hwaybill)) { if($this->fullorder->save(array('waybill'=>$Hwaybill,'fp'=>$Hfp,'yd'=>$Hyd,'libraryconfirm'=>2,'librarynot'=>'','printtime'=>time(),'printnumber'=>$fullorder['printnumber']+1,'print'=>3),$va[$n])) { $rows = array('type'=>1,'t'=>11000,'n'=>$n-1,'data'=>$v,'rows'=>array('1'=>$Hfp,'0'=>$Hyd,'2'=>$va[$n])); } } } else if($fullorder['printtype'] == 2) { if($this->fullorder->save(array('libraryconfirm'=>2,'librarynot'=>'','printtime'=>time(),'printnumber'=>$fullorder['printnumber']+1,'print'=>3),$va[$n])) { $country = $this->country->read($fullorder['country']); $rows = array('type'=>2,'fhd'=>$va[$n],'t'=>3000,'n'=>$n-1,'data'=>$v); } } if(isset($rows)) { echo json_encode(array('rows'=>($rows),'success'=>true));exit; } else { if($dhlover != 1) { echo json_encode(array('msg'=>"订单号:".$fullorder['orderinfo']." - ".$dhlover,'success'=>false));exit; } else { echo json_encode(array('msg'=>"订单号:".$fullorder['orderinfo']."打印类型错误!请跳过!",'success'=>false));exit; } } } } public function _excel() { if(isset($_GET['fexcel'])) { $dowid = $this->input->get('a'); $wid = ""; if($dowid != "") { $id_arr = explode(',',rtrim($dowid,',')); foreach ($id_arr as $v) { $wid .= " id = 0 or"; $wid .= " id = '$v' or"; } $wid = " and".rtrim($wid,'or'); } $t = $this->input->get('t',true); $timetk = $this->input->get('timetk',true); $timetj = $this->input->get('timetj',true); $shop = $this->input->get('shop',true); $source = $this->input->get('source',true); $orderinfo = $this->input->get('orderinfo',true); $number = $this->input->get('number',true); $library = $this->input->get('library',true); $waybill = $this->input->get('waybill',true); $express = $this->input->get('express',true); $timetk = strtotime($timetk); $timetj = strtotime($timetj); $where = "library!=3 and libraryconfirm=2 and mergeid = 0 and print = 3"; if($timetk && $timetj && $library == 2) { $where .= " and librarytime > '$timetk' and librarytime < '$timetj'"; } if($shop) { $where .= " and shop = '$shop'"; } if($number) { $where .= " and number = '$number'"; } if($library) { $where .= " and library = '$library'"; } if($waybill) { $where .= " and waybill = '$waybill'"; } if($express) { $where .= " and express = '$express'"; } if($orderinfo) { $where .= " and orderinfo = '$orderinfo'"; } //数据排序 $order_str = "librarytime desc"; if(empty($page)) { $start = 0; $perpage = 1; } else { $start = ($page - 1)*$perpage; } //取得信息列表 $info_list = $this->fullorder->find_all($where.$wid,'shop,type,orderinfo,number,waybill,express,print,library,librarytime',$order_str); //格式化数据 foreach ($info_list as $key=>$value) { $shop = $this->shop->read($value['shop']); $info_list[$key]['shop'] = $shop['shopname']; if($value['waybill'] == 0) { $info_list[$key]['waybill'] = ""; } $express = $this->express->read($value['express']); $info_list[$key]['express'] = $express['servicename']; $warehouse = $this->warehouse->read($value['type']); $info_list[$key]['type'] = $warehouse['title']; if($value['print'] == 1) { $info_list[$key]['print'] = '不可打印'; } else if($value['print'] == 2) { $info_list[$key]['print'] = '未打印'; } else if($value['print'] == 3) { $info_list[$key]['print'] = '已打印'; } if($value['library'] == 1) { $info_list[$key]['library'] = '未出库'; } else if($value['library'] == 2) { $info_list[$key]['library'] = '已出库'; } else if($value['library'] == 3) { $info_list[$key]['library'] = '已退库'; } if($value['librarytime'] == '0') { $info_list[$key]['librarytime'] = ''; } else { $info_list[$key]['librarytime'] = ''.date('Y-m-d H:i:s',$value['librarytime']).''; } } $title = '订单出库-'.date('Ymd',time()); $titlename = "