79 lines
2.1 KiB
PHP
79 lines
2.1 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\ApiRedisKey;
|
|
use App\Cache\Redis\Api\GoodCache;
|
|
use App\Cache\Redis\Api\SiteCache;
|
|
use App\Cache\Redis\RedisCache;
|
|
use App\Constants\Common\GoodCode;
|
|
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 MealListService extends BaseService
|
|
{
|
|
use CycleTrait;
|
|
|
|
/**
|
|
* @var GoodCache
|
|
*/
|
|
#[Inject]
|
|
protected GoodCache $goodCache;
|
|
|
|
/**
|
|
* @var SiteCache
|
|
*/
|
|
#[Inject]
|
|
protected SiteCache $siteCache;
|
|
|
|
/**
|
|
* @var RedisCache
|
|
*/
|
|
#[Inject]
|
|
protected RedisCache $redisCache;
|
|
|
|
|
|
/**
|
|
* @return array|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' => []]);
|
|
|
|
$this->goodCache->cycleId = (int)$cycleId;
|
|
$this->goodCache->kitchenId = (int)$siteInfo['kitchen_id'];
|
|
$data = $this->goodCache->getMealGoodList();
|
|
|
|
if (empty($data)) return $this->return->success('success', ['list' => []]);
|
|
|
|
$stockKey = ApiRedisKey::goodStockKey((int)$cycleId,(int)$siteInfo['kitchen_id']);
|
|
foreach ($data as &$item) {
|
|
foreach ($item['sku_list'] as $skuKey => &$v) {
|
|
$v['surplus_stock'] = $this->redisCache->zScore($stockKey,$v['id']) ?? 0;
|
|
|
|
if ($v['is_add_staple_food'] == GoodCode::IS_ADD_STAPLE_FOOD) unset($item['sku_list'][$skuKey]);
|
|
}
|
|
}
|
|
|
|
return $this->return->success('success', ['list' => $data]);
|
|
}
|
|
} |