feat : rank

This commit is contained in:
2025-04-09 16:08:00 +08:00
parent ee0f550828
commit aac53d8264
2 changed files with 42 additions and 23 deletions

View File

@@ -13,8 +13,11 @@ 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;
@@ -22,6 +25,7 @@ use Psr\Container\NotFoundExceptionInterface;
class AddStapleFoodInfoService extends BaseService
{
use CycleTrait;
use OssTrait;
/**
* @var GoodCache
@@ -35,6 +39,18 @@ class AddStapleFoodInfoService extends BaseService
#[Inject]
protected SiteCache $siteCache;
/**
* @var Sku
*/
#[Inject]
protected Sku $skuModel;
/**
* @var Spu
*/
#[Inject]
protected Spu $spuModel;
/**
* @return array
* @throws ContainerExceptionInterface
@@ -50,31 +66,18 @@ class AddStapleFoodInfoService extends BaseService
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();
$cycleId = (int)$cycleId;
$kitchenId = (int)$siteInfo['kitchen_id'];
$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']);
$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' => []]);
$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;
}
$res = $skuInfo->toArray();
$res['url'] = $this->getOssObjectById($res['image_ids']);
return $this->return->success('success', ['add_food_info' => $res]);
}