| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- <?php
- // 直接使用artisan命令运行,不需要手动初始化
- echo "开始添加木材相关配方数据...\n";
- // 配方数据
- $recipes = [
- [
- 'name' => '木板制作',
- 'result_item_id' => 34, // 木板ID
- 'result_quantity' => 4,
- 'success_rate' => 1.0, // 100%成功率
- 'coin_cost' => json_encode(['gold' => 2]),
- 'cooldown_seconds' => 0,
- 'is_visible' => 1,
- 'unlock_conditions' => json_encode([]),
- 'materials' => [
- [
- 'item_id' => 33, // 木材ID
- 'quantity' => 1,
- 'is_consumed' => 1
- ]
- ]
- ],
- [
- 'name' => '木箱制作',
- 'result_item_id' => 35, // 木箱ID(假设存在)
- 'result_quantity' => 1,
- 'success_rate' => 1.0,
- 'coin_cost' => json_encode(['gold' => 5]),
- 'cooldown_seconds' => 0,
- 'is_visible' => 1,
- 'unlock_conditions' => json_encode([]),
- 'materials' => [
- [
- 'item_id' => 34, // 木板ID
- 'quantity' => 4,
- 'is_consumed' => 1
- ]
- ]
- ],
- [
- 'name' => '木制工具箱',
- 'result_item_id' => 36, // 木制工具箱ID(假设存在)
- 'result_quantity' => 1,
- 'success_rate' => 0.9, // 90%成功率
- 'coin_cost' => json_encode(['gold' => 10]),
- 'cooldown_seconds' => 30,
- 'is_visible' => 1,
- 'unlock_conditions' => json_encode(['level' => 5]),
- 'materials' => [
- [
- 'item_id' => 34, // 木板ID
- 'quantity' => 6,
- 'is_consumed' => 1
- ],
- [
- 'item_id' => 37, // 铁钉ID(假设存在)
- 'quantity' => 2,
- 'is_consumed' => 1
- ]
- ]
- ],
- [
- 'name' => '高级木材加工',
- 'result_item_id' => 38, // 高级木材ID(假设存在)
- 'result_quantity' => 1,
- 'success_rate' => 0.8, // 80%成功率
- 'coin_cost' => json_encode(['gold' => 15]),
- 'cooldown_seconds' => 60,
- 'is_visible' => 1,
- 'unlock_conditions' => json_encode(['level' => 10]),
- 'materials' => [
- [
- 'item_id' => 33, // 木材ID
- 'quantity' => 3,
- 'is_consumed' => 1
- ],
- [
- 'item_id' => 39, // 特殊工具ID(假设存在)
- 'quantity' => 1,
- 'is_consumed' => 0 // 不消耗,只需要拥有
- ]
- ]
- ]
- ];
- try {
- DB::beginTransaction();
- foreach ($recipes as $recipeData) {
- echo "添加配方: {$recipeData['name']}\n";
- // 提取材料数据
- $materials = $recipeData['materials'];
- unset($recipeData['materials']);
- // 添加时间戳
- $recipeData['created_at'] = now();
- $recipeData['updated_at'] = now();
- // 插入配方
- $recipeId = DB::table('item_recipes')->insertGetId($recipeData);
- // 插入材料
- foreach ($materials as $material) {
- $material['recipe_id'] = $recipeId;
- $material['created_at'] = now();
- $material['updated_at'] = now();
- DB::table('item_recipe_materials')->insert($material);
- echo " - 添加材料: 物品ID {$material['item_id']}, 数量 {$material['quantity']}\n";
- }
- echo "配方 '{$recipeData['name']}' 添加成功,ID: {$recipeId}\n\n";
- }
- DB::commit();
- echo "所有木材相关配方添加完成!\n";
- } catch (Exception $e) {
- DB::rollBack();
- echo "错误: " . $e->getMessage() . "\n";
- exit(1);
- }
|