$thb[$c[$i]]['zh'],'id'=>$thb[$c[$i]]['id'],'count'=>$thb[$c[$i]]['count']+1):array('zh'=>$c[$i],'id'=>$thisid,'count'=>1);
**/
//一样的不再合并
$thb[] = array('zh'=>$c[$i],'id'=>$thisid,'count'=>1);
}
foreach ($thb as $v)
{
$item = array_merge($fk);$weight = 0;
if($fk['16'] == '126')
{
$weight = $weightsku[$item[0]];
}
else if($fk['16'] == '127')
{
if(isset($item[9]))
{
$sku127a = $item[0].'-'.$v['id'].'-'.$item[3].'-'.$item[6].'-'.$item[9];
$sku127b = $item[0].'-'.$v['id'].'-'.$item[6].'-'.$item[9];
if(isset($weightsku[$sku127a]))
{
$weight = $weightsku[$sku127a];
}
else if(isset($weightsku[$sku127b]))
{
$weight = $weightsku[$sku127b];
}
}
}
else if($fk['16'] == '128')
{
if(isset($item[8]))
{
$sku128 = $item[0].'-'.$v['id'].'-'.$item[6].'-'.$item[8];
if(isset($weightsku[$sku128]))
{
$weight = $weightsku[$sku128];
}
}
}
$cpb = $fk;$cpb[14] = $v['id'];$cpb[22] = '';//增加长度ID、去除真人发类型
$whlabel .= implode("",$cpb).'-'.$slx*$v['count'].'-0|';
$pdcc = (is_numeric($v['zh']))?$v['zh'].'inch |':strtoupper($v['zh']).'|';
$product .= $v['id'].',-'.rtrim(implode("-",$fk),'-').'-|'.$ptitleb.$pdcc.$slx*$v['count'].'|0|0|'.$v['zh'].'|0|0|'.$slx*$v['count']*$weight.'|0;';
}
}
if (stripos($pd[$x],'Gift-') !== false)
{
$ptitleg = '';
foreach ($cpson as $v)
{
$ptitleg .= isset($dtctitle[$v])?$dtctitle[$v].' ':'';
}
$whlabel .= implode("",$cpson).'-'.$slx.'-0|';
$product .= '-'.rtrim(implode("-",$cpson),'-').'-|'.$ptitleg.'|'.$slx.'|0|0||0|0|0|0;';
}
$x++;
$purchase += $purchasemy;
$cost += $costmy;
}
$product = str_replace('--','-',$product);
$qbslpx = 0;$wcslpx = '';
foreach ($slpx as $v)
{
$wcslpx .= $qbslpx.'-'.($qbslpx+$v).'|';
$qbslpx += $v;
}
$nr = str_replace(array('(',')'),array('(',')'),$nr);
if(stripos($whlabel,'|--|') !== false)
{
$whlabel = '';
$product = '';
}
return array('title'=>preg_replace(array('/(\s+)/','/分\s/u'),array(' ','分'),trim($nr,';')),'purchase'=>$purchase,'cost'=>$cost,'product'=>str_replace(array('---','--'),array('-','-'),$product),'whlabel'=>$whlabel,'wcslpx'=>trim($wcslpx,'|'),'cs'=>$cscs);
}
public function _spexcel()
{
$tc = array();
$typeclass = $this->typeclass->find_all();
foreach ($typeclass as $v)
{
$tc[$v['id']] = $v;
}
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'],'|'));
foreach ($userexcel as $value)
{
$excelshop .= " shop = ".$value." or";
}
if($excelshop != "")
{
$excelshop = "(".rtrim($excelshop,'or').")";
}
}
$post = $this->input->post(NULL, TRUE);
$tcall = $this->typeclass->find_all();
$typeclass = array();
foreach ($tcall as $v)
{
$tcjm[$v['id']] = array($v['jm'],$v['classid']);
$typeclass[$v['id']] = array('zh'=>$v['zh'],'classid'=>$v['classid'],'bm'=>$v['bm'],'title'=>$v['title'],'jm'=>$v['jm']);
}
$classid = $this->classid->sku();
if(isset($_GET['category']))
{
$timetk = $this->input->get('timetk',true);
$timetj = $this->input->get('timetj',true);
$color = $this->input->get('color',true);
$lowe = $this->input->get('lowe',true);
$size = $this->input->get('size',true);
$grade = $this->input->get('grade',true);
$lacetype = $this->input->get('lacetype',true);
$category = $this->input->get('category',true);
$shop = $this->input->get('shop',true);
$density = $this->input->get('density',true);
$warehouse = $this->input->get('warehouse',true);
$time = $this->input->get('time',true);
$timetk = strtotime($timetk);
$timetj = strtotime($timetj);
$where = "";
if($warehouse){
$where .= " type = ".$warehouse." and ";
}
if($category)
{
$where .= "fpdata like '%-".$category."-%' and ";
}
if($color)
{
$where .= "fpdata like '%-".$color."-%' and ";
}
if($size)
{
$where .= "fpdata like '%-".$size."-%' and ";
}
if($grade)
{
$where .= "fpdata like '%-".$grade."-%' and ";
}
if($shop)
{
$where .= "shop = '$shop' and ";
}
else
{
$where .= $excelshop." and ";
}
if($lowe)
{
$where .= "fpdata like '%-".$lowe."-%' and ";
}
if($density)
{
$where .= "fpdata like '%-".$density."-%' and ";
}
if($lacetype)
{
$where .= "fpdata like '%-".$lacetype."-%' and ";
}
$dataa = $this->fullorder->find_all($where.$time." > '$timetk' and ".$time." < '$timetj'",'fpdata,number,whlabel,type','id desc');
$datab = $this->fullordersmt->find_all($where.$time." > '$timetk' and ".$time." < '$timetj' and shop != '9'",'fpdata,number,whlabel,type','id desc');
$datac = $this->fullordertt->find_all($where.$time." > '$timetk' and ".$time." < '$timetj'",'fpdata,number,whlabel,type','id desc');
$data = array_merge($dataa,$datab,$datac);
$sp = array();$cs = array();
$warehouses = $this->warehouse->find_all('1=1','id,title');
$warehouses = array_column($warehouses,'title','id');
foreach ($data as $val)
{
$f = explode(';',trim($val['fpdata'],';'));
$w = explode('|',trim($val['whlabel'],'|'));
foreach ($f as $k=>$v)
{
if($category)
{
if(stripos($v,'-'.$category.'-') === false)
{
continue;
}
}
if($color)
{
if(stripos($v,'-'.$color.'-') === false)
{
continue;
}
}
if($lowe)
{
if(stripos($v,'-'.$lowe.'-') === false)
{
continue;
}
}
if($size)
{
if(stripos($v,$size.',') === false)
{
continue;
}
}
if($grade)
{
if(stripos($v,'-'.$grade.'-') === false)
{
continue;
}
}
if($lacetype)
{
if(stripos($v,'-'.$lacetype.'-') === false)
{
continue;
}
}
if($density)
{
if(stripos($v,'-'.$density.'-') === false)
{
continue;
}
}
$title = explode('|',$v);
$fg = str_replace(array('-163-','-164-','-165-','-166-','-0-','-126-','-127-','-128-','-197-','-195-'),'-',$title[0]);
$fg = explode(',',$fg);
//$fg = explode('-',trim($fg[1].$fg[0],'-'));
if(isset($fg[1])){
$fg = explode('-',trim($fg[1].$fg[0],'-'));
}else{
$fg = [];
}
$pm = array();
//$pm = array(13=>'',22=>'',8=>'',15=>'',18=>'','100'=>'',33=>'',34=>'',35=>'','dc'=>'','c'=>'',12=>'',25=>'',26=>'',14=>'',27=>'',10=>'',6=>'',9=>'',39=>'',999=>'',9999=>'');//品名顺序
foreach($fg as $vv)
{
if(isset($tc[$vv]['zh']))
{
$zh = explode('|',trim($tc[$vv]['zh'],'|'));
$pm[$tc[$vv]['classid']] = $zh[0];
}
}
$features = str_replace(array('-163-','-164-','-165-','-166-'),'-',$v);
$tsk = explode('|',trim($features,'|'));
if(stripos($tsk[0],',') !== false)
{
$ftt = explode(',',$tsk[0]);
$features = explode('-',trim($ftt[1],'-'));
$features[] = $ftt[0];
}
else
{
$features = explode('-',trim($tsk[0],'-'));
}
$jm = $classid;
$jm = $classid;
foreach($features as $vv)
{
if($vv != 0)
{
if(!isset($typeclass[$vv]))
{
continue;
}
if(isset($jm[$typeclass[$vv]['classid']]))
{
if($typeclass[$vv]['jm'])
{
$jm[$typeclass[$vv]['classid']] = $typeclass[$vv]['jm'];
}
}
}
}
$jm = array_filter($jm);//去除空值
$jm = implode("-",$jm);
$zh = implode(" ",$pm);
$zh = str_replace('自然色 ','',rtrim($zh,' '));
$zh = str_replace(array(' ',' ',' ',' ',' ',' ',' '),' ',$zh);
if(isset($title[1])){
if(isset($sp[$title[1]]))
{
$sp[$title[1]]['n'] += $title[2];
$sp[$title[1]]['number'] .= $val['number']."
";
}
else
{
$wh = explode('-',$w[$k]);
$wsku = $this->whlabel->find_all("number = '".$wh[0]."' and sku != 'Preset'");
$whs = (isset($wsku[0]['sku']))?$wsku[0]['sku']:'';
$sp[$title[1]] = array('t'=>$title[1],'z'=>$zh,'w'=>$whs,'j'=>$jm,'n'=>$title[2],'number'=>$val['number']."
");
}
$sp[$title[1]]['warehouse'] = isset($warehouses[$val['type']])?$warehouses[$val['type']]:'仓库异常';
}
}
}
echo "";
var_dump($sp);
die;
$sp = array_values($sp);
$title = "商品统计".date('Y-m-d H-i-s',time());
$titlename = "
";
$filename = $title.".xls";
$tail = "\n";
$this->excel->get_fz2($sp,$titlename,$filename,$tail);
}
}
public function _setting()
{
$post = $this->input->post(NULL, TRUE);
if(isset($post['excelpass']))
{
$excelpass = $this->input->post('excelpass',true);
$exceljmnum = $this->input->post('exceljmnum',true);
$excelusernum = $this->input->post('excelusernum',true);
if($excelpass == '')
{
echo json_encode(array('msg'=>'密码不能为空','success'=>false));exit;
}
if($exceljmnum < 1 || $excelusernum < 1)
{
echo json_encode(array('msg'=>'数量不可以小于1','success'=>false));exit;
}
$this->setting->save(array('svalue'=>$excelpass),'excelpass');
echo json_encode(array('msg'=>'Excel加密密码修改成功','success'=>false));exit;
}
}
public function _sctime()
{
$post = $this->input->post(NULL, TRUE);
if(isset($post['sctime']))
{
$sctime = $this->input->post('sctime',true);
if(!is_numeric($sctime))
{
echo json_encode(array('msg'=>'必须为正整数的数字!','success'=>false));exit;
}
$sctime = ($sctime>0)?$sctime*3600:0;
$this->setting->save(array('svalue'=>$sctime),'sctime');
echo json_encode(array('msg'=>'时差修改成功!','success'=>false));exit;
}
}
public function _dpay()
{
$post = $this->input->post(NULL, TRUE);
if(isset($post['pay']))
{
$pay = $this->input->post('pay',true);
$timetk = $this->input->post('timetk',true);
$timetj = $this->input->post('timetj',true);
$timetk = strtotime($timetk);
$timetj = strtotime($timetj);
$where = "shouldmoney > '0' and dtime > '$timetk' and dtime < '$timetj' and pay = '$pay'";
if(!$pay)
{
echo json_encode(array('msg'=>'请选择支付方式!','success'=>false));exit;
}
$fullorder = $this->fullorder->find_all($where);
$this->db->trans_begin();
$cs = array();
$p = $this->pay->get_typeclass($pay);
foreach($fullorder as $v)
{
$yga = $v['shouldmoney'];//金额
$ygc = $p['estimaterate'];//预估到账公式
$ifbudget = eval("return $yga*1.$ygc;");
if($ifbudget > 0)
{
$this->fullorder->save(array('budget'=>$ifbudget,'estimaterate'=>$ygc),$v['id']);
}
}
if ($this->db->trans_status() === TRUE)
{
$this->db->trans_commit();
echo json_encode(array('msg'=>'操作成功!','success'=>true));exit;
}
else
{
$this->db->trans_rollback();
echo json_encode(array('msg'=>'失败,请重试','success'=>false));
}
}
}
public function _dpex()
{
$post = $this->input->post(NULL, TRUE);
if(isset($post['n']))
{
$number = $this->input->post('n',true);
$postdata = $this->input->post('postdata',true);
$postdata = json_decode($postdata,true);
$d = array();
foreach ($postdata as $val)
{
$d[] = array(
'Money' => 'USD',//货币单位
//'Sku' => '123123',//产品 Sku (OrderType 为仓储订单必传)
'Cnname' => $val['zh'],//产品中文名
'Enname' => $val['en'].'*'.$val['num'],//产品英文名
'Price' => $val['dj']*1,//单价
'Weight' => $val['zl']*1,//重量
'Num' => $val['num']*1,//数量
'CustomsCode'=> $val['hg']//海关编码
);
}
$fullorder = $this->fullorder->get_number($number);
if(!$fullorder)
{
$fullorder = $this->fullordersmt->get_number($number);
}
if(!$fullorder)
{
echo json_encode(array('msg'=>'没有此编号的订单!','success'=>false));exit;
}
$fullorder = $this->_text($fullorder);
$fullorder['number'] = $fullorder['number'].'-'.date('s',time());//订单号重复修改新订单好
$data = $fullorder;
$url = "http://ambcargo.kingtrans.cn/PostInterfaceService?method=createOrder";
$Clientid = 'LYFZP';
$Token = 'NGkJSDx3bAxojl1YN232';
$code = array('DPEX'=>array('11','DPEX','1'),'ARAMEX'=>array('002','安迈世',0),'FEDEX'=>array('FEDEX_1CC','FEDEX_1CC',';lab10_10'),'UPS'=>array('04','UPS',0),'DHL'=>array('06','DHL',';lab10_10'),'FED-SN-IP'=>array('07','FED-SN-IP',';lab10_10'),'WML-FEDEX-ZZ'=>array('05','WML-FEDEX-ZZ',';lab10_10'),'FED-XS-F'=>array('03','FED-XS-F',';lab10_10'),'CNE'=>array('08','全球优先CNE','label10x10;0'),'TCNE'=>array('09','E速宝特惠','label10x10;0'));
$printcode = $code[$data['printcode']];
//创建并预报订单
$count = array(
'Verify' => array(
'Clientid'=>$Clientid,
'Token'=>$Token
),
'OrderType' => '1',//1:快件订单 2:快递制单-非实时返回单号 3:仓储订单 4:快递制单-实时返回单号(等待时间较 长)。此方法选择 4,后续如需调用其他 方法,例如调用删除接口,其他方法 OrderType 请选择 2。
'OrderDatas' => array(0=>array(
'CustomerNumber' => $data['number'],//订单号
'ChannelCode' => $printcode[0],//渠道代码
'CountryCode' => $data['lb'],//国家二字码
'TotalWeight' => $data['zzl'],//订单重量
'TotalValue' => $data['zsbjz'],//申报价值
'Number' => $data['zjs'],//件数
'Note' => $data['number'],//备注
/**
'Insurance' => array(//是否购买保险
'Code' => '',//保险类型
'Value' => '',//保险金额
),
**/
'FeePayData' => array(//运费支付信息
'FeePayType' => 'PP',//支付方式 [ PP:预付,CC:到付, TP:第三方]
'FeePayAccountNumber' => '',//支付账号 支付方式为 TP 时必传 支付方式为 PP 并且渠道 UPS 时必传
'FeePayCountryCode' => '',//支付账号对应国家 支付方式为 TP 时必传
'FeePayPostCode' => '',//支付账号对应邮编 支付方式为 TP 并且渠道 FEDEX 时必传
),
'TaxPayData' => array(//税金/关税支付信息 OrderType 为 [快递制单] 时必传字段
'TaxPayType' => 'PP',//支付方式 [ PP:预付,CC:到付, TP:第三方]
'TaxPayAccountNumber' => '',//支付账号 支付方式为 TP 时必传 支付方式为 PP 并且渠道 UPS 时必传
'TaxPayCountryCode' => '',//支付账号对应国家 支付方式为 TP 时必传
'TaxPayPostCode' => '',//支付账号对应邮编 支付方式为 TP 并且渠道 FEDEX 时必传
),
'Recipient' => array(//收件人信息
'Name' => $data['name'],//姓名
'Addres1' => $data['address'],//地址1
'Addres2' => $data['address2'],//地址2
'Mobile' => preg_replace('/\D/s','',$data['phone']),//手机
'Province' => $data['province'],//省/州
'City' => $data['city'],//城市
'Post' => trim($data['zipcode'],' '),//邮编
),
'OrderItems' => $d))
/**,
'Volumes' => array(//材积明细 (OrderType 为快递制单必传)
'Weight' => '123123',//实重
'Number' => '123123',//件数
'Length' => '123123',//长
'Width' => '123123',//宽
'Height' => '123123',//高
),
**/
);
$count = json_encode($count,true);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query(array('json'=>$count)));
$res = curl_exec($ch);
curl_close($ch);
$res = json_decode($res,true);
if(!isset($res['returnDatas'][0]['corpBillid']))
{
echo json_encode(array('msg'=>$res['returnDatas'][0]['message'],'success'=>false));exit;
}
else
{
$yd = $this->get_dpex_yd($res['returnDatas'][0]['corpBillid'],$printcode[2]);
$fp = $this->get_dpex_fp($res['returnDatas'][0]['corpBillid'],$count);
if($yd != 'c' && $fp != 'c')
{
echo json_encode(array('msg'=>'查看发票 查看运单
','success'=>true));exit;
}
else
{
echo json_encode(array('msg'=>'获取运单失败,请重试','success'=>false));exit;
}
}
}
}
public function _text($fullorder)
{
/** 发票地址信息暂时无用
$fullorder['baddress'] = explode(',',$fullorder['baddress']);
$fullorder['baddress'] = array_reverse($fullorder['baddress']);
$fullorder['baddress'][1] = $country['ename'];
**/
//获取所用相关信息
$warehouse = $this->warehouse->read($fullorder['type']);
$country = $this->country->read($fullorder['country']);//订单国家信息
$fcountry = $this->country->read($warehouse['country']);//仓库国家信息
$warehouse['country'] = $fcountry['ename'];//仓库国家名
$warehouse['lb'] = $fcountry['lb'];//仓库国家编码
$fullorder['warehouse'] = $warehouse;//仓库数据加入订单
$fullorder['lb'] = $country['lb'];//订单国家编码加入
$fullorder['country'] = $country['ename'];//订单国家名
$fullorder['zhou'] = $country['continent'];//所属州
$express = $this->express->read($fullorder['express']);
$fullorder['express'] = $express['servicename'];
$fullorder['account'] = $express['account'];
$fullorder['printcode'] = $express['printcode'];
$fullorder['time'] = date('Y-m-d',time());
$fullorder['times'] = date('Y-m-d H:i',time());
$fullorder['sbbm']= ($fullorder['sbpm'] == 'Hair Sample') ? 67042000 : 67041100;
$fullorder['address'] = str_replace(array('&'),array('&'),$fullorder['address']);
$fullorder['address2'] = str_replace(array('&'),array('&'),$fullorder['address2']);
$fullorder['shipremarks'] = str_replace(array('<','>',';',';'),array('<','>',';
',';
'),$fullorder['shipremarks']);
$shop = $this->shop->read($fullorder['shop']);
$fullorder['shop'] = $shop['shopname'];
if(is_numeric($fullorder['pay']))
{
$pay = $this->typeclass->read($fullorder['pay']);
if($pay['classid'] == '4')
{
$fullorder['pay'] = $pay['title'];
}
}
if($fullorder['printcode'] != "USPS")
{
$fullorder['client'] = htmlspecialchars($fullorder['client']);
$fullorder['name'] = htmlspecialchars($fullorder['name']);
}
//增加退货单所需信息
$pt = '';
$fpdata = explode(';',trim($fullorder['fpdata'],';'));
foreach ($fpdata as $v)
{
$p = explode('|',trim($v,'|'));
$pt .= ''.$p[1].' * '.$p[2].'
';
}
$fullorder['pt'] = $pt;
return $fullorder;
}
public function get_dpex_yd($waybill,$PrintPaper)
{
$url = "http://ambcargo.kingtrans.cn/PostInterfaceService?method=printOrderLabel";
$Clientid = 'LYFZP';
$Token = 'NGkJSDx3bAxojl1YN232';
$count = array(
'Verify' => array(
'Clientid'=>$Clientid,
'Token'=>$Token
),
'CorpBillidDatas'=> array(0=>array('CorpBillid'=>$waybill)),
'OrderType'=> "1",//1:快件订单 2:快递制单 3:仓库订单
'PrintPaper'=> $PrintPaper,//打印纸张 快递制单只固定为:label 和 A4
'PrintContent'=> "1"//打印内容 1:地址标签 2:报关单 3:配货信息 可自由组合用“,”号隔开 如:1,2,3
);
$count = json_encode($count,true);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query(array('json'=>$count)));
$res = curl_exec($ch);
curl_close($ch);
$res = json_decode($res,true);
if($res['statusCode'] == 'success')
{
return $res['url'];
}
else
{
return 'c';
}
}
public function get_dpex_fp($waybill)
{
$url = "http://ambcargo.kingtrans.cn/PostInterfaceService?method=printOrderInvoice";
$Clientid = 'LYFZP';
$Token = 'NGkJSDx3bAxojl1YN232';
$count = array(
'Verify' => array(
'Clientid'=>$Clientid,
'Token'=>$Token
),
'CorpBillidDatas'=> array(0=>array('CorpBillid'=>$waybill))
);
$count = json_encode($count,true);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query(array('json'=>$count)));
$res = curl_exec($ch);
curl_close($ch);
$res = json_decode($res,true);
if($res['statusCode'] == 'success')
{
return $res['url'];
}
else
{
return 'c';
}
}
public function _excellkh()
{
if(isset($_SESSION['api']))
{
$user = $this->user->get_api($_SESSION['api']);
$usp = $user;
$fgshop = "";$sid = "";
$user = explode('|',trim($user['shop'],'|'));
foreach ($user as $value)
{
if($value != '18' && $value != '19' && $value != '12' && $value != '13' && $value != '9' && $value != '15' && $value != '27')
{
$fgshop .= " shop = ".$value." or";//去掉指定的店铺
}
$sid .= " id = ".$value." or";
}
}
$post = $this->input->post(NULL, TRUE);
if(isset($_GET['time']))
{
$s = $this->input->get('shop',true);
$time = $this->input->get('time',true);
$timetk = $this->input->get('timetk',true);
$timetj = $this->input->get('timetj',true);
$timetk = strtotime($timetk);
$timetj = strtotime($timetj);
if($s)
{
$shop = $this->shop->find_all("id = '$shop'");
}
else
{
$shop = $this->shop->find_all("type = 269 and (".rtrim($sid,'or').')');
}
$d = array();
$k = $timetk-24*3600;//少一天为增加选择开始天时间
$j = $timetj;
$n = ($j-$k)/(24*3600);
if($n < 1)
{
$n = 1;
}
for($i=1;$i<$n;$i++)
{
$t = $j-($n*24*60*60)+($i*24*60*60);
foreach($shop as $val)
{
$data = $this->fullorder->find_all("source != 1 and $time > '$t' and $time < '".($t+24*3600)."' and shop = '".$val['id']."'");
$dd = 0;$m = 0;
foreach($data as $v)
{
$customer = $this->customer->get_email($v['email'],$v['shop']);
$customernum = $this->fullorder->find_count("$time < '".($t+24*3600)."' and email = '".$v['email']."' and shop = '".$v['shop']."'");
preg_match_all('/[0-9]/u',$v['phone'],$result);
$numphone = join('',$result[0]);
//$customerc = $this->customer->find_all("shop = '".$v['shop']."' and address = '".$v['address']."' and numphone = '".$numphone."'",'*','id desc');
if($customer)
{
if($customernum > 1)// || (isset($customerc[0]['num']) && $customerc[0]['num'] > 1) // || $customerc['type'] == 1 && $customerc['num'] > 1
{
$dd++;
$m += $v['shouldmoney'];
}
}
}
$ddzb = ($dd==0 || count($data) == 0)?0:sprintf("%01.2f",$dd/count($data)*100).'%';
$ddjezb = ($m==0 || array_sum(array_column($data,'shouldmoney')) == 0)?0:sprintf("%01.2f",$m/array_sum(array_column($data,'shouldmoney'))*100).'%';
$d[] = array(date('Y-m-d',$t),$val['shopname'],count($data),sprintf("%01.2f",array_sum(array_column($data,'shouldmoney'))),$dd,$m,$ddzb,$ddjezb);
}
}
$title = "老客户数据统计".date('Y-m-d H-i-s',time());
$titlename = "
时间 |
店铺 |
订单数 |
订单金额 |
老客户订单数 |
老客户订单金额 |
老客户订单数占比 |
老客户订单金额占比 |
";
$filename = $title.".xls";
$tail = "\n";
$this->excel->get_fz2($d,$titlename,$filename,$tail);
}
}
public function _excelshop()
{
if(isset($_SESSION['api']))
{
$user = $this->user->get_api($_SESSION['api']);
$usp = $user;
$fgshop = "";$sid = "";
$user = explode('|',trim($user['shop'],'|'));
foreach ($user as $value)
{
if($value != '18' && $value != '19' && $value != '12' && $value != '13' && $value != '9' && $value != '15' && $value != '27')
{
$fgshop .= " shop = ".$value." or";//去掉指定的店铺
}
$sid .= " id = ".$value." or";
}
}
$post = $this->input->post(NULL, TRUE);
if(isset($_GET['time']))
{
$s = $this->input->get('shop',true);
$time = $this->input->get('time',true);
$timetk = $this->input->get('timetk',true);
$timetj = $this->input->get('timetj',true);
$timetk = strtotime($timetk);
$timetj = strtotime($timetj);
if($s)
{
$shop = $this->shop->find_all("id = '$shop'");
}
else
{
$shop = $this->shop->find_all("type = 269 and (".rtrim($sid,'or').')');
}
$d = array();
$k = $timetk-24*3600;//少一天为增加选择开始天时间
$j = $timetj;
$n = ($j-$k)/(24*3600);
if($n < 1)
{
$n = 1;
}
for($i=1;$i<$n;$i++)
{
$t = $j-($n*24*60*60)+($i*24*60*60);
foreach($shop as $val)
{
$data = $this->fullorder->find_all("$time > '$t' and $time < '".($t+24*3600)."' and shop = '".$val['id']."'");
$dd = 0;$m = 0;
$d[] = array(date('Y-m-d',$t),$val['shopname'],count($data),sprintf("%01.2f",array_sum(array_column($data,'shouldmoney'))));
}
}
$title = "店铺数据统计".date('Y-m-d H-i-s',time());
$titlename = "";
$filename = $title.".xls";
$tail = "\n";
$this->excel->get_fz2($d,$titlename,$filename,$tail);
}
}
public function _qczd()
{
$post = $this->input->post(NULL, TRUE);
if(isset($post['number']))
{
$number = $this->input->post('number',true);
if(!$number || $number == '' || $number == NULL)
{
echo json_encode(array('msg'=>'没有编号信息','success'=>false));exit;
}
$a = $this->whlabel->find_all("zd = '$number' and state = '0'");
foreach ($a as $v)
{
$this->whlabel->save(array('zd'=>''),$v['id']);
}
echo json_encode(array('msg'=>'清除完成!','success'=>true));exit;
}
}
public function _ggdd()
{
$post = $this->input->post(NULL, TRUE);
if(isset($post['number']))
{
$number = $this->input->post('number',true);
$guarantee = $this->input->post('guarantee',true);
$quantity = $this->input->post('quantity',true);
$post = array();
if($guarantee)
{
$post['guarantee'] = $guarantee;
}
if($quantity)
{
$post['quantity'] = $quantity;
}
if(!$number || $number == '' || $number == NULL)
{
echo json_encode(array('msg'=>'没有编号信息','success'=>false));exit;
}
if(!$post)
{
echo json_encode(array('msg'=>'没有修改信息','success'=>false));exit;
}
$fullorder_name = 'fullorder';
$y = $this->fullorder->get_number($number);
if(!$y)
{
$fullorder_name = 'fullordersmt';
$y = $this->fullordersmt->get_number($number);
if(!$y)
{
$fullorder_name = 'fullordertt';
$y = $this->fullordertt->get_number($number);
if(!$y)
{
echo json_encode(array('msg'=>'无此编号数据','success'=>false));exit;
}
}
}
$this->$fullorder_name->save($post,$y['id']);
echo json_encode(array('msg'=>'修改完成!','success'=>true));exit;
}
}
}