flowcourseModel.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. /**
  3. * 流程步骤的
  4. */
  5. class flowcourseClassModel extends Model
  6. {
  7. private $courserows = array();
  8. public function initModel()
  9. {
  10. $this->settable('flow_course');
  11. }
  12. public function initCourse($setid, $fields='')
  13. {
  14. $this->courserows = array();
  15. if($fields=='')$fields = '`id`,`name`,`checktype`,`checktypename`,`whereid`,`where`,`status`,`mid`,`pid`,`recename`,`explain`,`optdt`,`nid`';
  16. $rows = $this->getall("`setid`='$setid' and `mid`>=0",$fields,'`pid`,`sort`');
  17. $isinit = false;
  18. $time = '2017-08-10 00:00:00';
  19. foreach($rows as $k=>$rs){
  20. if($rs['mid']>0)$isinit=true;
  21. if($rs['optdt']>$time)$isinit=true;
  22. }
  23. //没有初始化
  24. if(!$isinit){
  25. $pid = '-1';
  26. foreach($rows as $k=>$rs){
  27. if($pid==$rs['pid']){
  28. $mid = $rows[$k-1]['id'];
  29. }else{
  30. $mid = '0';
  31. }
  32. $pid = $rs['pid'];
  33. if($mid!=$rs['mid']){
  34. $this->update('mid='.$mid.'', $rs['id']);
  35. $rs['mid'] = $mid;
  36. }
  37. $this->courserows[] = $rs;
  38. }
  39. $this->update('pid=0', "`setid`='$setid'");
  40. }else{
  41. foreach($rows as $k=>$rs){
  42. $this->courserows[] = $rs;
  43. }
  44. }
  45. //分支说明
  46. foreach($this->courserows as $k=>$rs){
  47. $fzsm = '';
  48. if(!isempt($rs['recename']))$fzsm='适用('.$rs['recename'].')';
  49. $whereid = (int)$rs['whereid'];
  50. if($whereid>0){
  51. $wherena = $this->db->getmou('[Q]flow_where','name', 'id='.$whereid.'');
  52. if(!isempt($wherena)){
  53. if(!isempt($fzsm))$fzsm.=',';
  54. $fzsm.= $wherena;
  55. }
  56. }
  57. if(!isempt($rs['explain'])){
  58. if(!isempt($fzsm))$fzsm.=',';
  59. $fzsm.= '说明('.$rs['explain'].')';
  60. }else if(!isempt($rs['where'])){
  61. if(!isempt($fzsm))$fzsm.=',';
  62. $fzsm.= '审核条件('.$this->rock->jm->base64decode($rs['where']).')';
  63. }
  64. $this->courserows[$k]['fzsm'] = $fzsm;
  65. }
  66. return $this->courserows;
  67. }
  68. public function getCoursedata($setid, $fields='')
  69. {
  70. $drows = $this->initCourse($setid, $fields);
  71. $this->getCoursedatasarr = array();
  72. $children= $this->getCoursedatas($drows, '0', 1);
  73. $rows[] = array(
  74. 'name' => '提交',
  75. 'num' => 'turn',
  76. 'id' => 0,
  77. 'mid' => 0,
  78. 'level' => 0,
  79. 'children' => $children,
  80. 'childshu' => count($children),
  81. );
  82. if($fields==''){
  83. $barr['rows'] = $rows;
  84. $barr['treedata'] = $this->getTreedata($setid);
  85. }else{
  86. $barr['rows'] = $children;
  87. }
  88. return $barr;
  89. }
  90. private function getCoursedatas($drows,$mid,$level)
  91. {
  92. $rows = array();
  93. foreach($drows as $k=>$rs){
  94. if($rs['mid']==$mid){
  95. $rs['level'] = $level;
  96. $children = $this->getCoursedatas($drows, $rs['id'], $level+1);
  97. $rs['children'] = $children;
  98. $rs['childshu'] = count($children);
  99. $this->getCoursedatasarr[$rs['id']] = $rs;
  100. $rows[] = $rs;
  101. }
  102. }
  103. return $rows;
  104. }
  105. //获取显示数据
  106. public function getTreedata($setid)
  107. {
  108. $drows = $this->db->getall("select *,(select count(1) from `[Q]flow_course` where `mid`=a.id)as stotal from `[Q]flow_course` a where a.`setid`='$setid' order by a.`sort`");
  109. $this->getTreedatada = array();
  110. $this->getTreedatada[] = array(
  111. 'name' => '提交',
  112. 'num' => '',
  113. 'id' => 0,
  114. 'stotal' => 1,
  115. 'mid' => 0,
  116. 'status' => 1,
  117. 'iszf' => 0,
  118. 'level' => 1
  119. );
  120. $this->getTreedatas($drows,'0',2);
  121. return $this->getTreedatada;
  122. }
  123. private function getTreedatas($drows,$mid,$level)
  124. {
  125. foreach($drows as $k=>$rs){
  126. if($rs['mid']==$mid){
  127. $rs['level'] = $level;
  128. if($rs['whereid']=='0'){
  129. $rs['whereid']='';
  130. }else{
  131. $rs['whereid']=$this->db->getmou('[Q]flow_where','name', 'id='.$rs['whereid'].'');
  132. }
  133. $this->getTreedatada[] = $rs;
  134. $this->getTreedatas($drows, $rs['id'], $level+1);
  135. }
  136. }
  137. }
  138. /**
  139. * 流程匹配的
  140. */
  141. public function pipeiCourse($setid)
  142. {
  143. $barr = $this->getCoursedata($setid, '*' );
  144. $rows = $barr['rows'];
  145. return array(
  146. 'rows' => $rows,
  147. 'rowd' => $this->getCoursedatasarr,
  148. );
  149. }
  150. /**
  151. * 读取临时步骤
  152. */
  153. public function getcoursetemp($setid, $djid)
  154. {
  155. $rows = $this->getall("`setid`='$setid' and `mid` in(-1,-2) and whereid='$djid'",'*','optdt asc');
  156. return $rows;
  157. }
  158. }
粤ICP备19079148号