flowbillModel.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. <?php
  2. class flowbillClassModel extends Model
  3. {
  4. public $statustext;
  5. public $statuscolor;
  6. public $nowwhere = '';
  7. public function initModel()
  8. {
  9. $this->settable('flow_bill');
  10. $this->statustext = explode(',','待处理,已审核,处理不通过,,,已作废');
  11. $this->statuscolor = explode(',','blue,green,red,,,gray');
  12. }
  13. /**
  14. * 获取状态
  15. */
  16. public function getstatus($zt, $lx=0)
  17. {
  18. $a1 = $this->statustext;
  19. $a2 = $this->statuscolor;
  20. $str = '<font color='.$a2[$zt].'>'.$a1[$zt].'</font>';
  21. if($lx==0){
  22. return $str;
  23. }else{
  24. return array($a1[$zt], $a2[$zt]);
  25. }
  26. }
  27. /**
  28. * 读取单据数据
  29. * $glx 0是应用上读取,1后台读取
  30. */
  31. public function getrecord($uid, $lx, $page, $limit, $glx=0)
  32. {
  33. $srows = array();
  34. $modeid = (int)$this->rock->get('modeid','0');
  35. $where = '(`uid`='.$uid.' or `optid`='.$uid.')';
  36. $isdb = 0;
  37. //未通过
  38. if($lx=='flow_wtg'){
  39. $where .= ' and `status`=2';
  40. }
  41. if($lx=='flow_dcl'){
  42. $where .= ' and `status` not in(1,5)';
  43. }
  44. //已完成
  45. if($lx=='flow_ywc'){
  46. $where .= ' and `status`=1';
  47. }
  48. //异常
  49. if($lx=='flow_error'){
  50. $where .= ' and '.$this->errorwhere().'';
  51. }
  52. //待办
  53. if($lx=='daiban_daib' || $lx=='daiban_def'){
  54. $where = '`status` not in(1,2) and `isturn`=1 and '.$this->rock->dbinstr('nowcheckid', $uid);
  55. $isdb = 1;
  56. }
  57. //经我处理
  58. if($lx=='daiban_jwcl'){
  59. $where = '`isturn`=1 and '.$this->rock->dbinstr('allcheckid', $uid);
  60. }else if(contain($lx,'_jwcl')){//经我处理跟进模块编号搜索,$lx= 模块编号_jcwl
  61. $where = '`isturn`=1 and ';
  62. $wnum = str_replace('_jwcl','', $lx);
  63. $mrs = m('mode')->getone("`num`='$wnum'");
  64. if($mrs){
  65. $where .= '`modeid`='.$mrs['id'].' and ';
  66. }
  67. $where .= $this->rock->dbinstr('allcheckid', $uid);
  68. }
  69. //我全部下级申请
  70. if($lx=='daiban_myxia'){
  71. $where = '`isturn`=1 and '.m('admin')->getdownwheres('uid', $uid, 0);
  72. }
  73. //我直属下级申请
  74. if($lx=='daiban_mydown'){
  75. $where = '`isturn`=1 and '.m('admin')->getdownwheres('uid', $uid, 1);
  76. }
  77. //抄送
  78. if($lx=='flow_chaos'){
  79. $where ='1=2';
  80. $where1= $this->rock->dbinstr('csnameid', $uid);
  81. if($modeid>0)$where1.=' and `modeid`='.$modeid.'';
  82. $crows = $this->db->getall("select * from `[Q]flow_chao` where $where1");
  83. if($crows){
  84. $modeids = '';
  85. $modeidsa= array();
  86. foreach($crows as $k1=>$rs1){
  87. $modeids.=','.$rs1['modeid'].'';
  88. $modeidsa[$rs1['modeid']][] = $rs1['mid'];
  89. }
  90. foreach($modeidsa as $mkid=>$mids)$wherea[]='(`modeid` = '.$mkid.' and `mid` in('.join(',', $mids).'))';
  91. $where = '`isturn`=1 and ( '.join(' or ', $wherea).' )';
  92. }
  93. }
  94. //监控
  95. if($lx=='jiankong'){
  96. $where ='1=2';
  97. if($modeid>0){
  98. $wwhere = m('view')->jiankongwhere($modeid, $this->adminid);//返回主表的条件
  99. $wwhere = str_replace('{asqom}','', $wwhere);
  100. $moders = $this->db->getone('[Q]flow_set', $modeid);
  101. $where ='`isturn`=1 and `mid` in(select `id` from `[Q]'.$moders['table'].'` where 1=1 '.$wwhere.')';
  102. }
  103. }
  104. //我关注单据(未开发)
  105. if($lx=='follow'){
  106. $where ='1=2';
  107. }
  108. $this->nowwhere = $where;
  109. $key = $this->rock->post('key');
  110. if(!isempt($key))$where.=" and (`optname` like '%$key%' or `modename` like '%$key%' or `sericnum` like '$key%')";
  111. if($modeid>0)$where.=' and `modeid`='.$modeid.'';
  112. $arr = $this->getlimit('`isdel`=0 and '.$where, $page,'*','`optdt` desc', $limit);
  113. $rows = $arr['rows'];
  114. $modeids= '0';
  115. foreach($rows as $k=>$rs)$modeids.=','.$rs['modeid'].'';
  116. $modearr= array();
  117. if($modeids!='0'){
  118. $moders = m('flow_set')->getall("`id` in($modeids)");
  119. foreach($moders as $k=>$rs)$modearr[$rs['id']] = $rs;
  120. }
  121. $flowarrmo = array();
  122. foreach($rows as $k=>$rs){
  123. $modename = $rs['modename'];
  124. $summary = '';
  125. $summarx = '';
  126. $modenum = '';
  127. $statustext = '记录不存在';
  128. $statusstr = '不存在';
  129. $statuscolor= '#888888';
  130. $ishui = 0;
  131. $optdt = $rs['optdt'];
  132. if(isset($modearr[$rs['modeid']])){
  133. $mors = $modearr[$rs['modeid']];
  134. $modenum = $mors['num'];
  135. if(!isset($flowarrmo[$modenum])){
  136. $flow = m('flow:'.$modenum.'')->initdata($mors);
  137. $flowarrmo[$modenum] = $flow;
  138. }else{
  139. $flow = $flowarrmo[$modenum];
  140. }
  141. $modename = $mors['name'];
  142. $rers = $this->db->getone('[Q]'.$rs['table'].'', $rs['mid']);
  143. if($rers){
  144. $tihsrs = $flow->rsreplace($rers, 2, null, 1);
  145. $summary = $this->rock->reparr($mors['summary'], $tihsrs);
  146. $summarx = $this->rock->reparr($mors['summarx'], $tihsrs);
  147. $ztarr = $flow->getstatus($rers, $mors['statusstr'], $rs['nowcheckname']);
  148. $statustext = $ztarr[0];
  149. $statuscolor = $ztarr[1];
  150. $statusstr = $ztarr[3];
  151. if($rers['status']==5)$ishui = 1;
  152. }else{
  153. $this->update('isdel=1', $rs['id']);
  154. }
  155. }
  156. $title = '['.$rs['optname'].']'.$modename.'';
  157. $cont = '申请人:'.$rs['optname'].'<br>单号:'.$rs['sericnum'].'';
  158. $cont.='<br>申请日期:'.$rs['applydt'].'';
  159. if(!isempt($summary))$cont.='<br>摘要:'.$summary.'';
  160. //if(!isempt($rs['nstatustext']))$cont.='<br>状态:'.$rs['nstatustext'].'';
  161. if(!isempt($rs['checksm']))$cont.='<br>处理说明:'.$rs['checksm'].'';
  162. //应用摘要
  163. if(!isempt($summarx)){
  164. $suarr = $this->zhaiyaoar($summarx);
  165. foreach($suarr as $f=>$nr){
  166. $str = $this->rock->reparr($nr, $rers);
  167. if($f=='cont')$str = $this->contreplaces($str);
  168. $$f = $str;
  169. }
  170. if(isset($suarr['cont'])){
  171. if(isset($suarr['title']))
  172. $cont = '模块:'.$modename.'<br>申请人:'.$rs['optname'].'<br>'.$cont;
  173. //if(!isempt($rs['nstatustext']))$cont.='<br>状态:'.$rs['nstatustext'].'';
  174. if(!isempt($rs['checksm']))$cont.='<br>处理说明:'.$rs['checksm'].'';
  175. }
  176. }
  177. $srows[]= array(
  178. 'title' => $title,
  179. 'cont' => $cont,
  180. 'ishui' => $ishui,
  181. 'id' => $rs['mid'],
  182. 'uid' => $rs['uid'],
  183. 'optdt' => $optdt,
  184. 'sericnum' => $rs['sericnum'],
  185. 'applydt' => $rs['applydt'],
  186. 'statustext' => $statustext,
  187. 'statuscolor' => $statuscolor,
  188. 'statusstr' => $statusstr,
  189. 'modenum' => $modenum,
  190. 'modename' => $modename
  191. );
  192. }
  193. $arr['rows'] = $srows;
  194. return $arr;
  195. }
  196. private function zhaiyaoar($str)
  197. {
  198. $stra = explode("\n", $str);
  199. $arr = array();
  200. foreach($stra as $nr){
  201. if(strpos($nr,'title:')===0)$arr['title'] = substr($nr, 6);
  202. if(strpos($nr,'optdt:')===0)$arr['optdt'] = substr($nr, 6);
  203. if(strpos($nr,'cont:')===0)$arr['cont'] = substr($nr, 5);
  204. }
  205. if(!$arr)$arr['cont'] = $str;
  206. return $arr;
  207. }
  208. private function contreplaces($str)
  209. {
  210. $stra = explode('[br]', $str);
  211. $s1 = '';
  212. foreach($stra as $s){
  213. $a1 = explode(':', $s);
  214. if(isset($a1[1]) && $a1[1]==''){
  215. }else{
  216. $s1.='$%#'.$s.'';
  217. }
  218. }
  219. if($s1!=''){
  220. $s1 = str_replace('$%#', "\n", substr($s1, 3));
  221. }
  222. return $s1;
  223. }
  224. //获取待办处理数字
  225. public function daibanshu($uid)
  226. {
  227. $where = '`status` not in(1,2) and `isdel`=0 and `isturn`=1 and '.$this->rock->dbinstr('nowcheckid', $uid);
  228. $to = $this->rows($where);
  229. return $to;
  230. }
  231. //待提提交
  232. public function daiturntotal($uid)
  233. {
  234. $where = '(`uid`='.$uid.' or `optid`='.$uid.') and `status` not in(5) and `isturn`=0 and isdel=0';
  235. $to = $this->rows($where);
  236. return $to;
  237. }
  238. //未通过的
  239. public function applymywgt($uid)
  240. {
  241. $where = '`status`=2 and isdel=0 and (`uid`='.$uid.' or `optid`='.$uid.')';
  242. $to = $this->rows($where);
  243. return $to;
  244. }
  245. //异常单据条件,审核人中有停用的帐号
  246. public function errorwhere($qz='')
  247. {
  248. $where = ''.$qz.'`status` not in(1,5) and '.$qz.'`isdel`=0 and '.$qz.'`nstatus`<>2 and '.$qz.'`isturn`=1 and (('.$qz.'`nowcheckid` is null) or ('.$qz.'`nowcheckid` not in(select `id` from `[Q]admin` where `status`=1)))';
  249. return $where;
  250. }
  251. //异常数
  252. public function errortotal()
  253. {
  254. $where = $this->errorwhere();
  255. $to = $this->rows($where);
  256. return $to;
  257. }
  258. //单据数据
  259. public function getbilldata($rows)
  260. {
  261. $srows = array();
  262. $modeids= '0';
  263. foreach($rows as $k=>$rs)$modeids.=','.$rs['modeid'].'';
  264. $modearr= array();
  265. if($modeids!='0'){
  266. $moders = m('flow_set')->getall("`id` in($modeids)");
  267. foreach($moders as $k=>$rs)$modearr[$rs['id']] = $rs;
  268. }
  269. $flow = m('flow:user');
  270. $flowarrmo = array();
  271. foreach($rows as $k=>$rs){
  272. $modename = $rs['modename'];
  273. $summary = '';
  274. $modenum = '';
  275. $statustext = '记录不存在';
  276. $statuscolor= '#888888';
  277. $ishui = 0;
  278. $statusstr = '不存在';
  279. if(isset($modearr[$rs['modeid']])){
  280. $mors = $modearr[$rs['modeid']];
  281. $modename = $mors['name'];
  282. $summary = $mors['summary'];
  283. $modenum = $mors['num'];
  284. if(!isset($flowarrmo[$modenum])){
  285. $flow = m('flow:'.$modenum.'')->initdata($mors);
  286. $flowarrmo[$modenum] = $flow;
  287. }else{
  288. $flow = $flowarrmo[$modenum];
  289. }
  290. $rers = $this->db->getone('[Q]'.$rs['table'].'', $rs['mid']);
  291. $summary = $this->rock->reparr($summary, $rers);
  292. if($rers){
  293. $tihsrs = $flow->rsreplace($rers, 2, null, 1);
  294. $summary = $this->rock->reparr($mors['summary'], $tihsrs);
  295. $nowsets = $rs['nowcheckname']; //当前审核人
  296. $ztarr = $flow->getstatus($rers, $mors['statusstr'], $nowsets);
  297. $statustext = $ztarr[0];
  298. $statuscolor = $ztarr[1];
  299. if($rers['status']==5)$ishui = 1;
  300. $statusstr = $ztarr[3];
  301. }else{
  302. $this->update('isdel=1', $rs['id']); //记录已经不存在了
  303. }
  304. }
  305. $name = $rs['name'];
  306. if(isempt($name))$name = $rs['uname'];
  307. $deptname = $rs['deptname'];
  308. if(isempt($deptname))$deptname = $rs['udeptname'];
  309. $srows[]= array(
  310. 'id' => $rs['mid'],
  311. 'optdt' => $rs['optdt'],
  312. 'applydt' => $rs['applydt'],
  313. 'optname' => arrvalue($rs,'optname'),
  314. 'name' => $name,
  315. 'deptname' => $deptname,
  316. 'sericnum' => $rs['sericnum'],
  317. 'updt' => $rs['updt'],
  318. 'nowcheckid'=> $rs['nowcheckid'],
  319. 'nowcourseid'=> $rs['nowcourseid'], //当前步骤
  320. 'ishui' => $ishui,
  321. 'modename' => $modename,
  322. 'modenum' => $modenum,
  323. 'summary' => $summary,
  324. 'status' => $statusstr
  325. );
  326. }
  327. return $srows;
  328. }
  329. /**
  330. * 首页上显示我的申请
  331. */
  332. public function homelistshow()
  333. {
  334. $arr = $this->getrecord($this->adminid, 'flow_dcl', 1, 5,1);
  335. $rows = $arr['rows'];
  336. $arows = array();
  337. foreach($rows as $k=>$rs){
  338. $cont = '【'.$rs['modename'].'】单号:'.$rs['sericnum'].',日期:'.$rs['applydt'].','.$rs['statusstr'].'';
  339. $arows[] = array(
  340. 'cont' => $cont,
  341. 'modename' => $rs['modename'],
  342. 'modenum' => $rs['modenum'],
  343. 'id' => $rs['id'],
  344. 'count' => $arr['count']
  345. );
  346. }
  347. return $arows;
  348. }
  349. /*
  350. * 更新记录
  351. */
  352. public function updatebill($whe='')
  353. {
  354. $rows = $this->db->getall('SELECT b.`id`,b.`uname`,b.`udeptname`,b.`status`,a.`name`,a.`deptname` FROM `[Q]flow_bill` b left join `[Q]admin` a on b.`uid`=a.id where b.`udeptname` is null and b.`status` not in(1,5) '.$whe.'');
  355. $ztara= array(1,5);
  356. foreach($rows as $k=>$rs){
  357. if(isempt($rs['name']))continue;
  358. $zt = $rs['status'];
  359. if(isempt($rs['uname']) || isempt($rs['udeptname']) || !in_array($zt, $ztara)){
  360. $this->update(array(
  361. 'uname' => $rs['name'],
  362. 'udeptname' => $rs['deptname'],
  363. ), $rs['id']);
  364. }
  365. }
  366. }
  367. /**
  368. * 超过几分钟自动作废
  369. */
  370. public function autocheck()
  371. {
  372. //要作废的流程模块
  373. $rows = $this->db->getall('select `id`,`zfeitime`,`num` from `[Q]flow_set` where `status`=1 and `isflow`>0 and `zfeitime`>0');
  374. $this->rock->adminid = 0;
  375. $this->rock->adminname = '系统';
  376. foreach($rows as $k=>$rs){
  377. $modeid = $rs['id'];
  378. $dtfei = date('Y-m-d H:i:s', time()-(int)$rs['zfeitime']*60);
  379. $data = $this->getall("`modeid`='$modeid' and `isturn`=1 and `status` not in(1,5) and `updt`<'$dtfei'");
  380. if($data){
  381. $flow = m('flow')->initflow($rs['num']);
  382. foreach($data as $k1=>$rs1){
  383. $flow->loaddata($rs1['mid'], false);
  384. $flow->zuofeibill('超'.$rs['zfeitime'].'分钟未处理自动作废');
  385. }
  386. }
  387. }
  388. //超过几分钟自动审核通过/不通过
  389. $dats = $this->db->getarr('[Q]flow_course','`zshtime`>0 and `status`=1','zshtime,zshstate');
  390. $custids = '';
  391. if($dats)foreach($dats as $cid=>$rs)$custids.=','.$cid.'';
  392. if($custids=='')return;
  393. $custids = substr($custids, 1);
  394. $mxxus = 99999;
  395. $rows = $this->getall('`isturn`=1 and `status`=0 and `isdel`=0 and ((`nowcourseid` in('.$custids.')) or (`nowcourseid`>'.$mxxus.' and ((`nowcourseid`-`nowcheckid`)/'.$mxxus.') in('.$custids.')) )');
  396. //echo $this->db->nowsql;
  397. if(!$rows)return;
  398. $modeids = '';
  399. foreach($rows as $k=>$rs)$modeids.=','.$rs['modeid'].'';
  400. $modearr = $this->db->getarr('[Q]flow_set','id in('.substr($modeids, 1).')','`num`,`table`');
  401. foreach($rows as $k=>$rs){
  402. if(isempt($rs['nowcheckid']))continue;
  403. $nowcourseid = $rs['nowcourseid'];
  404. if($nowcourseid>$mxxus)$nowcourseid = ($nowcourseid-$rs['nowcheckid'])/$mxxus;
  405. $cusrs = arrvalue($dats,$nowcourseid, false);
  406. $modrs = arrvalue($modearr, $rs['modeid'], false);
  407. if(!$modrs || !$cusrs)continue;
  408. $dtfei = time()-(int)$cusrs['zshtime']*60;
  409. $updt = $rs['updt'];
  410. if(isempt($updt))$updt = $rs['optdt'];
  411. $nowcheckida1 = explode(',', $rs['nowcheckid']);
  412. $nowcheckida2 = explode(',', $rs['nowcheckname']);
  413. $table = $modrs['table'];
  414. $ors = $this->db->getone('[Q]'.$table.'','`id`='.$rs['mid'].'');
  415. if(!$ors){
  416. $this->update('`isdel`=1', $rs['id']);
  417. continue;
  418. }
  419. $this->rock->adminid = arrvalue($nowcheckida1,0);
  420. $this->rock->adminname = arrvalue($nowcheckida2,0);
  421. //超时了
  422. if(strtotime($updt)<$dtfei){
  423. $sm = '超'.$cusrs['zshtime'].'分钟未处理自动';
  424. $zt = (int)$cusrs['zshstate'];
  425. if($zt==1 || $zt==2){
  426. m('flow')->opt('check', $modrs['num'], $rs['mid'], $zt, $sm.'审核');//审核
  427. }else{
  428. $this->rock->adminid = 0;
  429. $this->rock->adminname = '系统';
  430. $flow = m('flow')->initflow($modrs['num'], $rs['mid'], false);
  431. if($zt==3)$flow->zuofeibill($sm.'作废');
  432. if($zt==4)$flow->deletebill($sm.'删除', false);
  433. if($zt==5)$flow->chuiban($sm.'催办');
  434. $this->update("`updt`='{$this->rock->now}'", $rs['id']);
  435. }
  436. }
  437. }
  438. }
  439. }
粤ICP备19079148号