feat : catering
This commit is contained in:
28
app/Cache/Redis/Admin/DriverCache.php
Normal file
28
app/Cache/Redis/Admin/DriverCache.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Cache\Redis\Admin;
|
||||
|
||||
use App\Cache\Redis\RedisCache;
|
||||
use App\Model\DriverSequence;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class DriverCache
|
||||
{
|
||||
/**
|
||||
* 注入 redis 方法
|
||||
* @var RedisCache $redis
|
||||
*/
|
||||
#[Inject]
|
||||
protected RedisCache $redis;
|
||||
|
||||
/**
|
||||
* @var DriverSequence
|
||||
*/
|
||||
#[Inject]
|
||||
protected DriverSequence $driverSequenceModel;
|
||||
|
||||
public function getDriverData()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -4,14 +4,18 @@ namespace App\Cache\Redis\Api;
|
||||
|
||||
use App\Cache\Redis\Common\CommonRedisKey;
|
||||
use App\Cache\Redis\RedisCache;
|
||||
use App\Constants\Common\SiteCode;
|
||||
use App\Constants\RedisCode;
|
||||
use App\Model\Site;
|
||||
use App\Service\ServiceTrait\Common\OssTrait;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class SiteCache
|
||||
{
|
||||
use OssTrait;
|
||||
|
||||
/**
|
||||
* @var RedisCache
|
||||
*/
|
||||
@@ -48,24 +52,111 @@ class SiteCache
|
||||
$this->redis->set($siteKey,json_encode(array_column($siteList, null, 'id'), JSON_UNESCAPED_UNICODE),RedisCode::SYSTEM_DB);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @param int $siteId
|
||||
// * @return array|null
|
||||
// * @throws ContainerExceptionInterface
|
||||
// * @throws NotFoundExceptionInterface
|
||||
// */
|
||||
// public function getSiteInfo(int $siteId): array|null
|
||||
// {
|
||||
// $this->setSiteRedis();
|
||||
//
|
||||
// $siteKey = CommonRedisKey::siteListKey();
|
||||
//
|
||||
// $siteListJsonDecode = json_decode($this->redis->get($siteKey,RedisCode::SYSTEM_DB), true);
|
||||
// if (empty($siteListJsonDecode)) return null;
|
||||
//
|
||||
// $siteList = array_column($siteListJsonDecode, null, 'id');
|
||||
//
|
||||
// unset($siteListJsonDecode);
|
||||
// return $siteList[$siteId] ?? null;
|
||||
// }
|
||||
|
||||
private function setSiteInfo(int $siteId): void
|
||||
{
|
||||
$siteKey = CommonRedisKey::siteInfoKey($siteId);
|
||||
|
||||
$info = $this->siteModel->getInfoById($siteId);
|
||||
|
||||
if (empty($info)) return;
|
||||
|
||||
if ($info->status == SiteCode::SITE_DISABLE || $info->is_del == SiteCode::SITE_DEL) return;
|
||||
|
||||
$this->redis->hMset($siteKey, [
|
||||
'id' => $info->id,
|
||||
'name' => $info->name,
|
||||
'kitchen_id' => $info->kitchen_id,
|
||||
'city_id' => $info->city_id,
|
||||
'address' => $info->address,
|
||||
'lng' => $info->lng,
|
||||
'lat' => $info->lat,
|
||||
'url' => $this->getOssObjectById($info->image_id)
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $siteId
|
||||
* @return array|null
|
||||
* @return array|false|\Redis|null
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function getSiteInfo(int $siteId): array|null
|
||||
public function getSiteInfo(int $siteId): false|array|\Redis|null
|
||||
{
|
||||
$this->setSiteRedis();
|
||||
$siteKey = CommonRedisKey::siteInfoKey($siteId);
|
||||
|
||||
$siteKey = CommonRedisKey::siteListKey();
|
||||
if (!$this->redis->exists($siteKey)) $this->setSiteInfo($siteId);
|
||||
|
||||
$siteListJsonDecode = json_decode($this->redis->get($siteKey,RedisCode::SYSTEM_DB), true);
|
||||
if (empty($siteListJsonDecode)) return null;
|
||||
|
||||
$siteList = array_column($siteListJsonDecode, null, 'id');
|
||||
|
||||
unset($siteListJsonDecode);
|
||||
return $siteList[$siteId] ?? null;
|
||||
return $this->redis->hGetAll($siteKey) ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $siteId
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
* @return bool|\Redis
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function updateSiteInfo(int $siteId,string $key,string $value)
|
||||
{
|
||||
$siteKey = CommonRedisKey::siteInfoKey($siteId);
|
||||
|
||||
if (!$this->redis->exists($siteKey)) $this->setSiteInfo($siteId);
|
||||
|
||||
return $this->redis->hMset($siteKey,[
|
||||
$key => $value
|
||||
]) ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $siteId
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function updateBatchValueInfo(int $siteId)
|
||||
{
|
||||
$siteKey = CommonRedisKey::siteInfoKey($siteId);
|
||||
|
||||
if ($this->redis->exists($siteKey)) $this->delSiteInfo($siteId);
|
||||
|
||||
$this->setSiteInfo($siteId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $siteId
|
||||
* @return bool|int
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function delSiteInfo(int $siteId)
|
||||
{
|
||||
$siteKey = CommonRedisKey::siteInfoKey($siteId);
|
||||
|
||||
if (!$this->redis->exists($siteKey)) return true;
|
||||
|
||||
return $this->redis->delete($siteKey);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -95,6 +95,15 @@ class CommonRedisKey
|
||||
return '__system:site:list';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $siteId
|
||||
* @return string
|
||||
*/
|
||||
public static function siteInfoKey(int $siteId): string
|
||||
{
|
||||
return '__system:site:info:id:'.$siteId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user