CollectionNewController.class.php
5.3 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
136
137
138
139
140
141
142
143
144
145
<?php
/**
* CollectionNewController.class.php
* 新增收藏 RPC 接口
* @author Xtong
* @version $Id$
*/
namespace Rpc\Controller\Collection;
use Common\Service\CommonCollectionService;
use Common\Model\CommonCollectionModel;
use Think\Log;
/**
* 新增收藏 RPC 接口
* @uses 调用方法:\Com\Rpc::phprpc(rpc 接口 url)->invoke(接口方法名, 需要传入的参数数组key-value);
*/
class CollectionNewController extends AbstractController
{
/**
* 新增收藏信息
* @desc 【RPC】新增收藏接口
* @param string app:true 被收藏数据所在应用模块目录标识名
* @param string uid:true 用户uid
* @param string dataId:true 被收藏数据的原始数据 Id。<strong style="color: red">注意:请确保被推荐数据 app、uid、dataId 联合值为唯一</strong>
* @param string title:true: 收藏内容标题(同事圈内容,资料库文件(夹)名等)
* @param string cover_type:true: 封面类型(0:无封面,1:图片,2:音频,3:视频)
* @param string cover_id:false: 封面附件ID
* @param string cover_url:false: 封面附件URL
* @param string url:true: 详情跳转URL
* @param string file_type:false: 文件类型(JPG,TXT,PDF等
* @param string file_size:false: 文件大小(单位:字节)
* @param string is_dir:false: 是否为文件夹(0:否,1:是)
* @param string circle_uid:false: 发布同事圈用户UID
* @param string circle_face:false: 发布同事圈的用户头像
* @param string circle_name:false: 发布同事圈的用户姓名
* @param string circle_img:false: 同事圈的图片数组
* @param string icon_title:true: 栏目名称
* @param string icon_id:true: 栏目ID
* @param string data_category_id:false: 分类ID
* @param string data_category_name:false: 分类名称
* @return boolean
*/
public function Index()
{
if (!$this->_checkKeyParams()) {
return false;
}
$keys = [
'cover_id',
'cover_url',
'file_type',
'file_size',
'is_dir',
'circle_uid',
'circle_face',
'circle_name',
'circle_img'
];
foreach ($keys as $_key) {
if (!isset($this->_params[$_key])) {
$this->_params[$_key] = '';
}
}
if (empty($this->_params['app'])
&& empty($this->_params['dataId'])
&& empty($this->_params['uid'])
&& empty($this->_params['icon_title'])
&& empty($this->_params['icon_id'])
) {
Log::record('收藏标记为空');
return $this->_set_error('_ERR_COLLECTION_ARTICLE_NULL_90001');
}
// 组织序列化数据
$extData = [
'file_type' => $this->_params['file_type'],
'file_size' => $this->_params['file_size'],
'is_dir' => $this->_params['is_dir'],
'circle_uid' => $this->_params['circle_uid'],
'circle_face' => $this->_params['circle_face'],
'circle_name' => $this->_params['circle_name'],
'circle_img' => $this->_params['circle_img']
];
$extSerialize = serialize($extData);
// 组装icon数据序列化数据
$icon_data = array(
'icon_name' => $this->_params['icon_title'],
'icon_id' => $this->_params['icon_id'],
'category_id' => $this->_params['data_category_id'],
'category_name' => $this->_params['data_category_name'],
'type'=> $this->_params['type'],
'is_anonymous'=>$this->_params['is_anonymous']
);
$icon_data_serialize = serialize($icon_data);
$collectionService = new CommonCollectionService();
// 判断收藏的数据是否已存在
$exists = $collectionService->getDuplicate(
$this->_params['app'],
$this->_params['dataId'],
$this->_params['uid']
);
if (!empty($exists)) {
Log::record('数据已被此用户收藏过,忽略再次收藏:app=' . $this->_params['app'] . '; dataId=' . $this->_params['dataId']
. '; uid=' . $this->_params['uid']);
$this->_set_error('_ERR_COLLECTION_DUPLICATE');
return false;
}
$data = [
'title' => $this->_params['title'],
'cover_id' => $this->_params['cover_id'],
'cover_url' => $this->_params['cover_url'],
'cover_type' => $this->_params['cover_type'],
'url' => $this->_params['url'],
'app_dir' => $this->_params['app'],
'app_identifier' => APP_IDENTIFIER,
'data_id' => $this->_params['dataId'],
'data' => $extSerialize, // 序列化同事圈和资料库的额外内容
'icon_data' => $icon_data_serialize, // 序列化ICON数据
'uid' => $this->_params['uid'],
'c_time' => MILLI_TIME,
'c_deleted' => CommonCollectionModel::DELETE_NO
];
$data['collection_id'] = $collectionService->collectionAdd($data);
Log::record('<!-- 新增收藏数据:');
Log::record(var_export($data, true));
Log::record('结束新增收藏数据 -->');
return true;
}
}