ExportLikeListController.class.php
3.15 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
<?php
/**
* Created by PhpStorm.
* User: liyifei2012it
* Date: 18/7/6
* Time: 10:53
*/
namespace Apicp\Controller\News;
use Com\PackageValidate;
use Com\PythonExcel;
use Common\Common\ExportDownload;
use Common\Common\NewsHelper;
use Common\Common\User;
use Common\Service\LikeService;
use Common\Service\ArticleService;
class ExportLikeListController extends \Apicp\Controller\AbstractController
{
/**
* LikeList
* @desc 导出点赞列表
* @param int article_id:true 新闻ID
* @return mixed
*/
public function Index_post()
{
// 验证规则
$rules = [
'article_id' => 'require|integer',
];
// 验证数据
$validate = new PackageValidate($rules, [], array_keys($rules));
$postData = $validate->postData;
// 取新闻信息
$articleServ = new ArticleService();
$article = $articleServ->get($postData['article_id']);
if (empty($article)) {
E('_ERR_ARTICLE_NOT_FOUND');
}
// 点赞列表
$likeServ = new LikeService();
$likeList = $likeServ->list_by_conds(['article_id' => $postData['article_id']]);
if ($likeList) {
// UC人员信息
$uids = array_column($likeList, 'uid');
$userServ = &User::instance();
$userList = $userServ->listAll(['memUids' => $uids]);
$userList = array_combine_by_key($userList, 'memUid');
// Excel文件名前缀
$titleSuffix = '_点赞人员';
// Excel列名
$columns = ['姓名', '组织', '岗位', '角色', '手机号'];
// Excel行数据
$rows = [];
if ($userList) {
$newsHelper = &NewsHelper::instance();
foreach ($likeList as $k => $v) {
$uid = $v['uid'];
if (isset($userList[$uid])) {
$user = $userList[$uid];
$rows[] = [
$user['memUsername'],
$newsHelper->getDpPath($user),
$user['memJob'],
$user['memRole'],
$user['memMobile'],
];
}
}
}
$title = $article['title'] . $titleSuffix . rgmdate(MILLI_TIME, '_ymdHis');
$filename = ExportDownload::get_down_dir($this->_login->user['eaId']) . $title . '.xls';
$result = PythonExcel::instance()->write($filename, $columns, $rows);
if ($result === true) {
// 写入数据到下载中心
$conditon = [
'title' => $title,
'ea_id' => $this->_login->user['eaId'],
'type' => ExportDownload::EXCEL_TYPE,
'size' => filesize($filename),
'username' => $this->_login->user['eaRealname'],
'url' => $filename,
'app_dir' => APP_DIR
];
ExportDownload::insert_down_load($conditon);
}
}
return true;
}
}