1
0

flowcourseModel.php 4.2 KB

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