CommonCollectionService.class.php
4.87 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php
/**
* CommonCollectionService.class.php
* 收藏系统 Service
* @author Xtong
* @version $Id$
*/
namespace Common\Service;
use Common\Model\CommonCollectionModel;
use Common\Model\CommonRecommenderModel;
use Think\Log;
class CommonCollectionService extends AbstractService
{
/**
* 有效的封面类型列表
*/
public $coverType = [];
/**
* 应用配置
*/
protected $_settingAppConfig = null;
/**
* 收藏系统 Service 构造方法
*/
public function __construct()
{
parent::__construct();
$this->_d = new CommonCollectionModel();
$this->coverType = [
CommonCollectionModel::COVER_NULL,
CommonCollectionModel::COVER_PIC,
CommonCollectionModel::COVER_AUDIO,
CommonCollectionModel::COVER_VIDEO
];
}
/**
* 验证封面类型是否合法
* @param number $type
* @return boolean
*/
public function is_type($type)
{
if (!is_scalar($type) || !in_array($type, $this->coverType)) {
return false;
}
return true;
}
/**
* 获取指定收藏数据关联的所有数据,一般用于查找重复的关联数据
* @param string $appDir 应用目录标识名
* @param string $dataId 数据关联的所在应用数据 ID
* @param string $uid 收藏者的 UID
* @return number
*/
public function getDuplicate($appDir, $dataId, $uid)
{
return $this->_d->getByAppdirDataidUid($appDir, $dataId, $uid);
}
/**
* 添加 一条收藏数据
* @param array $data 收藏数据
* @return \Think\mixed|string
*/
public function collectionAdd($data)
{
// 判断封面类型合法性
if (!$this->is_type($data['cover_type'])) {
Log::record('<!-- 收藏封面类型不合法 -->');
return false;
}
$fields = [
'title',
'cover_id',
'cover_url',
'cover_type',
'url',
'app_dir',
'app_identifier',
'data_id',
'data',
'uid',
'c_time',
'c_deleted',
'icon_data'
];
$values = [];
foreach ($fields as $_field) {
if (isset($data[$_field])) {
$values[$_field] = $data[$_field];
}
}
return $this->_d->insert($values);
}
public function formate_list($list)
{
// 获取栏目数据
$condition = array(
'type' => CommonRecommenderModel::TYPE_ICON,
'hide' => CommonRecommenderModel::HIDE_NO
);
$recommenderService = new CommonRecommenderService();
$recommenders = $recommenderService->list_by_conds($condition);
$recommenders = array_combine_by_key($recommenders, 'app_dir');
// 初始化列表
$new_list = [];
foreach ($list as $k => $v) {
$new_list[$k]['collection_id'] = (int)$v['collection_id'];
$new_list[$k]['app'] = $v['app_dir'];
// 应用名称
$app_title = '';
$recommender = $recommenders[$v['app_dir']];
if (!empty($recommender)) {
$app_title = $recommender['title'];
}
$new_list[$k]['app_title'] = $app_title;
$new_list[$k]['dataId'] = (int)$v['data_id'];
$new_list[$k]['title'] = $v['title'];
$new_list[$k]['cover_type'] = (int)$v['cover_type'];
$new_list[$k]['cover_id'] = $v['cover_id'];
$new_list[$k]['cover_url'] = $v['cover_url'];
$new_list[$k]['url'] = 'http://' . $_SERVER['HTTP_HOST'] . D_S . QY_DOMAIN . D_S . $v['url'];
$new_list[$k]['c_time'] = $v['c_time'];
$new_list[$k]['c_deleted'] = (int)$v['c_deleted'];
// 还原icon数据
$icon_data= unserialize($v['icon_data']);
// icon 数据
$new_list[$k]['icon_data'] =array(
'icon_name' => strval($icon_data['icon_name']),
'type'=>intval($icon_data['type']),
'is_anonymous'=>intval($icon_data['is_anonymous']),
);
// 初始化序列化
$data = [];
if (!empty($v['data'])) {
$data = unserialize($v['data']);
}
// 资料库
$new_list[$k]['file_type'] = $data['file_type'];
$new_list[$k]['file_size'] = $data['file_size'];
$new_list[$k]['is_dir'] = (int)$data['is_dir'];
// 同事圈
$new_list[$k]['circle_uid'] = $data['circle_uid'];
$new_list[$k]['circle_face'] = $data['circle_face'];
$new_list[$k]['circle_name'] = $data['circle_name'];
$new_list[$k]['circle_img'] = $data['circle_img'];
}
return $new_list;
}
}