JoinListController.class.php
2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
/**
* 导出已参与人员列表接口
* User: daijun
* Date: 18/3/24
* Time: 下午3:44
*/
namespace Apicp\Controller\Export;
use Com\PythonExcel;
use Common\Service\ActivityService;
use Common\Common\ExportDownload;
use Common\Service\RecordService;
class JoinListController extends \Apicp\Controller\AbstractController
{
public function Index()
{
$ac_id = I('post.ac_id');
if (empty($ac_id)) {
// 活动ID不能为空
E('_EMPTY_ACTIVITY_ID');
}
$activity_serv = new ActivityService();
$detail = $activity_serv->get($ac_id);
if (empty($detail)) {
// 活动信息不存在
E('_ERR_ACTIVITY_DATA');
}
$record_serv = new RecordService();
// 定义查询字段
$fields = 'lr_id,username,dp_name,mobile,role,job,remark,created';
// 查询列表数据
$list = $record_serv->list_by_where(['ac_id' => $ac_id], [], $fields);
$rand_str = substr(md5(QY_DOMAIN), 0, 1) . substr(md5(QY_DOMAIN), -1);
$file_name = $detail['title'] . '已参与人员列表_' . rgmdate(strval(MILLI_TIME), 'YmdHis') . $rand_str; // 导出文件名称
// 生成下载Excel
$this->_download($list, $file_name);
return true;
}
/**
* 导出模板
*
* @param array $list 导出数据
* @param string $file_name 文件名称
*
* @return bool
*/
protected function _download($list = [], $file_name = '')
{
// Excel 表头字段
$title = [
'姓名',
'组织',
'岗位',
'角色',
'手机号',
'参与时间',
];
$rows = [];
// 回帖数据处理
foreach ($list as $v) {
$rows[] = [
$v['username'],
$v['dp_name'],
$v['job'],
$v['role'],
" " . $v['mobile'],
rgmdate(strval($v['created']), 'Y/m/d H:i'),
];
}
unset($list);
$dir = DATA_PATH;
// 生成Excel 下载
$real_path = $dir . D_S . $file_name . '.xls';
$ret = PythonExcel::instance()->write($real_path, $title, $rows);
if ($ret) {
$data = [
'title' => $file_name,
'ea_id' => $this->_login->user['eaId'],
'type' => ExportDownload::EXCEL_TYPE,
'username' => $this->_login->user['eaRealname'],
'url' => $real_path,
'app_dir' => APP_DIR
];
ExportDownload::insert_down_load($data);
}
return true;
}
}