feat : banner
This commit is contained in:
@@ -20,6 +20,7 @@ use App\Constants\ConfigCode;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\Category;
|
||||
use App\Service\Api\BaseService;
|
||||
use App\Service\ServiceTrait\Api\BannerTrait;
|
||||
use App\Service\ServiceTrait\Common\CycleTrait;
|
||||
use App\Service\ServiceTrait\Common\OssTrait;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
@@ -30,6 +31,7 @@ use function Hyperf\Config\config;
|
||||
class OptionalListService extends BaseService
|
||||
{
|
||||
use CycleTrait;
|
||||
use BannerTrait;
|
||||
|
||||
/**
|
||||
* @var GoodCache
|
||||
@@ -86,7 +88,7 @@ class OptionalListService extends BaseService
|
||||
|
||||
$res = $this->buildData($data);
|
||||
|
||||
return $this->return->success('success', ['list' => $res]);
|
||||
return $this->return->success('success', ['list' => $res,'banner' => $this->getBanner((int)$this->request->input('city_id',config('system.default_city_id')))]);
|
||||
}
|
||||
|
||||
use OssTrait;
|
||||
|
||||
@@ -34,7 +34,7 @@ class IndexService extends BaseService
|
||||
$avatar = $this->getOssObjectById($userInfo->avatar_id);
|
||||
|
||||
$res = [
|
||||
'banner' => $this->getBanner(),
|
||||
// 'banner' => $this->getBanner(),
|
||||
'nickname' => $userInfo->nickname,
|
||||
'avatar' => $avatar,
|
||||
'point' => 0,
|
||||
|
||||
41
app/Service/ServiceTrait/Api/BannerTrait.php
Normal file
41
app/Service/ServiceTrait/Api/BannerTrait.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -30,5 +30,7 @@ return [
|
||||
// upload_dir
|
||||
'upload_dir' => BASE_PATH.'/uploads/',
|
||||
// 默认的厨房 id
|
||||
'default_kitchen_id' => env('DEFAULT_KITCHEN_ID',''),
|
||||
'default_kitchen_id' => env('DEFAULT_KITCHEN_ID',1),
|
||||
// 默认 城市 id
|
||||
'default_city_id' => env('DEFAULT_CITY_ID',3),
|
||||
];
|
||||
Reference in New Issue
Block a user