更新
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user