作者 潘浩文
1 个管道 的构建 通过 耗费 2 秒

接口对接测试

... ... @@ -2,6 +2,7 @@
namespace api\portal\controller;
use think\Controller;
use think\Db;
use PHPExcel;
/**
* @title 前台补充
... ... @@ -172,4 +173,56 @@ class PortalController extends Controller
Db::name('money_log')->insert(['create_time'=>time(),'user_id'=>$user['id'],'money'=>$order['money'],'now_money'=>$user['money']+$order['money'],'type'=>5]);
$this->success('操作成功');
}
/**
* @title excel表格导出
* @description
* @author panhaowen
* @url /portal/portal/BusinessOrderReturn
* @method POST
* @param name:market_id type:int require:1 desc:营销分类id
* @param name:param type:varchar require:1 desc:筛选参数
*/
//导出数据
public function excel()
{
$param=$this->request->param();
$selected=Db::name('market')->where('id',$param['market_id'])->find()['selected'];
$classify=Db::name('classify')->where('id','in',explode(',',$selected))->select();
$this->success('',$classify);
$where=[];
$list=Db::name('market_business')->where('market_id',$param['market_id']);
$path = ROOT_PATH . '/public/upload/'; //找到当前脚本所在路径
$PHPExcel = new PHPExcel(); //实例化PHPExcel类,类似于在桌面上新建一个Excel表格
$PHPSheet = $PHPExcel->getActiveSheet(); //获得当前活动sheet的操作对象
$PHPSheet->setTitle('表单信息'); //给当前活动sheet设置名称
$PHPSheet->setCellValue('A1', 'ID')
->setCellValue('B1', '微信名')
->setCellValue('C1', '手机号')
->setCellValue('D1', '餐谱');
foreach ($list as $k => $v) {
$n = $k + 2;
$PHPSheet->setCellValue("A$n", $v['id'])
->setCellValue("B$n", "$v[user_nickname]")
->setCellValue("C$n", "$v[mobile]")
->setCellValue("D$n", "$v[cook]");
}
$PHPExcel->getActiveSheet()->getDefaultColumnDimension()->setWidth(20);//设置默认宽度
$PHPWriter = PHPExcel_IOFactory::createWriter($PHPExcel,'Excel2007');//按照指定格式生成Excel文件,‘Excel2007'表示生成2007版本的xlsx,
$file_name='/'.date('Y-m-d',time()).'表单信息.xlsx';
$PHPWriter->save($path.$file_name); //表示在$path路径下面生成demo.xlsx文件
$filename ='./upload'.$file_name;
ob_end_clean();
$file=cmf_get_file_download_url(date('Y-m-d',time()).'表单信息.xlsx');
header("Location: $file");
//下载文件需要用到的头
// header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
// header('Content-Description: File Transfer');
// header('Content-Type: application/octet-stream');
// header('Content-Length: ' . filesize($filename));
// header('Content-Disposition: attachment; filename=' . basename($filename));
// readfile($filename);
exit;
}
}
... ...