Compare commits

...

5 Commits

Author SHA1 Message Date
2f1c7a9b28 feat : banner 2025-07-24 17:02:07 +08:00
66666f4a3a feat : spu 2025-07-24 10:36:54 +08:00
bbcc0d054f feat : spu 2025-07-24 10:34:26 +08:00
0a1610fc42 feat : sku 2025-07-24 10:09:25 +08:00
a296a30080 feat : kitchen 2025-07-24 10:00:20 +08:00
7 changed files with 68 additions and 13 deletions

View File

@@ -97,17 +97,17 @@ class SiteCache
/**
* @param int $siteId
* @return array|false|\Redis|null
* @return array|false|\Redis
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function getSiteInfo(int $siteId): false|array|\Redis|null
public function getSiteInfo(int $siteId): false|array|\Redis
{
$siteKey = CommonRedisKey::siteInfoKey($siteId);
if (!$this->redis->exists($siteKey,RedisCode::SYSTEM_DB)) $this->setSiteInfo($siteId);
return $this->redis->hGetAll($siteKey,RedisCode::SYSTEM_DB) ?? null;
return $this->redis->hGetAll($siteKey,RedisCode::SYSTEM_DB) ?? false;
}
/**

View File

@@ -96,7 +96,7 @@ class Sku extends Model
->where('saleable',GoodCode::LISTING)
// ->where('is_add_staple_food',GoodCode::IS_NOT_ADD_STAPLE_FOOD)
->orderBy('sort')
->select(['id','spu_id','title','image_ids','price','param','extra','total_stock','surplus_stock','order_num','is_add_staple_food','occupied','chef_id','origin_sku_id'])
->select(['id','spu_id','title','image_ids','price','param','extra','total_stock','surplus_stock','order_num','is_add_staple_food','occupied','chef_id','origin_sku_id','sub_title'])
->get();
}

View File

@@ -88,6 +88,7 @@ class SpuService extends BaseService
if (empty($list['data'])) return $this->return->success('success', ['list' => $list]);
$spuIds = array_column($list['data'], 'id');
$spuImageIds = array_column($list['data'], 'image_id');
$skuList = $this->skuModel
->whereIn('spu_id',$spuIds)
@@ -99,7 +100,7 @@ class SpuService extends BaseService
$imageIdArr = array_column($skuList,'image_ids');
$imageIds = array_unique(explode(',',implode(',',$imageIdArr)));
$imageList = $this->getOssObjects($imageIds);
$imageList = $this->getOssObjects(array_merge($imageIds,$spuImageIds));
$skuListArr = [];
foreach ($skuList as $sku) {
@@ -126,6 +127,7 @@ class SpuService extends BaseService
foreach ($list['data'] as &$item) {
$item['sku_list'] = $skuListArr[$item['id']] ?? [];
$item['image_url'] = $imageList[$item['image_id']] ?? '';
}
return $this->return->success('success', ['list' => $list]);
@@ -323,6 +325,7 @@ class SpuService extends BaseService
$info['city_name'] = $this->systemCityModel->getCityNameById((int)$info['city_id']);
$info['kitchen_name'] = $this->kitchenModel->getNameById((int)$info['kitchen_id']);
// $info['chef_name'] = $this->chefModel->getChineseNameById((int)$info['chef_id']);
$info['image_url'] = $this->getOssObjectById((int)$info['image_id']) ?? '';
$info['chef_name'] = '';
$info['category_name'] = $this->categoryModel->getNameById((int)$info['category_id']);

View File

@@ -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
@@ -55,6 +57,12 @@ class OptionalListService extends BaseService
#[Inject]
protected Category $categoryModel;
/**
* 默认地址
* @var array|false
*/
private array|false $siteInfo = [];
/**
* @return array
* @throws ContainerExceptionInterface
@@ -67,19 +75,20 @@ class OptionalListService extends BaseService
if (empty($cycleId)) return $this->return->success('success', ['list' => []]);
$this->goodCache->cycleId = (int)$cycleId;
if (!empty($this->request->input('site_id'))){
$siteInfo = $this->siteCache->getSiteInfo((int)$this->request->input('site_id'));
}
if (empty($siteInfo) || empty($siteInfo['kitchen_id'])) $siteInfo['kitchen_id'] = config('system.kitchen_id');
$this->goodCache->kitchenId = (int)$siteInfo['kitchen_id'];
if (!empty($this->request->input('site_id'))){
$this->siteInfo = $this->siteCache->getSiteInfo((int)$this->request->input('site_id'));
}
if (empty($this->siteInfo) || empty($this->siteInfo['kitchen_id'])) $this->siteInfo['kitchen_id'] = config('system.default_kitchen_id');
$this->goodCache->kitchenId = (int)$this->siteInfo['kitchen_id'];
$data = $this->goodCache->getOptionalGoodList();
if (empty($data)) return $this->return->success('success', ['list' => []]);
$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;

View File

@@ -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,

View 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;
}
}

View File

@@ -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),
];