Files
hyperf_service/app/Service/Api/Good/OptionalListService.php
2025-02-11 11:14:35 +08:00

58 lines
1.4 KiB
PHP

<?php
/**
* This service file is part of item.
*
* @author ctexthuang
* @contact ctexthuang@qq.com
*/
declare(strict_types=1);
namespace App\Service\Api\Good;
use App\Cache\Redis\Api\GoodCache;
use App\Cache\Redis\Api\SiteCache;
use App\Service\Api\BaseService;
use App\Service\ServiceTrait\Common\CycleTrait;
use Hyperf\Di\Annotation\Inject;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class OptionalListService extends BaseService
{
use CycleTrait;
/**
* @var GoodCache
*/
#[Inject]
protected GoodCache $goodCache;
/**
* @var SiteCache
*/
#[Inject]
protected SiteCache $siteCache;
/**
* @return array
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function handle(): array
{
$cycleId = $this->initTodayCycleId();
if (empty($cycleId)) return ['list' => []];
$this->goodCache->cycleId = (int)$cycleId;
$siteInfo = $this->siteCache->getSiteInfo((int)$this->request->input('site_id'));
if (empty($siteInfo) || empty($siteInfo['kitchen_id'])) return ['list' => []];
$this->goodCache->kitchenId = $siteInfo['kitchen_id'];
$data = $this->goodCache->getOptionalGoodList();
return $this->return->success('success', ['list' => $data]);
}
}