随着互联网的发展,越来越多的企业开始使用网络进行业务处理,这就要求企业必须有一套完善的审核流程管理系统来确保业务的安全和规范。在php开发中,thinkphp6框架提供了便捷的审核流程管理功能,本文将介绍如何在thinkphp6中实现审核流程管理。
一、thinkphp6审核流程管理基本思路
thinkphp6的审核流程管理基本思路是通过数据库记录来实现,一般需要创建两个数据表:
流程表:记录审核流程的基本信息,如流程名称、创建者、创建时间等;步骤表:记录审核流程中具体的审核步骤,包括每个审核步骤的名称、状态、处理人、处理时间等。审核流程管理的流程可以简单描述如下:
创建审核流程:管理员在后台创建审核流程,并设置每个审核步骤的名称、处理人等信息;提交审核:用户提交审核申请,系统按照审核流程开始审核;审核流程中的审核步骤:根据流程表和步骤表中记录的信息,自动分配审核人员进行审核;审核结果:审核通过或不通过,最终得出审核结果。二、创建流程表和步骤表
首先,我们需要在数据库中创建流程表和步骤表。
流程表:
create table `tp_flow` ( `id` int(11) not null auto_increment comment 'id', `name` varchar(50) default null comment '流程名称', `create_user_id` int(11) default null comment '创建人id', `create_time` datetime default null comment '创建时间', primary key (`id`)) engine=innodb default charset=utf8 comment='审核流程表';
步骤表:
create table `tp_step` ( `id` int(11) not null auto_increment comment 'id', `flow_id` int(11) default null comment '流程id', `name` varchar(50) default null comment '步骤名称', `status` tinyint(1) default '0' comment '状态:0-未处理,1-已处理', `handler_id` int(11) default null comment '处理人id', `handle_time` datetime default null comment '处理时间', primary key (`id`)) engine=innodb default charset=utf8 comment='审核步骤表';
三、创建模型类
接下来,我们需要创建模型类,定义流程表和步骤表的关系,并实现各种操作方法。
创建流程模型类首先,我们创建流程模型类flowmodel,定义与步骤模型类stepmodel的一对多关系,并提供流程管理相关方法。
// ppmodelflowmodel.phpnamespace appmodel;use thinkmodel;class flowmodel extends model{ protected $table = 'tp_flow'; // 定义与stepmodel的一对多关系 public function steps() { return $this->hasmany('stepmodel', 'flow_id', 'id'); } // 创建审核流程 public function addflow($data) { return $this->save($data); } // 编辑审核流程 public function editflow($id, $data) { return $this->where('id', $id)->update($data); } // 删除审核流程 public function delflow($id) { return $this->where('id', $id)->delete(); } // 按照id获取审核流程详情 public function getflowbyid($id) { return $this->with('steps')->find($id); } // 获取审核流程列表 public function getflowlist() { return $this->with('steps')->select(); }}
2.创建步骤模型类
然后,我们创建步骤模型类stepmodel,定义与流程模型类flowmodel的属于关系,并提供审核步骤相关的方法。
// ppmodelstepmodel.phpnamespace appmodel;use thinkmodel;class stepmodel extends model{ protected $table = 'tp_step'; // 定义与flowmodel的属于关系 public function flow() { return $this->belongsto('flowmodel', 'flow_id'); } // 添加审核步骤 public function addstep($data) { return $this->save($data); } // 编辑审核步骤 public function editstep($id, $data) { return $this->where('id', $id)->update($data); } // 删除审核步骤 public function delstep($id) { return $this->where('id', $id)->delete(); } // 按照id获取审核步骤详情 public function getstepbyid($id) { return $this->find($id); } // 获取审核步骤列表 public function getsteplistbyflowid($flow_id) { return $this->where('flow_id', $flow_id)->select(); } // 更新审核步骤状态 public function updatestepstatus($id, $status, $handler_id, $handle_time) { $data = [ 'status' => $status, 'handler_id' => $handler_id, 'handle_time' => $handle_time, ]; return $this->where('id', $id)->update($data); }}
三、审核流程的实现
在审核流程的实现中,我们需要在控制器或服务层中调用流程和步骤模型类的方法,来完成审核流程的各个步骤。
创建审核流程管理员在后台创建审核流程时,需要先创建流程,然后添加步骤。
// ppcontrollerflowcontroller.phpnamespace appcontroller;use appbasecontroller;use appmodelflowmodel;use appmodelstepmodel;use thinkrequest;class flowcontroller extends basecontroller{ protected $flowmodel; protected $stepmodel; public function __construct(flowmodel $flowmodel, stepmodel $stepmodel) { $this->flowmodel = $flowmodel; $this->stepmodel = $stepmodel; } // 创建审核流程 public function addflow(request $request) { $data = $request->post(); // 添加审核流程 $flow_result = $this->flowmodel->addflow([ 'name' => $data['name'], 'create_user_id' => $this->getcurrentuserid(), 'create_time' => date('y-m-d h:i:s'), ]); if (!$flow_result) { return $this->error('创建审核流程失败!'); } // 添加审核步骤 $step_data = []; foreach ($data['step'] as $key => $value) { $step_data[] = [ 'flow_id' => $this->flowmodel->id, 'name' => $value['name'], 'handler_id' => $value['handler_id'], ]; } $step_result = $this->stepmodel->saveall($step_data); if (!$step_result) { return $this->error('添加审核步骤失败!'); } return $this->success('创建审核流程成功!'); }}
提交审核用户在提交审核申请后,需要自动触发审核流程,让审核流程开始运行。
// ppcontrollerapplycontroller.phpnamespace appcontroller;use appbasecontroller;use appmodelstepmodel;use thinkrequest;class applycontroller extends basecontroller{ protected $stepmodel; public function __construct(stepmodel $stepmodel) { $this->stepmodel = $stepmodel; } // 提交审核 public function submitapply(request $request) { $data = $request->post(); // 获取审核流程的第一步骤 $steps = $this->stepmodel->getsteplistbyflowid($data['flow_id']); if (empty($steps)) { return $this->error('该审核流程未添加步骤!'); } $first_step = $steps[0]; // 更新第一步骤状态 $update_result = $this->stepmodel->updatestepstatus($first_step->id, 1, $this->getcurrentuserid(), date('y-m-d h:i:s')); if (!$update_result) { return $this->error('更新审核步骤状态失败!'); } return $this->success('提交审核成功!'); }}
审核流程中的审核步骤系统按照审核流程中定义的步骤自动分配审核人员进行审核,并记录审核结果。
// ppcontrollerapprovecontroller.phpnamespace appcontroller;use appbasecontroller;use appmodelstepmodel;use thinkrequest;class approvecontroller extends basecontroller{ protected $stepmodel; public function __construct(stepmodel $stepmodel) { $this->stepmodel = $stepmodel; } // 审核步骤 public function approvestep(request $request) { $data = $request->post(); // 获取当前步骤 $step = $this->stepmodel->getstepbyid($data['step_id']); // 更新当前步骤状态 $update_result = $this->stepmodel->updatestepstatus($data['step_id'], $data['status'], $this->getcurrentuserid(), date('y-m-d h:i:s')); if (!$update_result) { return $this->error('更新审核步骤状态失败!'); } // 获取下一步骤 $next_step = $this->stepmodel->where('flow_id', $step->flow_id)->where('id', '>', $data['step_id'])->order('id asc')->find(); if (!$next_step) { return $this->success('已审核完成!'); } // 更新下一步骤状态 $update_result = $this->stepmodel->updatestepstatus($next_step->id, 1, $next_step->handler_id, null); if (!$update_result) { return $this->error('更新审核步骤状态失败!'); } return $this->success('审核通过!'); }}
四、总结
通过以上代码示例,我们可以看到thinkphp6中非常便捷的实现了审核流程管理功能,通过流程表和步骤表的记录管理,以及模型类的方法操作,我们可以快速、简单地完成一个完整的审核流程管理系统。
以上就是thinkphp6中如何进行审核流程管理?的详细内容。