Compare commits

...

4 Commits

Author SHA1 Message Date
bbcc0d054f feat : spu 2025-07-24 10:34:26 +08:00
0a1610fc42 feat : sku 2025-07-24 10:09:25 +08:00
a296a30080 feat : kitchen 2025-07-24 10:00:20 +08:00
4d0e3907b2 feat : spu 2025-07-24 09:49:00 +08:00
6 changed files with 34 additions and 11 deletions

View File

@@ -168,6 +168,7 @@ class GoodCache
private function buildData(&$list): mixed
{
$spuIds = array_column($list, 'id');
$spuImage = array_column($list, 'image_id');
$skuList = $this->skuModel->getListBySpuIds($spuIds);
@@ -176,7 +177,7 @@ class GoodCache
$skuList = $skuList->toArray();
$imageIdArr = array_column($skuList,'image_ids');
$imageList = $this->getOssObjects($imageIdArr);
$imageList = $this->getOssObjects(array_merge($spuImage,$imageIdArr));
$chefIds = array_column($skuList,'chef_id');
$chefList = $this->adminUserModel->getDataByIds($chefIds);
@@ -209,6 +210,7 @@ class GoodCache
foreach ($list as &$item) {
$item['sku_list'] = $skuListArr[$item['id']] ?? [];
$item['spu_image_url'] = $imageList[$item['image_id']] ?? '';
$item['image_list'] = $imageArr[$item['id']] ?? [];
$item['price'] = !empty($price[$item['id']]) ? (min($price[$item['id']]) ?? 0) : 0;
}

View File

@@ -97,17 +97,17 @@ class SiteCache
/**
* @param int $siteId
* @return array|false|\Redis|null
* @return array|false|\Redis
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function getSiteInfo(int $siteId): false|array|\Redis|null
public function getSiteInfo(int $siteId): false|array|\Redis
{
$siteKey = CommonRedisKey::siteInfoKey($siteId);
if (!$this->redis->exists($siteKey,RedisCode::SYSTEM_DB)) $this->setSiteInfo($siteId);
return $this->redis->hGetAll($siteKey,RedisCode::SYSTEM_DB) ?? null;
return $this->redis->hGetAll($siteKey,RedisCode::SYSTEM_DB) ?? false;
}
/**

View File

@@ -96,7 +96,7 @@ class Sku extends Model
->where('saleable',GoodCode::LISTING)
// ->where('is_add_staple_food',GoodCode::IS_NOT_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','origin_sku_id'])
->select(['id','spu_id','title','image_ids','price','param','extra','total_stock','surplus_stock','order_num','is_add_staple_food','occupied','chef_id','origin_sku_id','sub_title'])
->get();
}

View File

@@ -17,6 +17,7 @@ use Hyperf\DbConnection\Model\Model;
* @property int $kitchen_id
* @property int $chef_id
* @property int $caterer_id
* @property int $image_id
* @property string $title
* @property string $sub_title
* @property int $category_id
@@ -85,7 +86,7 @@ class Spu extends Model
->where('type',$type)
->where('saleable',GoodCode::LISTING)
->orderBy('sort')
->select(['id','cycle_id','chef_id','title','title','sub_title','category_id','favorable'])
->select(['id','cycle_id','chef_id','title','title','sub_title','category_id','favorable','image_id'])
->get();
}

View File

@@ -156,6 +156,9 @@ class SpuService extends BaseService
if (!empty($info)) throw new ErrException('该菜品在当前城市已存在');
$imageId = $this->request->input('image_id');
$this->updateOssObjects([$imageId]);
$insertModel = new Spu();
@@ -170,6 +173,7 @@ class SpuService extends BaseService
$insertModel->saleable = $this->request->input('saleable');
$insertModel->type = $this->request->input('type');
$insertModel->sort = $this->request->input('sort');
$insertModel->image_id = $imageId;
$insertModel->favorable = GoodCode::NOT_FAVORABLE;
if (!$insertModel->save()) throw new ErrException('添加菜品失败');
@@ -233,6 +237,8 @@ class SpuService extends BaseService
$this->checkInfo();
$kitchenId = (int)$this->request->input('kitchen_id');
$oldKitchenId = (int)$info->kitchen_id;
@@ -245,6 +251,12 @@ class SpuService extends BaseService
$info->saleable = $this->request->input('saleable');
$info->type = $this->request->input('type');
$info->sort = $this->request->input('sort');
$requestOssId = $this->request->input('image_id',0);
if ($requestOssId != $info->image_id) {
$info->image_id = $requestOssId;
$this->updateOssObjects([$requestOssId]);
$this->updateOssObjectsDisable([$info->image_ids]);
}
if (!$info->save()) throw new ErrException('修改菜品失败');
@@ -311,6 +323,7 @@ class SpuService extends BaseService
$info['city_name'] = $this->systemCityModel->getCityNameById((int)$info['city_id']);
$info['kitchen_name'] = $this->kitchenModel->getNameById((int)$info['kitchen_id']);
// $info['chef_name'] = $this->chefModel->getChineseNameById((int)$info['chef_id']);
$info['image_url'] = $this->getOssObjectById((int)$info['image_id']) ?? '';
$info['chef_name'] = '';
$info['category_name'] = $this->categoryModel->getNameById((int)$info['category_id']);

View File

@@ -55,6 +55,12 @@ class OptionalListService extends BaseService
#[Inject]
protected Category $categoryModel;
/**
* 默认地址
* @var array|false
*/
private array|false $siteInfo = [];
/**
* @return array
* @throws ContainerExceptionInterface
@@ -67,12 +73,13 @@ class OptionalListService extends BaseService
if (empty($cycleId)) return $this->return->success('success', ['list' => []]);
$this->goodCache->cycleId = (int)$cycleId;
if (!empty($this->request->input('site_id'))){
$siteInfo = $this->siteCache->getSiteInfo((int)$this->request->input('site_id'));
}
if (empty($siteInfo) || empty($siteInfo['kitchen_id'])) $siteInfo['kitchen_id'] = config('system.kitchen_id');
$this->goodCache->kitchenId = (int)$siteInfo['kitchen_id'];
if (!empty($this->request->input('site_id'))){
$this->siteInfo = $this->siteCache->getSiteInfo((int)$this->request->input('site_id'));
}
if (empty($this->siteInfo) || empty($this->siteInfo['kitchen_id'])) $this->siteInfo['kitchen_id'] = config('system.default_kitchen_id');
$this->goodCache->kitchenId = (int)$this->siteInfo['kitchen_id'];
$data = $this->goodCache->getOptionalGoodList();
if (empty($data)) return $this->return->success('success', ['list' => []]);