feat : site

This commit is contained in:
2025-02-27 17:21:21 +08:00
parent a76d360b77
commit 3be21ed1b6
6 changed files with 305 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
<?php
/**
* This service file is part of item.
*
* @author ctexthuang
* @contact ctexthuang@qq.com
*/
declare(strict_types=1);
namespace App\Service\Api\System;
use App\Cache\Redis\Api\SiteCache;
use App\Extend\SystemUtil;
use App\Model\Site;
use App\Service\Api\BaseService;
use Hyperf\Di\Annotation\Inject;
class SiteListService extends BaseService
{
/**
* @var Site
*/
#[Inject]
protected Site $siteModel;
/**
* @return array
*/
public function handle(): array
{
$limit = $this->request->input('limit', 20);
$list = $this->siteModel
->when($name = $this->request->input('search_value'), function ($query) use ($name) {
$query->where('name', 'like', "%$name%");
})
// ->where('name', 'like', '%'.$this->request->input('search_value').'%')
->paginate($limit)
->toArray();
if (empty($list['data'])) return $this->return->success('success', ['list' => $list]);
foreach ($list['data'] as &$item) {
$item['gap'] = SystemUtil::calculateDistance(
['lng' => $this->request->input('lng'),'lat' => $this->request->input('lat')],
['lng' => $item['lng'], 'lat' => $item['lat']]
);
}
return $this->return->success('success', ['list' => $list]);
}
}