refactor: 重构后端目录结构和命名规范
- 将后端目录名从大写改为小写 (Controller->controller 等) - 将命名空间从 App\ 改为 app\ (符合 webman 官方规范) - 移除不必要的 bootstrap 目录 - 完善出差审批业务功能: - 添加删除草稿功能 - 添加审批操作功能(同意/拒绝) - 完善审批详情页,显示审批人和审批记录 - 前端优化: - 调整列表页行高 - 隐藏底部导航栏 - 仪表盘只显示3个快捷入口 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class User extends Model
|
||||
{
|
||||
protected $table = 'users';
|
||||
|
||||
protected $fillable = [
|
||||
'company_id',
|
||||
'sn',
|
||||
'report_to',
|
||||
'name',
|
||||
'avatar',
|
||||
'sex',
|
||||
'email',
|
||||
'phone',
|
||||
'password',
|
||||
'status',
|
||||
'user_type',
|
||||
'union_id',
|
||||
'feishu_user_id',
|
||||
'feishu_open_id',
|
||||
'tenant_key',
|
||||
'position',
|
||||
'sign_img',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'company_id' => 'integer',
|
||||
'report_to' => 'integer',
|
||||
'sex' => 'integer',
|
||||
'status' => 'integer',
|
||||
'user_type' => 'integer',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'password',
|
||||
];
|
||||
|
||||
/**
|
||||
* 关联公司
|
||||
*/
|
||||
public function company()
|
||||
{
|
||||
return $this->belongsTo(Company::class, 'company_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 上级用户
|
||||
*/
|
||||
public function parent()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'report_to');
|
||||
}
|
||||
|
||||
/**
|
||||
* 下级用户
|
||||
*/
|
||||
public function children()
|
||||
{
|
||||
return $this->hasMany(User::class, 'report_to');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取启用的用户
|
||||
*/
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->where('status', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据公司ID查找
|
||||
*/
|
||||
public function scopeByCompany($query, int $companyId)
|
||||
{
|
||||
return $query->where('company_id', $companyId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据飞书用户ID查找
|
||||
*/
|
||||
public function scopeByFeishuUserId($query, ?string $feishuUserId)
|
||||
{
|
||||
if ($feishuUserId === null) {
|
||||
return $query;
|
||||
}
|
||||
return $query->where('feishu_user_id', $feishuUserId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据飞书 UnionID 查找
|
||||
*/
|
||||
public function scopeByFeishuUnionId($query, ?string $feishuUnionId)
|
||||
{
|
||||
if ($feishuUnionId === null) {
|
||||
return $query;
|
||||
}
|
||||
return $query->where('union_id', $feishuUnionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据OpenID查找
|
||||
*/
|
||||
public function scopeByFeishuOpenId($query, ?string $openId)
|
||||
{
|
||||
if ($openId === null) {
|
||||
return $query;
|
||||
}
|
||||
return $query->where('feishu_open_id', $openId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索用户
|
||||
*/
|
||||
public function scopeSearch($query, ?string $keyword)
|
||||
{
|
||||
if (!$keyword) {
|
||||
return $query;
|
||||
}
|
||||
|
||||
return $query->where(function ($q) use ($keyword) {
|
||||
$q->where('name', 'like', "%{$keyword}%")
|
||||
->orWhere('email', 'like', "%{$keyword}%")
|
||||
->orWhere('phone', 'like', "%{$keyword}%")
|
||||
->orWhere('sn', 'like', "%{$keyword}%");
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user