load->library('session'); $this->load->_model('Model_whlabel','whlabel'); $this->load->_model('Model_warehouse','warehouse'); $this->load->_model('Model_excel','excel'); $this->load->_model('Model_fullorder','fullorder'); $this->load->_model('Model_fullordertt','fullordertt'); $this->load->_model('Model_fullordersmt','fullordersmt'); $this->load->_model('Model_outbound','outbound'); $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_kdniao','kdniao'); $this->load->_model('Model_notice','notice'); $this->load->_model('Model_dhl','dhl'); $this->load->_model('Model_usps','usps'); $this->load->_model('Model_fedex','fedex'); $this->load->_model('Model_ups','ups'); $this->load->_model('Model_ali','ali'); $this->load->_model('Model_dpd','dpd'); $this->load->_model('Model_shop','shop'); $this->load->_model('Model_user','user'); $this->load->_model('Model_whlabel','whlabel'); $this->load->_model('Model_specialstock','specialstock'); $this->load->_model('Model_fullorderxw','fullorderxw'); $this->load->helper('url'); } //定义方法的调用规则 获取URI第二段值 public function _remap($arg,$arg_array) { if($arg == 'out') { $this->_out(); } else if($arg == 'excel') { $this->_excel(); } else { $this->_index(); } } public function _out() { $post = $this->input->post(NULL, TRUE); if(isset($post['order'])) { $time = time(); $order = $this->input->post('order',true); if(substr($order,0,3) == '788' && substr($order,-4,4) == '0430')//Fedex联邦 { $order = substr($order,0,12); } $y = $this->fullorder->get_waybill($order); $fullorder_name = 'fullorder'; if(!$y) { $y = $this->fullorder->get_number($order); if(!$y) { $fullorder_name = 'fullordersmt'; $y = $this->fullordersmt->get_waybill($order); if(!$y) { $y = $this->fullordersmt->get_number($order); if(!$y) { if(!$y) { $fullorder_name = 'fullordertt'; $y = $this->fullordertt->get_waybill($order); if(!$y) { $y = $this->fullordertt->get_number($order); if(!$y) { $fullorder_name = 'fullorderxw'; $y = $this->fullorderxw->get_waybill($order); if(!$y) { $y = $this->fullorderxw->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; } $warehouse = $this->warehouse->read($y['type']); $this->db->trans_begin(); if($warehouse['zd'] == '1') { $wl = $this->whlabel->find_all("zd = '".$y['number']."'");//查找是否有占用库存情况 if($wl)//如果有那么清除所有占用 { foreach ($wl as $v) { $this->whlabel->save(array('state'=>0,'rktype'=>5,'zd'=>'','retreat'=>$time,'time'=>$time),$v['id']);//专属 } } } if(stripos($y['whlabel'],'z|') !== false) { $wl = $this->specialstock->find_all("zd = '".$y['number']."'"); if($wl)//如果有那么清除所有占用 { foreach ($wl as $v) { $this->specialstock->save(array('state'=>0,'rktype'=>5,'zd'=>'','retreat'=>$time,'time'=>$time),$v['id']); } } } $hbcfw = explode('|',trim($y['whlabel'],'|')); $hbcff = explode(';',trim($y['fpdata'],';')); $c = 0; $hbw = array(); $hbf = array(); for($i=0;$i$fullorder_name->save(array('whlabel'=>'|'.implode("|",$hbw).'|','fpdata'=>implode(";",$hbf).';'),$y['id']); $user = $this->user->get_api($_SESSION['api']); $this->$fullorder_name->save(array('library'=>3,'retreattime'=>$time,'retreatdata'=>$y['retreatdata'].'['.$user['userid'].':'.date('Y-m-d H:i:s',time()).':'.$this->input->ip_address().']-'),$y['id']); if ($this->db->trans_status() === FALSE) { $this->db->trans_commit(); echo json_encode(array('msg'=>'退库失败,请重试','success'=>false));exit; } else { $this->db->trans_commit(); echo json_encode(array('success'=>true));exit; } } } public function _index() { $post = $this->input->post(NULL, TRUE); if(isset($_SESSION['api'])) { $user = $this->user->get_api($_SESSION['api']); $usp = $user; $fgshop = "";$sid = "";$wid="";$wtype=""; $usersp = explode('|',trim($user['shop'],'|')); $userwh = explode('|',trim($user['warehouse'],'|')); foreach ($usersp as $value) { $fgshop .= " shop = ".$value." or"; $sid .= " id = ".$value." or"; } foreach ($userwh as $value) { $wid .= " id = ".$value." or"; $wtype .= " type = ".$value." or"; } } 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); $type = $this->input->post('type',true); $lowe = $this->input->post('lowe',true); $timetk = strtotime($timetk); $timetj = strtotime($timetj); $where = (isset($_SESSION['api']))?"library = 3 and (".rtrim($wtype,'or').")":"id= '0'"; 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'"; } if($type) { $where .= " and type = '$type'"; } if($lowe) { $where .= " and shipremarks like '%$lowe%'"; } //数据排序 $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,state,librarytime,retreattime,shipremarks',$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']; $info_list[$key]['librarytime'] = date('Y-m-d H:i',$value['librarytime']); if($value['retreattime'] == '0') { $info_list[$key]['retreattime'] = ''; } else { $info_list[$key]['retreattime'] = ''.date('Y-m-d H:i',$value['retreattime']).''; } $info_list[$key]['shipremarks'] = str_replace(array('<','>'),array('<','>'),$value['shipremarks']); } $info_listtt = $this->fullordertt->find_all($where,'id,shop,type,orderinfo,number,waybill,express,print,state,retreattime,shipremarks',$order_str,$start,$perpage); //格式化数据 foreach ($info_listtt as $key=>$value) { $shop = $this->shop->read($value['shop']); $info_listtt[$key]['shop'] = $shop['shopname']; if($value['waybill'] == 0) { $info_listtt[$key]['waybill'] = ""; } $express = $this->express->read($value['express']); $info_listtt[$key]['express'] = $express['servicename']; $warehouse = $this->warehouse->read($value['type']); $info_listtt[$key]['type'] = $warehouse['title']; $typeclass = $this->typeclass->read($value['state']); $info_listtt[$key]['state'] = $typeclass['spare']; if($value['print'] == 1) { $info_listtt[$key]['print'] = '不可打印'; } else if($value['print'] == 2) { $info_listtt[$key]['print'] = '未打印'; } else if($value['print'] == 3) { $info_listtt[$key]['print'] = '已打印'; } if($value['retreattime'] == '0') { $info_listtt[$key]['retreattime'] = ''; } else { $info_listtt[$key]['retreattime'] = ''.date('Y-m-d H:i:s',$value['retreattime']).''; } } $info_listxw = $this->fullorderxw->find_all($where,'id,shop,type,orderinfo,number,waybill,express,print,state,retreattime,shipremarks',$order_str,$start,$perpage); //格式化数据 foreach ($info_listxw as $key=>$value) { $shop = $this->shop->read($value['shop']); $info_listxw[$key]['shop'] = $shop['shopname']; if($value['waybill'] == 0) { $info_listxw[$key]['waybill'] = ""; } $express = $this->express->read($value['express']); $info_listxw[$key]['express'] = $express['servicename']; $warehouse = $this->warehouse->read($value['type']); $info_listxw[$key]['type'] = $warehouse['title']; $typeclass = $this->typeclass->read($value['state']); $info_listxw[$key]['state'] = $typeclass['spare']; if($value['print'] == 1) { $info_listxw[$key]['print'] = '不可打印'; } else if($value['print'] == 2) { $info_listxw[$key]['print'] = '未打印'; } else if($value['print'] == 3) { $info_listxw[$key]['print'] = '已打印'; } if($value['retreattime'] == '0') { $info_listxw[$key]['retreattime'] = ''; } else { $info_listxw[$key]['retreattime'] = ''.date('Y-m-d H:i:s',$value['retreattime']).''; } } $info_listsmt = $this->fullordersmt->find_all($where,'id,shop,type,orderinfo,number,waybill,express,print,state,retreattime,shipremarks',$order_str,$start,$perpage); //格式化数据 foreach ($info_listsmt as $key=>$value) { $shop = $this->shop->read($value['shop']); $info_listsmt[$key]['shop'] = $shop['shopname']; if($value['waybill'] == 0) { $info_listsmt[$key]['waybill'] = ""; } $express = $this->express->read($value['express']); $info_listsmt[$key]['express'] = $express['servicename']; $warehouse = $this->warehouse->read($value['type']); $info_listsmt[$key]['type'] = $warehouse['title']; $typeclass = $this->typeclass->read($value['state']); $info_listsmt[$key]['state'] = $typeclass['spare']; if($value['print'] == 1) { $info_listsmt[$key]['print'] = '不可打印'; } else if($value['print'] == 2) { $info_listsmt[$key]['print'] = '未打印'; } else if($value['print'] == 3) { $info_listsmt[$key]['print'] = '已打印'; } if($value['retreattime'] == '0') { $info_listsmt[$key]['retreattime'] = ''; } else { $info_listsmt[$key]['retreattime'] = ''.date('Y-m-d H:i:s',$value['retreattime']).''; } $info_listsmt[$key]['shipremarks'] = str_replace(array('<','>'),array('<','>'),$value['shipremarks']); } $total = $this->fullorder->find_count($where); $total += $this->fullordertt->find_count($where); $total += $this->fullorderxw->find_count($where); $total += $this->fullordersmt->find_count($where); $pagenum = ceil($total/$perpage); $over = $total-($start+$perpage); $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>(array_merge($info_list,$info_listtt,$info_listxw,$info_listsmt)));//$info_list_smt echo json_encode($rows);exit; } if(isset($_SESSION['api'])) { $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or')); $warehouse = $this->warehouse->find_all('1=1 and '.rtrim($wid,'or')); $this->data['wlshop'] = $wlshop; $this->data['warehouse'] = $warehouse; } $this->_Template('systemretreat',$this->data); } public function _excel() { $post = $this->input->get(NULL, TRUE); if(isset($_GET['excel'])) { if(isset($_SESSION['api'])) { $user = $this->user->get_api($_SESSION['api']); $usp = $user; $fgshop = "";$sid = "";$wid="";$wtype=""; $usersp = explode('|',trim($user['shop'],'|')); $userwh = explode('|',trim($user['warehouse'],'|')); foreach ($usersp as $value) { $fgshop .= " shop = ".$value." or"; $sid .= " id = ".$value." or"; } foreach ($userwh as $value) { $wid .= " id = ".$value." or"; $wtype .= " type = ".$value." or"; } } if(isset($post['page'])) { $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); $waybill = $this->input->get('waybill',true); $express = $this->input->get('express',true); $type = $this->input->get('type',true); $lowe = $this->input->get('lowe',true); $sdd = $this->input->get('sid',true); $timetk = strtotime($timetk); $timetj = strtotime($timetj); $where = (isset($_SESSION['api']))?"library = 3 and (".rtrim($wtype,'or').")":"id= '0'"; 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'"; } if($type) { $where .= " and type = '$type'"; } if($lowe) { $where .= " and shipremarks like '%$lowe%'"; } $sidwhere = ''; if($sdd) { $sd = ""; $s = explode(',',trim($sdd,',')); foreach ($s as $value) { $sd .= " id = ".$value." or"; } $sidwhere = " and (".rtrim($sd,'or').")"; } //数据排序 $order_str = "retreattime desc"; if(empty($page)) { $start = 0; $perpage = 1; } else { $start = ($page - 1)*$perpage; } //取得信息列表 $info_list = $this->fullorder->find_all($where.$sidwhere,'shop,type,orderinfo,number,waybill,express,state,librarytime,retreattime,shipremarks'); //格式化数据 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']; $info_list[$key]['librarytime'] = date('Y-m-d H:i',$value['librarytime']); if($value['retreattime'] == '0') { $info_list[$key]['retreattime'] = ''; } else { $info_list[$key]['retreattime'] = ''.date('Y-m-d H:i',$value['retreattime']).''; } $info_list[$key]['shipremarks'] = str_replace(array('<','>'),array('<','>'),$value['shipremarks']); } $info_listtt = $this->fullordertt->find_all($where.$sidwhere,'shop,type,orderinfo,number,waybill,express,state,librarytime,retreattime,shipremarks'); //格式化数据 foreach ($info_listtt as $key=>$value) { $shop = $this->shop->read($value['shop']); $info_listtt[$key]['shop'] = $shop['shopname']; if($value['waybill'] == 0) { $info_listtt[$key]['waybill'] = ""; } $express = $this->express->read($value['express']); $info_listtt[$key]['express'] = $express['servicename']; $warehouse = $this->warehouse->read($value['type']); $info_listtt[$key]['type'] = $warehouse['title']; $typeclass = $this->typeclass->read($value['state']); $info_listtt[$key]['state'] = $typeclass['spare']; $info_listtt[$key]['librarytime'] = date('Y-m-d H:i',$value['librarytime']); if($value['retreattime'] == '0') { $info_listtt[$key]['retreattime'] = ''; } else { $info_listtt[$key]['retreattime'] = ''.date('Y-m-d H:i:s',$value['retreattime']).''; } } $info_listxw = $this->fullorderxw->find_all($where.$sidwhere,'shop,type,orderinfo,number,waybill,express,state,librarytime,retreattime,shipremarks'); //格式化数据 foreach ($info_listxw as $key=>$value) { $shop = $this->shop->read($value['shop']); $info_listxw[$key]['shop'] = $shop['shopname']; if($value['waybill'] == 0) { $info_listxw[$key]['waybill'] = ""; } $express = $this->express->read($value['express']); $info_listxw[$key]['express'] = $express['servicename']; $warehouse = $this->warehouse->read($value['type']); $info_listxw[$key]['type'] = $warehouse['title']; $typeclass = $this->typeclass->read($value['state']); $info_listxw[$key]['state'] = $typeclass['spare']; $info_listxw[$key]['librarytime'] = date('Y-m-d H:i',$value['librarytime']); if($value['retreattime'] == '0') { $info_listxw[$key]['retreattime'] = ''; } else { $info_listxw[$key]['retreattime'] = ''.date('Y-m-d H:i:s',$value['retreattime']).''; } } $info_listsmt = $this->fullordersmt->find_all($where.$sidwhere,'shop,type,orderinfo,number,waybill,express,state,librarytime,retreattime,shipremarks'); //格式化数据 foreach ($info_listsmt as $key=>$value) { $shop = $this->shop->read($value['shop']); $info_listsmt[$key]['shop'] = $shop['shopname']; if($value['waybill'] == 0) { $info_listsmt[$key]['waybill'] = ""; } $express = $this->express->read($value['express']); $info_listsmt[$key]['express'] = $express['servicename']; $warehouse = $this->warehouse->read($value['type']); $info_listsmt[$key]['type'] = $warehouse['title']; $typeclass = $this->typeclass->read($value['state']); $info_listsmt[$key]['state'] = $typeclass['spare']; $info_listsmt[$key]['librarytime'] = date('Y-m-d H:i',$value['librarytime']); if($value['retreattime'] == '0') { $info_listsmt[$key]['retreattime'] = ''; } else { $info_listsmt[$key]['retreattime'] = ''.date('Y-m-d H:i:s',$value['retreattime']).''; } $info_listsmt[$key]['shipremarks'] = str_replace(array('<','>'),array('<','>'),$value['shipremarks']); } $rows = array_merge($info_list,$info_listtt,$info_listxw,$info_listsmt);//$info_list_smt $title = '订单退库-'.date('Y-m-d H-i-s',time()); $titlename = "
店铺名称 发货仓库 订单号 编号 运单号 快递公司 订单状态 出库时间 退库时间 仓库品名
"; $tail = "\n"; $filename = $title.".xls"; $this->excel->get_fz2(array_merge($info_list,$info_listsmt,$info_listtt,$info_listxw),$titlename,$filename,$tail); } } } }