feat: 第三阶段业务模块(服务产康/月嫂/进销存)

- 新增3个migration(15张表): service/nanny/inventory
- 新增15个Model + 13个Controller
- 新增55条API路由(总计212条)
- 新增3个前端API模块 + 11个管理页面
- vite build验证通过
This commit is contained in:
li
2026-03-13 20:29:45 +08:00
parent 16bcd9bcf0
commit e7d4d9b414
46 changed files with 2573 additions and 0 deletions
@@ -0,0 +1,17 @@
<?php
namespace App\Http\Controllers\Admin\Inventory;
use App\Http\Controllers\Controller;
use App\Models\Inventory\Inventory;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class InventoryController extends Controller
{
public function index(Request $request): JsonResponse
{
$query = Inventory::query()->with(['warehouse','material']);
$query->when($request->warehouse_id, fn($q, $v) => $q->where('warehouse_id', $v));
$query->when($request->material_id, fn($q, $v) => $q->where('material_id', $v));
return $this->paginate($query->paginate($request->input('per_page', 50)));
}
}
@@ -0,0 +1,26 @@
<?php
namespace App\Http\Controllers\Admin\Inventory;
use App\Http\Controllers\Controller;
use App\Models\Inventory\Material;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class MaterialController extends Controller
{
public function index(Request $request): JsonResponse
{
$query = Material::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->code, fn($q, $v) => $q->where('code', 'like', "%{$v}%"));
return $this->paginate($query->latest()->paginate($request->input('per_page', 15)));
}
public function store(Request $request): JsonResponse
{
$v = $request->validate(['name'=>'required|string|max:100','code'=>'nullable|string|max:50','category'=>'nullable|string|max:50','unit'=>'nullable|string|max:20','spec'=>'nullable|string|max:100','min_stock'=>'sometimes|integer|min:0','shelf_life_days'=>'nullable|integer|min:1','status'=>'sometimes|integer|in:0,1']);
return $this->success(Material::create($v));
}
public function show(Material $material): JsonResponse { return $this->success($material); }
public function update(Request $request, Material $material): JsonResponse { $v = $request->validate(['name'=>'sometimes|string|max:100','code'=>'nullable|string|max:50','category'=>'nullable|string|max:50','unit'=>'nullable|string|max:20','spec'=>'nullable|string|max:100','min_stock'=>'sometimes|integer|min:0','shelf_life_days'=>'nullable|integer|min:1','status'=>'sometimes|integer|in:0,1']); $material->update($v); return $this->success($material); }
public function destroy(Material $material): JsonResponse { $material->delete(); return $this->success(null); }
}
@@ -0,0 +1,44 @@
<?php
namespace App\Http\Controllers\Admin\Inventory;
use App\Http\Controllers\Controller;
use App\Models\Inventory\PurchaseOrder;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class PurchaseOrderController extends Controller
{
public function index(Request $request): JsonResponse
{
$query = PurchaseOrder::query()->with(['supplier','auditor']);
$query->when($request->order_no, fn($q, $v) => $q->where('order_no', 'like', "%{$v}%"));
$query->when($request->supplier_id, fn($q, $v) => $q->where('supplier_id', $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
{
$v = $request->validate(['order_no'=>'required|string|max:50|unique:purchase_orders','supplier_id'=>'nullable|exists:suppliers,id','total_amount'=>'nullable|numeric|min:0','items'=>'nullable|array','remark'=>'nullable|string']);
$v['status'] = 0; $v['created_by'] = auth()->id();
return $this->success(PurchaseOrder::create($v));
}
public function show(PurchaseOrder $purchaseOrder): JsonResponse { return $this->success($purchaseOrder->load(['supplier','auditor','creator'])); }
public function update(Request $request, PurchaseOrder $purchaseOrder): JsonResponse
{
if ($purchaseOrder->status >= 2) return $this->error('已审批的采购单不可修改', 40001);
$v = $request->validate(['supplier_id'=>'nullable|exists:suppliers,id','total_amount'=>'nullable|numeric|min:0','items'=>'nullable|array','remark'=>'nullable|string']);
$purchaseOrder->update($v);
return $this->success($purchaseOrder);
}
public function audit(Request $request, PurchaseOrder $purchaseOrder): JsonResponse
{
if ($purchaseOrder->status >= 2) return $this->error('已审批', 40001);
$v = $request->validate(['status'=>'required|integer|in:2,4']);
$purchaseOrder->update(['status'=>$v['status'],'audit_user_id'=>auth()->id(),'audit_at'=>now()]);
return $this->success($purchaseOrder);
}
public function destroy(PurchaseOrder $purchaseOrder): JsonResponse
{
if ($purchaseOrder->status >= 2) return $this->error('已审批不可删除', 40001);
$purchaseOrder->delete(); return $this->success(null);
}
}
@@ -0,0 +1,48 @@
<?php
namespace App\Http\Controllers\Admin\Inventory;
use App\Http\Controllers\Controller;
use App\Models\Inventory\StockMovement;
use App\Models\Inventory\Inventory;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class StockMovementController extends Controller
{
public function index(Request $request): JsonResponse
{
$query = StockMovement::query()->with('warehouse');
$query->when($request->warehouse_id, fn($q, $v) => $q->where('warehouse_id', $v));
$query->when($request->type, fn($q, $v) => $q->where('type', $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
{
$v = $request->validate([
'warehouse_id'=>'required|exists:warehouses,id','movement_no'=>'required|string|max:50|unique:stock_movements',
'type'=>'required|integer|in:1,2,3,4','direction'=>'nullable|integer|in:1,2',
'items'=>'nullable|array','related_order'=>'nullable|string|max:50','remark'=>'nullable|string',
]);
$v['status'] = 0; $v['operator_id'] = auth()->id();
return $this->success(StockMovement::create($v));
}
public function show(StockMovement $stockMovement): JsonResponse { return $this->success($stockMovement->load(['warehouse','operator'])); }
public function confirm(StockMovement $stockMovement): JsonResponse
{
if ($stockMovement->status === 1) return $this->error('已确认', 40001);
$stockMovement->update(['status' => 1]);
// 更新库存
if ($stockMovement->items) {
foreach ($stockMovement->items as $item) {
$inv = Inventory::firstOrCreate(
['warehouse_id'=>$stockMovement->warehouse_id,'material_id'=>$item['material_id'],'batch_no'=>$item['batch_no']??null],
['quantity'=>0]
);
$qty = $item['quantity'] ?? 0;
$inv->quantity = $stockMovement->direction === 1 ? $inv->quantity + $qty : $inv->quantity - $qty;
$inv->save();
}
}
return $this->success($stockMovement);
}
}
@@ -0,0 +1,24 @@
<?php
namespace App\Http\Controllers\Admin\Inventory;
use App\Http\Controllers\Controller;
use App\Models\Inventory\Supplier;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class SupplierController extends Controller
{
public function index(Request $request): JsonResponse
{
$query = Supplier::query();
$query->when($request->name, fn($q, $v) => $q->where('name', 'like', "%{$v}%"));
return $this->paginate($query->latest()->paginate($request->input('per_page', 15)));
}
public function store(Request $request): JsonResponse
{
$v = $request->validate(['name'=>'required|string|max:100','contact'=>'nullable|string|max:50','phone'=>'nullable|string|max:20','address'=>'nullable|string|max:255','bank_info'=>'nullable|string|max:255','status'=>'sometimes|integer|in:0,1']);
return $this->success(Supplier::create($v));
}
public function show(Supplier $supplier): JsonResponse { return $this->success($supplier); }
public function update(Request $request, Supplier $supplier): JsonResponse { $v = $request->validate(['name'=>'sometimes|string|max:100','contact'=>'nullable|string|max:50','phone'=>'nullable|string|max:20','address'=>'nullable|string|max:255','bank_info'=>'nullable|string|max:255','status'=>'sometimes|integer|in:0,1']); $supplier->update($v); return $this->success($supplier); }
public function destroy(Supplier $supplier): JsonResponse { $supplier->delete(); return $this->success(null); }
}
@@ -0,0 +1,24 @@
<?php
namespace App\Http\Controllers\Admin\Inventory;
use App\Http\Controllers\Controller;
use App\Models\Inventory\Warehouse;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class WarehouseController extends Controller
{
public function index(Request $request): JsonResponse
{
$query = Warehouse::query()->with('manager');
$query->when($request->name, fn($q, $v) => $q->where('name', 'like', "%{$v}%"));
return $this->paginate($query->latest()->paginate($request->input('per_page', 15)));
}
public function store(Request $request): JsonResponse
{
$v = $request->validate(['name'=>'required|string|max:50','manager_id'=>'nullable|exists:users,id','status'=>'sometimes|integer|in:0,1']);
return $this->success(Warehouse::create($v));
}
public function show(Warehouse $warehouse): JsonResponse { return $this->success($warehouse->load('manager')); }
public function update(Request $request, Warehouse $warehouse): JsonResponse { $v = $request->validate(['name'=>'sometimes|string|max:50','manager_id'=>'nullable|exists:users,id','status'=>'sometimes|integer|in:0,1']); $warehouse->update($v); return $this->success($warehouse); }
public function destroy(Warehouse $warehouse): JsonResponse { $warehouse->delete(); return $this->success(null); }
}