load->library('session');
$this->load->_model('Model_fullorder','fullorder');
$this->load->_model('Model_fullordertt','fullordertt');
$this->load->_model('Model_fullorderxw','fullorderxw');
$this->load->_model('Model_fullorder_smt','fullorder_smt');
$this->load->_model('Model_fullordersmt','fullordersmt');
$this->load->_model('Model_fullorderamz','fullorderamz');
$this->load->_model('Model_fullorderexcel','fullorderexcel');
$this->load->_model('Model_fullorderexcelclassid','fullorderexcelclassid');
$this->load->_model('Model_shop','shop');
$this->load->_model('Model_country','country');
$this->load->_model('Model_warehouse','warehouse');
$this->load->_model('Model_excel','excel');
$this->load->_model('Model_notice','notice');
$this->load->_model('Model_express','express');
$this->load->_model('Model_api','api');
$this->load->_model('Model_apismt','apismt');
$this->load->_model('Model_usps','usps');
$this->load->_model('Model_typeclass','typeclass');
$this->load->_model('Model_systemwigsout','systemwigsout');
$this->load->_model('Model_setting','setting');
$this->load->_model('Model_customer','customer');
$this->load->_model('Model_customersmt','customersmt');
$this->load->_model('Model_orderurl','orderurl');
$this->load->_model('Model_whlabel','whlabel');
$this->load->_model('Model_whlabel_bh','whlabel_bh');
$this->load->_model('Model_apiyy','apiyy');
$this->load->_model('Model_classid','classid');
$this->load->_model('Model_systemtransfer','systemtransfer');
$this->load->_model('Model_transfer','transfer');
$this->load->_model('Model_classid','classid');
$this->load->_model('Model_whlabel_type','whlabel_type');
$this->load->_model('Model_power','power');
$this->load->_model('Model_productdescribe','productdescribe');
$this->load->_model('Model_shopsku','shopsku');
$this->load->_model('Model_is','is');
$this->load->_model('Model_whlabel_qh','whlabel_qh');
$this->load->_model('Model_emaildata','emaildata');
$this->load->_model('Model_afspaypal','afspaypal');
$this->load->_model('Model_producttitle','producttitle');
$this->load->_model('Model_message','message');
}
//定义方法的调用规则 获取URI第二段值
public function _remap($arg,$arg_array)
{
if($arg == 'excel')
{
$this->_excel();
}
else if($arg == 'add')
{
$this->_add();
}
else if($arg == 'edit')
{
$this->_edit($arg_array);
}
else if($arg == 'copy'){
$this->_copy($arg_array);
}
else if($arg == 'del')
{
$this->_del();
}
else if($arg == 'rows')
{
$this->_rows();
}
else if($arg == 'waybill')
{
$this->_waybill($arg_array);
}
else if($arg == 'order')
{
$this->_order($arg_array);
}
else if($arg == 'xxpl')//线下批量导入
{
$this->_xxpl();
}
else if($arg == 'skuzh')//sku转中文
{
$this->_skuzh();
}
else if($arg == 'cs')
{
$this->_cs();
}
else if($arg == 'scwd')
{
$this->_scwd();
}
else if($arg == 'jmexcel')
{
$this->_jmexcel();
}
else if($arg == 'classid')
{
$this->_classid();
}
else if($arg == 'classidadd')
{
$this->_classidadd();
}
else if($arg == 'classidedit')
{
$this->_classidedit($arg_array);
}
else
{
$this->_index();
}
}
//管理
public function _index()
{
$post = $this->input->post(NULL, TRUE);
if(isset($post['page']))
{
$page = $this->input->post('page',true);
$perpage = $this->input->post('perpage',true);
$type = $this->input->post('type',true);
$where = "1=1 ";
//数据排序
$order_str = "id asc";
if(empty($page))
{
$start = 0;
$perpage = 1;
}
else
{
$start = ($page - 1)*$perpage;
}
if($type)
{
$where .= " and type = '$type'";
}
//取得信息列表
$info_list = $this->fullorderexcel->find_all($where,'id,type,title',$order_str,$start,$perpage);
foreach ($info_list as $k=>$v)
{
$classid = $this->fullorderexcelclassid->read($v['type']);
$info_list[$k]['type'] = $classid['title'];
$info_list[$k]['action'] = "复制表格";
}
$total = $this->fullorderexcel->find_count($where);
$pagenum = ceil($total/$perpage);
$over = $total-($start+$perpage);
$rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
echo json_encode($rows);exit;
}
$classid = $this->fullorderexcelclassid->find_all();
$this->data['classid'] = $classid;
$this->_Template('fullorderexcel',$this->data);
}
//添加
public function _add()
{
$post = $this->input->post(NULL, TRUE);
if(isset($post['title']))
{
$post['title'] = $this->input->post('title',true);
$post['type'] = $this->input->post('type',true);
$post['content'] = $this->input->post('content',true);
$post['contentzh'] = $this->input->post('contentzh',true);
$addid = $this->fullorderexcel->insert($post);
if($addid)
{
$adminid = $this->power->read(1);
$this->power->save(array("excelid"=>$adminid['excelid'].$addid.'|',"exceltext"=>$adminid['exceltext'].$post['title'].'|'),$adminid['id']);
echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
}
else
{
echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
}
}
$classid = $this->fullorderexcelclassid->find_all();
$this->data['classid'] = $classid;
$this->_Template('fullorderexcel_add',$this->data);
}
//修改
public function _edit($arg_array)
{
$post = $this->input->post(NULL, TRUE);
if(isset($post['id']))
{
$id = $this->input->post('id',true);
$post['title'] = $this->input->post('title',true);
$post['type'] = $this->input->post('type',true);
$post['content'] = $this->input->post('content',true);
$post['contentzh'] = $this->input->post('contentzh',true);
if($this->fullorderexcel->save($post,$id))
{
echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
}
else
{
echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
}
}
$arg_array = $arg_array[0];
$fullorderexcel = $this->fullorderexcel->read($arg_array);
$this->data['fullorderexcel'] = $fullorderexcel;
$classid = $this->fullorderexcelclassid->find_all();
$this->data['classid'] = $classid;
$this->_Template('fullorderexcel_edit',$this->data);
}
public function _copy($arg_array)
{
$post = $this->input->post(NULL, TRUE);
if(isset($post['id']))
{
$post['title'] = $this->input->post('title',true);
$post['type'] = $this->input->post('type',true);
$post['content'] = $this->input->post('content',true);
$post['contentzh'] = $this->input->post('contentzh',true);
unset($post['id']);
$addid =$this->fullorderexcel->insert($post);
if($addid)
{
$adminid = $this->power->read(1);
$this->power->save(array("excelid"=>$adminid['excelid'].$addid.'|',"exceltext"=>$adminid['exceltext'].$post['title'].'|'),$adminid['id']);
echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
}
else
{
echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
}
}
$arg_array = $arg_array[0];
$fullorderexcel = $this->fullorderexcel->read($arg_array);
$this->data['fullorderexcel'] = $fullorderexcel;
$classid = $this->fullorderexcelclassid->find_all();
$this->data['classid'] = $classid;
$this->_Template('fullorderexcel_copy',$this->data);
}
//删除
public function _del()
{
$post = $this->input->post(NULL, TRUE);
if(isset($post['s']))
{
$id_arr = $this->input->post('s');
$id_arr = explode(',',$id_arr);
if(!$id_arr)
{
echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
}
//循环删除记录
foreach ($id_arr as $v)
{
$this->fullorderexcel->remove($v);
}
echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
}
}
//获取数据
public function _rows()
{
$post = $this->input->post(NULL, TRUE);
if(isset($post['id']))
{
$id = $this->input->post('id',true);
$fullorderexcel = $this->fullorderexcel->read($id);
$content = explode('|',rtrim($fullorderexcel['content'],'|'));
$contentzh = explode('|',rtrim($fullorderexcel['contentzh'],'|'));
$data = array();
for($i=0;$i$a[1],1=>$b[1]);
}
echo json_encode(array('rows'=>($data),'success'=>true));
}
}
//导出订单excel
public function _excel()
{
if(isset($_SESSION['api']))
{
$user = $this->user->get_api($_SESSION['api']);
$usp = $user;
$fgshop = "";$sid = "";$excelshop="";
$usersp = explode('|',trim($user['shop'],'|'));
foreach ($usersp as $value)
{
$fgshop .= " shop = ".$value." or";
$sid .= " id = ".$value." or";
}
$userexcel = explode('|',trim($user['excelshop'],'|'));
if($user['excelshop'] == '')
{
echo "没有下载权限";exit;
}
foreach ($userexcel as $value)
{
$excelshop .= " shop = ".$value." or";
}
if($excelshop != "")
{
$excelshop = "(".rtrim($excelshop,'or').")";
}
}
if(isset($_GET['fexcel']))
{
$typeclass = array();
$tclass = $this->typeclass->find_all();
foreach ($tclass as $v)
{
$typeclass[$v['id']] = $v;
}
$dowid = $this->input->get('a');
$wid = "";
if($dowid != "")
{
$id_arr = explode(',',rtrim($dowid,','));
$wid .= " id = 0 or";
foreach ($id_arr as $v)
{
$wid .= " id = '$v' or";
}
$wid = " and".rtrim($wid,'or');
}
$fexcel = $this->input->get('fexcel',true);
$page = $this->input->get('page',true);
$perpage = $this->input->get('perpage',true);
$warehouse = $this->input->get('warehouse',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);
$state = $this->input->get('state',true);
$review = $this->input->get('review',true);
$type = $this->input->get('type',true);
$express = $this->input->get('express',true);
$orderinfo = $this->input->get('orderinfo',true);
$user = $this->input->get('user',true);
$client = $this->input->get('name',true);
$waybill = $this->input->get('waybill',true);
$number = $this->input->get('number',true);
$email = $this->input->get('email',true);
$dlz = $this->input->get('dlz',true);
$library = $this->input->get('library',true);
$libraryconfirm = $this->input->get('libraryconfirm',true);
$print = $this->input->get('print',true);
$timetkk = $this->input->get('timetkk',true);
$timetjj = $this->input->get('timetjj',true);
$xztime = $this->input->get('xztime',true);
$country = $this->input->get('country',true);
$zf = $this->input->get('zf',true);
$pay = $this->input->get('pay',true);
$phone = $this->input->get('phone',true);
$so = $this->input->get('so',true);
$sfxh = $this->input->get('sfxh',true);
$xdcs = $this->input->get('xdcs',true);
$xdcs = $this->input->get('xdcs',true);
$dbapi = $this->input->get('dbapi',true);
$orderurl = $this->input->get('orderurl',true);
$timetk = strtotime($timetk);
$timetj = strtotime($timetj);
$timetkk = strtotime($timetkk);
$timetjj = strtotime($timetjj);
$px = $this->input->get('px',true);
$fexcel = $this->fullorderexcel->read($fexcel);
$classid = $this->fullorderexcelclassid->read($fexcel['type']);
$where = "1 = 1 and (".rtrim($fgshop,'or').")";
if($warehouse)
{
$where .= " and type = '$warehouse'";
}
if($xztime)
{
if($timetk && $timetj)
{
$where .= " and ".$xztime." > '$timetk' and ".$xztime." < '$timetj'";
}
if($timetkk && $timetjj)
{
$where .= " and ".$xztime." > '$timetkk' and ".$xztime." < '$timetjj'";
}
}
else
{
$where .= " and dtime > '$timetk' and dtime < '$timetj'";
}
if($library)
{
$where .= " and library = '$library'";
}
if($print)
{
$where .= " and print = '$print'";
}
if($shop)
{
$where .= " and shop = '$shop'";
}
if($source)
{
if($source == '2d')
{
$where .= " and source >= '2'";
}
else
{
$where .= " and source = '$source'";
}
}
if($state)
{
$where .= " and state = '$state'";
}
if($review)
{
$where .= " and review = '$review'";
}
if($type)
{
$where .= " and type = '$type'";
}
if($express)
{
$where .= " and express = '$express'";
}
if($orderinfo)
{
$where .= " and orderinfo = '$orderinfo'";
}
if($user)
{
$where .= " and user = '$user'";
}
if($client)
{
$where .= " and client like '%$client%'";
}
if($waybill)
{
$where .= " and waybill = '$waybill'";
}
if($number)
{
$where .= " and number = '$number'";
}
if($email)
{
$where .= " and email = '$email'";
}
if($country)
{
$where .= " and country = '$country'";
}
if($dlz)
{
$where .= " and waybill != '' and dlz = 0";
}
if($libraryconfirm)
{
$where .= " and libraryconfirm = '$libraryconfirm'";
}
if($so)
{
$where .= " and shipremarks like '%$so%'";
}
if($pay)
{
$where .= " and pay = '$pay'";
}
if($phone)
{
$where .= " and phone = '$phone'";
}
if($sfxh != '')
{
$where .= " and sfxh = '$sfxh'";
}
if($orderurl)
{
$url = $this->orderurl->read($orderurl);
$where .= " and link like '%".$url['url']."%'";
}
if($zf)
{
if($zf == 1)
{
$where .= " and paypal not like '%-%-%-%'";
}
else
{
$where .= " and paypal like '%-%-%-%'";
}
}
$sj = $this->input->get('sj',true);
if($sj)
{
$sj = $this->input->get('sj',true);
}
else
{
$sj = $classid['type'];
}
$fexceleq = explode("|",rtrim($fexcel['content'],'|'));
foreach ($fexceleq as $k=>$v)
{
$fexceleq[$k] = explode('-',$v);
$num[$k] = $fexceleq[$k][0];
}
//array_multisort($num,SORT_ASC,$fexceleq);//重新排序
$feq = "";$kong = array();$sku9610 = '';
foreach ($fexceleq as $k=>$v)
{
if(isset($v[1]))
{
if($v[1] == 'klarnabill' || $v[1] == 'klarnaship' || $v[1] == 'PPname' || $v[1] == 'PPaddress' || $v[1] == 'PPemail' || $v[1] == 'afterpayship' || $v[1] == 'afterpaybill')
{
$feq .= 'klarnadata,';
}
if($v[1] == 'ccfpdata' || $v[1] == 'cpfpdata' || $v[1] == 'dbapi' || $v[1] == 'scapi')
{
$feq .= 'fpdata,';
}
if($v[1] != 'kong')//空值去除
{
if($v[1] == '9610sku' || $v[1] == 'issku' || $v[1] == 'sku')
{
if($v[1] == '9610sku')
{
$sku9610 = 1;
}
if($sj == 'fullordersmt')
{
$v[1] = 'sku';
}
else
{
$v[1] = 'issku';
}
}
$feq .= $v[1].',';
}
else
{
$kong[$v[0]] = 1;
}
}
}
//处理额外加上的subtotal和rowtoal 但是不想在表中加太多字段 想着以后有关金额的都给怼到extra_price字段中
if((strpos($feq,'subtotal')!= false)||(strpos($feq,'rowtotal')!= false)){
if(strpos($feq,'subtotal')!= false){
$feq = str_replace('subtotal,',"extra_price as subtotal,",$feq);
}
if(strpos($feq,'rowtotal')!= false){
$feq = str_replace('rowtotal,',"extra_price as rowtotal,",$feq);
}
}
$feq = rtrim($feq,',');
$fexcelzhw = explode('|',rtrim($fexcel['contentzh'],'|'));
foreach ($fexcelzhw as $k=>$v)
{
$fexcelzhw[$k] = explode('-',$v);
$numb[$k] = $fexcelzhw[$k][0];
}
//array_multisort($numb,SORT_ASC,$fexcelzhw);//重新排序
$fexcelzh = array();
foreach ($fexcelzhw as $k=>$v)
{
$fexcelzh[] = $v[1];
}
if($px)
{
$order_str = $px." desc";
}
else
{
$order_str = "id desc";
}
//取得信息列表
$info_list = $this->$sj->find_all($where.$wid.' and '.$excelshop,'id,'.$feq,$order_str);
//格式化数据
$i = 1;$shouldmoney = 0;$hl=1;
foreach ($info_list as $key=>$value)
{
$data = $this->$sj->read($value['id']);
$data = str_replace(array("'"),array("’"),$data);
if(isset($value['email']) && $usp['excelpass'] == '1')
{
$emailpass = $this->setting->get_excelpass($value['email']);
$info_list[$key]['email'] = $emailpass;
}
if(isset($value['phone']) && $usp['excelpass'] == '1')
{
$phonepass = $this->setting->get_excelpass($value['phone']);
$info_list[$key]['phone'] = $phonepass;
}
if(isset($value['currencytitle']))
{
if($value['currencytitle'] != "CNY")
{
$hl=$value['hl'];
}
$shouldmoney=$shouldmoney+($value['shouldmoney']*$hl);
$budget=$budget+($value['budget']*$hl);
$currency=$currency+(($value['shouldmoney']-$value['budget'])*$hl);
$refund=$refund+($value['refund']*$hl);
}
if(isset($value['shop']))
{
$shop = $this->shop->read($value['shop']);
$info_list[$key]['shop'] = $shop['shopname'];
}
if(isset($value['dtime']))
{
$info_list[$key]['dtime'] = date('Y-m-d H:i:s',$value['dtime']);
}
if(isset($value['printtime']))
{
if($value['printtime'] > 0)
{
$info_list[$key]['printtime'] = date('Y-m-d H:i:s',$value['printtime']);
}
}
if(isset($value['sku']))
{
if($sku9610 == '1')
{
$aesku = explode(';',$value['sku']);
$aesku = $aesku[0];
$aesku = explode(':',$aesku);
if(count($aesku) > 1)
{
$aesku = $aesku[1];
$aesku = str_replace('--','~',$aesku);
$aesku = explode('-',$aesku);
$aesku = $aesku[0];
$aesku = str_replace('~','--',$aesku);
$info_list[$key]['sku'] = $aesku;
}
else
{
$info_list[$key]['sku'] = '';
}
}
else
{
$info_list[$key]['sku'] = $value['sku'];
}
}
if(isset($value['issku']))
{
$value['issku'] = str_replace(array('<','>'),array('<','>'),$value['issku']);
if($sku9610 == '1')
{
$aesku = explode(';',$value['issku']);
$aesku = $aesku[0];
$aesku = str_replace('--','~',$aesku);
$aesku = explode('-',$aesku);
$aesku = $aesku[0];
$aesku = str_replace('~','--',$aesku);
$aesku = str_replace(array('<','>'),array('<','>'),$aesku);
$info_list[$key]['issku'] = $aesku;
}
else
{
$value['issku'] = str_replace(array('<','>'),array('<','>'),$value['issku']);
$info_list[$key]['issku'] = $value['issku'];
}
}
if(isset($value['subtotal'])){
$tmp_sub_str = "";
$subtotal_list = json_decode($value['subtotal'],true);
foreach($subtotal_list as $v){
if(isset($v['sub_total'])){
$tmp_sub_str .= sprintf( "%.2f",$v['sub_total'])."
";
}else{
$tmp_sub_str .= "0
";
}
}
$info_list[$key]['subtotal'] = $tmp_sub_str;
}
if(isset($value['rowtotal'])){
$tmp_sub_str = "";
$subtotal_list = json_decode($value['rowtotal'],true);
foreach($subtotal_list as $v){
if(isset($v['row_total'])){
$tmp_sub_str .= sprintf( "%.2f",$v['row_total'])."
";
}else{
$tmp_sub_str .= "0
";
}
}
$info_list[$key]['rowtotal'] = $tmp_sub_str;
}
if(isset($value['librarytime']))
{
if($value['librarytime'] > 0)
{
$info_list[$key]['librarytime'] = date('Y-m-d H:i:s',$value['librarytime']);
}
}
if(isset($value['buytime']))
{
if($value['buytime'] > 0)
{
$info_list[$key]['buytime'] = date('Y-m-d H:i:s',$value['buytime']);
}
}
if(isset($value['country']))
{
$country = $this->country->read($value['country']);
$info_list[$key]['country'] = $country['name'];
}
if(isset($value['street']))//暂时用街道导出州二字码
{
if($data['country'] == 192)//如果是美国
{
$ToState = array('alabama'=>'AL','alaska'=>'AK','arizona'=>'AZ','arkansas'=>'AR','california'=>'CA','colorado'=>'CO','connecticut'=>'CT','delaware'=>'DE','florida'=>'FL','georgia'=>'GA','hawaii'=>'HI','idaho'=>'ID','illinois'=>'IL','indiana'=>'IN','iowa'=>'IA','kansas'=>'KS','kentucky'=>'KY','louisiana'=>'LA','maine'=>'ME','maryland'=>'MD','massachusetts'=>'MA','michigan'=>'MI','minnesota'=>'MN','mississippi'=>'MS','missouri'=>'MO','montana'=>'MT','nebraska'=>'NE','nevada'=>'NV','new hampshire'=>'NH','new jersey'=>'NJ','new mexico'=>'NM','new york'=>'NY','north carolina'=>'NC','north dakota'=>'ND','ohio'=>'OH','oklahoma'=>'OK','oregon'=>'OR','pennsylvania'=>'PA','rhode island'=>'RI','south carolina'=>'SC','south dakota'=>'SD','tennessee'=>'TN','texas'=>'TX','utah'=>'UT','vermont'=>'VT','virginia'=>'VA','washington'=>'WA','west virginia'=>'WV','wisconsin'=>'WI','wyoming'=>'WY','district of columbia'=>'DC','virgin islands'=>'VI');
$data['province'] = preg_replace('/( | |\s)/',' ',$data['province']);
$data['province'] = trim($data['province'],' ');
if(isset($ToState[strtolower($data['province'])]))
{
$dataprovince = strlen($data['province'])==2?$data['province']:$ToState[strtolower($data['province'])];
}
else
{
$dataprovince = '';
}
$info_list[$key]['street'] = $dataprovince;
}
else
{
$info_list[$key]['street'] = '';
}
}
if(isset($value['pay']))
{
$pay = $this->typeclass->read($value['pay']);
$info_list[$key]['pay'] = $pay['title'];
}
if(isset($value['type']))
{
$type = $this->warehouse->read($value['type']);
$info_list[$key]['type'] = $type['title'];
}
if(isset($value['express']))
{
$express = $this->express->read($value['express']);
if($express)
{
$info_list[$key]['express'] = $express['servicename'];
}
else
{
$info_list[$key]['express'] = '未选择';
}
}
if(isset($value['ccfpdata']))
{
$ccfpdata = explode(';',$value['fpdata']);
$inc = 0;
foreach ($ccfpdata as $v)
{
if(stripos($v,',') !== false)
{
$cc = explode(',',$v);
$inctype = $this->typeclass->read($cc[0]);
if(is_numeric($inctype['spare']))
{
if($inctype['spare'] > $inc)
{
$inc = $inctype['spare'];
}
}
}
}
$info_list[$key]['ccfpdata'] = $inc.'inch';
}
if(isset($value['printtype']))
{
if($value['printtype'] == 1)
{
$info_list[$key]['printtype'] = '运单';
}
else if($value['printtype'] == 2)
{
$info_list[$key]['printtype'] = '发货单';
}
else if($value['printtype'] == 3)
{
$info_list[$key]['printtype'] = '不打印单据';
}
else
{
$info_list[$key]['printtype'] = '未选择';
}
}
if(isset($value['exstate']))
{
if($value['exstate'] == '99')
{
$info_list[$key]['exstate'] = '未获取到物流信息';
}
else if($value['exstate'] == '1')
{
$info_list[$key]['exstate'] = '已揽收';
}
else if($value['exstate'] == '2')
{
$info_list[$key]['exstate'] = '在途中';
}
else if($value['exstate'] == '3')
{
$info_list[$key]['exstate'] = '派送中';
}
else if($value['exstate'] == '4')
{
$info_list[$key]['exstate'] = '已签收';
}
else if($value['exstate'] == '5')
{
$info_list[$key]['exstate'] = '派送异常';
}
else
{
$info_list[$key]['exstate'] = '';
}
}
if(isset($value['link']))
{
if($value['link'] != '')
{
$link = explode(',',$value['link']);
$info_list[$key]['link'] = $link[0];
}
else
{
$info_list[$key]['link'] = '';
}
}
if(isset($value['klarnabill']))
{
$klarnadata = explode('|',$value['klarnadata']);
if(isset($klarnadata[2]))
{
$info_list[$key]['klarnabill'] = $klarnadata[2];
}
else
{
$info_list[$key]['klarnabill'] = '';
}
}
if(isset($value['klarnaship']))
{
$klarnadata = explode('|',$value['klarnadata']);
if(isset($klarnadata[3]))
{
$info_list[$key]['klarnaship'] = $klarnadata[3];
}
else
{
$info_list[$key]['klarnaship'] = '';
}
}
if(isset($value['afterpaybill']))
{
$klarnadata = explode('|',$value['klarnadata']);
if(isset($klarnadata[1]))
{
$info_list[$key]['afterpaybill'] = $klarnadata[1];
}
else
{
$info_list[$key]['afterpaybill'] = '';
}
}
if(isset($value['afterpayship']))
{
$klarnadata = explode('|',$value['klarnadata']);
if(isset($klarnadata[2]))
{
$info_list[$key]['afterpayship'] = $klarnadata[2];
}
else
{
$info_list[$key]['afterpayship'] = '';
}
}
if(isset($value['PPname']))
{
$info_list[$key]['PPname'] = '';
$klarnadata = explode('|',$value['klarnadata']);
if(isset($klarnadata[1]))
{
$klarnadata = json_decode($klarnadata[1],true);
if(isset($klarnadata['name']))
{
$info_list[$key]['PPname'] = $klarnadata['name'];
}
}
}
if(isset($value['PPemail']))
{
$info_list[$key]['PPemail'] = '';
$klarnadata = explode('|',$value['klarnadata']);
if(isset($klarnadata[1]))
{
$klarnadata = json_decode($klarnadata[1],true);
if(isset($klarnadata['email']))
{
if($usp['excelpass'] == '1')
{
$ppemailpass = $this->setting->get_excelpass($klarnadata['email']);
}
else
{
$ppemailpass = $klarnadata['email'];
}
$info_list[$key]['PPemail'] = $ppemailpass;
}
}
}
if(isset($value['PPaddress']))
{
$info_list[$key]['PPaddress'] = '';
$klarnadata = explode('|',$value['klarnadata']);
if(isset($klarnadata[1]))
{
$klarnadata = json_decode($klarnadata[1],true);
if(isset($klarnadata['address']))
{
$info_list[$key]['PPaddress'] = $klarnadata['address'];
}
}
}
if(isset($value['klarnadata']))
{
unset($info_list[$key]['klarnadata']);
}
if(isset($value['shippingmethod']))
{
$tax = explode('Tax:',$value['shippingmethod']);
$info_list[$key]['shippingmethod'] = (isset($tax[1]))?trim($tax[1],';'):'';
}
if(isset($value['systemwigsout']))
{
$out = $this->systemtransfer->find_all("number = '".$data['number']."'");
$outread = '';
if($out)
{
foreach ($out as $val)
{
$list = '';
$rk = explode('|',trim($val['rk'],'|'));
$rktime = explode('|',trim($val['rktime'],'|'));
$zw = array();
$t = $this->transfer->find_all("1=1");
foreach ($t as $v)
{
$zw[$v['id']] = $v['title'];
}
if($val['rk'] != '' && count($rk) > 0)
{
for($i=0;$i:'.$list.'
';
}
}
else
{
$systemwigsout = $this->systemwigsout->find_all("number = '".$data['number']."'");
if($systemwigsout)
{
foreach ($systemwigsout as $v)
{
$outread = '';
if($v['czwarehouse'] == 37)
{
$outread .= '华荣厂';
}
else if($v['czwarehouse'] == 0)
{
$outread .= '龙盈厂';
}
$cz = explode('|',trim($v['cz'],'|'));
$cztime = explode('|',trim($v['cztime'],'|'));
$zw = $this->transfer->get_list();
if($v['cz'] != '' && count($cz) > 0)
{
for($i=0;$iwarehouse->read($value['type']);
$info_list[$key]['type'] = $type['title'];
}
if(isset($value['xdcs']))
{
if($sj == 'fullorder')
{
$xdcs = $this->customer->get_email($data['email'],$data['shop']);
}
else
{
$xdcs = $this->customersmt->get_shopdata($data['shop'],$data['name'],$data['address']);
}
$info_list[$key]['xdcs'] = (isset($xdcs['num']))?(($xdcs['num']==0)?1:$xdcs['num']):1;
}
if(isset($value['dbapi']) || isset($value['scapi']))
{
$jmlist = '';$shuliang = '';
$classid = $this->classid->sku();
$dbapi = explode(';',trim($value['fpdata'],';'));
foreach ($dbapi as $va)
{
$pm = $classid;
$jm = $classid;
$bmpx = array(13=>'',16=>'',18=>'',25=>'',26=>'',41=>'');
$features = str_replace(array('-163-','-164-','-165-','-166-'),'-',$va);
$ts = explode('|',trim($features,'|'));
if(stripos($ts[0],',') !== false)
{
$ft = explode(',',$ts[0]);
$features = explode('-',trim($ft[1],'-'));
$features[] = $ft[0];
}
else
{
$features = explode('-',trim($ts[0],'-'));
}
foreach($features as $k=>$v)
{
if(isset($typeclass[$v]) && isset($bmpx[$typeclass[$v]['classid']]))
{
if($typeclass[$v]['bm'] != '')
{
$bmpx[$typeclass[$v]['classid']] = $typeclass[$v]['bm'];
}
}
if($v != 0 && isset($typeclass[$v]))
{
if($typeclass[$v]['classid'] == 13)
{
$dj = $typeclass[$v]['title'];
}
if($typeclass[$v]['classid'] == 8)
{
$ys = $typeclass[$v]['title'];
}
if($typeclass[$v]['classid'] == 15)
{
$hx = $typeclass[$v]['title'];
}
if(isset($pm[$typeclass[$v]['classid']]))
{
if($typeclass[$v]['title'] == '9A')
{
$pm[$typeclass[$v]['classid']] = '9A';
}
else if($typeclass[$v]['title'] == '10A')
{
$pm[$typeclass[$v]['classid']] = '10A';
}
else
{
$clzh = $typeclass[$v]['zh'];
if(stripos($typeclass[$v]['zh'],'|') !== false)
{
$clzh = explode('|',rtrim($typeclass[$v]['zh'],'|'));
$clzh = $clzh[0];
}
$pm[$typeclass[$v]['classid']] = $clzh;
}
}
if(isset($jm[$typeclass[$v]['classid']]))
{
if($typeclass[$v]['jm'])
{
$jm[$typeclass[$v]['classid']] = $typeclass[$v]['jm'];
}
}
}
}
$jm = array_filter($jm);//去除空值
$jm = implode("-",$jm);
$jmlist .= $jm.'
';
$shuliang .= (isset($ts[2])?$ts[2]:'未知').'
';
$pm = array_filter($pm);//去除空值
$zh = implode(" ",$pm);
$zh = preg_replace("/\r\n|\r|\n/",'',trim($zh,' '));
}
if(isset($value['dbapi']))
{
$info_list[$key]['dbapi'] = $jmlist;
}
else
{
$info_list[$key]['scapi'] = $shuliang;
}
}
if(isset($value['dbapi']) && isset($value['scapi']))
{
$jmlist = '';$shuliang = '';
$classid = $this->classid->sku();
$dbapi = explode(';',trim($value['fpdata'],';'));
foreach ($dbapi as $va)
{
$pm = $classid;
$jm = $classid;
$bmpx = array(13=>'',16=>'',18=>'',25=>'',26=>'',41=>'');
$features = str_replace(array('-163-','-164-','-165-','-166-'),'-',$va);
$ts = explode('|',trim($features,'|'));
if(stripos($ts[0],',') !== false)
{
$ft = explode(',',$ts[0]);
$features = explode('-',trim($ft[1],'-'));
$features[] = $ft[0];
}
else
{
$features = explode('-',trim($ts[0],'-'));
}
foreach($features as $k=>$v)
{
if(isset($typeclass[$v]) && isset($bmpx[$typeclass[$v]['classid']]))
{
if($typeclass[$v]['bm'] != '')
{
$bmpx[$typeclass[$v]['classid']] = $typeclass[$v]['bm'];
}
}
if($v != 0 && isset($typeclass[$v]))
{
if($typeclass[$v]['classid'] == 13)
{
$dj = $typeclass[$v]['title'];
}
if($typeclass[$v]['classid'] == 8)
{
$ys = $typeclass[$v]['title'];
}
if($typeclass[$v]['classid'] == 15)
{
$hx = $typeclass[$v]['title'];
}
if(isset($pm[$typeclass[$v]['classid']]))
{
if($typeclass[$v]['title'] == '9A')
{
$pm[$typeclass[$v]['classid']] = '9A';
}
else if($typeclass[$v]['title'] == '10A')
{
$pm[$typeclass[$v]['classid']] = '10A';
}
else
{
$clzh = $typeclass[$v]['zh'];
if(stripos($typeclass[$v]['zh'],'|') !== false)
{
$clzh = explode('|',rtrim($typeclass[$v]['zh'],'|'));
$clzh = $clzh[0];
}
$pm[$typeclass[$v]['classid']] = $clzh;
}
}
if(isset($jm[$typeclass[$v]['classid']]))
{
if($typeclass[$v]['jm'])
{
$jm[$typeclass[$v]['classid']] = $typeclass[$v]['jm'];
}
}
}
}
$jm = array_filter($jm);//去除空值
$jm = implode("-",$jm);
$jmlist .= $jm.'
';
$shuliang .= (isset($ts[2])?$ts[2]:'未知').'
';
$pm = array_filter($pm);//去除空值
$zh = implode(" ",$pm);
$zh = preg_replace("/\r\n|\r|\n/",'',trim($zh,' '));
}
$info_list[$key]['dbapi'] = $jmlist;
$info_list[$key]['scapi'] = $shuliang;
}
if(isset($value['cpfpdata']))
{
$fpread = '';
$cpfpdata = explode(';',trim($value['fpdata'],';'));
foreach ($cpfpdata as $v)
{
$va = explode('|',trim($v,'|'));
if(isset($va[1])){
$fpread .= $va[1].'; ';
}else{
$fpread .="合并单没有产品异常标记";
}
}
$info_list[$key]['cpfpdata'] = $fpread;
}
unset($info_list[$key]['id']);
unset($info_list[$key]['fpdata']);
}
$fzh = "";
foreach ($fexcelzh as $v)
{
$fzh .= "".$v." | ";
}
$data = array($shouldmoney.' CNY');
$title = $fexcel['title'].'-'.date('Ymd',time());
$titlename = "";
$tail = "\n";
$filename = $title.".xls";
$this->excel->get_fz5($info_list,$titlename,$filename,$tail,$kong);
}
}
//上传运单
public function _waybill($arg_array)
{
$readid = $arg_array[0];
$dataorder = array();$datashop = array();$dataex = array();$datack = array();
/* 订单加入键值-k */
$fdata = $this->fullorder->find_all('shop = "'.$readid.'" and dtime > "'.(time()-30*24*3600).'" and review > 4 and dlz < 1 and state = 207');
foreach ($fdata as $v)
{
$dataorder[$v['orderinfo']] = $v;
}
$sdata = $this->fullordersmt->find_all('shop = "'.$readid.'" and dtime > "'.(time()-30*24*3600).'" and review > 4 and state = 207 and (dlz < 1 or dlz = 3)');
foreach ($sdata as $v)
{
$dataorder[$v['orderinfo']] = $v;
}
$tdata = $this->fullordertt->find_all('shop = "'.$readid.'" and dtime > "'.(time()-30*24*3600).'" and review > 4 and state = 207 and (dlz < 1 or dlz = 3)');
foreach ($tdata as $v)
{
$dataorder[$v['orderinfo']] = $v;
}
$xdata = $this->fullorderxw->find_all('shop = "'.$readid.'" and dtime > "'.(time()-30*24*3600).'" and review > 4 and state = 207 and (dlz < 1 or dlz = 3)');
foreach ($xdata as $v)
{
$dataorder[$v['orderinfo']] = $v;
}
/* 订单加入键值-j */
/* 店铺加入键值-j */
$fshop = $this->shop->find_all('1=1');
foreach ($fshop as $v)
{
$datashop[$v['id']] = $v;
}
/* 店铺加入键值-k */
/* 快递加入键值-j */
$fex = $this->express->find_all('1=1');
foreach ($fex as $v)
{
$dataex[$v['id']] = $v;
}
/* 快递加入键值-k */
/* 仓库加入键值-k */
$fwh = $this->warehouse->find_all('1=1');
foreach ($fwh as $v)
{
$datack[$v['id']] = $v;
}
/* 仓库加入键值-j */
$fs = $this->notice->get_ordertatus(216);//216成功状态
if(is_numeric($readid) == false || $readid < 1)
{
echo json_encode(array('msg'=>'店铺信息错误!','success'=>true));exit;
}
$dir = '/data/excel/'.date('Ymd',time()).'/';
$config['upload_path'] = '.'.$dir ;
$config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
$config['allowed_types'] = 'xls|xlsx|csv';
$config['max_size'] = 10240;
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ($this->upload->do_upload('userfile'))
{
$full_path = $dir.$this->upload->data('file_name');
$fileName = '.' . $full_path;
if (!file_exists($fileName))
{
echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
}
else
{
require_once "./data/excel/PHPExcel/IOFactory.php";
$phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
$phpExcel->setActiveSheetIndex(0);// 设置为默认表
$sheetCount = $phpExcel->getSheetCount();// 获取表格数量
$row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
$column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
++$column;//如果列数大于26行
$list = array();
for ($i = 2; $i <= $row; $i++) // 行数循环
{
$data = array();
for ($c = 'A'; $c != $column; $c++) // 列数循环
{
$data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
}
$list[] = $data;
}
}
$i = 0;$j = 0;$ed = array();$cscs = array();
$this->db->trans_begin();
foreach ($list as $key=>$value)
{
$ddh = preg_replace('/\D/s','',$value['0']);
$ydh = preg_replace('/\W/s','',$value['1']);
$shop = $datashop[$readid];
if($shop['type'] == '269')
{
$orid = $readid.$ddh;
}
else
{
$orid = $ddh;
}
if(isset($dataorder[$orid]))
{
if($shop['type'] == 269)//独立站前缀需要添加ID
{
$time = time();
$xg = $dataorder[$orid];
$oldw = $xg['waybill'];
$ex = $dataex[$xg['express']];
$warehouse = $datack[$xg['type']];
$msg = $ydh;
$xg['waybill'] = $ydh;
$fs = $this->notice->find_all("shop = '".$xg['shop']."' and message = '1' and state = '1' and type = '4' and ktime < '$time' and jtime > '$time'");
if(isset($fs[0]))
{
$fs = $fs[0];
$fs['email'] = $this->emaildata->read($fs['email']);
if(($xg['dlzemail'] == 1 && $msg != $oldw) || $xg['dlzemail'] == 0)
{
$ck = $this->notice->get_god($xg,$shop,$ex,$fs);
if($ck == 1)
{
$ckemail = '邮件发送成功,';
$this->fullorder->save(array('dlzemail'=>1,'dlzemailtime'=>time()),$xg['id']);
}
}
}
if($msg != $oldw)
{
if($xg['source'] != 1)
{
$ms = $this->message->find_all("express like '%,".$xg['express'].",%'");
if(!isset($ms[0]))
{
$ms = $this->message->read(2);
}
else
{
$ms = $ms[0];
}
$ddh = substr($xg['orderinfo'],1);
$shopifyid = $xg['shopify'];
//独立站地址更新订单状态、物流信息
$shopname = $shop['brandname']; //店铺名
$buyername = $xg['bname']; //Bill Name
$email_call = $shop['shopid']; //发货人邮箱;
$phone = $shop['shopphone']; //发货人电话
$track_type = $ex['title']; //快递名称
$service = $ex['title']; //快递追踪名称
$track_link = $ex['url']; //快递查询网址
$logistics_number = $ydh; //运单号
$t= array('%buyername%','%email_call%','%track_type%','%service%','%track_link%','%logistics_number%','%shop%','%phone%','%jtime%');
$h= array($buyername,$email_call,$track_type,$service,$track_link,$logistics_number,$shopname,$phone,$ex['yjtime']);
$remark = str_replace($t,$h,$ms['content']);
@$gx = $this->api->get_gx($ddh,$ydh,$xg,$shop,$ex,$remark,$shopifyid);
}
else if($xg['source'] == 1)
{
$gx['res'] = 3;
$gx['state'] = 216;
}
}
else
{
$gx['res'] = $xg['dlz'];
$gx['state'] = $xg['state'];
}
$xg['iscode'] = $ex['title'];
$xg['url'] = $shop['shopname'];
@$chuanshu = $this->api->get_paypal($xg);
//$this->afspaypal->insert(array('number'=>$xg['number'],'cs'=>$chuanshu));
$this->fullorder->save(array('waybill'=>$msg,'state'=>$gx['state'],'dlz'=>$gx['res']),$xg['id']);
/**
$xg = $dataorder[$arg_array[0].$ddh];
$ex = $dataex[$xg['express']];
$warehouse = $datack[$xg['type']];
if($xg['source'] != 1 && $ex['iscode'] != 'Other' && $xg['state'] == '207')
{
//独立站地址更新订单状态、物流信息
$gx = $this->api->get_gx($ddh,$ydh,$xg,$shop,$ex,$xg['msg'],$xg['msg'],$dataorder[$orid]['shopify']);
if(!isset($gx['res']))
{
$ed[] = array($ddh.'-更新失败');
$j++;
continue;
}
$this->fullorder->save(array('waybill'=>$ydh,'dlz'=>$gx['res'],'state'=>$gx['state']),$xg['id']);
if($gx['res'] == 1 && $fs)
{
$ck = $this->_email($fs['content'],$xg,$warehouse['company']);
}
}
else if($xg['source'] == 1 && $xg['state'] == '207')
{
$this->fullorder->save(array('waybill'=>$ydh,'dlz'=>3,'state'=>216),$xg['id']);
if($fs)
{
$ck = $this->_email($fs['content'],$xg,$warehouse['company']);
}
}
else
{
$ed[] = array($ddh.'-状态错误');
$j++;
continue;
}
**/
}
else if($shop['type'] == 270)//速卖通对接发货声明
{
$xg = $dataorder[$ddh];
$ex = $dataex[$xg['express']];
$warehouse = $datack[$xg['type']];
if($xg['source'] != 1 && $ex['aecode'] != 'Other' && $xg['library'] == 2 && ($xg['dlz'] == '0' || $xg['dlz'] == '2'))
{
$result = $this->apismt->get_out($ydh,'all',$xg['orderinfo'],$ex['aecode'],$sp['code']);
if(isset($result['result_success']) && $result['result_success'] == "true")
{
$this->fullordersmt->save(array('waybill'=>$ydh,'state'=>209,'dlz'=>1),$xg['id']);
/** 合并信息处理开始-发货声明 **/
if($xg['merge'] != '0')
{
$hdata = $this->fullordersmt->find_all("merge = '".$xg['merge']."' and id != '".$xg['id']."' and dlz = '0' and source != 1");$l=0;
foreach ($hdata as $v)
{
$result = $this->apismt->get_out($ydh,'all',$v['orderinfo'],$ex['aecode'],$sp['code']);
if(isset($result['result_success']) && $result['result_success'] == "true")
{
$this->fullordersmt->save(array('waybill'=>$ydh,'state'=>209,'dlz'=>1),$v['id']);
}
else
{
$ed[] = array($v['orderinfo'].'-合并单发货声明失败,请在ERP上手动操作此单');
$j++;
continue;
}
$l++;
if($l > 10)
{
break;
}
}
}
/** 合并信息处理结束开始 **/
}
else
{
$ed[] = array($ddh.'-发货声明失败');
$j++;
continue;
}
}
else if($xg['source'] != 1 && $ex['aecode'] != 'Other' && $xg['dlz'] == '1' && $xg['library'] == 2)//修改声明
{
$obtain = $this->apismt->get_obtain($xg['orderinfo'],$sp['code']);//修改声明先查询之前物流信息
if(isset($obtain['logistics_no']))
{
$result = $this->apismt->get_editout($obtain['logistics_no'],$ydh,'all',$xg['orderinfo'],$obtain['service_name'],$ex['aecode'],$sp['code']);
}
if(isset($result['result_success']) && $result['result_success'] == "true")
{
$this->fullordersmt->save(array('waybill'=>$ydh),$xg['id']);
/** 合并信息处理开始-修改声明 **/
if($xg['merge'] != '0')
{
$hdata = $this->fullordersmt->find_all("merge = '".$xg['merge']."' and id != '".$xg['id']."' and dlz != 1 and source != 1");$l=0;
foreach ($hdata as $v)
{
$obtain = $this->apismt->get_obtain($v['orderinfo'],$sp['code']);//修改声明先查询之前物流信息
if(isset($obtain['logistics_no']))
{
$result = $this->apismt->get_editout($obtain['logistics_no'],$ydh,'all',$v['orderinfo'],$obtain['service_name'],$ex['aecode'],$sp['code']);
}
if(isset($result['result_success']) && $result['result_success'] == "true")
{
$this->fullordersmt->save(array('waybill'=>$ydh),$v['id']);
}
else
{
$ed[] = array($v['orderinfo'].'-合并单修改发货声明失败,请在ERP上手动操作此单');
$j++;
continue;
}
$l++;
if($l > 10)
{
break;
}
}
}
/** 合并信息处理结束开始 **/
}
else
{
$ed[] = array($ddh.'-修改发货声明失败');
$j++;
continue;
}
}
else if($xg['source'] == 1 && $xg['state'] == '207')
{
$this->fullordersmt->save(array('waybill'=>$ydh,'dlz'=>3,'state'=>216),$xg['id']);
}
else
{
$this->fullordersmt->save(array('waybill'=>$ydh),$xg['id']);
}
}
}
else
{
$ed[] = array($ddh.'-单号错误或重复操作');
$i++;
continue;
}
sleep(1);//停留1秒
}
if ($this->db->trans_status() === FALSE)
{
$this->db->trans_rollback();
}
else
{
$this->db->trans_commit();
}
if($i+$j > 0)
{
$time = date('Ymd',time());
$title = '错误信息-'.$time;
$titlename = "";
$tail = "\n";
$filename = $title.".xls";
$ecl = $this->excel->get_fz3($ed,$titlename,$filename,$tail);
$dir = '/data/excel/'.$time.'/';
$file_name = 'error_'.$time.rand(1000,9999);
if(!is_dir('.'.$dir))mkdir('.'.$dir,0777);
$myfile = fopen(".".$dir.$file_name.".xls", "w") or die();
fwrite($myfile,$ecl);
fclose($myfile);
$error = $dir.$file_name.'.xls';
echo json_encode(array('msg'=>'添加成功,'.$i.'条异常,'.$j.'条失败','error'=>$error,'success'=>true));exit;
}
else
{
echo json_encode(array('msg'=>'添加成功!','error'=>1,'success'=>true));exit;
}
}
else
{
echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;
}
}
//上传速卖通订单
public function _order($arg_array)
{
$dataorder = array();$datashop = array();$dataex = array();$datack = array();
/* 订单加入键值-k */
$fdata = $this->fullorder_smt->find_all('dtime >'.(time()-5*24*3600));
foreach ($fdata as $v)
{
$dataorder[$v['orderinfo']] = $v;
}
/* 订单加入键值-j */
$dir = '/data/excel/'.date('Ymd',time()).'/';
$config['upload_path'] = '.'.$dir ;
$config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
$config['allowed_types'] = 'xls|xlsx|csv';
$config['max_size'] = 10240;
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ($this->upload->do_upload('userfile'))
{
$full_path = $dir.$this->upload->data('file_name');
$fileName = '.' . $full_path;
if (!file_exists($fileName))
{
echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
}
else
{
require_once "./data/excel/PHPExcel/IOFactory.php";
$phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
$phpExcel->setActiveSheetIndex(0);// 设置为默认表
$sheetCount = $phpExcel->getSheetCount();// 获取表格数量
$row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
$column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
++$column;//如果列数大于26行
$list = array();
for ($i = 2; $i <= $row; $i++) // 行数循环
{
$data = array();
for ($c = 'A'; $c != $column; $c++) // 列数循环
{
$data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
}
$list[] = $data;
}
}
$i = 0;$j = 0;$ed = array();$tytime = time();
foreach ($list as $key=>$value)
{
$value['2'] = preg_replace('/\D/s','',$value['2']);
if($value['2'] && !isset($dataorder[$value['2']]))
{
$num = $this->fullorder_smt->find_count('gtime = "'.date('Ymd',time()).'"');
$post['source'] = 2;//订单类型:1.线下订单2.PC3.手机
$post['state'] = 207;//订单状态:207等待发货
$post['review'] = 6;//审核状态:1.未送审2.待审核3.不通过4取消重审5.审核通过6.自动通过
$post['reviewtime'] = $tytime;//审核时间
$post['print'] = 2;//打印状态:1.不可打印2.未打印3.已打印
$post['library'] = 1;//出库状态:1.未出库2.已出库3.已退库
$post['libraryconfirm'] = 1;//出库确认:1.不允许2.允许
if($post['print'] != 3)
{
$post['librarynot'] = "订单未打印,未审核或未通过";//不能出库原因
}
$value['1'] = trim($value['1'],' ');
$shortname = explode('-',$value['1']);
$shortname = $this->shop->get_shortname($shortname[0]);
if(!$shortname)
{
$ed[] = array($value['1'].'-编码有问题');
$i++;
continue;
}
$post['shop'] = $shortname['id']?$shortname['id']:0;//速卖通
$post['user'] = '无';
$post['number'] = $value['1'];//编号
$post['orderinfo'] = $value['2'];//订单号
$post['client'] = preg_replace('/( | | |\s)/',' ',$value['3']);//客户名称
$post['buytime'] = $tytime;//时间转UX
$post['dtime'] = $tytime;//订单时间
$post['gtime'] = date('Ymd',$tytime);//格式化时间
//$post['pay'] = $this->input->post('pay',true);//支付方式
$post['capital'] = 3;//资金状态
$post['type'] = 5;//发货仓库
$post['currency'] = 219;//币种
$post['currencytitle'] = 'USD';//币种名称
$post['freight'] = 0;//运费
$post['expressmoney'] = 0;//物流金额
$post['shouldmoney'] = 0;//应收金额
$post['budget'] = 0;//应到金额*店铺到帐金额比
$orderremarks = '';//订单备注
$post['shipremarks'] = $value['12'];//仓库品名
$post['email'] = '';//邮箱
$post['name'] = preg_replace('/( | | |\s)/',' ',$value['3']);//名字
$post['phone'] = $value['10'];//电话
$post['country'] = 192;//国家
$ct = $this->country->get_ename($value['9']);//国家
$post['al'] = $ct['lb'];//国家二字码
$post['province'] = $value['8'];//省、州
$post['city'] = $value['6'];//城市
$post['zipcode'] = $value['7'];//邮编
$post['address'] = $value['4'];//地址1
$post['address2'] = $value['5']?$value['5']:'';//地址2
$post['express'] = 2;//快递
$post['printtype'] = 1;//打印类型
$post['fpdata'] = '';//购买产品内容
$post['sbpm'] = 'Hair Sample';//申报品名
$post['zwpm'] = '假发';//中文品名
$post['ts'] = $value['17'];//条数
$post['dtsbjz'] = 15;//单条申报价
$post['zsbjz'] = 15;//总申报价
$post['zzl'] = 0.5;//总重量
$post['zjs'] = 1;//总件数
$post['quantity'] = 1;//数量
$post['paypal'] = '';//支付号
$post['guarantee'] = '';//卖家保障
$post['zzl'] = $value['13'];//总重量
$post['bx'] = $value['14'];//总重量
$post['qm'] = $value['15'];//总重量
$post['js'] = $value['16'];//总重量
$barcode = $this->usps->get_address(array('address'=>$value['4'],'address2'=>$value['5'],'city'=>$value['6'],'province'=>$value['8'],'zipcode'=>$value['7']));
if(isset($barcode['Address']['Error']['Description']))
{
$ed[] = array($value['1'].'-'.$barcode['Address']['Error']['Description']);
$i++;
}
else
{
$this->fullorder_smt->insert($post);
}
}
else
{
$ed[] = array($value['1'].'-单号错误或重复操作');
$i++;
}
sleep(2);//停留2秒
}
if($i+$j > 0)
{
$time = date('Ymd',time());
$title = '错误信息-'.$time;
$titlename = "";
$tail = "\n";
$filename = $title.".xls";
$ecl = $this->excel->get_fz3($ed,$titlename,$filename,$tail);
$dir = '/data/excel/'.$time.'/';
$file_name = 'error_'.$time.rand(1000,9999);
if(!is_dir('.'.$dir))mkdir('.'.$dir,0777);
$myfile = fopen(".".$dir.$file_name.".xls", "w") or die();
fwrite($myfile,$ecl);
fclose($myfile);
$error = $dir.$file_name.'.xls';
echo json_encode(array('msg'=>'添加成功,'.$i.'条异常,'.$j.'条失败','error'=>$error,'success'=>true));exit;
}
else
{
echo json_encode(array('msg'=>'添加成功!','error'=>1,'success'=>true));exit;
}
}
else
{
echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;
}
}
public function _email($content,$data,$shopname)
{
$express = $this->express->read($data['express']);
$t= array('$userName','$orderid','$trackingNumber','$expressCompany','$contactPerson','$mobileNo','$zip','$recipientAddress');//需要被替换的内容
$h= array($data['client'],$data['orderinfo'],$data['waybill'],$express['servicename'],$data['name'],$data['phone'],$data['zipcode'],$data['address']);//替换的内容
$content = str_replace($t,$h,$content);
$this->load->library('email');
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtpdm-ap-southeast-1.aliyun.com';
$config['smtp_port'] = 465;
$config['smtp_user'] = 'service@email.supernovahair.com';
$config['smtp_pass'] = 'LONGyihair374';
$config['smtp_crypto'] = 'ssl';
$config['crlf'] = "\r\n";
$config['newline'] = "\r\n";
$this->email->initialize($config);
$this->email->from('service@email.supernovahair.com',$shopname);
$this->email->to($data['email']);//收件
$this->email->subject('The product you purchased has a new progress');//标题
$this->email->message($content);//内容
if ( ! $this->email->send())
{
return 2;
}
else
{
return 1;
}
}
//导出订单excel
public function _cs()
{
if(isset($_GET['fexcel']))
{
if(isset($_SESSION['api']))
{
$user = $this->user->get_api($_SESSION['api']);
$usp = $user;
$fgshop = "";$sid = "";
$user = explode('|',trim($user['shop'],'|'));
foreach ($user as $value)
{
$fgshop .= " shop = ".$value." or";
$sid .= " id = ".$value." or";
}
}
$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');
}
$fexcel = $this->input->get('fexcel',true);
$page = $this->input->get('page',true);
$perpage = $this->input->get('perpage',true);
$warehouse = $this->input->get('warehouse',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);
$state = $this->input->get('state',true);
$review = $this->input->get('review',true);
$type = $this->input->get('type',true);
$express = $this->input->get('express',true);
$orderinfo = $this->input->get('orderinfo',true);
$user = $this->input->get('user',true);
$client = $this->input->get('name',true);
$waybill = $this->input->get('waybill',true);
$number = $this->input->get('number',true);
$email = $this->input->get('email',true);
$dlz = $this->input->get('dlz',true);
$library = $this->input->get('library',true);
$libraryconfirm = $this->input->get('libraryconfirm',true);
$print = $this->input->get('print',true);
$timetkk = $this->input->get('timetkk',true);
$timetjj = $this->input->get('timetjj',true);
$timetk = strtotime($timetk);
$timetj = strtotime($timetj);
$timetkk = strtotime($timetkk);
$timetjj = strtotime($timetjj);
$where = "mergeid = 0 and (".rtrim($fgshop,'or').")";
if($warehouse)
{
$where .= " and type = '$warehouse'";
}
if($timetk && $timetj)
{
$timetj = $timetj+24*3600;
$where .= " and dtime > '$timetk' and dtime < '$timetj'";
}
if($timetkk && $timetjj)
{
$where .= " and librarytime > '$timetkk' and librarytime < '$timetjj'";
}
if($library)
{
$where .= " and library = '$library'";
}
if($print)
{
$where .= " and print = '$print'";
}
if($shop)
{
$where .= " and shop = '$shop'";
}
if($source)
{
$where .= " and source = '$source'";
}
if($state)
{
$where .= " and state = '$state'";
}
if($review)
{
$where .= " and review = '$review'";
}
if($type)
{
$where .= " and type = '$type'";
}
if($express)
{
$where .= " and express = '$express'";
}
if($orderinfo)
{
$where .= " and orderinfo = '$orderinfo'";
}
if($user)
{
$where .= " and user = '$user'";
}
if($client)
{
$where .= " and client like '%$client%'";
}
if($waybill)
{
$where .= " and waybill = '$waybill'";
}
if($number)
{
$where .= " and number = '$number'";
}
if($email)
{
$where .= " and email = '$email'";
}
if($dlz)
{
$where .= " and waybill != '' and dlz = 0";
}
if($dlz)
{
$where .= " and libraryconfirm = '$libraryconfirm'";
}
$fexcel = $this->fullorderexcel->read($fexcel);
$fexceleq = explode("|",rtrim($fexcel['content'],'|'));
foreach ($fexceleq as $k=>$v)
{
$fexceleq[$k] = explode('-',$v);
$num[$k] = $fexceleq[$k][0];
}
//array_multisort($num,SORT_ASC,$fexceleq);//重新排序
$feq = "";
foreach ($fexceleq as $k=>$v)
{
$feq .= $v[1].',';
}
$feq = rtrim($feq,',');
$fexcelzhw = explode('|',rtrim($fexcel['contentzh'],'|'));
foreach ($fexcelzhw as $k=>$v)
{
$fexcelzhw[$k] = explode('-',$v);
$numb[$k] = $fexcelzhw[$k][0];
}
//array_multisort($numb,SORT_ASC,$fexcelzhw);//重新排序
$fexcelzh = array();
foreach ($fexcelzhw as $k=>$v)
{
$fexcelzh[] = $v[1];
}
//取得信息列表
$info_list = $this->fullorder->find_all($where.$wid,$feq,'id desc');
//格式化数据
$i = 1;$shouldmoney = 0;$hl=1;
foreach ($info_list as $key=>$value)
{
if(isset($value['currencytitle']))
{
if($value['currencytitle'] != "CNY")
{
$hl=$value['hl'];
}
$shouldmoney=$shouldmoney+($value['shouldmoney']*$hl);
$budget=$budget+($value['budget']*$hl);
$currency=$currency+(($value['shouldmoney']-$value['budget'])*$hl);
$refund=$refund+($value['refund']*$hl);
}
if(isset($value['shop']))
{
$shop = $this->shop->read($value['shop']);
$info_list[$key]['shop'] = $shop['shopname'];
}
if(isset($value['dtime']))
{
$info_list[$key]['dtime'] = date('Y-m-d H:i:s',$value['dtime']);
}
if(isset($value['country']))
{
$country = $this->country->read($value['country']);
$info_list[$key]['country'] = $country['name'];
}
if(isset($value['type']))
{
$type = $this->warehouse->read($value['type']);
$info_list[$key]['type'] = $type['title'];
}
if(isset($value['express']))
{
$express = $this->express->read($value['express']);
if($express)
{
$info_list[$key]['express'] = $express['servicename'];
}
else
{
$info_list[$key]['express'] = '未选择';
}
}
}
echo $timetkk;
}
}
public function _gggs($sku,$s,$j,$k)
{
$companytitle = array(9=>3,10=>2,11=>1,12=>4);
$this->load->database();
$this->db->select('id');
$this->db->from('crowd_whlabel');
$this->db->where('warehouse', '5');
$this->db->where('sku', $sku);
$this->db->where('state', '0');
$this->db->limit($s,$k);
$query = $this->db->get();
$ids = array_column($query->result_array(), 'id');
if (!empty($ids))
{
// 更新
$this->db->where_in('id', $ids);
$this->db->update('crowd_whlabel', array('companytitle' => $companytitle[$j]));
return $this->db->affected_rows();
}
}
public function _xxpl()
{
$this->load->database();
$data = ['type' => ''];
$this->db->update('crowd_whlabel', $data);
$wt = array();
$whlabel_type = $this->whlabel_type->find_all();
foreach ($whlabel_type as $v)
{
$wt[$v['title']] = $v['id'];
}
/* 订单加入键值-j */
$dir = '/data/excel/'.date('Ymd',time()).'/';
$config['upload_path'] = '.'.$dir ;
$config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
$config['allowed_types'] = 'xls|xlsx|csv';
$config['max_size'] = 10240;
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ($this->upload->do_upload('userfile'))
{
$full_path = $dir.$this->upload->data('file_name');
$fileName = '.' . $full_path;
if (!file_exists($fileName))
{
echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
}
else
{
require_once "./data/excel/PHPExcel/IOFactory.php";
@$phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
@$phpExcel->setActiveSheetIndex(0);// 设置为默认表
$sheetCount = $phpExcel->getSheetCount();// 获取表格数量
$row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
$column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
++$column;//如果列数大于26行
$list = array();
for ($i = 2; $i <= $row; $i++) // 行数循环
{
$data = array();
for ($c = 'A'; $c != $column; $c++) // 列数循环
{
$data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
}
$list[] = $data;
}
}
$wt = array();
$whlabel_type = $this->whlabel_type->find_all();
foreach ($whlabel_type as $v)
{
$wt[$v['title']] = $v['id'];
}
$j = 0;$ed = array();$e = 0;$c = 0;$cs = array();
foreach ($list as $v)
{
$this->load->database();
// 设置更新数据
$data = ['type' => $wt[$v[1]]];
// 添加条件:SKU 为 123456 且 warehouse 为 5
$this->db->where('SKU', $v[0]);
$this->db->where('warehouse', '5');
// 批量更新
$this->db->update('crowd_whlabel', $data);
}
/** 导入缺货
$time = time();
$whlabel = $this->whlabel->get_sku($v[0]);
if($whlabel)
{
$this->whlabel_qh->insert(array('sku'=>$whlabel['sku'],'features'=>$whlabel['features'],'num'=>$v['1'],'gtime'=>date('Ym',$time),'gxtime'=>date('Ymd',$time)));
}
else
{
$ed[] = $v['0'];
$j++;
}
}
**/
/**
更换等级
$this->load->database();
// 设置更新数据
$data = ['type' => $wt[$v[1]]];
// 添加条件:SKU 为 123456 且 warehouse 为 5
$this->db->where('SKU', $v[0]);
$this->db->where('warehouse', '5');
// 批量更新
$this->db->update('crowd_whlabel', $data);
**/
/**
$whlabel_type = $this->whlabel_type->find_all();
foreach ($whlabel_type as $v)
{
$wt[$v['title']] = $v['id'];
}
foreach ($list as $v)
{
$w = $this->whlabel->find_all("sku = '".$v[0]."' and warehouse = 5");
if($w && isset($wt[$v[1]]))
{
foreach ($w as $val)
{
$this->whlabel->save(array('type'=>$wt[$v[1]]),$val['id']);
}
}
else
{
$ed[] = array($v[0],$v[1]);
$j++;
}
}
**/
if($e > 0)
{
$time = date('Ymd',time());
$title = '错误信息-'.$time;
$titlename = "";
$tail = "\n";
$filename = $title.".xls";
@$ecl = $this->excel->get_fz3($ed,$titlename,$filename,$tail);
$dir = '/data/excel/'.$time.'/';
$file_name = 'error_'.$time.rand(1000,9999);
if(!is_dir('.'.$dir))mkdir('.'.$dir,0777);
$myfile = fopen(".".$dir.$file_name.".xls", "w") or die();
fwrite($myfile,$ecl);
fclose($myfile);
$error = $dir.$file_name.'.xls';
echo json_encode(array('msg'=>$j.'条异常,','error'=>$error,'success'=>true));exit;
}
else
{
echo json_encode(array('msg'=>'添加成功!'.$c,'success'=>true));exit;
}
}
else
{
echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;
}
}
public function _skuzh()
{
/* 订单加入键值-j */
$dir = '/data/excel/'.date('Ymd',time()).'/';
$config['upload_path'] = '.'.$dir ;
$config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
$config['allowed_types'] = 'xls|xlsx|csv';
$config['max_size'] = 10240;
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ($this->upload->do_upload('userfile'))
{
$full_path = $dir.$this->upload->data('file_name');
$fileName = '.' . $full_path;
if (!file_exists($fileName))
{
echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
}
else
{
require_once "./data/excel/PHPExcel/IOFactory.php";
@$phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
@$phpExcel->setActiveSheetIndex(0);// 设置为默认表
$sheetCount = $phpExcel->getSheetCount();// 获取表格数量
$row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
$column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
++$column;//如果列数大于26行
$list = array();
for ($i = 2; $i <= $row; $i++) // 行数循环
{
$data = array();
for ($c = 'A'; $c != $column; $c++) // 列数循环
{
$data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
}
$list[] = $data;
}
}
$dictionaries = $this->typeclass->find_all('spare!= "" and classid != 1 and classid != 2 and classid != 3 and classid != 4 and classid != 5 and classid != 11 and classid != 16 and classid != 17 and classid != 20 and classid != 21 and classid != 23 and classid != 24 and classid != 29 and classid != 30 and classid != 31 and classid != 32');
$dtc = array();
foreach ($dictionaries as $v)
{
if(stripos($v['spare'],'|') !== false)//如果有多个值
{
$v['spare'] = explode('|',$v['spare']);
foreach ($v['spare'] as $k=>$vs)
{
if(stripos($v['zh'],'|') !== false)
{
$vzh = explode('|',$v['zh']);
$dtc[strtolower($vs)] = array('classid'=>$v['classid'],'zh'=>$vzh[$k],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$vs);
}
else
{
$dtc[strtolower($vs)] = array('classid'=>$v['classid'],'zh'=>$v['zh'],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$vs);
}
}
}
else
{
$dtc[strtolower($v['spare'])] = array('classid'=>$v['classid'],'zh'=>$v['zh'],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$v['spare']);
}
}
$dictionaries2 = $this->typeclass->find_all();
foreach ($dictionaries2 as $v)
{
$dtctitle[$v['id']] = $v['title'];
}
/* 匹配结束 */
/* 价格加入 */
$money = array();
$productdescribe = $this->productdescribe->find_all('1=1');
foreach ($productdescribe as $v)
{
$money[$v['number']] = array();
}
/* 价格加入 */
/* 匹配ID加入 */
$int = array();
$intdata = $this->typeclass->find_all('classid=14','id,spare');
foreach ($intdata as $v)
{
$v['spare'] = explode('|',$v['spare']);
$int[$v['id']] = $v['spare'][0];
}
/* 匹配ID加入 */
$zjsku = array();
$shopsku = $this->shopsku->find_all();
foreach ($shopsku as $val)
{
$ss = explode(',',trim($val['shop'],','));
foreach ($ss as $v)
{
if(isset($zjsku[$v]))
{
$zjsku[$v] .= ','.trim($val['sku'],',');
}
else
{
$zjsku[$v] = trim($val['sku'],',');
}
}
}
/* 匹配ID结束 */
$q = '1;';
$is = $this->is->find_all('1=1','*','number asc');//获取仓库平匹配表
$shop = $this->shop->read(19);
if(isset($zjsku[$shop['id']]))//判断是否找到店铺SKU
{
$sku = rtrim($sku,',').','.$zjsku[$shop['id']];
}
$ed = array();
foreach ($list as $v)
{
$r = $this->api->matching(trim($q,';'),$v['2'],$dtc,$money,$int,$dtctitle,$shop);
$p = '';
$product = explode(';',trim($r['product'],';'));
if($r['title'] != '' && $product)
{
foreach ($product as $val)
{
$vc = explode('|',$val);
if(isset($vc[1]))
{
$p .= $vc[1].'
';
}
}
$r['title'] = str_replace(array('<','>'),array('<','>'),$r['title']);
$ed[] = array($v['0'],$v['1'],$r['title'],$v['3'],$v['4'],$v['5']);
}
else
{
$ed[] = array($v['0'],$v['1'],$v['2'].' SKU错误',$v['3'],$v['4'],$v['5']);
}
}
$time = date('Ymd',time());
$title = 'sku转换'.$time;
$titlename = "";
$tail = "\n";
$filename = $title.".xls";
@$ecl = $this->excel->get_fz3($ed,$titlename,$filename,$tail);
$dir = '/data/excel/'.$time.'/';
$file_name = 'sku转换 '.$time.rand(1000,9999);
if(!is_dir('.'.$dir))mkdir('.'.$dir,0777);
$myfile = fopen(".".$dir.$file_name.".xls", "w") or die();
fwrite($myfile,$ecl);
fclose($myfile);
$error = $dir.$file_name.'.xls';
echo json_encode(array('msg'=>'转换成功!','error'=>$error,'success'=>true));exit;
}
else
{
echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;
}
}
public function _xxpl_b()
{
$dataorder = array();$datashop = array();$dataex = array();$datack = array();
/* 订单加入键值-k */
$fdata = $this->fullordersmt->find_all('dtime >'.(time()-10*24*3600));
foreach ($fdata as $v)
{
$dataorder[$v['orderinfo']] = $v;
}
/* 订单加入键值-j */
$dir = '/data/excel/'.date('Ymd',time()).'/';
$config['upload_path'] = '.'.$dir ;
$config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
$config['allowed_types'] = 'xls|xlsx|csv';
$config['max_size'] = 10240;
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ($this->upload->do_upload('userfile'))
{
$full_path = $dir.$this->upload->data('file_name');
$fileName = '.' . $full_path;
if (!file_exists($fileName))
{
echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
}
else
{
require_once "./data/excel/PHPExcel/IOFactory.php";
@$phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
@$phpExcel->setActiveSheetIndex(0);// 设置为默认表
$sheetCount = $phpExcel->getSheetCount();// 获取表格数量
$row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
$column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
++$column;//如果列数大于26行
$list = array();
for ($i = 2; $i <= $row; $i++) // 行数循环
{
$data = array();
for ($c = 'A'; $c != $column; $c++) // 列数循环
{
$data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
}
$list[] = $data;
}
}
$i = 0;$j = 0;$ed = array();$time = time();
foreach ($list as $key=>$value)
{
$shop = $this->shop->get_shopname($value['2']);//通过店铺名称查找店铺
if(!$shop)
{
$ed[] = array($value['0'].'-无此店铺');
$i++;continue;
}
$post['buytime'] = strtotime($value['6']);//付款时间
$value['0'] = preg_replace('/\D/s','',$value['0']);
if($value['0'] && !isset($dataorder[$value['0']]))
{
$post['source'] = 2;//订单类型:1.线下订单2.PC3.手机
$post['state'] = 207;//订单状态:207等待发货
$post['review'] = 6;//审核状态:1.未送审2.待审核3.不通过4取消重审5.审核通过6.自动通过
$post['reviewtime'] = $time;//审核时间
$post['print'] = 2;//打印状态:1.不可打印2.未打印3.已打印
$post['library'] = 1;//出库状态:1.未出库2.已出库3.已退库
$post['libraryconfirm'] = 1;//出库确认:1.不允许2.允许
$post['dtime'] = $time;//订单时间
$post['capital'] = 3;//资金状态
$post['currency'] = 219;//币种
$post['currencytitle'] = 'USD';//币种名称
$post['freight'] = 0;//运费
$post['expressmoney'] = 0;//物流金额
$post['shouldmoney'] = 0;//应收金额
if($post['print'] != 3)
{
$post['librarynot'] = "订单未打印";//不能出库原因
}
$post['gtime'] = date('Ymd',$post['buytime']);//格式化时间
$num = $this->fullordersmt->find_count('gtime = "'.date('Ymd',$post['buytime']).'" and shop = "'.$shop['id'].'"','id');
$post['number'] = $shop['shortname'].'-'.substr(date('ymd',$post['buytime']),1).'-'.(substr(strval($num+1+1000),1,3));//编号
$post['user'] = $shop['shopuser'];//店铺负责人
$post['orderinfo'] = $value['0'];//订单号
$post['type'] = $value['7'];//发货仓库
$post['shop'] = $shop['id'];//店铺
$post['shouldmoney'] = $value['3'];//订单金额
$post['product'] = $value['4']?$value['4']:'';//商品名称
$post['pay'] = $value['5'];//付款方式
$post['paypal'] = $value['1']?$value['1']:'';//交易号
$post['orderremarks'] = $value['8']?$value['8']:'';//订单备注
$post['shipremarks'] = $value['9'];//仓库品名
$post['client'] = preg_replace('/( | | | |\s)/',' ',$value['10']);//公司名
$post['name'] = preg_replace('/( | | | |\s)/',' ',$value['11']);//收货人
$post['phone'] = $value['12'];//电话
$ct = $this->country->get_ename(preg_replace('/( | | | |\s)/',' ',$value['13']));//国家
if(!$ct)
{
$ed[] = array($value['0'].'-无此国家');
$i++;continue;
}
$post['country'] = $ct['id'];//国家
$post['al'] = $ct['lb'];//国家二字码
$post['province'] = $value['14'];//省、州
$post['city'] = $value['15'];//城市
$post['zipcode'] = $value['16'];//邮编
$post['address'] = $value['17'];//地址1
$post['address2'] = $value['18']?$value['18']:'';//地址2
$yga = $value['3'];$ygb = $shop['estimaterate'];
$post['budget'] = eval("return $yga*1.$ygb;");//预估到帐金额
$post['sbpm'] = $value['19'];//申报品名
$post['zwpm'] = $value['20'];//中文品名
$post['ts'] = $value['21'];//条数
$post['dtsbjz'] = $value['22'];//单条申报价
$post['zsbjz'] = $value['23'];//总申报价
$post['zzl'] = $value['24'];//总重量
$post['zjs'] = $value['25'];//总件数
$express = $this->express->get_servicename(preg_replace('/( | | | |\s)/',' ',$value['26']));
if(!$express)
{
$ed[] = array($value['0'].'-无此快递方式');
$i++;continue;
}
$post['express'] = $express['id'];//快递
$post['printtype'] = 1;//打印类型 1.运单.2.发货单
$post['fpdata'] = '';//购买产品内容
$this->fullordersmt->insert($post);
}
else
{
$ed[] = array($value['0'].'-单号错误或重复操作');
$i++;
}
sleep(2);//停留2秒
}
if($i+$j > 0)
{
$time = date('Ymd',time());
$title = '错误信息-'.$time;
$titlename = "";
$tail = "\n";
$filename = $title.".xls";
@$ecl = $this->excel->get_fz3($ed,$titlename,$filename,$tail);
$dir = '/data/excel/'.$time.'/';
$file_name = 'error_'.$time.rand(1000,9999);
if(!is_dir('.'.$dir))mkdir('.'.$dir,0777);
$myfile = fopen(".".$dir.$file_name.".xls", "w") or die();
fwrite($myfile,$ecl);
fclose($myfile);
$error = $dir.$file_name.'.xls';
echo json_encode(array('msg'=>'添加成功,'.$i.'条异常,'.$j.'条失败','error'=>$error,'success'=>true));exit;
}
else
{
echo json_encode(array('msg'=>'添加成功!','error'=>1,'success'=>true));exit;
}
}
else
{
echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;
}
}
public function _scwd()
{
$dir = '/data/excel/'.date('Ymd',time()).'/';
$config['upload_path'] = '.'.$dir ;
$config['allowed_types'] = '*';
$config['max_size'] = 102400;
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ($this->upload->do_upload('userfile'))
{
$full_path = $dir.$this->upload->data('file_name');
echo json_encode(array('msg'=>'成功!','wdurl'=>$full_path,'success'=>true));exit;
}
else
{
echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;
}
}
public function _jmexcel()
{
$setting = $this->setting->get_settings();
$excelpass = $setting['excelpass'];
$excelusernum = $setting['excelusernum'];
$exceljmnum = $setting['exceljmnum'];
$user = $this->user->get_api($_SESSION['api']);
if(!isset($user['exceltime']))
{
$this->session->sess_destroy();
header("Location:/");
}
$post = $this->input->post(NULL, TRUE);
if(isset($post['data']))
{
$data = $this->input->post('data',true);
$data = str_replace("\n",",",$data);;
$data = explode(',',trim($data,','));
$d = '';$i = 0;
foreach ($data as $v)
{
if($v == '')
{
continue;
}
$j = $this->setting->get_jmexcelpass($v);
if($j == '')
{
$j = $v.' 信息不正确';
}
$d .= $j."
";
$i++;
}
if($i > $exceljmnum)
{
echo json_encode(array('msg'=>'每次解密数量不可超出'.$exceljmnum.'条','success'=>false));exit;
}
if($user['exceltime'] != date('Ymd',time()))
{
$this->user->save(array('exceltime'=>date('Ymd',time()),'excelnum'=>1),$user['id']);
}
else
{
if($user['excelnum'] > $excelusernum)
{
echo json_encode(array('msg'=>'今日此账号解密次数已使用完毕','success'=>false));exit;
}
else
{
$this->user->save(array('excelnum'=>$user['excelnum']+1),$user['id']);
}
}
echo json_encode(array('msg'=>$d,'success'=>true));exit;
}
$this->data['excelpass'] = $excelpass;
$this->data['excelusernum'] = $excelusernum;
$this->data['exceljmnum'] = $exceljmnum;
$this->_Template('fullorderexcel_jmexcel',$this->data);
}
//管理
public function _classid()
{
$post = $this->input->post(NULL, TRUE);
if(isset($post['page']))
{
$page = $this->input->post('page',true);
$perpage = $this->input->post('perpage',true);
$type = $this->input->post('type',true);
$where = "1=1 ";
//数据排序
$order_str = "id asc";
if(empty($page))
{
$start = 0;
$perpage = 1;
}
else
{
$start = ($page - 1)*$perpage;
}
if($type)
{
$where .= " and type = '$type'";
}
//取得信息列表
$info_list = $this->fullorderexcelclassid->find_all($where,'id,title,type',$order_str,$start,$perpage);
$total = $this->fullorderexcelclassid->find_count($where);
$pagenum = ceil($total/$perpage);
$over = $total-($start+$perpage);
$rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
echo json_encode($rows);exit;
}
$this->_Template('fullorderexcel_classid',$this->data);
}
//添加
public function _classidadd()
{
$post = $this->input->post(NULL, TRUE);
if(isset($post['title']))
{
if($this->fullorderexcelclassid->insert($post))
{
echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
}
else
{
echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
}
}
$this->_Template('fullorderexcel_classidadd',$this->data);
}
//修改
public function _classidedit($arg_array)
{
$post = $this->input->post(NULL, TRUE);
if(isset($post['id']))
{
$id = $this->input->post('id',true);
if($this->fullorderexcelclassid->save($post,$id))
{
echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
}
else
{
echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
}
}
$arg_array = $arg_array[0];
$fullorderexcelclassid = $this->fullorderexcelclassid->read($arg_array);
$this->data['fullorderexcelclassid'] = $fullorderexcelclassid;
$this->_Template('fullorderexcel_classidedit',$this->data);
}
}