124 lines
3.4 KiB
PHP
124 lines
3.4 KiB
PHP
|
<?php
|
|||
|
// +----------------------------------------------------------------------
|
|||
|
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
|||
|
// +----------------------------------------------------------------------
|
|||
|
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
|||
|
// | 开源版本可自由商用,可去除界面版权logo
|
|||
|
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
|||
|
// | github下载:https://github.com/likeshop-github/likeadmin
|
|||
|
// | 访问官网:https://www.likeadmin.cn
|
|||
|
// | likeadmin团队 版权所有 拥有最终解释权
|
|||
|
// +----------------------------------------------------------------------
|
|||
|
// | author: likeadminTeam
|
|||
|
// +----------------------------------------------------------------------
|
|||
|
|
|||
|
namespace app\common\logic\user;
|
|||
|
|
|||
|
|
|||
|
use app\common\model\user\UserMenu;
|
|||
|
use app\common\logic\BaseLogic;
|
|||
|
use think\facade\Db;
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* 用户菜单逻辑
|
|||
|
* Class UserMenuLogic
|
|||
|
* @package app\adminapi\logic\user
|
|||
|
*/
|
|||
|
class UserMenuLogic extends BaseLogic
|
|||
|
{
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* @notes 添加用户菜单
|
|||
|
* @param array $params
|
|||
|
* @return bool
|
|||
|
* @author likeadmin
|
|||
|
* @date 2023/08/23 09:38
|
|||
|
*/
|
|||
|
public static function add(array $params): bool
|
|||
|
{
|
|||
|
Db::startTrans();
|
|||
|
try {
|
|||
|
UserMenu::create([
|
|||
|
'pid' => $params['pid'],
|
|||
|
'type' => $params['type'],
|
|||
|
'name' => $params['name'],
|
|||
|
'icon' => $params['icon'],
|
|||
|
'sort' => $params['sort'],
|
|||
|
'paths' => $params['paths'],
|
|||
|
'params' => $params['params'],
|
|||
|
'is_show' => $params['is_show'],
|
|||
|
'is_disable' => $params['is_disable'],
|
|||
|
'notes' => $params['notes']??''
|
|||
|
]);
|
|||
|
|
|||
|
Db::commit();
|
|||
|
return true;
|
|||
|
} catch (\Exception $e) {
|
|||
|
Db::rollback();
|
|||
|
self::setError($e->getMessage());
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* @notes 编辑用户菜单
|
|||
|
* @param array $params
|
|||
|
* @return bool
|
|||
|
* @author likeadmin
|
|||
|
* @date 2023/08/23 09:38
|
|||
|
*/
|
|||
|
public static function edit(array $params): bool
|
|||
|
{
|
|||
|
Db::startTrans();
|
|||
|
try {
|
|||
|
UserMenu::where('id', $params['id'])->update([
|
|||
|
'pid' => $params['pid'],
|
|||
|
'type' => $params['type'],
|
|||
|
'name' => $params['name'],
|
|||
|
'icon' => $params['icon'],
|
|||
|
'sort' => $params['sort'],
|
|||
|
'paths' => $params['paths'],
|
|||
|
'params' => $params['params'],
|
|||
|
'is_show' => $params['is_show'],
|
|||
|
'is_disable' => $params['is_disable'],
|
|||
|
'notes' => $params['notes']??''
|
|||
|
]);
|
|||
|
|
|||
|
Db::commit();
|
|||
|
return true;
|
|||
|
} catch (\Exception $e) {
|
|||
|
Db::rollback();
|
|||
|
self::setError($e->getMessage());
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* @notes 删除用户菜单
|
|||
|
* @param array $params
|
|||
|
* @return bool
|
|||
|
* @author likeadmin
|
|||
|
* @date 2023/08/23 09:38
|
|||
|
*/
|
|||
|
public static function delete(array $params): bool
|
|||
|
{
|
|||
|
return UserMenu::destroy($params['id']);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* @notes 获取用户菜单详情
|
|||
|
* @param $params
|
|||
|
* @return array
|
|||
|
* @author likeadmin
|
|||
|
* @date 2023/08/23 09:38
|
|||
|
*/
|
|||
|
public static function detail($params): array
|
|||
|
{
|
|||
|
return UserMenu::findOrEmpty($params['id'])->toArray();
|
|||
|
}
|
|||
|
}
|