first commit

This commit is contained in:
liu
2026-07-23 12:31:37 +08:00
parent 760c9ba8b6
commit 00a0938a1b
14 changed files with 1442 additions and 3 deletions
@@ -0,0 +1,139 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
* 对账管理(D1-D10):财务对账、门店对账单、结算表
*/
public function up(): void
{
// 财务对账单表(D1 按品类对账、D2 按供应商筛选)
if (! Schema::hasTable('reconciliation')) {
Schema::create('reconciliation', function (Blueprint $table) {
$table->increments('id')->comment('对账ID');
$table->string('recon_no', 32)->unique()->comment('对账单编号');
$table->string('title', 100)->comment('对账单标题');
$table->date('period_start')->comment('对账周期开始');
$table->date('period_end')->comment('对账周期结束');
$table->integer('category_id')->default(0)->comment('按品类筛选(0为全部,D1');
$table->integer('supplier_id')->default(0)->comment('按供应商筛选(0为全部,D2');
$table->decimal('publish_amount', 10, 2)->default(0)->comment('公布金额合计(D5');
$table->decimal('actual_amount', 10, 2)->default(0)->comment('实际采购金额合计(D5');
$table->decimal('diff_amount', 10, 2)->default(0)->comment('差额合计(D5');
$table->integer('status')->default(0)->comment('状态(0对账中 1已完成 2已生成结算表)');
$table->integer('operator_id')->default(0)->comment('对账员(系统用户ID');
$table->string('remark', 255)->default('')->comment('备注');
$table->timestamps();
$table->index(['period_start', 'period_end'], 'reconciliation_period_index');
$table->comment('财务对账单表');
});
}
// 财务对账明细表(D4 数据修改、D5 差额对比、D6 单品级门店备注、D8 对账状态标记)
if (! Schema::hasTable('reconciliation_item')) {
Schema::create('reconciliation_item', function (Blueprint $table) {
$table->increments('id')->comment('明细ID');
$table->integer('recon_id')->comment('财务对账单ID');
$table->integer('store_id')->comment('门店ID');
$table->integer('purchase_item_id')->default(0)->comment('采购单明细ID');
$table->integer('order_item_id')->default(0)->comment('门店订货明细ID');
$table->integer('product_id')->comment('商品ID');
$table->string('product_name', 100)->comment('品名(快照)');
$table->decimal('quantity', 10, 2)->default(0)->comment('数量(D4可修改)');
$table->decimal('weight', 10, 3)->default(0)->comment('称重数据(D4可修改)');
$table->decimal('publish_amount', 10, 2)->default(0)->comment('公布金额(门店订货金额)');
$table->decimal('actual_amount', 10, 2)->default(0)->comment('实际采购金额(分摊)');
$table->decimal('diff_amount', 10, 2)->default(0)->comment('差额');
$table->integer('is_reconciled')->default(0)->comment('对账状态(1已对账 0未对账,D8)');
$table->string('store_remark', 255)->default('')->comment('单品级门店备注(D6');
$table->integer('sort')->default(0)->comment('排序');
$table->timestamps();
$table->index(['recon_id'], 'reconciliation_item_recon_index');
$table->index(['store_id', 'is_reconciled'], 'reconciliation_item_store_index');
$table->comment('财务对账明细表');
});
}
// 门店对账单表(门店在小程序端自助生成,回款周期快照决定应结算日期)
if (! Schema::hasTable('statement')) {
Schema::create('statement', function (Blueprint $table) {
$table->increments('id')->comment('对账单ID');
$table->string('statement_no', 32)->unique()->comment('对账单编号');
$table->integer('store_id')->comment('门店ID');
$table->date('period_start')->comment('对账周期开始');
$table->date('period_end')->comment('对账周期结束');
$table->decimal('total_amount', 10, 2)->default(0)->comment('对账总金额');
$table->integer('payment_cycle_days')->default(0)->comment('回款周期(天),生成时从门店快照');
$table->date('settlement_date')->nullable()->comment('应结算日期(按回款周期计算)');
$table->integer('status')->default(0)->comment('状态(0未对账 1已对账 2已结算)');
$table->timestamp('reconciled_at')->nullable()->comment('对账完成时间');
$table->timestamp('settled_at')->nullable()->comment('结算时间');
$table->string('remark', 255)->default('')->comment('备注');
$table->timestamps();
$table->index(['store_id', 'period_start'], 'statement_store_period_index');
$table->comment('门店对账单表');
});
}
// 门店对账单明细表(每个单品/订单的对账状态标识)
if (! Schema::hasTable('statement_item')) {
Schema::create('statement_item', function (Blueprint $table) {
$table->increments('id')->comment('明细ID');
$table->integer('statement_id')->comment('对账单ID');
$table->integer('order_id')->comment('订单ID');
$table->integer('order_item_id')->comment('订货明细ID');
$table->integer('product_id')->comment('商品ID');
$table->string('product_name', 100)->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('is_reconciled')->default(0)->comment('对账状态(1已对账 0未对账)');
$table->string('store_remark', 255)->default('')->comment('门店备注');
$table->timestamps();
$table->index(['statement_id'], 'statement_item_statement_index');
$table->comment('门店对账单明细表');
});
}
// 结算表(D9 对账结束后生成结算表/回框统计表,D10 下载存档)
if (! Schema::hasTable('settlement')) {
Schema::create('settlement', function (Blueprint $table) {
$table->increments('id')->comment('结算ID');
$table->string('settlement_no', 32)->unique()->comment('结算单编号');
$table->integer('recon_id')->default(0)->comment('关联财务对账单ID');
$table->integer('store_id')->default(0)->comment('门店ID0为汇总结算)');
$table->date('period_start')->comment('结算周期开始');
$table->date('period_end')->comment('结算周期结束');
$table->decimal('total_amount', 10, 2)->default(0)->comment('结算总金额(公布)');
$table->decimal('actual_amount', 10, 2)->default(0)->comment('实际采购总金额');
$table->decimal('diff_amount', 10, 2)->default(0)->comment('差额合计');
$table->integer('status')->default(0)->comment('状态(0待结算 1已结算)');
$table->string('file_path', 255)->default('')->comment('导出文件路径(Excel/PDFD10');
$table->integer('operator_id')->default(0)->comment('操作人(系统用户ID');
$table->timestamp('settled_at')->nullable()->comment('结算时间');
$table->string('remark', 255)->default('')->comment('备注');
$table->timestamps();
$table->index(['store_id', 'status'], 'settlement_store_status_index');
$table->comment('结算表');
});
}
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('reconciliation');
Schema::dropIfExists('reconciliation_item');
Schema::dropIfExists('statement');
Schema::dropIfExists('statement_item');
Schema::dropIfExists('settlement');
}
};