IconNewController.class.php
5.56 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
<?php
/**
* IconNewController.class.php
* 【运营管理】管理后台新建栏目接口
* @author Deepseath
* @version $Id$
*/
namespace Apicp\Controller\Recommender;
use Apicp\Controller\Recommender\AbstractController;
use Common\Common\AttachOperation;
use Common\Service\CommonRecommenderService;
use Common\Model\CommonRecommenderModel;
use Common\Common\Attach;
/**
* 【管理后台】新建栏目接口
*/
class IconNewController extends AbstractController
{
/**
* 新建栏目接口
* @desc 【管理后台】新建栏目接口
* @param int addType:true 添加类型(0:选择关联模块,1:自定义添加)
* @param string attachId:true 栏目图标附件 Id
* @param string title:true 栏目标题,不能超过 4个 字符
* @param string description:false 栏目描述,不能超过 120个 字符
* @param string url:true 栏目相对链接 URL
* @param string app:true 指定的应用模块
* @param string dataCategoryId:true 栏目关联的应用分类 ID
* @param array data:true 栏目关联的应用分类详情,结构如下:<br>
* [<br>
* ['id' => '一级分类ID', 'name' => '分类名称', 'upId' => '上级分类ID', 'url' => '分类 URL'],<br>
* ['id' => '二级分类ID', 'name' => '分类名称', 'upId' => '上级分类ID', 'url' => '分类 URL']<br>
* ['id' => '三级分类ID', 'name' => '分类名称', 'upId' => '上级分类ID', 'url' => '分类 URL']<br>
* ... ... <br>
* ]
* @return <pre>array(
* 'recommendId' => 123 // 新增的栏目 Id
* )</pre>
*/
public function Index()
{
// 添加类型
$addType = I('addType', 0, 'rintval');
// 图片附件 ID
$attachId = I('attachId', '');
// 栏目名称
$title = I('title', '');
// 栏目描述
$description = I('description', '');
// 链接 URL
$url = I('url', '');
// 关联的 APP
$app = I('app', '');
// 关联的 APP 分类 ID
$dataCategoryId = I('dataCategoryId', '');
// 关联版块,数组
/**
* [
* ['id' => '分类ID', 'name' => '分类名称', 'upId' => '上级分类ID', 'url' => '分类 URL'],
* ['id' => '分类ID', 'name' => '分类名称', 'upId' => '上级分类ID', 'url' => '分类 URL'],
* ['id' => '分类ID', 'name' => '分类名称', 'upId' => '上级分类ID', 'url' => '分类 URL']
* ]
*/
$data = I('data/a', []);
if (empty($attachId)) {
return $this->_set_error('_ERR_RECOMMENDER_ICON_ATTACH_ID_EMPTY_40104');
}
$attachServ = &Attach::instance();
$pic = $attachServ->getAttachUrl($attachId);
$pic = empty($pic) ? $attachId : $pic;
$recommenderService = new CommonRecommenderService();
if (!$recommenderService->verifyFieldTitle($title)) {
return $this->_set_error('_ERR_RECOMMENDER_ICON_TITLE_TOOLONG_40106');
}
if (!$recommenderService->verifyFieldDescription($description)) {
return $this->_set_error('_ERR_RECOMMENDER_ICON_DESCRIPTION_TOOLONG_40107');
}
if (!$recommenderService->verifyFieldUrl($url)) {
return $this->_set_error('_ERR_RECOMMENDER_ICON_URL_ERROR_40108');
}
// 如果不是自定义栏目
if (!$addType) {
if (empty($app) || $dataCategoryId === '' || empty($data)) {
// 检查提交的相关参数是否存在
return $this->_set_error('_ERR_RECOMMENDER_ICON_PARAM_40109');
}
if (!$recommenderService->is_app($app)) {
// 检查应用模块标识是否正确
return $this->_set_error('_ERR_RECOMMENDER_ICON_APP_ERROR_40110');
}
if ($recommenderService->countDuplicate(CommonRecommenderModel::TYPE_ICON, $app, null,
$dataCategoryId) > 0
) {
// 检查关联的分类是否重复
return $this->_set_error('_ERR_RECOMMENDER_ICON_DUPLICATE_40111');
}
}
// 新增数据
$recommenderId = $recommenderService->recommenderUpdate([
'type' => CommonRecommenderModel::TYPE_ICON,
'displayorder' => CommonRecommenderModel::VALUE_DISPLAYORDER_MIN,
'hide' => CommonRecommenderModel::HIDE_NO,
'system' => CommonRecommenderModel::SYSTEM_NO,
'title' => $title,
'attach_id' => $attachId,
'pic' => $pic,
'url' => $url,
'description' => $description,
'app_dir' => $app,
'app_identifier' => APP_IDENTIFIER,
'data_id' => '',
'data_category_id' => $dataCategoryId,
'data' => [
'category' => $data
],
'dateline' => MILLI_TIME,
'adminer_id' => $this->_login->user['eaId'],
'adminer' => $this->_login->user['eaRealname'],
'add_type' => $addType,
]);
// 设置其排序号为 ID
$recommenderService->update($recommenderId, [
'displayorder' => $recommenderId
]);
// 附件操作
if (strlen($attachId) == 32) {
$attach_serv = new AttachOperation();
$attach_serv->insert_attach(
APP_DIR,
'recommender',
$recommenderId,
['attach_ids' => [$attachId]]
);
}
return $this->_result = [
'recommenderId' => $recommenderId
];
}
}