|
@@ -18,6 +18,7 @@ namespace app\user\controller;
|
|
|
use app\common\constant\CommonConstant;
|
|
|
use app\common\service\DingtalkService;
|
|
|
use app\common\service\UserService;
|
|
|
+use app\common\model\User as model;
|
|
|
use library\Controller;
|
|
|
|
|
|
/**
|
|
@@ -190,6 +191,45 @@ class Member extends Controller
|
|
|
$this->_save($this->table, ['signature_status' => $signature_status]);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出
|
|
|
+ **/
|
|
|
+ public function export(){
|
|
|
+ $data = model::field('is_deleted',true)
|
|
|
+ ->where('is_deleted', CommonConstant::IS_DELETED_0)
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+ if(!$data) $this->error('暂无可以导出的数据');
|
|
|
+ $field=array(
|
|
|
+ 'A' => array('name', '用户姓名'),
|
|
|
+ 'B' => array('mobile', '手机号码'),
|
|
|
+ 'C' => array('title', '职位'),
|
|
|
+ );
|
|
|
+ $this->phpExcelList($field,$data,'会员列表');
|
|
|
+ }
|
|
|
+
|
|
|
+ public function phpExcelList($field=[],$list=[],$title='文件'){
|
|
|
+ $PHPExcel=new \PHPExcel();
|
|
|
+ $PHPSheet=$PHPExcel->getActiveSheet();
|
|
|
+ $PHPSheet->setTitle('demo'); //给当前活动sheet设置名称
|
|
|
+ foreach($list as $key=>$value)
|
|
|
+ {
|
|
|
+ foreach($field as $k=>$v){
|
|
|
+ if($key == 0){
|
|
|
+ $PHPSheet= $PHPExcel->getActiveSheet()->setCellValue($k.'1',$v[1]);
|
|
|
+ }
|
|
|
+ $i=$key+2;
|
|
|
+ $PHPExcel->getActiveSheet()->setCellValue($k . $i, $value[$v[0]]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $PHPWriter = \PHPExcel_IOFactory::createWriter($PHPExcel,'Excel2007'); //按照指定格式生成Excel文件,
|
|
|
+ header('Content-Type: application/vnd.ms-excel'); // 告诉浏览器生成一个excel05版的表格
|
|
|
+ header("Content-Disposition: attachment;filename={$title}.xls"); //告诉浏览器输出文件的名称
|
|
|
+ header('Cache-Control: max-age=0'); //禁止缓存
|
|
|
+ $PHPWriter->save("php://output"); //输出到浏览器
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 更新员工和部门
|
|
|
**/
|
|
@@ -197,5 +237,4 @@ class Member extends Controller
|
|
|
DingtalkService::renew();
|
|
|
$this->success('更新员工和部门成功');
|
|
|
}
|
|
|
-
|
|
|
}
|