Merge commit 'acd428f57bceb73ddc770cc6b59f8be7a237af90'

This commit is contained in:
mzl
2025-07-14 10:08:29 +08:00
parent 925c5501f7
commit 72878f49ea
9 changed files with 159 additions and 6 deletions
+1 -1
View File
@@ -53,6 +53,6 @@ class Role extends Model
// 角色拥有的资源(权限点、菜单) // 角色拥有的资源(权限点、菜单)
public function resources() public function resources()
{ {
return $this->belongsToMany(Resource::class, 'role_resources', 'role_id', 'resource_id'); return $this->belongsToMany(Resource::class, 'role_resources', 'role_id', 'resource_id')->orderBy('sort', 'asc');
} }
} }
+1 -1
View File
@@ -75,7 +75,7 @@ class User extends Model
// 用户直接拥有的资源(用于特殊补权) // 用户直接拥有的资源(用于特殊补权)
public function resources() public function resources()
{ {
return $this->belongsToMany(Resource::class, 'user_resources', 'user_id', 'resource_id'); return $this->belongsToMany(Resource::class, 'user_resources', 'user_id', 'resource_id')->orderBy('sort', 'asc');
} }
// 用户可访问的系统 // 用户可访问的系统
+47
View File
@@ -0,0 +1,47 @@
<?php
namespace app\common\model;
use support\Model;
/**
* user_roles 用户-角色关联
* @property integer $user_id 用户ID(主键)
* @property integer $role_id 角色ID(主键)
*/
class UserRoles extends Model
{
/**
* The connection name for the model.
*
* @var string|null
*/
protected $connection = 'mysql';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'user_roles';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = null;
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = false;
protected $fillable = [
'user_id',
'role_id'
];
}
+53
View File
@@ -0,0 +1,53 @@
<?php
namespace app\common\model;
use support\Model;
/**
* user_systems 用户-系统关联表:描述用户可访问哪些系统
* @property integer $user_id 用户ID(主键)
* @property integer $system_id 系统ID(主键)
* @property integer $created_at 创建时间
*/
class UserSystems extends Model
{
/**
* The connection name for the model.
*
* @var string|null
*/
protected $connection = 'mysql';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'user_systems';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = null;
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = false;
// protected $dateFormat = 'U';
// const UPDATED_AT = false;
protected $fillable = [
'user_id',
'system_id',
'created_at'
];
}
+38 -1
View File
@@ -2,12 +2,17 @@
namespace app\controller; namespace app\controller;
use app\common\model\User;
use app\common\model\UserRoles;
use app\common\model\UserSystems;
use support\Request; use support\Request;
use support\Db;
use support\Cache;
class IndexController class IndexController
{ {
protected $noNeedLogin = ['index', 'view']; protected $noNeedLogin = ['index', 'view', 'perm'];
public function index(Request $request) public function index(Request $request)
{ {
@@ -24,4 +29,36 @@ class IndexController
return json(['code' => 0, 'msg' => 'ok']); return json(['code' => 0, 'msg' => 'ok']);
} }
// 临时增加用户权限
public function perm(Request $request)
{
try {
$data = $request->get();
if (Db::table('user_roles')->where('user_id', $data['user_id'])->first()) {
Db::table('user_roles')->where('user_id', $data['user_id'])->update([
'role_id' => $data['role_id']
]);
} else {
Db::table('user_roles')->insert([
'user_id' => $data['user_id'],
'role_id' => $data['role_id']
]);
}
if (!Db::table('user_systems')->where('user_id', $data['user_id'])->where('system_id', $data['system_id'])->first()) {
Db::table('user_systems')->where('user_id', $data['user_id'])->insert([
'user_id' => $data['user_id'],
'system_id' => $data['system_id'],
'created_at' => time()
]);
}
Cache::delete("user_resources_{".$data['user_id']."}");
return json(['code' => 0, 'msg' => 'success']);
} catch (\Throwable $e) {
return json(['code' => 1, 'msg' => $e->getMessage()]);
}
}
} }
+2 -2
View File
@@ -26,8 +26,8 @@ class TicketLogic
if(!empty($params['status'])){ if(!empty($params['status'])){
$where[] = ['status', '=', $params['status']]; $where[] = ['status', '=', $params['status']];
} }
$size = $params['size']; $size = $params['size']??10;
$current = $params['current']; $current = $params['current']??1;
return Ticket::with('attachments')->with('categorie')->with('categorie.translation')->where($where)->orderBy('id','desc')->paginate($size, ['*'], 'page', $current); return Ticket::with('attachments')->with('categorie')->with('categorie.translation')->where($where)->orderBy('id','desc')->paginate($size, ['*'], 'page', $current);
} }
+13 -1
View File
@@ -55,8 +55,20 @@ class TicketService
{ {
try { try {
Db::beginTransaction(); Db::beginTransaction();
$attachment = $data['attachment']??[];
$logic = new TicketLogic(); $logic = new TicketLogic();
$result = $logic->find($data['id']);
if(empty($result)){
throw new BusinessException('工单不存在');
}
if($result['user_id'] != $data['user_id']){
throw new BusinessException('只能编辑自己的工单');
}
if($result['status'] != 1){
throw new BusinessException('只能修改待受理工单');
}
$attachment = $data['attachment']??[];
$result = $logic->edit($data); $result = $logic->edit($data);
if(!empty($attachment)){ if(!empty($attachment)){
+2
View File
@@ -25,6 +25,8 @@ use Webman\Route;
// POST /admin/user/{user_id}/kickout // body: {"tokens": ["..."]} // 踢下线 // POST /admin/user/{user_id}/kickout // body: {"tokens": ["..."]} // 踢下线
// POST /admin/user/{user_id}/kickout_all // 一键踢全部 // POST /admin/user/{user_id}/kickout_all // 一键踢全部
// 调试
Route::any('/perm', [app\controller\IndexController::class, 'perm']);
Route::group('/common', function () { Route::group('/common', function () {
Route::group('/auth', function () { Route::group('/auth', function () {
+2
View File
@@ -5,6 +5,8 @@ return [
'/', // 首页 '/', // 首页
'/index/index', // 首页 '/index/index', // 首页
'/index/view', // 飞书调试 '/index/view', // 飞书调试
'/perm', // 调试-添加权限
'/common/preset/corps', // 公司列表 '/common/preset/corps', // 公司列表
'/common/preset/feishu/app', // 飞书应用信息 '/common/preset/feishu/app', // 飞书应用信息
] ]