Files
makemd/server/src/services/AdCreativeService.ts

45 lines
1.4 KiB
TypeScript
Raw Normal View History

import { logger } from '../utils/logger';
import db from '../config/database';
export interface CreativeRequest {
tenantId: string;
productId: string;
platform: 'FB' | 'TIKTOK' | 'IG';
style: 'PROFESSIONAL' | 'CASUAL' | 'URGENT';
}
/**
* [BIZ_MKT_04] AI 广 API
* @description AI 广
*/
export class AdCreativeService {
/**
* 广 (BIZ_MKT_04)
*/
static async generateCreative(req: CreativeRequest): Promise<any> {
logger.info(`[AdCreative] Generating ${req.platform} creative for Product: ${req.productId}`);
// 1. 获取商品基础信息
const product = await db('cf_product').where({ id: req.productId }).first();
if (!product) throw new Error('Product not found');
// 2. 模拟 AI 生成逻辑 (实际中应集成 LLM)
const adCopy = this.mockAiGen(product.title, req.platform, req.style);
return {
productId: req.productId,
platform: req.platform,
adCopy,
hook: "Don't miss out on this deal!",
cta: "Shop Now"
};
}
private static mockAiGen(title: string, platform: string, style: string): string {
if (platform === 'TIKTOK') {
return `🔥 Trending Now: ${title}! Get yours before it's gone! #viral #shop`;
}
return `Special Offer: High-quality ${title} available now. Free shipping on orders over $50.`;
}
}