refactor: fix directory structure and namespaces for webman conventions
- Rename directories to lowercase: Controller→controller, Model→model, Service→service, Util→util, Bootstrap→bootstrap
- Update all namespaces from App\Xxx to app\xxx (webman convention)
- Update all import statements across the codebase
- Update route.php to use lowercase namespaces
- Remove unused CompanyFeishuApp model
- Comment out unimplemented controller routes
Following webman 2.x framework conventions:
- Models: app\model\{ClassName}
- Controllers: app\controller\{ClassName}
- Services: app\service\{ClassName}
- Utils: app\util\{ClassName}
- Middleware: app\middleware\{ClassName}
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,134 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Service\ApprovalService;
|
||||
use Webman\Http\Request;
|
||||
use Webman\Http\Response;
|
||||
|
||||
class ApprovalController extends BaseController
|
||||
{
|
||||
private ApprovalService $approvalService;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->approvalService = new ApprovalService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取审批列表
|
||||
*/
|
||||
public function list(Request $request): Response
|
||||
{
|
||||
$type = $request->input('type', 'my');
|
||||
$page = (int) $request->input('page', 1);
|
||||
$pageSize = (int) $request->input('page_size', 20);
|
||||
|
||||
$userId = $this->getUserId($request);
|
||||
|
||||
if (!$userId) {
|
||||
return $this->error('用户未登录', 401);
|
||||
}
|
||||
|
||||
$result = $this->approvalService->getList($userId, $type, $page, $pageSize);
|
||||
|
||||
return $this->success($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取审批详情
|
||||
*/
|
||||
public function detail(Request $request): Response
|
||||
{
|
||||
$id = $request->route('id');
|
||||
|
||||
$order = \App\Model\ApprovalOrder::with(['flow', 'applicant', 'records.approver'])
|
||||
->findOrFail($id);
|
||||
|
||||
return $this->success($order);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交审批
|
||||
*/
|
||||
public function submit(Request $request): Response
|
||||
{
|
||||
$data = $request->all();
|
||||
$userId = $this->getUserId($request);
|
||||
|
||||
if (!$userId) {
|
||||
return $this->error('用户未登录', 401);
|
||||
}
|
||||
|
||||
$data['applicant_id'] = $userId;
|
||||
|
||||
try {
|
||||
$order = $this->approvalService->submit($data);
|
||||
return $this->success($order);
|
||||
} catch (\Exception $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 审批通过
|
||||
*/
|
||||
public function approve(Request $request): Response
|
||||
{
|
||||
$id = $request->route('id');
|
||||
$comment = $request->post('comment');
|
||||
$userId = $this->getUserId($request);
|
||||
|
||||
if (!$userId) {
|
||||
return $this->error('用户未登录', 401);
|
||||
}
|
||||
|
||||
try {
|
||||
$order = $this->approvalService->approve((int) $id, $userId, $comment);
|
||||
return $this->success($order);
|
||||
} catch (\Exception $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 审批拒绝
|
||||
*/
|
||||
public function reject(Request $request): Response
|
||||
{
|
||||
$id = $request->route('id');
|
||||
$comment = $request->post('comment');
|
||||
$userId = $this->getUserId($request);
|
||||
|
||||
if (!$userId) {
|
||||
return $this->error('用户未登录', 401);
|
||||
}
|
||||
|
||||
try {
|
||||
$order = $this->approvalService->reject((int) $id, $userId, $comment);
|
||||
return $this->success($order);
|
||||
} catch (\Exception $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 撤销申请
|
||||
*/
|
||||
public function cancel(Request $request): Response
|
||||
{
|
||||
$id = $request->route('id');
|
||||
$userId = $this->getUserId($request);
|
||||
|
||||
if (!$userId) {
|
||||
return $this->error('用户未登录', 401);
|
||||
}
|
||||
|
||||
try {
|
||||
$order = $this->approvalService->cancel((int) $id, $userId);
|
||||
return $this->success($order);
|
||||
} catch (\Exception $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Webman\Http\Request;
|
||||
use Webman\Http\Response;
|
||||
|
||||
class BusinessTripController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 获取出差列表
|
||||
*/
|
||||
public function list(Request $request): Response
|
||||
{
|
||||
$type = $request->input('type', 'my');
|
||||
|
||||
// TODO: 从数据库获取出差列表
|
||||
return $this->success([
|
||||
'list' => [],
|
||||
'total' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取出差详情
|
||||
*/
|
||||
public function detail(Request $request): Response
|
||||
{
|
||||
$id = $request->route('id');
|
||||
|
||||
// TODO: 从数据库获取出差详情
|
||||
return $this->success([
|
||||
'id' => $id,
|
||||
'title' => '测试出差',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交出差申请
|
||||
*/
|
||||
public function apply(Request $request): Response
|
||||
{
|
||||
$data = $request->all();
|
||||
|
||||
// TODO: 保存出差数据并创建审批流程
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新出差申请
|
||||
*/
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$id = $request->route('id');
|
||||
$data = $request->all();
|
||||
|
||||
// TODO: 更新出差数据
|
||||
return $this->success();
|
||||
}
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
class CompanyFeishuApp extends Model
|
||||
{
|
||||
protected $table = 'company_feishu_apps';
|
||||
|
||||
protected $fillable = [
|
||||
'company_id',
|
||||
'system_id',
|
||||
'name',
|
||||
'tenant_key',
|
||||
'app_id',
|
||||
'app_secret',
|
||||
'encrypt_key',
|
||||
'verification_token',
|
||||
'base_uri',
|
||||
'callback_url',
|
||||
'mobile_callback_url',
|
||||
'scopes',
|
||||
'state',
|
||||
'sort',
|
||||
'status',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'company_id' => 'integer',
|
||||
'system_id' => 'integer',
|
||||
'sort' => 'integer',
|
||||
'status' => 'integer',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'app_secret',
|
||||
'encrypt_key',
|
||||
'verification_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* 关联公司
|
||||
*/
|
||||
public function company()
|
||||
{
|
||||
return $this->belongsTo(Company::class, 'company_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取启用的应用
|
||||
*/
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->where('status', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据系统ID查找
|
||||
*/
|
||||
public function scopeBySystemId($query, int $systemId)
|
||||
{
|
||||
return $query->where('system_id', $systemId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取X-Server应用
|
||||
*/
|
||||
public function scopeXServer($query)
|
||||
{
|
||||
return $query->where('system_id', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取工单应用
|
||||
*/
|
||||
public function scopeTicket($query)
|
||||
{
|
||||
return $query->where('system_id', 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取CRM应用
|
||||
*/
|
||||
public function scopeCrm($query)
|
||||
{
|
||||
return $query->where('system_id', 3);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
namespace app\controller;
|
||||
|
||||
use App\Util\JwtUtil;
|
||||
use app\util\JwtUtil;
|
||||
use Webman\Http\Request;
|
||||
use Webman\Http\Response;
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
namespace app\controller;
|
||||
|
||||
use Webman\Http\Request;
|
||||
use Webman\Http\Response;
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
namespace app\controller;
|
||||
|
||||
use Webman\Http\Request;
|
||||
use Webman\Http\Response;
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Middleware;
|
||||
namespace app\middleware;
|
||||
|
||||
use App\Util\JwtUtil;
|
||||
use app\util\JwtUtil;
|
||||
use Webman\Http\Request;
|
||||
use Webman\Http\Response;
|
||||
use support\Log;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Middleware;
|
||||
namespace app\middleware;
|
||||
|
||||
use Webman\Http\Request;
|
||||
use Webman\Http\Response;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model;
|
||||
namespace app\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model;
|
||||
namespace app\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model;
|
||||
namespace app\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model;
|
||||
namespace app\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model;
|
||||
namespace app\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
@@ -78,9 +78,9 @@ class Company extends Model
|
||||
public function getDefaultFeishuApp(): ?array
|
||||
{
|
||||
$sql = "SELECT * FROM company_feishu_apps WHERE company_id = ? AND system_id = 1 AND status = 1 ORDER BY sort ASC LIMIT 1";
|
||||
$stmt = \App\Util\Db::connection()->getPdo()->prepare($sql);
|
||||
$stmt = \app\util\Db::connection()->getPdo()->prepare($sql);
|
||||
$stmt->execute([$this->id]);
|
||||
return $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
return $stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,8 +89,8 @@ class Company extends Model
|
||||
public function getFeishuApps(): array
|
||||
{
|
||||
$sql = "SELECT * FROM company_feishu_apps WHERE company_id = ? AND status = 1 ORDER BY sort";
|
||||
$stmt = \App\Util\Db::connection()->getPdo()->prepare($sql);
|
||||
$stmt = \app\util\Db::connection()->getPdo()->prepare($sql);
|
||||
$stmt->execute([$this->id]);
|
||||
return $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model;
|
||||
namespace app\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
namespace app\service;
|
||||
|
||||
use App\Model\ApprovalFlow;
|
||||
use App\Model\ApprovalNode;
|
||||
use App\Model\ApprovalOrder;
|
||||
use App\Model\ApprovalRecord;
|
||||
use App\Model\User;
|
||||
use Illuminate\Database\DatabaseManager;
|
||||
use App\Util\Db;
|
||||
use app\model\ApprovalFlow;
|
||||
use app\model\ApprovalNode;
|
||||
use app\model\ApprovalOrder;
|
||||
use app\model\ApprovalRecord;
|
||||
use app\model\User;
|
||||
use app\util\Db;
|
||||
use Illuminate\Database\Connection;
|
||||
|
||||
class ApprovalService
|
||||
@@ -1,10 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
namespace app\service;
|
||||
|
||||
use App\Model\Company;
|
||||
use App\Model\User;
|
||||
use App\Util\Db;
|
||||
use app\model\Company;
|
||||
use app\model\User;
|
||||
use app\util\Db;
|
||||
use support\Cache;
|
||||
|
||||
class FeishuService
|
||||
@@ -49,7 +49,7 @@ class FeishuService
|
||||
$sql = "SELECT * FROM company_feishu_apps WHERE id = ? AND status = 1";
|
||||
$stmt = Db::connection()->getPdo()->prepare($sql);
|
||||
$stmt->execute([$appId]);
|
||||
$app = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$app = $stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$app) {
|
||||
throw new \Exception('飞书应用配置不存在');
|
||||
@@ -66,7 +66,7 @@ class FeishuService
|
||||
$sql = "SELECT * FROM company_feishu_apps WHERE company_id = ? AND system_id = 1 AND status = 1 ORDER BY sort ASC LIMIT 1";
|
||||
$stmt = Db::connection()->getPdo()->prepare($sql);
|
||||
$stmt->execute([$companyId]);
|
||||
$app = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$app = $stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$app) {
|
||||
throw new \Exception('未配置飞书应用');
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Util;
|
||||
namespace app\util;
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
use Illuminate\Events\Dispatcher;
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Util;
|
||||
namespace app\util;
|
||||
|
||||
use Firebase\JWT\JWT;
|
||||
use Firebase\JWT\Key;
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Util;
|
||||
namespace app\util;
|
||||
|
||||
/**
|
||||
* 多语言翻译类
|
||||
+22
-22
@@ -5,34 +5,34 @@ use Webman\Route;
|
||||
// API 路由
|
||||
Route::group('/api/v1', function () {
|
||||
// 认证路由
|
||||
Route::post('/auth/login', [App\Controller\AuthController::class, 'login']);
|
||||
Route::post('/auth/feishu-login', [App\Controller\AuthController::class, 'feishuLogin']);
|
||||
Route::post('/auth/login', [app\controller\AuthController::class, 'login']);
|
||||
Route::post('/auth/feishu-login', [app\controller\AuthController::class, 'feishuLogin']);
|
||||
|
||||
// 用户路由(需要认证)
|
||||
Route::group(function () {
|
||||
Route::get('/user/info', [App\Controller\UserController::class, 'info']);
|
||||
Route::get('/user/menu', [App\Controller\UserController::class, 'menu']);
|
||||
Route::get('/user/companies', [App\Controller\UserController::class, 'companies']);
|
||||
Route::post('/user/switch-company', [App\Controller\UserController::class, 'switchCompany']);
|
||||
Route::get('/user/info', [app\controller\UserController::class, 'info']);
|
||||
Route::get('/user/menu', [app\controller\UserController::class, 'menu']);
|
||||
Route::get('/user/companies', [app\controller\UserController::class, 'companies']);
|
||||
Route::post('/user/switch-company', [app\controller\UserController::class, 'switchCompany']);
|
||||
});
|
||||
|
||||
// 审批路由
|
||||
Route::group(function () {
|
||||
Route::get('/approval/list', [App\Controller\ApprovalController::class, 'list']);
|
||||
Route::get('/approval/detail/{id}', [App\Controller\ApprovalController::class, 'detail']);
|
||||
Route::post('/approval/submit', [App\Controller\ApprovalController::class, 'submit']);
|
||||
Route::post('/approval/approve/{id}', [App\Controller\ApprovalController::class, 'approve']);
|
||||
Route::post('/approval/reject/{id}', [App\Controller\ApprovalController::class, 'reject']);
|
||||
Route::post('/approval/cancel/{id}', [App\Controller\ApprovalController::class, 'cancel']);
|
||||
});
|
||||
// 审批路由(待实现)
|
||||
// Route::group(function () {
|
||||
// Route::get('/approval/list', [app\controller\ApprovalController::class, 'list']);
|
||||
// Route::get('/approval/detail/{id}', [app\controller\ApprovalController::class, 'detail']);
|
||||
// Route::post('/approval/submit', [app\controller\ApprovalController::class, 'submit']);
|
||||
// Route::post('/approval/approve/{id}', [app\controller\ApprovalController::class, 'approve']);
|
||||
// Route::post('/approval/reject/{id}', [app\controller\ApprovalController::class, 'reject']);
|
||||
// Route::post('/approval/cancel/{id}', [app\controller\ApprovalController::class, 'cancel']);
|
||||
// });
|
||||
|
||||
// 出差审批路由
|
||||
Route::group(function () {
|
||||
Route::get('/business-trip/list', [App\Controller\BusinessTripController::class, 'list']);
|
||||
Route::get('/business-trip/detail/{id}', [App\Controller\BusinessTripController::class, 'detail']);
|
||||
Route::post('/business-trip/apply', [App\Controller\BusinessTripController::class, 'apply']);
|
||||
Route::put('/business-trip/{id}', [App\Controller\BusinessTripController::class, 'update']);
|
||||
});
|
||||
// 出差审批路由(待实现)
|
||||
// Route::group(function () {
|
||||
// Route::get('/business-trip/list', [app\controller\BusinessTripController::class, 'list']);
|
||||
// Route::get('/business-trip/detail/{id}', [app\controller\BusinessTripController::class, 'detail']);
|
||||
// Route::post('/business-trip/apply', [app\controller\BusinessTripController::class, 'apply']);
|
||||
// Route::put('/business-trip/{id}', [app\controller\BusinessTripController::class, 'update']);
|
||||
// });
|
||||
});
|
||||
|
||||
// 默认路由
|
||||
|
||||
Reference in New Issue
Block a user