41 lines
866 B
PHP
41 lines
866 B
PHP
<?php
|
|
|
|
namespace App\Service\ServiceTrait\Api;
|
|
|
|
use App\Constants\Common\BannerCode;
|
|
use App\Model\Banner;
|
|
use App\Service\ServiceTrait\Common\OssTrait;
|
|
use Hyperf\Di\Annotation\Inject;
|
|
|
|
trait BannerTrait
|
|
{
|
|
use OssTrait;
|
|
|
|
/**
|
|
* @var Banner
|
|
*/
|
|
#[Inject]
|
|
protected Banner $bannerModel;
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
private function getBanner(int $cityId): array
|
|
{
|
|
$res = $this->bannerModel
|
|
->where('city_id',$cityId)
|
|
->where('status',BannerCode::DISPLAYED)
|
|
->orderBy('sort')
|
|
->get();
|
|
if ($res->isEmpty()) return [];
|
|
$res = $res->toArray();
|
|
|
|
$imageList = $this->getOssObjects(array_column($res, 'image_id'));
|
|
|
|
foreach ($res as &$v) {
|
|
$v['url'] = $imageList[$v['image_id']]['url'] ?? '';
|
|
}
|
|
|
|
return $res;
|
|
}
|
|
} |