Onlinereg.class.php
9.47 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<?php
class Controller_Admin_Onlinereg extends Controller_Admin_Base
{
/**
* 参展商登记
*/
public function indexAction()
{
$type = intval($this->_request->get('type', 0));
$types = array(
Facade_Onlinereg::TYPE_ONLINE_EXHIBITOR =>'参展商',
Facade_Onlinereg::TYPE_ONLINE_SPONSOR =>'赞助商',
Facade_Onlinereg::TYPE_ONLINE_MEDIA =>'媒体');
if(!in_array($type, array_keys($types))) {
$type = 0;
}
$limit = 15;
$total = Facade_Onlinereg::getSellerTotalByType($type);
$pagination = new Lib_Helper_Pagination($total, $limit);
$pagination->setParames(array('type' => $type));
$list = Facade_Onlinereg::getSellerListByType($type, $pagination->getOffset(), $limit);
$this->_view['list'] = $list;
$this->_view['pagination'] = $pagination->getPagination();
$this->_view['type'] = $type;
$this->_view['sellerTypes'] = $types;
}
/**
* 参展商手册
*/
public function downloadAction()
{
$limit = 15;
$type = intval($this->_request->get('type', 0));
if(!in_array($type, array(Facade_Onlinereg::TYPE_ONLINE_DOWNLOAD_EXHIBITOR,
Facade_Onlinereg::TYPE_ONLINE_DOWNLOAD_MEDIA)))
{
$type = 0;
}
$total = Facade_Onlinereg::getDownloadTotalByType($type);
$pagination = new Lib_Helper_Pagination($total, $limit);
$pagination->setParames(array('type' => $type));
$list = Facade_Onlinereg::getDownloadListByType($type, $pagination->getOffset(), $limit);
foreach ($list as &$download)
{
$download['cover'] = Lib_Images::getImageUrl($download['cover'], 'source','fragmentimg');
}
$this->_view['type'] = $type;
$this->_view['list'] = $list;
$this->_view['pagination'] = $pagination->getPagination();
$this->_view['key'] = Lib_Images::genKey('fragmentimg');
}
/**
* 获取商家数据
*
* @return array
*/
public function getsellerAction()
{
$sellerId = $this->_request->query('id');
$seller = array();
if(!empty($sellerId))
{
$seller = Facade_Onlinereg::getSellerById($sellerId);
}
if(!empty($seller))
{
return $this->returnJson(true, 200, $seller);
}
else
{
return $this->returnJson(false, 403);
}
}
/**
* 设置商家数据
*
* @return array
*/
public function setsellerAction()
{
$data = $_POST;
if(isset($data['id']))
{
unset($data['files']);
$data = array_map('addslashes', $data);
$status = Facade_Onlinereg::setSeller($data);
if($status)
{
return $this->returnJson(true, 200);
}
else
{
return $this->returnJson(false, 403);
}
}
else
{
return $this->returnJson(false, 403);
}
}
/**
* 获取下载相关
*/
public function getdownloadAction()
{
$id = intval($this->_request->query('id'));
$download = Facade_Onlinereg::getDownloadById($id);
return $this->returnJson(true, 200, $download);
}
/**
* 设置下载信息
*
* @return json
*/
public function setdownloadAction()
{
$status = false;
$type = $this->_request->query('type', 0);
$id = $this->_request->query('id', 0);
$title = trim($this->_request->query('title', ''));
$cover = $this->_request->query('cover', '');
$file = $this->_request->query('file', '');
$source = $this->_request->query('source', '');
$source_link = $this->_request->query('source_link', '');
if(!empty($title) && !empty($id))
{
//更新数据
$status = Facade_Onlinereg::setDownloadInfoById($id, $title, $cover, $file, $source, $source_link);
}
else if(!empty($title) && in_array($type, array(
Facade_Onlinereg::TYPE_ONLINE_DOWNLOAD_EXHIBITOR,
Facade_Onlinereg::TYPE_ONLINE_DOWNLOAD_MEDIA)))
{
$status = Facade_Onlinereg::setDownloadInfo($title, $cover, $file, $source, $source_link, $type);
}
if($status)
{
return $this->returnJson(true, 200);
}
else
{
return $this->returnJson(false, 403);
}
}
/**
* 删除下载数据
*
*/
public function deldownloadAction()
{
$id = $this->_request->query('id');
$status = Facade_Onlinereg::delDownload($id);
if($status)
{
return $this->returnJson(true, 200);
}
else
{
return $this->returnJson(false, 403);
}
}
/**
* 导出excel
*/
public function exportAction()
{
$typeAttrs = array(
Facade_Onlinereg::TYPE_ONLINE_EXHIBITOR => array('ID','品牌名称','是否入驻有货','品牌注册','公司名称','联系人',
'电话','邮箱','公司与品牌关系','商品所在地','是否3C','官网','时间'),
Facade_Onlinereg::TYPE_ONLINE_SPONSOR => array('ID','品牌名称','是否入驻有货','产品类型','所属国家','公司名称','公司地址',
'联系人','电话','邮箱','品牌官网','时间'),
Facade_Onlinereg::TYPE_ONLINE_MEDIA => array('ID','姓名','职位','性别','媒体名/公司名','介绍','官网地址',
'所在城市','邮箱','手机','座机','固定地址','邮编','时间'),
);
$typeDBKeys = array(
Facade_Onlinereg::TYPE_ONLINE_EXHIBITOR => array('id','name','is_enter_yohobuy',
'brand_reg_type','company','contact','telphone','email','relation','place','is_3c','website','create_time'),
Facade_Onlinereg::TYPE_ONLINE_SPONSOR => array('id','name','is_enter_yohobuy','product_type','country',
'company','place','contact','telphone','email','website','create_time'),
Facade_Onlinereg::TYPE_ONLINE_MEDIA => array('id','name','profession','sex','company','introduction','website',
'city','email','mobile','telphone','place','zipcode','create_time'),
);
$typeSaveNames = array(
Facade_Onlinereg::TYPE_ONLINE_EXHIBITOR => 'exhibitor',
Facade_Onlinereg::TYPE_ONLINE_SPONSOR => 'sponsor',
Facade_Onlinereg::TYPE_ONLINE_MEDIA => 'media',
);
$type = 0;
$id = $this->_request->query('id');
$sellerIds = array_filter(explode(',', $id),'is_numeric');
$sellerList = array();
foreach($sellerIds as $sellerId)
{
$sellerList[] = Facade_Onlinereg::getSellerById($sellerId);
}
if(!empty($sellerList))
{
$excel = new Util_Excel_Excel();
$excel->getProperties()->setCreator('yoho')
->setTitle('yohood')->setSubject('yohood')->setDescription('yohood')->setKeywords('yohood');
$excel->setActiveSheetIndex(0);
$type = $sellerList[0]['type'];
$attrs = $typeAttrs[$type];
$indexs = range('A','Z');
$brandRegTypes = array('未注册','已注册','已申请');
$relationAttrs = array('品牌商','代理商','经销商','其他');
$pos = 0;
$cellNum = 1;
foreach($attrs as $attr)//输出属性
{
$cell = $indexs[$pos++];
$excel->getActiveSheet()->getColumnDimension($cell)->setWidth(15);
$excel->getActiveSheet()->setCellValue($cell.$cellNum, $attr);
}
foreach($sellerList as $seller)
{
$cellNum ++;
$pos = 0;
for($i = 0; $i<count($attrs); $i++)
{
$key = $typeDBKeys[$type][$i];
$cell = $indexs[$pos++].$cellNum;
$attr = $seller[$key];
if($key == 'create_time') //时间属性
{
$value = date('Y-m-d H:i:s', $attr);
}
else if(in_array($key, array('is_enter_yohobuy','is_3c')))//是否
{
$value = empty($attr) ? '否':'是';
}
else if($key == 'brand_reg_type')//品牌注册类型
{
$value = $brandRegTypes[$attr];
}
else if($key == 'relation')//公司与品牌关系
{
$value = $relationAttrs[$attr];
}
else
{
$value = $attr;
}
$excel->getActiveSheet()->setCellValue($cell, $value);
}
}
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$typeSaveNames[$type].'.xls"');
header('Cache-Control: max-age=0');
$excel->setActiveSheetIndex(0);
$objWriter = PHPExcel_IOFactory::createWriter($excel, 'Excel5');
$objWriter->save('php://output');
}
else
{
die('没有下载');
}
}
}