feat : rank
This commit is contained in:
@@ -96,6 +96,22 @@ class Sku extends Model
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $spuIds
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAddStapleFoodListBySpuIds(array $spuIds): Collection
|
||||
{
|
||||
return $this
|
||||
->whereIn('spu_id',$spuIds)
|
||||
->where('is_del',GoodCode::SKU_IS_NO_DEL)
|
||||
->where('saleable',GoodCode::LISTING)
|
||||
->where('is_add_staple_food',GoodCode::IS_ADD_STAPLE_FOOD)
|
||||
->orderBy('sort')
|
||||
->select(['id','spu_id','title','image_ids','price','param','extra','total_stock','surplus_stock','order_num','is_add_staple_food','occupied','chef_id'])
|
||||
->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $spuId
|
||||
* @return Collection
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user