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_fullorder_smt','fullorder_smt');
$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_fedex_cby','fedex_cby');
$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->helper('url');
}
//定义方法的调用规则 获取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 == 'outbound')//打印操作
{
$this->_outbound($arg_array);
}
else if($arg == 'fedex')//联邦打印页面
{
$this->_fedex($arg_array);
}
else if($arg == 'fhdusa')//打印操作
{
$this->_fhdusa($arg_array);
}
else if($arg == 'shop')
{
$this->_shop();
}
else if($arg == 'lowe')
{
$this->_lowe();
}
else if($arg == 'warehouse')
{
$this->_warehouse();
}
else if($arg == 'express')
{
$this->_express();
}
else if($arg == 'select')
{
$this->_select();
}
else if($arg == 'retreat')
{
$this->_retreat();
}
else if($arg == 'excel')
{
$this->_excel();
}
else if($arg == 'exceldy')
{
$this->_exceldy();
}
else if($arg == 'number')//扫描发货单打印运单
{
$this->_number();
}
else if($arg == 'fedexhz')//扫描发货单打印运单
{
$this->_fedexhz();
}
else if($arg == 'cpexcel')
{
$this->_cpexcel();
}
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,'dlz');
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'],'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);
$weight = $this->input->post('weight',true);
if(!isset($weight))//测试没问题后可以删
{
$weight = '';
}
if(substr($order,0,3) == '788' && substr($order,-4,4) == '0430')//Fedex联邦
{
$order = substr($order,0,12);
}
if(strlen($order) == '34')//联邦杭州超长运单截取
{
$order = substr($order,22,12);
}
if(!$order)
{
echo json_encode(array('msg'=>'出库信息无能为空!','success'=>false));exit;
}
$fullorder_name = 'fullorder';$outtype = 1;
$y = $this->fullorder->get_waybill($order);
if(!$y)
{
$y = $this->fullorder->get_number($order);
$outtype = 2;
if(!$y)
{
$fullorder_name = 'fullordersmt';$outtype = 1;
$y = $this->fullordersmt->get_waybill($order);
if(!$y)
{
$y = $this->fullordersmt->get_number($order);
$outtype = 2;
if(!$y)
{
echo json_encode(array('msg'=>'无此数据','success'=>false));exit;
/**
$fullorder_name = 'fullorder_smt';
$y = $this->fullorder_smt->get_waybill($order);
if(!$y)
{
$y = $this->fullorder_smt->get_number($order);
if(!$y)
{
echo json_encode(array('msg'=>'无此数据','success'=>false));exit;
}
}
**/
}
}
}
}
if($y['mergeid'] == '1')
{
$y = $this->$fullorder_name->read($y['merge']);
}
$express = $this->express->read($y['express']);
if($y['state'] == 216 && $fullorder_name == 'fullordersmt')
{
$y['librarynot'] = '客户已取消!';
}
if($y['print'] != 3 || $y['libraryconfirm'] == 1 || $y['state'] == 214 || $y['state'] == 217 || $y['state'] == 283 || $y['state'] == 206 || $y['state'] == 205 || $y['state'] == 204 || $y['state'] == 210 || $y['state'] == 211 || $y['state'] == 212 || ($y['state'] == 216 && $fullorder_name == 'fullordersmt'))//独立站216先关了
{
echo json_encode(array('msg'=>$y['librarynot'],'success'=>false));exit;
}
if($y['library'] > 1)
{
echo json_encode(array('msg'=>'此数据 '.date('Y-m-d H:i:s',$y['librarytime']).' 已操作','success'=>false));exit;
}
if($express['out'] != 3)
{
if($express['out'] != $outtype)
{
$smlx = ($express['out']=='1')?'运单':'发货单';
echo json_encode(array('msg'=>'扫描类型错误!此单需要扫描'.$smlx,'success'=>false));exit;
}
}
if($y['express'] == '9999999')//if($y['express'] == '24' || $y['express'] == '3')
{
$numweight = str_replace('kg','',$weight);
if($weight == '' || $numweight < '0.1')
{
echo json_encode(array('msg'=>'此单需要称重!','success'=>false));exit;
}
}
if(((time() - $y['printtime']) > (15*24*3600) || $y['printtime'] < 1590211800) && $y['express'] == '24')
{
echo json_encode(array('yd'=>1,'id'=>$y['id'],'express'=>$y['express'],'name'=>$fullorder_name,'success'=>true));exit;
}
if((time() - $y['printtime']) > (3*24*3600) && $y['express'] == '3')
{
echo json_encode(array('yd'=>1,'id'=>$y['id'],'express'=>$y['express'],'name'=>$fullorder_name,'success'=>true));exit;
}
$warehouse = $this->warehouse->read($y['type']);
if($warehouse['zd'] == '1')
{
$whlabel = $this->whlabel->find_all("zd = '".$y['number']."' and warehouse = '".$y['type']."' and (state = '0' or state = '9')");
$cpsl = 0;
$pp = explode('|',trim($y['whlabel'],'|'));
foreach ($pp as $va)
{
$num = explode('-',$va);
$cpsl += $num[1];
}
if(count($whlabel) < 1 && $warehouse['ys'] != 1)//以后吧 && $warehouse['ys'] != 1去掉 前期防止没占用的不能出
{
echo json_encode(array('msg'=>'此订单未占用库存','success'=>false));exit;
}
else if(count($whlabel) != $cpsl && $warehouse['ys'] != 1)//以后吧 && $warehouse['ys'] != 1去掉 前期防止没占用的不能出
{
echo json_encode(array('msg'=>'库存占用量与实际出库量不符','success'=>false));exit;
}
else
{
foreach ($whlabel as $v)
{
$this->whlabel->save(array('state'=>1,'orderinfo'=>$y['orderinfo'],'waybill'=>$y['waybill'],'outk'=>$time,'time'=>$time),$v['id']);
}
}
/**
$ckcg = 0;$save = array();
$pp = explode('|',trim($y['whlabel'],'|'));
foreach ($pp as $va)
{
$uid = array();//储存可用出库产品的ID
$num = explode('-',$va);
$shopwhlabel = $this->whlabel->find_all("state = 0 and number = '$num[0]' and warehouse = '".$y['type']."' and shop !='' and shop like '%,".$y['shop'].",%'");
$whlabel = $this->whlabel->find_all("state = 0 and number = '$num[0]' and warehouse = '".$y['type']."' and (shop IS NULL or shop = '')");
if($shopwhlabel)
{
if(count($shopwhlabel) >= $num[1])//如果专用的条数大于需求
{
for($i=0;$i<$num[1];$i++)
{
$uid[] = $shopwhlabel[$i]['id'];
}
$save[] = $uid;
}
else if(count($shopwhlabel) < $num[1] && count($whlabel) >= $num[1])//如果专用的条数小于需求,但专用的条数+通用的条数大于等于需求,判断为可用,有限扣减专用数
{
for($x=0;$x<$num[1];$x++)
{
$uid[] = $whlabel[$x]['id'];
}
$save[] = $uid;
}
else
{
$ckcg++;
}
}
else if(!$whlabel || count($whlabel) < $num[1])
{
$ckcg++;
}
else
{
for($i=0;$i<$num[1];$i++)
{
$uid[] = $whlabel[$i]['id'];
}
$save[] = $uid;
}
}
if($ckcg > 0)
{
echo json_encode(array('msg'=>'无法匹配库存或库存为0','success'=>false));exit;
}
else
{
foreach ($save as $vb)
{
foreach ($vb as $vc)
{
$this->whlabel->save(array('state'=>1,'orderinfo'=>$y['orderinfo'],'waybill'=>$y['waybill'],'outk'=>$time,'time'=>$time),$vc);
}
}
}
**/
}
if($fullorder_name == 'fullordersmt')
{
$stt = ($y['waybill']!='')?209:$y['state'];
if($this->$fullorder_name->save(array('library'=>2,'state'=>$stt,'librarytime'=>$time,'weight'=>$weight),$y['id']))
{
echo json_encode(array('success'=>true));exit;
}
else
{
echo json_encode(array('msg'=>'出库失败,请重试','success'=>false));exit;
}
}
else
{
if($this->$fullorder_name->save(array('library'=>2,'librarytime'=>$time,'weight'=>$weight),$y['id']))
{
echo json_encode(array('success'=>true));exit;
}
else
{
echo json_encode(array('msg'=>'出库失败,请重试','success'=>false));exit;
}
}
}
if(isset($post['page']))
{
$api = $this->input->post('api',true);
if(isset($api))
{
$user = $this->user->get_api($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";
}
}
$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);
$type = $this->input->post('type',true);
$lowe = $this->input->post('lowe',true);
$so = $this->input->post('so',true);
$librarytime = $this->input->post('librarytime',true);
$timetk = strtotime($timetk);
$timetj = strtotime($timetj);
$cxtime = 'id';
$where = (isset($_SESSION['api']) || $api)?"library!=3 and libraryconfirm=2 and mergeid = 0 and print = 3 and (".rtrim($wtype,'or').")":"library!=3 and libraryconfirm=2 and mergeid = 0 and print = 3";
if($timetk && $timetj && $library == 2 && $librarytime != 1)
{
$cxtime = 'reviewtime';
$where .= " and librarytime > '$timetk' and librarytime < '$timetj'";
}
else if($timetk && $timetj && $library == 2 && $librarytime == 1)
{
$cxtime = 'librarytime';
$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'";
}
if($type)
{
$where .= " and type = '$type'";
}
if($lowe)
{
$where .= " and shipremarks like '%$lowe%'";
}
if($so)
{
$where .= " and shipremarks like '%$so%'";
}
//数据排序
$order_str = $cxtime." 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,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'];
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']).'';
}
}
$info_list_smt = $this->fullorder_smt->find_all($where,'id,shop,type,orderinfo,number,waybill,express,print,library,librarytime,shipremarks',$order_str,$start,$perpage);
//格式化数据
foreach ($info_list_smt as $key=>$value)
{
$shop = $this->shop->read($value['shop']);
$info_list_smt[$key]['shop'] = $shop['shopname'];
if($value['waybill'] == '0')
{
$info_list_smt[$key]['waybill'] = "";
}
$express = $this->express->read($value['express']);
$info_list_smt[$key]['express'] = $express['servicename'];
$warehouse = $this->warehouse->read($value['type']);
$info_list_smt[$key]['type'] = $warehouse['title'];
if($value['print'] == 1)
{
$info_list_smt[$key]['print'] = '不可打印';
}
else if($value['print'] == 2)
{
$info_list_smt[$key]['print'] = '未打印';
}
else if($value['print'] == 3)
{
$info_list_smt[$key]['print'] = '已打印';
}
if($value['library'] == 1)
{
$info_list_smt[$key]['library'] = '未出库';
}
else if($value['library'] == 2)
{
$info_list_smt[$key]['library'] = '已出库';
}
else if($value['library'] == 3)
{
$info_list_smt[$key]['library'] = '已退库';
}
if($value['librarytime'] == '0')
{
$info_list_smt[$key]['librarytime'] = '';
}
else
{
$info_list_smt[$key]['librarytime'] = ''.date('Y-m-d H:i:s',$value['librarytime']).'';
}
}
$info_listsmt = $this->fullordersmt->find_all($where,'id,shop,type,orderinfo,number,waybill,express,print,library,librarytime,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'];
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['library'] == 1)
{
$info_listsmt[$key]['library'] = '未出库';
}
else if($value['library'] == 2)
{
$info_listsmt[$key]['library'] = '已出库';
}
else if($value['library'] == 3)
{
$info_listsmt[$key]['library'] = '已退库';
}
if($value['librarytime'] == '0')
{
$info_listsmt[$key]['librarytime'] = '';
}
else
{
$info_listsmt[$key]['librarytime'] = ''.date('Y-m-d H:i:s',$value['librarytime']).'';
}
}
$total = $this->fullorder->find_count($where);
$total += $this->fullorder_smt->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_list_smt,$info_listsmt)));
echo json_encode($rows);exit;
}
$this->data['express'] = $this->express->find_all();
$this->_Template('apt_out',$this->data);
}
//退库
public function _retreat()
{
$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 = 'fullorder_smt';
$y = $this->fullorder_smt->get_waybill($order);
if(!$y)
{
$y = $this->fullorder_smt->get_number($order);
if(!$y)
{
$fullorder_name = 'fullordersmt';
$y = $this->fullordersmt->get_waybill($order);
if(!$y)
{
$y = $this->fullordersmt->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']);
if($warehouse['zd'] == '1')
{
$wl = $this->whlabel->find_all("zd = '".$y['number']."'");//查找是否有占用库存情况
if($wl)//如果有那么清除所有占用
{
$i = 0;
foreach ($wl as $v)
{
$this->whlabel->save(array('state'=>0,'retreat'=>$time,'time'=>$time),$v['id']);//专属
$i++;
}
if($i != count($wl))
{
echo json_encode(array('msg'=>"退库错误,请重试",'success'=>false));exit;
}
}
/**
$ckcg = 0;$save = array();
$pp = explode('|',trim($y['whlabel'],'|'));
foreach ($pp as $va)
{
$uid = array();//储存可用出库产品的ID
$num = explode('-',$va);
$whlabel = $this->whlabel->find_all("state = 1 and number = '$num[0]' and warehouse = '".$y['type']."' and orderinfo = '".$y['orderinfo']."' and waybill = '".$y['waybill']."'");
if(!$whlabel || count($whlabel) != $num[1])
{
$ckcg++;
}
else
{
for($i=0;$i<$num[1];$i++)
{
$uid[] = $whlabel[$i]['id'];
}
$save[] = $uid;
}
}
if($ckcg > 0)
{
echo json_encode(array('msg'=>'有产品无出库信息','success'=>false));exit;
}
else
{
foreach ($save as $vb)
{
foreach ($vb as $vc)
{
$this->whlabel->save(array('state'=>0,'retreat'=>$time,'time'=>$time),$vc);
}
}
}
**/
}
if($this->$fullorder_name->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']))
{
$api = $this->input->post('api',true);
if(isset($api))
{
$user = $this->user->get_api($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";
}
}
$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']) || $api)?"library=3 and gtime > 20190127 and (".rtrim($wtype,'or').")":"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'";
}
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,print,state,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'];
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']).'';
}
}
$info_list_smt = $this->fullorder_smt->find_all($where,'id,shop,type,orderinfo,number,waybill,express,print,state,retreattime,shipremarks',$order_str,$start,$perpage);
//格式化数据
foreach ($info_list_smt as $key=>$value)
{
$shop = $this->shop->read($value['shop']);
$info_list_smt[$key]['shop'] = $shop['shopname'];
if($value['waybill'] == 0)
{
$info_list_smt[$key]['waybill'] = "";
}
$express = $this->express->read($value['express']);
$info_list_smt[$key]['express'] = $express['servicename'];
$warehouse = $this->warehouse->read($value['type']);
$info_list_smt[$key]['type'] = $warehouse['title'];
$typeclass = $this->typeclass->read($value['state']);
$info_list_smt[$key]['state'] = $typeclass['spare'];
if($value['print'] == 1)
{
$info_list_smt[$key]['print'] = '不可打印';
}
else if($value['print'] == 2)
{
$info_list_smt[$key]['print'] = '未打印';
}
else if($value['print'] == 3)
{
$info_list_smt[$key]['print'] = '已打印';
}
if($value['retreattime'] == '0')
{
$info_list_smt[$key]['retreattime'] = '';
}
else
{
$info_list_smt[$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']).'';
}
}
$total = $this->fullorder->find_count($where);
$total += $this->fullorder_smt->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_list_smt,$info_listsmt)));
echo json_encode($rows);exit;
}
$this->data['express'] = $this->express->find_all();
$this->_Template('apt_retreat',$this->data);
}
//打印页面
public function _print()
{
$post = $this->input->post(NULL, TRUE);
if(isset($_SESSION['api']))
{
$user = $this->user->get_api($_SESSION['api']);
$usp = $user;
$fgshop = "";$sid = "";$wid="";
$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";
}
}
if(isset($post['page']))
{
$api = $this->input->post('api',true);
$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);
$type = $this->input->post('type',true);
$lowe = $this->input->post('lowe',true);
$info = $this->input->post('info',true);
$ji = $this->input->post('ji',true);
$so = $this->input->post('so',true);
$timetk = strtotime($timetk);
$timetj = strtotime($timetj);
if(isset($api))
{
$user = $this->user->get_api($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";
}
}
$where = (isset($_SESSION['api']) || $api)?"mergeid != '1' and (".rtrim($fgshop,'or').") and (".rtrim($wtype,'or').")":"mergeid != '1'";
if($print == 3)
{
$where .= " and printtime > '$timetk' and printtime < '$timetj' and print = 3";
}
else
{
$where .= " and express != 0 and printtype > 0 and printtype < 3 and print = 2 and review > 4 and library = 1 and state = 207";
}
if($shop)
{
$where .= " and shop = '$shop'";
}
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'";
}
if($type)
{
$where .= " and type = '$type'";
}
if($lowe)
{
$where .= " and fpdata like '%-$lowe-%'";
}
if($ji)
{
$where .= " and shipremarks like '%急%'";
}
if($so)
{
$where .= " and shipremarks like '%$so%'";
}
//数据排序
$order_str = ($print != 3)?"id desc":"printtime desc";
if(empty($page))
{
$start = 0;
$perpage = 1;
}
else
{
$start = ($page - 1)*$perpage;
}
$info_list = array();
$info_listsmt = array();
$dlz = 0; $smt = 0;
if($info != 'fullordersmt')
{
//取得信息列表
$info_list = $this->fullorder->find_all($where,'id,shop,orderinfo,number,express,waybill,print,printtype,printnumber,printtime,shipremarks',$order_str,$start,$perpage);
//格式化数据
foreach ($info_list as $key=>$value)
{
$info_list[$key]['id'] = $value['id'].'-fullorder';
$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'] = "未选择";
}
}
$dlz = $this->fullorder->find_count($where);
}
/**
$info_list_smt = $this->fullorder_smt->find_all($where,'id,shop,orderinfo,number,express,waybill,print,printtype,printnumber,printtime,shipremarks',$order_str,$start,$perpage);
//格式化数据
foreach ($info_list_smt as $key=>$value)
{
$info_list_smt[$key]['id'] = $value['id'].'-fullorder_smt';
$shop = $this->shop->read($value['shop']);
$info_list_smt[$key]['shop'] = $shop['shopname'];
$express = $this->express->read($value['express']);
if($express)
{
$info_list_smt[$key]['express'] = $express['servicename'];
}
else
{
$info_list_smt[$key]['express'] = '未选择';
}
if($value['printtime'] != 0)
{
$info_list_smt[$key]['printtime'] = date('Y-m-d H:i:s',$value['printtime']);
}
else
{
$info_list_smt[$key]['printtime'] = '无';
}
if($value['print'] == 1)
{
$info_list_smt[$key]['print'] = "禁止打印";
}
else if($value['print'] == 2)
{
$info_list_smt[$key]['print'] = "未打印";
}
else if($value['print'] == 3)
{
$info_list_smt[$key]['print'] = "已打印";
}
if($value['printtype'] == 1)
{
$info_list_smt[$key]['printtype'] = "运单";
}
else if($value['printtype'] == 2)
{
$info_list_smt[$key]['printtype'] = "发货单";
}
else if($value['printtype'] == 0)
{
$info_list_smt[$key]['printtype'] = "未选择";
}
}
**/
if($info != 'fullorder')
{
$info_listsmt = $this->fullordersmt->find_all($where,'id,shop,orderinfo,number,express,waybill,print,printtype,printnumber,printtime,shipremarks',$order_str,$start,$perpage);
//格式化数据
foreach ($info_listsmt as $key=>$value)
{
$info_listsmt[$key]['id'] = $value['id'].'-fullordersmt';
$shop = $this->shop->read($value['shop']);
$info_listsmt[$key]['shop'] = $shop['shopname'];
$express = $this->express->read($value['express']);
if($express)
{
$info_listsmt[$key]['express'] = $express['servicename'];
}
else
{
$info_listsmt[$key]['express'] = '未选择';
}
if($value['printtime'] != 0)
{
$info_listsmt[$key]['printtime'] = date('Y-m-d H:i:s',$value['printtime']);
}
else
{
$info_listsmt[$key]['printtime'] = '无';
}
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['printtype'] == 1)
{
$info_listsmt[$key]['printtype'] = "运单";
}
else if($value['printtype'] == 2)
{
$info_listsmt[$key]['printtype'] = "发货单";
}
else if($value['printtype'] == 0)
{
$info_listsmt[$key]['printtype'] = "未选择";
}
}
$smt += $this->fullordersmt->find_count($where);
}
//$total += $this->fullorder_smt->find_count($where);
$total = $dlz+$smt;
$rows = array_merge($info_list,$info_listsmt);
//$rows = array_slice($rows,$start,$perpage);
$pagenum = ceil($total/$perpage);
$over = $total-($start+$perpage);
$rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($rows));//array_merge($info_list,$info_list_smt,$info_listsmt)
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('apt_print',$this->data);
}
//打印
public function _printing()
{
$post = $this->input->post(NULL, TRUE);
if(isset($post['s']))
{
$v = $this->input->post('s');
$va = explode(',',rtrim($v,','));
$n = $this->input->post('n');
$type = 3;$text = array();$text['data'] = array();$time = time();
$pd = explode('-',$va[$n]);
$va[$n] = $pd[0];
$fullorder_name = $pd[1];
$fullorder = $this->$fullorder_name->read($va[$n]);
if(isset($va[$n+1]))
{
$xyz = explode('-',$va[$n+1]);
$sf = $this->$fullorder_name->read($xyz[0]);
if($sf['printtype'] == 1 && $fullorder['printtype'] == 2)
{
sleep(15);
}
}
$fullorder = $this->_text($fullorder);//获取所需信息
$oldprinttime = ($fullorder['printtime'] > 0)?$fullorder['oldprinttime'].$fullorder['printtime'].'-':'';
$fullorder['printtime'] = date('m-d H:i',$time);//打印用时间、发货单用,不能删
if($fullorder['printtype'] == 1 && $fullorder['library'] != 2)// && $fullorder['library'] != 2
{
if($fullorder['printcode'] == "DHL")//如果打印过那么重新获取运单
{
sleep(12);
$barcode = $this->dhl->get_data($fullorder);//获取DHL快递信息
if(isset($barcode['AirwayBillNumber']))
{
$bctime = date('Ymd',$time);
$Hwaybill = $barcode['AirwayBillNumber'];
$Hfp = $this->_pdf($barcode['LabelImage']['MultiLabels']['MultiLabel']['DocImageVal'],'f-'.$Hwaybill,$bctime);
$Hyd = $this->_pdf($barcode['LabelImage']['OutputImage'],'y-'.$Hwaybill,$bctime);
if(isset($Hfp) && isset($Hyd) && isset($Hwaybill))
{
if($fullorder['waybill'] != "")
{
$oldwaybill = $fullorder['oldwaybill'].'-'.date('Ymd',$time).'/'.$fullorder['waybill'];
}
else
{
$oldwaybill = $fullorder['oldwaybill'];
}
$oldwaybill .= '-'.$bctime.'/'.$Hwaybill;
$fullorder['printnumber'] = $fullorder['printnumber'] +1;//不能删
if($this->$fullorder_name->save(array('waybill'=>$Hwaybill,'libraryconfirm'=>2,'librarynot'=>'','printtime'=>$time,'printnumber'=>$fullorder['printnumber'],'print'=>3,'oldwaybill'=>$oldwaybill,'oldprinttime'=>$oldprinttime),$va[$n]))
{
$type = 1;
$text = array('yd'=>'data/pdf/'.$bctime.'/y-'.$Hwaybill.'.pdf','data'=>$fullorder);
}
}
}
else
{
$failed = (isset($barcode['Response']['Status']['Condition']['ConditionData'])?$barcode['Response']['Status']['Condition']['ConditionData']:$barcode['Response']['Status']['Condition'][0]['ConditionData']);
$this->$fullorder_name->save(array('print'=>1,'failed'=>$failed),$va[$n]);
}
}
else if($fullorder['printcode'] == "USPS")
{
sleep(10);
$barcode = $this->usps->get_data($fullorder);//获取DHL快递信息
if(isset($barcode['LabelImage']))
{
$bctime = date('Ymd',$time);
$Hwaybill = $barcode['BarcodeNumber'];
$Hyd = $this->_pdf($barcode['LabelImage'],'y-'.$Hwaybill,$bctime);
if(isset($barcode['LabelImage']) && isset($Hwaybill))
{
if($fullorder['waybill'] != "")
{
$oldwaybill = $fullorder['oldwaybill'].'-'.date('Ymd',$time).'/'.$fullorder['waybill'];
}
else
{
$oldwaybill = $fullorder['oldwaybill'];
}
$oldwaybill .= '-'.$bctime.'/'.$Hwaybill;
$fullorder['printnumber'] = $fullorder['printnumber'] +1;//不能删
if($this->$fullorder_name->save(array('waybill'=>$Hwaybill,'libraryconfirm'=>2,'librarynot'=>'','printtime'=>$time,'printnumber'=>$fullorder['printnumber'],'print'=>3,'oldwaybill'=>$oldwaybill,'oldprinttime'=>$oldprinttime),$va[$n]))
{
$type = 1;
$text = array('yd'=>'data/pdf/'.$bctime.'/y-'.$Hwaybill.'.pdf','data'=>$fullorder,'id'=>$fullorder['id'],'pt'=>$fullorder_name);
}
}
}
else
{
$failed = $barcode['Description'];//错误提示
$this->$fullorder_name->save(array('print'=>1,'failed'=>$failed),$va[$n]);
}
}
else if($fullorder['printcode'] == "FEDEXGF")//官方FEDEX接口
{
sleep(10);
$barcode = $this->fedex->get_data($fullorder);//获取联邦快递信息
if($barcode['x'] == 1)
{
$bctime = date('Ymd',$time);
$Hwaybill = $barcode['waybill'];
$Hyd = $this->_pdf($barcode['label'],'y-'.$Hwaybill,$bctime);
$Hfp = $this->_pdf($barcode['invoice'],'f-'.$Hwaybill,$bctime);//开通ETD模式,保留PDF,不需要打印
if(isset($barcode['label']) && isset($Hwaybill))
{
if($fullorder['waybill'] != "")
{
$oldwaybill = $fullorder['oldwaybill'].'-'.date('Ymd',$time).'/'.$fullorder['waybill'];
}
else
{
$oldwaybill = $fullorder['oldwaybill'];
}
$oldwaybill .= '-'.$bctime.'/'.$Hwaybill;
$fullorder['printnumber'] = $fullorder['printnumber'] +1;//不能删
if($this->$fullorder_name->save(array('waybill'=>$Hwaybill,'libraryconfirm'=>2,'librarynot'=>'','printtime'=>$time,'printnumber'=>$fullorder['printnumber'],'print'=>3,'oldwaybill'=>$oldwaybill,'oldprinttime'=>$oldprinttime),$va[$n]))
{
$type = 1;
$text = array('yd'=>'data/pdf/'.$bctime.'/y-'.$Hwaybill.'.pdf','data'=>$fullorder,'id'=>$fullorder['id'],'pt'=>$fullorder_name);
}
}
}
else
{
$failed = $barcode['Description'];//错误提示
$this->$fullorder_name->save(array('print'=>1,'failed'=>$failed),$va[$n]);
}
}
else if($fullorder['printcode'] == "FEDEXCBY")//官方FEDEX接口许昌玉美桥
{
sleep(10);
$barcode = $this->fedex_cby->get_data($fullorder);//获取联邦快递信息
if($barcode['x'] == 1)
{
$bctime = date('Ymd',$time);
$Hwaybill = $barcode['waybill'];
$Hyd = $this->_pdf($barcode['label'],'y-'.$Hwaybill,$bctime);
$Hfp = $this->_pdf($barcode['invoice'],'f-'.$Hwaybill,$bctime);//开通ETD模式,保留PDF,不需要打印
if(isset($barcode['label']) && isset($Hwaybill))
{
if($fullorder['waybill'] != "")
{
$oldwaybill = $fullorder['oldwaybill'].'-'.date('Ymd',$time).'/'.$fullorder['waybill'];
}
else
{
$oldwaybill = $fullorder['oldwaybill'];
}
$oldwaybill .= '-'.$bctime.'/'.$Hwaybill;
$fullorder['printnumber'] = $fullorder['printnumber'] +1;//不能删
if($this->$fullorder_name->save(array('waybill'=>$Hwaybill,'libraryconfirm'=>2,'librarynot'=>'','printtime'=>$time,'printnumber'=>$fullorder['printnumber'],'print'=>3,'oldwaybill'=>$oldwaybill,'oldprinttime'=>$oldprinttime),$va[$n]))
{
$type = 1;
$text = array('yd'=>'data/pdf/'.$bctime.'/y-'.$Hwaybill.'.pdf','data'=>$fullorder,'id'=>$fullorder['id'],'pt'=>$fullorder_name);
}
}
}
else
{
$failed = $barcode['Description'];//错误提示
$this->$fullorder_name->save(array('print'=>1,'failed'=>$failed),$va[$n]);
}
}
/** DPD只获取运单号不打印运单 **/
else if($fullorder['printcode'] == "DPD")
{
sleep(15);//不打印运单 4秒延时
if($fullorder['zhou'] == '12')//欧洲
{
if($fullorder_name == 'fullordersmt')//速卖通9610
{
$fullorder['ysfs'] == '1921';
}
else if($fullorder_name == 'fullorder')//独立站9610
{
$fullorder['ysfs'] == '2021';
}
}
else if($fullorder['zhou'] == '13')//非洲
{
$fullorder['ysfs'] == '1881';
}
//$fullorder['ysfs'] == '2041';//欧洲全程不包双清、税
//$fullorder['ysfs'] == '1981';//欧洲速卖通非9610
//$fullorder['ysfs'] == '2001';//欧洲独立站非9610
$barcode = $this->dpd->get_data($fullorder);//获取信息
if($barcode['x'] == 1)//$barcode['a'] == 2 && $Hyd['a'] == 2
{
$bctime = date('Ymd',$time);
$Hwaybill = $barcode['waybill'];//运单号
if($fullorder['waybill'] != "")
{
$oldwaybill = $fullorder['oldwaybill'].'-'.date('Ymd',$time).'/'.$fullorder['waybill'];
}
else
{
$oldwaybill = $fullorder['oldwaybill'];
}
$oldwaybill .= '-'.$bctime.'/'.$Hwaybill;
$fullorder['printnumber'] = $fullorder['printnumber'] +1;//不能删
if($this->$fullorder_name->save(array('waybill'=>$Hwaybill,'libraryconfirm'=>2,'librarynot'=>'','printtime'=>$time,'printnumber'=>$fullorder['printnumber'],'print'=>3,'oldwaybill'=>$oldwaybill,'oldprinttime'=>$oldprinttime),$va[$n]))
{
$type = 2;
$text = array('data'=>$fullorder);
}
}
else
{
$failed = $barcode['Description'];
$this->$fullorder_name->save(array('print'=>1,'failed'=>$failed),$va[$n]);
}
}
/** 阿里仓联邦不打印运单模式
else if($fullorder['printcode'] == "FEDEX" || $fullorder['printcode'] == "TOLL" || $fullorder['printcode'] == "ARAMEX")
{
sleep(4);//不打印运单 4秒延时
$lj = $this->ali->get_lj($fullorder['number'],2,'订单修改');
$barcode = $this->ali->get_data($fullorder);//获取DHL快递信息
//$Hyd = $this->ali->get_label($fullorder['number'],1);//目前不需要打印标签
//1:10 X 10标签 2:A4纸 3:10X15标签 默认1
if($barcode['a'] == 2)//$barcode['a'] == 2 && $Hyd['a'] == 2
{
$bctime = date('Ymd',$time);
$Hwaybill = $barcode['number'];//运单号
//$this->_pdfurl($Hyd['pdf'],'y-'.$Hwaybill,$bctime);//目前不需要打印标签
if($fullorder['waybill'] != "")
{
$oldwaybill = $fullorder['oldwaybill'].'-'.date('Ymd',$time).'/'.$fullorder['waybill'];
}
else
{
$oldwaybill = $fullorder['oldwaybill'];
}
$oldwaybill .= '-'.$bctime.'/'.$Hwaybill;
$fullorder['printnumber'] = $fullorder['printnumber'] +1;//不能删
if($this->$fullorder_name->save(array('waybill'=>$Hwaybill,'libraryconfirm'=>2,'librarynot'=>'','printtime'=>$time,'printnumber'=>$fullorder['printnumber'],'print'=>3,'oldwaybill'=>$oldwaybill,'oldprinttime'=>$oldprinttime),$va[$n]))
{
$type = 2;
$text = array('data'=>$fullorder);
}
}
else
{
$failed = $barcode['m'];
//$failed = isset($barcode['m'])?$barcode['m']:'-(此单已预报,务必先取消再允许打印)';//获取运单号错误提示
//$failed .= isset($Hyd['m'])?$Hyd['m']:'';//获取标签错误提示
if($fullorder['print'] == 3)
{
$this->$fullorder_name->save(array('libraryconfirm'=>1,'failed'=>date('Y-m-d H:i:s',time()).$failed),$va[$n]);
}
else
{
$this->$fullorder_name->save(array('print'=>1,'failed'=>date('Y-m-d H:i:s',time()).$failed),$va[$n]);
}
}
}
**/
else if($fullorder['printcode'] == "FEDEX" || $fullorder['printcode'] == "TOLL" || $fullorder['printcode'] == "ARAMEX")
{
sleep(13);//不打印运单 4秒延时
$lj = $this->ali->get_lj($fullorder['number'],2,'订单修改');
$barcode = $this->ali->get_data($fullorder);//获取快递信息
$Hyd = $this->ali->get_label($fullorder['number'],1);//目前不需要打印标签
//1:10 X 10标签 2:A4纸 3:10X15标签 默认1
if($barcode['a'] == 2 && $Hyd['a'] == 2)
{
$bctime = date('Ymd',$time);
$Hwaybill = $barcode['number'];//运单号
$this->_pdfurl($Hyd['pdf'],'y-'.$Hwaybill,$bctime);//上传PDF
if($fullorder['waybill'] != "")
{
$oldwaybill = $fullorder['oldwaybill'].'-'.date('Ymd',$time).'/'.$fullorder['waybill'];
}
else
{
$oldwaybill = $fullorder['oldwaybill'];
}
$oldwaybill .= '-'.$bctime.'/'.$Hwaybill;
$fullorder['printnumber'] = $fullorder['printnumber'] +1;//不能删
if($this->$fullorder_name->save(array('waybill'=>$Hwaybill,'libraryconfirm'=>2,'librarynot'=>'','printtime'=>$time,'printnumber'=>$fullorder['printnumber'],'print'=>3,'oldwaybill'=>$oldwaybill,'oldprinttime'=>$oldprinttime),$va[$n]))
{
$type = 1;
$text = array('yd'=>'data/pdf/'.$bctime.'/y-'.$Hwaybill.'.pdf','data'=>$fullorder,'id'=>$fullorder['id'],'pt'=>$fullorder_name);
}
}
else
{
//$failed = $barcode['m'];
$failed = isset($barcode['m'])?$barcode['m']:'-(此单已预报,务必先取消再允许打印)';//获取运单号错误提示
$failed .= isset($Hyd['m'])?$Hyd['m']:'';//获取标签错误提示
if($fullorder['print'] == 3)
{
$this->$fullorder_name->save(array('libraryconfirm'=>1,'failed'=>date('Y-m-d H:i:s',time()).$failed),$va[$n]);
}
else
{
$this->$fullorder_name->save(array('print'=>1,'failed'=>date('Y-m-d H:i:s',time()).$failed),$va[$n]);
}
}
}
else if($fullorder['printcode'] == "UPS")//接口
{
sleep(25);
$barcode = $this->ups->get_data($fullorder);//获取快递信息
if($barcode['x'] == 1)
{
$bctime = date('Ymd',$time);
$Hwaybill = $barcode['waybill'];
$Hyd = $this->_pdfurl($barcode['label'],'y-'.$Hwaybill,$bctime);
if(isset($barcode['label']) && isset($Hwaybill))
{
if($fullorder['waybill'] != "")
{
$oldwaybill = $fullorder['oldwaybill'].'-'.date('Ymd',$time).'/'.$fullorder['waybill'];
}
else
{
$oldwaybill = $fullorder['oldwaybill'];
}
$oldwaybill .= '-'.$bctime.'/'.$Hwaybill;
$fullorder['printnumber'] = $fullorder['printnumber'] +1;//不能删
if($this->$fullorder_name->save(array('waybill'=>$Hwaybill,'libraryconfirm'=>2,'librarynot'=>'','printtime'=>$time,'printnumber'=>$fullorder['printnumber'],'print'=>3,'oldwaybill'=>$oldwaybill,'oldprinttime'=>$oldprinttime),$va[$n]))
{
$type = 1;
$text = array('yd'=>'data/pdf/'.$bctime.'/y-'.$Hwaybill.'.pdf','data'=>$fullorder,'id'=>$fullorder['id'],'pt'=>$fullorder_name);
}
}
}
else
{
$failed = $barcode['Description'];//错误提示
$this->$fullorder_name->save(array('print'=>1,'failed'=>$failed),$va[$n]);
}
}
else
{
$this->$fullorder_name->save(array('print'=>1,'failed'=>'未找到此快递运单接口'),$va[$n]);
}
if($fullorder_name == 'fullordersmt' || $fullorder_name == 'fullorder_smt')
{
$text['data']['dplx'] = '速卖通';
}
else
{
$text['data']['dplx']= '独立站';
}
$rows = array('type'=>$type,'n'=>$n-1,'data'=>$v,'text'=>$text);
echo json_encode(array('rows'=>($rows),'success'=>true));exit;
}
else if($fullorder['printtype'] == 2 && $fullorder['library'] != 2)
{
sleep(15);
$fullorder['printnumber'] = $fullorder['printnumber'] +1;//不能删
if($this->$fullorder_name->save(array('libraryconfirm'=>2,'librarynot'=>'','printtime'=>$time,'printnumber'=>$fullorder['printnumber'],'print'=>3,'oldprinttime'=>$oldprinttime),$va[$n]))
{
$type = 2;
$text = array('data'=>$fullorder);
}
if($fullorder_name == 'fullordersmt' || $fullorder_name == 'fullorder_smt')
{
$text['data']['dplx']= '速卖通';
}
else
{
$text['data']['dplx']= '独立站';
}
$rows = array('type'=>$type,'n'=>$n-1,'data'=>$v,'text'=>$text);
echo json_encode(array('rows'=>($rows),'success'=>true));exit;
}
else
{
if($fullorder_name == 'fullordersmt' || $fullorder_name == 'fullorder_smt')
{
$text['data']['dplx']= '速卖通';
}
else
{
$text['data']['dplx']= '独立站';
}
$rows = array('type'=>$type,'n'=>$n-1,'data'=>$v,'text'=>$text);
echo json_encode(array('msg'=>'该订单已出库,无法打印!','success'=>false));exit;
}
}
}
public function _outbound()
{
$post = $this->input->post(NULL, TRUE);
if(isset($post['page']))
{
$api = $this->input->post('api',true);
$page = $this->input->post('page',true);
$perpage = $this->input->post('perpage',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);
$timetk = $this->input->post('timetk',true);
$timetj = $this->input->post('timetj',true);
$timetk = strtotime($timetk);
$timetj = strtotime($timetj);
$where = "type != 0";
if(isset($api))
{
if($type)
{
$where .= " and type = '$type'";
}
else
{
$uw = '';
$u = $this->user->get_api($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'";
}
if($waybill)
{
$where .= " and waybill = '$waybill'";
}
if($express)
{
$where .= " and express = '$express'";
}
//数据排序
$order_str = "id desc";
if(empty($page))
{
$start = 0;
$perpage = 1;
}
else
{
$start = ($page - 1)*$perpage;
}
//取得信息列表
$info_list = $this->outbound->find_all($where,'id,type,express,number,waybill,time',$order_str,$start,$perpage);
//格式化数据
foreach ($info_list as $key=>$value)
{
if($value['waybill'] == '0')
{
$info_list[$key]['waybill'] = "无";
}
if($value['express'] == '0')
{
$info_list[$key]['express'] = "无";
}
else
{
$express = $this->express->read($value['express']);
$info_list[$key]['express'] = $express['servicename'];
}
$warehouse = $this->warehouse->read($value['type']);
$info_list[$key]['type'] = $warehouse['title'];
$info_list[$key]['time'] = ''.date('Y-m-d H:i:s',$value['time']).'';
}
$ex = array();
$ed = $this->outbound->find_all($where,'express');
foreach ($ed as $key=>$value)
{
if(isset($ex[$value['express']]))
{
$ex[$value['express']] += 1;
}
else
{
$ex[$value['express']] = 1;
}
}
$exdata = '';
foreach ($ex as $k=>$v)
{
$e = $this->express->read($k);
$exdata .= "
".$e['servicename'].":".$v."单";
}
$datacount = $this->outbound->find_count("gtime = '".date('Ymd',time())."'");
$total = $this->outbound->find_count($where);
$pagenum = ceil($total/$perpage);
$over = $total-($start+$perpage);
$adm = ($api == '21a6d1cfb3cc66471680bd61ae94e8fa7af75bfb')?1:2;
$rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'datacount'=>$datacount,'adm'=>$adm,'exdata'=>$exdata);
echo json_encode($rows);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');
}
$id = $this->input->get('id',true);
$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);
$type = $this->input->get('type',true);
$so = $this->input->get('so',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'";
}
else
{
$where .= " and printtime > '$timetk' and printtime < '$timetj'";
}
if($id)
{
if($type)
{
$where .= " and type = '$type'";
}
else
{
$uw = '';
$u = $this->user->get_api($id);
$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;
}
}
else
{
echo json_encode(array('msg'=>'导出失败,请更新!','success'=>false));exit;
}
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'";
}
if($so)
{
$where .= " and shipremarks like '%$so%'";
}
//数据排序
$order_str = ($print != 3)?"id desc":"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,shipremarks,ts',$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']).'';
}
}
//取得信息列表
$info_listsmt = $this->fullordersmt->find_all($where.$wid,'shop,type,orderinfo,number,waybill,express,print,library,librarytime,shipremarks,ts',$order_str);
//格式化数据
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'];
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['library'] == 1)
{
$info_listsmt[$key]['library'] = '未出库';
}
else if($value['library'] == 2)
{
$info_listsmt[$key]['library'] = '已出库';
}
else if($value['library'] == 3)
{
$info_listsmt[$key]['library'] = '已退库';
}
if($value['librarytime'] == '0')
{
$info_listsmt[$key]['librarytime'] = '';
}
else
{
$info_listsmt[$key]['librarytime'] = ''.date('Y-m-d H:i:s',$value['librarytime']).'';
}
}
//取得信息列表
$info_list_smt = $this->fullorder_smt->find_all($where.$wid,'shop,type,orderinfo,number,waybill,express,print,library,librarytime,shipremarks',$order_str);
//格式化数据
foreach ($info_list_smt as $key=>$value)
{
$shop = $this->shop->read($value['shop']);
$info_list_smt[$key]['shop'] = $shop['shopname'];
if($value['waybill'] == '0')
{
$info_list_smt[$key]['waybill'] = "";
}
$express = $this->express->read($value['express']);
$info_list_smt[$key]['express'] = $express['servicename'];
$warehouse = $this->warehouse->read($value['type']);
$info_list_smt[$key]['type'] = $warehouse['title'];
if($value['print'] == 1)
{
$info_list_smt[$key]['print'] = '不可打印';
}
else if($value['print'] == 2)
{
$info_list_smt[$key]['print'] = '未打印';
}
else if($value['print'] == 3)
{
$info_list_smt[$key]['print'] = '已打印';
}
if($value['library'] == 1)
{
$info_list_smt[$key]['library'] = '未出库';
}
else if($value['library'] == 2)
{
$info_list_smt[$key]['library'] = '已出库';
}
else if($value['library'] == 3)
{
$info_list_smt[$key]['library'] = '已退库';
}
if($value['librarytime'] == '0')
{
$info_list_smt[$key]['librarytime'] = '';
}
else
{
$info_list_smt[$key]['librarytime'] = ''.date('Y-m-d H:i:s',$value['librarytime']).'';
}
}
$title = '订单出库-'.date('Ymd',time());
$titlename = "";
$tail = "\n";
$filename = $title.".xls";
$this->excel->get_fz2(array_merge($info_list,$info_list_smt,$info_listsmt),$titlename,$filename,$tail);
}
}
public function _cpexcel()
{
if(isset($_GET['excel']))
{
$id = $this->input->get('id',true);
$timetk = $this->input->get('timetk',true);
$timetj = $this->input->get('timetj',true);
$shop = $this->input->get('shop',true);
$library = $this->input->get('library',true);
$type = $this->input->get('type',true);
$number = $this->input->get('number',true);
$orderinfo = $this->input->get('orderinfo',true);
$number = $this->input->get('number',true);
$express = $this->input->get('express',true);
$timetk = strtotime($timetk);
$timetj = strtotime($timetj);
$where = "mergeid = 0";
if($timetk && $timetj && $library == 2)
{
$where .= " and librarytime > '$timetk' and librarytime < '$timetj'";
}
else
{
$where .= " and printtime > '$timetk' and printtime < '$timetj'";
}
if($id)
{
if($type)
{
$where .= " and type = '$type'";
}
else
{
$uw = '';
$u = $this->user->get_api($id);
$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($shop)
{
$where .= " and shop = '$shop'";
}
if($library)
{
$where .= " and library = '$library'";
}
if($number)
{
$where .= " and number = '$number'";
}
if($orderinfo)
{
$where .= " and orderinfo = '$orderinfo'";
}
if($express)
{
$where .= " and express = '$express'";
}
/* 匹配ID加入 */
$tc = array();
$typeclass = $this->typeclass->find_all();
foreach ($typeclass as $v)
{
$tc[$v['id']] = $v['title'];
}
$shouldmoney=0;$expressmoney=0;$budget=0;$refundj=0;$refundj=0;$cost=0;$lr=0;
//取得信息列表
$info_lista = $this->fullordersmt->find_all($where,'fpdata');
$info_listb = $this->fullorder->find_all($where,'fpdata');
$info_list = array_merge($info_lista,$info_listb);
//格式化数据
$i = 0;$cpexcel = array();
foreach ($info_list as $key=>$value)
{
if(stripos($value['fpdata'],';') !== false)
{
$fpdata = explode(';',rtrim($value['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],'-'));
$dj = $tc[$cp[2]];
$ys = $tc[$cp[3]];
unset($cp[0],$cp[1],$cp[2],$cp[3]);
foreach ($cp as $v)
{
$title .= $tc[$v].' ';
}
$cpexcel[$ke] = array($fg[5],$dj,$ys,$title,$fg[2]);//内容,尺寸,等级,颜色,数量
}
}
$i++;
}
$title = "统计信息";
$titlename = "";
$filename = $title.".xls";
$tail = "\n";
$this->excel->get_fz2($cpexcel,$titlename,$filename,$tail);
}
}
public function _exceldy()
{
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');
}
$id = $this->input->get('id',true);
$t = $this->input->get('t',true);
$print = $this->input->get('print',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);
$waybill = $this->input->get('waybill',true);
$express = $this->input->get('express',true);
$type = $this->input->get('type',true);
$so = $this->input->get('so',true);
$timetk = strtotime($timetk);
$timetj = strtotime($timetj);
$where = "mergeid = 0";
if($print == 3)
{
$where .= " and printtime > '$timetk' and printtime < '$timetj' and print = 3";
}
else
{
$where .= " and express != 0 and printtype > 0 and printtype < 3 and print = 2 and review > 4 and library = 1 and state = 207";
}
if($id)
{
if($type)
{
$where .= " and type = '$type'";
}
else
{
$uw = '';
$u = $this->user->get_api($id);
$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;
}
}
else
{
echo json_encode(array('msg'=>'导出失败,请更新!','success'=>false));exit;
}
if($print)
{
$where .= " and print = '$print'";
}
if($shop)
{
$where .= " and shop = '$shop'";
}
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($so)
{
$where .= " and shipremarks like '%$so%'";
}
//数据排序
$order_str = ($print != 3)?"id desc":"printtime desc";
if(empty($page))
{
$start = 0;
$perpage = 1;
}
else
{
$start = ($page - 1)*$perpage;
}
//取得信息列表
$info_list = $this->fullorder->find_all($where.$wid,'type,shop,orderinfo,number,express,waybill,print,printtype,printnumber,printtime,shipremarks',$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['printtype'] == 1)
{
$info_list[$key]['printtype'] = '运单';
}
else if($value['printtype'] == 2)
{
$info_list[$key]['printtype'] = '发货单';
}
if($value['printtime'] == '0')
{
$info_list[$key]['printtime'] = '';
}
else
{
$info_list[$key]['printtime'] = ''.date('Y-m-d H:i:s',$value['printtime']).'';
}
}
//取得信息列表
$info_listsmt = $this->fullordersmt->find_all($where.$wid,'type,shop,orderinfo,number,express,waybill,print,printtype,printnumber,printtime,shipremarks',$order_str);
//格式化数据
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'];
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['printtype'] == 1)
{
$info_listsmt[$key]['printtype'] = '运单';
}
else if($value['printtype'] == 2)
{
$info_listsmt[$key]['printtype'] = '发货单';
}
if($value['printtime'] == '0')
{
$info_listsmt[$key]['printtime'] = '';
}
else
{
$info_listsmt[$key]['printtime'] = ''.date('Y-m-d H:i:s',$value['printtime']).'';
}
}
$title = '订单打印-'.date('Ymd',time());
$titlename = "";
$tail = "\n";
$filename = $title.".xls";
$this->excel->get_fz2(array_merge($info_list,$info_listsmt),$titlename,$filename,$tail);
}
}
public function _fedexhz()
{
$post = $this->input->post(NULL, TRUE);
if(isset($post['id']))
{
$id = $this->input->post('id',true);
$fullorder_name = $this->input->post('name',true);
$express = $this->input->post('express',true);
$express = $this->express->read($express);
$fullorder = $this->$fullorder_name->read($id);
if($fullorder['type'] == '2')
{
$fullorder['type'] = 1;
}
$time = time();
$fullorder = $this->_text($fullorder);//获取所需信息
$oldprinttime = ($fullorder['printtime'] > 0)?$fullorder['oldprinttime'].$fullorder['printtime'].'-':'';
$fullorder['printtime'] = date('m-d H:i',$time);//打印用时间、发货单用,不能删
$time = time();
if($express['printcode'] == "FEDEXGF")
{
$barcode = $this->fedex->get_data($fullorder);//获取联邦快递信息
if($barcode['x'] == 1)
{
$bctime = date('Ymd',$time);
$Hwaybill = $barcode['waybill'];
$Hyd = $this->_pdf($barcode['label'],'y-'.$Hwaybill,$bctime);
$Hfp = $this->_pdf($barcode['invoice'],'f-'.$Hwaybill,$bctime);//开通ETD模式,保留PDF,不需要打印
if(isset($barcode['label']) && isset($Hwaybill))
{
if($fullorder['waybill'] != "")
{
$oldwaybill = $fullorder['oldwaybill'].'-'.date('Ymd',$time).'/'.$fullorder['waybill'];
}
else
{
$oldwaybill = $fullorder['oldwaybill'];
}
$oldwaybill .= '-'.$bctime.'/'.$Hwaybill;
$fullorder['printnumber'] = $fullorder['printnumber'] +1;//不能删
if($this->$fullorder_name->save(array('waybill'=>$Hwaybill,'printtime'=>$time,'printnumber'=>$fullorder['printnumber'],'oldwaybill'=>$oldwaybill,'oldprinttime'=>$oldprinttime),$fullorder['id']))
{
$warehouse = $this->warehouse->read($fullorder['type']);
echo json_encode(array('yd'=>'data/pdf/'.$bctime.'/y-'.$Hwaybill.'.pdf','printer3'=>$warehouse['printer3'],'printer4'=>$warehouse['printer4'],'success'=>true));exit;
}
else
{
echo json_encode(array('msg'=>'打印错误,请联系店员','cw'=>'写入数据库错误','success'=>false));exit;
}
}
}
else
{
echo json_encode(array('msg'=>'打印错误,请联系店员','cw'=>$barcode['Description'],'success'=>false));exit;
}
}
else if($express['printcode'] == "UPSXXXXXXXXX")//接口UPS暂时不打
{
$barcode = $this->ups->get_data($fullorder);//获取快递信息
if($barcode['x'] == 1)
{
$bctime = date('Ymd',$time);
$Hwaybill = $barcode['waybill'];
$Hyd = $this->_pdfurl($barcode['label'],'y-'.$Hwaybill,$bctime);
if(isset($barcode['label']) && isset($Hwaybill))
{
if($fullorder['waybill'] != "")
{
$oldwaybill = $fullorder['oldwaybill'].'-'.date('Ymd',$time).'/'.$fullorder['waybill'];
}
else
{
$oldwaybill = $fullorder['oldwaybill'];
}
$oldwaybill .= '-'.$bctime.'/'.$Hwaybill;
$fullorder['printnumber'] = $fullorder['printnumber'] +1;//不能删
if($this->$fullorder_name->save(array('waybill'=>$Hwaybill,'libraryconfirm'=>2,'librarynot'=>'','printtime'=>$time,'printnumber'=>$fullorder['printnumber'],'print'=>3,'oldwaybill'=>$oldwaybill,'oldprinttime'=>$oldprinttime),$va[$n]))
{
$type = 1;
$text = array('yd'=>'data/pdf/'.$bctime.'/y-'.$Hwaybill.'.pdf','data'=>$fullorder,'id'=>$fullorder['id'],'pt'=>$fullorder_name);
}
}
}
else
{
echo json_encode(array('msg'=>'打印错误,请联系店员','cw'=>$barcode['Description'],'success'=>false));exit;
}
}
else
{
echo json_encode(array('msg'=>'打印错误,请联系店员','success'=>false));exit;
}
}
}
//扫描发货单出运单开始
public function _number()
{
$post = $this->input->post(NULL, TRUE);
if(isset($post['order']))
{
$order = $this->input->post('order',true);
$fullorder_name = 'fullorder';
$y = $this->fullorder->get_number($order);
if(!$y)
{
$fullorder_name = 'fullordersmt';
$y = $this->fullordersmt->get_number($order);
if(!$y)
{
echo json_encode(array('msg'=>'无此发货单数据!','success'=>false));exit;
}
}
if($y['express'] != '24')
{
echo json_encode(array('msg'=>'物流方式不正确!','success'=>false));exit;
}
$data = $this->get_fedex_hz_number($y,$fullorder_name);
$warehouse = $this->warehouse->read($y['type']);
if(isset($data['yd']))
{
echo json_encode(array('numberyd'=>$data['yd'],'printer1'=>$warehouse['printer1'],'success'=>true));exit;
}
else
{
echo json_encode(array('msg'=>$data,'cw'=>$data,'success'=>false));exit;
}
}
}
public function get_fedex_hz_number($fullorder,$fullorder_name)
{
$time = time();
$fullorder = $this->_text($fullorder);//获取所需信息
$oldprinttime = ($fullorder['printtime'] > 0)?$fullorder['oldprinttime'].$fullorder['printtime'].'-':'';
$fullorder['printtime'] = date('m-d H:i',$time);//打印用时间、发货单用,不能删
$time = time();
$barcode = $this->fedex->get_data($fullorder);//获取联邦快递信息
if($barcode['x'] == 1)
{
$bctime = date('Ymd',$time);
$Hwaybill = $barcode['waybill'];
$Hyd = $this->_pdf($barcode['label'],'y-'.$Hwaybill,$bctime);
$Hfp = $this->_pdf($barcode['invoice'],'f-'.$Hwaybill,$bctime);//开通ETD模式,保留PDF,不需要打印
if(isset($barcode['label']) && isset($Hwaybill))
{
$oldwaybill = $fullorder['oldwaybill'].'-'.$bctime.'/'.$Hwaybill;
if($this->$fullorder_name->save(array('print'=>3,'waybill'=>$Hwaybill,'oldwaybill'=>$oldwaybill),$fullorder['id']))
{
return array('yd'=>'data/pdf/'.$bctime.'/y-'.$Hwaybill.'.pdf');
}
}
}
else
{
$failed = $barcode['Description'];//错误提示
$this->$fullorder_name->save(array('print'=>1,'failed'=>$failed),$fullorder['id']);
return '订单存在错误,已移交店员处理中';
}
}
//扫描发货单出运单结束
public function _fhd($arg_array)
{
if(isset($arg_array[1]))
{
$fu = ($arg_array[0] == 'dlz')?'fullorder':'fullordersmt';
$a = $this->$fu->find_all("waybill = '$arg_array[1]'");
$fullorder = $this->$fu->read($a[0]['id']);
$fullorder = $this->_text($fullorder);//获取所需信息
$this->data['data'] = $fullorder;
$this->data['fu'] = $fu;
$this->_Template('apt_fhd',$this->data);
}
}
public function _fedex($arg_array)
{
if(isset($arg_array[0]))
{
$this->data['data'] = array($arg_array[0],$arg_array[1]);
$this->_Template('apt_fedex',$this->data);
}
}
public function _fhdusa($arg_array)
{
if(isset($arg_array[0]))
{
$fullorder_name = $arg_array[1];
$fullorder = $this->$fullorder_name->read($arg_array[0]);
$fullorder = $this->_text($fullorder);//获取所需信息
$fullorder['printtime'] = date('Y-m-d H:i:s',$fullorder['printtime']);
$this->data['data'] = $fullorder;
$this->_Template('apt_fhdusa',$this->data);
}
}
public function _text($fullorder)
{
/** 发票地址信息暂时无用
$fullorder['baddress'] = explode(',',$fullorder['baddress']);
$fullorder['baddress'] = array_reverse($fullorder['baddress']);
$fullorder['baddress'][1] = $country['ename'];
**/
//获取所用相关信息
$warehouse = $this->warehouse->read($fullorder['type']);
$country = $this->country->read($fullorder['country']);//订单国家信息
$fcountry = $this->country->read($warehouse['country']);//仓库国家信息
$warehouse['country'] = $fcountry['ename'];//仓库国家名
$warehouse['lb'] = $fcountry['lb'];//仓库国家编码
$fullorder['warehouse'] = $warehouse;//仓库数据加入订单
$fullorder['lb'] = $country['lb'];//订单国家编码加入
$fullorder['country'] = $country['ename'];//订单国家名
$fullorder['zhou'] = $country['continent'];//所属州
$express = $this->express->read($fullorder['express']);
$fullorder['express'] = $express['servicename'];
$fullorder['account'] = $express['account'];
$fullorder['printcode'] = $express['printcode'];
$fullorder['time'] = date('Y-m-d',time());
$fullorder['times'] = date('Y-m-d H:i',time());
$fullorder['sbbm']= ($fullorder['sbpm'] == 'Hair Sample') ? 67042000 : 67041100;
$fullorder['address'] = str_replace(array('&'),array('&'),$fullorder['address']);
$fullorder['address2'] = str_replace(array('&'),array('&'),$fullorder['address2']);
$shop = $this->shop->read($fullorder['shop']);
$fullorder['shop'] = $shop['shopname'];
return $fullorder;
}
public function _select()
{
$post = $this->input->post(NULL, TRUE);
if(isset($post['warehouse']))
{
$warehouse = $this->input->post('warehouse',true);
$user = $this->user->get_api($warehouse);
//店铺
$spid = '';
$user['shop'] = explode('|',trim($user['shop'],'|'));
foreach ($user['shop'] as $v)
{
$spid .= " id = '$v' or";
}
$spid = rtrim($spid,'or');
$spid = ltrim($spid,' ');
$shop = $this->shop->find_all($spid);
//花型
$lowe = $this->typeclass->find_all('classid = 15 and id != 105 and id != 107 and id != 108 and id != 112 and id != 114 and id != 115 and id != 116 and id != 117 and id != 118 and id != 119 and id != 120 and id != 121 and id != 122 and id != 123 and id != 124 and id != 125 and id != 292 and id != 63 and id != 289 and id != 290 and id != 181 and id != 273 and id != 148 and id != 38 and id != 291 and id != 55 and id != 271 and id != 285 and id != 186 and id != 187 and id != 188 and id != 189');
//仓库
$warehouse = array();
$user['warehouse'] = explode('|',trim($user['warehouse'],'|'));
$user['warehousetext'] = explode('|',trim($user['warehousetext'],'|'));
for($i=0;$i$user['warehouse'][$i],'title'=>$user['warehousetext'][$i]);
}
$type = $warehouse;
//快递
$express = $this->express->find_all('1=1','*','idsort desc');
echo json_encode(array('shop'=>$shop,'lowe'=>$lowe,'type'=>$warehouse,'express'=>$express,'success'=>true));exit;
}
}
public function _shop()
{
$post = $this->input->post(NULL, TRUE);
if(isset($post['shop']))
{
$shop = $this->shop->find_all();
echo json_encode(array('msg'=>$shop));exit;
}
}
public function _lowe()
{
$post = $this->input->post(NULL, TRUE);
if(isset($post['lowe']))
{
$lowe = $this->typeclass->find_all('classid = 15 and id != 105 and id != 107 and id != 108 and id != 112 and id != 114 and id != 115 and id != 116 and id != 117 and id != 118 and id != 119 and id != 120 and id != 121 and id != 122 and id != 123 and id != 124 and id != 125 and id != 292 and id != 63 and id != 289 and id != 290 and id != 181 and id != 273 and id != 148 and id != 38 and id != 291 and id != 55 and id != 271 and id != 285 and id != 186 and id != 187 and id != 188 and id != 189');
echo json_encode(array('msg'=>$lowe));exit;
}
}
public function _warehouse()
{
$post = $this->input->post(NULL, TRUE);
if(isset($post['warehouse']))
{
$warehouse = $this->input->post('warehouse',true);
$user = $this->user->get_api($warehouse);
$warehouse = array();
$user['warehouse'] = explode('|',trim($user['warehouse'],'|'));
$user['warehousetext'] = explode('|',trim($user['warehousetext'],'|'));
for($i=0;$i$user['warehouse'][$i],'title'=>$user['warehousetext'][$i]);
}
echo json_encode(array('msg'=>$warehouse));exit;
}
}
public function _express()
{
$post = $this->input->post(NULL, TRUE);
if(isset($post['express']))
{
$express = $this->express->find_all('1=1','*','idsort desc');
echo json_encode(array('msg'=>$express));exit;
}
}
public function _pdf($pdf,$title,$bctime)
{
$pdf_path = './data/pdf/'.$bctime.'/';
$file_base64 = $pdf;
$file_base64 = preg_replace('/data:.*;base64,/i', '', $file_base64);
$file_base64 = base64_decode($file_base64);
if(!is_dir($pdf_path))mkdir($pdf_path,0777); //上传目录不存在则创建
file_put_contents($pdf_path.$title.'.pdf',$file_base64);
return $bctime;
}
public function _pdfurl($pdf,$title,$bctime)
{
$pdf_path = './data/pdf/'.$bctime.'/';
$pdf = fopen($pdf,"r");
if(!is_dir($pdf_path))mkdir($pdf_path,0777); //上传目录不存在则创建
file_put_contents($pdf_path.$title.'.pdf',$pdf);
return $bctime;
}
public function _img($pdf,$title,$bctime)
{
$pdf_path = './data/img/'.$bctime.'/';
$file_base64 = $pdf;
$file_base64 = preg_replace('/data:.*;base64,/i', '', $file_base64);
$file_base64 = base64_decode($file_base64);
if(!is_dir($pdf_path))mkdir($pdf_path,0777); //上传目录不存在则创建
file_put_contents($pdf_path.$title.'.png',$file_base64);
return $bctime;
}
}