123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357 |
- <?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->helper('url');
- }
- //定义方法的调用规则 获取URI第二段值
- public function _remap($arg,$arg_array)
- {
- if($arg == 'out')
- {
- $this->_out();
- }
- 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)
- {
- 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,'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,'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_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->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_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);
- }
- }
|