| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485 |
- <?php
- class flowbillClassModel extends Model
- {
- public $statustext;
- public $statuscolor;
- public $nowwhere = '';
-
- public function initModel()
- {
- $this->settable('flow_bill');
- $this->statustext = explode(',','待处理,已审核,处理不通过,,,已作废');
- $this->statuscolor = explode(',','blue,green,red,,,gray');
- }
-
- /**
- * 获取状态
- */
- public function getstatus($zt, $lx=0)
- {
- $a1 = $this->statustext;
- $a2 = $this->statuscolor;
- $str = '<font color='.$a2[$zt].'>'.$a1[$zt].'</font>';
- if($lx==0){
- return $str;
- }else{
- return array($a1[$zt], $a2[$zt]);
- }
- }
-
- /**
- * 读取单据数据
- * $glx 0是应用上读取,1后台读取
- */
- public function getrecord($uid, $lx, $page, $limit, $glx=0)
- {
- $srows = array();
- $modeid = (int)$this->rock->get('modeid','0');
- $where = '(`uid`='.$uid.' or `optid`='.$uid.')';
- $isdb = 0;
- //未通过
- if($lx=='flow_wtg'){
- $where .= ' and `status`=2';
- }
-
- if($lx=='flow_dcl'){
- $where .= ' and `status` not in(1,5)';
- }
-
- //已完成
- if($lx=='flow_ywc'){
- $where .= ' and `status`=1';
- }
-
- //异常
- if($lx=='flow_error'){
- $where .= ' and '.$this->errorwhere().'';
- }
-
- //待办
- if($lx=='daiban_daib' || $lx=='daiban_def'){
- $where = '`status` not in(1,2) and `isturn`=1 and '.$this->rock->dbinstr('nowcheckid', $uid);
- $isdb = 1;
- }
-
- //经我处理
- if($lx=='daiban_jwcl'){
- $where = '`isturn`=1 and '.$this->rock->dbinstr('allcheckid', $uid);
- }else if(contain($lx,'_jwcl')){//经我处理跟进模块编号搜索,$lx= 模块编号_jcwl
- $where = '`isturn`=1 and ';
- $wnum = str_replace('_jwcl','', $lx);
- $mrs = m('mode')->getone("`num`='$wnum'");
- if($mrs){
- $where .= '`modeid`='.$mrs['id'].' and ';
- }
- $where .= $this->rock->dbinstr('allcheckid', $uid);
- }
-
- //我全部下级申请
- if($lx=='daiban_myxia'){
- $where = '`isturn`=1 and '.m('admin')->getdownwheres('uid', $uid, 0);
- }
-
- //我直属下级申请
- if($lx=='daiban_mydown'){
- $where = '`isturn`=1 and '.m('admin')->getdownwheres('uid', $uid, 1);
- }
-
- //抄送
- if($lx=='flow_chaos'){
- $where ='1=2';
- $where1= $this->rock->dbinstr('csnameid', $uid);
- if($modeid>0)$where1.=' and `modeid`='.$modeid.'';
- $crows = $this->db->getall("select * from `[Q]flow_chao` where $where1");
- if($crows){
- $modeids = '';
- $modeidsa= array();
- foreach($crows as $k1=>$rs1){
- $modeids.=','.$rs1['modeid'].'';
- $modeidsa[$rs1['modeid']][] = $rs1['mid'];
- }
- foreach($modeidsa as $mkid=>$mids)$wherea[]='(`modeid` = '.$mkid.' and `mid` in('.join(',', $mids).'))';
- $where = '`isturn`=1 and ( '.join(' or ', $wherea).' )';
- }
- }
-
- //监控
- if($lx=='jiankong'){
- $where ='1=2';
- if($modeid>0){
- $wwhere = m('view')->jiankongwhere($modeid, $this->adminid);//返回主表的条件
- $wwhere = str_replace('{asqom}','', $wwhere);
- $moders = $this->db->getone('[Q]flow_set', $modeid);
- $where ='`isturn`=1 and `mid` in(select `id` from `[Q]'.$moders['table'].'` where 1=1 '.$wwhere.')';
- }
- }
- //我关注单据(未开发)
- if($lx=='follow'){
- $where ='1=2';
- }
- $this->nowwhere = $where;
-
- $key = $this->rock->post('key');
- if(!isempt($key))$where.=" and (`optname` like '%$key%' or `modename` like '%$key%' or `sericnum` like '$key%')";
- if($modeid>0)$where.=' and `modeid`='.$modeid.'';
- $arr = $this->getlimit('`isdel`=0 and '.$where, $page,'*','`optdt` desc', $limit);
- $rows = $arr['rows'];
- $modeids= '0';
- foreach($rows as $k=>$rs)$modeids.=','.$rs['modeid'].'';
- $modearr= array();
- if($modeids!='0'){
- $moders = m('flow_set')->getall("`id` in($modeids)");
- foreach($moders as $k=>$rs)$modearr[$rs['id']] = $rs;
- }
- $flowarrmo = array();
- foreach($rows as $k=>$rs){
- $modename = $rs['modename'];
- $summary = '';
- $summarx = '';
- $comidname = '';
- $modenum = '';
- $statustext = '记录不存在';
- $statusstr = '不存在';
- $statuscolor= '#888888';
- $ishui = 0;
- $optdt = $rs['optdt'];
- if(isset($modearr[$rs['modeid']])){
- $mors = $modearr[$rs['modeid']];
- $modenum = $mors['num'];
- if(!isset($flowarrmo[$modenum])){
- $flow = m('flow:'.$modenum.'')->initdata($mors);
- $flowarrmo[$modenum] = $flow;
- }else{
- $flow = $flowarrmo[$modenum];
- }
- $modename = $mors['name'];
- $rers = $this->db->getone('[Q]'.$rs['table'].'', $rs['mid']);
- if($rers){
- $tihsrs = $flow->rsreplace($rers, 2, null, 1);
- $comidname = arrvalue($tihsrs,'comidname');
- $summary = $this->rock->reparr($mors['summary'], $tihsrs);
- $summarx = $this->rock->reparr($mors['summarx'], $tihsrs);
-
- $ztarr = $flow->getstatus($rers, $mors['statusstr'], $rs['nowcheckname']);
- $statustext = $ztarr[0];
- $statuscolor = $ztarr[1];
- $statusstr = $ztarr[3];
- if($rers['status']==5)$ishui = 1;
- }else{
- $this->update('isdel=1', $rs['id']);
- }
- }
-
- $title = '['.$rs['optname'].']'.$modename.'';
- $cont = '申请人:'.$rs['optname'].'<br>单号:'.$rs['sericnum'].'';
- $cont.='<br>申请日期:'.$rs['applydt'].'';
- if(!isempt($summary))$cont.='<br>摘要:'.$summary.'';
- //if(!isempt($rs['nstatustext']))$cont.='<br>状态:'.$rs['nstatustext'].'';
- if(!isempt($rs['checksm']))$cont.='<br>处理说明:'.$rs['checksm'].'';
-
- //应用摘要
- if(!isempt($summarx)){
- $suarr = $this->zhaiyaoar($summarx);
- foreach($suarr as $f=>$nr){
- $str = $this->rock->reparr($nr, $rers);
- if($f=='cont')$str = $this->contreplaces($str);
- $$f = $str;
- }
- if(isset($suarr['cont'])){
- if(isset($suarr['title']))
- $cont = '模块:'.$modename.'<br>申请人:'.$rs['optname'].'<br>'.$cont;
- //if(!isempt($rs['nstatustext']))$cont.='<br>状态:'.$rs['nstatustext'].'';
- if(!isempt($rs['checksm']))$cont.='<br>处理说明:'.$rs['checksm'].'';
- }
- }
- if(ISMORECOM)$cont.='<br>所属单位※:'.$comidname.'';
-
- $srows[]= array(
- 'title' => $title,
- 'cont' => $cont,
- 'ishui' => $ishui,
- 'id' => $rs['mid'],
- 'uid' => $rs['uid'],
- 'optdt' => $optdt,
- 'sericnum' => $rs['sericnum'],
- 'applydt' => $rs['applydt'],
- 'statustext' => $statustext,
- 'statuscolor' => $statuscolor,
- 'statusstr' => $statusstr,
- 'modenum' => $modenum,
- 'modename' => $modename
- );
- }
- $arr['rows'] = $srows;
-
- return $arr;
- }
-
- private function zhaiyaoar($str)
- {
- $stra = explode("\n", $str);
- $arr = array();
- foreach($stra as $nr){
- if(strpos($nr,'title:')===0)$arr['title'] = substr($nr, 6);
- if(strpos($nr,'optdt:')===0)$arr['optdt'] = substr($nr, 6);
- if(strpos($nr,'cont:')===0)$arr['cont'] = substr($nr, 5);
- }
- if(!$arr)$arr['cont'] = $str;
- return $arr;
- }
-
- private function contreplaces($str)
- {
- $stra = explode('[br]', $str);
- $s1 = '';
- foreach($stra as $s){
- $a1 = explode(':', $s);
- if(isset($a1[1]) && $a1[1]==''){
- }else{
- $s1.='$%#'.$s.'';
- }
- }
- if($s1!=''){
- $s1 = str_replace('$%#', "\n", substr($s1, 3));
- }
- return $s1;
- }
-
- //获取待办处理数字
- public function daibanshu($uid)
- {
- $where = '`status` not in(1,2) and `isdel`=0 and `isturn`=1 and '.$this->rock->dbinstr('nowcheckid', $uid);
- $to = $this->rows($where);
- return $to;
- }
-
- //待提提交
- public function daiturntotal($uid)
- {
- $where = '(`uid`='.$uid.' or `optid`='.$uid.') and `status` not in(5) and `isturn`=0 and isdel=0';
- $to = $this->rows($where);
- return $to;
- }
-
- //未通过的
- public function applymywgt($uid)
- {
- $where = '`status`=2 and isdel=0 and (`uid`='.$uid.' or `optid`='.$uid.')';
- $to = $this->rows($where);
- return $to;
- }
-
- //异常单据条件,审核人中有停用的帐号
- public function errorwhere($qz='')
- {
- $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)))';
- return $where;
- }
-
- //异常数
- public function errortotal()
- {
- $where = $this->errorwhere();
- $to = $this->rows($where);
- return $to;
- }
-
- //单据数据
- public function getbilldata($rows)
- {
- $srows = array();
- $modeids= '0';
- foreach($rows as $k=>$rs)$modeids.=','.$rs['modeid'].'';
- $modearr= array();
- if($modeids!='0'){
- $moders = m('flow_set')->getall("`id` in($modeids)");
- foreach($moders as $k=>$rs)$modearr[$rs['id']] = $rs;
- }
- $flow = m('flow:user');
- $flowarrmo = array();
- foreach($rows as $k=>$rs){
- $modename = $rs['modename'];
- $summary = '';
- $modenum = '';
- $comidname = '';
- $statustext = '记录不存在';
- $statuscolor= '#888888';
- $ishui = 0;
- $statusstr = '不存在';
- if(isset($modearr[$rs['modeid']])){
- $mors = $modearr[$rs['modeid']];
- $modename = $mors['name'];
- $summary = $mors['summary'];
- $modenum = $mors['num'];
- if(!isset($flowarrmo[$modenum])){
- $flow = m('flow:'.$modenum.'')->initdata($mors);
- $flowarrmo[$modenum] = $flow;
- }else{
- $flow = $flowarrmo[$modenum];
- }
- $rers = $this->db->getone('[Q]'.$rs['table'].'', $rs['mid']);
- $summary = $this->rock->reparr($summary, $rers);
- if($rers){
- $tihsrs = $flow->rsreplace($rers, 2, null, 1);
- $summary = $this->rock->reparr($mors['summary'], $tihsrs);
-
- $comidname = arrvalue($tihsrs,'comidname');//所属单位
- $nowsets = $rs['nowcheckname']; //当前审核人
- $ztarr = $flow->getstatus($rers, $mors['statusstr'], $nowsets);
- $statustext = $ztarr[0];
- $statuscolor = $ztarr[1];
- if($rers['status']==5)$ishui = 1;
- $statusstr = $ztarr[3];
- }else{
- $this->update('isdel=1', $rs['id']); //记录已经不存在了
- }
- }
- $name = $rs['name'];
- if(isempt($name))$name = $rs['uname'];
- $deptname = $rs['deptname'];
- if(isempt($deptname))$deptname = $rs['udeptname'];
-
- $srows[]= array(
- 'id' => $rs['mid'],
- 'optdt' => $rs['optdt'],
- 'applydt' => $rs['applydt'],
- 'optname' => arrvalue($rs,'optname'),
- 'name' => $name,
- 'deptname' => $deptname,
- 'sericnum' => $rs['sericnum'],
- 'updt' => $rs['updt'],
- 'nowcheckid'=> $rs['nowcheckid'],
- 'nowcourseid'=> $rs['nowcourseid'], //当前步骤
- 'ishui' => $ishui,
- 'modename' => $modename,
- 'modenum' => $modenum,
- 'summary' => $summary,
- 'comidname' => $comidname,
- 'status' => $statusstr
- );
- }
- return $srows;
- }
-
- /**
- * 首页上显示我的申请
- */
- public function homelistshow()
- {
- $arr = $this->getrecord($this->adminid, 'flow_dcl', 1, 5,1);
- $rows = $arr['rows'];
- $arows = array();
- foreach($rows as $k=>$rs){
- $cont = '【'.$rs['modename'].'】单号:'.$rs['sericnum'].',日期:'.$rs['applydt'].','.$rs['statusstr'].'';
- $arows[] = array(
- 'cont' => $cont,
- 'modename' => $rs['modename'],
- 'modenum' => $rs['modenum'],
- 'id' => $rs['id'],
- 'count' => $arr['count']
- );
- }
- return $arows;
- }
-
- /*
- * 更新记录
- */
- public function updatebill($whe='')
- {
- $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.'');
- $ztara= array(1,5);
- foreach($rows as $k=>$rs){
- if(isempt($rs['name']))continue;
- $zt = $rs['status'];
- if(isempt($rs['uname']) || isempt($rs['udeptname']) || !in_array($zt, $ztara)){
- $this->update(array(
- 'uname' => $rs['name'],
- 'udeptname' => $rs['deptname'],
- ), $rs['id']);
- }
- }
- }
-
-
- /**
- * 超过几分钟自动作废
- */
- public function autocheck()
- {
- //要作废的流程模块
- $rows = $this->db->getall('select `id`,`zfeitime`,`num` from `[Q]flow_set` where `status`=1 and `isflow`>0 and `zfeitime`>0');
- $this->rock->adminid = 0;
- $this->rock->adminname = '系统';
- foreach($rows as $k=>$rs){
- $modeid = $rs['id'];
- $dtfei = date('Y-m-d H:i:s', time()-(int)$rs['zfeitime']*60);
- $data = $this->getall("`modeid`='$modeid' and `isturn`=1 and `status` not in(1,5) and `updt`<'$dtfei'");
- if($data){
- $flow = m('flow')->initflow($rs['num']);
- foreach($data as $k1=>$rs1){
- $flow->loaddata($rs1['mid'], false);
- $flow->zuofeibill('超'.$rs['zfeitime'].'分钟未处理自动作废');
- }
- }
- }
-
- //超过几分钟自动审核通过/不通过
- $dats = $this->db->getarr('[Q]flow_course','`zshtime`>0 and `status`=1','zshtime,zshstate');
- $custids = '';
- if($dats)foreach($dats as $cid=>$rs)$custids.=','.$cid.'';
- if($custids=='')return;
- $custids = substr($custids, 1);
- $mxxus = 99999;
- $rows = $this->getall('`isturn`=1 and `status`=0 and `isdel`=0 and ((`nowcourseid` in('.$custids.')) or (`nowcourseid`>'.$mxxus.' and ((`nowcourseid`-`nowcheckid`)/'.$mxxus.') in('.$custids.')) )');
- //echo $this->db->nowsql;
- if(!$rows)return;
- $modeids = '';
- foreach($rows as $k=>$rs)$modeids.=','.$rs['modeid'].'';
- $modearr = $this->db->getarr('[Q]flow_set','id in('.substr($modeids, 1).')','`num`,`table`');
-
- foreach($rows as $k=>$rs){
- if(isempt($rs['nowcheckid']))continue;
- $nowcourseid = $rs['nowcourseid'];
- if($nowcourseid>$mxxus)$nowcourseid = ($nowcourseid-$rs['nowcheckid'])/$mxxus;
-
- $cusrs = arrvalue($dats,$nowcourseid, false);
- $modrs = arrvalue($modearr, $rs['modeid'], false);
- if(!$modrs || !$cusrs)continue;
- $dtfei = time()-(int)$cusrs['zshtime']*60;
- $updt = $rs['updt'];
- if(isempt($updt))$updt = $rs['optdt'];
- $nowcheckida1 = explode(',', $rs['nowcheckid']);
- $nowcheckida2 = explode(',', $rs['nowcheckname']);
-
- $table = $modrs['table'];
- $ors = $this->db->getone('[Q]'.$table.'','`id`='.$rs['mid'].'');
- if(!$ors){
- $this->update('`isdel`=1', $rs['id']);
- continue;
- }
-
- $this->rock->adminid = arrvalue($nowcheckida1,0);
- $this->rock->adminname = arrvalue($nowcheckida2,0);
-
- //超时了
- if(strtotime($updt)<$dtfei){
- $sm = '超'.$cusrs['zshtime'].'分钟未处理自动';
- $zt = (int)$cusrs['zshstate'];
-
- if($zt==1 || $zt==2){
- m('flow')->opt('check', $modrs['num'], $rs['mid'], $zt, $sm.'审核');//审核
- }else{
- $this->rock->adminid = 0;
- $this->rock->adminname = '系统';
- $flow = m('flow')->initflow($modrs['num'], $rs['mid'], false);
- if($zt==3)$flow->zuofeibill($sm.'作废');
- if($zt==4)$flow->deletebill($sm.'删除', false);
- if($zt==5)$flow->chuiban($sm.'催办');
- $this->update("`updt`='{$this->rock->now}'", $rs['id']);
- }
- }
- }
-
- }
- }
|