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->timestamp('supplier_confirmed_at')->nullable()->comment('供应商确认接单时间(NULL未确认)'); $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'); } };