diff --git a/app/Cache/Redis/Admin/MenuCache.php b/app/Cache/Redis/Admin/MenuCache.php index 3f2a035..b94f4c6 100644 --- a/app/Cache/Redis/Admin/MenuCache.php +++ b/app/Cache/Redis/Admin/MenuCache.php @@ -3,6 +3,7 @@ namespace App\Cache\Redis\Admin; use App\Cache\Redis\RedisCache; +use App\Constants\RedisCode; use App\Model\AdminMenu; use App\Service\ServiceTrait\Admin\AdminRoleMenuTrait; use Hyperf\Di\Annotation\Inject; @@ -48,15 +49,15 @@ class MenuCache */ public function getMenu(): array { - if ($this->redis->exists($this->menuKey,'system')) { - return json_decode($this->redis->get($this->menuKey,'system'),true); + if ($this->redis->exists($this->menuKey,RedisCode::SYSTEM_DB)) { + return json_decode($this->redis->get($this->menuKey,RedisCode::SYSTEM_DB),true); } $allMenuList = $this->adminMenuModel->getAllMenu(); $data = $this->getDbMenu($allMenuList); - $this->redis->set($this->menuKey,json_encode($data),'system'); + $this->redis->set($this->menuKey,json_encode($data),RedisCode::SYSTEM_DB); return $data; } @@ -69,6 +70,6 @@ class MenuCache */ public function delMenu(): void { - $this->redis->delete($this->menuKey,'system'); + $this->redis->delete($this->menuKey,RedisCode::SYSTEM_DB); } } \ No newline at end of file diff --git a/app/Cache/Redis/Admin/RoleCache.php b/app/Cache/Redis/Admin/RoleCache.php index f5ad6d9..d9b7284 100644 --- a/app/Cache/Redis/Admin/RoleCache.php +++ b/app/Cache/Redis/Admin/RoleCache.php @@ -5,6 +5,7 @@ namespace App\Cache\Redis\Admin; use App\Cache\Redis\RedisCache; use App\Constants\Admin\AuthCode; use App\Constants\Common\RoleCode; +use App\Constants\RedisCode; use App\Model\AdminMenu; use App\Model\AdminRoleMenu; use App\Service\ServiceTrait\Admin\AdminRoleMenuTrait; @@ -75,10 +76,10 @@ class RoleCache $this->getKey(); - if ($this->redis->exists($this->roleMenuArrKey,'system') && $this->redis->exists($this->roleMenuListKey,'system')) { + if ($this->redis->exists($this->roleMenuArrKey,RedisCode::SYSTEM_DB) && $this->redis->exists($this->roleMenuListKey,RedisCode::SYSTEM_DB)) { return [ - 'role_arr' => $this->redis->sMembers($this->roleMenuArrKey,'system'), - 'role_list' => json_decode($this->redis->get($this->roleMenuListKey,'system'),true), + 'role_arr' => $this->redis->sMembers($this->roleMenuArrKey,RedisCode::SYSTEM_DB), + 'role_list' => json_decode($this->redis->get($this->roleMenuListKey,RedisCode::SYSTEM_DB),true), ]; } @@ -101,8 +102,8 @@ class RoleCache $this->delRoleCache(); - $this->redis->set($this->roleMenuListKey,json_encode($data),'system'); - $this->redis->sAddBatch($this->roleMenuArrKey,$menuIds,'system'); + $this->redis->set($this->roleMenuListKey,json_encode($data),RedisCode::SYSTEM_DB); + $this->redis->sAddBatch($this->roleMenuArrKey,$menuIds,RedisCode::SYSTEM_DB); return [ 'role_arr' => $menuIds, @@ -124,7 +125,7 @@ class RoleCache $this->getKey(); } - $this->redis->delete($this->roleMenuArrKey,'system'); - $this->redis->delete($this->roleMenuListKey,'system'); + $this->redis->delete($this->roleMenuArrKey,RedisCode::SYSTEM_DB); + $this->redis->delete($this->roleMenuListKey,RedisCode::SYSTEM_DB); } } \ No newline at end of file diff --git a/app/Cache/Redis/Admin/SectionCache.php b/app/Cache/Redis/Admin/SectionCache.php index fa7634f..d366248 100644 --- a/app/Cache/Redis/Admin/SectionCache.php +++ b/app/Cache/Redis/Admin/SectionCache.php @@ -3,6 +3,7 @@ namespace App\Cache\Redis\Admin; use App\Cache\Redis\RedisCache; +use App\Constants\RedisCode; use App\Model\AdminSection; use App\Service\ServiceTrait\Admin\SectionTrait; use Hyperf\Di\Annotation\Inject; @@ -49,15 +50,15 @@ class SectionCache */ public function getList(): array { - if ($this->redis->exists($this->key,'system')) { - return json_decode($this->redis->get($this->key,'system'),true); + if ($this->redis->exists($this->key,RedisCode::SYSTEM_DB)) { + return json_decode($this->redis->get($this->key,RedisCode::SYSTEM_DB),true); } $allList = $this->adminSectionModel->getList(); $data = $this->getDbList($allList); - $this->redis->set($this->key,json_encode($data),'system'); + $this->redis->set($this->key,json_encode($data),RedisCode::SYSTEM_DB); return $data; } @@ -70,6 +71,6 @@ class SectionCache */ public function delList() { - $this->redis->delete($this->key,'system'); + $this->redis->delete($this->key,RedisCode::SYSTEM_DB); } } \ No newline at end of file diff --git a/app/Cache/Redis/Admin/UserCache.php b/app/Cache/Redis/Admin/UserCache.php index 1726c9b..a3714df 100644 --- a/app/Cache/Redis/Admin/UserCache.php +++ b/app/Cache/Redis/Admin/UserCache.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace App\Cache\Redis\Admin; use App\Cache\Redis\RedisCache; +use App\Constants\RedisCode; use Hyperf\Di\Annotation\Inject; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; @@ -26,7 +27,7 @@ class UserCache */ public function getAdminToken($userId): false|string { - return $this->redis->get(AdminRedisKey::adminUserToken($userId),'system') ?? false; + return $this->redis->get(AdminRedisKey::adminUserToken($userId),RedisCode::SYSTEM_DB) ?? false; } /** @@ -41,7 +42,7 @@ class UserCache public function setAdminToken($userId, string $token, int $ttl): bool { $key = AdminRedisKey::adminUserToken($userId); - $this->redis->delete($key,'system'); - return $this->redis->setEx($key, $token, $ttl, 'system'); + $this->redis->delete($key,RedisCode::SYSTEM_DB); + return $this->redis->setEx($key, $token, $ttl, RedisCode::SYSTEM_DB); } } \ No newline at end of file diff --git a/app/Cache/Redis/Common/CityCache.php b/app/Cache/Redis/Common/CityCache.php index f326c81..5ec03c9 100644 --- a/app/Cache/Redis/Common/CityCache.php +++ b/app/Cache/Redis/Common/CityCache.php @@ -3,6 +3,7 @@ namespace App\Cache\Redis\Common; use App\Cache\Redis\RedisCache; +use App\Constants\RedisCode; use App\Model\SystemCityConfig; use Hyperf\Di\Annotation\Inject; use Psr\Container\ContainerExceptionInterface; @@ -41,7 +42,7 @@ class CityCache $key = CommonRedisKey::getSystemRegionList($type); - if ($this->redis->exists($key)) return json_decode($this->redis->get($key), true); + if ($this->redis->exists($key,RedisCode::SYSTEM_DB)) return json_decode($this->redis->get($key,RedisCode::SYSTEM_DB), true); if ($type == 'all') { $data = $this->systemCityConfigModel->getAll(); @@ -49,7 +50,7 @@ class CityCache $data = $this->systemCityConfigModel->getListByDeep($deep); } - $this->redis->set($key, json_encode($data)); + $this->redis->set($key, json_encode($data),RedisCode::SYSTEM_DB); return $data; } diff --git a/app/Cache/Redis/Common/CommonRedisKey.php b/app/Cache/Redis/Common/CommonRedisKey.php index f0323a4..9f6ac32 100644 --- a/app/Cache/Redis/Common/CommonRedisKey.php +++ b/app/Cache/Redis/Common/CommonRedisKey.php @@ -9,11 +9,30 @@ class CommonRedisKey * @param $pid * @return string */ - public static function getSystemConfigList($pid): string + public static function getSystemConfigListByPid($pid): string { return '__system:config:list:' . $pid; } + /** + * 获取配置项所有 + * @return string + */ + public static function getSystemConfigList(): string + { + return '__system:config:list'; + } + + /** + * 获取配置项缓存key + * @param $name + * @return string + */ + public static function getConfigKey($name): string + { + return '__system:config:' . $name; + } + /** * 获取系统配置 * @return string diff --git a/app/Cache/Redis/Common/ConfigCache.php b/app/Cache/Redis/Common/ConfigCache.php index 86e2ac9..1dc77b6 100644 --- a/app/Cache/Redis/Common/ConfigCache.php +++ b/app/Cache/Redis/Common/ConfigCache.php @@ -3,12 +3,18 @@ namespace App\Cache\Redis\Common; use App\Cache\Redis\RedisCache; +use App\Constants\ConfigCode; +use App\Constants\RedisCode; use App\Model\Config; use App\Model\Cycle; use Hyperf\Di\Annotation\Inject; +use Hyperf\Tappable\HigherOrderTapProxy; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; class ConfigCache { + /** * @var RedisCache */ @@ -21,11 +27,78 @@ class ConfigCache #[Inject] protected Config $configModel; - public function setConfigCacheByPid($pid) + /** + * @param $pid + * @return array|mixed + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + private function setConfigCacheByPid($pid): mixed { - $key = CommonRedisKey::getSystemConfigList($pid); - if ($this->redis->exists($key,'system')) return json_decode($this->redis->get($key),true); + $key = CommonRedisKey::getSystemConfigListByPid($pid); + if ($this->redis->exists($key,RedisCode::SYSTEM_DB)) return json_decode($this->redis->get($key,RedisCode::SYSTEM_DB),true); - return []; + $data = $this->configModel->where('pid', $pid)->pluck('value','key')->toArray(); + + if (empty($data)) return []; + + $this->redis->set($key,json_encode($data),RedisCode::SYSTEM_DB); + + return $data; + } + + /** + * @param $key + * @return mixed|string + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + public function getConfigValue($key): mixed + { + $arr = $this->setConfigCache(); + + return $arr[$key] ?? ''; + } + + /** + * @param $key + * @param int $isRedis + * @param int $expire + * @return false|HigherOrderTapProxy|mixed|\Redis|string|null + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + public function getConfigValueByKey($key, int $isRedis = 0,int $expire = 600): mixed + { + $redisKey = CommonRedisKey::getConfigKey($key); + + if (!$this->redis->exists($redisKey,RedisCode::SYSTEM_DB)) { + $value = $this->configModel->where('key',$key)->value('value'); + if ($isRedis == 1) { + $this->redis->setEx($redisKey, $value, $expire,RedisCode::SYSTEM_DB); + } + return $value; + } + + return $this->redis->get($key,RedisCode::SYSTEM_DB) ?? ConfigCode::DEFAULT_VALUE[$key]; + } + + /** + * @return array|mixed + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + private function setConfigCache(): mixed + { + $key = CommonRedisKey::getSystemConfigList(); + if ($this->redis->exists($key,RedisCode::SYSTEM_DB)) return json_decode($this->redis->get($key,RedisCode::SYSTEM_DB),true); + + $data = $this->configModel->pluck('value','key')->toArray(); + + if (empty($data)) return []; + + $this->redis->set($key,json_encode($data),RedisCode::SYSTEM_DB); + + return $data; } } \ No newline at end of file diff --git a/app/Cache/Redis/Common/CycleCache.php b/app/Cache/Redis/Common/CycleCache.php index 2485ec7..5d34178 100644 --- a/app/Cache/Redis/Common/CycleCache.php +++ b/app/Cache/Redis/Common/CycleCache.php @@ -3,6 +3,7 @@ namespace App\Cache\Redis\Common; use App\Cache\Redis\RedisCache; +use App\Constants\RedisCode; use App\Model\Cycle; use Hyperf\Di\Annotation\Inject; use Psr\Container\ContainerExceptionInterface; @@ -10,6 +11,7 @@ use Psr\Container\NotFoundExceptionInterface; class CycleCache { + /** * @var RedisCache */ @@ -31,7 +33,7 @@ class CycleCache { $key = CommonRedisKey::getCycleList(); - if ($this->redis->exists($key,'system')) return; + if ($this->redis->exists($key,RedisCode::SYSTEM_DB)) return; $allData = $this->cycleModel->get(); @@ -40,7 +42,12 @@ class CycleCache $allData = $allData->toArray(); foreach ($allData as $item) { - $this->redis->zAdd($key, $item['id'],$item['dates'],'system'); + $this->redis->zAdd($key, $item['id'],$item['dates'],RedisCode::SYSTEM_DB); } } + +// public function getCycleCache(string $key) +// { +// $this->redis->zScore() +// } } \ No newline at end of file diff --git a/app/Cache/Redis/RedisCache.php b/app/Cache/Redis/RedisCache.php index f73ee4d..dd80578 100644 --- a/app/Cache/Redis/RedisCache.php +++ b/app/Cache/Redis/RedisCache.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace App\Cache\Redis; +use App\Constants\RedisCode; use Hyperf\Context\ApplicationContext; use Hyperf\Redis\RedisFactory; use Hyperf\Redis\RedisProxy; @@ -21,7 +22,7 @@ class RedisCache * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ - private function getRedis(string $poolName = 'default'): RedisProxy + private function getRedis(string $poolName = RedisCode::DEFAULT_DB): RedisProxy { return ApplicationContext::getContainer()->get(RedisFactory::class)->get($poolName); } @@ -40,7 +41,7 @@ class RedisCache * @throws NotFoundExceptionInterface * @throws RedisException */ - public function eval(string $script, array $array, int $num = 1, string $poolName = 'default'): mixed + public function eval(string $script, array $array, int $num = 1, string $poolName = RedisCode::DEFAULT_DB): mixed { return $this->getRedis($poolName)->eval($script, $array, $num); } @@ -55,7 +56,7 @@ class RedisCache * @throws NotFoundExceptionInterface * @throws RedisException */ - public function addLock(string $key, int $ttl = 5, string $poolName = 'lock'): int + public function addLock(string $key, int $ttl = 5, string $poolName = RedisCode::LOCK_DB): int { $script = <<delete($key, $poolName); } @@ -90,7 +91,7 @@ class RedisCache * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ - public function multi(string $poolName = 'default'): bool|Redis + public function multi(string $poolName = RedisCode::DEFAULT_DB): bool|Redis { return $this->getRedis($poolName)->multi(); } @@ -102,7 +103,7 @@ class RedisCache * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ - public function exec(string$poolName = 'default'): Redis|array|false + public function exec(string$poolName = RedisCode::DEFAULT_DB): Redis|array|false { return $this->getRedis($poolName)->exec(); } @@ -119,7 +120,7 @@ class RedisCache * @throws NotFoundExceptionInterface * @throws RedisException */ - public function exists(string $key, string $poolName = 'default'): int|bool + public function exists(string $key, string $poolName = RedisCode::DEFAULT_DB): int|bool { return $this->getRedis($poolName)->exists($key); } @@ -133,7 +134,7 @@ class RedisCache * @throws NotFoundExceptionInterface * @throws RedisException */ - public function delete(string $key, string $poolName = 'default'): int|bool + public function delete(string $key, string $poolName = RedisCode::DEFAULT_DB): int|bool { return $this->getRedis($poolName)->del($key); } @@ -147,7 +148,7 @@ class RedisCache * @throws NotFoundExceptionInterface * @throws RedisException */ - public function expire(string $key, int $ex, string $poolName = 'default'): bool + public function expire(string $key, int $ex, string $poolName = RedisCode::DEFAULT_DB): bool { return $this->getRedis($poolName)->expire($key, $ex); } @@ -161,7 +162,7 @@ class RedisCache * @throws NotFoundExceptionInterface * @throws RedisException */ - public function ttl(string $key, string $poolName = 'default') + public function ttl(string $key, string $poolName = RedisCode::DEFAULT_DB) { return $this->getRedis($poolName)->ttl($key); } @@ -180,7 +181,7 @@ class RedisCache * @throws NotFoundExceptionInterface * @throws RedisException */ - public function set(string $key, string $value, string $poolName = 'default'): bool + public function set(string $key, string $value, string $poolName = RedisCode::DEFAULT_DB): bool { return $this->getRedis($poolName)->set($key, $value); } @@ -194,7 +195,7 @@ class RedisCache * @throws NotFoundExceptionInterface * @throws RedisException */ - public function get(string $key, string $poolName = 'default'): mixed + public function get(string $key, string $poolName = RedisCode::DEFAULT_DB): mixed { return $this->getRedis($poolName)->get($key); } @@ -210,7 +211,7 @@ class RedisCache * @throws NotFoundExceptionInterface * @throws RedisException */ - public function setEx(string $key, string $value, int $ttl, string $poolName = 'default'): Redis|bool + public function setEx(string $key, string $value, int $ttl, string $poolName = RedisCode::DEFAULT_DB): Redis|bool { return $this->getRedis($poolName)->setex($key, $ttl, $value); @@ -227,7 +228,7 @@ class RedisCache * @throws NotFoundExceptionInterface * @throws RedisException */ - public function incr($key, string $poolName = 'default') + public function incr($key, string $poolName = RedisCode::DEFAULT_DB) { return $this->getRedis($poolName)->incr($key); } @@ -247,7 +248,7 @@ class RedisCache * @throws NotFoundExceptionInterface * @throws RedisException */ - public function sIsMember($key, $value, string $poolName = 'default') + public function sIsMember($key, $value, string $poolName = RedisCode::DEFAULT_DB) { return $this->getRedis($poolName)->sIsMember($key, $value); } @@ -262,7 +263,7 @@ class RedisCache * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ - public function sAdd($key, $value, string $poolName = 'default') + public function sAdd($key, $value, string $poolName = RedisCode::DEFAULT_DB) { return $this->getRedis($poolName)->sAdd($key, $value); } @@ -276,7 +277,7 @@ class RedisCache * @throws NotFoundExceptionInterface * @throws RedisException */ - public function sMembers($key, string $poolName = 'default') + public function sMembers($key, string $poolName = RedisCode::DEFAULT_DB) { return $this->getRedis($poolName)->sMembers($key); } @@ -290,7 +291,7 @@ class RedisCache * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ - public function sRem($key, $value, string $poolName = 'default') + public function sRem($key, $value, string $poolName = RedisCode::DEFAULT_DB) { return $this->getRedis($poolName)->sRem($key, $value); } @@ -305,7 +306,7 @@ class RedisCache * @throws NotFoundExceptionInterface * @throws RedisException */ - public function sAddBatch($key, array $values, string $poolName = 'default') + public function sAddBatch($key, array $values, string $poolName = RedisCode::DEFAULT_DB) { return $this->getRedis($poolName)->sAddArray($key, $values); } @@ -324,7 +325,7 @@ class RedisCache * @throws NotFoundExceptionInterface * @throws RedisException */ - public function hMset($key, $hashKeys, $expire = null, string $poolName = 'default') + public function hMset($key, $hashKeys, $expire = null, string $poolName = RedisCode::DEFAULT_DB) { $result = $this->getRedis($poolName)->hMset($key, $hashKeys); if ($expire) { @@ -342,7 +343,7 @@ class RedisCache * @throws NotFoundExceptionInterface * @throws RedisException */ - public function hGetAll($key, string $poolName = 'default') + public function hGetAll($key, string $poolName = RedisCode::DEFAULT_DB) { return $this->getRedis($poolName)->hGetAll($key); } @@ -359,7 +360,7 @@ class RedisCache * @throws NotFoundExceptionInterface * @throws RedisException */ - public function hSet($key, $hashKey, $hashValue, int $expire = 0, string $poolName = 'default') + public function hSet($key, $hashKey, $hashValue, int $expire = 0, string $poolName = RedisCode::DEFAULT_DB) { $result = $this->getRedis($poolName)->hSet($key, $hashKey, $hashValue); if ($expire) { @@ -378,7 +379,7 @@ class RedisCache * @throws NotFoundExceptionInterface * @throws RedisException */ - public function hGet($key, $hashKey, string $poolName = 'default') + public function hGet($key, $hashKey, string $poolName = RedisCode::DEFAULT_DB) { return $this->getRedis($poolName)->hGet($key, $hashKey); } @@ -393,7 +394,7 @@ class RedisCache * @throws NotFoundExceptionInterface * @throws RedisException */ - public function hDel($key, $hashKey, string $poolName = 'default') + public function hDel($key, $hashKey, string $poolName = RedisCode::DEFAULT_DB) { return $this->getRedis($poolName)->hDel($key, $hashKey); } @@ -408,7 +409,7 @@ class RedisCache * @throws NotFoundExceptionInterface * @throws RedisException */ - public function hExists($key, $hashKey, string $poolName = 'default') + public function hExists($key, $hashKey, string $poolName = RedisCode::DEFAULT_DB) { return $this->getRedis($poolName)->hExists($key, $hashKey); } @@ -425,7 +426,7 @@ class RedisCache * @throws NotFoundExceptionInterface * @throws RedisException */ - public function HIncrBy($key, $hashKey, $hashValue, string $poolName = 'default') + public function HIncrBy($key, $hashKey, $hashValue, string $poolName = RedisCode::DEFAULT_DB) { return $this->getRedis($poolName)->hincrby($key, $hashKey, $hashValue); } @@ -444,7 +445,7 @@ class RedisCache * @throws NotFoundExceptionInterface * @throws RedisException */ - public function lPush(string $key, string $data, string $poolName = 'default'): false|int|Redis + public function lPush(string $key, string $data, string $poolName = RedisCode::DEFAULT_DB): false|int|Redis { return $this->getRedis($poolName)->lPush($key, $data); } @@ -458,7 +459,7 @@ class RedisCache * @throws NotFoundExceptionInterface * @throws RedisException */ - public function rPop($key, string $poolName = 'default') + public function rPop($key, string $poolName = RedisCode::DEFAULT_DB) { return $this->getRedis($poolName)->rPop($key); } @@ -471,7 +472,7 @@ class RedisCache * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ - public function lPushBatch($data, string $poolName = 'default') + public function lPushBatch($data, string $poolName = RedisCode::DEFAULT_DB) { $result = $this->getRedis($poolName); call_user_func_array([$result, 'lPush'], $data); @@ -487,7 +488,7 @@ class RedisCache * @throws NotFoundExceptionInterface * @throws RedisException */ - public function lLen($key, string $poolName = 'default') + public function lLen($key, string $poolName = RedisCode::DEFAULT_DB) { return $this->getRedis($poolName)->lLen($key); } @@ -506,7 +507,7 @@ class RedisCache * @throws NotFoundExceptionInterface * @throws RedisException */ - public function zScore($key, $value, string $poolName = 'default') + public function zScore($key, $value, string $poolName = RedisCode::DEFAULT_DB) { return $this->getRedis($poolName)->zScore($key, $value); } @@ -522,7 +523,7 @@ class RedisCache * @throws NotFoundExceptionInterface * @throws RedisException */ - public function zAdd($key, $score, $value, string $poolName = 'default'): false|int|Redis + public function zAdd($key, $score, $value, string $poolName = RedisCode::DEFAULT_DB): false|int|Redis { return $this->getRedis($poolName)->zAdd($key, $score, $value); } @@ -536,7 +537,7 @@ class RedisCache * @throws NotFoundExceptionInterface * @throws RedisException */ - public function zRem($key, $value, string $poolName = 'default'): false|int|Redis + public function zRem($key, $value, string $poolName = RedisCode::DEFAULT_DB): false|int|Redis { return $this->getRedis($poolName)->zRem($key, $value); } @@ -549,7 +550,7 @@ class RedisCache * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ - public function zRank($key, $value, string $poolName = 'default') + public function zRank($key, $value, string $poolName = RedisCode::DEFAULT_DB) { return $this->getRedis($poolName)->zRank($key, $value); } @@ -567,7 +568,7 @@ class RedisCache * @throws NotFoundExceptionInterface * @throws RedisException */ - public function geoAdd($key, $lng, $lat, $value, string $poolName = 'default'): false|int|Redis + public function geoAdd($key, $lng, $lat, $value, string $poolName = RedisCode::DEFAULT_DB): false|int|Redis { return $this->getRedis($poolName)->geoAdd($key, $lng, $lat, $value); } @@ -583,7 +584,7 @@ class RedisCache * @throws NotFoundExceptionInterface * @throws RedisException */ - public function geoDist($key, $value1, $value2, string $unit = 'km', string $poolName = 'default'): false|int|Redis + public function geoDist($key, $value1, $value2, string $unit = 'km', string $poolName = RedisCode::DEFAULT_DB): false|int|Redis { return $this->getRedis($poolName)->geoDist($key, $value1, $value2, $unit); } diff --git a/app/Constants/ConfigCode.php b/app/Constants/ConfigCode.php new file mode 100644 index 0000000..4a1c206 --- /dev/null +++ b/app/Constants/ConfigCode.php @@ -0,0 +1,12 @@ + '15:00:00' + ]; +} \ No newline at end of file diff --git a/app/Constants/RedisCode.php b/app/Constants/RedisCode.php new file mode 100644 index 0000000..b3c71e9 --- /dev/null +++ b/app/Constants/RedisCode.php @@ -0,0 +1,10 @@ +handle(); + } + + #[RequestMapping(path: 'meal',methods: 'post')] + public function meal() + { + return (new MealListService)->handle(); + } +} \ No newline at end of file diff --git a/app/Controller/Api/LoginController.php b/app/Controller/Api/LoginController.php index 4a1d997..e92010b 100644 --- a/app/Controller/Api/LoginController.php +++ b/app/Controller/Api/LoginController.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace App\Controller\Api; +use App\Controller\AbstractController; use App\Request\Api\LoginRequest; use App\Service\Api\Login\LoginService; use Hyperf\HttpServer\Annotation\Controller; @@ -11,7 +12,7 @@ use Hyperf\HttpServer\Annotation\RequestMapping; use Hyperf\Validation\Annotation\Scene; #[Controller(prefix: 'api/login')] -class LoginController +class LoginController extends AbstractController { #[RequestMapping(path: 'index',methods: 'post')] #[Scene(scene: 'login')] diff --git a/app/Controller/Api/UserController.php b/app/Controller/Api/UserController.php index 5018e50..9722ea3 100644 --- a/app/Controller/Api/UserController.php +++ b/app/Controller/Api/UserController.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace App\Controller\Api; +use App\Controller\AbstractController; use App\Middleware\Api\JwtAuthMiddleware; use App\Request\Api\UserRequest; use App\Service\Api\User\BindPhoneByWxService; @@ -18,7 +19,7 @@ use Psr\Container\NotFoundExceptionInterface; #[Middlewares([ JwtAuthMiddleware::class, ])] -class UserController +class UserController extends AbstractController { /** * @param UserRequest $request diff --git a/app/Cron/Good/CycleCreateTask.php b/app/Cron/Good/CycleCreateTask.php index 0f43722..2c97f83 100644 --- a/app/Cron/Good/CycleCreateTask.php +++ b/app/Cron/Good/CycleCreateTask.php @@ -13,6 +13,7 @@ namespace App\Cron\Good; use App\Cache\Redis\Common\CommonRedisKey; use App\Cache\Redis\Common\CycleCache; use App\Cache\Redis\RedisCache; +use App\Constants\RedisCode; use App\Extend\DateUtil; use App\Lib\Log; use App\Model\Cycle; @@ -72,7 +73,7 @@ class CycleCreateTask $noDataInsertArr = []; $noDataArr = []; foreach ($nextCycleRange as $date) { - $one = $this->redis->zScore($key,$date,'system'); + $one = $this->redis->zScore($key,$date,RedisCode::SYSTEM_DB); if ($one) continue; @@ -93,7 +94,7 @@ class CycleCreateTask $res = $res->toArray(); foreach ($res as $one) { - $this->redis->zAdd($key,$one['id'],$one['dates'],'system'); + $this->redis->zAdd($key,$one['id'],$one['dates'],RedisCode::SYSTEM_DB); } $this->log->notice('添加周期成功,添加的周期为'.json_encode($noDataArr,JSON_UNESCAPED_UNICODE)); diff --git a/app/Cron/Oss/OssDelByDisableTask.php b/app/Cron/Oss/OssDelByDisableTask.php index cc4888d..1b42d6a 100644 --- a/app/Cron/Oss/OssDelByDisableTask.php +++ b/app/Cron/Oss/OssDelByDisableTask.php @@ -12,6 +12,7 @@ namespace App\Cron\Oss; use App\Cache\Redis\Common\CommonRedisKey; use App\Cache\Redis\RedisCache; +use App\Constants\RedisCode; use App\Extend\DateUtil; use App\Lib\Log; use App\Model\OssObject; @@ -58,7 +59,7 @@ class OssDelByDisableTask foreach ($list->toArray() as $item) { - $this->redis->lPush(CommonRedisKey::getDeleteOssImgListByOssId(), (string)$item,'system'); + $this->redis->lPush(CommonRedisKey::getDeleteOssImgListByOssId(), (string)$item,RedisCode::SYSTEM_DB); } $this->log->notice(__CLASS__.'异步删除昨日无效图片'); diff --git a/app/Cron/Oss/OssDelByOssIdTask.php b/app/Cron/Oss/OssDelByOssIdTask.php index 0bd925c..62834d0 100644 --- a/app/Cron/Oss/OssDelByOssIdTask.php +++ b/app/Cron/Oss/OssDelByOssIdTask.php @@ -12,6 +12,7 @@ namespace App\Cron\Oss; use App\Cache\Redis\Common\CommonRedisKey; use App\Cache\Redis\RedisCache; +use App\Constants\RedisCode; use App\Lib\Log; use App\Model\OssObject; use Hyperf\Crontab\Annotation\Crontab; @@ -48,7 +49,7 @@ class OssDelByOssIdTask $ossIds = []; for ($i = 1; $i < 50; $i++) { - $one = $this->redis->rPop($key,'system'); + $one = $this->redis->rPop($key,RedisCode::SYSTEM_DB); if (empty($one)){ continue; } @@ -87,7 +88,7 @@ class OssDelByOssIdTask //把图片地址丢到删除redis队列 foreach ($urlList as $item) { $url = substr(parse_url($item)['path'],1); - $this->redis->lPush(CommonRedisKey::getDeleteOssImgListByUrl(), $url,'system'); + $this->redis->lPush(CommonRedisKey::getDeleteOssImgListByUrl(), $url,RedisCode::SYSTEM_DB); } $this->log->notice(__CLASS__.':success:删除oss文件个数:' . count($ossIds)); diff --git a/app/Cron/Oss/OssDelByUrlTask.php b/app/Cron/Oss/OssDelByUrlTask.php index 21f34d3..6c0ff3c 100644 --- a/app/Cron/Oss/OssDelByUrlTask.php +++ b/app/Cron/Oss/OssDelByUrlTask.php @@ -12,6 +12,7 @@ namespace App\Cron\Oss; use App\Cache\Redis\Common\CommonRedisKey; use App\Cache\Redis\RedisCache; +use App\Constants\RedisCode; use App\Lib\Log; use Hyperf\Crontab\Annotation\Crontab; use Hyperf\Di\Annotation\Inject; @@ -62,7 +63,7 @@ class OssDelByUrlTask $delNum = 0; for ($i = 1; $i < 50; $i++) { - $url = $this->redis->rPop($key,'system'); + $url = $this->redis->rPop($key,RedisCode::SYSTEM_DB); if (!empty($url)) { $delNum++; diff --git a/app/Service/Api/Good/MealListService.php b/app/Service/Api/Good/MealListService.php new file mode 100644 index 0000000..d7e4fd2 --- /dev/null +++ b/app/Service/Api/Good/MealListService.php @@ -0,0 +1,21 @@ +redisCache->lPush(CommonRedisKey::getDeleteOssImgListByUrl(), $this->data['object'],'system'); + $this->redisCache->lPush(CommonRedisKey::getDeleteOssImgListByUrl(), $this->data['object'],RedisCode::SYSTEM_DB); } } \ No newline at end of file diff --git a/app/Service/ServiceTrait/Api/WxMiniTrait.php b/app/Service/ServiceTrait/Api/WxMiniTrait.php index a5a6c9c..b345746 100644 --- a/app/Service/ServiceTrait/Api/WxMiniTrait.php +++ b/app/Service/ServiceTrait/Api/WxMiniTrait.php @@ -13,6 +13,7 @@ namespace App\Service\ServiceTrait\Api; use App\Cache\Redis\Api\ApiRedisKey; use App\Cache\Redis\Common\CommonRedisKey; use App\Cache\Redis\RedisCache; +use App\Constants\RedisCode; use App\Exception\ErrException; use App\Lib\Log; use GuzzleHttp\Exception\GuzzleException; @@ -75,7 +76,7 @@ trait WxMiniTrait if (empty($data) || empty($data['access_token']) || empty($data['expires_in'])) return ''; - $this->redisCache->setEx($key, $data['access_token'], $data['expires_in'] - 10,'system'); + $this->redisCache->setEx($key, $data['access_token'], $data['expires_in'] - 10,RedisCode::SYSTEM_DB); return $data['access_token']; } diff --git a/app/Service/ServiceTrait/Common/CycleTrait.php b/app/Service/ServiceTrait/Common/CycleTrait.php index a1fe75c..d5225df 100644 --- a/app/Service/ServiceTrait/Common/CycleTrait.php +++ b/app/Service/ServiceTrait/Common/CycleTrait.php @@ -2,7 +2,9 @@ namespace App\Service\ServiceTrait\Common; +use App\Cache\Redis\Common\ConfigCache; use App\Cache\Redis\Common\CycleCache; +use App\Constants\ConfigCode; use Hyperf\Di\Annotation\Inject; trait CycleTrait @@ -13,10 +15,22 @@ trait CycleTrait #[Inject] protected CycleCache $cycleCache; - + /** + * @var ConfigCache + */ + #[Inject] + protected ConfigCache $configCache; protected function initTodayCycleId() { + $TodayCutOffTime = $this->configCache->getConfigValueByKey(ConfigCode::TODAY_CUT_OFF_TIME_KEY); + + if (date('H:i:s') >= ($TodayCutOffTime)) { + $day = date('Y-m-d',strtotime('+1 day')); + } else { + $day = date('Y-m-d',strtotime('today')); + } + } } \ No newline at end of file diff --git a/app/Service/ServiceTrait/Common/SiteTrait.php b/app/Service/ServiceTrait/Common/SiteTrait.php index 3d3f8c4..3416207 100644 --- a/app/Service/ServiceTrait/Common/SiteTrait.php +++ b/app/Service/ServiceTrait/Common/SiteTrait.php @@ -12,6 +12,7 @@ namespace App\Service\ServiceTrait\Common; use App\Cache\Redis\Common\CommonRedisKey; use App\Cache\Redis\RedisCache; +use App\Constants\RedisCode; use Hyperf\Di\Annotation\Inject; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; @@ -36,7 +37,7 @@ trait SiteTrait public function setSiteCache($value, string $lng = '0', string $lat = '0'): void { $key = CommonRedisKey::getActivateSiteList(); - $this->redisCache->zRem($key,$value,'system'); - $this->redisCache->geoAdd($key,$lng,$lat,$value,'system'); + $this->redisCache->zRem($key,$value,RedisCode::SYSTEM_DB); + $this->redisCache->geoAdd($key,$lng,$lat,$value,RedisCode::SYSTEM_DB); } } \ No newline at end of file