添加根据经纬度获取城市
添加后台统计看板
This commit is contained in:
@@ -42,9 +42,21 @@ class Ad extends AdminBase
|
||||
}
|
||||
$this->_error($result);
|
||||
}
|
||||
$this->assign('category_list',AdLogic::getGoodsCategory());
|
||||
// 确保 client 参数有效
|
||||
if (empty($client)) {
|
||||
$client = $this->request->param('client', '1');
|
||||
}
|
||||
$category_list = AdLogic::getGoodsCategory();
|
||||
$link_page = \app\common\model\Ad::getLinkPage($client);
|
||||
$position_list = AdLogic::infoPosition($client);
|
||||
$this->assign('category_list', AdLogic::getGoodsCategory());
|
||||
$this->assign('link_page', \app\common\model\Ad::getLinkPage($client));
|
||||
$this->assign('position_list', AdLogic::infoPosition($client));
|
||||
|
||||
$this->assign([
|
||||
'category_list' => $category_list,
|
||||
'link_page' => $link_page,
|
||||
'position_list' => $position_list,
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
||||
124
application/admin/controller/BulletinBoard.php
Normal file
124
application/admin/controller/BulletinBoard.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
use app\admin\model\User;
|
||||
use app\common\server\UrlServer;
|
||||
use think\facade\Url;
|
||||
|
||||
class BulletinBoard extends AdminBase
|
||||
{
|
||||
|
||||
//看板统计
|
||||
public function index()
|
||||
{
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
||||
//地图上显示注册用户位置
|
||||
public function map()
|
||||
{
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function getUserMap()
|
||||
{
|
||||
// 查询有经纬度的用户
|
||||
$userArray = User::where('latitude', '<>', '')
|
||||
->where('longitude', '<>', '')
|
||||
->field('id,nickname,mobile,avatar,longitude,latitude')
|
||||
->select();
|
||||
// 格式化数据,转换为前端期望的字段名
|
||||
$result = [];
|
||||
foreach ($userArray as $user) {
|
||||
// 处理头像URL,使用代理接口避免CORS问题
|
||||
$avatar = '';
|
||||
if (!empty($user['avatar'])) {
|
||||
$originalUrl = UrlServer::getFileUrl($user['avatar']);
|
||||
// 去掉JSON编码时产生的转义反斜杠
|
||||
$originalUrl = str_replace('\\/', '/', $originalUrl);
|
||||
|
||||
// 如果URL是跨域的,使用代理接口
|
||||
$currentDomain = $this->request->domain();
|
||||
if (strpos($originalUrl, $currentDomain) === false) {
|
||||
// 跨域,使用代理(手动构建URL避免双重编码)
|
||||
$avatar = $this->request->domain() . '/admin/bulletin_board/proxyImage?url=' . rawurlencode($originalUrl);
|
||||
} else {
|
||||
// 同域,直接使用
|
||||
$avatar = $originalUrl;
|
||||
}
|
||||
}
|
||||
|
||||
$result[] = [
|
||||
'id' => $user['id'] ?? 0,
|
||||
'lng' => floatval($user['longitude'] ?? 0),
|
||||
'lat' => floatval($user['latitude'] ?? 0),
|
||||
'name' => $user['nickname'] ?? '',
|
||||
'contact' => $user['nickname'] ?? '', // 兼容两种字段名
|
||||
'mobile' => $user['mobile'] ?? '',
|
||||
'phone' => $user['mobile'] ?? '', // 兼容 telephone/phone
|
||||
'telephone' => $user['mobile'] ?? '',
|
||||
'avatar' => $avatar
|
||||
];
|
||||
}
|
||||
|
||||
return $this->_success('获取成功', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 图片代理接口,解决CORS跨域问题
|
||||
*/
|
||||
public function proxyImage()
|
||||
{
|
||||
$url = $this->request->get('url', '');
|
||||
if (empty($url)) {
|
||||
header('HTTP/1.1 404 Not Found');
|
||||
exit;
|
||||
}
|
||||
|
||||
// 解码URL
|
||||
$url = urldecode($url);
|
||||
|
||||
// 验证URL格式
|
||||
if (!filter_var($url, FILTER_VALIDATE_URL)) {
|
||||
header('HTTP/1.1 400 Bad Request');
|
||||
exit;
|
||||
}
|
||||
|
||||
// 只允许图片格式
|
||||
$allowedExtensions = ['jpg', 'jpeg', 'png', 'gif', 'webp'];
|
||||
$extension = strtolower(pathinfo(parse_url($url, PHP_URL_PATH), PATHINFO_EXTENSION));
|
||||
if (!in_array($extension, $allowedExtensions)) {
|
||||
header('HTTP/1.1 403 Forbidden');
|
||||
exit;
|
||||
}
|
||||
|
||||
// 获取图片
|
||||
$context = stream_context_create([
|
||||
'http' => [
|
||||
'method' => 'GET',
|
||||
'timeout' => 10,
|
||||
'header' => [
|
||||
'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
$imageData = @file_get_contents($url, false, $context);
|
||||
|
||||
if ($imageData === false) {
|
||||
header('HTTP/1.1 404 Not Found');
|
||||
exit;
|
||||
}
|
||||
|
||||
// 设置响应头
|
||||
header('Content-Type: image/' . ($extension === 'jpg' ? 'jpeg' : $extension));
|
||||
header('Cache-Control: public, max-age=3600');
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header('Access-Control-Allow-Methods: GET');
|
||||
|
||||
// 输出图片
|
||||
echo $imageData;
|
||||
exit;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user