diff --git a/app/Http/Controllers/Api/Images/GetController.php b/app/Http/Controllers/Api/Images/GetController.php index cbc1a98..215ef24 100644 --- a/app/Http/Controllers/Api/Images/GetController.php +++ b/app/Http/Controllers/Api/Images/GetController.php @@ -46,10 +46,7 @@ private function findValidUrlBySubKey($sSubKey, $iNum, $oFlow) $aAuthors = json_decode($sAuthors, true); $oQuery = ModelArticles::whereIn("sAuthorCode", $aAuthors)->orderBy("id", "asc"); -// $oQuery = ArticleKeyAuthorMap::where("key", $sSubKey)->first()?->authors; -// $oQuery = ModelArticles::where("sAuthorCode", $sAuthorCode)->orderBy("id", "asc"); -// $oQuery = ModelArticles::where("aOpt", "like", $sSubKey)->orderBy("id", "asc"); -// $oQuery = ModelArticles::where("aOpt", "like", '%'.$sSubKey.'%')->orderBy("id", "asc"); // 要这样吗 + $iTotal = $oQuery->count(); if ($iTotal === 0) throw new \Exception("subkey:{$sSubKey} 旗下无任何记录"); @@ -59,7 +56,7 @@ private function findValidUrlBySubKey($sSubKey, $iNum, $oFlow) $iTrueNum = $iOffset + 1; // 真正对应数据库的第几条 $oArticle = $oQuery->skip($iOffset)->first(); -echo "
";var_dump($oArticle->aOpt["thumb_use"]);
+echo "";var_dump($oArticle->aOpt["thumb_use"]); // 是11
// 2. 拼文件名
$aThumbUse = $oArticle->aOpt["thumb_use"] ?? ["b"];
$sThumbUse = $aThumbUse[array_rand($aThumbUse)];
diff --git a/app/Http/Controllers/Api/Nasa/V1/Base/ListController.php b/app/Http/Controllers/Api/Nasa/V1/Base/ListController.php
index 24325ad..ff0b4be 100755
--- a/app/Http/Controllers/Api/Nasa/V1/Base/ListController.php
+++ b/app/Http/Controllers/Api/Nasa/V1/Base/ListController.php
@@ -295,6 +295,8 @@ public function detailSave(Request $oRequest)
unset($aParams['id'], $aParams['_method']);
+ $aCasts = $oThisModel->getCasts();
+
foreach ($aParams as $k => &$v) {
if (empty($v) && empty($oThisModel->{$k})) {
continue;
@@ -302,12 +304,22 @@ public function detailSave(Request $oRequest)
if (empty($v) && $v !== 0 && $v !== '0') {
$v = '';
}
+
+ $sCastType = $aCasts[$k] ?? null;
+ if (in_array($sCastType, ['array', 'json', 'collection'], true) && is_string($v)) {
+ // 如果传入的是字符串,手动解码为数组,防止 Eloquent 在 save 时二次转义
+ $aDecoded = json_decode($v, true);
+// if (json_last_error() === JSON_ERROR_NONE && is_array($aDecoded)) {
+ $v = $aDecoded;
+// }
+ }
+
if ($oThisModel->{$k} != $v) {
$oThisModel->{$k} = $v;
}
}
- $oThisModel->save();
+ $oThisModel->save(); // 在这里保存的aOpt,如何避免被转译
$aChangeField = $oThisModel->getChanges();
diff --git a/app/Models/Articles.php b/app/Models/Articles.php
index c2a8402..4832a67 100755
--- a/app/Models/Articles.php
+++ b/app/Models/Articles.php
@@ -16,7 +16,7 @@ protected function casts(): array
'aOpt' => 'array',
'aSchemaPro' => 'array',
];
- }// 我希望查询的时候忽略这个设置
+ }// 这样设置了为什么查出来的aOpt却是字符串格式
protected static function booted(): void
{