Files
yuezi-saas/backend/app/Http/Controllers/Admin/System/StoreController.php
T
li ee2b1757d0 feat: 员工自助注册+审核流程
- 新增 registration_packages 表:管理员配置注册套餐(名称/角色)
- AuthController 新增 register() 和 registrationPackages() 公开接口
- UserController 新增 approve() / reject() 审核接口
- StoreController 新增 publicList() 公开门店列表
- 前端 /register 注册页:选门店→选岗位套餐→填信息→提交
- 前端 system/registration-packages:套餐 CRUD
- 用户管理页:待审核状态展示 + 通过/拒绝快捷操作
- 登录页底部加「申请注册」跳转链接
- 路由白名单加 /register
2026-03-14 17:39:50 +08:00

99 lines
3.0 KiB
PHP

<?php
namespace App\Http\Controllers\Admin\System;
use App\Http\Controllers\Controller;
use App\Models\Store;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class StoreController extends Controller
{
public function index(Request $request): JsonResponse
{
$query = Store::with('region');
if ($request->keyword) {
$query->where('name', 'like', "%{$request->keyword}%");
}
if ($request->filled('status')) {
$query->where('status', $request->status);
}
$stores = $query->orderByDesc('id')
->paginate($request->input('page_size', 20));
return $this->paginate($stores);
}
public function store(Request $request): JsonResponse
{
$data = $request->validate([
'region_id' => 'nullable|exists:regions,id',
'name' => 'required|string|max:100',
'code' => 'nullable|string|max:20|unique:stores,code',
'address' => 'nullable|string|max:255',
'phone' => 'nullable|string|max:20',
'contact' => 'nullable|string|max:50',
'capacity' => 'nullable|integer|min:0|max:9999',
'description' => 'nullable|string|max:500',
'status' => 'in:0,1',
]);
// capacity 列有 NOT NULL + default(0),空值时用默认值
$data['capacity'] = $data['capacity'] ?? 0;
$store = Store::create($data);
return $this->success($store, '创建成功');
}
public function show(Store $store): JsonResponse
{
$store->load('region');
return $this->success($store);
}
public function update(Request $request, Store $store): JsonResponse
{
$data = $request->validate([
'region_id' => 'nullable|exists:regions,id',
'name' => 'string|max:100',
'code' => 'nullable|string|max:20|unique:stores,code,' . $store->id,
'address' => 'nullable|string|max:255',
'phone' => 'nullable|string|max:20',
'contact' => 'nullable|string|max:50',
'capacity' => 'nullable|integer|min:0|max:9999',
'description' => 'nullable|string|max:500',
'status' => 'in:0,1',
]);
if (array_key_exists('capacity', $data) && $data['capacity'] === null) {
$data['capacity'] = 0;
}
$store->update($data);
return $this->success($store, '更新成功');
}
public function destroy(Store $store): JsonResponse
{
if ($store->users()->exists()) {
return $this->error('该门店下还有员工,无法删除');
}
$store->delete();
return $this->success(null, '删除成功');
}
/**
* 公开门店列表(注册页用,仅返回启用门店的 id/name)
*/
public function publicList(): JsonResponse
{
$stores = Store::withoutGlobalScope('store')
->where('status', 1)
->orderByDesc('id')
->get(['id', 'name']);
return $this->success($stores);
}
}