feat: spu

This commit is contained in:
2025-01-22 11:04:12 +08:00
parent 2beb8d9e55
commit 9b7390129d
10 changed files with 426 additions and 10 deletions

View File

@@ -71,6 +71,7 @@ class SpuService extends BaseService
->where('city_id',$cityId)
->where('kitchen_id',$kitchenId)
->where('is_del',GoodCode::SPU_IS_NO_DEL)
->where('type',$this->request->input('type'))
->paginate($limit)
->toArray();
@@ -152,6 +153,8 @@ class SpuService extends BaseService
$insertModel->sub_title = $this->request->input('sub_title','');
$insertModel->category_id = $this->request->input('category_id');
$insertModel->saleable = $this->request->input('saleable');
$insertModel->type = $this->request->input('type');
$insertModel->sort = $this->request->input('sort');
if (!$insertModel->save()) throw new ErrException('添加菜品失败');
@@ -214,6 +217,8 @@ class SpuService extends BaseService
$info->sub_title = $this->request->input('sub_title','');
$info->category_id = $this->request->input('category_id');
$info->saleable = $this->request->input('saleable');
$info->type = $this->request->input('type');
$info->sort = $this->request->input('sort');
if (!$info->save()) throw new ErrException('修改菜品失败');

View File

@@ -10,12 +10,38 @@ declare(strict_types=1);
namespace App\Service\Api\Good;
use App\Cache\Redis\Api\GoodCache;
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 OptionalListService extends BaseService
{
public function handle()
use CycleTrait;
/**
* @var GoodCache
*/
#[Inject]
protected GoodCache $goodCache;
/**
* @return array
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function handle(): array
{
//todo Write logic
$cycleId = $this->initTodayCycleId();
if (empty($cycleId)) return ['list' => []];
$this->goodCache->cycleId = (int)$cycleId;
$this->goodCache->kitchenId = (int)$this->request->input('kitchen_id');
$data = $this->goodCache->getOptionalGoodList();
return $this->return->success('success', ['list' => $data]);
}
}

View File

@@ -5,7 +5,12 @@ namespace App\Service\ServiceTrait\Common;
use App\Cache\Redis\Common\ConfigCache;
use App\Cache\Redis\Common\CycleCache;
use App\Constants\ConfigCode;
use App\Constants\RedisCode;
use App\Model\Cycle;
use Hyperf\Di\Annotation\Inject;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Redis;
trait CycleTrait
{
@@ -15,13 +20,24 @@ trait CycleTrait
#[Inject]
protected CycleCache $cycleCache;
/**
* @var Cycle
*/
#[Inject]
protected Cycle $cycleModel;
/**
* @var ConfigCache
*/
#[Inject]
protected ConfigCache $configCache;
protected function initTodayCycleId()
/**
* @return bool|float|Redis
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
protected function initTodayCycleId(): float|bool|Redis
{
$TodayCutOffTime = $this->configCache->getConfigValueByKey(ConfigCode::TODAY_CUT_OFF_TIME_KEY);
@@ -31,6 +47,9 @@ trait CycleTrait
$day = date('Y-m-d',strtotime('today'));
}
$cycleCacheId = $this->cycleCache->getCycleCache($day);
if (!empty($cycleCacheId)) return $cycleCacheId;
return $this->cycleModel->getIdByDate($day);
}
}