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:
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Meal;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Meal\DailyMealPlan;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DailyMealPlanController extends Controller
|
||||
{
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$query = DailyMealPlan::query()->with(['customer', 'review']);
|
||||
$query->when($request->customer_id, fn($q, $v) => $q->where('customer_id', $v));
|
||||
$query->when($request->plan_date, fn($q, $v) => $q->whereDate('plan_date', $v));
|
||||
$query->when($request->meal_type, fn($q, $v) => $q->where('meal_type', $v));
|
||||
$query->when($request->has('status'), fn($q) => $q->where('status', $request->status));
|
||||
|
||||
return $this->paginate($query->latest()->paginate($request->input('per_page', 30)));
|
||||
}
|
||||
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'customer_id' => 'required|exists:customers,id',
|
||||
'plan_date' => 'required|date',
|
||||
'meal_type' => 'required|integer|in:1,2,3,4,5',
|
||||
'dishes' => 'nullable|array',
|
||||
'special_note' => 'nullable|string',
|
||||
]);
|
||||
$validated['status'] = 0;
|
||||
|
||||
return $this->success(DailyMealPlan::create($validated));
|
||||
}
|
||||
|
||||
public function show(DailyMealPlan $dailyMealPlan): JsonResponse
|
||||
{
|
||||
return $this->success($dailyMealPlan->load(['customer', 'review']));
|
||||
}
|
||||
|
||||
public function update(Request $request, DailyMealPlan $dailyMealPlan): JsonResponse
|
||||
{
|
||||
if ($dailyMealPlan->status >= 2) {
|
||||
return $this->error('已送达的排餐不可修改', 40001);
|
||||
}
|
||||
$validated = $request->validate([
|
||||
'meal_type' => 'sometimes|integer|in:1,2,3,4,5',
|
||||
'dishes' => 'nullable|array',
|
||||
'special_note' => 'nullable|string',
|
||||
]);
|
||||
$dailyMealPlan->update($validated);
|
||||
return $this->success($dailyMealPlan);
|
||||
}
|
||||
|
||||
public function destroy(DailyMealPlan $dailyMealPlan): JsonResponse
|
||||
{
|
||||
if ($dailyMealPlan->status >= 1) {
|
||||
return $this->error('已备餐的排餐不可删除', 40001);
|
||||
}
|
||||
$dailyMealPlan->delete();
|
||||
return $this->success(null);
|
||||
}
|
||||
|
||||
public function deliver(DailyMealPlan $dailyMealPlan): JsonResponse
|
||||
{
|
||||
if ($dailyMealPlan->status >= 2) {
|
||||
return $this->error('已送达', 40001);
|
||||
}
|
||||
$dailyMealPlan->update([
|
||||
'status' => 2,
|
||||
'deliver_at' => now(),
|
||||
]);
|
||||
return $this->success($dailyMealPlan);
|
||||
}
|
||||
|
||||
public function updateStatus(Request $request, DailyMealPlan $dailyMealPlan): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'status' => 'required|integer|in:0,1,2,3',
|
||||
]);
|
||||
$dailyMealPlan->update($validated);
|
||||
return $this->success($dailyMealPlan);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Meal;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Meal\Dish;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DishController extends Controller
|
||||
{
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$query = Dish::query();
|
||||
$query->when($request->name, fn($q, $v) => $q->where('name', 'like', "%{$v}%"));
|
||||
$query->when($request->category, fn($q, $v) => $q->where('category', $v));
|
||||
$query->when($request->has('status'), fn($q) => $q->where('status', $request->status));
|
||||
|
||||
return $this->paginate($query->latest()->paginate($request->input('per_page', 15)));
|
||||
}
|
||||
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string|max:50',
|
||||
'category' => 'nullable|string|max:30',
|
||||
'description' => 'nullable|string',
|
||||
'image' => 'nullable|string|max:255',
|
||||
'ingredients' => 'nullable|array',
|
||||
'contraindications' => 'nullable|array',
|
||||
'price' => 'sometimes|numeric|min:0',
|
||||
'status' => 'sometimes|integer|in:0,1',
|
||||
]);
|
||||
return $this->success(Dish::create($validated));
|
||||
}
|
||||
|
||||
public function show(Dish $dish): JsonResponse
|
||||
{
|
||||
return $this->success($dish);
|
||||
}
|
||||
|
||||
public function update(Request $request, Dish $dish): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'name' => 'sometimes|string|max:50',
|
||||
'category' => 'nullable|string|max:30',
|
||||
'description' => 'nullable|string',
|
||||
'image' => 'nullable|string|max:255',
|
||||
'ingredients' => 'nullable|array',
|
||||
'contraindications' => 'nullable|array',
|
||||
'price' => 'sometimes|numeric|min:0',
|
||||
'status' => 'sometimes|integer|in:0,1',
|
||||
]);
|
||||
$dish->update($validated);
|
||||
return $this->success($dish);
|
||||
}
|
||||
|
||||
public function destroy(Dish $dish): JsonResponse
|
||||
{
|
||||
$dish->delete();
|
||||
return $this->success(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Meal;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Meal\MealPlanTemplate;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class MealPlanTemplateController extends Controller
|
||||
{
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$query = MealPlanTemplate::query();
|
||||
$query->when($request->name, fn($q, $v) => $q->where('name', 'like', "%{$v}%"));
|
||||
$query->when($request->stage, fn($q, $v) => $q->where('stage', $v));
|
||||
$query->when($request->has('status'), fn($q) => $q->where('status', $request->status));
|
||||
|
||||
return $this->paginate($query->latest()->paginate($request->input('per_page', 15)));
|
||||
}
|
||||
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string|max:50',
|
||||
'stage' => 'nullable|string|max:30',
|
||||
'meals' => 'nullable|array',
|
||||
'status' => 'sometimes|integer|in:0,1',
|
||||
]);
|
||||
return $this->success(MealPlanTemplate::create($validated));
|
||||
}
|
||||
|
||||
public function show(MealPlanTemplate $mealPlanTemplate): JsonResponse
|
||||
{
|
||||
return $this->success($mealPlanTemplate);
|
||||
}
|
||||
|
||||
public function update(Request $request, MealPlanTemplate $mealPlanTemplate): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'name' => 'sometimes|string|max:50',
|
||||
'stage' => 'nullable|string|max:30',
|
||||
'meals' => 'nullable|array',
|
||||
'status' => 'sometimes|integer|in:0,1',
|
||||
]);
|
||||
$mealPlanTemplate->update($validated);
|
||||
return $this->success($mealPlanTemplate);
|
||||
}
|
||||
|
||||
public function destroy(MealPlanTemplate $mealPlanTemplate): JsonResponse
|
||||
{
|
||||
$mealPlanTemplate->delete();
|
||||
return $this->success(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Meal;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Meal\MealReview;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class MealReviewController extends Controller
|
||||
{
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$query = MealReview::query()->with(['mealPlan', 'customer']);
|
||||
$query->when($request->customer_id, fn($q, $v) => $q->where('customer_id', $v));
|
||||
$query->when($request->daily_meal_plan_id, fn($q, $v) => $q->where('daily_meal_plan_id', $v));
|
||||
$query->when($request->score, fn($q, $v) => $q->where('score', $v));
|
||||
|
||||
return $this->paginate($query->latest('created_at')->paginate($request->input('per_page', 15)));
|
||||
}
|
||||
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'daily_meal_plan_id' => 'required|exists:daily_meal_plans,id',
|
||||
'customer_id' => 'required|exists:customers,id',
|
||||
'score' => 'nullable|integer|min:1|max:5',
|
||||
'content' => 'nullable|string',
|
||||
]);
|
||||
return $this->success(MealReview::create($validated));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user