feat : site
This commit is contained in:
53
app/Service/Api/System/SiteListService.php
Normal file
53
app/Service/Api/System/SiteListService.php
Normal 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]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user