123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643 |
- <?php defined('BASEPATH') OR exit('No direct script access allowed');
- header("Access-Control-Allow-Origin: *");
- class Systemretreat extends Start_Controller {
- public function __construct(){
- parent::__construct();
- $this->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<count($hbcfw);$i++)
- {
- $w = explode('-',$hbcfw[$i]);
- $f = explode('|',$hbcff[$i]);
- $f[9] = 0;
- $w[2] = 0;
- $hbw[] = implode("-",$w);
- $hbf[] = implode("|",$f);
- }
- $this->$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'] = '<em class="t"></em>';
- }
- else
- {
- $info_list[$key]['retreattime'] = '<em class="t">'.date('Y-m-d H:i',$value['retreattime']).'</em>';
- }
- $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'] = '<em class="t"></em>';
- }
- else
- {
- $info_listtt[$key]['retreattime'] = '<em class="t">'.date('Y-m-d H:i:s',$value['retreattime']).'</em>';
- }
-
- }
- $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'] = '<em class="t"></em>';
- }
- else
- {
- $info_listxw[$key]['retreattime'] = '<em class="t">'.date('Y-m-d H:i:s',$value['retreattime']).'</em>';
- }
-
- }
- $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'] = '<em class="t"></em>';
- }
- else
- {
- $info_listsmt[$key]['retreattime'] = '<em class="t">'.date('Y-m-d H:i:s',$value['retreattime']).'</em>';
- }
- $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'] = '<em class="t"></em>';
- }
- else
- {
- $info_list[$key]['retreattime'] = '<em class="t">'.date('Y-m-d H:i',$value['retreattime']).'</em>';
- }
- $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'] = '<em class="t"></em>';
- }
- else
- {
- $info_listtt[$key]['retreattime'] = '<em class="t">'.date('Y-m-d H:i:s',$value['retreattime']).'</em>';
- }
-
- }
- $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'] = '<em class="t"></em>';
- }
- else
- {
- $info_listxw[$key]['retreattime'] = '<em class="t">'.date('Y-m-d H:i:s',$value['retreattime']).'</em>';
- }
-
- }
- $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'] = '<em class="t"></em>';
- }
- else
- {
- $info_listsmt[$key]['retreattime'] = '<em class="t">'.date('Y-m-d H:i:s',$value['retreattime']).'</em>';
- }
- $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 = "<table border=1>
- <tr align='center'>
- <td>店铺名称</td>
- <td>发货仓库</td>
- <td>订单号</td>
- <td>编号</td>
- <td>运单号</td>
- <td>快递公司</td>
- <td>订单状态</td>
- <td>出库时间</td>
- <td>退库时间</td>
- <td>仓库品名</td>
- </tr>
- </table>";
- $tail = "\n";
- $filename = $title.".xls";
- $this->excel->get_fz2(array_merge($info_list,$info_listsmt,$info_listtt,$info_listxw),$titlename,$filename,$tail);
- }
-
- }
- }
- }
|