model=new\app\admin\model\Order;}functionexcel_handle($ids){$this->success('处理成功,正在生成报表!',null,$ids);}函数excout($ids=null){$info=db('order')->find($ids);if(empty($info)){$this->error('订单不存在');}$list=db('order_details')->alias('details')->join('goods','goods.id=details.goods_id')->join('goods_sku','goods_sku.id=details.sku_id')->field('详情.*,goods.nameasgoods_name,goods_sku.nameassuk_name')->where('order_id',$info['id'])->select();//订单信息error_reporting(E_ALL);ini_set('display_errors',TRUE);ini_set('display_startup_errors',TRUE);ini_set("error_reporting","E_ALL&~E_NOTICE");define('EOL',(PHP_SAPI=='cli')?PHP_EOL:'
');date_default_timezone_set('欧洲/伦敦');包括“扩展/phpexcel/Classes/PHPExcel/IOFactory.php”;//设置模板文件$objPHPExcel=\PHPExcel_IOFactory::load("PI-larkkey.xls");//IncludejsonConvertstringtoarray//data//$billData=json_decode($_REQUEST["billData"],true);//月表$months=array(1=>'Jan',2=>'Feb',3=>'Mar',4=>'Apr',5=>'May',6=>'Jun',7=>'七月',8=>'八月',9=>'九月',10=>'十月',11=>'十一月',12=>'十二月');//基础信息$basic_info=array('consignee_company_name'=>$info['contactname'],'consignee_address'=>$info['address'],'consignee_tel'=>$info['tel'],'loading_port'=>$info['loading'],'destination_port'=>$info['destination'],'shippment_way'=>$info['shippment'],'invoice_number'=>'INVOICENO:'.$info['发票号码']);//基本信息日期$basic_info['date']=$months[(int)Date('m')]."".Date('D').",".Date("Y");//基本信息填充元格式$objPHPExcel->getActiveSheet()->setCellValue('B7',$basic_info['consignee_company_name'])->setCellValue('B8',$basic_info['consignee_address'])->setCellValue('B9',$basic_info['consignee_tel'])->setCellValue('B10','宁波')->setCellValue('B11',$basic_info['destination_port'])->setCellValue('B12','byexpress')->setCellValue('G7',$basic_info['invoice_number'])->setCellValue('G8',$basic_info['date']);//设置B10$objValidation_=$objPHPExcel->getActiveSheet()->getCell("B10")->getDataValidation();$objValidation_->setType(\PHPExcel_Cell_DataValidation::TYPE_LIST)->setErrorStyle(\PHPExcel_Cell_DataValidation::STYLE_INFORMATION)->setAllowBlank(false)->setShowInputMessage(true)->setShowErrorMessage(true)->setShowDropDown(true)->setErrorTitle('输入的值错误')->setError('您输入的值不在下拉框列表中')->setPromptTitle('设备类型')->setFormula1('"宁波,深圳,广州"');//设置B12$objValidation_=$objPHPExcel->getActiveSheet()->getCell("B12")->getDataValidation();$objValidation_->setType(\PHPExcel_Cell_DataValidation::TYPE_LIST)->setErrorStyle(\PHPExcel_Cell_DataValidation::STYLE_INFORMATION)->setAllowBlank(false)->setShowInputMessage(true)->setShowErrorMessage(true)->setShowDropDown(true)->itT'的输入的值错误')->setError('您输入的值不在下拉列表中')->setPromptTitle('设备类型')->setFormula1('"快递,空运,快递"');//列表信息//$list_data=array(//'0'=>array(//'pic'=>'',//图片//'item_no'=>'001',//商品编号//'description'=>'wife',//description//'protocol'=>'sex',//attribute//'color'=>'green',//color//'qty_pcs'=>'100',//Quantity/Pcs-装箱数量//'usd_pcs'=>'50',//US$/Pcs//'amount'=>'100'//总价//)//);$list_data=$list;//$PHPSheet->getColumnDimension('C')->setWidth(70);//$PHPSheet->getRowDimension(21)->setRowHeight(75);//高度//随环填满相同标题单元格$row=14;foreach($list_dataas$r=>$dataRow){$this->excelPic($dataRow['image'],'A'.$row,$objPHPExcel->getActiveSheet());$objPHPExcel->getActiveSheet()->getRowDimension($row)->setRowHeight(100);$objPHPExcel->getActiveSheet()//->setCellValue('A'.$row,$dataRow['image'])->setCellValue('B'.$row,$dataRow['model_no'])->setCellValue('c'.$row,$dataRow['goods_name'])->setCellValue('D'.$row,$dataRow['suk_name'])->setCellValue('E'.$row,$dataRow['mode']==1?'ReadToSheep':'Customization')->setCellValue('F'.$row,$dataRow['num'])->setCellValue('G'.$row,$dataRow['公关ice'])->setCellValue('H'.$row,$dataRow['num']*$dataRow['price']);$行++;}//显示总价$objPHPExcel->getActiveSheet()->setCellValue('A'.$row,'Total:'."")->setCellValue('H'.$row,$info['amount'])->setCellValue('A'.($row+2),"Note:")//下面是固定文本信息->setCellValue('A'.($row+3),"1,PriceTerm:FOBNingbo")->setCellValue('A'.($row+4),"2,PriceValidity:30days")->setCellValue('A'.($row+5),"3,PaymentTerm:30%T/T,发货前70%余额或L/C或Paypal")->setCellValue('A'.($row+6),"4,Packing:whiteneuralpackingorourlogopacking,")->setCellValue('A'.($row+7),"如果需要定制包装,需要MOQ。包装成本需要调整。")->setCellValue('A'.($row+10),"BankDetail:");$objWriter=\PHPExcel_IOFactory::createWriter($objPHPExcel,'Excel5');ob_end_clean();header('Content-Type:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');header('Content-Disposition:attachment;filename=larkkey_'.time().'.xlsx');header('缓存控制:max-age=0');$objWriter->save("php://output");出口;//让访问浏览器直接下载文件流//Header("Location:/uploads/larkkey_".time().".xls");}函数excelPic($url,$seat,$obj){if(empty($url)){return$obj;$temp_pic=$this->download($url,'../public/uploads/temp/');$temp[]=$local_pic_path='../public/uploads/temp/'.$temp_pic;如果(file_exists($local_pic_path)){$img=new\PHPExcel_Worksheet_Drawing();$img->setPath($local_pic_path);//写入图片路径//$img->setHeight(100);//写入图片高度$img->setWidth(100);//写入图片宽度//$img->setOffsetX(105);//写入指定网格中图片的X坐标值//$img->setOffsetY(5);//写入指定网格中的图片gridY坐标值//$img->setRotation(1);//设置旋转角度//$img->getShadow()->setVisible(true);//$img->getShadow()->setDirection(50);$img->setCoordinates($seat);//设置图片所在表格的位置$img->setWorksheet($obj);//将图片写入当前表格}return$obj;}函数下载($url,$path='images/'){$ch=curl_init();curl_setopt($ch,CURLOPT_URL,$url);curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,30);curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);//信任任何证书$file=curl_exec($ch);curl_close($ch);$filename=pathinfo($url,PATHINFO_BASENAME);$resource=fopen($path.$filename,'a');fwrite($资源,$文件);fclose($资源);返回$文件名;}}文件
