From b53555b74ce6ecb060cf2afc615aa758529ad28d Mon Sep 17 00:00:00 2001 From: qiuxiang <394405259@qq.com> Date: Wed, 7 Oct 2026 11:19:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E3=80=8C=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E7=A7=8D=E8=8F=9C=E8=AE=A2=E5=8D=95=E3=80=8D=E6=98=A0=E5=B0=84?= =?UTF-8?q?=E8=AF=BB=E5=8F=96=E4=B8=BA=E7=A9=BA=EF=BC=9A=E8=A1=A5=20delete?= =?UTF-8?q?d=5Fat=20=E5=88=97=E5=B9=B6=E6=94=B9=E7=94=A8=E8=A1=A8=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因:映射表模型继承的基类带 SoftDeletes,而新建的 jst_order_label_planting_rules 没有 deleted_at 列, 查询直接报错(被服务兜底成空映射),页面全部显示「否」。 - 新增迁移 2026_10_07_130000 补 deleted_at(建表迁移也同步补上,供全新安装) - 服务改用 DB 表查询,避开基类软删除/公司作用域与模型缓存,导入后立即失效重读 --- app/Business/JstOrderLabelPlantingRules.php | 4 +- ...e_jst_order_label_planting_rules_table.php | 1 + ...d_at_to_jst_order_label_planting_rules.php | 37 +++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 database/migrations/2026_10_07_130000_add_deleted_at_to_jst_order_label_planting_rules.php diff --git a/app/Business/JstOrderLabelPlantingRules.php b/app/Business/JstOrderLabelPlantingRules.php index c280c6fa..54d79832 100644 --- a/app/Business/JstOrderLabelPlantingRules.php +++ b/app/Business/JstOrderLabelPlantingRules.php @@ -3,6 +3,7 @@ namespace App\Business; use App\Models\Business\JstOrderLabelPlantingRule; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Schema; use Throwable; @@ -26,8 +27,9 @@ class JstOrderLabelPlantingRules return []; } + // 直接用表查询:避开基类的软删除/公司作用域与模型缓存,映射表由命令写入后立即失效重读 $map = []; - foreach (JstOrderLabelPlantingRule::query() + foreach (DB::table('jst_order_label_planting_rules') ->where('company_id', $companyId) ->get(['label', 'is_planting']) as $row) { $label = trim((string) $row->label); diff --git a/database/migrations/2026_10_07_120000_create_jst_order_label_planting_rules_table.php b/database/migrations/2026_10_07_120000_create_jst_order_label_planting_rules_table.php index af0ead62..a094f237 100644 --- a/database/migrations/2026_10_07_120000_create_jst_order_label_planting_rules_table.php +++ b/database/migrations/2026_10_07_120000_create_jst_order_label_planting_rules_table.php @@ -20,6 +20,7 @@ return new class extends Migration $table->string('label', 191)->comment('聚水潭订单标签'); $table->string('is_planting', 8)->default('是')->comment('是否种菜订单:是/否'); $table->timestamps(); + $table->softDeletes(); $table->unique(['company_id', 'label'], 'jst_order_label_planting_unique'); }); diff --git a/database/migrations/2026_10_07_130000_add_deleted_at_to_jst_order_label_planting_rules.php b/database/migrations/2026_10_07_130000_add_deleted_at_to_jst_order_label_planting_rules.php new file mode 100644 index 00000000..0effb1d1 --- /dev/null +++ b/database/migrations/2026_10_07_130000_add_deleted_at_to_jst_order_label_planting_rules.php @@ -0,0 +1,37 @@ +softDeletes(); + }); + } + + public function down(): void + { + if (! Schema::hasTable('jst_order_label_planting_rules') + || ! Schema::hasColumn('jst_order_label_planting_rules', 'deleted_at')) { + return; + } + + Schema::table('jst_order_label_planting_rules', function (Blueprint $table): void { + $table->dropSoftDeletes(); + }); + } +};