no message

This commit is contained in:
hellcat 2026-07-28 21:06:02 +08:00
parent 08763435f3
commit f571bf9392
3 changed files with 16 additions and 7 deletions

View File

@ -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 "<pre>";var_dump($oArticle->aOpt["thumb_use"]);
echo "<pre>";var_dump($oArticle->aOpt["thumb_use"]); // 是11
// 2. 拼文件名
$aThumbUse = $oArticle->aOpt["thumb_use"] ?? ["b"];
$sThumbUse = $aThumbUse[array_rand($aThumbUse)];

View File

@ -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();

View File

@ -16,7 +16,7 @@ protected function casts(): array
'aOpt' => 'array',
'aSchemaPro' => 'array',
];
}// 我希望查询的时候忽略这个设置
}// 这样设置了为什么查出来的aOpt却是字符串格式
protected static function booted(): void
{