Files
xin-procurement/database/migrations/2026_07_23_030611_create_purchase_table.php
T
2026-07-23 20:41:25 +08:00

88 lines
4.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
* 采购管理(C1-C6):采购单、采购明细(发送供应商)、采购金额分摊(D3)
*/
public function up(): void
{
// 采购单表(C1 基于所有门店订单汇总生成)
if (! Schema::hasTable('purchase_order')) {
Schema::create('purchase_order', function (Blueprint $table) {
$table->increments('id')->comment('采购单ID');
$table->string('purchase_no', 32)->unique()->comment('采购单编号');
$table->date('purchase_date')->comment('采购日期');
$table->integer('status')->default(0)->comment('采购单状态(0待发送 1部分发送 2全部发送 3已完成)');
$table->decimal('total_quantity', 10, 2)->default(0)->comment('采购总量');
$table->decimal('total_weight', 10, 3)->default(0)->comment('采购总重量');
$table->decimal('estimate_amount', 10, 2)->default(0)->comment('预估金额(按订货汇总)');
$table->decimal('actual_amount', 10, 2)->default(0)->comment('实际采购金额');
$table->integer('operator_id')->default(0)->comment('采购员(系统用户ID');
$table->string('remark', 255)->default('')->comment('备注');
$table->timestamps();
$table->index(['purchase_date', 'status'], 'purchase_order_date_status_index');
$table->comment('采购单表');
});
}
// 采购单明细表(C2/C3 按分类排序导出,C4 可修改,C5/C6 发送供应商及状态标记)
if (! Schema::hasTable('purchase_order_item')) {
Schema::create('purchase_order_item', function (Blueprint $table) {
$table->increments('id')->comment('明细ID');
$table->integer('purchase_id')->comment('采购单ID');
$table->integer('product_id')->comment('商品ID');
$table->integer('supplier_id')->default(0)->comment('供应商ID');
$table->string('product_name', 100)->comment('品名(快照)');
$table->string('product_spec', 100)->default('')->comment('规格/包规(快照)');
$table->decimal('price', 10, 2)->default(0)->comment('采购单价');
$table->decimal('quantity', 10, 2)->default(0)->comment('采购量');
$table->decimal('weight', 10, 3)->default(0)->comment('实际称重');
$table->decimal('amount', 10, 2)->default(0)->comment('采购金额');
$table->integer('sort')->default(0)->comment('排序(导出用)');
$table->integer('is_sent')->default(0)->comment('是否已发送供应商(1已发送 0未发送)');
$table->timestamp('sent_at')->nullable()->comment('发送时间');
$table->string('remark', 255)->default('')->comment('备注');
$table->timestamps();
$table->index(['purchase_id'], 'purchase_order_item_purchase_index');
$table->index(['supplier_id', 'is_sent'], 'purchase_order_item_supplier_sent_index');
$table->comment('采购单明细表');
});
}
// 采购分摊表(D3 采购金额自动分配到各门店/各单品)
if (! Schema::hasTable('purchase_allocation')) {
Schema::create('purchase_allocation', function (Blueprint $table) {
$table->increments('id')->comment('分摊ID');
$table->integer('purchase_item_id')->comment('采购单明细ID');
$table->integer('order_item_id')->comment('门店订货明细ID');
$table->integer('store_id')->comment('分摊到的门店ID');
$table->integer('product_id')->comment('商品ID');
$table->decimal('quantity', 10, 2)->default(0)->comment('分摊数量');
$table->decimal('weight', 10, 3)->default(0)->comment('分摊重量');
$table->decimal('amount', 10, 2)->default(0)->comment('分摊金额');
$table->timestamps();
$table->index(['purchase_item_id'], 'purchase_allocation_item_index');
$table->index(['order_item_id'], 'purchase_allocation_order_item_index');
$table->index(['store_id'], 'purchase_allocation_store_index');
$table->comment('采购分摊表');
});
}
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('purchase_order');
Schema::dropIfExists('purchase_order_item');
Schema::dropIfExists('purchase_allocation');
}
};