Files
hyperf_service/app/Service/Api/Good/AddStapleFoodInfoService.php
2025-04-09 16:08:00 +08:00

84 lines
2.2 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\Constants\Common\GoodCode;
use App\Model\Sku;
use App\Model\Spu;
use App\Service\Api\BaseService;
use App\Service\ServiceTrait\Common\CycleTrait;
use App\Service\ServiceTrait\Common\OssTrait;
use Hyperf\Di\Annotation\Inject;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class AddStapleFoodInfoService extends BaseService
{
use CycleTrait;
use OssTrait;
/**
* @var GoodCache
*/
#[Inject]
protected GoodCache $goodCache;
/**
* @var SiteCache
*/
#[Inject]
protected SiteCache $siteCache;
/**
* @var Sku
*/
#[Inject]
protected Sku $skuModel;
/**
* @var Spu
*/
#[Inject]
protected Spu $spuModel;
/**
* @return array
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function handle(): array
{
$cycleId = $this->initTodayCycleId();
if (empty($cycleId)) return $this->return->success('success', ['list' => []]);
$siteInfo = $this->siteCache->getSiteInfo((int)$this->request->input('site_id'));
if (empty($siteInfo) || empty($siteInfo['kitchen_id'])) return $this->return->success('success', ['list' => []]);
$cycleId = (int)$cycleId;
$kitchenId = (int)$siteInfo['kitchen_id'];
$spuInfo = $this->spuModel->getListByCycleIdAndType($cycleId, $kitchenId,GoodCode::SPU_TYPE_MEAL);
if (empty($spuInfo)) return $this->return->success('success', ['add_food_info' => []]);
$spuIds = array_column($spuInfo->toArray(), 'spu_id');
// $data = $this->goodCache->getMealGoodList();
$skuInfo = $this->skuModel->getAddStapleFoodListBySpuIds($spuIds);
if (empty($skuInfo)) return $this->return->success('success', ['add_food_info' => []]);
$res = $skuInfo->toArray();
$res['url'] = $this->getOssObjectById($res['image_ids']);
return $this->return->success('success', ['add_food_info' => $res]);
}
}