This commit is contained in:
yaooo 2023-12-13 15:22:59 +08:00
commit 9ca70a6b35
5 changed files with 432 additions and 0 deletions

View File

@ -0,0 +1,108 @@
<?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\adminapi\controller\project;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\project\ProjectRoleSetLists;
use app\adminapi\logic\project\ProjectRoleSetLogic;
use app\adminapi\validate\project\ProjectRoleSetValidate;
/**
* 项目角色设置控制器
* Class ProjectRoleSetController
* @package app\adminapi\controller\project
*/
class ProjectRoleSetController extends BaseAdminController
{
/**
* @notes 获取项目角色设置列表
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/13 14:23
*/
public function lists()
{
return $this->dataLists(new ProjectRoleSetLists());
}
/**
* @notes 添加项目角色设置
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/13 14:23
*/
public function add()
{
$params = (new ProjectRoleSetValidate())->post()->goCheck('add');
$result = ProjectRoleSetLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(ProjectRoleSetLogic::getError());
}
/**
* @notes 编辑项目角色设置
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/13 14:23
*/
public function edit()
{
$params = (new ProjectRoleSetValidate())->post()->goCheck('edit');
$result = ProjectRoleSetLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(ProjectRoleSetLogic::getError());
}
/**
* @notes 删除项目角色设置
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/13 14:23
*/
public function delete()
{
$params = (new ProjectRoleSetValidate())->post()->goCheck('delete');
ProjectRoleSetLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取项目角色设置详情
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/13 14:23
*/
public function detail()
{
$params = (new ProjectRoleSetValidate())->goCheck('detail');
$result = ProjectRoleSetLogic::detail($params);
return $this->data($result);
}
}

View File

@ -0,0 +1,77 @@
<?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\adminapi\lists\project;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\project\ProjectRoleSet;
use app\common\lists\ListsSearchInterface;
/**
* 项目角色设置列表
* Class ProjectRoleSetLists
* @package app\adminapi\listsproject
*/
class ProjectRoleSetLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2023/12/13 14:23
*/
public function setSearch(): array
{
return [
'%like%' => ['name'],
];
}
/**
* @notes 获取项目角色设置列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2023/12/13 14:23
*/
public function lists(): array
{
return ProjectRoleSet::where($this->searchWhere)
->field(['id', 'name', 'sort'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->toArray();
}
/**
* @notes 获取项目角色设置数量
* @return int
* @author likeadmin
* @date 2023/12/13 14:23
*/
public function count(): int
{
return ProjectRoleSet::where($this->searchWhere)->count();
}
}

View File

@ -0,0 +1,108 @@
<?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\adminapi\logic\project;
use app\common\model\project\ProjectRoleSet;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 项目角色设置逻辑
* Class ProjectRoleSetLogic
* @package app\adminapi\logic\project
*/
class ProjectRoleSetLogic extends BaseLogic
{
/**
* @notes 添加项目角色设置
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/12/13 14:23
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
ProjectRoleSet::create([
'name' => $params['name'],
'sort' => $params['sort'],
]);
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/12/13 14:23
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
ProjectRoleSet::where('id', $params['id'])->update([
'name' => $params['name'],
'sort' => $params['sort'],
]);
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/12/13 14:23
*/
public static function delete(array $params): bool
{
return ProjectRoleSet::destroy($params['id']);
}
/**
* @notes 获取项目角色设置详情
* @param $params
* @return array
* @author likeadmin
* @date 2023/12/13 14:23
*/
public static function detail($params): array
{
return ProjectRoleSet::field('id,name,sort')->findOrEmpty($params['id'])->toArray();
}
}

View File

@ -0,0 +1,105 @@
<?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\adminapi\validate\project;
use app\common\model\project\ProjectRoleSet;
use app\common\validate\BaseValidate;
/**
* 项目角色设置验证器
* Class ProjectRoleSetValidate
* @package app\adminapi\validate\project
*/
class ProjectRoleSetValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'name' => 'require|unique:'.ProjectRoleSet::class,
'sort' => 'require|integer',
];
protected $message = [
'id.require' => '缺少必要参数',
'name.require' => '角色名称不能为空',
'name.unique' => '角色名称已存在',
'sort.require' => '排序号不能为空',
'sort.integer' => '排序号必须为整数',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'name' => '角色名称',
'sort' => '排序号',
];
/**
* @notes 添加场景
* @return ProjectRoleSetValidate
* @author likeadmin
* @date 2023/12/13 14:23
*/
public function sceneAdd()
{
return $this->remove('id',true);
}
/**
* @notes 编辑场景
* @return ProjectRoleSetValidate
* @author likeadmin
* @date 2023/12/13 14:23
*/
public function sceneEdit()
{}
/**
* @notes 删除场景
* @return ProjectRoleSetValidate
* @author likeadmin
* @date 2023/12/13 14:23
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return ProjectRoleSetValidate
* @author likeadmin
* @date 2023/12/13 14:23
*/
public function sceneDetail()
{
return $this->only(['id']);
}
}

View File

@ -0,0 +1,34 @@
<?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\model\project;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* 项目角色设置模型
* Class ProjectRoleSet
* @package app\common\model\project
*/
class ProjectRoleSet extends BaseModel
{
use SoftDelete;
protected $name = 'project_role_set';
protected $deleteTime = 'delete_time';
}