add flow_type moudle

This commit is contained in:
weiz 2024-01-31 14:02:22 +08:00
parent 8e8b26ded0
commit 2986e5fe15
5 changed files with 516 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\oa;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\oa\FlowTypeLists;
use app\adminapi\logic\oa\FlowTypeLogic;
use app\adminapi\validate\oa\FlowTypeValidate;
/**
* 审批类型控制器
* Class FlowTypeController
* @package app\adminapi\controller\oa
*/
class FlowTypeController extends BaseAdminController
{
/**
* @notes 获取审批类型列表
* @return \think\response\Json
* @author likeadmin
* @date 2024/01/31 10:48
*/
public function lists()
{
return $this->dataLists(new FlowTypeLists());
}
/**
* @notes 添加审批类型
* @return \think\response\Json
* @author likeadmin
* @date 2024/01/31 10:48
*/
public function add()
{
$params = (new FlowTypeValidate())->post()->goCheck('add');
$result = FlowTypeLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(FlowTypeLogic::getError());
}
/**
* @notes 编辑审批类型
* @return \think\response\Json
* @author likeadmin
* @date 2024/01/31 10:48
*/
public function edit()
{
$params = (new FlowTypeValidate())->post()->goCheck('edit');
$result = FlowTypeLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(FlowTypeLogic::getError());
}
/**
* @notes 删除审批类型
* @return \think\response\Json
* @author likeadmin
* @date 2024/01/31 10:48
*/
public function delete()
{
$params = (new FlowTypeValidate())->post()->goCheck('delete');
FlowTypeLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取审批类型详情
* @return \think\response\Json
* @author likeadmin
* @date 2024/01/31 10:48
*/
public function detail()
{
$params = (new FlowTypeValidate())->goCheck('detail');
$result = FlowTypeLogic::detail($params);
return $this->data($result);
}
}

View File

@ -0,0 +1,88 @@
<?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\oa;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\dept\Dept;
use app\common\model\dept\Orgs;
use app\common\model\oa\FlowType;
use app\common\lists\ListsSearchInterface;
/**
* 审批类型列表
* Class FlowTypeLists
* @package app\adminapi\listsoa
*/
class FlowTypeLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2024/01/31 10:48
*/
public function setSearch(): array
{
return [
'=' => ['type'],
'%like%' => ['title'],
];
}
/**
* @notes 获取审批类型列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2024/01/31 10:48
*/
public function lists(): array
{
return FlowType::where($this->searchWhere)
->field(['id', 'type', 'title', 'name', 'org_id', 'department_ids', 'status'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function($data){
$org = Orgs::field('name')->where('id',$data['org_id'])->findOrEmpty();
$dept = Dept::where('id','in',$data['department_ids'])->column('name');
$data['org_name'] = $org['name'];
$data['dept_name'] = implode(',',$dept);
$data['type_text'] = $data->type_text;
$data['status_text'] = $data->status_text;
unset($data['org_id'],$data['department_ids']);
})
->toArray();
}
/**
* @notes 获取审批类型数量
* @return int
* @author likeadmin
* @date 2024/01/31 10:48
*/
public function count(): int
{
return FlowType::where($this->searchWhere)->count();
}
}

View File

@ -0,0 +1,124 @@
<?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\oa;
use app\common\model\dept\Dept;
use app\common\model\dept\Orgs;
use app\common\model\oa\FlowType;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 审批类型逻辑
* Class FlowTypeLogic
* @package app\adminapi\logic\oa
*/
class FlowTypeLogic extends BaseLogic
{
/**
* @notes 添加审批类型
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/01/31 10:48
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
FlowType::create([
'type' => $params['type'],
'title' => $params['title'],
'name' => $params['name'],
'org_id' => $params['org_id'],
'department_ids' => implode(',',$params['department_ids']),
'status' => 2
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑审批类型
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/01/31 10:48
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
FlowType::where('id', $params['id'])->update([
'type' => $params['type'],
'title' => $params['title'],
'name' => $params['name'],
'org_id' => $params['org_id'],
'department_ids' => implode(',',$params['department_ids']),
'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 2024/01/31 10:48
*/
public static function delete(array $params): bool
{
return FlowType::destroy($params['id']);
}
/**
* @notes 获取审批类型详情
* @param $params
* @return array
* @author likeadmin
* @date 2024/01/31 10:48
*/
public static function detail($params): array
{
$data = FlowType::field('id,type,title,name,org_id,department_ids,status')->findOrEmpty($params['id']);
$org = Orgs::field('name')->where('id',$data['org_id'])->findOrEmpty();
$dept = Dept::where('id','in',$data['department_ids'])->column('name');
$data['org_name'] = $org['name'];
$data['dept_name'] = implode(',',$dept);
$data['type_text'] = $data->type_text;
$data['status_text'] = $data->status_text;
$data['department_ids'] = explode(',',$data['department_ids']);
return $data->toArray();
}
}

View File

@ -0,0 +1,153 @@
<?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\oa;
use app\common\model\dept\Dept;
use app\common\model\dept\Orgs;
use app\common\model\dict\DictData;
use app\common\validate\BaseValidate;
/**
* 审批类型验证器
* Class FlowTypeValidate
* @package app\adminapi\validate\oa
*/
class FlowTypeValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'type' => 'require|checkType',
'title' => 'require',
'name' => 'require',
'org_id' => 'require|checkOrg',
'department_ids' => 'require|checkDepartmentIds',
'status' => 'require|checkStatus',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'type' => '所属分类',
'title' => '名称',
'name' => '标识',
'org_id' => '应用组织',
'department_ids' => '应用部门',
'status' => '状态',
];
/**
* @notes 添加场景
* @return FlowTypeValidate
* @author likeadmin
* @date 2024/01/31 10:48
*/
public function sceneAdd()
{
return $this->remove('id',true)->remove('status',true);
}
/**
* @notes 编辑场景
* @return FlowTypeValidate
* @author likeadmin
* @date 2024/01/31 10:48
*/
public function sceneEdit()
{
return $this->only(['id','type','title','name','org_id','department_ids','status']);
}
/**
* @notes 删除场景
* @return FlowTypeValidate
* @author likeadmin
* @date 2024/01/31 10:48
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return FlowTypeValidate
* @author likeadmin
* @date 2024/01/31 10:48
*/
public function sceneDetail()
{
return $this->only(['id']);
}
public function checkType($value): bool|string
{
$dict = DictData::where('type_value','flow_type')->column('value');
if(!in_array($value,$dict)){
return '所属分类无效';
}
return true;
}
public function checkOrg($value): bool|string
{
$data = Orgs::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '组织不存在';
}
return true;
}
public function checkDepartmentIds($value,$rule,$data): bool|string
{
if(!is_array($value)){
return '应用部门数据格式错误';
}
foreach($value as $v){
$dept = Dept::where('id',$v)->findOrEmpty();
if($dept->isEmpty()){
return '部门不存在';
}
if($dept['org_id'] != $data['org_id']) {
return '部门信息无效';
}
}
return true;
}
public function checkStatus($value): bool|string
{
$dict = DictData::where('type_value','flow_type_status')->column('value');
if(!in_array($value,$dict)){
return '状态值无效';
}
return true;
}
}

View File

@ -0,0 +1,43 @@
<?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\oa;
use app\common\model\BaseModel;
use app\common\model\dict\DictData;
use think\model\concern\SoftDelete;
/**
* 审批类型模型
* Class FlowType
* @package app\common\model\oa
*/
class FlowType extends BaseModel
{
use SoftDelete;
protected $name = 'flow_type';
protected $deleteTime = 'delete_time';
public function getTypeTextAttr($value,$data){
$dict = DictData::where('type_value','flow_type')->column('name','value');
return !empty($data['type']) ? $dict[$data['type']] : '';
}
public function getStatusTextAttr($value,$data){
$dict = DictData::where('type_value','flow_type_status')->column('name','value');
return !empty($data['status']) ? $dict[$data['status']] : '';
}
}