4
0
Fork 0
dcat-admin-goods/database/2022_08_11_184332_create_go...

100 lines
4.4 KiB
PHP

<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateGoodsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('goods_category', function (Blueprint $table) {
$table->id();
$table->string('name')->comment('分类名称');
$table->string('image')->nullable()->comment('封面图');
$table->string('description')->nullable()->comment('描述');
$table->unsignedBigInteger('parent_id')->default(0)->comment('父级ID');
$table->unsignedInteger('level')->default(1)->comment('层级');
$table->unsignedInteger('sort')->default(1)->comment('排序 asc');
$table->unsignedTinyInteger('is_enable')->default(1)->comment('状态');
$table->string('path')->default('-')->comment('所有的父级ID');
$table->comment('商品-分类');
});
Schema::create('goods_type', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->json('attr')->nullable()->comment('属性[{name: "属性名", values: [可选值]}]');
$table->json('spec')->nullable()->comment('规格[{name: "属性名", values: [可选值]}]');
$table->json('part')->nullable()->comment('配件[{name: "属性名", values: [可选值]}]');
$table->comment('商品-类型');
});
Schema::create('goods_brand', function (Blueprint $table) {
$table->id();
$table->string('name')->comment('名称');
$table->string('image')->nullable()->comment('图标');
$table->comment('商品-品牌');
});
Schema::create('goods', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('category_id')->comment('所属分类, 关联 goods_category.id');
$table->unsignedBigInteger('merchant_id')->nullable()->comment('商户ID');
$table->unsignedBigInteger('type_id')->nullable()->comment('所属类别');
$table->unsignedBigInteger('brand_id')->nullable()->comment('所属品牌');
$table->string('name')->comment('商品名称');
$table->string('goods_sn')->comment('编号');
$table->string('cover_image')->nullable()->comment('封面图');
$table->json('images')->nullable()->comment('图片集');
$table->string('description')->nullable()->comment('描述');
$table->json('content')->nullable()->comment('详细');
$table->unsignedInteger('on_sale')->default(0)->comment('是否上架');
$table->unsignedInteger('is_recommend')->default(0)->comment('是否推荐');
$table->unsignedInteger('stock')->default(0)->comment('库存');
$table->unsignedInteger('sold_count')->default(0)->comment('销量');
$table->decimal('price', 12, 2)->comment('售价');
$table->json('attr')->nullable()->comment('属性[{name, values: [{name, value}]}]');
$table->json('spec')->nullable()->comment('规格[{name, values: [{name, value}]}]');
$table->json('part')->nullable()->comment('配件[{name, values: [{name, value}]}]');
$table->timestamps();
$table->comment('商品');
});
Schema::create('goods_sku', function (Blueprint $table) {
$table->id();
$table->string('sn')->comment('货号');
$table->unsignedBigInteger('goods_id')->comment('所属商品, 关联 goods.id');
$table->string('name')->comment('名称');
$table->decimal('price', 12, 2)->comment('价格');
$table->unsignedInteger('stock')->comment('库存');
$table->unsignedInteger('sold_count')->default(0)->comment('销量');
$table->json('spec')->nullable()->comment('规格[{name, value, price}]');
$table->comment('商品-SKU');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('goods_sku');
Schema::dropIfExists('goods');
Schema::dropIfExists('goods_category');
Schema::dropIfExists('goods_type');
Schema::dropIfExists('goods_brand');
}
}