|
|
@@ -149,6 +149,20 @@ class PetActiveSkill extends ModelCore
|
|
|
public function updateLastCheckTime(): bool
|
|
|
{
|
|
|
$config = $this->config;
|
|
|
+
|
|
|
+ // 确保config是数组类型
|
|
|
+ if (!is_array($config)) {
|
|
|
+ // 如果是字符串,尝试解析JSON
|
|
|
+ if (is_string($config)) {
|
|
|
+ $config = json_decode($config, true);
|
|
|
+ if (json_last_error() !== JSON_ERROR_NONE) {
|
|
|
+ $config = [];
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $config = [];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
$config['last_check_time'] = now()->toDateTimeString();
|
|
|
$this->config = $config;
|
|
|
return $this->save();
|
|
|
@@ -161,7 +175,21 @@ class PetActiveSkill extends ModelCore
|
|
|
*/
|
|
|
public function getLastCheckTime(): ?\Carbon\Carbon
|
|
|
{
|
|
|
- $lastCheckTime = $this->config['last_check_time'] ?? null;
|
|
|
+ $config = $this->config;
|
|
|
+
|
|
|
+ // 确保config是数组类型
|
|
|
+ if (!is_array($config)) {
|
|
|
+ if (is_string($config)) {
|
|
|
+ $config = json_decode($config, true);
|
|
|
+ if (json_last_error() !== JSON_ERROR_NONE) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $lastCheckTime = $config['last_check_time'] ?? null;
|
|
|
return $lastCheckTime ? \Carbon\Carbon::parse($lastCheckTime) : null;
|
|
|
}
|
|
|
|
|
|
@@ -181,7 +209,21 @@ class PetActiveSkill extends ModelCore
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- $checkInterval = $this->config['check_interval'] ?? 60; // 默认60秒
|
|
|
+ $config = $this->config;
|
|
|
+
|
|
|
+ // 确保config是数组类型
|
|
|
+ if (!is_array($config)) {
|
|
|
+ if (is_string($config)) {
|
|
|
+ $config = json_decode($config, true);
|
|
|
+ if (json_last_error() !== JSON_ERROR_NONE) {
|
|
|
+ $config = [];
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $config = [];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $checkInterval = $config['check_interval'] ?? 60; // 默认60秒
|
|
|
return now()->diffInSeconds($lastCheckTime) >= $checkInterval;
|
|
|
}
|
|
|
|
|
|
@@ -194,7 +236,21 @@ class PetActiveSkill extends ModelCore
|
|
|
*/
|
|
|
public function getConfigValue(string $key, $default = null)
|
|
|
{
|
|
|
- return $this->config[$key] ?? $default;
|
|
|
+ $config = $this->config;
|
|
|
+
|
|
|
+ // 确保config是数组类型
|
|
|
+ if (!is_array($config)) {
|
|
|
+ if (is_string($config)) {
|
|
|
+ $config = json_decode($config, true);
|
|
|
+ if (json_last_error() !== JSON_ERROR_NONE) {
|
|
|
+ return $default;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return $default;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $config[$key] ?? $default;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -207,6 +263,19 @@ class PetActiveSkill extends ModelCore
|
|
|
public function setConfigValue(string $key, $value): bool
|
|
|
{
|
|
|
$config = $this->config;
|
|
|
+
|
|
|
+ // 确保config是数组类型
|
|
|
+ if (!is_array($config)) {
|
|
|
+ if (is_string($config)) {
|
|
|
+ $config = json_decode($config, true);
|
|
|
+ if (json_last_error() !== JSON_ERROR_NONE) {
|
|
|
+ $config = [];
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $config = [];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
$config[$key] = $value;
|
|
|
$this->config = $config;
|
|
|
return $this->save();
|