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

接口对接测试

@@ -189,31 +189,42 @@ class PortalController extends Controller @@ -189,31 +189,42 @@ class PortalController extends Controller
189 public function excel() 189 public function excel()
190 { 190 {
191 $param=$this->request->param(); 191 $param=$this->request->param();
192 - $selected=Db::name('market')->where('id',$param['market_id'])->find()['selected'];  
193 - $classify=Db::name('classify')->where('id','in',explode(',',$selected))->select()->toArray(); 192 + $market=Db::name('market')->where('id',$param['market_id'])->find();
  193 + $selected=Db::name('classify')->where('id','in',explode(',',$market['selected']))->select()->toArray();
194 $where=[]; 194 $where=[];
195 - foreach ($classify as $v){ 195 + $where['market_id']=$param['market_id'];
  196 + foreach ($selected as $v){
196 if (!empty($param[$v['field']])){ 197 if (!empty($param[$v['field']])){
197 $where[$v['field']]=$param[$v['field']]; 198 $where[$v['field']]=$param[$v['field']];
198 } 199 }
199 } 200 }
200 - $this->success('1',$where);  
201 - $list=Db::name('market_business')->where('market_id',$param['market_id']); 201 +// $this->success('1',$where);
  202 + $list=Db::name('market_business')->where($where)->select()->toArray();
202 $path = ROOT_PATH . '/public/upload/'; //找到当前脚本所在路径 203 $path = ROOT_PATH . '/public/upload/'; //找到当前脚本所在路径
203 $PHPExcel = new PHPExcel(); //实例化PHPExcel类,类似于在桌面上新建一个Excel表格 204 $PHPExcel = new PHPExcel(); //实例化PHPExcel类,类似于在桌面上新建一个Excel表格
204 $PHPSheet = $PHPExcel->getActiveSheet(); //获得当前活动sheet的操作对象 205 $PHPSheet = $PHPExcel->getActiveSheet(); //获得当前活动sheet的操作对象
205 - $PHPSheet->setTitle('表单信息'); //给当前活动sheet设置名称  
206 - $PHPSheet->setCellValue('A1', 'ID')  
207 - ->setCellValue('B1', '微信名')  
208 - ->setCellValue('C1', '手机号')  
209 - ->setCellValue('D1', '餐谱'); 206 + $PHPSheet->setTitle('报价表'); //给当前活动sheet设置名称
  207 +
  208 + $type=Db::name('type')->where('id',$market['type'])->find();
  209 + $classify=Db::name('classify')->where('id','in',explode(',',$type['classify']))->select()->toArray();
  210 + $arr=['B','C','D','E','F','G','H','I','J','K','L','M','N'];
  211 + $PHPSheet->setCellValue('A1', 'ID');
  212 + foreach ($classify as $k=>$v){
  213 + $PHPSheet->setCellValue($arr[$k].'1', $v['name']);
  214 + }
  215 +// $PHPSheet->setCellValue('A1', 'ID')
  216 +// ->setCellValue('B1', '微信名')
  217 +// ->setCellValue('C1', '手机号')
  218 +// ->setCellValue('D1', '餐谱');
210 foreach ($list as $k => $v) { 219 foreach ($list as $k => $v) {
211 $n = $k + 2; 220 $n = $k + 2;
212 -  
213 - $PHPSheet->setCellValue("A$n", $v['id'])  
214 - ->setCellValue("B$n", "$v[user_nickname]")  
215 - ->setCellValue("C$n", "$v[mobile]")  
216 - ->setCellValue("D$n", "$v[cook]"); 221 + $PHPSheet->setCellValue("A$n", $v['id']);
  222 + foreach ($classify as $k2=>$v2){
  223 + $PHPSheet->setCellValue($arr[$k2]."$n", $v[$v2['field']]);
  224 + }
  225 +// ->setCellValue("B$n", "$v[user_nickname]")
  226 +// ->setCellValue("C$n", "$v[mobile]")
  227 +// ->setCellValue("D$n", "$v[cook]");
217 } 228 }
218 $PHPExcel->getActiveSheet()->getDefaultColumnDimension()->setWidth(20);//设置默认宽度 229 $PHPExcel->getActiveSheet()->getDefaultColumnDimension()->setWidth(20);//设置默认宽度
219 $PHPWriter = PHPExcel_IOFactory::createWriter($PHPExcel,'Excel2007');//按照指定格式生成Excel文件,‘Excel2007'表示生成2007版本的xlsx, 230 $PHPWriter = PHPExcel_IOFactory::createWriter($PHPExcel,'Excel2007');//按照指定格式生成Excel文件,‘Excel2007'表示生成2007版本的xlsx,