FlowTpl.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. namespace app\admin\controller\base\flow;
  3. /**
  4. * @title : 审批流管理
  5. * @desc :
  6. * @Author : Rock
  7. * @Date : 2023-08-31 20:14:25
  8. */
  9. use app\admin\controller\Base;
  10. use app\common\model\base\flow\FlowTpl as FlowTplModel;
  11. use app\common\model\base\flow\FlowTplNode as FlowTplNodeModel;
  12. use app\common\model\base\flow\FlowTplLink as FlowTplLinkModel;
  13. class FlowTpl extends Base
  14. {
  15. public function initialize()
  16. {
  17. parent::initialize();
  18. $this->model = new FlowTplModel;
  19. }
  20. /**
  21. * @title: 创建查询条件
  22. * @desc: 描述
  23. * @return {*}
  24. * @author: Rock
  25. * @method: POST
  26. * @Date: 2023-08-31 20:45:57
  27. */
  28. private function createWhere()
  29. {
  30. $data = $this->request->param();
  31. $where = [];
  32. if(!empty($data['keyword'])){
  33. $where[] = ['title','LIKE',"%".$data['keyword']."%"];
  34. }
  35. return $where;
  36. }
  37. /**
  38. * @title: 列表
  39. * @desc: 描述
  40. * @param {int} {pageNo} {1} {页码,传0则不分页}
  41. * @param {int} {pageSize} {10} {每页数量}
  42. * @return {*}
  43. * @author: Rock
  44. * @method: POST
  45. * @Date: 2023-08-31 20:46:27
  46. */
  47. public function getList(int $pageNo=1,int $pageSize=10)
  48. {
  49. $where = $this->createWhere();
  50. if($pageNo){
  51. $list = $this->model->where($where)->paginate(['page'=>$pageNo,'list_rows'=>$pageSize]);
  52. return pageRes(1,"获取成功",$list->total(),$list->items());
  53. }else{
  54. $list = $this->model->where($where)->select();
  55. return res(1,"获取成功",$list);
  56. }
  57. }
  58. /**
  59. * @title: 获取审批流信息
  60. * @desc: 描述
  61. * @param {int} {id} {} {审批流ID}
  62. * @return {*}
  63. * @author: Rock
  64. * @method: POST
  65. * @Date: 2023-09-02 09:41:29
  66. */
  67. public function getInfo(int $id=0)
  68. {
  69. $info = $this->model->where('id',$id)->with(['nodeList','linkList'])->find();
  70. return res(1,"获取成功",$info);
  71. }
  72. /**
  73. * @title: 新增/修改流程
  74. * @desc: 描述
  75. * @return {*}
  76. * @author: Rock
  77. * @method: POST
  78. * @Date: 2023-08-31 20:47:17
  79. */
  80. public function doEdit()
  81. {
  82. $data = $this->request->param();
  83. $nodeList = $data['nodeList']??[];
  84. $linkList = $data['linkList']??[];
  85. $tpl_id = $data['id']??0;
  86. try{
  87. FlowTplModel::startTrans();
  88. $this->model->replace()->save($data);
  89. $tpl_id = $this->model->id;
  90. // 删除旧的
  91. FlowTplNodeModel::where('tpl_id',$tpl_id)->delete();
  92. FlowTplLinkModel::where('tpl_id',$tpl_id)->delete();
  93. // 创建新的
  94. foreach($nodeList as &$nodeItem){
  95. $nodeItem['tpl_id'] = $tpl_id;
  96. }
  97. foreach($linkList as &$linkItem){
  98. $linkItem['tpl_id'] = $tpl_id;
  99. }
  100. (new FlowTplNodeModel)->insertAll($nodeList);
  101. (new FlowTplLinkModel)->insertAll($linkList);
  102. FlowTplModel::commit();
  103. return res(1,"保存成功");
  104. }catch(\Exception $e){
  105. FlowTplModel::rollback();
  106. return res(2,"保存失败",$e->getMessage(),$e->getTrace());
  107. }
  108. }
  109. /**
  110. * @title: 删除审批流
  111. * @desc: 描述
  112. * @param {int} {id} {} {流程ID}
  113. * @return {*}
  114. * @author: Rock
  115. * @method: POST
  116. * @Date: 2023-08-31 20:47:45
  117. */
  118. public function doDelete(int $id=0)
  119. {
  120. try{
  121. FlowTplModel::startTrans();
  122. $this->model->where('id',$id)->delete();
  123. FlowTplNodeModel::where('tpl_id',$id)->delete();
  124. FlowTplLinkModel::where('tpl_id',$id)->delete();
  125. FlowTplModel::commit();
  126. return res(1,"删除成功");
  127. }catch(\Exception $e){
  128. FlowTplModel::rollback();
  129. return res(2,"删除失败",$e->getMessage(),$e->getTrace());
  130. }
  131. }
  132. }