Files
zyt/server/app/common/service/qywx/QywxPromotionMediaStore.php
2026-08-31 15:17:34 +08:00

39 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace app\common\service\qywx;
use think\facade\Db;
/** 独立存储边界,测试可使用内存替身,禁止连接业务数据库。 */
class QywxPromotionMediaStore
{
public function find(string $assetId): ?array
{
return Db::name('qywx_promotion_media')->where('asset_id', $assetId)->find() ?: null;
}
public function insert(array $row): void
{
Db::name('qywx_promotion_media')->insert($row);
}
public function update(string $assetId, array $fields): void
{
Db::name('qywx_promotion_media')->where('asset_id', $assetId)->update($fields);
}
/** 只预热已保存方案引用的素材;未使用上传不永久续期。 */
public function referencedAssetIds(): array
{
$ids = [];
foreach (Db::name('qywx_promotion_config')->alias('cfg')
->join('qywx_promotion_pool pool', 'pool.id = cfg.pool_id')
->whereNull('pool.delete_time')->column('cfg.config_json') as $json) {
$ids = array_merge($ids, QywxPromotionMediaService::assetIds(QywxPromotionConfig::decode($json)));
}
return array_values(array_unique($ids));
}
}