如何根据几天的时间实施广告投放

我正在研究一个项目的复杂功能。该功能是在特定日期的一天中的特定时间最准时地显示广告。假设我的数据库中有 20 个广告,其中 4 个要在 14 天内每天显示 1 小时。6 个每天显示 3 小时,持续 24 天。10 个每天显示 6 小时,持续 30 天。


由于管理员是为其创建计划的人,因此我有一个表来处理此列:


广告计划:


 $table->string('ad_type');

 $table->string('duration');

 $table->string('display_time');

 $table->string('amount');

现在每个 ad_placement 都属于上面的一个计划,所以我在 ad_placements 表中有这个:


$table->string('ad_plan_id');

$table->string('title');

$table->string('image');

$table->string('description');

$table->string('url');

$table->string('time_end')->nullable();

$table->string('duration_end')->nullable();

$table->enum('is_approve', ['Approved', 'Pending'])->default('Pending');

$table->string('view')->nullable();

配置关系后,创建计划和展示位置开始工作。我的股票是如何在指定日期的特定时间最好地按时显示数据库中的这些数据。


请朋友们帮帮我,我不了解如何实现它的逻辑。


慕桂英3389331
浏览 151回答 1
1回答

白衣非少年

Php 是一种基于服务器的技术,不具备时间意识如果你想让它有时间意识,你有两个选择:使用 Crontab(或等效的 Windows)使用前端脚本(javascript 或其他)我的建议是编写一个 getAdsForDateTime(DateTime $datetime) 函数,该函数将在您的数据库中查询要在给定时刻显示的广告。根据您的应用程序所需的规范,您选择的(和时间感知的)方法将调用此函数
打开App,查看更多内容
随时随地看视频慕课网APP