BannerNewController.class.php
5.13 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
<?php
/**
* BannerNewController.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 BannerNewController extends AbstractController
{
/**
* 新增首页条幅数据
* @desc 【管理后台】新增首页条幅数据
* @param string addType:true 添加类型(0:选择关联模块,1:自定义添加)
* @param string attachId:true 条幅图片附件 Id
* @param string title:true 条幅标题,不能超过 4个 字符
* @param string url:true 条幅手机端访问链接 URL
* @param string app:true 指定的应用模块
* @param string dataCategoryId:true 条幅关联的应用分类 ID
* @param string dataId:true 条幅关联的文章 ID
* @param array data:true 条幅关联的文章和分类信息:<pre>
* [<br>
* ['category' => [<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>
* ]<br>
* ]
* </pre>
* @return array('recommendId' => '新增的条幅 Id')
*/
public function Index()
{
// 添加类型
$addType = I('addType', 0, 'rintval');
// 图片附件 ID
$attachId = I('attachId', '');
// 条幅名称
$title = I('title', '');
// 链接 URL
$url = I('url', '');
// 关联的 APP
$app = I('app', '');
// 关联的 APP 分类 ID
$dataCategoryId = I('dataCategoryId', '');
// 关联的文章 ID
$dataId = I('dataId', '');
// 关联版块,数组
/**
* [
* ['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_ATTACHID_EMPTY_40093');
}
$attachServ = &Attach::instance();
$pic = $attachServ->getAttachUrl($attachId);
if (empty($pic)) {
return $this->_set_error('_ERR_RECOMMENDER_ATTACH_URL_ERROR_40094');
}
$recommenderService = new CommonRecommenderService();
if (!$recommenderService->verifyFieldTitle($title, 64)) {
return $this->_set_error('_ERR_RECOMMENDER_TITLE_TOOLONG_40095');
}
if (!$recommenderService->verifyFieldUrl($url)) {
return $this->_set_error('_ERR_RECOMMENDER_URL_ERROR_40096');
}
// 不是自定义类型
if (!$addType) {
if (!$recommenderService->is_app($app)) {
// 检查应用模块标识是否正确
return $this->_set_error('_ERR_RECOMMENDER_APP_ERROR_40097');
}
if ($recommenderService->countDuplicate(CommonRecommenderModel::TYPE_BANNER, $app, $dataId,
$dataCategoryId) > 0
) {
// 检查关联的分类是否重复
return $this->_set_error('_ERR_RECOMMENDER_DATA_DUPLICATE_40098');
}
}
$recommenderId = $recommenderService->recommenderUpdate([
'type' => CommonRecommenderModel::TYPE_BANNER,
'displayorder' => CommonRecommenderModel::VALUE_DISPLAYORDER_MIN,
'hide' => CommonRecommenderModel::HIDE_NO,
'system' => CommonRecommenderModel::SYSTEM_NO,
'title' => $title,
'attach_id' => $attachId,
'pic' => $pic,
'url' => $url,
'description' => '',
'app_dir' => $app,
'app_identifier' => APP_IDENTIFIER,
'data_id' => $dataId,
'data_category_id' => $dataCategoryId,
'data' => $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
];
}
}