Files
chatroom/database/migrations/2026_02_27_005300_create_gifts_table.php
lkddi c5cc55fc84 功能:送花/礼物系统完整开发
- 新增 Gift 模型和 gifts 数据表(7种默认花卉,各有图片/金币/魅力配置)
- 7张花卉图片生成并存放于 public/images/gifts/
- 名片弹窗新增送礼物 UI:图片选择列表、金币/魅力标注、数量选择
- sendFlower 控制器方法:按 gift_id 查找礼物、扣金币、加魅力、广播消息
- 聊天消息渲染支持显示礼物图片(含弹跳动画效果)
- 后台可在 gifts 表中管理花卉类型(名称、图标、图片、金币、魅力、排序、启禁用)
2026-02-27 01:01:56 +08:00

58 lines
3.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* 文件功能:创建 gifts 礼物表并填充默认鲜花数据
*
* 礼物系统支持后台管理多种花/礼物类型,每种有不同的金币消耗和魅力增量。
* 图片存放在 public/images/gifts/ 目录下。
*
* @author ChatRoom Laravel
*
* @version 1.0.0
*/
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* 创建 gifts 表并填充默认礼物数据
*/
public function up(): void
{
Schema::create('gifts', function (Blueprint $table) {
$table->id();
$table->string('name', 50)->comment('礼物名称');
$table->string('emoji', 10)->comment('显示图标/emoji');
$table->string('image', 100)->nullable()->comment('礼物图片路径(相对 /images/gifts/');
$table->unsignedInteger('cost')->default(0)->comment('消耗金币数');
$table->unsignedInteger('charm')->default(1)->comment('增加魅力值');
$table->unsignedTinyInteger('sort_order')->default(0)->comment('排序(越小越靠前)');
$table->boolean('is_active')->default(true)->comment('是否启用');
$table->timestamps();
});
// 填充默认鲜花数据(图片文件名与 sort_order 对应)
DB::table('gifts')->insert([
['name' => '小雏菊', 'emoji' => '🌼', 'image' => 'daisy.png', 'cost' => 5, 'charm' => 1, 'sort_order' => 1, 'is_active' => true, 'created_at' => now(), 'updated_at' => now()],
['name' => '玫瑰花', 'emoji' => '🌹', 'image' => 'rose.png', 'cost' => 10, 'charm' => 2, 'sort_order' => 2, 'is_active' => true, 'created_at' => now(), 'updated_at' => now()],
['name' => '向日葵', 'emoji' => '🌻', 'image' => 'sunflower.png', 'cost' => 20, 'charm' => 5, 'sort_order' => 3, 'is_active' => true, 'created_at' => now(), 'updated_at' => now()],
['name' => '樱花束', 'emoji' => '🌸', 'image' => 'sakura.png', 'cost' => 50, 'charm' => 12, 'sort_order' => 4, 'is_active' => true, 'created_at' => now(), 'updated_at' => now()],
['name' => '满天星', 'emoji' => '💐', 'image' => 'bouquet.png', 'cost' => 100, 'charm' => 30, 'sort_order' => 5, 'is_active' => true, 'created_at' => now(), 'updated_at' => now()],
['name' => '蓝色妖姬', 'emoji' => '🪻', 'image' => 'bluerose.png', 'cost' => 200, 'charm' => 66, 'sort_order' => 6, 'is_active' => true, 'created_at' => now(), 'updated_at' => now()],
['name' => '钻石花冠', 'emoji' => '👑', 'image' => 'crown.png', 'cost' => 520, 'charm' => 188, 'sort_order' => 7, 'is_active' => true, 'created_at' => now(), 'updated_at' => now()],
]);
}
/**
* 回滚:删除 gifts 表
*/
public function down(): void
{
Schema::dropIfExists('gifts');
}
};