新增组织管理模块相关功能
This commit is contained in:
parent
bfc7e8d20b
commit
ad3613f84e
108
app/adminapi/controller/dept/OrgsController.php
Normal file
108
app/adminapi/controller/dept/OrgsController.php
Normal 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\dept;
|
||||
|
||||
|
||||
use app\adminapi\controller\BaseAdminController;
|
||||
use app\adminapi\lists\dept\OrgsLists;
|
||||
use app\adminapi\logic\dept\OrgsLogic;
|
||||
use app\adminapi\validate\dept\OrgsValidate;
|
||||
|
||||
|
||||
/**
|
||||
* Orgs控制器
|
||||
* Class OrgsController
|
||||
* @package app\adminapi\controller
|
||||
*/
|
||||
class OrgsController extends BaseAdminController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取列表
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2023/12/09 10:55
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new OrgsLists());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2023/12/09 10:55
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$params = (new OrgsValidate())->post()->goCheck('add');
|
||||
$result = OrgsLogic::add($params);
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(OrgsLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2023/12/09 10:55
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$params = (new OrgsValidate())->post()->goCheck('edit');
|
||||
$result = OrgsLogic::edit($params);
|
||||
if (true === $result) {
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(OrgsLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2023/12/09 10:55
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$params = (new OrgsValidate())->post()->goCheck('delete');
|
||||
OrgsLogic::delete($params);
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取详情
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2023/12/09 10:55
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$params = (new OrgsValidate())->goCheck('detail');
|
||||
$result = OrgsLogic::detail($params);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
}
|
78
app/adminapi/lists/dept/OrgsLists.php
Normal file
78
app/adminapi/lists/dept/OrgsLists.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?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\dept;
|
||||
|
||||
|
||||
use app\adminapi\lists\BaseAdminDataLists;
|
||||
use app\common\model\dept\Orgs;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Orgs列表
|
||||
* Class OrgsLists
|
||||
* @package app\adminapi\lists
|
||||
*/
|
||||
class OrgsLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author likeadmin
|
||||
* @date 2023/12/09 10:55
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['status'],
|
||||
'%like%' => ['name', 'master'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author likeadmin
|
||||
* @date 2023/12/09 10:55
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return Orgs::where($this->searchWhere)
|
||||
->field(['id', 'name', 'master', 'status'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取数量
|
||||
* @return int
|
||||
* @author likeadmin
|
||||
* @date 2023/12/09 10:55
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return Orgs::where($this->searchWhere)->count();
|
||||
}
|
||||
|
||||
}
|
110
app/adminapi/logic/dept/OrgsLogic.php
Normal file
110
app/adminapi/logic/dept/OrgsLogic.php
Normal file
@ -0,0 +1,110 @@
|
||||
<?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\dept;
|
||||
|
||||
|
||||
use app\common\model\dept\Orgs;
|
||||
use app\common\logic\BaseLogic;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* Orgs逻辑
|
||||
* Class OrgsLogic
|
||||
* @package app\adminapi\logic
|
||||
*/
|
||||
class OrgsLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author likeadmin
|
||||
* @date 2023/12/09 10:55
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
Orgs::create([
|
||||
'name' => $params['name'],
|
||||
'master' => $params['master'],
|
||||
'status' => $params['status']
|
||||
]);
|
||||
|
||||
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/09 10:55
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
Orgs::where('id', $params['id'])->update([
|
||||
'name' => $params['name'],
|
||||
'master' => $params['master'],
|
||||
'status' => $params['status']
|
||||
]);
|
||||
|
||||
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/09 10:55
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
return Orgs::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author likeadmin
|
||||
* @date 2023/12/09 10:55
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
return Orgs::findOrEmpty($params['id'])->toArray();
|
||||
}
|
||||
}
|
100
app/adminapi/validate/dept/OrgsValidate.php
Normal file
100
app/adminapi/validate/dept/OrgsValidate.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?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\dept;
|
||||
|
||||
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
|
||||
/**
|
||||
* Orgs验证器
|
||||
* Class OrgsValidate
|
||||
* @package app\adminapi\validate
|
||||
*/
|
||||
class OrgsValidate extends BaseValidate
|
||||
{
|
||||
|
||||
/**
|
||||
* 设置校验规则
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
'name' => 'require',
|
||||
'master' => 'require',
|
||||
'status' => 'require|integer|in:0,1',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 参数描述
|
||||
* @var string[]
|
||||
*/
|
||||
protected $field = [
|
||||
'id' => 'id',
|
||||
'name' => '组织名称',
|
||||
'master' => '组织负责人',
|
||||
'status' => '组织状态',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加场景
|
||||
* @return OrgsValidate
|
||||
* @author likeadmin
|
||||
* @date 2023/12/09 10:55
|
||||
*/
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->only(['name','master','status']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑场景
|
||||
* @return OrgsValidate
|
||||
* @author likeadmin
|
||||
* @date 2023/12/09 10:55
|
||||
*/
|
||||
public function sceneEdit()
|
||||
{
|
||||
return $this->only(['id','name','master','status']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除场景
|
||||
* @return OrgsValidate
|
||||
* @author likeadmin
|
||||
* @date 2023/12/09 10:55
|
||||
*/
|
||||
public function sceneDelete()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 详情场景
|
||||
* @return OrgsValidate
|
||||
* @author likeadmin
|
||||
* @date 2023/12/09 10:55
|
||||
*/
|
||||
public function sceneDetail()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
}
|
39
app/common/model/dept/Orgs.php
Normal file
39
app/common/model/dept/Orgs.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?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\dept;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
|
||||
/**
|
||||
* Orgs模型
|
||||
* Class Orgs
|
||||
* @package app\common\model
|
||||
*/
|
||||
class Orgs extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
protected $name = 'orgs';
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
public function getStatusAttr($value): string
|
||||
{
|
||||
$status = [1=>'禁用',0=>'正常'];
|
||||
return $status[$value];
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user