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(); + }); + } +};