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

接口对接测试

... ... @@ -189,31 +189,42 @@ class PortalController extends Controller
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()->toArray();
$market=Db::name('market')->where('id',$param['market_id'])->find();
$selected=Db::name('classify')->where('id','in',explode(',',$market['selected']))->select()->toArray();
$where=[];
foreach ($classify as $v){
$where['market_id']=$param['market_id'];
foreach ($selected as $v){
if (!empty($param[$v['field']])){
$where[$v['field']]=$param[$v['field']];
}
}
$this->success('1',$where);
$list=Db::name('market_business')->where('market_id',$param['market_id']);
// $this->success('1',$where);
$list=Db::name('market_business')->where($where)->select()->toArray();
$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', '餐谱');
$PHPSheet->setTitle('报价表'); //给当前活动sheet设置名称
$type=Db::name('type')->where('id',$market['type'])->find();
$classify=Db::name('classify')->where('id','in',explode(',',$type['classify']))->select()->toArray();
$arr=['B','C','D','E','F','G','H','I','J','K','L','M','N'];
$PHPSheet->setCellValue('A1', 'ID');
foreach ($classify as $k=>$v){
$PHPSheet->setCellValue($arr[$k].'1', $v['name']);
}
// $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]");
$PHPSheet->setCellValue("A$n", $v['id']);
foreach ($classify as $k2=>$v2){
$PHPSheet->setCellValue($arr[$k2]."$n", $v[$v2['field']]);
}
// ->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,
... ...