feat: 第二阶段核心业务模块(CRM/房务/护理/月子餐)

后端:
- 4个迁移文件新增23张业务表
- 23个Eloquent Model(含关联/类型转换/门店隔离)
- 20个Controller(含CRUD+业务操作: 合同审核/入住退房/护理异常处理等)
- 110+条API路由(crm/room/care/meal四大前缀)

前端:
- 4个API模块(crm.js/room.js/care.js/meal.js)
- 13个业务页面(线索/客户/合同/渠道/投诉/房型/房间/预定/护理档案/护理计划/护理记录/菜品/排餐)
This commit is contained in:
li
2026-03-13 20:18:29 +08:00
parent 11c177a432
commit 16bcd9bcf0
65 changed files with 4660 additions and 0 deletions
@@ -0,0 +1,164 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
// 渠道来源
Schema::create('channels', function (Blueprint $table) {
$table->id();
$table->foreignId('store_id')->constrained();
$table->string('name', 50);
$table->tinyInteger('type')->nullable()->comment('1线上 2线下 3转介绍');
$table->tinyInteger('status')->default(1);
$table->timestamps();
});
// 线索
Schema::create('leads', function (Blueprint $table) {
$table->id();
$table->foreignId('store_id')->constrained();
$table->unsignedBigInteger('channel_id')->nullable();
$table->string('name', 50);
$table->string('phone', 20);
$table->string('wechat', 50)->nullable();
$table->date('expected_date')->nullable()->comment('预产期');
$table->string('source', 50)->nullable();
$table->tinyInteger('status')->default(1)->comment('1新建 2跟进中 3已转化 4无效');
$table->unsignedBigInteger('owner_id')->nullable()->comment('负责销售');
$table->text('remark')->nullable();
$table->unsignedBigInteger('created_by')->nullable();
$table->timestamps();
$table->index(['store_id', 'status']);
$table->index('owner_id');
$table->index('phone');
});
// 线索跟进记录
Schema::create('lead_follows', function (Blueprint $table) {
$table->id();
$table->foreignId('lead_id')->constrained()->onDelete('cascade');
$table->unsignedBigInteger('user_id');
$table->tinyInteger('type')->nullable()->comment('1电话 2微信 3到店 4其他');
$table->text('content')->nullable();
$table->timestamp('next_follow_at')->nullable();
$table->timestamp('created_at')->nullable();
$table->index('lead_id');
});
// 客户
Schema::create('customers', function (Blueprint $table) {
$table->id();
$table->foreignId('store_id')->constrained();
$table->unsignedBigInteger('lead_id')->nullable();
$table->string('name', 50);
$table->string('phone', 20);
$table->string('id_card', 20)->nullable();
$table->string('wechat', 50)->nullable();
$table->date('birthday')->nullable();
$table->date('expected_date')->nullable();
$table->date('actual_date')->nullable();
$table->tinyInteger('baby_count')->default(1);
$table->json('tags')->nullable();
$table->tinyInteger('status')->default(1)->comment('1潜在 2签约 3在住 4离店 5无效');
$table->unsignedBigInteger('owner_id')->nullable();
$table->text('remark')->nullable();
$table->timestamps();
$table->softDeletes();
$table->index(['store_id', 'status']);
$table->index('phone');
});
// 客户家属
Schema::create('customer_families', function (Blueprint $table) {
$table->id();
$table->foreignId('customer_id')->constrained()->onDelete('cascade');
$table->string('name', 50)->nullable();
$table->string('phone', 20)->nullable();
$table->string('relation', 20)->nullable();
$table->tinyInteger('is_emergency')->default(0);
$table->timestamps();
$table->index('customer_id');
});
// 合同
Schema::create('contracts', function (Blueprint $table) {
$table->id();
$table->foreignId('store_id')->constrained();
$table->foreignId('customer_id')->constrained();
$table->string('contract_no', 50)->unique();
$table->string('package_name', 100)->nullable();
$table->decimal('total_amount', 12, 2);
$table->decimal('discount_amount', 12, 2)->default(0);
$table->decimal('actual_amount', 12, 2);
$table->integer('days')->nullable();
$table->date('check_in_date')->nullable();
$table->date('check_out_date')->nullable();
$table->tinyInteger('status')->default(0)->comment('0待审 1通过 2无效 3已退');
$table->unsignedBigInteger('audit_user_id')->nullable();
$table->timestamp('audit_at')->nullable();
$table->string('audit_remark', 255)->nullable();
$table->text('remark')->nullable();
$table->unsignedBigInteger('created_by')->nullable();
$table->timestamps();
$table->index('store_id');
$table->index('customer_id');
});
// 问卷模板
Schema::create('questionnaire_templates', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('store_id')->nullable();
$table->string('title', 100);
$table->text('description')->nullable();
$table->json('questions')->nullable();
$table->tinyInteger('type')->nullable()->comment('1入住前 2入住中 3离店 4回访');
$table->tinyInteger('status')->default(1);
$table->timestamps();
});
// 问卷回收
Schema::create('questionnaire_answers', function (Blueprint $table) {
$table->id();
$table->foreignId('questionnaire_template_id')->constrained('questionnaire_templates')->onDelete('cascade');
$table->foreignId('customer_id')->constrained();
$table->json('answers')->nullable();
$table->decimal('score', 5, 2)->nullable();
$table->tinyInteger('status')->default(0)->comment('0未完成 1已提交');
$table->timestamps();
});
// 投诉
Schema::create('complaints', function (Blueprint $table) {
$table->id();
$table->foreignId('store_id')->constrained();
$table->foreignId('customer_id')->constrained();
$table->tinyInteger('type')->nullable()->comment('1服务 2膳食 3环境 4其他');
$table->text('content');
$table->json('images')->nullable();
$table->tinyInteger('status')->default(0)->comment('0待处理 1处理中 2已解决 3已关闭');
$table->unsignedBigInteger('handler_id')->nullable();
$table->text('handle_result')->nullable();
$table->timestamp('handle_at')->nullable();
$table->timestamps();
$table->index(['store_id', 'status']);
});
}
public function down(): void
{
Schema::dropIfExists('complaints');
Schema::dropIfExists('questionnaire_answers');
Schema::dropIfExists('questionnaire_templates');
Schema::dropIfExists('contracts');
Schema::dropIfExists('customer_families');
Schema::dropIfExists('customers');
Schema::dropIfExists('lead_follows');
Schema::dropIfExists('leads');
Schema::dropIfExists('channels');
}
};
@@ -0,0 +1,95 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
// 房型
Schema::create('room_types', function (Blueprint $table) {
$table->id();
$table->foreignId('store_id')->constrained();
$table->string('name', 50);
$table->decimal('price', 12, 2)->nullable()->comment('日单价');
$table->text('description')->nullable();
$table->json('images')->nullable();
$table->json('facilities')->nullable();
$table->integer('sort')->default(0);
$table->tinyInteger('status')->default(1);
$table->timestamps();
});
// 房间
Schema::create('rooms', function (Blueprint $table) {
$table->id();
$table->foreignId('store_id')->constrained();
$table->foreignId('room_type_id')->constrained();
$table->string('floor', 10)->nullable();
$table->string('number', 20);
$table->tinyInteger('status')->default(1)->comment('1空房 2已预定 3入住 4维修 5清洁');
$table->integer('sort')->default(0);
$table->timestamps();
$table->unique(['store_id', 'number']);
});
// 预定/入住记录
Schema::create('reservations', function (Blueprint $table) {
$table->id();
$table->foreignId('store_id')->constrained();
$table->foreignId('customer_id')->constrained();
$table->unsignedBigInteger('contract_id')->nullable();
$table->foreignId('room_id')->constrained();
$table->date('check_in_date');
$table->date('check_out_date');
$table->timestamp('actual_check_in')->nullable();
$table->timestamp('actual_check_out')->nullable();
$table->tinyInteger('status')->default(0)->comment('0预定 1已入住 2已退房 3已取消');
$table->text('remark')->nullable();
$table->unsignedBigInteger('created_by')->nullable();
$table->timestamps();
$table->index(['room_id', 'check_in_date', 'check_out_date']);
$table->index('customer_id');
});
// 客户外出记录
Schema::create('customer_outings', function (Blueprint $table) {
$table->id();
$table->foreignId('reservation_id')->constrained();
$table->foreignId('customer_id')->constrained();
$table->timestamp('out_at');
$table->timestamp('expected_back_at')->nullable();
$table->timestamp('actual_back_at')->nullable();
$table->text('reason')->nullable();
$table->text('risk_note')->nullable();
$table->unsignedBigInteger('created_by')->nullable();
$table->timestamps();
});
// 呼叫记录
Schema::create('call_records', function (Blueprint $table) {
$table->id();
$table->foreignId('store_id')->constrained();
$table->foreignId('room_id')->constrained();
$table->unsignedBigInteger('customer_id')->nullable();
$table->tinyInteger('type')->nullable()->comment('1护理 2清洁 3送水 4其他');
$table->tinyInteger('status')->default(0)->comment('0待处理 1处理中 2已完成');
$table->unsignedBigInteger('handler_id')->nullable();
$table->timestamp('handle_at')->nullable();
$table->string('remark', 255)->nullable();
$table->timestamps();
$table->index(['store_id', 'status']);
});
}
public function down(): void
{
Schema::dropIfExists('call_records');
Schema::dropIfExists('customer_outings');
Schema::dropIfExists('reservations');
Schema::dropIfExists('rooms');
Schema::dropIfExists('room_types');
}
};
@@ -0,0 +1,99 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
// 护理档案
Schema::create('care_profiles', function (Blueprint $table) {
$table->id();
$table->foreignId('customer_id')->constrained();
$table->unsignedBigInteger('reservation_id')->nullable();
$table->tinyInteger('type')->comment('1妈妈 2宝宝');
$table->string('baby_name', 50)->nullable();
$table->tinyInteger('baby_gender')->nullable()->comment('1男 2女');
$table->dateTime('baby_birthday')->nullable();
$table->decimal('birth_weight', 5, 2)->nullable();
$table->tinyInteger('birth_method')->nullable()->comment('1顺产 2剖宫产');
$table->text('allergies')->nullable();
$table->text('medical_history')->nullable();
$table->tinyInteger('risk_level')->default(0)->comment('0正常 1低风险 2高风险');
$table->json('assessment')->nullable();
$table->timestamps();
$table->index('customer_id');
});
// 护理计划
Schema::create('care_plans', function (Blueprint $table) {
$table->id();
$table->foreignId('care_profile_id')->constrained()->onDelete('cascade');
$table->date('plan_date');
$table->string('stage', 50)->nullable()->comment('阶段:产后第X天');
$table->json('items')->nullable();
$table->unsignedBigInteger('nurse_id')->nullable();
$table->tinyInteger('status')->default(0)->comment('0待执行 1执行中 2已完成');
$table->timestamps();
$table->index(['care_profile_id', 'plan_date']);
});
// 护理记录
Schema::create('care_records', function (Blueprint $table) {
$table->id();
$table->foreignId('care_profile_id')->constrained()->onDelete('cascade');
$table->unsignedBigInteger('care_plan_id')->nullable();
$table->tinyInteger('type')->nullable()->comment('1妈妈护理 2宝宝护理');
$table->json('items')->nullable();
$table->text('remark')->nullable();
$table->json('images')->nullable();
$table->unsignedBigInteger('nurse_id');
$table->timestamp('recorded_at');
$table->timestamps();
$table->index('care_profile_id');
$table->index('recorded_at');
});
// 护理异常
Schema::create('care_exceptions', function (Blueprint $table) {
$table->id();
$table->foreignId('care_profile_id')->constrained()->onDelete('cascade');
$table->unsignedBigInteger('reporter_id');
$table->tinyInteger('level')->comment('1一般 2重要 3紧急');
$table->text('description');
$table->json('images')->nullable();
$table->tinyInteger('status')->default(0)->comment('0上报 1处理中 2已解决');
$table->unsignedBigInteger('handler_id')->nullable();
$table->text('handle_result')->nullable();
$table->timestamp('handle_at')->nullable();
$table->timestamps();
$table->index('care_profile_id');
});
// 健康指标记录
Schema::create('health_metrics', function (Blueprint $table) {
$table->id();
$table->foreignId('care_profile_id')->constrained()->onDelete('cascade');
$table->string('metric_type', 30)->comment('temperature/weight/jaundice/blood_pressure');
$table->decimal('value', 8, 2);
$table->string('unit', 10)->nullable();
$table->timestamp('recorded_at');
$table->unsignedBigInteger('recorder_id')->nullable();
$table->string('remark', 255)->nullable();
$table->timestamp('created_at')->nullable();
$table->index(['care_profile_id', 'metric_type']);
$table->index('recorded_at');
});
}
public function down(): void
{
Schema::dropIfExists('health_metrics');
Schema::dropIfExists('care_exceptions');
Schema::dropIfExists('care_records');
Schema::dropIfExists('care_plans');
Schema::dropIfExists('care_profiles');
}
};
@@ -0,0 +1,73 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
// 菜品库
Schema::create('dishes', function (Blueprint $table) {
$table->id();
$table->foreignId('store_id')->constrained();
$table->string('name', 50);
$table->string('category', 30)->nullable()->comment('汤/主食/配菜/甜品');
$table->text('description')->nullable();
$table->string('image', 255)->nullable();
$table->json('ingredients')->nullable();
$table->json('contraindications')->nullable()->comment('禁忌');
$table->decimal('price', 8, 2)->default(0);
$table->tinyInteger('status')->default(1);
$table->timestamps();
$table->index('store_id');
});
// 排餐模板
Schema::create('meal_plan_templates', function (Blueprint $table) {
$table->id();
$table->foreignId('store_id')->constrained();
$table->string('name', 50);
$table->string('stage', 30)->nullable()->comment('适用阶段');
$table->json('meals')->nullable();
$table->tinyInteger('status')->default(1);
$table->timestamps();
});
// 每日排餐
Schema::create('daily_meal_plans', function (Blueprint $table) {
$table->id();
$table->foreignId('store_id')->constrained();
$table->foreignId('customer_id')->constrained();
$table->date('plan_date');
$table->tinyInteger('meal_type')->comment('1早餐 2午餐 3下午茶 4晚餐 5宵夜');
$table->json('dishes')->nullable();
$table->text('special_note')->nullable();
$table->tinyInteger('status')->default(0)->comment('0待备餐 1已备餐 2已送达 3未用');
$table->timestamp('deliver_at')->nullable();
$table->timestamps();
$table->index(['customer_id', 'plan_date']);
$table->index(['store_id', 'plan_date']);
});
// 膳食评价
Schema::create('meal_reviews', function (Blueprint $table) {
$table->id();
$table->foreignId('daily_meal_plan_id')->constrained()->onDelete('cascade');
$table->foreignId('customer_id')->constrained();
$table->tinyInteger('score')->nullable()->comment('1-5星');
$table->text('content')->nullable();
$table->timestamp('created_at')->nullable();
$table->index('daily_meal_plan_id');
});
}
public function down(): void
{
Schema::dropIfExists('meal_reviews');
Schema::dropIfExists('daily_meal_plans');
Schema::dropIfExists('meal_plan_templates');
Schema::dropIfExists('dishes');
}
};