feat : rank
This commit is contained in:
@@ -96,6 +96,22 @@ class Sku extends Model
|
|||||||
->get();
|
->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
|
* @param int $spuId
|
||||||
* @return Collection
|
* @return Collection
|
||||||
|
|||||||
@@ -13,8 +13,11 @@ namespace App\Service\Api\Good;
|
|||||||
use App\Cache\Redis\Api\GoodCache;
|
use App\Cache\Redis\Api\GoodCache;
|
||||||
use App\Cache\Redis\Api\SiteCache;
|
use App\Cache\Redis\Api\SiteCache;
|
||||||
use App\Constants\Common\GoodCode;
|
use App\Constants\Common\GoodCode;
|
||||||
|
use App\Model\Sku;
|
||||||
|
use App\Model\Spu;
|
||||||
use App\Service\Api\BaseService;
|
use App\Service\Api\BaseService;
|
||||||
use App\Service\ServiceTrait\Common\CycleTrait;
|
use App\Service\ServiceTrait\Common\CycleTrait;
|
||||||
|
use App\Service\ServiceTrait\Common\OssTrait;
|
||||||
use Hyperf\Di\Annotation\Inject;
|
use Hyperf\Di\Annotation\Inject;
|
||||||
use Psr\Container\ContainerExceptionInterface;
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
use Psr\Container\NotFoundExceptionInterface;
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
@@ -22,6 +25,7 @@ use Psr\Container\NotFoundExceptionInterface;
|
|||||||
class AddStapleFoodInfoService extends BaseService
|
class AddStapleFoodInfoService extends BaseService
|
||||||
{
|
{
|
||||||
use CycleTrait;
|
use CycleTrait;
|
||||||
|
use OssTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var GoodCache
|
* @var GoodCache
|
||||||
@@ -35,6 +39,18 @@ class AddStapleFoodInfoService extends BaseService
|
|||||||
#[Inject]
|
#[Inject]
|
||||||
protected SiteCache $siteCache;
|
protected SiteCache $siteCache;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Sku
|
||||||
|
*/
|
||||||
|
#[Inject]
|
||||||
|
protected Sku $skuModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Spu
|
||||||
|
*/
|
||||||
|
#[Inject]
|
||||||
|
protected Spu $spuModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
* @throws ContainerExceptionInterface
|
* @throws ContainerExceptionInterface
|
||||||
@@ -50,31 +66,18 @@ class AddStapleFoodInfoService extends BaseService
|
|||||||
|
|
||||||
if (empty($siteInfo) || empty($siteInfo['kitchen_id'])) return $this->return->success('success', ['list' => []]);
|
if (empty($siteInfo) || empty($siteInfo['kitchen_id'])) return $this->return->success('success', ['list' => []]);
|
||||||
|
|
||||||
$this->goodCache->cycleId = (int)$cycleId;
|
$cycleId = (int)$cycleId;
|
||||||
$this->goodCache->kitchenId = (int)$siteInfo['kitchen_id'];
|
$kitchenId = (int)$siteInfo['kitchen_id'];
|
||||||
$data = $this->goodCache->getMealGoodList();
|
|
||||||
|
|
||||||
$skuArr = [];
|
$spuInfo = $this->spuModel->getListByCycleIdAndType($cycleId, $kitchenId,GoodCode::SPU_TYPE_MEAL);
|
||||||
foreach ($data as $one){
|
if (empty($spuInfo)) return $this->return->success('success', ['add_food_info' => []]);
|
||||||
$newSkuList = array_map(function($sku) use($one) {
|
$spuIds = array_column($spuInfo->toArray(), 'spu_id');
|
||||||
$sku['spu_title'] = strtolower($one['title']);
|
// $data = $this->goodCache->getMealGoodList();
|
||||||
$sku['type'] = GoodCode::SPU_TYPE_OPTIONAL;
|
$skuInfo = $this->skuModel->getAddStapleFoodListBySpuIds($spuIds);
|
||||||
return $sku;
|
if (empty($skuInfo)) return $this->return->success('success', ['add_food_info' => []]);
|
||||||
}, $one['sku_list']);
|
|
||||||
|
|
||||||
$skuArr = array_merge($skuArr,$newSkuList);
|
$res = $skuInfo->toArray();
|
||||||
}
|
$res['url'] = $this->getOssObjectById($res['image_ids']);
|
||||||
|
|
||||||
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]);
|
return $this->return->success('success', ['add_food_info' => $res]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user