CollectionController.class.php
3.49 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
/**
* CollectionController.class.php
* 同事圈收藏
* User: Xtong
* Date: 2017年06月02日
*/
namespace Api\Controller\Workmate;
use Common\Common\Collection;
use Common\Common\Constant;
use Common\Common\User;
use Common\Model\CircleModel;
use Common\Service\AttachmentService;
use Common\Service\CircleService;
use VcySDK\Logger;
class CollectionController extends \Api\Controller\AbstractController
{
/**
* 主方法
* @return boolean
*/
public function Index_post()
{
$id = I('post.id');
// 如果话题ID不存在
if (empty($id)) {
E('_EMPTY_CIRCLE_ID');
}
// 不支持外部人员收藏
if (empty($this->uid)) {
E('_NOT_ALLOW_OUTER_COLLECTION');
}
// 实例化话题表
$service = new CircleService();
// 获取话题详情
$info = $service->get_by_conds(
array(
'id' => $id,
'pid' => CircleModel::CIRCLE_PID
)
);
// 如果话题详情不存在
if (empty($info)) {
E('_EMPTY_CIRCLE_INFO');
}
$img = [];
// 实例化附件表
$attach_serv = new AttachmentService();
$res = $attach_serv->list_by_conds([
'cid' => $id
], null);
if (!empty($res)) {
foreach ($res as $k => $v) {
$img[$k]['atId'] = $v['atid'];
$img[$k]['imgUrl'] = imgUrlReal($v['atid']);
}
}
// 初始化收藏类
$collection = new Collection();
// 获取ICON详情
$icon_info = $collection->get_icon_info(array(
'app_dir' => APP_DIR,
'app_identifier' => APP_IDENTIFIER,
'data_category_id' => '1'
));
// 获取收藏状态 xtong 2017年06月02日
$url = rpcUrl('/Public/Rpc/Collection/CollectionNew');
$title = $info['content'];
if (Constant::CIRCLE_TOPIC_TYPE == $info['type']) {
$title = $info['title'];
}
$msg_type = $service::CIRCLE_INFO;
// 话题回帖
if (Constant::CIRCLE_REPLIES_TOPIC_TYPE == $info['type']) {
$msg_type = $service::REPLIES_INFO;
}
// 话题
if (Constant::CIRCLE_TOPIC_TYPE == $info['type']) {
$msg_type = $service::TOPIC_INFO;
}
$params = [
'uid' => $this->uid,
'app' => 'workmate',
'dataId' => $id,
'title' => $title,
'cover_type' => 0,
'url' => "Workmate/Frontend/Index/Msg?type={$msg_type}&id=" . $id,
'circle_uid' => $info['uid'],
'circle_face' => User::instance()->avatar($info['uid']),
'circle_name' => $info['username'],
'circle_img' => $img,
'icon_title' => $icon_info['title'],
'icon_id' => $icon_info['recommender_id'],
'data_category_id' => '',
'data_category_name' => '',
'cover_id' => $info['cover_id'],
'cover_url' => !empty($info['cover_id']) ? imgUrlReal($info['cover_id']) : '',
'type' => $info['type'],
'is_anonymous'=>intval($info['is_anonymous'])
];
$res = \Com\Rpc::phprpc($url)->invoke('Index', $params);
Logger::write('收藏添加:' . var_export($res, true));
if (!$res) {
E('_ERR_ALREADY_COLLECTION');
}
// 返回成功
$this->_result = [];
}
}