58 lines
1.6 KiB
PHP
58 lines
1.6 KiB
PHP
<?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\Constants\Common\SiteCode;
|
|
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').'%')
|
|
->where('is_del',SiteCode::SITE_NO_DEL)
|
|
->paginate($limit)
|
|
->toArray();
|
|
|
|
if (empty($list['data'])) return $this->return->success('success', ['list' => $list]);
|
|
|
|
foreach ($list['data'] as &$item) {
|
|
$item['gap'] = 0;
|
|
if (empty($this->request->input('lng')) || empty($this->request->input('lat'))) continue;
|
|
|
|
$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]);
|
|
}
|
|
} |