81 lines
2.1 KiB
PHP
81 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\GoodCache;
|
|
use App\Cache\Redis\Api\SiteCache;
|
|
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 AddStapleFoodInfoService 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 $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();
|
|
|
|
$skuArr = [];
|
|
foreach ($data as $one){
|
|
$newSkuList = array_map(function($sku) use($one) {
|
|
$sku['spu_title'] = strtolower($one['title']);
|
|
$sku['type'] = GoodCode::SPU_TYPE_OPTIONAL;
|
|
return $sku;
|
|
}, $one['sku_list']);
|
|
|
|
$skuArr = array_merge($skuArr,$newSkuList);
|
|
}
|
|
|
|
if (empty($skuArr)) return $this->return->success('success', ['add_food_info' => []]);
|
|
|
|
$res = [];
|
|
foreach ($skuArr as $one){
|
|
if ($one['is_add_staple_food'] != GoodCode::IS_ADD_STAPLE_FOOD) continue;
|
|
|
|
$res[] = $one;
|
|
|
|
break;
|
|
}
|
|
|
|
return $this->return->success('success', ['add_food_info' => $res]);
|
|
}
|
|
} |