flowbillModel.php 14 KB

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