forked from cashgithubs/Project
/
lbs_update.php
executable file
·401 lines (389 loc) · 10.5 KB
/
lbs_update.php
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
<?php
define('MOD_UNIQUEID','lbs');//模块标识
require_once './global.php';
require_once(CUR_CONF_PATH.'lib/lbs.class.php');
require_once(CUR_CONF_PATH.'core/lbs.core.php');
class LBSUpdateApi extends outerUpdateBase
{
public function __construct()
{
parent::__construct();
$this->lbs_field = new lbs_field();
$this->lbs = new ClassLBS();
}
public function __destruct()
{
parent::__destruct();
}
public function create()
{
$data = array(
'title' => trim($this->input['title']),
'sort_id' => intval($this->input['sort_id']),
'province_id' => intval($this->input['province_id']),
'city_id' => intval($this->input['city_id']),
'area_id' => intval($this->input['area_id']),
'stime' => strtotime($this->input['stime']),
'etime' => strtotime($this->input['etime']),
'baidu_longitude' => $this->input['baidu_longitude'],
'baidu_latitude' => $this->input['baidu_latitude'],
'address' => trim($this->input['address']),
'GPS_longitude' => $this->input['GPS_longitude'],
'GPS_latitude' => $this->input['GPS_latitude'],
'create_time' => TIMENOW,
'org_id' => $this->user['org_id'],
'user_id' => $this->user['user_id'],
'user_name' => $this->user['user_name'],
'ip' => $this->user['ip'],
);
if (!$data['title'])
{
$this->errorOutput('标题不能为空');
}
//如果百度坐标存在的话,就转换为GPS坐标也存起来
if($data['baidu_longitude'] && $data['baidu_latitude'] && !$data['GPS_longitude'] && !$data['GPS_latitude'])
{
$gps = $this->lbs->FromBaiduToGpsXY($data['baidu_longitude'],$data['baidu_latitude']);
$data['GPS_longitude'] = $gps['GPS_x'];
$data['GPS_latitude'] = $gps['GPS_y'];
}
//如果GPS坐标存在的话,就转换为百度坐标也存起来
if(!$data['baidu_longitude'] && !$data['baidu_latitude'] && $data['GPS_longitude'] && $data['GPS_latitude'])
{
$baidu = $this->lbs->FromGpsToBaiduXY($data['GPS_longitude'],$data['GPS_latitude']);
$data['baidu_longitude'] = $baidu['x'];
$data['baidu_latitude'] = $baidu['y'];
}
//电话处理
$tel = $this->input['tel'];
if (is_array($tel))
{
$tel = array_filter($tel);
if (!empty($tel))
{
$data['tel'] = serialize($tel);
}
}
//添加lbs信息
$lbs = $this->lbs->add_lbs($data);
if (!$lbs['id'])
{
$this->errorOutput('数据库插入失败');
}
$id = $lbs['id'];
//附加信息处理
$data['field']=$this->lbs_field->field_contentupdate($id,$this->input['sort_id'],$this->input['catalog']);
//添加描述
$content = trim($this->input['content']);
if ($content)
{
$contentInfor = $this->lbs->add_content($content, $id);
if (!$contentInfor)
{
$this->errorOutput('数据库插入失败');
}
$data['content'] = $contentInfor;
}
//图片上传
if ($_FILES['photos'])
{
$photos = array();
//检测图片服务器
if (!$this->settings['App_material'])
{
$this->errorOutput('图片服务器未安装!');
}
$count = count($_FILES['photos']['name']);
for($i = 0; $i < $count; $i++)
{
if ($_FILES['photos']['name'][$i])
{
if ($_FILES['photos']['error'][$i]>0)
{
$this->errorOutput('图片上传异常');
}
if ($_FILES['photos']['size'][$i]>100000000)
{
$this->errorOutput('只允许上传100M以下的图片!');
}
foreach($_FILES['photos'] AS $k =>$v)
{
$photo['Filedata'][$k] = $_FILES['photos'][$k][$i];
}
$photos[] = $photo;
}
}
if (!empty($photos))
{
//循环插入图片服务器
foreach ($photos as $val)
{
$PhotoInfor = $this->lbs->uploadToPicServer($val, $id);
if (empty($PhotoInfor))
{
$this->errorOutput('图片服务器错误!');
}
$temp = array(
'cid' => $id,
'type' => $PhotoInfor['type'],
'original_id' => $PhotoInfor['id'],
'host' => $PhotoInfor['host'],
'dir' => $PhotoInfor['dir'],
'filepath' => $PhotoInfor['filepath'],
'filename' => $PhotoInfor['filename'],
'imgwidth' => $PhotoInfor['imgwidth'],
'imgheight' => $PhotoInfor['imgheight'],
'mark' => 'img',
);
//插入数据库
$ret_pic = $this->lbs->upload_pic($temp);
//默认第一张图片为索引图
if (!$indexpic)
{
$indexpic = $this->lbs->update_indexpic($ret_pic['id'], $id);
$data['indexpic'] = $indexpic['id'];
$data['img_info'] = $indexpic;
}
if ($ret_pic)
{
$data['images'][] = $ret_pic;
}
else
{
$this->errorOutput('图片入库失败');
}
}
}
}
//视频上传
if ($_FILES['video'])
{
$videos = array();
//检测视频服务器
if (!$this->settings['App_mediaserver'])
{
$this->errorOutput('视频服务器未安装!');
}
$count = count($_FILES['video']['name']);
for($i = 0; $i < $count; $i++)
{
if ($_FILES['video']['name'][$i])
{
if ($_FILES['video']['error'][$i]>0)
{
$this->errorOutput('视频上传异常');
}
foreach($_FILES['video'] AS $k =>$v)
{
$video['videofile'][$k] = $_FILES['video'][$k][$i];
}
$videos[] = $video;
}
}
if (!empty($videos))
{
foreach ($videos as $videoInfor)
{
//上传视频服务器
$videodata = $this->lbs->uploadToVideoServer($videoInfor, $data['title'], '',2);
if (!$videodata)
{
$this->errorOutput('视频服务器错误!');
}
//视频入库
$arr = array(
'cid' => $id,
'type' => $videodata['type'],
'host' => $videodata['protocol'].$videodata['host'],
'dir' => $videodata['dir'],
'original_id'=> $videodata['id'],
'filename' => $videodata['file_name'],
'mark' => 'video',
);
$ret_vod = $this->lbs->upload_vod($arr);
if ($ret_vod)
{
$data['video'][] = $ret_vod;
}
else
{
$this->errorOutput('视频入库失败');
}
}
}
}
$data['id'] = $id;
$this->addItem($data);
$this->output();
}
public function update()
{
$id = intval($this->input['id']);
if(!$id)
{
$this->errorOutput(NOID);
}
//数据验证,不可修改他人数据
$res = $this->lbs->checkSelfData($id, $this->user['id']);
if (!$res)
{
//$this->errorOutput('不可修改他人数据');
}
$data = array(
'title' => trim($this->input['title']),
'sort_id' => intval($this->input['sort_id']),
'province_id' => intval($this->input['province_id']),
'city_id' => intval($this->input['city_id']),
'area_id' => intval($this->input['area_id']),
'stime' => strtotime($this->input['stime']),
'etime' => strtotime($this->input['etime']),
'indexpic' => intval($this->input['indexpic']),
'baidu_longitude' => $this->input['baidu_longitude'],
'baidu_latitude' => $this->input['baidu_latitude'],
'address' => trim($this->input['address']),
'update_time' => TIMENOW,
'update_org_id' => $this->user['org_id'],
'update_user_id' => $this->user['user_id'],
'update_user_name' => $this->user['user_name'],
'update_ip' => $this->user['ip'],
);
if (!$data['title'])
{
$this->errorOutput('标题不能为空');
}
if (!$data['sort_id'])
{
$this->errorOutput('请选择分类');
}
if($data['baidu_longitude'] && $data['baidu_latitude'])
{
$gps = $this->lbs->FromBaiduToGpsXY($data['baidu_longitude'],$data['baidu_latitude']);
$data['GPS_longitude'] = $gps['GPS_x'];
$data['GPS_latitude'] = $gps['GPS_y'];
}
//电话处理
$tel = $this->input['tel'];
if (is_array($tel))
{
$tel = array_filter($tel);
if (!empty($tel))
{
$data['tel'] = serialize($tel);
}
}
$sql = 'UPDATE '.DB_PREFIX.'lbs SET ';
foreach ($data as $key=>$val)
{
$sql .= $key . '="' . addslashes($val) . '",';
}
$sql = rtrim($sql, ',');
$sql.= ' WHERE id = ' . $id;
$this->db->query($sql);
//内容处理
$content = trim($this->input['content']);
$sql = 'UPDATE '.DB_PREFIX.'lbs_content SET content = "'.addslashes($content).'" WHERE id = '.$id;
$this->db->query($sql);
//图片删除
if ($this->input['delMaterialIds'])
{
if (is_array($this->input['delMaterialIds']))
{
$delMaterialIds = implode(',', $this->input['delMaterialIds']);
}
if (is_string($this->input['delMaterialIds']))
{
$delMaterialIds = $this->input['delMaterialIds'];
}
$ret = $this->lbs->deleteMaterials($delMaterialIds);
if (!$ret)
{
$this->errorOutput('删除图片失败');
}
}
//图片上传
if ($_FILES['photos'])
{
$photos = array();
//检测图片服务器
if (!$this->settings['App_material'])
{
$this->errorOutput('图片服务器未安装!');
}
$count = count($_FILES['photos']['name']);
for($i = 0; $i < $count; $i++)
{
if ($_FILES['photos']['name'][$i])
{
if ($_FILES['photos']['error'][$i]>0)
{
$this->errorOutput('图片上传异常');
}
if ($_FILES['photos']['size'][$i]>100000000)
{
$this->errorOutput('只允许上传100M以下的图片!');
}
foreach($_FILES['photos'] AS $k =>$v)
{
$photo['Filedata'][$k] = $_FILES['photos'][$k][$i];
}
$photos[] = $photo;
}
}
if (!empty($photos))
{
//循环插入图片服务器
foreach ($photos as $val)
{
$PhotoInfor = $this->lbs->uploadToPicServer($val, $id);
if (empty($PhotoInfor))
{
$this->errorOutput('图片服务器错误!');
}
$temp = array(
'cid' => $id,
'type' => $PhotoInfor['type'],
'original_id' => $PhotoInfor['id'],
'host' => $PhotoInfor['host'],
'dir' => $PhotoInfor['dir'],
'filepath' => $PhotoInfor['filepath'],
'filename' => $PhotoInfor['filename'],
'imgwidth' => $PhotoInfor['imgwidth'],
'imgheight' => $PhotoInfor['imgheight'],
'mark' => 'img',
);
//插入数据库
$ret_pic = $this->lbs->upload_pic($temp);
if ($ret_pic)
{
$data['images'][] = $ret_pic;
}
else
{
$this->errorOutput('图片入库失败');
}
}
}
}
$data['id'] = $id;
$this->lbs_field->field_contentupdate($id,$this->input['sort_id'],$this->input['catalog']);
$this->addItem($data);
$this->output();
}
public function delete()
{
}
public function unknow()
{
$this->errorOutput('此方法不存在');
}
}
$ouput= new LBSUpdateApi();
if(!method_exists($ouput, $_INPUT['a']))
{
$action = 'unknow';
}
else
{
$action = $_INPUT['a'];
}
$ouput->$action();