Files
xin-school/database/migrations/2026_05_30_000005_create_merchant_tables.php
T
2026-05-30 18:02:41 +08:00

150 lines
7.8 KiB
PHP

<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
// 商户分类
if (! Schema::hasTable('merchant_categories')) {
Schema::create('merchant_categories', function (Blueprint $table) {
$table->id();
$table->string('name', 50)->comment('分类名称');
$table->string('slug', 50)->comment('标识');
$table->string('description', 255)->default('')->comment('描述');
$table->string('icon', 255)->default('')->comment('图标');
$table->integer('sort')->default(0)->comment('排序');
$table->tinyInteger('status')->default(1)->comment('状态:0=禁用,1=正常');
$table->timestamps();
$table->unique('slug');
$table->comment('商户分类');
});
}
// 商户/店铺
if (! Schema::hasTable('merchants')) {
Schema::create('merchants', function (Blueprint $table) {
$table->id();
$table->unsignedInteger('user_id')->comment('所属用户ID');
$table->unsignedBigInteger('category_id')->nullable()->comment('商户分类ID');
$table->string('name', 50)->comment('店铺名称');
$table->string('logo', 255)->default('')->comment('店铺Logo');
$table->string('banner', 255)->default('')->comment('店铺横幅/封面');
$table->text('description')->nullable()->comment('店铺简介');
$table->string('contact_name', 30)->default('')->comment('联系人');
$table->string('contact_mobile', 20)->default('')->comment('联系电话');
$table->string('province', 30)->default('')->comment('省');
$table->string('city', 30)->default('')->comment('市');
$table->string('district', 30)->default('')->comment('区');
$table->string('address', 255)->default('')->comment('详细地址');
$table->string('latitude', 20)->default('')->comment('纬度');
$table->string('longitude', 20)->default('')->comment('经度');
$table->string('business_hours', 100)->default('')->comment('营业时间');
$table->decimal('balance', 10, 2)->default(0)->comment('账户余额');
$table->decimal('total_income', 10, 2)->default(0)->comment('累计收入');
$table->decimal('min_price', 10, 2)->default(0)->comment('起送价');
$table->tinyInteger('status')->default(0)->comment('状态:0=待审核,1=正常,2=停用,3=已关闭');
$table->string('reject_reason', 255)->default('')->comment('拒绝原因');
$table->timestamps();
$table->index('user_id');
$table->index('category_id');
$table->index('status');
$table->comment('商户/店铺');
});
}
// 商品分类
if (! Schema::hasTable('product_categories')) {
Schema::create('product_categories', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('merchant_id')->comment('商户ID');
$table->unsignedBigInteger('parent_id')->default(0)->comment('父级ID');
$table->string('name', 50)->comment('分类名称');
$table->string('slug', 50)->comment('标识');
$table->string('description', 255)->default('')->comment('描述');
$table->string('icon', 255)->default('')->comment('图标');
$table->integer('sort')->default(0)->comment('排序');
$table->tinyInteger('status')->default(1)->comment('状态:0=禁用,1=正常');
$table->timestamps();
$table->index('merchant_id');
$table->comment('商品分类');
});
}
// 商品
if (! Schema::hasTable('merchant_products')) {
Schema::create('merchant_products', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('merchant_id')->comment('商户ID');
$table->unsignedBigInteger('category_id')->nullable()->comment('分类ID');
$table->string('name', 100)->comment('商品名称');
$table->text('description')->nullable()->comment('商品描述');
$table->json('images')->nullable()->comment('商品图片列表');
$table->decimal('price', 10, 2)->comment('售价');
$table->decimal('original_price', 10, 2)->nullable()->comment('原价');
$table->integer('stock')->default(0)->comment('库存');
$table->string('unit', 20)->default('份')->comment('单位');
$table->integer('sales')->default(0)->comment('销量');
$table->tinyInteger('status')->default(1)->comment('状态:0=下架,1=上架');
$table->tinyInteger('is_recommend')->default(0)->comment('是否推荐:0=否,1=是');
$table->integer('sort')->default(0)->comment('排序');
$table->timestamps();
$table->softDeletes();
$table->index('merchant_id');
$table->index('category_id');
$table->index('status');
$table->comment('商户商品');
});
}
// 打印机
if (! Schema::hasTable('printers')) {
Schema::create('printers', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('merchant_id')->comment('商户ID');
$table->string('name', 50)->comment('打印机名称');
$table->string('brand', 50)->default('')->comment('品牌');
$table->string('model', 50)->default('')->comment('型号');
$table->string('device_no', 100)->default('')->comment('设备编号');
$table->string('secret_key', 255)->default('')->comment('密钥');
$table->tinyInteger('status')->default(1)->comment('状态:0=离线,1=在线,2=故障');
$table->json('config')->nullable()->comment('打印配置');
$table->timestamps();
$table->index('merchant_id');
$table->comment('打印机');
});
}
// 打印任务
if (! Schema::hasTable('print_tasks')) {
Schema::create('print_tasks', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('printer_id')->comment('打印机ID');
$table->unsignedBigInteger('order_id')->nullable()->comment('关联订单ID');
$table->text('content')->comment('打印内容');
$table->integer('copies')->default(1)->comment('打印份数');
$table->tinyInteger('status')->default(0)->comment('状态:0=待打印,1=打印中,2=已完成,3=失败');
$table->string('error_msg', 255)->default('')->comment('错误信息');
$table->timestamp('printed_at')->nullable()->comment('打印时间');
$table->timestamps();
$table->index('printer_id');
$table->index('order_id');
$table->comment('打印任务');
});
}
}
public function down(): void
{
Schema::dropIfExists('print_tasks');
Schema::dropIfExists('printers');
Schema::dropIfExists('merchant_products');
Schema::dropIfExists('product_categories');
Schema::dropIfExists('merchants');
Schema::dropIfExists('merchant_categories');
}
};