|
|
@@ -2,6 +2,35 @@
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
+use App\Module\Farm\Models\FarmFruitGrowthCycle;
|
|
|
+use App\Module\Farm\Models\FarmGodBuff;
|
|
|
+use App\Module\Farm\Models\FarmLandType;
|
|
|
+use App\Module\Farm\Models\FarmLandUpgradeConfig;
|
|
|
+use App\Module\Farm\Models\FarmMysterySeeLandEffect;
|
|
|
+use App\Module\Farm\Models\FarmSeed;
|
|
|
+use App\Module\Farm\Models\FarmSeedOutput;
|
|
|
+use App\Module\Farm\Models\FarmShrineConfig;
|
|
|
+use App\Module\Fund\Models\FundConfigModel;
|
|
|
+use App\Module\Fund\Models\FundCurrencyModel;
|
|
|
+use App\Module\Fund\Models\FundModel;
|
|
|
+use App\Module\GameItems\Models\ItemCategory;
|
|
|
+use App\Module\Mex\Models\MexPriceConfig;
|
|
|
+use App\Module\Pet\Models\PetLevelConfig;
|
|
|
+use App\Module\Pet\Models\PetSkill;
|
|
|
+use App\Module\Point\Models\PointAdminModel;
|
|
|
+use App\Module\Point\Models\PointConfigModel;
|
|
|
+use App\Module\Point\Models\PointCurrencyModel;
|
|
|
+use App\Module\Point\Models\PointModel;
|
|
|
+use App\Module\Shop\Models\ShopCategory;
|
|
|
+use App\Module\Shop\Models\ShopItem;
|
|
|
+use App\Module\ThirdParty\Models\ThirdPartyCredential;
|
|
|
+use App\Module\ThirdParty\Models\ThirdPartyLog;
|
|
|
+use App\Module\ThirdParty\Models\ThirdPartyQuota;
|
|
|
+use App\Module\ThirdParty\Models\ThirdPartyService;
|
|
|
+use App\Module\Transfer\Models\TransferApp;
|
|
|
+use App\Module\Transfer\Services\TransferService;
|
|
|
+use App\Module\UrsPromotion\Models\UrsTalentConfig;
|
|
|
+use App\Module\UrsPromotion\Models\UrsTransferFeeConfig;
|
|
|
use Illuminate\Console\Command;
|
|
|
use Illuminate\Support\Facades\File;
|
|
|
use Illuminate\Support\Str;
|
|
|
@@ -9,20 +38,80 @@ use Illuminate\Support\Str;
|
|
|
|
|
|
/**
|
|
|
* 生成配置表的 数据库备份文件
|
|
|
- *
|
|
|
+ *
|
|
|
+ * php artisan generate:configdb
|
|
|
+ *
|
|
|
*/
|
|
|
class GenerateConfigDbCommand extends Command
|
|
|
{
|
|
|
- protected $signature = 'generate:configdb';
|
|
|
+
|
|
|
+ protected $signature = 'generate:configdb';
|
|
|
protected $description = '生成配置表的 数据库备份文件,包含创建语句和插入语句';
|
|
|
|
|
|
- protected $outFile = 'database/sql/configdb.sql';
|
|
|
+ protected $outFile = 'database/sql/configdb.sql';
|
|
|
protected $modelList = [
|
|
|
+ // 系统
|
|
|
+ \App\Module\System\Models\SysConfig::class,
|
|
|
+ // 物品
|
|
|
+ \App\Module\GameItems\Models\Item::class,
|
|
|
+ \App\Module\GameItems\Models\ItemCategory::class,
|
|
|
+ \App\Module\GameItems\Models\ItemChestConfig::class,
|
|
|
+ \App\Module\GameItems\Models\ItemDismantleRule::class,
|
|
|
+ \App\Module\GameItems\Models\ItemGroup::class,
|
|
|
+ \App\Module\GameItems\Models\ItemGroupItem::class,
|
|
|
+ \App\Module\GameItems\Models\ItemOutputLimit::class,
|
|
|
+ \App\Module\GameItems\Models\ItemRecipe::class,
|
|
|
+ // Game模块
|
|
|
+ \App\Module\Game\Models\GameConditionGroup::class,
|
|
|
+ \App\Module\Game\Models\GameConditionItem::class,
|
|
|
+ \App\Module\Game\Models\GameConsumeGroup::class,
|
|
|
+ \App\Module\Game\Models\GameConsumeItem::class,
|
|
|
+ \App\Module\Game\Models\GameRewardGroup::class,
|
|
|
+ \App\Module\Game\Models\GameRewardGroupPityCount::class,
|
|
|
+ \App\Module\Game\Models\GameRewardItem::class,
|
|
|
+ \App\Module\Game\Models\GameTag::class,
|
|
|
+ \App\Module\Game\Models\GameTagRelation::class,
|
|
|
+ // 农场
|
|
|
\App\Module\Farm\Models\FarmConfig::class,
|
|
|
\App\Module\Farm\Models\FarmShrineConfig::class,
|
|
|
\App\Module\Farm\Models\FarmHouseConfig::class,
|
|
|
+ FarmFruitGrowthCycle::class,
|
|
|
+ FarmGodBuff::class,
|
|
|
+ FarmLandType::class,
|
|
|
+ FarmLandUpgradeConfig::class,
|
|
|
+ FarmMysterySeeLandEffect::class,
|
|
|
+ FarmSeed::class,
|
|
|
+ FarmSeedOutput::class,
|
|
|
+ FarmShrineConfig::class,
|
|
|
+ // mex
|
|
|
+ MexPriceConfig::class,
|
|
|
+ // 宠物
|
|
|
\App\Module\Pet\Models\PetConfig::class,
|
|
|
- \App\Module\System\Models\SysConfig::class,
|
|
|
+ PetLevelConfig::class,
|
|
|
+ PetSkill::class,
|
|
|
+ // urs 推广
|
|
|
+ UrsTalentConfig::class,
|
|
|
+ UrsTransferFeeConfig::class,
|
|
|
+ // Fund 模块
|
|
|
+ FundModel::class,
|
|
|
+ FundConfigModel::class,
|
|
|
+ FundCurrencyModel::class,
|
|
|
+ // Point 模块
|
|
|
+ PointModel::class,
|
|
|
+ PointConfigModel::class,
|
|
|
+ PointCurrencyModel::class,
|
|
|
+ // 三方模块
|
|
|
+ ThirdPartyService::class,
|
|
|
+ ThirdPartyCredential::class,
|
|
|
+ ThirdPartyQuota::class,
|
|
|
+ // 划转模块
|
|
|
+ TransferApp::class,
|
|
|
+ // 商店模块
|
|
|
+ ShopItem::class,
|
|
|
+ ShopCategory::class,
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
];
|
|
|
|
|
|
public function handle()
|
|
|
@@ -43,7 +132,7 @@ class GenerateConfigDbCommand extends Command
|
|
|
$sqlContent .= "-- 警告: 此文件由系统自动生成,禁止修改!\n";
|
|
|
$sqlContent .= "-- ******************************************************************\n\n";
|
|
|
|
|
|
- $totalTables = 0;
|
|
|
+ $totalTables = 0;
|
|
|
$totalRecords = 0;
|
|
|
|
|
|
// 遍历每个模型
|
|
|
@@ -52,10 +141,10 @@ class GenerateConfigDbCommand extends Command
|
|
|
$this->info("处理模型: {$modelClass}");
|
|
|
|
|
|
// 实例化模型
|
|
|
- $model = new $modelClass();
|
|
|
- $connection = $model->getConnection();
|
|
|
+ $model = new $modelClass();
|
|
|
+ $connection = $model->getConnection();
|
|
|
$tablePrefix = $connection->getTablePrefix();
|
|
|
- $tableName = $tablePrefix . $model->getTable();
|
|
|
+ $tableName = $tablePrefix . $model->getTable();
|
|
|
|
|
|
$this->info(" 表名: {$tableName}");
|
|
|
|
|
|
@@ -79,7 +168,7 @@ class GenerateConfigDbCommand extends Command
|
|
|
$sqlContent .= "{$createTableSQL};\n\n";
|
|
|
|
|
|
// 获取表数据
|
|
|
- $records = $connection->table($model->getTable())->get();
|
|
|
+ $records = $connection->table($model->getTable())->get();
|
|
|
$recordCount = $records->count();
|
|
|
|
|
|
$this->info(" 记录数: {$recordCount}");
|
|
|
@@ -89,15 +178,15 @@ class GenerateConfigDbCommand extends Command
|
|
|
$sqlContent .= "-- 数据插入\n";
|
|
|
|
|
|
// 获取字段名
|
|
|
- $firstRecord = (array) $records->first();
|
|
|
- $columns = array_keys($firstRecord);
|
|
|
- $columnList = '`' . implode('`, `', $columns) . '`';
|
|
|
+ $firstRecord = (array)$records->first();
|
|
|
+ $columns = array_keys($firstRecord);
|
|
|
+ $columnList = '`' . implode('`, `', $columns) . '`';
|
|
|
|
|
|
$sqlContent .= "INSERT INTO `{$tableName}` ({$columnList}) VALUES\n";
|
|
|
|
|
|
$values = [];
|
|
|
foreach ($records as $record) {
|
|
|
- $recordArray = (array) $record;
|
|
|
+ $recordArray = (array)$record;
|
|
|
$escapedValues = array_map(function ($value) {
|
|
|
if ($value === null) {
|
|
|
return 'NULL';
|
|
|
@@ -107,7 +196,7 @@ class GenerateConfigDbCommand extends Command
|
|
|
return "'" . addslashes($value) . "'";
|
|
|
}
|
|
|
}, $recordArray);
|
|
|
- $values[] = '(' . implode(', ', $escapedValues) . ')';
|
|
|
+ $values[] = '(' . implode(', ', $escapedValues) . ')';
|
|
|
}
|
|
|
|
|
|
$sqlContent .= implode(",\n", $values) . ";\n\n";
|
|
|
@@ -152,15 +241,15 @@ class GenerateConfigDbCommand extends Command
|
|
|
*/
|
|
|
private function formatBytes(int $bytes): string
|
|
|
{
|
|
|
- $units = ['B', 'KB', 'MB', 'GB'];
|
|
|
+ $units = [ 'B', 'KB', 'MB', 'GB' ];
|
|
|
$bytes = max($bytes, 0);
|
|
|
- $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
|
|
|
- $pow = min($pow, count($units) - 1);
|
|
|
+ $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
|
|
|
+ $pow = min($pow, count($units) - 1);
|
|
|
|
|
|
$bytes /= 1 << 10 * $pow;
|
|
|
|
|
|
return round($bytes, 2) . ' ' . $units[$pow];
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
}
|