flowbillModel.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  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. $comidname = '';
  127. $modenum = '';
  128. $statustext = '记录不存在';
  129. $statusstr = '不存在';
  130. $statuscolor= '#888888';
  131. $ishui = 0;
  132. $optdt = $rs['optdt'];
  133. if(isset($modearr[$rs['modeid']])){
  134. $mors = $modearr[$rs['modeid']];
  135. $modenum = $mors['num'];
  136. if(!isset($flowarrmo[$modenum])){
  137. $flow = m('flow:'.$modenum.'')->initdata($mors);
  138. $flowarrmo[$modenum] = $flow;
  139. }else{
  140. $flow = $flowarrmo[$modenum];
  141. }
  142. $modename = $mors['name'];
  143. $rers = $this->db->getone('[Q]'.$rs['table'].'', $rs['mid']);
  144. if($rers){
  145. $tihsrs = $flow->rsreplace($rers, 2, null, 1);
  146. $comidname = $tihsrs['comidname'];
  147. $summary = $this->rock->reparr($mors['summary'], $tihsrs);
  148. $summarx = $this->rock->reparr($mors['summarx'], $tihsrs);
  149. $ztarr = $flow->getstatus($rers, $mors['statusstr'], $rs['nowcheckname']);
  150. $statustext = $ztarr[0];
  151. $statuscolor = $ztarr[1];
  152. $statusstr = $ztarr[3];
  153. if($rers['status']==5)$ishui = 1;
  154. }else{
  155. $this->update('isdel=1', $rs['id']);
  156. }
  157. }
  158. $title = '['.$rs['optname'].']'.$modename.'';
  159. $cont = '申请人:'.$rs['optname'].'<br>单号:'.$rs['sericnum'].'';
  160. $cont.='<br>申请日期:'.$rs['applydt'].'';
  161. if(!isempt($summary))$cont.='<br>摘要:'.$summary.'';
  162. //if(!isempt($rs['nstatustext']))$cont.='<br>状态:'.$rs['nstatustext'].'';
  163. if(!isempt($rs['checksm']))$cont.='<br>处理说明:'.$rs['checksm'].'';
  164. //应用摘要
  165. if(!isempt($summarx)){
  166. $suarr = $this->zhaiyaoar($summarx);
  167. foreach($suarr as $f=>$nr){
  168. $str = $this->rock->reparr($nr, $rers);
  169. if($f=='cont')$str = $this->contreplaces($str);
  170. $$f = $str;
  171. }
  172. if(isset($suarr['cont'])){
  173. if(isset($suarr['title']))
  174. $cont = '模块:'.$modename.'<br>申请人:'.$rs['optname'].'<br>'.$cont;
  175. //if(!isempt($rs['nstatustext']))$cont.='<br>状态:'.$rs['nstatustext'].'';
  176. if(!isempt($rs['checksm']))$cont.='<br>处理说明:'.$rs['checksm'].'';
  177. }
  178. }
  179. if(ISMORECOM)$cont.='<br>所属单位※:'.$comidname.'';
  180. $srows[]= array(
  181. 'title' => $title,
  182. 'cont' => $cont,
  183. 'ishui' => $ishui,
  184. 'id' => $rs['mid'],
  185. 'uid' => $rs['uid'],
  186. 'optdt' => $optdt,
  187. 'sericnum' => $rs['sericnum'],
  188. 'applydt' => $rs['applydt'],
  189. 'statustext' => $statustext,
  190. 'statuscolor' => $statuscolor,
  191. 'statusstr' => $statusstr,
  192. 'modenum' => $modenum,
  193. 'modename' => $modename
  194. );
  195. }
  196. $arr['rows'] = $srows;
  197. return $arr;
  198. }
  199. private function zhaiyaoar($str)
  200. {
  201. $stra = explode("\n", $str);
  202. $arr = array();
  203. foreach($stra as $nr){
  204. if(strpos($nr,'title:')===0)$arr['title'] = substr($nr, 6);
  205. if(strpos($nr,'optdt:')===0)$arr['optdt'] = substr($nr, 6);
  206. if(strpos($nr,'cont:')===0)$arr['cont'] = substr($nr, 5);
  207. }
  208. if(!$arr)$arr['cont'] = $str;
  209. return $arr;
  210. }
  211. private function contreplaces($str)
  212. {
  213. $stra = explode('[br]', $str);
  214. $s1 = '';
  215. foreach($stra as $s){
  216. $a1 = explode(':', $s);
  217. if(isset($a1[1]) && $a1[1]==''){
  218. }else{
  219. $s1.='$%#'.$s.'';
  220. }
  221. }
  222. if($s1!=''){
  223. $s1 = str_replace('$%#', "\n", substr($s1, 3));
  224. }
  225. return $s1;
  226. }
  227. //获取待办处理数字
  228. public function daibanshu($uid)
  229. {
  230. $where = '`status` not in(1,2) and `isdel`=0 and `isturn`=1 and '.$this->rock->dbinstr('nowcheckid', $uid);
  231. $to = $this->rows($where);
  232. return $to;
  233. }
  234. //待提提交
  235. public function daiturntotal($uid)
  236. {
  237. $where = '(`uid`='.$uid.' or `optid`='.$uid.') and `status` not in(5) and `isturn`=0 and isdel=0';
  238. $to = $this->rows($where);
  239. return $to;
  240. }
  241. //未通过的
  242. public function applymywgt($uid)
  243. {
  244. $where = '`status`=2 and isdel=0 and (`uid`='.$uid.' or `optid`='.$uid.')';
  245. $to = $this->rows($where);
  246. return $to;
  247. }
  248. //异常单据条件,审核人中有停用的帐号
  249. public function errorwhere($qz='')
  250. {
  251. $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)))';
  252. return $where;
  253. }
  254. //异常数
  255. public function errortotal()
  256. {
  257. $where = $this->errorwhere();
  258. $to = $this->rows($where);
  259. return $to;
  260. }
  261. //单据数据
  262. public function getbilldata($rows)
  263. {
  264. $srows = array();
  265. $modeids= '0';
  266. foreach($rows as $k=>$rs)$modeids.=','.$rs['modeid'].'';
  267. $modearr= array();
  268. if($modeids!='0'){
  269. $moders = m('flow_set')->getall("`id` in($modeids)");
  270. foreach($moders as $k=>$rs)$modearr[$rs['id']] = $rs;
  271. }
  272. $flow = m('flow:user');
  273. $flowarrmo = array();
  274. foreach($rows as $k=>$rs){
  275. $modename = $rs['modename'];
  276. $summary = '';
  277. $modenum = '';
  278. $comidname = '';
  279. $statustext = '记录不存在';
  280. $statuscolor= '#888888';
  281. $ishui = 0;
  282. $statusstr = '不存在';
  283. if(isset($modearr[$rs['modeid']])){
  284. $mors = $modearr[$rs['modeid']];
  285. $modename = $mors['name'];
  286. $summary = $mors['summary'];
  287. $modenum = $mors['num'];
  288. if(!isset($flowarrmo[$modenum])){
  289. $flow = m('flow:'.$modenum.'')->initdata($mors);
  290. $flowarrmo[$modenum] = $flow;
  291. }else{
  292. $flow = $flowarrmo[$modenum];
  293. }
  294. $rers = $this->db->getone('[Q]'.$rs['table'].'', $rs['mid']);
  295. $summary = $this->rock->reparr($summary, $rers);
  296. if($rers){
  297. $tihsrs = $flow->rsreplace($rers, 2, null, 1);
  298. $summary = $this->rock->reparr($mors['summary'], $tihsrs);
  299. $comidname = $tihsrs['comidname'];//所属单位
  300. $nowsets = $rs['nowcheckname']; //当前审核人
  301. $ztarr = $flow->getstatus($rers, $mors['statusstr'], $nowsets);
  302. $statustext = $ztarr[0];
  303. $statuscolor = $ztarr[1];
  304. if($rers['status']==5)$ishui = 1;
  305. $statusstr = $ztarr[3];
  306. }else{
  307. $this->update('isdel=1', $rs['id']); //记录已经不存在了
  308. }
  309. }
  310. $name = $rs['name'];
  311. if(isempt($name))$name = $rs['uname'];
  312. $deptname = $rs['deptname'];
  313. if(isempt($deptname))$deptname = $rs['udeptname'];
  314. $srows[]= array(
  315. 'id' => $rs['mid'],
  316. 'optdt' => $rs['optdt'],
  317. 'applydt' => $rs['applydt'],
  318. 'optname' => arrvalue($rs,'optname'),
  319. 'name' => $name,
  320. 'deptname' => $deptname,
  321. 'sericnum' => $rs['sericnum'],
  322. 'updt' => $rs['updt'],
  323. 'nowcheckid'=> $rs['nowcheckid'],
  324. 'nowcourseid'=> $rs['nowcourseid'], //当前步骤
  325. 'ishui' => $ishui,
  326. 'modename' => $modename,
  327. 'modenum' => $modenum,
  328. 'summary' => $summary,
  329. 'comidname' => $comidname,
  330. 'status' => $statusstr
  331. );
  332. }
  333. return $srows;
  334. }
  335. /**
  336. * 首页上显示我的申请
  337. */
  338. public function homelistshow()
  339. {
  340. $arr = $this->getrecord($this->adminid, 'flow_dcl', 1, 5,1);
  341. $rows = $arr['rows'];
  342. $arows = array();
  343. foreach($rows as $k=>$rs){
  344. $cont = '【'.$rs['modename'].'】单号:'.$rs['sericnum'].',日期:'.$rs['applydt'].','.$rs['statusstr'].'';
  345. $arows[] = array(
  346. 'cont' => $cont,
  347. 'modename' => $rs['modename'],
  348. 'modenum' => $rs['modenum'],
  349. 'id' => $rs['id'],
  350. 'count' => $arr['count']
  351. );
  352. }
  353. return $arows;
  354. }
  355. /*
  356. * 更新记录
  357. */
  358. public function updatebill($whe='')
  359. {
  360. $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.'');
  361. $ztara= array(1,5);
  362. foreach($rows as $k=>$rs){
  363. if(isempt($rs['name']))continue;
  364. $zt = $rs['status'];
  365. if(isempt($rs['uname']) || isempt($rs['udeptname']) || !in_array($zt, $ztara)){
  366. $this->update(array(
  367. 'uname' => $rs['name'],
  368. 'udeptname' => $rs['deptname'],
  369. ), $rs['id']);
  370. }
  371. }
  372. }
  373. /**
  374. * 超过几分钟自动作废
  375. */
  376. public function autocheck()
  377. {
  378. //要作废的流程模块
  379. $rows = $this->db->getall('select `id`,`zfeitime`,`num` from `[Q]flow_set` where `status`=1 and `isflow`>0 and `zfeitime`>0');
  380. $this->rock->adminid = 0;
  381. $this->rock->adminname = '系统';
  382. foreach($rows as $k=>$rs){
  383. $modeid = $rs['id'];
  384. $dtfei = date('Y-m-d H:i:s', time()-(int)$rs['zfeitime']*60);
  385. $data = $this->getall("`modeid`='$modeid' and `isturn`=1 and `status` not in(1,5) and `updt`<'$dtfei'");
  386. if($data){
  387. $flow = m('flow')->initflow($rs['num']);
  388. foreach($data as $k1=>$rs1){
  389. $flow->loaddata($rs1['mid'], false);
  390. $flow->zuofeibill('超'.$rs['zfeitime'].'分钟未处理自动作废');
  391. }
  392. }
  393. }
  394. //超过几分钟自动审核通过/不通过
  395. $dats = $this->db->getarr('[Q]flow_course','`zshtime`>0 and `status`=1','zshtime,zshstate');
  396. $custids = '';
  397. if($dats)foreach($dats as $cid=>$rs)$custids.=','.$cid.'';
  398. if($custids=='')return;
  399. $custids = substr($custids, 1);
  400. $mxxus = 99999;
  401. $rows = $this->getall('`isturn`=1 and `status`=0 and `isdel`=0 and ((`nowcourseid` in('.$custids.')) or (`nowcourseid`>'.$mxxus.' and ((`nowcourseid`-`nowcheckid`)/'.$mxxus.') in('.$custids.')) )');
  402. //echo $this->db->nowsql;
  403. if(!$rows)return;
  404. $modeids = '';
  405. foreach($rows as $k=>$rs)$modeids.=','.$rs['modeid'].'';
  406. $modearr = $this->db->getarr('[Q]flow_set','id in('.substr($modeids, 1).')','`num`,`table`');
  407. foreach($rows as $k=>$rs){
  408. if(isempt($rs['nowcheckid']))continue;
  409. $nowcourseid = $rs['nowcourseid'];
  410. if($nowcourseid>$mxxus)$nowcourseid = ($nowcourseid-$rs['nowcheckid'])/$mxxus;
  411. $cusrs = arrvalue($dats,$nowcourseid, false);
  412. $modrs = arrvalue($modearr, $rs['modeid'], false);
  413. if(!$modrs || !$cusrs)continue;
  414. $dtfei = time()-(int)$cusrs['zshtime']*60;
  415. $updt = $rs['updt'];
  416. if(isempt($updt))$updt = $rs['optdt'];
  417. $nowcheckida1 = explode(',', $rs['nowcheckid']);
  418. $nowcheckida2 = explode(',', $rs['nowcheckname']);
  419. $table = $modrs['table'];
  420. $ors = $this->db->getone('[Q]'.$table.'','`id`='.$rs['mid'].'');
  421. if(!$ors){
  422. $this->update('`isdel`=1', $rs['id']);
  423. continue;
  424. }
  425. $this->rock->adminid = arrvalue($nowcheckida1,0);
  426. $this->rock->adminname = arrvalue($nowcheckida2,0);
  427. //超时了
  428. if(strtotime($updt)<$dtfei){
  429. $sm = '超'.$cusrs['zshtime'].'分钟未处理自动';
  430. $zt = (int)$cusrs['zshstate'];
  431. if($zt==1 || $zt==2){
  432. m('flow')->opt('check', $modrs['num'], $rs['mid'], $zt, $sm.'审核');//审核
  433. }else{
  434. $this->rock->adminid = 0;
  435. $this->rock->adminname = '系统';
  436. $flow = m('flow')->initflow($modrs['num'], $rs['mid'], false);
  437. if($zt==3)$flow->zuofeibill($sm.'作废');
  438. if($zt==4)$flow->deletebill($sm.'删除', false);
  439. if($zt==5)$flow->chuiban($sm.'催办');
  440. $this->update("`updt`='{$this->rock->now}'", $rs['id']);
  441. }
  442. }
  443. }
  444. }
  445. }
粤ICP备19079148号