作者 sgj
1 个管道 的构建 失败 耗费 7 秒

导入导出功能完善

... ... @@ -9,6 +9,7 @@
namespace app\admin\controller;
use app\admin\model\Excel;
use cmf\controller\AdminBaseController;
use think\Request;
use think\Validate;
... ... @@ -644,6 +645,82 @@ class ActivityController extends AdminBaseController
return $this->fetch();
}
public function excel(){
$map['j.activity_id']=input('id');
$activity=\db('activity')->where('id',$map['j.activity_id'])->find();
$map['j.delete_time']=0;
$join=\db('join')
->field('j.*,v.name,v.photo')
->alias('j')
->join('volunteer v','v.user_id=j.user_id')
->where($map)
->select()
->toArray();
/* dump($join);*/
//dump(get_image_path('https://volunteer.cnpu.org/upload/20190112/9bd2840928f0acee61ce6c906cda32c3.jpg'));
foreach ($join as $k=>$v){
/*dump($k);*/
if (!empty($v['add_time'])){
$join[$k]['add_time']=date('Y-m-d H:i:s',$v['add_time']);
}
if (!empty($v['sgin_time'])){
$join[$k]['sgin_time']=date('Y-m-d H:i:s',$v['sgin_time']);
}
$join[$k]['work_content']=\db('work')->where('id',$v['work_content'])->value('name');
if (!empty($v['select_time'])){
$select[$k]=json_decode($v['select_time'],true);
foreach ($select[$k] as $k1=>$v1){
$date[$k]['time'][$k1]=$v1['date'].' '.$v1['time'];
}
$date[$k]['select']=implode(',',$date[$k]['time']);
}else{
$join[$k]['apply_stay']='';
}
if (!empty($v['apply_stay'])){
$select[$k]=json_decode($v['apply_stay'],true);
foreach ($select[$k] as $k1=>$v1){
$date[$k]['time'][$k1]=$v1['date'].' '.$v1['idcard'];
}
$date[$k]['select']=implode(',',$date[$k]['time']);
}else{
$join[$k]['apply_stay']='';
}
$join[$k]['photo']=get_image_path($v['photo']);
if (!empty($v['apply_food'])){
$select[$k]=json_decode($v['apply_food'],true);
foreach ($select[$k] as $k1=>$v1){
$date[$k]['time'][$k1]=$v1['date'].' '.$v1['time'];
}
$date[$k]['select']=implode(',',$date[$k]['time']);
}else{
$join[$k]['apply_food']='';
}
}
$title = [
['ID', 15, 'id', 1],
['姓名', 15, 'name', 1],
['图片', 15, 'photo', 2,200],
['参与方式', 15, 'type', 1],
['审核状态', 15, 'status', 1],
['选择时间', 15, 'select_time', 1],
['申请入住', 15, 'apply_stay', 1],
['申请用餐', 15, 'apply_food', 1],
['工作报告', 15, 'work_report', 1],
['拒绝原因', 15, 'refund_reason', 1],
];
$Excel = new Excel();
$letter = $Excel->excelAcross(count($title));
// dump($letter);
$Excel->excel($letter, $title, $join, "$activity[activity_name]活动申请列表");
}
}
\ No newline at end of file
... ...
... ... @@ -72,8 +72,10 @@ class Excel
$objPHPExcel->setActiveSheetIndex(0)->getStyle($v)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
//设置首行
$objActSheet->setCellValue($v.'1', $title[$k][0]);
// 设置个表格宽度
$objPHPExcel->getActiveSheet()->getColumnDimension($v)->setWidth($title[$k][1]);
// 垂直居中
$objPHPExcel->getActiveSheet()->getStyle($v)->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
}
... ... @@ -85,9 +87,10 @@ class Excel
if ($title[$key][3]==1){
$objActSheet->setCellValue($val.$k, empty($v[$title[$key][2]])?'':$v[$title[$key][2]]);
}else{
$objPHPExcel->getActiveSheet()->getDefaultRowDimension($k)->setRowHeight(200);
// 图片生成
$objDrawing[$k] = new \PHPExcel_Worksheet_Drawing();
$objDrawing[$k]->setPath('./upload/'.$v[$title[$key][2]]);
$objDrawing[$k]->setPath('./'.$v[$title[$key][2]]);
// 设置宽度高度
//$objDrawing[$k]->setHeight(80);//照片高度
$objDrawing[$k]->setWidth($title[$key][4]); //照片宽度
... ...
... ... @@ -1853,3 +1853,13 @@ function wxappNotice($message){
return $result;
}
/**
* 获取路径
* @param $url
*/
function get_image_path($url){
$domain='/upload';
$return=strstr($url,$domain);
return $return;
}
\ No newline at end of file
... ...