InfoController.class.php
4.46 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
116
117
<?php
/**
* Created by PhpStorm.
* User: tangxingguo
* Date: 2017/4/21
* Time: 10:19
*/
namespace Api\Controller\Doc;
use Com\PackageValidate;
use Common\Common\Constant;
use Common\Common\RpcFavoriteHelper;
use Common\Service\FileService;
use Common\Service\RightService;
class InfoController extends \Api\Controller\AbstractController
{
/**
* Info
* @author tangxingguo
* @desc 文件(夹)详情接口
* @param int file_id:true 文件、文件夹ID
* @return array
array(
'file_id' => 123, // 文件ID
'file_name' => '好好学习.pdf', // 文件名称
'at_suffix' => 'pdf', // 文件尾缀
'at_size' => 123456, // 附件尺寸(单位字节)
'path' => '资料库/课程中心/学习资料', // 文件位置
'update_time' => 1493264288000, // 最后更新时间
'created' => 1493264288000, // 创建时间
'total_file' => 10, // 包含文件数
'file_type' => 2, // 文件类型(1=文件夹;2=文件)
'at_convert_url' => 'http://dsc.vchangyi.com/123.pdf', // 预览URL
'is_download' =>1, // 是否允许下载(1=不允许;2=允许)
'at_url' => 'http://dsc.vchangyi.com/123.pdf', // 下载URL(is_download=2时存在)
'my_is_favorite' => 1, // 我是否收藏(1=未收藏,2=已收藏)
);
*/
public function Index_post()
{
// 验证规则
$rules = [
'file_id' => 'require|integer',
];
// 验证数据
$validate = new PackageValidate($rules, [], array_keys($rules));
$fileId = $validate->postData['file_id'];
$user = $this->_login->user;
// 取当前文件信息
$fileServ = new FileService();
$fileInfo = $fileServ->get_by_conds(['file_id' => $fileId, 'file_status' => Constant::FILE_STATUS_NORMAL]);
if (empty($fileInfo)) {
E('_ERR_FILE_DATA_IS_NULL');
}
// 数据处理
$getPathId = $fileId;
switch ($fileInfo['file_type']) {
// 文件类型:文件
case Constant::FILE_TYPE_IS_DOC:
$getPathId = $fileInfo['parent_id'];
$fileInfo['at_suffix'] = end(explode('.', $fileInfo['file_name']));
// 目录下载权限检查
$rightServ = new RightService();
$downloadRight = $rightServ->checkDownloadRight($user, $fileInfo['parent_id']);
$parentInfo = $fileServ->get_by_conds(['file_id' => $fileInfo['parent_id']]);
if ($fileInfo['parent_id'] == 0 || ($parentInfo['is_download'] == Constant::FILE_DOWNLOAD_RIGHT_ON && $downloadRight)) {
$fileInfo['is_download'] = Constant::FILE_MY_DOWNLOAD_RIGHT_YES;
} else {
$fileInfo['is_download'] = Constant::FILE_MY_DOWNLOAD_RIGHT_NO;
}
// 文件url加入鉴权参数
$params = [
'_id' => $fileId,
'user' => $user,
];
$fileInfo['at_url'] = fileUrl($fileInfo['at_url'], $params);
$fileInfo['at_convert_url'] = fileUrl($fileInfo['at_convert_url'], $params);
break;
// 文件类型:文件夹
case Constant::FILE_TYPE_IS_FOLDER:
list($totalSize, $totalNum) = $fileServ->getFolderInfo($fileId);
$fileInfo['total_file'] = $totalNum;
$fileInfo['at_size'] = $totalSize;
break;
}
// 路径
$path = '资料库';
if ($getPathId != 0) {
$pathArr = $fileServ->getPaths($getPathId);
$path .= '/' . implode('/', array_column($pathArr, 'file_name'));
}
$fileInfo['path'] = $path;
// RPC查询收藏结果
$data = [
'uid' => $user['memUid'],
'dataId' => $fileId,
];
$rpcFavorite = &RpcFavoriteHelper::instance();
$status = $rpcFavorite->getStatus($data);
$fileInfo['my_is_favorite'] = Constant::FILE_MY_FAVORITE_NO;
if (isset($status['collection']) && $status['collection'] == RpcFavoriteHelper::COLLECTION_YES) {
$fileInfo['my_is_favorite'] = Constant::FILE_MY_FAVORITE_YES;
}
$this->_result = $fileInfo;
}
}