4
0
Fork 0
dcat-admin/packages/goods/updates/CreateGoodsTable.php

82 lines
3.2 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()
{
$this->down();
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', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('category_id')->comment('所属分类, 关联 goods_category.id');
$table->string('name')->comment('商品名称');
$table->string('goods_sn')->unique()->comment('编号');
$table->string('cover_image')->nullable()->comment('封面图');
$table->json('images')->nullable()->comment('图片集');
$table->string('description')->nullable()->comment('描述');
$table->text('content')->nullable()->comment('详细');
$table->unsignedInteger('on_sale')->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('属性');
$table->json('spec')->nullable()->comment('规格');
$table->json('part')->nullable()->comment('配件');
$table->timestamps();
$table->softDeletes();
$table->foreign('category_id')->references('id')->on('goods_category');
$table->comment('商品');
});
Schema::create('goods_sku', function (Blueprint $table) {
$table->id();
$table->string('sn')->unique()->comment('货号');
$table->unsignedBigInteger('goods_id')->comment('所属商品, 关联 goods.id');
$table->string('name')->comment('名称');
$table->decimal('price', 12, 2)->comment('价格');
$table->unsignedInteger('stock')->comment('库存');
$table->json('spec')->nullable()->comment('规格');
$table->foreign('goods_id')->references('id')->on('goods');
$table->comment('商品-SKU');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('goods_sku');
Schema::dropIfExists('goods');
Schema::dropIfExists('goods_category');
}
};