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()); } } }