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_fullordersmt','fullordersmt'); $this->load->_model('Model_express','express'); $this->load->_model('Model_shop','shop'); $this->load->_model('Model_typeclass','typeclass'); $this->load->_model('Model_country','country'); $this->load->_model('Model_warehouse','warehouse'); $this->load->_model('Model_kdniao','kdniao'); $this->load->_model('Model_notice','notice'); $this->load->_model('Model_dhl','dhl'); $this->load->_model('Model_usps','usps'); $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 == 'fhdusa')//打印操作 { $this->_fhdusa($arg_array); } else if($arg == 'shop') { $this->_shop(); } else if($arg == 'lowe') { $this->_lowe(); } else if($arg == 'express') { $this->_express(); } else if($arg == 'retreat') { $this->_retreat(); } else if($arg == 'excel') { $this->_excel(); } else { $this->_index(); } } //管理 public function _index() { $post = $this->input->post(NULL, TRUE); if(isset($post['userid'])) { $userid = $this->input->post('userid',true); $userpass = $this->input->post('userpass',true); $password = sha1($userpass); $user = $this->user->get_uid($userid,'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'],'success'=>true));exit; } else { echo json_encode(array('msg'=>"用户或密码不正确",'success'=>false));exit; } } else { echo json_encode(array('msg'=>"用户不正确",'success'=>false));exit; } } } //出库 public function _fout() { $post = $this->input->post(NULL, TRUE); if(isset($post['order'])) { $time = time(); $order = $this->input->post('order',true); $y = $this->fullorder->get_waybill($order); $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) { echo json_encode(array('msg'=>'无此数据','success'=>false));exit; } } } } if($y['libraryconfirm'] == 1 || $y['state'] == 217) { 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($y['type'] == 5) { $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)+count($shopwhlabel)) >= $num[1])//如果专用的条数小于需求,但专用的条数+通用的条数大于等于需求,判断为可用,有限扣减专用数 { for($i=0;$i 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($this->$fullorder_name->save(array('library'=>2,'librarytime'=>$time),$y['id'])) { echo json_encode(array('success'=>true));exit; if($fullorder_name == 'fullordersmt' && $y['source'] != 1)//速卖通发货声明 { $ex = $this->express->read($y['express']); $shop = $shop->shop->read($y['shop']); if($y['dlz'] == 1)//如果已经声明过需要操作修改声明 { $obtain = $this->apismt->get_obtain($y['orderinfo'],$shop['code']);//修改声明先查询之前物流信息 $result = $this->apismt->get_editout($obtain['logistics_no'],$y['whlabel'],'all',$y['orderinfo'],$obtain['service_name'],$ex['servicetitle'],$shop['code']); if($result['result_success'] == 'true') { $this->db->trans_begin(); $this->$fullorder_name->save(array('dlz'=>1),$y['id']); if($y['merge'] != '0') { $hdata = $this->$fullorder_name->find_all("merge = '".$y['merge']."' and id != '".$y['id']."'"); foreach ($hdata as $v) { $obtain = $this->apismt->get_obtain($v['orderinfo'],$shop['code']);//修改声明先查询之前物流信息 $result = $this->apismt->get_editout($obtain['logistics_no'],$y['whlabel'],'all',$v['orderinfo'],$obtain['service_name'],$ex['servicetitle'],$shop['code']); if($result['result_success'] == 'true') { $this->$fullorder_name->save(array('dlz'=>1),$v['id']); } } } if ($this->db->trans_status() === TRUE) { $this->db->trans_commit(); } else { $this->db->trans_rollback(); } } else { $this->$fullorder_name->save(array('dlz'=>2),$y['id']); } } else //未发货声明状态 { $result = $this->apismt->get_out($y['whlabel'],'all',$y['orderinfo'],$ex['servicetitle'],$shop['code']); $shop = $this->shop->read($y['shop']); $go = $this->notice->get_go($y,$shop,'logisticstatus',1);//速卖通发送订单留言:已揽收 $go = ($go==1)?'揽收留言发送成功':'揽收留言发送失败'; //速卖通出库后状态需要改为209:买家待收货状态 if($result['result_success'] == 'true') { $this->db->trans_begin(); $this->$fullorder_name->save(array('dlz'=>1,'fscontent'=>$go,'state'=>209),$y['id']); if($y['merge'] != '0') { $hdata = $this->$fullorder_name->find_all("merge = '".$y['merge']."' and id != '".$y['id']."'"); foreach ($hdata as $v) { $result = $this->apismt->get_out($y['whlabel'],'all',$v['orderinfo'],$ex['servicetitle'],$shop['code']); $go = $this->notice->get_go($v,$shop,'logisticstatus',1);//速卖通发送订单留言:已揽收 $go = ($go==1)?'揽收留言发送成功':'揽收留言发送失败'; if($result['result_success'] == 'true') { $this->$fullorder_name->save(array('dlz'=>1,'fscontent'=>$go,'state'=>209),$v['id']); } } } if ($this->db->trans_status() === TRUE) { $this->db->trans_commit(); } else { $this->db->trans_rollback(); } } else { $this->$fullorder_name->save(array('dlz'=>2,'fscontent'=>$go,'state'=>209),$y['id']); } } } $sp = $this->shop->read($y['shop']); $this->notice->get_go($y,$sp,'ordertatus',209);//通知消息模板,是否有已发货需要发送内容 } else { echo json_encode(array('msg'=>'出库失败,请重试','success'=>false));exit; } } if(isset($post['page'])) { $page = $this->input->post('page',true); $perpage = $this->input->post('perpage',true); $timetk = $this->input->post('timetk',true); $timetj = $this->input->post('timetj',true); $shop = $this->input->post('shop',true); $source = $this->input->post('source',true); $orderinfo = $this->input->post('orderinfo',true); $number = $this->input->post('number',true); $library = $this->input->post('library',true); $waybill = $this->input->post('waybill',true); $express = $this->input->post('express',true); $type = $this->input->post('type',true); $lowe = $this->input->post('lowe',true); $librarytime = $this->input->post('librarytime',true); $timetk = strtotime($timetk); $timetj = strtotime($timetj); $cxtime = 'id'; $where = "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%'"; } //数据排序 $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->fullordersmt->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']).''; } } $total = $this->fullorder->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))); echo json_encode($rows);exit; } $this->data['express'] = $this->express->find_all(); $this->_Template('whlabel_fout',$this->data); } //退库 public function _retreat() { $post = $this->input->post(NULL, TRUE); if(isset($post['order'])) { $time = time(); $order = $this->input->post('order',true); $y = $this->fullorder->get_waybill($order); $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) { echo json_encode(array('msg'=>'无此数据','success'=>false));exit; } } } } if($y['library'] == 3) { echo json_encode(array('msg'=>'此数据 '.date('Y-m-d H:i:s',$y['retreattime']).' 已操作','success'=>false));exit; } if($y['library'] == 1) { echo json_encode(array('msg'=>'此数据未出库','success'=>false));exit; } if($y['type'] == 5) { $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'=>2,'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'])) { $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 = "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->fullordersmt->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']).''; } } $total = $this->fullorder->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))); echo json_encode($rows);exit; } $this->data['express'] = $this->express->find_all(); $this->_Template('whlabel_fout',$this->data); } //打印页面 public function _print() { $post = $this->input->post(NULL, TRUE); if(isset($post['page'])) { $page = $this->input->post('page',true); $perpage = $this->input->post('perpage',true); $timetk = $this->input->post('timetk',true); $timetj = $this->input->post('timetj',true); $shop = $this->input->post('shop',true); $print = $this->input->post('print',true); $express = $this->input->post('express',true); $waybill = $this->input->post('waybill',true); $printtype = $this->input->post('printtype',true); $orderinfo = $this->input->post('orderinfo',true); $number = $this->input->post('number',true); $type = $this->input->post('type',true); $lowe = $this->input->post('lowe',true); $timetk = strtotime($timetk); $timetj = strtotime($timetj); $where = "1=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 shipremarks like '%$lowe%'"; } //数据排序 $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,'id,shop,orderinfo,number,express,waybill,print,printtype,printnumber,printtime,shipremarks',$order_str,$start,$perpage); //格式化数据 foreach ($info_list as $key=>$value) { $shop = $this->shop->read($value['shop']); $info_list[$key]['shop'] = $shop['shopname']; $express = $this->express->read($value['express']); if($express) { $info_list[$key]['express'] = $express['servicename']; } else { $info_list[$key]['express'] = '未选择'; } if($value['printtime'] != 0) { $info_list[$key]['printtime'] = date('Y-m-d H:i:s',$value['printtime']); } else { $info_list[$key]['printtime'] = '无'; } if($value['print'] == 1) { $info_list[$key]['print'] = "禁止打印"; } else if($value['print'] == 2) { $info_list[$key]['print'] = "未打印"; } else if($value['print'] == 3) { $info_list[$key]['print'] = "已打印"; } if($value['printtype'] == 1) { $info_list[$key]['printtype'] = "运单"; } else if($value['printtype'] == 2) { $info_list[$key]['printtype'] = "发货单"; } else if($value['printtype'] == 0) { $info_list[$key]['printtype'] = "未选择"; } } $info_list_smt = $this->fullordersmt->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) { $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'] = "未选择"; } } $total = $this->fullorder->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))); echo json_encode($rows);exit; } $this->_Template('whlabel_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 = '';$time = time(); if($va[$n] < 100000) { $fullorder_name = 'fullordersmt'; } else { $fullorder_name = 'fullorder'; } $fullorder = $this->$fullorder_name->read($va[$n]); if(isset($va[$n+1])) { $sf = $this->$fullorder_name->read($va[$n+1]); if($sf['printtype'] == 1 && $fullorder['printtype'] == 2) { sleep(9); } } $fullorder = $this->_text($fullorder);//获取所需信息 $fullorder['printtime'] = date('Y-m-d H:i',$time);//打印用时间 if($fullorder['printtype'] == 1 && $fullorder['library'] != 2) { if($fullorder['servicecode'] == "DHLGF")//如果打印过那么重新获取运单 { sleep(3); $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']; } $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),$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['servicecode'] == "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']; } $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),$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]); } $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(4); $fullorder['printnumber'] = $fullorder['printnumber'] +1;//不能删 if($this->$fullorder_name->save(array('libraryconfirm'=>2,'librarynot'=>'','printtime'=>$time,'printnumber'=>$fullorder['printnumber'],'print'=>3),$va[$n])) { $type = 2; $text = array('data'=>$fullorder); } $rows = array('type'=>$type,'n'=>$n-1,'data'=>$v,'text'=>$text); echo json_encode(array('rows'=>($rows),'success'=>true));exit; } else { $rows = array('type'=>$type,'n'=>$n-1,'data'=>$v,'text'=>$text); echo json_encode(array('msg'=>'该订单已出库,无法打印!','success'=>false));exit; } } } public function _excel() { if(isset($_GET['fexcel'])) { $dowid = $this->input->get('a'); $wid = ""; if($dowid != "") { $id_arr = explode(',',rtrim($dowid,',')); foreach ($id_arr as $v) { $wid .= " id = 0 or"; $wid .= " id = '$v' or"; } $wid = " and".rtrim($wid,'or'); } $t = $this->input->get('t',true); $timetk = $this->input->get('timetk',true); $timetj = $this->input->get('timetj',true); $shop = $this->input->get('shop',true); $source = $this->input->get('source',true); $orderinfo = $this->input->get('orderinfo',true); $number = $this->input->get('number',true); $library = $this->input->get('library',true); $waybill = $this->input->get('waybill',true); $express = $this->input->get('express',true); $timetk = strtotime($timetk); $timetj = strtotime($timetj); $where = "library!=3 and libraryconfirm=2 and mergeid = 0 and print = 3"; if($timetk && $timetj && $library == 2) { $where .= " and librarytime > '$timetk' and librarytime < '$timetj'"; } if($shop) { $where .= " and shop = '$shop'"; } if($number) { $where .= " and number = '$number'"; } if($library) { $where .= " and library = '$library'"; } if($waybill) { $where .= " and waybill = '$waybill'"; } if($express) { $where .= " and express = '$express'"; } if($orderinfo) { $where .= " and orderinfo = '$orderinfo'"; } //数据排序 $order_str = ($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',$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_list_smt = $this->fullordersmt->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 = "".$t."
"; $tail = "\n"; $filename = $title.".xls"; $this->excel->get_fz2(array_merge($info_list,$info_list_smt),$titlename,$filename,$tail); } } public function _fhd($arg_array) { if(isset($arg_array[0])) { $fullorder = $this->fullorder->read($arg_array[0]); $fullorder = $this->_text($fullorder);//获取所需信息 $this->data['data'] = $fullorder; $this->_Template('apt_fhd',$this->data); } } public function _fhdusa($arg_array) { if(isset($arg_array[0])) { if($arg_array[0] < 100000) { $fullorder_name = 'fullordersmt'; } else { $fullorder_name = 'fullorder'; } $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'];//订单国家名 $express = $this->express->read($fullorder['express']); $fullorder['express'] = $express['servicename']; $fullorder['account'] = $express['account']; $fullorder['servicecode'] = $express['servicecode']; $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']); $shop = $this->shop->read($fullorder['shop']); $fullorder['shop'] = $shop['shopname']; return $fullorder; } 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 _express() { $post = $this->input->post(NULL, TRUE); if(isset($post['express'])) { $express = $this->express->find_all(); 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; } }