123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <?php
- namespace app\admin\controller\base\flow;
- /**
- * @title : 审批流管理
- * @desc :
- * @Author : Rock
- * @Date : 2023-08-31 20:14:25
- */
- use app\admin\controller\Base;
- use app\common\model\base\flow\FlowTpl as FlowTplModel;
- use app\common\model\base\flow\FlowTplNode as FlowTplNodeModel;
- use app\common\model\base\flow\FlowTplLink as FlowTplLinkModel;
- class FlowTpl extends Base
- {
- public function initialize()
- {
- parent::initialize();
- $this->model = new FlowTplModel;
- }
- /**
- * @title: 创建查询条件
- * @desc: 描述
- * @return {*}
- * @author: Rock
- * @method: POST
- * @Date: 2023-08-31 20:45:57
- */
- private function createWhere()
- {
- $data = $this->request->param();
- $where = [];
- if(!empty($data['keyword'])){
- $where[] = ['title','LIKE',"%".$data['keyword']."%"];
- }
- return $where;
- }
- /**
- * @title: 列表
- * @desc: 描述
- * @param {int} {pageNo} {1} {页码,传0则不分页}
- * @param {int} {pageSize} {10} {每页数量}
- * @return {*}
- * @author: Rock
- * @method: POST
- * @Date: 2023-08-31 20:46:27
- */
- public function getList(int $pageNo=1,int $pageSize=10)
- {
- $where = $this->createWhere();
- if($pageNo){
- $list = $this->model->where($where)->paginate(['page'=>$pageNo,'list_rows'=>$pageSize]);
- return pageRes(1,"获取成功",$list->total(),$list->items());
- }else{
- $list = $this->model->where($where)->select();
- return res(1,"获取成功",$list);
- }
- }
- /**
- * @title: 获取审批流信息
- * @desc: 描述
- * @param {int} {id} {} {审批流ID}
- * @return {*}
- * @author: Rock
- * @method: POST
- * @Date: 2023-09-02 09:41:29
- */
- public function getInfo(int $id=0)
- {
- $info = $this->model->where('id',$id)->with(['nodeList','linkList'])->find();
- return res(1,"获取成功",$info);
- }
- /**
- * @title: 新增/修改流程
- * @desc: 描述
- * @return {*}
- * @author: Rock
- * @method: POST
- * @Date: 2023-08-31 20:47:17
- */
- public function doEdit()
- {
- $data = $this->request->param();
- $nodeList = $data['nodeList']??[];
- $linkList = $data['linkList']??[];
- $tpl_id = $data['id']??0;
- try{
- FlowTplModel::startTrans();
- $this->model->replace()->save($data);
- $tpl_id = $this->model->id;
- // 删除旧的
- FlowTplNodeModel::where('tpl_id',$tpl_id)->delete();
- FlowTplLinkModel::where('tpl_id',$tpl_id)->delete();
- // 创建新的
- foreach($nodeList as &$nodeItem){
- $nodeItem['tpl_id'] = $tpl_id;
- }
- foreach($linkList as &$linkItem){
- $linkItem['tpl_id'] = $tpl_id;
- }
- (new FlowTplNodeModel)->insertAll($nodeList);
- (new FlowTplLinkModel)->insertAll($linkList);
- FlowTplModel::commit();
- return res(1,"保存成功");
- }catch(\Exception $e){
- FlowTplModel::rollback();
- return res(2,"保存失败",$e->getMessage(),$e->getTrace());
- }
-
- }
- /**
- * @title: 删除审批流
- * @desc: 描述
- * @param {int} {id} {} {流程ID}
- * @return {*}
- * @author: Rock
- * @method: POST
- * @Date: 2023-08-31 20:47:45
- */
- public function doDelete(int $id=0)
- {
- try{
- FlowTplModel::startTrans();
- $this->model->where('id',$id)->delete();
- FlowTplNodeModel::where('tpl_id',$id)->delete();
- FlowTplLinkModel::where('tpl_id',$id)->delete();
- FlowTplModel::commit();
- return res(1,"删除成功");
- }catch(\Exception $e){
- FlowTplModel::rollback();
- return res(2,"删除失败",$e->getMessage(),$e->getTrace());
- }
- }
- }
|