正在显示
1 个修改的文件
包含
53 行增加
和
0 行删除
@@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
2 | namespace api\portal\controller; | 2 | namespace api\portal\controller; |
3 | use think\Controller; | 3 | use think\Controller; |
4 | use think\Db; | 4 | use think\Db; |
5 | +use PHPExcel; | ||
5 | 6 | ||
6 | /** | 7 | /** |
7 | * @title 前台补充 | 8 | * @title 前台补充 |
@@ -172,4 +173,56 @@ class PortalController extends Controller | @@ -172,4 +173,56 @@ class PortalController extends Controller | ||
172 | Db::name('money_log')->insert(['create_time'=>time(),'user_id'=>$user['id'],'money'=>$order['money'],'now_money'=>$user['money']+$order['money'],'type'=>5]); | 173 | Db::name('money_log')->insert(['create_time'=>time(),'user_id'=>$user['id'],'money'=>$order['money'],'now_money'=>$user['money']+$order['money'],'type'=>5]); |
173 | $this->success('操作成功'); | 174 | $this->success('操作成功'); |
174 | } | 175 | } |
176 | + | ||
177 | + /** | ||
178 | + * @title excel表格导出 | ||
179 | + * @description | ||
180 | + * @author panhaowen | ||
181 | + * @url /portal/portal/BusinessOrderReturn | ||
182 | + * @method POST | ||
183 | + * @param name:market_id type:int require:1 desc:营销分类id | ||
184 | + * @param name:param type:varchar require:1 desc:筛选参数 | ||
185 | + */ | ||
186 | + //导出数据 | ||
187 | + public function excel() | ||
188 | + { | ||
189 | + $param=$this->request->param(); | ||
190 | + $selected=Db::name('market')->where('id',$param['market_id'])->find()['selected']; | ||
191 | + $classify=Db::name('classify')->where('id','in',explode(',',$selected))->select(); | ||
192 | + $this->success('',$classify); | ||
193 | + $where=[]; | ||
194 | + $list=Db::name('market_business')->where('market_id',$param['market_id']); | ||
195 | + $path = ROOT_PATH . '/public/upload/'; //找到当前脚本所在路径 | ||
196 | + $PHPExcel = new PHPExcel(); //实例化PHPExcel类,类似于在桌面上新建一个Excel表格 | ||
197 | + $PHPSheet = $PHPExcel->getActiveSheet(); //获得当前活动sheet的操作对象 | ||
198 | + $PHPSheet->setTitle('表单信息'); //给当前活动sheet设置名称 | ||
199 | + $PHPSheet->setCellValue('A1', 'ID') | ||
200 | + ->setCellValue('B1', '微信名') | ||
201 | + ->setCellValue('C1', '手机号') | ||
202 | + ->setCellValue('D1', '餐谱'); | ||
203 | + foreach ($list as $k => $v) { | ||
204 | + $n = $k + 2; | ||
205 | + | ||
206 | + $PHPSheet->setCellValue("A$n", $v['id']) | ||
207 | + ->setCellValue("B$n", "$v[user_nickname]") | ||
208 | + ->setCellValue("C$n", "$v[mobile]") | ||
209 | + ->setCellValue("D$n", "$v[cook]"); | ||
210 | + } | ||
211 | + $PHPExcel->getActiveSheet()->getDefaultColumnDimension()->setWidth(20);//设置默认宽度 | ||
212 | + $PHPWriter = PHPExcel_IOFactory::createWriter($PHPExcel,'Excel2007');//按照指定格式生成Excel文件,‘Excel2007'表示生成2007版本的xlsx, | ||
213 | + $file_name='/'.date('Y-m-d',time()).'表单信息.xlsx'; | ||
214 | + $PHPWriter->save($path.$file_name); //表示在$path路径下面生成demo.xlsx文件 | ||
215 | + $filename ='./upload'.$file_name; | ||
216 | + ob_end_clean(); | ||
217 | + $file=cmf_get_file_download_url(date('Y-m-d',time()).'表单信息.xlsx'); | ||
218 | + header("Location: $file"); | ||
219 | + //下载文件需要用到的头 | ||
220 | +// header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); | ||
221 | +// header('Content-Description: File Transfer'); | ||
222 | +// header('Content-Type: application/octet-stream'); | ||
223 | +// header('Content-Length: ' . filesize($filename)); | ||
224 | +// header('Content-Disposition: attachment; filename=' . basename($filename)); | ||
225 | +// readfile($filename); | ||
226 | + exit; | ||
227 | + } | ||
175 | } | 228 | } |
-
请 注册 或 登录 后发表评论