PHP code example of jobsys / approval-module
1. Go to this page and download the library: Download jobsys/approval-module library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jobsys / approval-module example snippets
"Approval" => [
"route_prefix" => "manager", // 路由前缀
"approval_types" => [ // 审核类型列表
'ProjectCreated' => [ // 审核类型名称
'displayName' => '项目创建', // 审核类型显示名称
'type' => 'project-created', // 审核类型标识
'approve_todo' => \App\Notifications\ProjectApproveTodo::class, // 审核待办通知类
'approved_event' => \App\Events\ProjectApproved::class, // 审核结果事件通知类
],
]
]
$project = Project::find(1);
$approvalService->createApprovalTask($project, config('approval.approval_types.ProjectCreated'));
$project = Project::find(1);
ProjectCreated::dispatch($project);
$query = Project::with(['department:id,name'])->when($name, function ($query) use ($name) {
return $query->where('name', 'like', '%' . $name . '%');
})
$pagination = $service->getUserApprovable($query, $this->login_user, $process, $approval_status)->paginate();
// 审核状态
enum ApprovalStatus: string
{
case Pending = 'pending'; //待审核
case Approved = 'approved'; //审核通过
case Rejected = 'rejected'; //审核驳回
case Skipped = 'skipped'; //审核跳过
case Updated = 'updated'; //审核对象已更新
}
//后续节点对于审核对象的可见性
enum ApprovalSubsequentAction: string
{
case Invisible = 'invisible'; //不可见
case Visible = 'visible'; //可见
case Approve = 'approve'; //可审核
}
/**
* 获取前端可用的审核状态选项
* @return array[]
*/
function approval_status_options(): array
/**
* 创建审核任务
* @param Model $approvable
* @param array $config
* @return array
*/
public function createApprovalTask(Model $approvable, array $config): array
/**
* 获取用户待审核的审核对象
* @param Builder $builder
* @param User $user
* @param ApprovalProcess $process
* @param string $status
* @return Builder
*/
public function getUserApprovable(Builder $builder, User $user, ApprovalProcess $process, string $status = ''): Builder
/**
* 审核
* @param User $user
* @param Model $approvable
* @param ApprovalProcess $process
* @param string $approval_status
* @param string $approval_comment
* @param bool $is_snapshot
* @return array
*/
public function approve(User $user, Model $approvable, ApprovalProcess $process, string $approval_status, string $approval_comment = '', bool $is_snapshot = false): array
/**
* 获取当前用户对于某个审核对象的审核任务
* @param User $user
* @param ApprovalProcess $process
* @param Model $approvable
* @return ApprovalTask|null
*/
public function getUserApprovableTask(User $user, ApprovalProcess $process, Model $approvable): ApprovalTask|null
/**
* 为审核对象添加审核历史和详情
* @param ApprovalProcess $process
* @param Model $approvable
* @return void
*/
public function getApprovalDetail(ApprovalProcess $process, Model $approvable): void
bash
# 安装依赖
composer module:enable Approval && php artisan module:publish-migration Approval && php artisan migrate
bash
2014_10_12_000002_create_approval_tables.php # 审核模块数据表