PHPExcel开发文档
https://www.kancloud.cn/chunyu/php_basic_knowledge/1041088
1、控制器-平台订单-导出
//功能:提交导入订单-天猫
public function loadOrderFrom_tmall(){
$shopId=request()->param('id/d')?request()->param('id/d'):0;
@ini_set('memory_limit','512M');
set_time_limit(0);
if($shopId<=0) errorMsg(400,'网络错误,请刷新重试!');
$shop=Shop::get($shopId);
if(!$shop) errorMsg(400,'未查询到店铺信息!');
if($shop->status==0) errorMsg(400,'店铺已删除!');
if($shop->supplierId<=0) errorMsg(400,'店铺未绑定客户!');
if($shop->platCateId!=1) errorMsg(400,'网络异常,请刷新重试!');
if (count($_FILES) < 0) errorMsg(400,'文件读取失败!请刷新重试!');
if ($_FILES['file']['size'] > 3145728) errorMsg(400, '上传文件大小超过限制!');
$datas = $this->getexcelUnRepeat($_FILES["file"]["tmp_name"]);//读取EXC文件,组装成数组
if(!$datas) errorMsg(400,'导入的表格内容不能为空!');
unset($datas[0]);
//生成文件名
$path=APP_PUBLIC.'download/'.date('Ymd');
if(!is_dir($path)){
mkdir($path,0755);
}
$filename=date('YmdHis').str_pad(rand(0, 999), 3, '0', STR_PAD_LEFT).'.txt';
//订单前缀
$settingArr=Setting::get(['companyId'=>$shop->companyId,'enName'=>'orderPrefix_C','status'=>1]);
$needIdcard = Setting::get(array('companyId'=>$this->companyId,'enName'=>'needIdcard'));
$orderArr=$torderArr=$sorderArr=$pAddressArr=array();
$this->hasUrl=$panum=0;
$addr=new Addr();
foreach($datas as $key=>$data) {
$orderSn = delSpecilaChar($data[0], 4);//订单号
$n = $key + 1;
if (!$orderSn) {
$str = '第' . $n . '行订单编号:为空!' . "\r\n";
@file_put_contents($path . '/' . $filename, $str, FILE_APPEND);
$this->hasUrl = 1;
continue;
}
//验证第三方订单是否已经存在
$oret = OrderThird::get(['order_id' => $orderSn, 'deleted' => 0, 'shopId' => $shopId, 'companyId' => $this->companyId]);
if ($oret) {
$str = '第' . $n . '行订单编号【' . $orderSn . '】,已经存在!' . "\r\n";
@file_put_contents($path . '/' . $filename, $str, FILE_APPEND);
$this->hasUrl = 1;
continue;
}
//验证订单是否存在
if ($this->companyId == 2) {
$oret = Order::get(['forderSn' => $orderSn, 'deleted' => 0, 'companyId' => $this->companyId]);
} else {
$oret = Order::get(['forderSn' => $orderSn, 'deleted' => 0, 'shopId' => $shopId, 'companyId' => $this->companyId]);
}
if ($oret) {
$str = '第' . $n . '行订单编号【' . $orderSn . '】,已经存在!' . "\r\n";
@file_put_contents($path . '/' . $filename, $str, FILE_APPEND);
$this->hasUrl = 1;
continue;
}
$ostate = trim($data[11]);
if ($ostate == '交易关闭') continue;
//多商品订单,只获取一次订单信息
if (!in_array($orderSn, $sorderArr)) {
$isSync = 1;
$remsg = '';
$status = 1;
if ($needIdcard->value == 1) $consignee = delSpecilaChar($data[13], 6);//下单人
if ($needIdcard->value == 0) $consignee = delSpecilaChar($data[13], 5);//下单人
if (!$consignee) {
$str = '第' . $n . '订单号【' . $orderSn . '】收货人姓名不能为空!' . "\r\n";
@file_put_contents($path . '/' . $filename, $str, FILE_APPEND);
$this->hasUrl = 1;
continue;
}
$oaddress = $address = delSpecilaChar($data[14], 7);
if (!$address) {
$str = '第' . $n . '订单号【' . $orderSn . '】收货地址不能为空!' . "\r\n";
@file_put_contents($path . '/' . $filename, $str, FILE_APPEND);
$this->hasUrl = 1;
continue;
}
$mobile = trim($data[17]);
if (!$mobile) {
$str = '第' . $n . '订单号【' . $orderSn . '】联系手机号不能为空!' . "\r\n";
@file_put_contents($path . '/' . $filename, $str, FILE_APPEND);
$this->hasUrl = 1;
continue;
}
$buyerIdNumber = '';
if ($needIdcard->value == 1) {
if (!isset($data[71])) {
$str = '第' . $n . '订单号【' . $orderSn . '】没有身份证!' . "\r\n";
@file_put_contents($path . '/' . $filename, $str, FILE_APPEND);
$this->hasUrl = 1;
continue;
}
$buyerIdNumber = delSpecilaChar($data[71], 8);
if (!$buyerIdNumber) {
$str = '第' . $n . '订单号【' . $orderSn . '】身份证不能为空!' . "\r\n";
@file_put_contents($path . '/' . $filename, $str, FILE_APPEND);
$this->hasUrl = 1;
continue;
}
$buyerIdNumber = strtoupper($buyerIdNumber);
} else {
if (isset($data[71])) {
$buyerIdNumber = delSpecilaChar($data[71], 8);
$buyerIdNumber = strtoupper($buyerIdNumber);
}
}
//运单号
// $reCode=str_replace("No:",'',trim($data[24]));
// $logisticsCode=trim($reCode);
// if(!$logisticsCode){
// $str='第'.$n.'行运单号不能为空!'."\r\n";
// @file_put_contents($path.'/'.$filename,$str,FILE_APPEND);
// $this->hasUrl=1;
// continue;
// }
// if (!preg_match("/^[A-Za-z0-9]+$/u", $logisticsCode)){
// $str='第'.$n.'运单号'.$logisticsCode.'有非法字符!'."\r\n";
// @file_put_contents($path.'/'.$filename,$str,FILE_APPEND);
// $this->hasUrl=1;
// continue;
// }
//省
$province = $city = $district = '';
$ret = 0;
foreach ($this->raddrArr as $raddr) {
$ret = mb_strpos($address, $raddr, 0, 'utf-8');
if ($ret > 0) break;
}
$saddr = '';
if ($ret > 0) {
$saddr = mb_substr($address, 0, $ret + 1, 'utf-8');//取前三位市
}
$pAddress = array();
if ($saddr) {
$pAddress = PlatAddress::get(['saddr' => $saddr]);
}
if ($pAddress) {
$province = $pAddress->province;
$city = $pAddress->city;
$district = $pAddress->district;
} else {
$ret = $addr->checkAddr($address, '第' . $n . '订单号【' . $orderSn . '】,');
if ($ret['retCode'] == 400) {
$isSync = 0;
$remsg .= $ret['retMessage'];
$status = 2;
} else {
$province = $ret['data']['province'];
$city = $ret['data']['city'];
$district = $ret['data']['district'];
if ($saddr) {
$pAddressArr[$panum]['saddr'] = $saddr;
$pAddressArr[$panum]['address'] = $oaddress;
$pAddressArr[$panum]['province'] = $province;
$pAddressArr[$panum]['city'] = $city;
$pAddressArr[$panum]['district'] = $district;
$panum++;
}
}
/*$sprovince=mb_substr($address,0,2,'utf-8');//取地址前两位
$rprovince=Address::get(['name'=>['like',$sprovince.'%'],'level'=>1]);
if(!$rprovince){
$isSync=0;
$remsg.='第'.$n.'订单号【'.$orderSn.'】地址省份异常!';
$status=2;
}else{
$province=$rprovince->name;
$ret=mb_strpos($address,$province,0,'utf-8');
if($ret===0){
$address=mb_substr($address,mb_strlen($province,'utf-8'),mb_strlen($address,'utf-8'),'utf-8');//去掉地址里面的省份
}else{
$ret=mb_strpos($address,$sprovince.'省',0,'utf-8');
if($ret===0){
$address=mb_substr($address,mb_strlen($sprovince.'省','utf-8'),mb_strlen($address,'utf-8'),'utf-8');//去掉地址里面的省份
}else{
$address=mb_substr($address,mb_strlen($sprovince,'utf-8'),mb_strlen($address,'utf-8'),'utf-8');//去掉地址里面的省份
}
}
//市
$scity=mb_substr($address,0,2,'utf-8');//取前三位市
$rcity=Address::get(['name'=>['like',$scity.'%'],'parentId'=>$rprovince->addrId]);
if(!$rcity){
$isSync=0;
$remsg.='第'.$n.'订单号【'.$orderSn.'】地址城市异常!';
$status=2;
}else{
$city=$rcity->name;
$ret=mb_strpos($address,$city,0,'utf-8');
if($ret===0){
$address=mb_substr($address,mb_strlen($city,'utf-8'),mb_strlen($address,'utf-8'),'utf-8');//去掉地址里面的省份
}else{
$address=mb_substr($address,mb_strlen($scity,'utf-8'),mb_strlen($address,'utf-8'),'utf-8');//去掉地址里面的省份
}
//区
$sdistrict=mb_substr($address,0,2,'utf-8');//取前三位区
$rdistrict=Address::get(['name'=>['like',$sdistrict.'%'],'parentId'=>$rcity->addrId]);
if(!$rdistrict){
$isSync=0;
$remsg.='第'.$n.'订单号【'.$orderSn.'】地址区异常!';
$status=2;
}else{
$district=$rdistrict->name;
if($saddr){
$pAddressArr[$panum]['saddr']=$saddr;
$pAddressArr[$panum]['address']=$oaddress;
$pAddressArr[$panum]['province']=$province;
$pAddressArr[$panum]['city']=$city;
$pAddressArr[$panum]['district']=$district;
$panum++;
}
}
}
}*/
}
//第三方订单
//region
$torderArr[$orderSn]['shopId'] = $shopId;
$torderArr[$orderSn]['companyId'] = $shop->companyId;
$torderArr[$orderSn]['order_id'] = $orderSn;
$torderArr[$orderSn]['consignee'] = $consignee;
$torderArr[$orderSn]['buyerName'] = $consignee;
$torderArr[$orderSn]['buyerRegNo'] = $consignee;
$torderArr[$orderSn]['province'] = $province;
$torderArr[$orderSn]['city'] = $city;
$torderArr[$orderSn]['district'] = $district;
// $torderArr[$orderSn]['logisticsCode']=$logisticsCode;//运单号
$torderArr[$orderSn]['address'] = $oaddress;
$torderArr[$orderSn]['mobile'] = $mobile;
$torderArr[$orderSn]['buyerIdNumber'] = $buyerIdNumber;
$torderArr[$orderSn]['buyerIdNumber'] = $buyerIdNumber;
$acturalPaid = floatval(str_replace(',', '', $data[9]));
//$discount=$goodsValue-$acturalPaid;
$torderArr[$orderSn]['goodsValue'] = 0;
$torderArr[$orderSn]['acturalPaid'] = $acturalPaid;
$torderArr[$orderSn]['discount'] = 0;
$addtime = date('Y-m-d H:i:s', strtotime($data[19]));
$torderArr[$orderSn]['addTime'] = $addtime;
$paytime = date('Y-m-d H:i:s', strtotime($data[20]));// 订单付款时间
$torderArr[$orderSn]['payTime'] = $paytime;
$torderArr[$orderSn]['remark'] = '';
$cmark = delSpecilaChar($data[25], 7);
if ($cmark) {
$torderArr[$orderSn]['remark'] .= $cmark;
}
$torderArr[$orderSn]['isSync'] = $isSync;
$torderArr[$orderSn]['status'] = $status;
$torderArr[$orderSn]['gcount'] = 0;
$torderArr[$orderSn]['gNum'] = 1;
$torderArr[$orderSn]['remsg'] = $remsg;
$torderArr[$orderSn]['n'] = $n;//endregion
//订单
//region
$orderArr[$orderSn]['companyId'] = $shop->companyId;
$orderArr[$orderSn]['shopId'] = $shop->shopId;
$orderArr[$orderSn]['supplierCode'] = $shop->dealer->supplierCode;
$orderArr[$orderSn]['settleName'] = $shop->dealer->supplierName;
$orderArr[$orderSn]['orderSn'] = $settingArr['value'] . date('YmdHis') . str_pad(rand(0, 999999), 6, '0', STR_PAD_LEFT);
$orderArr[$orderSn]['forderSn'] = $orderSn;
$orderArr[$orderSn]['consignee'] = $consignee;
$orderArr[$orderSn]['buyerName'] = $consignee;
$orderArr[$orderSn]['buyerRegNo'] = $consignee;
$orderArr[$orderSn]['province'] = $province;
$orderArr[$orderSn]['city'] = $city;
$orderArr[$orderSn]['district'] = $district;
$orderArr[$orderSn]['address'] = $oaddress;
$orderArr[$orderSn]['mobile'] = $mobile;
$buyerRegNo = delSpecilaChar($data[1], 7);
if (!$buyerRegNo) {
$buyerRegNo = $consignee;
}
$orderArr[$orderSn]['buyerRegNo'] = $buyerRegNo;
$orderArr[$orderSn]['buyerName'] = $consignee;
$orderArr[$orderSn]['buyerIdNumber'] = $buyerIdNumber;
$orderArr[$orderSn]['goodsValue'] = 0;
$orderArr[$orderSn]['discount'] = 0;
$orderArr[$orderSn]['acturalPaid'] = $acturalPaid;
$orderArr[$orderSn]['remark'] = $torderArr[$orderSn]['remark'];
$orderArr[$orderSn]['thirdStatus'] = 5;
$orderArr[$orderSn]['thirdInfo'] = '查询到对应关系,直接跳过!';
$orderArr[$orderSn]['thirdTime'] = date('Y-m-d H:i:s');
$orderArr[$orderSn]['senderId'] = 0;
$orderArr[$orderSn]['gqty'] = 0;
$orderArr[$orderSn]['gcount'] = 0;
$orderArr[$orderSn]['gNum'] = 1;
$orderArr[$orderSn]['remsg'] = '';
//endregion
$sorderArr[] = $orderSn;
}
// $goodsName=$data[22];
$goodsCode = $data[70];
if (!$goodsCode) {
$str = '第' . $n . '行订单编号【' . $orderSn . '】,宝贝标题不能为空!' . "\r\n";
@file_put_contents($path . '/' . $filename, $str, FILE_APPEND);
$this->hasUrl = 1;
unset($torderArr[$orderSn]);
unset($orderArr[$orderSn]);
continue;
}
if (intval($data[70]) == 2) {
$goodsArr = explode(",", $goodsCode);
} else {
$goodsArr = explode("+", $goodsCode);
}
foreach ($goodsArr as $key => $v) {
$goodsName = '';
// if (intval($data[72]) == 2) {
// $qty = intval(delSpecilaChar($data[27], 1)) / count($goodsArr);
// $price = round(floatval($data[10]) / intval(delSpecilaChar($data[27], 1)), 2);
// } else {
// $qty = intval(delSpecilaChar($data[27], 1));
// $price = round(floatval($data[10]) / (intval(delSpecilaChar($data[27], 1)) * count($goodsArr)), 2);
// }
//计算数量与单价
$qty = intval(delSpecilaChar($data[26], 1)) / count($goodsArr);
$price = round(floatval($data[9]) / intval(delSpecilaChar($data[26], 1)), 2);
$torderArr[$orderSn]['goods'][$torderArr[$orderSn]['gNum']]['gNum'] = $torderArr[$orderSn]['gNum'];
$torderArr[$orderSn]['goods'][$torderArr[$orderSn]['gNum']]['sku_id'] = $v;
$torderArr[$orderSn]['goods'][$torderArr[$orderSn]['gNum']]['sku_name'] = $goodsName;
$torderArr[$orderSn]['goods'][$torderArr[$orderSn]['gNum']]['qty'] = $qty;
$torderArr[$orderSn]['goods'][$torderArr[$orderSn]['gNum']]['price'] = $price;
$torderArr[$orderSn]['goodsValue'] = floatval($data[10]);
if (intval($data[22]) == 2) {
$torderArr[$orderSn]['gcount'] = intval(delSpecilaChar($data[26], 1));
} else {
$torderArr[$orderSn]['gcount'] = intval(delSpecilaChar($data[26], 1)) * count($goodsArr);
}
$skuGoods = Sku::alias('s')->join('sku_goods sg', 'sg.skuId=s.skuId', 'left')->join('goods g', 'g.id=sg.goodsId and g.deleted=0', 'left')
->join('goods_hscode hs', 'hs.hsCode=g.Hscode and hs.status=1', 'left')->field('sg.qty,sg.goodsId,g.goodsName,g.goodsCode,hs.taxRate')
->where(['s.shopId' => $shop->shopId, 's.skuCode' => $v])->select();
setLog(json_encode($skuGoods),'skuGoods');
if (!$skuGoods) {
$torderArr[$orderSn]['isSync'] = 0;
$torderArr[$orderSn]['status'] = 2;
$torderArr[$orderSn]['remsg'] .= '商品:' . $v . '未查询到对应未查询到对应的关系!';
} else {
$skugoodsNum = 0;
$iscon = true;
foreach ($skuGoods as $sg) {
$torderArr[$orderSn]['goods'][$torderArr[$orderSn]['gNum']]['sku_id'] = $sg->goodsCode;
if (!($sg->goodsName)) {
$torderArr[$orderSn]['isSync'] = 0;
$torderArr[$orderSn]['status'] = 2;
$torderArr[$orderSn]['remsg'] .= 'sku' . $v . '未查询到对应的商品【' . $sg->goodsId . '】信息;';
$iscon = false;
continue;
}
if (!($sg->taxRate)) {
$torderArr[$orderSn]['isSync'] = 0;
$torderArr[$orderSn]['status'] = 2;
$torderArr[$orderSn]['remsg'] .= 'sku' . $v . '未查询到对应商品【' . $sg->goodsName . '】的hs编码信息;';
$iscon = false;
continue;
}
if ($sg->taxRate > '1') {
$torderArr[$orderSn]['isSync'] = 0;
$torderArr[$orderSn]['status'] = 2;
$torderArr[$orderSn]['remsg'] .= 'sku' . $v . '对应商品【' . $sg->goodsName . '】的商品税率【' . $sg->taxRate . '】异常;';
$iscon = false;
continue;
}
$skugoodsNum += $sg->qty;
}
if ($iscon) {
$oprice = round($price / $skugoodsNum, 2);
foreach ($skuGoods as $sg) {
$orderArr[$orderSn]['goods'][$orderArr[$orderSn]['gNum']]['gNum'] = $orderArr[$orderSn]['gNum'];
$orderArr[$orderSn]['goods'][$orderArr[$orderSn]['gNum']]['goodsName'] = $sg->goodsName;
$orderArr[$orderSn]['goods'][$orderArr[$orderSn]['gNum']]['goodsCode'] = $sg->goodsCode;
$orderArr[$orderSn]['goods'][$orderArr[$orderSn]['gNum']]['taxRate'] = $sg->taxRate;
$oqty = $qty * $sg->qty;
//$oprice=round($price/$sg->qty,2);
$ototalPrice = $oqty * $oprice;
$orderArr[$orderSn]['goods'][$orderArr[$orderSn]['gNum']]['qty'] = $oqty;
$orderArr[$orderSn]['goods'][$orderArr[$orderSn]['gNum']]['price'] = $oprice;
$orderArr[$orderSn]['goods'][$orderArr[$orderSn]['gNum']]['totalPrice'] = $ototalPrice;
$orderArr[$orderSn]['goodsValue'] += $ototalPrice;
$orderArr[$orderSn]['gNum']++;
$orderArr[$orderSn]['gqty'] += $oqty;
$orderArr[$orderSn]['gcount']++;
}
}
}
$torderArr[$orderSn]['gNum']++;
}
}
$count=0;
setLog(json_encode($torderArr),'torderArr');
if($torderArr){
foreach($torderArr as $key=>$torder){
$n=$torder['n'];
Db::startTrans();
try{
$tgoodsArr=$torder['goods'];
/*$tgValue=$torder['goodsValue'];
$tgcount=$torder['gcount'];
$price=round($tgValue/$tgcount,2);
$tamount=0;
foreach($tgoodsArr as $k=>$tg){
$tamount+=$price*$tg['qty'];
$tgoodsArr[$k]['price']=$price;
}
/*if($tamount>$tgValue){
$diff=$tamount-$tgValue;
$torder['goodsValue']=$tamount;
$torder['discount']=$torder['discount']+$diff;
}
if($tamount<$tgValue){
$diff=$tgValue-$tamount;
if($torder['discount']>=$diff){
$torder['goodsValue']=$tamount;
$torder['discount']=$torder['discount']-$diff;
}else{
$torder['goodsValue']=$torder['acturalPaid']=$tamount;
$torder['discount']=0;
}
}*/
if($torder['goodsValue']>$torder['acturalPaid']){
$torder['discount']=$torder['goodsValue']-$torder['acturalPaid'];
}
if($torder['discount']<0){
$torder['discount']=0;
}
unset($torder['goods']);
unset($torder['gNum']);
unset($torder['n']);
unset($torder['gcount']);
$mtorder=new OrderThird($torder);
$mtorder->save();
$mtorder->orderGoods()->saveAll($tgoodsArr);
$taction=array();
$taction['companyId']=$shop->companyId;
$taction['userId']=$shop->userId;
$taction['type']=0;
$taction['remark']=$shop->userName.'通过【平台店铺】导入订单:'.$torder['order_id'];
$mtorder->oaction()->save($taction);
if($torder['isSync']==1){
$order=$orderArr[$key];
$ogoodsArr=$order['goods'];
/*$ogValue=$order['goodsValue'];
$ogcount=$order['gqty'];
$oamount=0;
$price=round($ogValue/$ogcount,2);
foreach($ogoodsArr as $o=>$og){
/*$totalPrice=$price*$og['qty'];
$ogoodsArr[$o]['price']=$price;
$ogoodsArr[$o]['totalPrice']=$totalPrice;
$oamount+=$totalPrice;
$order['goodsValue']+=$totalPrice;
}
if($oamount>$ogValue){
$diff=$oamount-$ogValue;
$order['goodsValue']=$oamount;
$order['discount']=$order['discount']+$diff;
}
if($oamount<$ogValue){
$diff=$ogValue-$oamount;
if($torder['discount']>=$diff){
$order['goodsValue']=$oamount;
$order['discount']=$order['discount']-$diff;
}else{
$order['goodsValue']=$order['acturalPaid']=$oamount;
$order['discount']=0;
}
}*/
if($order['goodsValue']>$order['acturalPaid']){
$order['discount']=$order['goodsValue']-$order['acturalPaid'];
}
$goodsValue=$order['goodsValue'];
$discount=$order['discount'];
foreach($ogoodsArr as $o=>$ogoods){
//优惠单价(含税)=(商品单价*(商品总价-优惠金额))/(商品总价*(1+税率))
$fenzi=$ogoods['price']*($goodsValue-$discount);
$fenmu=$goodsValue*(1+$ogoods['taxRate']);
$dprice=$fenzi/$fenmu;
$dprice=round($dprice,2);
$ogoodsArr[$o]['dprice']=$dprice;
//优惠单价=(商品单价*(商品总价-优惠金额))/商品总价
$fenzi=$ogoods['price']*($goodsValue-$discount);
$tprice=$fenzi/$goodsValue;
$tprice=round($tprice,2);
$ogoodsArr[$o]['tprice']=$tprice;
//税
$taxTotal=$dprice*$ogoods['taxRate'];
$taxTotal=round($taxTotal,2);
$ogoodsArr[$o]['taxTotal']=$taxTotal;
unset($ogoodsArr[$o]['taxRate']);
}
unset($order['goods']);
unset($order['gNum']);
unset($order['gqty']);
//订单日志
$action=array();
$action['companyId']=$shop->companyId;
$action['userId']=$shop->userId;
$action['type']=0;
$action['remark']=$shop->userName.'通过【平台店铺】导入订单:'.$order['orderSn'].';';
$order['createtime']=$addtime;//第三方下单时间
$morder=new Order($order);
$morder->save();
$morder->orderGoods()->saveAll($ogoodsArr);
$morder->oaction()->save($action);
//统计
$this->staticChart($shopId,1,0,$order['acturalPaid'],$morder->orderId);
}
Db::commit();
$count++;
}catch (Exception $e){
Db::rollback();
$str='第'.$n.'行订单编号【'.$torder['order_id'].'】异常:'.$e->getLine().'.'.$e->getMessage().'!'."\r\n";
@file_put_contents($path.'/'.$filename,$str,FILE_APPEND);
$this->hasUrl=1;
}
}
}
if($pAddressArr){
Db::startTrans();
try{
$pAddr=new PlatAddress;
$pAddr->saveAll($pAddressArr);
Db::commit();
}catch (Exception $e){
Db::rollback();
}
}
if($count>0){
Db::startTrans();
try{
$shop->amount=$shop->amount+$count;
$shop->updateTime=date('Y-m-d H:i:s');
$shop->save();
Db::commit();
}catch(Exception $e){
Db::rollback();
} //功能:读取excel文档内容
protected function getexcelUnRepeat($filename){
vendor("phpexcel.PHPExcel");
//$objPHPExcel = new \PHPExcel();
$objPHPExcel = \PHPExcel_IOFactory::createReaderForFile($filename);//use excel2007 for 2007 format
$objReader = $objPHPExcel->load($filename);
$objWorksheet = $objReader->setActiveSheetIndex();
$data=$objWorksheet->toArray();
return $data;
}
}
$url='';
if($this->hasUrl){
$url=request()->domain().'/public/download/'.date('Ymd').'/'.$filename;
}
errorMsg(200,'成功导入'.$count.'条订单!',$url);
}
读取EXC文件,组装成数组
//功能:读取excel文档内容
protected function getexcelUnRepeat($filename){
vendor("phpexcel.PHPExcel");
//$objPHPExcel = new \PHPExcel();
$objPHPExcel = \PHPExcel_IOFactory::createReaderForFile($filename);//use excel2007 for 2007 format
$objReader = $objPHPExcel->load($filename);
$objWorksheet = $objReader->setActiveSheetIndex();
$data=$objWorksheet->toArray();
return $data;
}