flow.php 119 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712
  1. <?php
  2. /**
  3. * 来自:信呼开发团队
  4. * 作者:磐石(rainrock)
  5. * 网址:http://www.rockoa.com/
  6. * 系统的核心文件之一,处理工作流程模块的。
  7. */
  8. class flowModel extends Model
  9. {
  10. public $modenum; //当前模块编号
  11. public $editcont= ''; //修改的记录
  12. public $id = 0; //当前单据ID
  13. public $moders; //当前模块数组
  14. public $modeid; //当前模块Id
  15. public $modename; //当前模块名称
  16. public $sericnum; //当前单据单号
  17. public $billrs = array(); //当前单据流程信息
  18. public $rs = array(); //当前单据记录信息
  19. public $urs = array(); //当前单据对应用户
  20. public $drs = array(); //当前单据对应用户
  21. public $fieldsarr = array(); //主表元素字段数组
  22. public $fieldsarra = array(); //元素数组
  23. public $mwhere;
  24. public $mtable; //当前模块对应表
  25. public $uname; //当前单据对应用户姓名
  26. public $uid = 0; //当前单据对应用户Id
  27. public $optid = 0; //当前当街对应操作用Id,如提交人Id
  28. public $isflow = 0; //当前模块是否有流程审核步骤
  29. public $ismobile= 0; //是否移动的页面请求的
  30. public $minwidth= 100; //录入页面子表最小宽度
  31. public $inputwidth= 0; //录入页面宽度
  32. public $atype = '';
  33. public $daochubo= false; //是否导出操作
  34. public $companyid= 1; //默认单位Id
  35. //当初始化模块后调用
  36. protected function flowinit(){}
  37. //当初始化单据调用
  38. protected function flowchangedata(){}
  39. //当触发通知时处理
  40. protected function flowchangetodo(){}
  41. //删除单据时调用,$sm删除说明
  42. protected function flowdeletebill($sm){}
  43. //作废单据时调用,$sm作废说明
  44. protected function flowzuofeibill($sm){}
  45. //提交时调用
  46. protected function flowsubmit($na, $sm){}
  47. //添加日志记录调用$arr 添加数组
  48. protected function flowaddlog($arr){}
  49. protected function flowdatalog($arr){}
  50. //审核之前调用$zt 状态, $sm说明
  51. protected function flowcheckbefore(){}
  52. //审核完成后调用
  53. protected function flowcheckafter($zt, $sm){}
  54. //流程全部完成后调用
  55. protected function flowcheckfinsh($zt){}
  56. protected function flowgetfields($lx){}
  57. protected function flowgetoptmenu($opt){}
  58. //自定义审核人重新的方法$num 步骤单号
  59. protected function flowcheckname($num){}
  60. //审核步骤根据$num 编号判断是否需要审核
  61. protected function flowcoursejudge($num){}
  62. //操作单据
  63. protected function flowoptmenu($ors, $crs){}
  64. //自定义是否可查看本单据
  65. protected function flowisreadqx(){return false;}
  66. //自定义是否可以删除权限,如返回0不能删除,1可删除,其他值无效
  67. protected function flowisdeleteqx(){return false;}
  68. //已弃用
  69. protected function flowprintrows($r){return $r;}
  70. //子表数据替换处理$lx=0编辑时,1展示时
  71. protected function flowsubdata($r, $lx=0){return $r;}
  72. //默认推送格式从写
  73. protected function flownexttodo($type){return false;}
  74. //单据判断条件从写$lx类型,$uid用户Id
  75. protected function flowbillwhere($lx, $uid){return '';}
  76. protected $flowweixinarr = array();
  77. protected $flowviewufieds = 'uid';
  78. //关联单位id字段默认是comid
  79. protected $flowcompanyidfieds = 'comid';
  80. protected $flowfieldstype = 0; //获取字段类型0默认*,1根据字段元素设置得到字段
  81. //初始化单据可替换其他属性,$lx,0默认,1详情展示,2列表显示,3打印页,4外部详情页
  82. public function flowrsreplace($rs){return $rs;}
  83. //这个是移动端列表中使用
  84. public function flowrsreplace_we($row, $rs){return $row;}
  85. //通用移动端列表搜索
  86. public function flowwesearchdata($lx){return array();}
  87. //编辑的时候替换
  88. protected function flowrsreplaceedit($rs){return $rs;}
  89. //默认状态1时可以就算审核通过,默认是1
  90. protected $flowstatusarr = array(1);
  91. //子表样式,可以改成print打印
  92. protected $subsubdatastyle = '';
  93. //关联其他模块
  94. protected $wherejoin = array();
  95. //默认排序如:id,desc
  96. public $defaultorder = '';
  97. //是否可编辑别人单据
  98. public $floweditother = false;
  99. //详情边框元素
  100. public $xiangbordercolor = '';
  101. public function echomsg($msg)
  102. {
  103. if(!isajax())exit($msg);
  104. showreturn('', $msg, 201);
  105. exit();
  106. }
  107. //字段处理$farr字段,$lx=0pc,1移动
  108. public function flowfieldarr($farr, $lx){return $farr;}
  109. //自定义录入模版$lx=0pc,1移动
  110. public function flowinputtpl($cont, $lx){return $cont;}
  111. public function flowviewtpl($cont, $lx){return $cont;}
  112. //在线编辑单据下附件
  113. public function floweditoffice($frs, $ofrs){}
  114. /**
  115. * 初始化流程信息
  116. */
  117. public function initdata($num, $id=null)
  118. {
  119. if(is_array($num)){
  120. $this->moders= $num;
  121. }else{
  122. $this->moders = m('flow_set')->getone(is_numeric($num) ? $num : "`num`='$num'");
  123. if(!$this->moders)$this->echomsg('模块['.$num.']不存在,请到[流程模块列表]下添加');
  124. }
  125. $this->daochubo = ($this->rock->post('execldown')=='true') ? true :false;
  126. $table = $this->moders['table'];
  127. $this->modeid = $this->moders['id'];
  128. $this->modenum = $this->moders['num'];
  129. $this->modename = $this->moders['name'];
  130. $this->isflow = (int)$this->moders['isflow'];
  131. $this->settable($table);
  132. $this->mtable = $table;
  133. $this->viewmodel = m('view');
  134. $this->chaomodel = m('flow_chao');
  135. $this->billmodel = m('flow_bill');
  136. $this->todomodel = m('flow_todo');
  137. $this->todosmodel = m('flowtodo');
  138. $this->flogmodel = m('flow_log');
  139. $this->checksmodel = m('flow_checks');
  140. $this->cnamemodel = m('flowcname');
  141. $this->wheremodel = m('where');
  142. $this->adminmodel = m('admin');
  143. $this->remindmodel = m('remind'); //单据提醒表
  144. $this->option = m('option');
  145. $this->companyid = $this->adminmodel->getcompanyid();
  146. $this->tfieldsarra(); //初始化录入的表单元素
  147. $this->mwhere = "`table`='$this->mtable' and `mid`=-1";
  148. if(!$this->defaultorder){
  149. $sortdir = arrvalue($this->moders, 'sortdir');
  150. if(!isempt($sortdir))$this->defaultorder = str_replace(' ',',', $sortdir);
  151. }
  152. $this->flowinit();
  153. if($id==null)return $this;
  154. $this->loaddata($id, true);
  155. return $this;
  156. }
  157. private function tfieldsarra()
  158. {
  159. $rows = m('flow_element')->getrows("`mid`='$this->modeid' and `iszb`=0",'`name`,`fields`,`isbt`,`iszs`,`fieldstype`,`savewhere`,`data`,`isdr`,`iszb`,`issou`,`islu`,`islb`,`isonly`,`attr`','`sort`');
  160. $this->fieldsarr = array();
  161. if($rows)foreach($rows as $k=>$rs){
  162. if($rs['islu']==1)$this->fieldsarr[] = $rs;
  163. }
  164. $this->fieldsarra = $rows;
  165. }
  166. //录入页上的标题
  167. public function inputtitle()
  168. {
  169. return $this->moders['name'];
  170. }
  171. /**
  172. * 列表上要搜索的的,此方法仅用到在:webmain/flow/input/inputAction.php 行607上返回,模块接口可重写这个方法
  173. */
  174. public function flowsearchfields()
  175. {
  176. $arr = array();
  177. if($this->isflow>0){
  178. $arr[] = array('name'=>'申请人...','fields'=>'uid');
  179. $arr[] = array('name'=>'提交人...','fields'=>'optid');
  180. }
  181. return $arr;
  182. }
  183. /**
  184. * 初始化单据数据
  185. * id 单据Id $ispd 是否判断有查看权限
  186. */
  187. public function loaddata($id, $ispd=true)
  188. {
  189. $this->id = (int)$id;
  190. $this->mwhere = "`table`='$this->mtable' and `mid`='$id'";
  191. //防止同主表模块串数据
  192. $swhere = "`id`='$id'";
  193. $wherestr = $this->moders['where'];
  194. if(!isempt($wherestr)){
  195. $wherestr = $this->rock->covexec($wherestr);
  196. $swhere .= ' and '.$wherestr;
  197. }
  198. $this->rs = $this->getone($swhere);
  199. $this->uname = '';
  200. if(!$this->rs)$this->echomsg('数据记录不存在了');
  201. $this->rs['base_name'] = '';
  202. $this->rs['base_deptname'] = '';
  203. if(isset($this->rs['uid']))$this->uid = $this->rs['uid'];
  204. if(isset($this->rs['comid']))$this->companyid = $this->rs['comid'];
  205. if(!isset($this->rs['applydt']))$this->rs['applydt'] = '';
  206. if(!isset($this->rs['status']))$this->rs['status'] = 1;
  207. $uisfield = property_exists($this, 'uidfields') ? $this->uidfields : 'optid';
  208. if($this->uid==0 && isset($this->rs[$uisfield]))$this->uid = $this->rs[$uisfield];
  209. $this->optid = isset($this->rs['optid']) ? $this->rs['optid'] : $this->uid;
  210. $this->urs = $this->adminmodel->getone($this->uid,'id,name,user,deptid,deptids,deptname,deptallname,face,ranking,superid,superpath,superman,deptpath');
  211. if($this->isempt($this->rs['applydt'])&&isset($this->rs['optdt']))$this->rs['applydt']=substr($this->rs['optdt'],0,10);
  212. if($this->urs){
  213. $this->drs = $this->db->getone('[Q]dept',"`id`='".$this->urs['deptid']."'");
  214. $this->uname = $this->urs['name'];
  215. $this->rs['base_name'] = $this->uname;
  216. if($this->drs){
  217. $this->rs['base_deptname'] = $this->drs['name'];
  218. }
  219. }
  220. $this->sericnum = '';
  221. $this->billrs = $this->billmodel->getone($this->mwhere);
  222. if($this->billrs){
  223. $this->sericnum = $this->billrs['sericnum'];
  224. if(isempt(arrvalue($this->billrs,'uname'))){
  225. $this->savebill();
  226. }
  227. if($this->billrs['status']!=$this->rs['status'])$this->billmodel->update('`status`='.$this->rs['status'].'', $this->billrs['id']);//状态不一样更新一下
  228. if($this->billrs['isturn']!=$this->rs['isturn'])$this->billmodel->update('`isturn`='.$this->rs['isturn'].'', $this->billrs['id']);
  229. if(isempt($this->rs['base_name']))$this->rs['base_name'] = $this->billrs['uname'];
  230. if(isempt($this->rs['base_deptname']))$this->rs['base_deptname'] = $this->billrs['udeptname'];
  231. }else{
  232. if($this->isflow>0)$this->savebill();
  233. }
  234. if($this->isflow>0){
  235. if($this->rs['status']==1 && $this->rs['isturn']=='0'){
  236. $this->update(array('isturn' => 1), $this->id);
  237. $this->rs['isturn'] = 1;
  238. if($this->billrs)$this->billmodel->update('`isturn`=1', $this->billrs['id']);
  239. }
  240. }
  241. $this->getlogrows = array();
  242. if($ispd)$this->isreadqx();
  243. $this->rssust = $this->rs;
  244. $this->flowchangedata();
  245. $this->rs['base_systitle'] = TITLE;//系统名称
  246. $this->rs['base_modename'] = $this->modename;
  247. $this->rs['base_sericnum'] = $this->sericnum;
  248. $this->rs['base_summary'] = $this->getsummary();
  249. }
  250. /**
  251. * 当前模块我待办数量
  252. */
  253. public function getdaiban()
  254. {
  255. $s = $this->rock->dbinstr('nowcheckid', $this->adminid);
  256. $to = $this->billmodel->rows('`modeid`='.$this->modeid.' and `isdel`=0 and `status` not in(1,2) and '.$s.'');
  257. return $to;
  258. }
  259. /**
  260. * 判断单据是否可以查看
  261. */
  262. public function isreadqx($glx=0)
  263. {
  264. $bo = false;
  265. if($this->adminid==1)$bo=true;//为1的超级管理员可查看
  266. if($this->uid==$this->adminid && $this->adminid>0)$bo=true;
  267. if(!$bo && $this->isflow>0){
  268. if($this->billrs){
  269. $allcheckid = $this->billrs['allcheckid'];
  270. if(contain(','.$allcheckid.',',','.$this->adminid.','))$bo = true;
  271. }
  272. }
  273. //可以查看下属人员的
  274. if(!$bo){
  275. if($this->urs && contain($this->urs['superpath'],'['.$this->adminid.']'))$bo = true;
  276. }
  277. //通知表上的权限
  278. if(!$bo){
  279. $tos = $this->todosmodel->rows("".$this->mwhere." and `uid`='$this->adminid'");
  280. if($tos>0)$bo=true;
  281. }
  282. //抄送表上的
  283. if(!$bo){
  284. $tos = $this->chaomodel->rows($this->mwhere.' and '.$this->rock->dbinstr('csnameid', $this->adminid).'');
  285. if($tos>0)$bo=true;
  286. }
  287. //todo表里
  288. if(!$bo){
  289. $tos = $this->db->rows('[Q]todo', "`uid`='$this->adminid' and ".$this->mwhere."");
  290. if($tos>0)$bo=true;
  291. }
  292. if(!$bo)$bo = $this->flowisreadqx(); //自定义查看权限
  293. //权限设置上的
  294. if(!$bo){
  295. $bo = $this->isreadqxs();
  296. }
  297. //监控流程也是可以查看
  298. if(!$bo){
  299. $tos = $this->isjiankongqx();
  300. if($tos>0)$bo=true;
  301. }
  302. if($glx==1)return $bo;
  303. if(!$bo)$this->echomsg('无权限查看模块['.$this->modenum.'.'.$this->modename.']'.$this->uname.'的数据,请联系管理员到[流程模块→流程模块权限]下设置');
  304. }
  305. /**
  306. * 从权限上看是否有查看权限
  307. */
  308. public function isreadqxs()
  309. {
  310. $bo = false;
  311. $where = $this->viewmodel->viewwhere($this->moders, $this->adminid, $this->flowviewufieds);
  312. $where = str_replace('{asqom}','', $where);
  313. $tos = $this->rows("`id`='$this->id' $where ");
  314. if($tos>0)$bo=true;
  315. return $bo;
  316. }
  317. /**
  318. * 判断单据是否可以编辑
  319. */
  320. public function iseditqx()
  321. {
  322. $bo = 0;
  323. if($bo==0 && $this->isflow>0){
  324. if($this->billrs && ($this->uid == $this->adminid || $this->optid==$this->adminid)){
  325. if($this->billrs['nstatus']==0 || $this->billrs['nstatus']==2){
  326. $bo = 1;
  327. }
  328. }
  329. if($this->rs['status']==1)$bo=0;
  330. }
  331. if($bo==0){
  332. $where = $this->viewmodel->editwhere($this->moders, $this->adminid, $this->flowviewufieds);
  333. $where = str_replace('{asqom}','', $where);
  334. $tos = $this->rows("`id`='$this->id' $where ");
  335. if($tos>0)$bo=1;
  336. }
  337. return $bo;
  338. }
  339. /**
  340. * 判断当前单据是否可以删除
  341. */
  342. public function isdeleteqx()
  343. {
  344. $bo = 0;
  345. if($bo==0 && $this->isflow>0){
  346. if($this->billrs && ($this->uid == $this->adminid || $this->optid==$this->adminid)){
  347. if($this->billrs['nstatus']==0 || $this->billrs['nstatus']==2){
  348. $bo = 1;
  349. }
  350. }
  351. if($this->rs['status']==1)$bo=0;
  352. }
  353. if($bo==0){
  354. $where = $this->viewmodel->deletewhere($this->moders, $this->adminid, $this->flowviewufieds);
  355. $where = str_replace('{asqom}','', $where);
  356. $tos = $this->rows("`id`='$this->id' $where ");
  357. if($tos>0)$bo=1;
  358. }
  359. $isd = $this->flowisdeleteqx();
  360. if(is_numeric($isd) && $isd <= 1)$bo = $isd;
  361. return $bo;
  362. }
  363. /**
  364. * 判断是否监控权限
  365. */
  366. public function isjiankongqx()
  367. {
  368. $bo = 0;
  369. if($bo==0){
  370. $where = $this->viewmodel->jiankongwhere($this->moders, $this->adminid, $this->flowviewufieds);
  371. $where = str_replace('{asqom}','', $where);
  372. $tos = $this->rows("`id`='$this->id' $where ");
  373. if($tos>0)$bo=1;
  374. }
  375. return $bo;
  376. }
  377. /**
  378. * 获取详情展示字段
  379. */
  380. public function getfields($lx=0)
  381. {
  382. $fields = array();
  383. if(!$this->fieldsarra)$this->tfieldsarra();
  384. $farr = $this->fieldsarra;
  385. foreach($farr as $k=>$rs)if($rs['iszs']=='1')$fields[$rs['fields']] = $rs['name'];
  386. $fters = $this->flowgetfields($lx);
  387. if(is_array($fters))$fields = array_merge($fields, $fters);
  388. return $fields;
  389. }
  390. /**
  391. * 获取录入页面地址
  392. */
  393. public function getinputurl($num='',$mid=0,$can=array())
  394. {
  395. if($num=='')$num = $this->modenum;
  396. $xa = 'lu';
  397. if($this->ismobile==1)$xa = 'lum';
  398. $url = 'index.php?a='.$xa.'&m=input&d=flow&num='.$num.'&mid='.$mid.'';
  399. if(is_array($can)){
  400. foreach($can as $k=>$v)$url.='&'.$k.'='.$v.'';
  401. }else{
  402. $url .= '&'.$can.'';
  403. }
  404. return $url;
  405. }
  406. public function replacepbr(&$arr, $k)
  407. {
  408. $val = arrvalue($arr, $k);
  409. if(!c('html')->ishtml($val))$arr[$k] = str_replace("\n",'<br>', $val);
  410. return $arr;
  411. }
  412. /**
  413. * 读取展示数据
  414. * $lx 0pc, 1移动,$isdy=2就是打印读取
  415. */
  416. public function getdatalog($lx=0, $isdy=0)
  417. {
  418. m('log')->addread($this->mtable, $this->id);
  419. $this->todosmodel->biaoyidu($this->adminid, $this->modenum, $this->id);
  420. $fobj = m('file');
  421. $this->ismobile = $lx;
  422. $arr['modename'] = $this->modename;
  423. $arr['title'] = $this->modename;
  424. $arr['modeid'] = $this->modeid;
  425. $arr['modenum'] = $this->modenum;
  426. $arr['mid'] = $this->id;
  427. $arr['status'] = arrvalue($this->rs,'status');
  428. $arr['logarr'] = $this->getlog(1);
  429. $arr['isplview'] = arrvalue($this->moders,'ispl','0');
  430. $arr['isys'] = arrvalue($this->moders,'isys','0');
  431. $contview = '';
  432. $lsds = ($isdy==2) ? $isdy: $lx;
  433. $path = ''.P.'/flow/page/view_'.$this->modenum.'_'.$lsds.'.html';
  434. if(COMPANYNUM){
  435. $path1 = ''.P.'/flow/page/view_'.$this->modenum.'_'.COMPANYNUM.'_'.$lsds.'.html';
  436. if(file_exists($path1))$path = $path1;
  437. }
  438. $fstr = $fobj->getstr($this->mtable, $this->id, 3);//3说明是详情也读
  439. $issubtabs = 0;
  440. //if($fstr != ''){
  441. // $this->rs['file_content'] = $fstr;
  442. //}
  443. $data = $this->flowrsreplace($this->rs, ($isdy==2) ? 3 : 1);
  444. $dataa = $this->viewjinfields(array($data));
  445. $data = $dataa[0];
  446. //读取多行子表
  447. $subdata = $this->getsuballdata(1);
  448. if($subdata){
  449. $zbzd = m('flow_element')->getrows("`mid`='$this->modeid' and `iszb`>0 and `iszs`=1 and `fieldstype` in('uploadimg','uploadfile','textarea')",'`name`,`fields`,`fieldstype`,`iszb`','`iszb`,`sort`');
  450. foreach($subdata as $zb=>$da){
  451. $sub = $da['fields'];
  452. //--autharstart--
  453. foreach($zbzd as $k1=>$rs1){
  454. if($rs1['iszb']==$zb+1){
  455. $fty = $rs1['fieldstype'];
  456. $fid = $rs1['fields'];
  457. foreach($da['data'] as $k2=>$rs2){
  458. $fval = arrvalue($rs2, $fid);
  459. if($fty=='uploadimg'){
  460. if(!isempt($fval) && substr($fval,0,4)!='<img'){
  461. $fval = $this->rock->gethttppath($fval);
  462. $da['data'][$k2][$fid] = '<img src="'.$fval.'" onclick="c.showviews(this)" height="70">';
  463. }
  464. }
  465. if($fty=='uploadfile'){
  466. if(isempt($fval))$fval='0';
  467. if($fval!='0'){
  468. $da['data'][$k2][$fid] = $fobj->getstr('', '', 3, "`id` in($fval)");
  469. }
  470. }
  471. if($fty=='textarea'){
  472. $this->replacepbr($da['data'][$k2], $fid);
  473. }
  474. }
  475. }
  476. }
  477. //--autharend--
  478. $data[$sub] = $this->getsubdata($zb,$da['data'],arrvalue($data,'subdatays'.$zb.'',$lx));
  479. $data[''.$sub.'_style'] = 'padding:0';
  480. }
  481. }
  482. //文件字段替换上传和上传图片的
  483. $farrobj = $chufarr= array();
  484. if(method_exists($this, 'flowxiangfields'))$chufarr = $this->flowxiangfields($chufarr);
  485. $farrobj['base_sericnum'] = array('name'=>arrvalue($chufarr,'base_sericnum','单号'));
  486. $farrobj['base_name'] = array('name'=>arrvalue($chufarr,'base_name','申请人'));
  487. $farrobj['base_deptname'] = array('name'=>arrvalue($chufarr,'base_deptname','申请人部门'));
  488. $farrobj['base_status'] = array('name'=>arrvalue($chufarr,'base_status','流程状态'));
  489. $farrobj['file_content'] = array('name'=>arrvalue($chufarr,'file_content','相关文件'));
  490. foreach($this->fieldsarra as $k=>$rs){
  491. $fid = $rs['fields'];
  492. $fty = $rs['fieldstype'];
  493. if($fty=='uploadfile'){
  494. $fval = arrvalue($data, $fid);
  495. if(isempt($fval))$fval='0';
  496. $data[$fid] = '';
  497. if($fval!='0'){
  498. $data[$fid] = $fobj->getstr('', '', 3, "`id` in($fval)");
  499. }
  500. }
  501. if($fty=='uploadimg'){
  502. $fval = arrvalue($data, $fid);
  503. if(!isempt($fval) && substr($fval,0,4)!='<img'){
  504. $fval = $this->rock->gethttppath($fval);
  505. $data[$fid] = '<img src="'.$fval.'" onclick="c.showviews(this)" height="100">';
  506. }
  507. }
  508. //文本域自动换行
  509. if($fty=='textarea'){
  510. $this->replacepbr($data, $fid);
  511. }
  512. if($fty=='ditumap' && !isempt($rs['data'])){
  513. $wzhi = arrvalue($data, $rs['data']);
  514. if(!isempt($wzhi))$data[$fid].='<a href="javascript:;" onclick="js.showmap(\''.$wzhi.','.$data[$fid].'\')">[查看地图]</a>';
  515. }
  516. $farrobj[$fid] = $rs;
  517. }
  518. $_logarr = $qfields = array();
  519. foreach($arr['logarr'] as $k1=>$rs1)$_logarr[$rs1['id']] = $rs1;
  520. //读取流程审核步骤信息,只显示同意的
  521. $logrows = $this->flogmodel->getrows($this->mwhere.' and `modeid`='.$this->modeid.' and `courseid`>0 and `courseid`<88888 and `status`>0 and `valid`=1');
  522. foreach($logrows as $k2=>$rs2){
  523. $rs3 = $_logarr[$rs2['id']];
  524. $_coid = $rs2['courseid'];
  525. if(!isempt($rs3['qmimg']))$rs3['name'] = '<img height="30" onclick="c.showviews(this)" width="70" src="'.$rs3['qmimg'].'">';
  526. $key1 = 'course'.$_coid.'';
  527. //if(isempt($rs3['sm']))$rs3['sm']= $rs3['statusname'];
  528. if(!isset($data[''.$key1.'_name'])){
  529. $data[''.$key1.'_name'] = $rs3['name'];
  530. $data[''.$key1.'_zt'] = '<font color="'.$rs3['color'].'">'.$rs3['statusname'].'</font>';
  531. $data[''.$key1.'_sm'] = $rs3['sm'];
  532. $data[''.$key1.'_dt'] = $rs3['checkdt'];
  533. }else{
  534. $data[''.$key1.'_name'] .= ','.$rs3['name'];
  535. $data[''.$key1.'_sm'] .= ','.$rs3['sm'];
  536. $data[''.$key1.'_dt'] = $rs3['checkdt'];
  537. }
  538. //全部处理意见
  539. $key2 = ''.$key1.'_all';
  540. if(!isset($data[$key2])){
  541. $qfields[$key2] = $rs2['name'];
  542. $data[$key2]='';
  543. }
  544. $str1 = $rs3['name'].' <font color="'.$rs3['color'].'">'.$rs3['statusname'].'</font> '.$rs3['checkdt'].'';
  545. if(!isempt($rs3['sm']))$str1.=','.$rs3['sm'].'';
  546. if($data[$key2]!='')$data[$key2].='<hr size="1">';
  547. $data[$key2].= $str1;
  548. }
  549. $ztass = $this->getnowstatus();
  550. $data['base_status'] = $ztass[3];
  551. //使用了自定的展示模板
  552. if(file_exists($path)){
  553. $contview = $this->flowviewtpl(file_get_contents($path), $lx);
  554. preg_match_all('/\^(.*?)\^/', $contview, $list);
  555. foreach($list[1] as $k=>$nrs){
  556. $fzdrs = arrvalue($farrobj, $nrs);
  557. if($fzdrs)$contview = str_replace('^'.$nrs.'^', $fzdrs['name'], $contview);
  558. }
  559. $contview = $this->rock->reparr($contview, $data);
  560. }
  561. $arr['isdefaultview'] = 0;
  562. if($this->isempt($contview) || contain($contview, '$contview$')){
  563. $arr['isdefaultview'] = 1;
  564. $_fields = array();
  565. if($this->isflow>0){
  566. $_fields['base_sericnum'] = $farrobj['base_sericnum']['name'];
  567. $_fields['base_name'] = $farrobj['base_name']['name'];
  568. $_fields['base_deptname'] = $farrobj['base_deptname']['name'];
  569. $_fields['base_status'] = $farrobj['base_status']['name'];
  570. }
  571. $fields = array_merge($_fields, $this->getfields($lx));
  572. //if($fstr!='')$fields['file_content'] = $farrobj['file_content']['name'];
  573. foreach($subdata as $zb=>$da){
  574. $fields[$da['fields']] = $da['name'];
  575. }
  576. if($qfields)$fields = array_merge($fields,$qfields);//审核的字段显示到详情里
  577. if($lx==0)foreach($fields as $k=>$rs){$data[''.$k.'_style'] = 'width:75%';break;}
  578. $_colsr = $this->xiangbordercolor;
  579. if($_colsr=='')$_colsr = getconfig('bcolorxiang');
  580. $contvimr = c('html')->xiangtable($fields, $data, $_colsr);
  581. $contvimr = '<div align="center">'.$contvimr.'</div>';
  582. //移动默认展示
  583. if($lx==1){
  584. $contvimr = '';
  585. if($this->isflow>0){
  586. $contvimr.='<div class="r-border-b">
  587. <div class="blank5"></div>
  588. <table><tr>
  589. <td width="50" align="left"><img style="height:40px;width:40px;border-radius:50%;" src="'.$this->urs['face'].'"></td>
  590. <td><div>'.$this->urs['name'].'<font color="#888888">('.$this->urs['ranking'].')</font></div><div style="padding-top:5px">'.$this->urs['deptallname'].'</div></td>
  591. </tr></table>
  592. <div style="margin:5px 0px" class="blank10"></div>
  593. </div>';
  594. unset($fields['base_name']);
  595. unset($fields['base_deptname']);
  596. }
  597. $contvimr .= '<div><table width="100%" id="mobile_info_table">';
  598. foreach($fields as $f=>$n){
  599. $vs = arrvalue($data, $f);
  600. if(!isempt($vs)){
  601. //子表
  602. if(substr($f,0,7)=='subdata'){
  603. $contvimr .= '<tr><td colspan="3"><div style="padding:5px" align="left"><div><b>'.$n.'</b></div>'.$vs.'</div></td></tr>';
  604. }else{
  605. $contvimr .= '<tr><td style="vertical-align:text-top;">';
  606. $contvimr .= '<div align="left" style="color:#000;padding:6px 0px 3px;font-size:16px;font-weight:bold;">';
  607. $contvimr .= str_replace(' ','<br>',$n); // 标题
  608. $contvimr .= '</div>';
  609. $contvimr .= '<div style="padding:8px 10px 8px 10px;color:#3A3A3C;font-size:15px;width:94%;min-height:15px;border:1px solid #dcdcdc;border-radius:5px;" align="left">';
  610. if ($f == 'base_status' || fnmatch("course[0-9]*_all",$f)) {
  611. $contvimr .= $vs;
  612. } else {
  613. $contvimr .= '<input class="inputs" style="border:none;background:none;" name="input_'.$f.'" value="'.$vs.'" readonly="">';
  614. }
  615. $contvimr .= '</div></td><td></td></tr>';
  616. }
  617. }
  618. }
  619. $contvimr .= '</table></div>';
  620. }
  621. if(isempt($contview))$contview = $contvimr;
  622. $contview = str_replace('$contview$',$contvimr, $contview);
  623. }
  624. unset($farrobj);
  625. $arr['contview'] = $contview;
  626. $arr['readarr'] = m('log')->getreadarr($this->mtable, $this->id); //已读人员
  627. $arr['isedit'] = $this->iseditqx();
  628. $arr['isdel'] = $this->isdeleteqx();
  629. $arr['isflow'] = $this->isflow;
  630. $arr['modename'] = $this->modename;
  631. $arr['ischehui'] = $this->ischehui();
  632. $arr['statustext'] = $ztass[4];
  633. $arr['statuscolor'] = $ztass[1];
  634. $arr['optmenu'] = $this->getoptmenu(1); //获取在详情上展示菜单
  635. $arr['isgbjl'] = (int)$this->rock->arrvalue($this->moders,'isgbjl','0'); //是否关闭操作记录
  636. $arr['isgbcy'] = (int)$this->rock->arrvalue($this->moders,'isgbcy','0'); //是否不显示查阅记录
  637. //判断是否需要回执(2018-07-06)新增
  638. $receiptrs = false;
  639. $receiptrow = m('receipt')->getall("`modenum`='$this->modenum' and `mid`='$this->id' and `status`=1");
  640. foreach($receiptrow as $k=>$hrs){
  641. $uid1 = ','.$this->adminid.',';
  642. if(!contain(','.$hrs['receid'].',', $uid1))continue;
  643. if(!contain(','.$hrs['receids'].',', $uid1)){
  644. $receiptrs = array(
  645. 'id' => $hrs['id'],
  646. 'optname' => $hrs['optname'],
  647. );
  648. break;
  649. }
  650. }
  651. $arr['flowinfor'] = array(); //流程信息
  652. $arr['readunarr'] = array(); //未读人员
  653. $arr['receiptrs'] = $receiptrs; //回执确认
  654. if($this->isflow>0){
  655. $arr['flowinfor']= $this->getflowinfor();
  656. if($arr['flowinfor']['ischeck']==1){
  657. $arr['isplview']='0';//需要审核就不要评论框了
  658. }
  659. }
  660. if(isset($data['title']))$arr['title'] = $data['title'];
  661. $_oarr = $this->flowdatalog($arr);
  662. if(is_array($_oarr))foreach($_oarr as $k=>$v)$arr[$k]=$v;
  663. $conta = $this->rock->matcharr($contview,2);
  664. $edbof = false;
  665. foreach($conta as $fids){
  666. $thnr = '';
  667. $contview = str_replace('`'.$fids.'`', $thnr, $contview);
  668. }
  669. $arr['contview'] = $contview;
  670. return $arr;
  671. }
  672. //$lx=0PC,1移动
  673. private function getsubdata($xu, $rows, $lx=0)
  674. {
  675. $iscz = 0;
  676. $iszb = $xu+1;
  677. $fields = 'subdata'.$xu.'';
  678. $subrows = $this->db->getrows('[Q]flow_element','`mid`='.$this->modeid.' and `iszb`='.$iszb.' and `iszs`=1','`fields`,`name`,`isalign`','`sort`');
  679. $cont = '';
  680. if($this->db->count > 0){
  681. $iscz = 1;
  682. $headstr = '@xuhaos,,center'; $colorbb = getconfig('bcolorxiang', '#cccccc');
  683. //if($lx==1){$headstr = '';$colorbb = 'black';}
  684. foreach($subrows as $k=>$rs){
  685. $headstr.='@'.$rs['fields'].','.$rs['name'].'';
  686. if($rs['isalign']=='1')$headstr.=',left';
  687. if($rs['isalign']=='2')$headstr.=',right';
  688. }
  689. foreach($rows as $k=>$rs)$rows[$k]['xuhaos'] = $k+1;
  690. $slex = ($lx==0) ? 'noborder':'';
  691. if($this->subsubdatastyle!='')$slex = $this->subsubdatastyle;
  692. $cont = c('html')->createrows($rows, substr($headstr,1), $colorbb, $slex);
  693. }
  694. return $cont;
  695. }
  696. /**
  697. * 判断当前是否可以撤回
  698. * 撤回条件,审核未同意,最后一步是当前人审核的而为同意,2小时之内
  699. */
  700. public function ischehui()
  701. {
  702. $is = 0;
  703. if($this->rs['status']==1 || $this->isflow==3)return $is;//自由流程不允许撤回
  704. $where = "".$this->mwhere." and `valid`=1 order by `id` desc";
  705. $rs = $this->flogmodel->getone($where);
  706. $time = time()-2*3600;
  707. if($rs && $rs['status']=='1' && $rs['checkid']==$this->adminid && strtotime($rs['optdt'])>$time &&
  708. ($rs['courseid']>0 || $rs['iszb']=='1' ))
  709. $is = $rs['id'];
  710. return $is;
  711. }
  712. /**
  713. * 撤回操作
  714. */
  715. public function chehui($sm='')
  716. {
  717. //--autharstart--
  718. $id = $this->ischehui();
  719. if($id==0)return '当前不允许撤回操作';
  720. $this->flogmodel->update('courseid=0', "`id`='$id'");
  721. $this->addlog(array(
  722. 'explain' => $sm,
  723. 'name' => '撤回'
  724. ));
  725. $this->checksmodel->delete($this->mwhere.' and `optid`='.$this->adminid.'');//删除我指定的人
  726. $barr = $this->getflow(false);
  727. //当前审核人空
  728. if(isempt($barr['nowcheckid'])){
  729. $courseid = $barr['nowcourseid'];
  730. $this->addcheckname($courseid, $this->adminid, $this->adminname, false,2);
  731. $barr = $this->getflow(false);
  732. }
  733. $this->getflowsave($barr);
  734. return 'ok';
  735. //--autharend--
  736. return $this->bd6('5peg5L!h5ZG8562!5o6I5peg5q2k5Yqf6IO9');
  737. }
  738. public function bd6($str)
  739. {
  740. return $this->rock->jm->base64dencode($str);
  741. }
  742. /**
  743. * 读取编辑数据
  744. */
  745. public function getdataedit()
  746. {
  747. $fobj = m('file');
  748. $arr['data'] = $this->flowrsreplaceedit($this->rssust);
  749. $arr['table'] = $this->mtable;
  750. $arr['tables'] = $this->moders['tables'];
  751. $arr['modeid'] = $this->modeid;
  752. $arr['isedit'] = $this->iseditqx();
  753. $arr['isflow'] = $this->isflow;
  754. $arr['user'] = $this->urs;
  755. $arr['status'] = $this->rs['status'];
  756. $filers = $fobj->getfile($this->mtable,$this->id);
  757. foreach($filers as $fk=>$frs1)$filers[$fk]['thumbpath']=$fobj->getthumbpath($frs1);//缩略图显示
  758. $arr['filers'] = $filers;
  759. $arr['subdata'] = $this->getsuballdata();
  760. $filearr = array();
  761. $fileids = '';
  762. foreach($this->fieldsarr as $k=>$rs){
  763. $fid = $rs['fields'];
  764. $flx = $rs['fieldstype'];
  765. if($flx=='uploadfile'){
  766. $fval = arrvalue($this->rssust, $fid);
  767. if(!isempt($fval))$fileids.=','.$fval.'';
  768. }
  769. if($flx=='uploadimg'){
  770. $arr['data'][''.$fid.'_view'] = $this->rock->gethttppath($arr['data'][$fid]);
  771. }
  772. }
  773. //--autharstart--
  774. //读取子表中上传文件的id
  775. if($arr['subdata']){
  776. $zbzd = m('flow_element')->getrows("`mid`='$this->modeid' and `iszb`>0 and `fieldstype`='uploadfile'",'`name`,`fields`,`fieldstype`,`iszb`','`iszb`,`sort`');
  777. foreach($zbzd as $k1=>$rs1){
  778. $zbda = arrvalue($arr['subdata'], 'subdata'.(floatval($rs1['iszb'])-1).'');
  779. if($zbda)foreach($zbda as $k2=>$rs2){
  780. $fval = arrvalue($rs2, $rs1['fields']);
  781. if(!isempt($fval))$fileids.=','.$fval.'';
  782. }
  783. }
  784. }
  785. //--autharend--
  786. //读取文件详情
  787. if($fileids!=''){
  788. $frows = $fobj->getall('`id` in('.substr($fileids, 1).')','filename,id,filesizecn,fileext,optname,thumbpath,thumbplat');
  789. foreach($frows as $k1=>$rs1){
  790. $rs1['thumbpath'] = $fobj->getthumbpath($rs1);
  791. $filearr['f'.$rs1['id'].''] = $rs1;
  792. }
  793. }
  794. $arr['filearr'] = $filearr;
  795. $ztarr = $this->getnowstatus();
  796. $arr['statustext'] = $ztarr[0];
  797. $arr['statuscolor'] = $ztarr[1];
  798. return $arr;
  799. }
  800. /*
  801. * 读取流程信息
  802. */
  803. public function getflowinfor()
  804. {
  805. $ischeck = 0;
  806. $ischange= 0;
  807. $str = '';
  808. $arr = $this->getflow();
  809. if($arr['nowcheckid'] != $this->billrs['nowcheckid'])$this->getflowsave($arr, true);
  810. $nstatus = $this->rs['status'];
  811. $isturn = $this->rs['isturn'];
  812. $nowcheckid = ','.$arr['nowcheckid'].',';
  813. if($isturn==1 && $nstatus !=1 && contain($nowcheckid, ','.$this->adminid.',') && !in_array($nstatus, array(2,5))){
  814. $ischeck = 1;
  815. }
  816. $logarr = $this->getlog();
  817. $nowcur = $this->nowcourse;
  818. if(arrvalue($this->nextcourse,'checktype')=='change'){
  819. $ischange = 1; //需要自己选择下一步处理人
  820. }
  821. $sarr['ischeck'] = $ischeck;
  822. $sarr['ischange'] = $ischange;
  823. $sarr['nowcourse'] = $nowcur;
  824. $sarr['iszhuanban'] = 0;
  825. $sarr['ischao'] = 0;
  826. $sarr['nextcourse'] = $this->nextcourse;
  827. $sarr['nstatustext'] = $arr['nstatustext'];
  828. //--autharstart--
  829. $sarr['iszhuanban'] = (int)arrvalue($nowcur,'iszf',0);
  830. if($sarr['iszhuanban']>0){
  831. $sarr['zbrangeid'] = $this->rock->repempt(arrvalue($nowcur,'zbrangeid'));
  832. $sarr['zbrangelx'] = 'check';
  833. if($sarr['iszhuanban']==2)$sarr['zbrangelx']='';//转办单选
  834. }
  835. $sarr['ischao'] = (int)arrvalue($nowcur,'cslx',0);
  836. $sarr['ischaofwid'] = arrvalue($nowcur,'csfwid');
  837. //--autharend--
  838. if($isturn==0)$sarr['nstatustext'] = '<font color="#ff6600">待提交</font>';
  839. //读取当前审核表单,必填字段|选填字段
  840. $_checkfields = arrvalue($nowcur,'checkfields');
  841. $checkfields = array();
  842. if($ischeck == 1 && !isempt($_checkfields)){
  843. $_checkfieldsa = explode('|', $_checkfields);
  844. $_checkfields = join(',',$_checkfieldsa);
  845. $_checkxuant = arrvalue($_checkfieldsa, 1);
  846. $inputobj = c('input');
  847. $inputobj->flow = $this;
  848. $inputobj->mid = $this->id;
  849. $inputobj->urs = $this->urs;
  850. $elwswhere = "`mid`='$this->modeid' and `iszb`=0 and instr(',$_checkfields,', concat(',',`fields`,','))>0";
  851. $infeidss = $inputobj->initFields($elwswhere);
  852. foreach($infeidss as $_fs=>$fsva){
  853. $_sfes = $fsva['fields'];
  854. $_type = $fsva['fieldstype'];
  855. $showinpus = 1;
  856. $isbt = 1;
  857. if($_checkxuant && contain(','.$_checkxuant.',',','.$_sfes.','))$isbt=0;
  858. if($_type=='hidden' || $_type=='fixed')$showinpus=2;
  859. $_val = arrvalue($this->rssust, $_sfes);
  860. $cheo = (substr($_type,0,6)=='change' && !isempt($fsva['data']));
  861. if($cheo)$_val.='|'.arrvalue($this->rssust, $fsva['data']).''; //默认值
  862. $checkfields[$_sfes] = array(
  863. 'inputstr' => $inputobj->getfieldcontval($_sfes, $_val),
  864. 'name' => $fsva['name'],
  865. 'isbt' => $isbt,
  866. 'fieldstype'=> $_type,
  867. 'fieldsarr' => $fsva,
  868. 'showinpus' => $showinpus
  869. );
  870. if($cheo){
  871. $_sfes = $fsva['data'];
  872. $checkfields[$_sfes] = array(
  873. 'inputstr' => '',
  874. 'isbt' => $isbt,
  875. 'name' => $fsva['name'].'id',
  876. 'fieldstype'=> $_type,
  877. 'fieldsarr' => false,
  878. 'showinpus' => 2
  879. );
  880. }
  881. }
  882. }
  883. $sarr['checkfields'] = $checkfields;
  884. if($nstatus==2)$sarr['nstatustext'] ='<font color="#AB47F7">待提交人处理('.$this->urs['name'].')</font>';
  885. $loglen = count($logarr);
  886. //<img align="absmiddle" class="face" src="'.$rs['face'].'">
  887. foreach($logarr as $k=>$rs){
  888. if($rs['courseid']>0){
  889. $sty = '';
  890. $col = $rs['color'];
  891. if($str!='')$str.=' → ';
  892. $str.='<span style="'.$sty.'">'.$rs['actname'].'('.$rs['name'].'<font color="'.$col.'">'.$rs['statusname'].'</font>)</span>';
  893. }
  894. }
  895. //未同意
  896. if($nstatus=='2'){
  897. if($str!='')$str.=' → ';
  898. $str.= $sarr['nstatustext'];
  899. }else if($nstatus=='5'){
  900. if($str!='')$str.=' → ';
  901. $sarr['nstatustext'] = '<font color="#888888">已作废</font>';
  902. $str.= '<font color="#888888">已作废</font>';
  903. }else{
  904. foreach($this->flowarr as $k=>$rs){
  905. if($rs['ischeck']==0){
  906. $sty = 'color:#888888';
  907. if($rs['isnow']==1)$sty='font-weight:bold;color:#800000';
  908. if($str!='')$str.=' <font color=#888888>→</font> ';
  909. $str.='<span style="'.$sty.'">'.$rs['name'].'';
  910. if(!isempt($rs['nowcheckname']))$str.='('.$rs['nowcheckname'].')';
  911. $str.='</span>';
  912. }
  913. }
  914. }
  915. $sarr['flowcoursestr'] = $str;
  916. if($nstatus==1)$sarr['nstatustext'] = $this->getnowstatus(1); //完成后状态
  917. $actstr = ',同意|green,不同意|red';
  918. if(isset($nowcur['courseact']) ){
  919. $actstrt = $nowcur['courseact'];
  920. if(!isempt($actstrt))$actstr = ','.$actstrt;
  921. }
  922. $act = c('array')->strtoarray($actstr);
  923. foreach($act as $k=>$as1)if($k>0 && $as1[0]==$as1[1])$act[$k][1]='';
  924. if(arrvalue($this->moders,'isys')=='1' && (int)arrvalue($nowcur,'mid','0')>=0){
  925. $act[25]= array('前加签','','');
  926. $act[26]= array('后加签','','');
  927. }
  928. $sarr['courseact'] = $act;
  929. $nowstatus = $this->rs['status'];
  930. if($this->isflow>0 && $this->rs['isturn']==0)$nowstatus=3;
  931. $sarr['nowstatus'] = $nowstatus;
  932. //不同意退回可选择人员
  933. $step = $this->rock->arrvalue($nowcur, 'step','0');
  934. $tuicourse = $this->flogmodel->getall($this->mwhere.' and `courseid`>0 and `valid`=1 and `status`=1 and `step`<'.$step.'','`id`,`checkname`,`name`','`step` desc');
  935. $sarr['tuicourse'] = $tuicourse;
  936. return $sarr;
  937. }
  938. /**
  939. * 更新单据状态
  940. */
  941. public function updatestatus($zt)
  942. {
  943. $this->update('`status`='.$zt.'', $this->id);
  944. $this->billmodel->update('`status`='.$zt.'', $this->mwhere);
  945. }
  946. /**
  947. * 获取状态列表数组
  948. */
  949. public function getstatusarr()
  950. {
  951. return $this->getstatus(null, '','',2);
  952. }
  953. /**
  954. * 获取某单据当前状态
  955. * $rs 单据数据,$statusstr设置的状态,$other 当前审核人
  956. */
  957. public function getstatus($rs, $statusstr='',$other='', $glx=0)
  958. {
  959. $statustext = $statuscolor = '';
  960. if($statusstr=='')$statusstr=$this->rock->arrvalue($this->moders,'statusstr');
  961. $statusara = array();
  962. $colorsa = array('blue','green','red','#ff6600','#526D08','#888888','','','','','','','','','','','','','');
  963. if(isempt($statusstr)){
  964. $statussst = '不同意';
  965. $statusstr = '待?处理|blue,已审核|green,'.$statussst.'|red';
  966. }
  967. $nowcheckname= arrvalue($rs,'nowcheckname', arrvalue($this->billrs,'nowcheckname'));
  968. if(isempt($other))$other = $nowcheckname;
  969. $statusar = c('array')->strtoarray($statusstr);
  970. foreach($statusar as $k=>$v){
  971. if($v[0]==$v[1])$v[1]= arrvalue($colorsa, $k);
  972. $statusara[$k] = $v;
  973. }
  974. $statusara[5] = array('已作废','#888888');
  975. $statusara[23] = array('退回','#17B2B7');
  976. if($glx==2)return $statusara;
  977. $isturn = -1;
  978. if(isset($rs['isturn']))$isturn = (int)$rs['isturn'];
  979. $zt = $this->rock->arrvalue($rs, 'status');
  980. if($isturn==0){
  981. $statustext = '待提交';
  982. $statuscolor= '#ff6600';
  983. }elseif(!isempt($zt)){
  984. if(isset($statusara[$zt])){
  985. $statustext = $statusara[$zt][0];
  986. $statuscolor = $statusara[$zt][1];
  987. }
  988. }
  989. if(contain($statustext,'?')){
  990. $statusstr = str_replace('?', '<font color="'.$statuscolor.'">'.$other.'</font>', $statustext);
  991. }else{
  992. $statusstr = '<font color="'.$statuscolor.'">'.$statustext.'</font>';
  993. }
  994. if($glx==1){
  995. return $statusstr;
  996. }
  997. return array(str_replace('?', $other, $statustext), $statuscolor, $zt, $statusstr, str_replace('?', '', $statustext));
  998. }
  999. public function getstatusstr($rs)
  1000. {
  1001. return $this->getstatus($rs, '','', 1);
  1002. }
  1003. /**
  1004. * 当前单击状态
  1005. */
  1006. public function getnowstatus($glx=0)
  1007. {
  1008. return $this->getstatus($this->rs, '','', $glx);
  1009. }
  1010. //$lx=0默认,1详情
  1011. private $getlogrows = array();
  1012. public function getlog($lx=0)
  1013. {
  1014. if(isset($this->getlogrows[$lx]))return $this->getlogrows[$lx];
  1015. $rows = $this->flogmodel->getrows($this->mwhere, '`checkname` as `name`,`checkid`,`name` as actname,`optdt`,`status`,`explain`,`statusname`,`valid`,`courseid`,`color`,`id`,`qmimg`','`id` asc');
  1016. $uids = $idss = '';
  1017. $dts = c('date');
  1018. $fo = m('file');
  1019. $editarrs = array();
  1020. //--autharstart--
  1021. if($lx==1){
  1022. $editarr = $this->db->getall('SELECT `optid`,`optdt` FROM `[Q]editrecord` where '.$this->mwhere.' order by `optid`,`optdt`');
  1023. foreach($editarr as $k1=>$rs1)$editarrs[$rs1['optid'].$rs1['optdt']]=1;
  1024. }
  1025. //--autharend--
  1026. foreach($rows as $k=>$rs){
  1027. $uids.=','.$rs['checkid'].'';
  1028. $idss.=','.$rs['id'].'';
  1029. $col = $rs['color'];
  1030. if(isempt($col))$col='green';
  1031. if(contain($rs['statusname'],'不') || $rs['status']=='2')$col='red';
  1032. $rows[$k]['color'] = $col;
  1033. $rows[$k]['checkdt'] = $rs['optdt'];
  1034. $rows[$k]['sm'] = $rs['explain'];
  1035. if(!isempt($rs['qmimg'])){
  1036. //签名是手写的
  1037. if(!contain($rs['qmimg'],'.')){
  1038. $qmimg = ''.UPDIR.'/'.date('Y-m').'/qmimg'.$rs['id'].'.png';
  1039. $bo = true;
  1040. if(!file_exists($qmimg)){
  1041. $bar= explode(',', $rs['qmimg']);
  1042. $bo = $this->rock->createtxt($qmimg, base64_decode($bar[1]));
  1043. }
  1044. if(!$bo){
  1045. $qmimg = $rs['qmimg'];
  1046. }else{
  1047. $qmimg = ''.URL.''.$qmimg.'';
  1048. }
  1049. }else{
  1050. $qmimg = $rs['qmimg'];
  1051. if(!file_exists($qmimg)){
  1052. $qmimg = '';
  1053. }else{
  1054. $qmimg = ''.URL.''.$qmimg.'';
  1055. }
  1056. }
  1057. $rows[$k]['qmimg'] = $qmimg;
  1058. if(!isempt($qmimg))$rows[$k]['explain']= '<img height="30" width="70" src="'.$qmimg.'">'.$rs['explain'].'';
  1059. }
  1060. //--autharstart--
  1061. if($lx==1 && $rs['actname']=='编辑'){
  1062. if(isset($editarrs[$rs['checkid'].$rs['optdt']]))$rows[$k]['explain'] = $this->strappend($rows[$k]['explain'], '<a class="zhu" href="javascript:;" onclick="c.showeditcont(\''.strtotime($rs['optdt']).'\','.$rs['checkid'].')">修改记录</a>');
  1063. }
  1064. //--autharend--
  1065. }
  1066. //读取相关文件
  1067. if($idss!=''){
  1068. $farr = $fo->getfile('flow_log', substr($idss, 1));
  1069. if($farr)foreach($rows as $k=>$rs){
  1070. $fstr = $fo->getallstr($farr, $rs['id'],2);
  1071. $rows[$k]['explain']= $this->strappend($rs['explain'], $fstr, '<br>');
  1072. }
  1073. }
  1074. //读取对应人员头像
  1075. if($uids!=''){
  1076. $rows = m('admin')->getadmininfor($rows, substr($uids, 1), 'checkid');
  1077. }
  1078. $this->getlogrows[$lx] = $rows;
  1079. return $rows;
  1080. }
  1081. public function addlog($arr=array())
  1082. {
  1083. $addarr = array(
  1084. 'table' => $this->mtable,
  1085. 'mid' => $this->id,
  1086. 'checkname' => $this->adminname,
  1087. 'checkid' => $this->adminid,
  1088. 'optdt' => $this->rock->now,
  1089. 'courseid' => '0',
  1090. 'status' => '1',
  1091. 'ip' => $this->rock->ip,
  1092. 'web' => $this->rock->web,
  1093. 'modeid' => $this->modeid
  1094. );
  1095. foreach($arr as $k=>$v)$addarr[$k]=$v;
  1096. if(isset($addarr['explain']))$addarr['explain']= htmlspecialchars($addarr['explain']);
  1097. $this->flogmodel->insert($addarr);
  1098. $ssid = $this->db->insert_id();
  1099. $fileid = $this->rock->post('fileid'); //这个是审批处理时下的上传文件
  1100. if($fileid!='')m('file')->addfile($fileid, 'flow_log', $ssid, $this->modenum.'|'.$this->id);
  1101. $logfileid = $this->rock->post('logfileid'); //这个是从单据操作菜单添加追加时
  1102. if($logfileid!='')m('file')->addfile($logfileid, 'flow_log', $ssid, $this->modenum.'|'.$this->id);
  1103. $addarr['id'] = $ssid;
  1104. $this->flowaddlog($addarr);
  1105. $this->getlogrows = array();
  1106. return $ssid;
  1107. }
  1108. public function submit($na='', $sm='')
  1109. {
  1110. if($na=='')$na='提交';
  1111. $isturn = 1;
  1112. if($na=='保存')$isturn = 0;
  1113. $this->addlog(array(
  1114. 'name' => $na,
  1115. 'explain' => $sm
  1116. ));
  1117. if($this->isflow>0){
  1118. $marr['isturn'] = $isturn;
  1119. $marr['status'] = 0;
  1120. $this->rs['status'] = 0;
  1121. $this->update($marr, $this->id);
  1122. //每次编辑判断是否重新开始走审批。
  1123. if(arrvalue($this->moders,'isflowlx')=='1' || $this->isflow>=3){
  1124. $this->checksmodel->delete($this->mwhere);
  1125. $this->flogmodel->update('`valid`=0', ''.$this->mwhere.' and `courseid`>0 and `valid`=1');
  1126. }
  1127. $farr = $this->getflow();
  1128. //第一步自定义审核人
  1129. if($farr['nowcourseid']>0){
  1130. $sysnextoptid = $this->rock->post('sysnextoptid'); $sysnextopt = $this->rock->post('sysnextopt'); $sysnextcustidid = (int)$this->rock->post('sysnextcustidid');
  1131. if($sysnextcustidid == $farr['nowcourseid'] && !isempt($sysnextoptid) && !isempt($sysnextopt)){
  1132. $this->addcheckname($sysnextcustidid, $sysnextoptid, $sysnextopt, true, 1);
  1133. $farr = $this->getflow(); //重新在读取匹配流程
  1134. }
  1135. }
  1136. $farr['status'] = 0;
  1137. $this->savebill($farr);
  1138. if($isturn == 1){
  1139. $this->nexttodo($farr['nowcheckid'],'submit');
  1140. }
  1141. }
  1142. $this->flowsubmit($na, $sm);
  1143. //抄送保存
  1144. $this->savecsname(
  1145. $this->rock->post('syschaosongid'),
  1146. $this->rock->post('syschaosong'),
  1147. $this->adminid,0,$isturn,$na);
  1148. if($na=='编辑'){
  1149. $this->gettodosend('boedit');
  1150. }else{
  1151. $this->gettodosend('boturn');//提交
  1152. }
  1153. }
  1154. private function savecsname($csnameid,$csname,$uid,$type,$isturn, $na)
  1155. {
  1156. if(!isempt($csnameid)){
  1157. $where = $this->mwhere.' and `type`='.$type.'';
  1158. if($type>0)$where.=' and `uid`='.$uid.'';
  1159. $csid = (int)$this->chaomodel->getmou('id', $where);
  1160. if($csid==0)$where = '';
  1161. $this->chaomodel->record(array(
  1162. 'modeid' => $this->modeid,
  1163. 'table' => $this->mtable,
  1164. 'mid' => $this->id,
  1165. 'uid' => $uid,
  1166. 'type' => $type,
  1167. 'csname' => $csname,
  1168. 'csnameid' => $csnameid,
  1169. ),$where);
  1170. if($isturn==1)$this->nexttodo($csnameid,'chao', $na);//发送通知
  1171. }
  1172. }
  1173. /**
  1174. * 获取抄送人姓名
  1175. */
  1176. public function getcsname($id=0)
  1177. {
  1178. if($id>0){
  1179. $where= "`table`='$this->mtable' and `mid`='$id' and `type`=0";
  1180. }else{
  1181. $where= "`modeid`={$this->modeid} and `uid`={$this->adminid} and `type`=0";
  1182. $iscs = (int)$this->moders['iscs'];
  1183. //if($iscs<=2)$where='1=2';//默认不读取
  1184. }
  1185. $ors = $this->chaomodel->getone($where,'*','`id` desc');
  1186. $csname = $csnameid = '';
  1187. if($ors){
  1188. $csname = $ors['csname'];
  1189. $csnameid = $ors['csnameid'];
  1190. }
  1191. return array(
  1192. 'csname' => $csname,
  1193. 'csnameid' => $csnameid,
  1194. 'id' => $id,
  1195. );
  1196. }
  1197. /**
  1198. * 追加说明
  1199. */
  1200. public function zhuijiaexplain($sm='')
  1201. {
  1202. $this->addlog(array(
  1203. 'explain' => $sm,
  1204. 'name' => '追加说明',
  1205. 'status' => 1,
  1206. ));
  1207. $zt = $this->rs['status'];
  1208. if($zt==2 && $this->isflow>0 && $this->adminid==$this->uid){
  1209. $marr['status'] = 0;
  1210. $this->rs['status'] = 0;
  1211. $this->update($marr, $this->id);
  1212. $farr = $this->getflow();
  1213. $farr['status'] = 0;
  1214. $this->savebill($farr);
  1215. $this->nexttodo($farr['nowcheckid'],'zhui', $sm);
  1216. }
  1217. $this->gettodosend('bozhui','', $sm);
  1218. }
  1219. /**
  1220. * 催办
  1221. */
  1222. public function chuiban($sm='')
  1223. {
  1224. $this->addlog(array(
  1225. 'explain' => $sm,
  1226. 'name' => '催办',
  1227. 'status' => 1,
  1228. ));
  1229. $farr = $this->getflow(true);
  1230. $this->nexttodo($farr['nowcheckid'],'cuiban', $sm);
  1231. $this->gettodosend('cuiban','', $sm);
  1232. }
  1233. //提请预算读取
  1234. public function getyushen($rows)
  1235. {
  1236. return $rows;
  1237. }
  1238. private function getyushenss($id, $rows, $xu, $isq)
  1239. {
  1240. if($xu==0)$this->_tempauoe = array();
  1241. if(isset($rows[$id])){
  1242. $_tars = $rows[$id];
  1243. if($isq==1)$this->getyushenss($_tars['id'], $rows, $xu+1, $isq);
  1244. $this->_tempauoe[] = $_tars;
  1245. if($isq==0)$this->getyushenss($_tars['id'], $rows, $xu+1, $isq);
  1246. }
  1247. return $this->_tempauoe;
  1248. }
  1249. /**
  1250. * 匹配流程读取
  1251. */
  1252. public function getflowpipei($uid=0)
  1253. {
  1254. $urs = $this->urs;
  1255. if(!$urs)$urs = $uid;
  1256. if(!is_array($urs))$urs = $this->db->getone('[Q]admin', "`id`='$urs'", '`deptid`,`deptpath`,`id`');
  1257. $coursedb = m('flowcourse');
  1258. $barr = $coursedb->pipeiCourse($this->modeid);
  1259. $rows = $barr['rows'];
  1260. $this->pipeiCoursearrc = $barr['rowd'];
  1261. $this->pipeiCoursearrs = array();
  1262. $this->pipeiCoursearr = array();
  1263. $kqobj = m('kaoqin');
  1264. $this->getflowpipeis($rows, $urs, $kqobj);
  1265. unset($this->pipeiCoursearrs);
  1266. unset($this->pipeiCoursearrc);
  1267. return $this->getyushen($this->pipeiCoursearr);
  1268. }
  1269. private function getflowpipeis($rows,$urs, $kqobj)
  1270. {
  1271. $shiyong = array();
  1272. $defix = $xuhao = 0; //默认是0的
  1273. $uid = arrvalue($urs,'id',0);
  1274. $zshu = count($rows);
  1275. foreach($rows as $k=>$rs){
  1276. $whereid = (int)$rs['whereid'];
  1277. $receid = $rs['receid'];
  1278. $wherestr= arrvalue($rs, 'where');
  1279. //停用了
  1280. if($rs['status']=='0')continue;
  1281. //where条件字段
  1282. if(!isempt($wherestr)){
  1283. $wherestr = m('base')->strreplace($this->rock->jm->base64decode($wherestr), $uid);
  1284. $to = $this->rows("`id`='$this->id' and $wherestr ");
  1285. if($to==0)continue;//条件不成立
  1286. }
  1287. //有条件的【流程模块条件】下的ID
  1288. if($whereid > 0){
  1289. $bo = $this->wheremanzhu($whereid);
  1290. if(!$bo)continue;
  1291. }
  1292. //特殊判断过滤
  1293. if(!isempt($rs['num'])){
  1294. $bo = $this->flowcoursejudge($rs['num'], $rs);
  1295. if(is_bool($bo) && !$bo)continue;
  1296. }
  1297. $xuhao++;
  1298. if($defix==0 && (isempt($receid) || contain($receid,'all'))){
  1299. $defix = $xuhao;
  1300. }
  1301. //当有设置审核条件满足时就用这个做默认,2018-07-10 新增,如果是多个满足就取最后一个
  1302. if(isempt($receid) && (!isempt($wherestr) || $whereid > 0)){
  1303. $defix = $xuhao;
  1304. }
  1305. $rs['xuhao'] = $xuhao;
  1306. $shiyong[] = $rs;
  1307. }
  1308. //在根据receid匹配到哪个流程
  1309. $pboss = false;//是否有匹配到
  1310. if($shiyong){
  1311. $gxuha = $kqobj->getpipeimid($urs, $shiyong, 'xuhao', $defix); //这个匹配出来是大于0的
  1312. if($gxuha>0){
  1313. $pboss = true;//有匹配到
  1314. $gxuha = $gxuha-1;
  1315. $prs = $shiyong[$gxuha];
  1316. $this->getflowpipeisss($prs, $urs, $kqobj);
  1317. }
  1318. }
  1319. //没匹配到,可能是跳过,而且有下级需要审批
  1320. if(!$pboss && $zshu==1 && $rows[0]['childshu']>0){
  1321. $this->getflowpipeis($rows[0]['children'], $urs, $kqobj);
  1322. }
  1323. }
  1324. private function getflowpipeisss($prsnrs, $urs, $kqobj)
  1325. {
  1326. $prs = $prsnrs;
  1327. unset($prs['children']);
  1328. $this->pipeiCoursearrs[]= $prs['id'];
  1329. $this->pipeiCoursearr[] = $prs;
  1330. if($prs['childshu']>0){
  1331. $this->getflowpipeis($prsnrs['children'], $urs, $kqobj);
  1332. }else{
  1333. //有nid下级就读取
  1334. $nid = arrvalue($prs,'nid','0');
  1335. if($nid>0 && !in_array($nid, $this->pipeiCoursearrs) && isset($this->pipeiCoursearrc, $nid)){
  1336. $this->getflowpipeis(array($this->pipeiCoursearrc[$nid]), $urs, $kqobj);
  1337. }
  1338. }
  1339. }
  1340. /*
  1341. * 获取流程
  1342. */
  1343. public function getflow($sbo=false)
  1344. {
  1345. $this->flowarr = array();
  1346. $allcheckid = $nowcheckid = $nowcheckname = $nstatustext = '';
  1347. $allcheckids = array();
  1348. $nowcourseid = 0;
  1349. $nstatus = $this->rs['status'];
  1350. $this->nowcourse = array();
  1351. $this->nextcourse = array();
  1352. $this->flowisend = 0;
  1353. $curs = $this->flogmodel->getrows($this->mwhere,'checkid,checkname,courseid,`valid`,`status`,`statusname`,`name`,`iszb`','id desc');
  1354. $cufss = $ztnas = $chesarr = array();
  1355. foreach($curs as $k=>$rs){
  1356. if($rs['iszb']=='1' && !in_array($rs['checkid'], $allcheckids))$allcheckids[] = $rs['checkid']; //转办也记录到经我处理的
  1357. if($rs['courseid']=='0')continue;
  1358. $_su = ''.$rs['courseid'].'';
  1359. $_su1 = ''.$rs['courseid'].'_'.$rs['checkid'].'';
  1360. //$rs['status']为1就一走下一步
  1361. if($rs['valid']==1 && in_array($rs['status'], $this->flowstatusarr)){
  1362. if(!isset($cufss[$_su]))$cufss[$_su]=0;
  1363. $cufss[$_su]++;
  1364. $chesarr[$_su1] = 1; //标识已审核
  1365. }
  1366. if(!in_array($rs['checkid'], $allcheckids))$allcheckids[] = $rs['checkid'];
  1367. if($nstatustext=='' && $rs['courseid']>0){
  1368. $nstatustext = ''.$rs['checkname'].'处理'.$rs['statusname'].'';
  1369. $nstatus = $rs['status'];
  1370. }
  1371. $ztnas[$rs['courseid']] = ''.$rs['checkname'].''.$rs['statusname'].'';
  1372. }
  1373. $nowstep = $zongsetp = -1;
  1374. $isend = 0;
  1375. $czt = $this->rs['status'];
  1376. $coutye = 0; //判断是否需要前后审批处理
  1377. $rows = ($czt==1 || $czt==5)? array() : $this->getflowpipei($this->uid);
  1378. if($rows){
  1379. //读取flow_checks是否比审核状态(退回的)
  1380. $checksa = $this->checksmodel->getrows($this->mwhere.' and `addlx`=3');
  1381. $coursea = $nrows = array();
  1382. foreach($checksa as $k=>$rs)$coursea[$rs['courseid']]='1';
  1383. $nrows = array();
  1384. //获取审核人
  1385. $allcheckid = '';
  1386. $isoptsuperbo = false;
  1387. foreach($rows as $k=>$rs){
  1388. $uarr = $this->getcheckname($rs);
  1389. $rows[$k]['checkid'] = $uarr[0];
  1390. $rows[$k]['checkname'] = $uarr[1];
  1391. $allcheckid .= ','.$uarr[0].'';
  1392. if($rs['checktype']=='optsuper' && isempt($uarr[0]))$isoptsuperbo=true;//有操作人上级
  1393. }
  1394. //有需要读取上一步
  1395. if($isoptsuperbo)foreach($rows as $k=>$rs){
  1396. if($rs['checktype']=='optsuper'){
  1397. //读取上一步处理人
  1398. $_k1 = $k-1;
  1399. $_uid = $this->optid;
  1400. if($_k1>=0){
  1401. $ours = $this->flogmodel->getone($this->mwhere.' and `courseid`='.$rows[$_k1]['id'].' and `valid`=1 ','`checkid`','`id` desc');
  1402. if(!$ours){
  1403. $_uid = (int)$rows[$_k1]['checkid'];
  1404. }else{
  1405. $_uid = $ours['checkid'];
  1406. }
  1407. }
  1408. $uarr = $this->adminmodel->getsuperman($_uid);
  1409. if($uarr){
  1410. $rows[$k]['checkid'] = $uarr[0];
  1411. $rows[$k]['checkname'] = $uarr[1];
  1412. }
  1413. }
  1414. }
  1415. //print_r($rows);
  1416. foreach($rows as $k=>$rs){
  1417. $nrows[] = $rs;
  1418. //全部直属上级
  1419. if($rs['checktype']=='superall'){
  1420. $ids1 = $rs['id'];
  1421. $suparr = $this->adminmodel->getsuperarr($this->uid);
  1422. if($suparr){
  1423. $logdsar = $this->getlog();
  1424. foreach($logdsar as $k1=>$rs1){
  1425. if($rs1['courseid']>0 && $rs1['status']=='1' && $rs1['valid']=='1')$allcheckid .= ','.$rs1['checkid'].'';
  1426. }
  1427. foreach($suparr as $k1=>$surs){
  1428. if(!contain(','.$allcheckid.',', ','.$surs['id'].',')){
  1429. $rs['oldid'] = $ids1;
  1430. $rs['id'] = $ids1 * 99999 + $surs['id'];
  1431. $rs['checkid'] = $surs['id'];
  1432. $rs['checkname'] = $surs['name'];
  1433. $rs['iszf'] = 0;
  1434. $nrows[] = $rs;
  1435. $allcheckid .= ','.$surs['id'].'';
  1436. }
  1437. }
  1438. }
  1439. }
  1440. }
  1441. $yisheh = '';
  1442. if($this->isflow==2){
  1443. $logdsar = $this->getlog();
  1444. foreach($logdsar as $k1=>$rs1)
  1445. if($rs1['courseid']>0 && $rs1['status']==1 && $rs1['valid']==1)$yisheh .= ','.$rs1['checkid'].'';
  1446. }
  1447. foreach($nrows as $k=>$rs){
  1448. $whereid = (int)$rs['whereid'];
  1449. $checkshu = $rs['checkshu'];
  1450. $checkid = $rs['checkid'];
  1451. $checkname = $rs['checkname'];
  1452. $checktype = $rs['checktype'];
  1453. //顺序前缀审批,申请人提交人不参与审批
  1454. if($this->isflow==2 && !isempt($checkid) && isempt($rs['checkfields'])){
  1455. if(($checkid==$this->uid || $checkid==$this->optid) )continue; //申请人
  1456. $k2 = $k+1;
  1457. $ntype = 'yes';
  1458. if(isset($nrows[$k2])){
  1459. if($nrows[$k2]['checktype']=='change')$ntype='no';//下步上步指定
  1460. }
  1461. //已经处理就不处理
  1462. if($ntype=='yes' && contain(','.$yisheh.',',','.$checkid.','))continue;
  1463. }
  1464. if(!isempt($checkid))$yisheh .= ','.$checkid.'';
  1465. $zongsetp++;
  1466. $ischeck = 0;
  1467. $checkids = $checknames = '';
  1468. $_su = ''.$rs['id'].'';
  1469. $nowshu = 0;
  1470. if(isset($cufss[$_su]))$nowshu = $cufss[$_su];
  1471. if(!$this->isempt($checkid)){
  1472. $checkida = explode(',', $checkid);
  1473. $checkidna = explode(',', $checkname);
  1474. $_chid = $_chna = '';
  1475. foreach($checkida as $k1=>$chkid){
  1476. $_su1 = ''.$rs['id'].'_'.$chkid.'';
  1477. if(!in_array($chkid, $allcheckids))$allcheckids[] = $chkid;
  1478. if(!isset($chesarr[$_su1])){
  1479. $_chid.=','.$chkid.'';
  1480. $_chna.=','.arrvalue($checkidna, $k1).'';
  1481. }
  1482. }
  1483. if($_chid!='')$_chid = substr($_chid, 1);
  1484. if($_chna!='')$_chna = substr($_chna, 1);
  1485. if($_chid==''){
  1486. $ischeck = 1;
  1487. }else{
  1488. if($checkshu>0&&$nowshu>=$checkshu)$ischeck = 1;
  1489. }
  1490. $checkids = $_chid;
  1491. $checknames = $_chna;
  1492. }else{
  1493. if($checkshu>0&&$nowshu>=$checkshu)$ischeck = 1;
  1494. //需要全部审核时 同时已有审核过了 也没有审核人了
  1495. if($checkshu == 0 && $nowshu>0)$ischeck = 1;
  1496. }
  1497. if($ischeck==0 && $coutye==0){
  1498. if((int)arrvalue($rs,'coursetype','0')>0)$coutye = 1;
  1499. }
  1500. $rs['ischeck'] = $ischeck;
  1501. $rs['islast'] = 0;
  1502. $rs['checkid'] = $checkid;
  1503. $rs['checkname'] = $checkname;
  1504. $rs['nowcheckid'] = $checkids;
  1505. $rs['nowcheckname'] = $checknames;
  1506. $rs['isnow'] = 0;
  1507. $rs['nowstep'] = $zongsetp;
  1508. $rs['step'] = $k+1;
  1509. if($ischeck==0 && $nowstep==-1){
  1510. $rs['isnow']= 1;
  1511. $nowstep = $zongsetp;
  1512. $this->nowcourse = $rs; //当前审核步骤信息
  1513. $nowcourseid = $rs['id'];
  1514. $nowcheckid = $checkids;
  1515. $nowcheckname = $checknames;
  1516. }
  1517. if($nowstep>-1 && $zongsetp==$nowstep+1)$this->nextcourse = $rs; //下一步信息
  1518. $this->flowarr[]= $rs;
  1519. }
  1520. }
  1521. if($zongsetp>-1)$this->flowarr[$zongsetp]['islast']=1;
  1522. if($nowstep == -1){
  1523. $isend = 1;
  1524. }else{
  1525. $nstatustext = '待'.$nowcheckname.'处理';
  1526. }
  1527. $this->flowisend = $isend;
  1528. $allcheckid = join(',', $allcheckids);
  1529. $arrbill['allcheckid'] = $allcheckid;
  1530. $arrbill['nowcourseid'] = $nowcourseid;
  1531. $arrbill['nowcheckid'] = $nowcheckid;
  1532. $arrbill['nowcheckname'] = $nowcheckname;
  1533. $arrbill['nstatustext'] = $nstatustext;
  1534. $arrbill['nstatus'] = $nstatus;
  1535. $arrbill['status'] = $this->rs['status'];
  1536. $arrbill['isturn'] = $this->rs['isturn'];
  1537. if($sbo)$this->getflowsave($arrbill);
  1538. return $arrbill;
  1539. }
  1540. public function wheremanzhu($id)
  1541. {
  1542. $uid = $this->uid;
  1543. $ser = $this->wheremodel->getflowwhere($id, $uid);
  1544. if(!$ser)return true;
  1545. $str = $ser['ntr'];
  1546. if(!isempt($str)){
  1547. $to = $this->db->rows('[Q]admin',"`id`='$uid' and ($str)");
  1548. if($to>0)return false;
  1549. }
  1550. $str = $ser['str'];
  1551. if(!isempt($str)){
  1552. $str= str_replace('{asqom}','', $str);
  1553. $to = $this->rows("`id`='$this->id' and $str");
  1554. if($to==0)return false;
  1555. }
  1556. $str = $ser['utr'];
  1557. if(!isempt($str)){
  1558. $to = $this->db->rows('[Q]admin',"`id`='$uid' and $str");
  1559. if($to==0)return false;
  1560. }
  1561. return true;
  1562. }
  1563. public function getflowsave($sarr, $suvu=false)
  1564. {
  1565. if(!$sarr)return;
  1566. if($suvu)$sarr['updt'] = $this->rock->now;
  1567. $this->billmodel->update($sarr, $this->mwhere);
  1568. }
  1569. //获取审核人
  1570. private function getcheckname($crs)
  1571. {
  1572. $type = $crs['checktype'];
  1573. $cuid = $name = '';
  1574. $courseid= $crs['id'];
  1575. $cheorws = $this->checksmodel->getall($this->mwhere.' and `courseid`='.$courseid.'','checkid,checkname');
  1576. if($cheorws){
  1577. foreach($cheorws as $k=>$rs){
  1578. $lxss = $rs['checkid'];
  1579. if(isempt($lxss) || $lxss=='0')continue;
  1580. $cuid.=','.$lxss.'';
  1581. $name.=','.$rs['checkname'].'';
  1582. }
  1583. if($cuid != ''){
  1584. $cuid = substr($cuid, 1);
  1585. $name = substr($name, 1);
  1586. return array($cuid, $name);
  1587. }
  1588. }
  1589. //自定义审核人读取
  1590. if(!$this->isempt($crs['num'])){
  1591. $uarr = $this->flowcheckname($crs['num']);
  1592. if(is_array($uarr)){
  1593. if(!$this->isempt($uarr[0]))return $uarr;
  1594. }
  1595. }
  1596. if($type=='super' || $type=='superall'){
  1597. $cuid = $this->urs['superid'];
  1598. $name = $this->urs['superman'];
  1599. }
  1600. if($type=='dept' || $type=='super' || $type=='superall'){
  1601. if($this->isempt($cuid) && $this->drs){
  1602. $cuid = $this->drs['headid'];
  1603. $name = $this->drs['headman'];
  1604. }
  1605. }
  1606. if($type=='apply'){
  1607. $cuid = $this->urs['id'];
  1608. $name = $this->urs['name'];
  1609. }
  1610. if($type=='opt'){
  1611. $cuid = $this->rs['optid'];
  1612. $name = $this->rs['optname'];
  1613. if(isempt($cuid)){
  1614. $cuid = $this->urs['id'];
  1615. $name = $this->urs['name'];
  1616. }
  1617. }
  1618. if($type=='user'){
  1619. $cuid = $crs['checktypeid'];
  1620. $name = $crs['checktypename'];
  1621. }
  1622. if($type=='rank'){
  1623. $rank = $crs['checktypename'];
  1624. if(!$this->isempt($rank)){
  1625. $wheer1 = $this->adminmodel->getcompanywhere(5,'',$this->companyid);
  1626. $rnurs = $this->db->getrows('[Q]admin',"`status`=1 and `ranking`='$rank' ".$wheer1."",'id,name','sort');
  1627. foreach($rnurs as $k=>$rns){
  1628. $cuid.=','.$rns['id'].'';
  1629. $name.=','.$rns['name'].'';
  1630. }
  1631. if($cuid != ''){
  1632. $cuid = substr($cuid, 1);
  1633. $name = substr($name, 1);
  1634. }
  1635. }
  1636. }
  1637. if($type=='cname'){
  1638. $cnbar = $this->cnamemodel->getcheckname($crs['checktypeid'], $this->uid);
  1639. $cuid = arrvalue($cnbar, 0);
  1640. $name = arrvalue($cnbar, 1);
  1641. }
  1642. //主表上字段,一般都是ID字段
  1643. if($type=='field'){
  1644. $fids = $crs['checktypeid'];
  1645. if(!isempt($fids)){
  1646. $vals = '';
  1647. $farrs= explode(',', $fids);
  1648. foreach($farrs as $fid){
  1649. $vid = arrvalue($this->rs, $fid);
  1650. if(!isempt($vid))$vals.=','.$vid.'';
  1651. }
  1652. if($vals!=''){
  1653. $vals = substr($vals, 1);
  1654. $uarr = $this->adminmodel->getrows('`status`=1 and `id` in('.$vals.')','id,name','FIELD(`id`,'.$vals.')');
  1655. foreach($uarr as $k=>$rs){
  1656. $cuid.=','.$rs['id'].'';
  1657. $name.=','.$rs['name'].'';
  1658. }
  1659. if($cuid != ''){
  1660. $cuid = substr($cuid, 1);
  1661. $name = substr($name, 1);
  1662. }
  1663. }
  1664. }
  1665. }
  1666. $cuid = $this->rock->repempt($cuid);
  1667. $name = $this->rock->repempt($name);
  1668. return array($cuid, $name);
  1669. }
  1670. /**
  1671. * 创建编号
  1672. */
  1673. public function createbianhao($num, $fid, $wshu=3)
  1674. {
  1675. if(isempt($num))$num=''.$this->modenum.'-';
  1676. @$appdt = $this->rs['applydt'];
  1677. if(isempt($appdt))$appdt = $this->rock->date;
  1678. $apdt = str_replace('-','', substr($appdt,0,10));
  1679. $num = str_replace('Ymd',$apdt,$num);
  1680. return $this->db->sericnum($num,'[Q]'.$this->mtable.'', $fid, $wshu);
  1681. }
  1682. /**
  1683. * 录入页上编号
  1684. */
  1685. public function createinputnum($num, $fid)
  1686. {
  1687. $acta = '';
  1688. if(method_exists($this, $num)){
  1689. $acta = $num;
  1690. }else{
  1691. if(contain($num, ',')){
  1692. $arra = explode(',', $num);
  1693. $acta = $arra[0];
  1694. $num = $arra[1];
  1695. }
  1696. }
  1697. if($acta && method_exists($this, $acta)){
  1698. $barr = $this->$acta($num);
  1699. if(is_array($barr)){
  1700. $qom = arrvalue($barr, 'qom', $num);//前缀
  1701. $wshu= arrvalue($barr, 'wshu', 3);//位数
  1702. $bom = arrvalue($barr, 'bom');//后缀
  1703. $fields = arrvalue($barr, 'fields', $fid);
  1704. return $this->createbianhao($qom, $fields, $wshu).$bom;
  1705. }else{
  1706. if(isempt($barr))$barr = $num;
  1707. return $this->createbianhao($barr, $fid);
  1708. }
  1709. }else{
  1710. return $this->createbianhao($num, $fid);
  1711. }
  1712. }
  1713. /**
  1714. * 创建流程单号
  1715. */
  1716. public function createnum()
  1717. {
  1718. $num = $this->moders['sericnum'];
  1719. if($num=='无'||$this->isempt($num))$num='TM-Ymd-';
  1720. @$appdt = $this->rs['applydt'];
  1721. if(isempt($appdt))$appdt = $this->rock->date;
  1722. $apdt = str_replace('-','', $appdt);
  1723. $num = str_replace('Ymd',$apdt,$num);
  1724. return $this->db->sericnum($num,'[Q]flow_bill', 'sericnum', 3);
  1725. }
  1726. public function savebill($oarr=array())
  1727. {
  1728. $dbs = $this->billmodel;
  1729. $whes= $this->mwhere;
  1730. $birs= $dbs->getone($whes);
  1731. $arr = array(
  1732. 'table' => $this->mtable,
  1733. 'mid' => $this->id,
  1734. 'optdt' => isset($this->rs['optdt']) ? $this->rs['optdt'] : $this->rock->now,
  1735. 'optname' => $this->adminname,
  1736. 'optid' => $this->adminid,
  1737. 'modeid' => $this->modeid,
  1738. 'updt' => $this->rock->now,
  1739. 'isturn' => $this->rs['isturn'],
  1740. 'nstatus' => $this->rs['status'],
  1741. 'applydt' => $this->rs['applydt'],
  1742. 'modename' => $this->modename,
  1743. 'uname' => $this->rs['base_name'],
  1744. 'udeptname' => $this->rs['base_deptname'],
  1745. 'uid' => $this->uid,
  1746. 'isdel' => '0',
  1747. );
  1748. foreach($oarr as $k=>$v)$arr[$k]=$v;
  1749. if(!$birs){
  1750. $arr['status'] = $arr['nstatus'];
  1751. $arr['createdt']= $arr['optdt'];
  1752. $arr['sericnum']= $this->createnum();
  1753. $arr['udeptid'] = $this->rock->post('sysudeptid', $this->urs['deptid']);
  1754. $whes = '';
  1755. $this->sericnum = $arr['sericnum'];
  1756. }else{
  1757. $udeptid = $birs['udeptid'];
  1758. if($udeptid==0)$arr['udeptid']=$this->urs['deptid'];
  1759. }
  1760. $dbs->record($arr, $whes);
  1761. return $arr;
  1762. }
  1763. /**
  1764. * 获取摘要
  1765. */
  1766. public function getsummary()
  1767. {
  1768. return $this->rock->reparr($this->moders['summary'], $this->rs);
  1769. }
  1770. public function addcheckname($courseid, $uid, $uname, $onbo=false, $addlx=0)
  1771. {
  1772. if(isempt($uid)){$uid = '0';$uname= 'auto';}
  1773. $uida = explode(',', ''.$uid.'');
  1774. $uidan = explode(',', $uname);
  1775. if($onbo)$this->checksmodel->delete($this->mwhere.' and `courseid`='.$courseid.'');
  1776. if($uida)foreach($uida as $k=>$uid){
  1777. $uname = $this->rock->arrvalue($uidan, $k);
  1778. $zyarr = array(
  1779. 'table' => $this->mtable,
  1780. 'mid' => $this->id,
  1781. 'modeid' => $this->modeid,
  1782. 'courseid' => $courseid,
  1783. 'optid' => $this->adminid,
  1784. 'optname' => $this->adminname,
  1785. 'addlx' => $addlx, //添加类型:1自定义,2撤回添加,3退回添加,4转移添加,5自由流程,6选择流程,7监控转办
  1786. 'optdt' => $this->rock->now,
  1787. 'status' => 0
  1788. );
  1789. $this->checksmodel->delete($this->mwhere.' and `checkid`='.$uid.' and `courseid`='.$courseid.'');
  1790. $zyarr['checkid'] = $uid;
  1791. $zyarr['checkname'] = $uname;
  1792. $this->checksmodel->insert($zyarr);
  1793. }
  1794. if($addlx==4)$this->checksmodel->delete($this->mwhere.' and `checkid`='.$this->adminid.' and `courseid`='.$courseid.'');//删除别人转给我的
  1795. }
  1796. /**
  1797. * 判断保存的数据是否
  1798. */
  1799. public function savedatastr($fval, $farr, $data=array())
  1800. {
  1801. $str = '';
  1802. if(!$farr)return $str;
  1803. $savewhere = $farr['savewhere'];
  1804. $name = $farr['name'];
  1805. $types = $farr['fieldstype'];
  1806. if(isempt($savewhere) || isempt($fval))return $str;
  1807. $savewhere = str_replace(array('{0}','{date}','{now}'), array($name, $this->rock->date,$this->rock->now), $savewhere);
  1808. $savewhere = $this->rock->reparr($savewhere, $data);
  1809. $saees = explode(',', $savewhere);
  1810. if($types=='date' || $types=='datetime')$fval = strtotime($fval);
  1811. if($types=='number')$fval = floatval($fval);
  1812. foreach($saees as $saeess){
  1813. $fsaed = explode('|', $saeess);
  1814. $msg = isset($fsaed[2]) ? $fsaed[2] : ''.$name.'数据不符号';
  1815. $val = isset($fsaed[1]) ? $fsaed[1] : '';
  1816. $lfs = $fsaed[0];
  1817. if($val != ''){
  1818. if($types=='date' || $types=='datetime')$val = strtotime($val);
  1819. if($types=='number')$val = floatval($val);
  1820. if($lfs=='gt'){$bo = $fval>$val;if(!$bo)return $msg;}
  1821. if($lfs=='egt'){$bo = $fval>=$val;if(!$bo)return $msg;}
  1822. if($lfs=='lt'){$bo = $fval<$val;if(!$bo)return $msg;}
  1823. if($lfs=='elt'){$bo = $fval<=$val;if(!$bo)return $msg;}
  1824. if($lfs=='eg'){$bo = $fval==$val;if(!$bo)return $msg;}
  1825. if($lfs=='neg'){$bo = $fval!=$val;if(!$bo)return $msg;}
  1826. }
  1827. }
  1828. return $str;
  1829. }
  1830. /**
  1831. * 重写更新一下方法
  1832. */
  1833. public function update($arr, $where)
  1834. {
  1835. if(is_array($arr)){
  1836. foreach($arr as $k=>$v)$this->rs[$k]=$v;
  1837. }
  1838. return parent::update($arr,$where);
  1839. }
  1840. /**
  1841. * 将操作记录标识无效状态
  1842. */
  1843. public function updatelogvalid($whe)
  1844. {
  1845. $this->flogmodel->update('valid=0', $this->mwhere.' '.$whe);
  1846. }
  1847. /**
  1848. * 说明追加
  1849. */
  1850. public function strappend($sm, $str, $fh=',')
  1851. {
  1852. if(isempt($str))return $sm;
  1853. if(!isempt($sm))$sm.=$fh;
  1854. $sm.=$str;
  1855. return $sm;
  1856. }
  1857. /**
  1858. * 异常直接标识已完成
  1859. */
  1860. public function checkerror($lx=1,$sm='')
  1861. {
  1862. if($sm=='')$sm='单据异常管理员处理';
  1863. $msg = $this->check($lx, $sm, 1);
  1864. return $msg;
  1865. }
  1866. /**
  1867. * 提交审核处理
  1868. * $zt 状态 $sm 说明 $lx=0默认1异常标识
  1869. */
  1870. public function check($zt, $sm='', $lx=0)
  1871. {
  1872. if($this->rs['status']==1)return '流程已处理完成,无需操作';
  1873. $arr = $this->getflow();
  1874. $flowinfor = $this->getflowinfor();
  1875. if($flowinfor['ischeck']==0 && $lx==0)return '当前是['.$arr['nowcheckname'].']处理';
  1876. $nowcourse = $this->nowcourse; //当前步骤信息
  1877. //异常的审核
  1878. if($lx==1){
  1879. if($arr['nowcourseid']!=0)return '当前有审核步骤ID是存在的不能直接标识已完成';
  1880. $to = $this->flogmodel->rows($this->mwhere.' and `courseid`>0 and `status`=1');
  1881. if($to==0)return '该单据没有任何通过审核处理不能直接标识已完成或已审核';
  1882. $nowcourse = array('id'=>66666,'name'=>'异常处理','step'=>0);
  1883. }
  1884. $nextcourse = $this->nextcourse;
  1885. $zynameid = $this->rock->post('zynameid');
  1886. $zyname = $this->rock->post('zyname');
  1887. $csnameid = '';
  1888. $csname = '';
  1889. $nextname = $this->rock->post('nextname');
  1890. $nextnameid = $this->rock->post('nextnameid');
  1891. $qmimgstr = $this->rock->post('qmimgstr'); //签名图片
  1892. $tuiid = (int)$this->rock->post('tuiid'); //退回到哪个flowlog.id上
  1893. $iszhuanyi = $ischangenext = 0;
  1894. if($zt==1 && $this->isflow!=3 && isempt($zynameid) && arrvalue($nextcourse,'checktype')=='change'){
  1895. $ischangenext = 1;//需要选下步处理人
  1896. }
  1897. if($zt!=2)$tuiid = 0;//只有2的状态才能退回
  1898. $istongyi = in_array($zt, $this->flowstatusarr); //是否审核本步骤同意
  1899. //判断是否转办
  1900. if($zynameid!='' && $istongyi){
  1901. if($zynameid==$this->adminid)return '不能转给自己';
  1902. $sm = $this->strappend($sm, '转给:'.$zyname.'');
  1903. $iszhuanyi = 1;
  1904. $this->rs['syszb_name'] = $zyname;
  1905. $this->rs['syszb_nameid'] = $zynameid;
  1906. }
  1907. //--autharstart--
  1908. $csnameid = $this->rock->post('csnameid');
  1909. $csname = $this->rock->post('csname');
  1910. if(arrvalue($nowcourse,'cslx')=='2' && $csnameid=='' && $istongyi)return '必须选择抄送对应人';
  1911. if(arrvalue($nowcourse,'cslx')=='3' && $istongyi){
  1912. $csfwid = arrvalue($nowcourse,'csfwid');
  1913. $csfwname = arrvalue($nowcourse,'csfwname');
  1914. if(!isempt($csfwid)){
  1915. if(contain($csfwid,'super')){
  1916. $_super = $this->adminmodel->getsuperman($this->adminid);
  1917. $csfwid = str_replace('super', $_super[0], $csfwid);
  1918. $csfwname = str_replace('审批人直属上级', $_super[1], $csfwname);
  1919. if(substr($csfwid,0,1)==','){$csfwid = substr($csfwid, 1);$csfwname = substr($csfwname, 1);}
  1920. }
  1921. $csnameid = $this->adminmodel->gjoins($csfwid);
  1922. $csname = $csfwname;
  1923. }
  1924. }
  1925. $this->rs['syscs_name'] = $csname;
  1926. $this->rs['syscs_nameid'] = $csnameid;
  1927. //--autharend--
  1928. if($nextnameid=='' && $ischangenext==1)return '请选择下一步处理人';
  1929. $ufied = array();
  1930. if($iszhuanyi == 0 && $zt!=2){
  1931. foreach($flowinfor['checkfields'] as $chef=>$chefv){
  1932. $ufied[$chef] = $this->rock->post('cfields_'.$chef.'');
  1933. if(isempt($ufied[$chef]) && $chefv['isbt']=='1')$this->echomsg(''.$chefv['name'].'不能为空');
  1934. $_str = $this->savedatastr($ufied[$chef], $chefv['fieldsarr'], $this->rs);
  1935. if($_str!='')$this->echomsg($_str);
  1936. }
  1937. }
  1938. $this->checkiszhuanyi = $iszhuanyi;//是否为转办
  1939. $barr = $this->flowcheckbefore($zt, $ufied, $sm);
  1940. $msg = '';
  1941. if(is_array($barr) && isset($barr['msg']))$msg = $barr['msg'];
  1942. //更新字段
  1943. if(is_array($barr) && isset($barr['update'])){
  1944. foreach($barr['update'] as $_k=>$_v)$ufied[$_k] = $_v;
  1945. }
  1946. if(is_string($barr))$msg = $barr;
  1947. if(!isempt($msg))return $msg;
  1948. if($ufied){
  1949. $bo = $this->update($ufied, $this->id);
  1950. if(!$bo)return 'dberr:'.$this->db->error();
  1951. }
  1952. $courseact = $flowinfor['courseact'];
  1953. $act = $courseact[$zt];
  1954. $statusname = $act[0];//状态名称
  1955. $statuscolor= $act[1];//状态颜色
  1956. $nzt = $act[2];//处理后对应状态
  1957. $courseid = $nowcourse['id'];
  1958. $this->checksmodel->update('`status`='.$zt.'', $this->mwhere.' and `checkid`='.$this->adminid.' and `courseid`='.$courseid.'');
  1959. if($iszhuanyi == 1){
  1960. $this->addcheckname($courseid, $zynameid, $zyname, false, 4);
  1961. $nowcourse['id'] = 0;
  1962. }
  1963. //指定下步审核
  1964. if($ischangenext==1){
  1965. $this->addcheckname($nextcourse['id'], $nextnameid, $nextname, true, 1);
  1966. }
  1967. //读取退回记录
  1968. $tuirs = array();
  1969. if($tuiid > 0)$tuirs = $this->flogmodel->getone($tuiid);
  1970. if(!$tuirs)$tuiid = 0;
  1971. if($tuiid>0){
  1972. $sm = $this->strappend($sm, '退回到['.$tuirs['name'].'('.$tuirs['checkname'].')]');
  1973. $statusname = '退回';
  1974. $statuscolor = '#17B2B7';
  1975. }
  1976. $this->checkistui = $tuiid;//是否为退回的
  1977. $logsm = $sm;
  1978. if($iszhuanyi==0 && $csname)$logsm = $this->strappend($logsm,'抄送给:'.$csname.'');
  1979. $this->lastlogid = $this->addlog(array(
  1980. 'courseid' => $nowcourse['id'],
  1981. 'name' => $nowcourse['name'],
  1982. 'step' => $nowcourse['step'],
  1983. 'status' => $zt,
  1984. 'statusname'=> $statusname,
  1985. 'color' => $statuscolor,
  1986. 'explain' => $logsm,
  1987. 'iszb' => $iszhuanyi,
  1988. 'qmimg' => $qmimgstr
  1989. ));
  1990. //退回处理
  1991. if($tuiid > 0){
  1992. $this->addcheckname($tuirs['courseid'], $tuirs['checkid'], $tuirs['checkname'], true, 3);
  1993. $this->updatelogvalid('and `courseid`>0 and `status`=1 and `step`>='.$tuirs['step'].'');
  1994. }
  1995. $lzt = $this->rock->repempt($nzt, $zt);//最后状态
  1996. $uparr = $nexttodoarr = $nexttodoarc = array();
  1997. $bsarr = $this->getflow();
  1998. $bsarr['tuiid'] = $tuiid;
  1999. $nextcheckid = $bsarr['nowcheckid']; //下一步审核人
  2000. if($istongyi){//同意
  2001. if($iszhuanyi==0){
  2002. $uparr['status']= $this->rock->repempt($nzt,'0');
  2003. }
  2004. $nexttodoarr = array($nextcheckid, 'next', $sm, $statusname);//通知下一步处理人
  2005. }else{
  2006. if($tuiid>0){
  2007. $lzt = 23; //退回固定状态23
  2008. $nexttodoarr = array($nextcheckid, 'tui', $sm, $statusname); //通知到退回的人员
  2009. }elseif($zt==2){//2固定不同意
  2010. $nexttodoarr = array($this->optid, 'nothrough', $sm, $statusname);
  2011. }
  2012. $uparr['status'] = $lzt;
  2013. }
  2014. $this->flowcheckafter($zt, $sm, $nowcourse);
  2015. $bsarr['nstatus'] = $lzt;
  2016. $bsarr['checksm'] = $sm;
  2017. //没有当前步骤就是结束完成了
  2018. if(!$this->nowcourse){
  2019. $uparr['status'] = $lzt;
  2020. $nexttodoarc = array($this->optid, 'finish', $sm, '');
  2021. }
  2022. //最后状态更新
  2023. if($uparr){
  2024. $this->update($uparr, $this->id);
  2025. }
  2026. //审核完成了调用对应函数接口
  2027. if(!$this->nowcourse){
  2028. $this->flowcheckfinsh($zt);
  2029. if($istongyi){
  2030. $this->checksmodel->delete($this->mwhere);//完成了删除设置审核人
  2031. }
  2032. }
  2033. $bsarr['status'] = $this->rs['status'];//状态
  2034. $this->getflowsave($bsarr, true);
  2035. //通知给相应人员
  2036. if($this->db->backsql()){
  2037. $bos = ($courseid == arrvalue($this->nowcourse, 'id') && $istongyi);
  2038. if($nexttodoarr && (!$bos || $iszhuanyi==1))$this->nexttodo($nexttodoarr[0],$nexttodoarr[1],$nexttodoarr[2],$nexttodoarr[3]);
  2039. if($nexttodoarc)$this->nexttodo($nexttodoarc[0],$nexttodoarc[1],$nexttodoarc[2],$nexttodoarc[3]);
  2040. }
  2041. //通知发送的
  2042. if($iszhuanyi == 1){
  2043. $this->gettodosend('bozhuan','', $sm, 0, ''.$this->adminname.'将['.$nowcourse['name'].']转给:'.$zyname.'');
  2044. }else{
  2045. if($istongyi)$this->gettodosend('botong', $statusname, $sm, $nowcourse['id']);
  2046. if($zt==2)$this->gettodosend('bobutong',$statusname, $sm, $nowcourse['id']);
  2047. if(!$this->nowcourse && $istongyi)$this->gettodosend('bofinish', '', $sm); //全部完成了
  2048. }
  2049. //通知给抄送人,转办不需要抄送
  2050. if($iszhuanyi==0){
  2051. $sm1 = '在“'.$nowcourse['name'].'”处理'.$statusname.'';
  2052. $this->savecsname($csnameid,$csname,$this->adminid,$nowcourse['id'],1, $sm1);
  2053. }
  2054. return 'ok';
  2055. }
  2056. public function pushs($receid, $cont, $title='', $params=array())
  2057. {
  2058. return $this->push($receid,'', $cont, $title, 0, $params);
  2059. }
  2060. /**
  2061. * 详情的URL
  2062. */
  2063. public function getxiangurl($num='', $id=0, $lx='x')
  2064. {
  2065. if($num=='')$num = $this->modenum;
  2066. if($id==0)$id = $this->id;
  2067. $url = URL;
  2068. if($lx=='auto')$lx = ($this->ismobile==1)?'x':'p';
  2069. if($lx=='x' || $lx=='a')$url = $this->rock->getouturl();//移动端
  2070. $url = ''.$url.'task.php?a='.$lx.'&num='.$num.'&mid='.$id.'';
  2071. if(COMPANYNUM)$url.='&dwnum='.COMPANYNUM.'';
  2072. return $url;
  2073. }
  2074. public function getxiangurlx($num='',$id=0){return $this->getxiangurl($num,$id,'x');}
  2075. /**
  2076. * 推送提醒
  2077. */
  2078. public function push($receid, $gname='', $cont='', $title='', $wkal=0, $params=array())
  2079. {
  2080. if(isempt($receid) && $wkal==1)$receid='all';
  2081. if(isempt($receid))return false;
  2082. if(contain(','.$receid.',', ',d1,'))$receid='all'; //如果选顶级d1就是全员
  2083. $modenum = arrvalue($params, 'modenum', $this->modenum);
  2084. $modename = arrvalue($params, 'modename', $this->modename);
  2085. $id = (int)arrvalue($params, 'id', $this->id);
  2086. $moders = arrvalue($params, 'moders');
  2087. if(!is_array($moders))$moders = $this->moders;
  2088. if($gname=='')$gname = $modename;
  2089. $reim = m('reim');
  2090. $url = $this->getxiangurl($modenum, $id, 'p');
  2091. $wxurl = $this->getxiangurl($modenum, $id, 'x');
  2092. $emurl = $this->getxiangurl($modenum, $id, 'a');
  2093. if($id==0){
  2094. $url = '';$wxurl = '';$emurl='';
  2095. }
  2096. $url = arrvalue($params, 'url', $url); //PC上URL
  2097. $wxurl = arrvalue($params, 'wxurl', $wxurl); //移动端URL
  2098. $emurl = arrvalue($params, 'emurl', $emurl); //邮件上URL
  2099. $slx = 0;
  2100. $pctx = $moders['pctx'];
  2101. $mctx = $moders['mctx'];
  2102. $wxtx = $moders['wxtx'];
  2103. $ddtx = $moders['ddtx'];
  2104. $emtx = $moders['emtx'];
  2105. if($pctx==0 && $mctx==1)$slx=2;
  2106. if($pctx==1 && $mctx==0)$slx=1;
  2107. if($pctx==0 && $mctx==0)$slx=3;
  2108. $this->rs['now_adminname'] = $this->adminname;
  2109. $this->rs['now_modename'] = $modename;
  2110. $cont = $this->rock->reparr($cont, $this->rs);
  2111. $receid = $this->adminmodel->gjoins($receid);//已经返回对应人id了
  2112. $uids = m('todo')->addtodo($receid, $modename, $cont, $modenum, $id);
  2113. if($uids!='' && $moders['type'] != '系统' && $id > 0)$this->todosmodel->addtotouids($uids, array(
  2114. 'table' => $moders['table'],
  2115. 'mid' => $id,
  2116. 'modename' => $modename,
  2117. 'modenum' => $modenum,
  2118. ));
  2119. $title = $this->rock->reparr($title, $this->rs);
  2120. $reim->pushagent($uids, $gname, $cont, $title, $url, $wxurl, $slx, ''.$modenum.'|'.$id.'');
  2121. $this->flowchangetodo($uids, $gname);
  2122. if(isempt($title))$title = $modename;
  2123. //--autharstart--
  2124. //邮件提醒发送不发送全体人员的,太多了
  2125. if($emtx == 1 && $receid != 'all'){
  2126. $emcont = '您好:<br>'.$cont.'(邮件由系统自动发送)';
  2127. if($emurl!=''){
  2128. $emcont.='<br><a href="'.$emurl.'" target="_blank" style="color:blue"><u>详情&gt;&gt;</u></a>';
  2129. }
  2130. $msg = m('email')->sendmail($title, $emcont, $receid);
  2131. if($msg!='ok')m('log')->addlogs('邮件', $msg , 2);
  2132. }
  2133. //微信提醒发送
  2134. $isptbo = $reim->installwx(5);
  2135. if($wxtx==1 || $isptbo){
  2136. $wxarra = $this->flowweixinarr;
  2137. $wxarr = array(
  2138. 'title' => $title,
  2139. 'description' => $cont,
  2140. 'url' => $wxurl
  2141. );
  2142. $picurl = arrvalue($this->rs, 'fengmian');
  2143. if($picurl != ''){
  2144. if(substr($picurl,0,4) != 'http')$picurl = URL.$picurl;
  2145. $wxarr['picurl'] = $picurl;
  2146. }
  2147. foreach($wxarra as $k=>$v)$wxarr[$k]=$v;
  2148. //REIM即时通讯平台
  2149. if($isptbo){
  2150. $sarr = $wxarr;
  2151. $sarr['url'] = $emurl;
  2152. m('reimplat:agent')->sendxiao($receid, $gname, $sarr);
  2153. }
  2154. //企业微信提醒
  2155. if($reim->installwx(1) && $wxtx==1){
  2156. $gnames = $gname;
  2157. if($gname != $modename)$gnames =''.$modename.','.$gname.'';
  2158. $devagent = $this->option->getval('weixinqy_devagent');
  2159. if(isempt($devagent))$devagent = '办公助手';
  2160. $barr = m('weixinqy:index')->sendxiao($receid, ''.$gnames.','.$devagent.'', $wxarr);
  2161. m('log')->todolog('企业微信提醒', $barr);
  2162. }
  2163. //微信公众号
  2164. if(($gname=='流程待办' || $gname=='流程申请') && $wxtx==1 && $reim->installwx(4)){
  2165. $zta = $this->getnowstatus();
  2166. $barr = m('wxgzh:index')->send($receid, '流程待办', array(
  2167. 'url' => $wxurl,
  2168. 'applyname' => $this->rs['base_name'],
  2169. 'deptname' => $this->rs['base_deptname'],
  2170. 'sericnum' => $this->sericnum,
  2171. 'title' => $title,
  2172. 'explain' => $cont,
  2173. 'modename' => $this->modename,
  2174. 'optname' => $this->adminname,
  2175. 'optdt' => $this->rock->now,
  2176. 'statustext' => $zta[0],
  2177. 'statustext_color' => $zta[1],
  2178. 'applydt' => arrvalue($this->billrs, 'applydt', $this->rock->date),
  2179. 'summary' => $this->getsummary(),
  2180. ));
  2181. m('log')->todolog('微信模版消息', $barr);
  2182. }
  2183. }
  2184. //钉钉提醒发送
  2185. if($ddtx==1 && $reim->installwx(2)){
  2186. $barr = m('dingding:index')->sendoa($receid, $gname, array(
  2187. 'title' => $title,
  2188. 'content' => $cont,
  2189. 'wxurl' => arrvalue($this->flowweixinarr, 'url', $wxurl),
  2190. 'modename' => $modename
  2191. ));
  2192. m('log')->todolog('钉钉提醒', $barr);
  2193. }
  2194. //--autharend--
  2195. $this->flowweixinarr=array();
  2196. return $receid;
  2197. }
  2198. /**
  2199. * 下一步发通知
  2200. */
  2201. public function nexttodo($nuid, $type, $sm='', $act='')
  2202. {
  2203. $cont = '';
  2204. $tit = '';
  2205. $gname = '流程待办';
  2206. $summary= $this->getsummary();
  2207. if($type=='submit' || $type=='next' || $type == 'cuiban'){
  2208. $cont = '你有['.$this->uname.']的['.$this->modename.',单号:'.$this->sericnum.']需要处理';
  2209. if($sm!='')$cont.=',说明:'.$sm.'';
  2210. $tit = ''.$this->uname.'的'.$this->modename.'';
  2211. //短信提醒
  2212. if($type != 'cuiban'){
  2213. $txnum = $this->option->getval('sms_txnum');
  2214. if(!isempt($txnum)){
  2215. $mknum = $this->option->getval('sms_mknum');
  2216. if($mknum=='all' || contain(','.$mknum.',',','.$this->modenum.',')){
  2217. $wxurl = $this->getxiangurlx();
  2218. $farr = $this->getflow();
  2219. $barr = c('xinhuapi')->sendsms($nuid, '', $txnum, array(
  2220. 'modename' => $this->modename,
  2221. 'sericnum' => $this->sericnum,
  2222. 'applyname'=> $this->uname,
  2223. 'deptname' => $this->rs['base_deptname'],
  2224. 'name' => $farr['nowcheckname'],
  2225. 'userName' => $this->uname,
  2226. 'orderName'=> $this->modename,
  2227. ),$wxurl);
  2228. }
  2229. }
  2230. }
  2231. $type = 'daiban';
  2232. }
  2233. //审核不同意
  2234. if($type == 'nothrough'){
  2235. $cont = '你提交['.$this->modename.',单号:'.$this->sericnum.']'.$this->adminname.'处理['.$act.'],原因:['.$sm.']';
  2236. $gname= '流程申请';
  2237. $tit = ''.$this->modename.'处理'.$act.'';
  2238. }
  2239. if($type == 'finish'){
  2240. $cont = '你提交的['.$this->modename.',单号:'.$this->sericnum.']已全部处理完成';
  2241. $gname= '流程申请';
  2242. $tit = ''.$this->modename.'全部处理完成';
  2243. }
  2244. if($type == 'zhui'){
  2245. $cont = ''.$this->adminname.'追加单据说明['.$this->modename.',单号:'.$this->sericnum.'],说明:['.$sm.']';
  2246. }
  2247. //退回
  2248. if($type == 'tui'){
  2249. $cont = '['.$this->adminname.']退回单据['.$this->modename.',单号:'.$this->sericnum.']到你这请及时处理,说明:'.$sm.'';
  2250. }
  2251. //提交抄送
  2252. if($type == 'chao'){
  2253. $cont = ''.$this->adminname.''.$sm.'了“'.$this->modename.'”';
  2254. if(!isempt($summary))$cont.=',摘要“'.$summary.'”';
  2255. if($this->isflow>0)$cont.=',单号“'.$this->sericnum.'”';
  2256. $gname= '';
  2257. $tit = ''.$this->modename.'的单据抄送';
  2258. }
  2259. //评论
  2260. if($type=='pinglun'){
  2261. $cont = ''.$this->adminname.''.$act.'你的['.$this->modename.']单据,说明:'.$sm.'';
  2262. $gname = '';
  2263. $tit = ''.$this->modename.'评论';
  2264. }
  2265. //回执确认
  2266. if($type=='receipt'){
  2267. $cont = ''.$this->adminname.''.$act.'['.$this->modename.']的单据';
  2268. if($sm!='')$cont.=',说明:'.$sm.'';
  2269. $gname = '回执确认';
  2270. $tit = ''.$this->modename.'回执确认';
  2271. }
  2272. $nbis = $this->flownexttodo($type); //自定义推送内容
  2273. if($nbis){
  2274. if(is_string($nbis))$cont = $nbis;
  2275. if(is_array($nbis)){
  2276. $tit = arrvalue($nbis, 'title', $tit);
  2277. $gname = arrvalue($nbis, 'gname', $gname);
  2278. $cont = arrvalue($nbis, 'cont', $cont);
  2279. }
  2280. }
  2281. if($cont!='')$this->push($nuid, $gname, $cont, $tit);
  2282. }
  2283. public function getwxurl($num='')
  2284. {
  2285. if($num=='')$num = $this->modenum;
  2286. $url = $this->rock->getouturl();
  2287. $str = ''.$url.'?m=ying&d=we&num='.$num.'';
  2288. return $str;
  2289. }
  2290. /**
  2291. * 模块移动端url
  2292. */
  2293. public function getweurl($num='')
  2294. {
  2295. if($num=='')$num = $this->modenum;
  2296. $url = $this->rock->getouturl();
  2297. $str = ''.$url.'?m=ying&d=we&mnum='.$num.'';
  2298. return $str;
  2299. }
  2300. /**
  2301. * 删除单据
  2302. */
  2303. public function deletebill($sm='', $qxpd=true)
  2304. {
  2305. if(getconfig('systype')=='demo')return '演示请勿删除';
  2306. if($qxpd){
  2307. $is = $this->isdeleteqx();
  2308. if($is==0)return '无权删除';
  2309. }
  2310. //删除前判断
  2311. if(method_exists($this,'flowdeletebillbefore')){
  2312. $bstr = $this->flowdeletebillbefore($sm);
  2313. if(!isempt($bstr))return $bstr;
  2314. }
  2315. $modewhere = "`modenum`='".$this->modenum."' and `mid`=".$this->id."";
  2316. $this->flogmodel->delete($this->mwhere);
  2317. m('reads')->delete($this->mwhere);
  2318. m('file')->delfiles($this->mtable, $this->id);
  2319. $tables = $this->moders['tables'];
  2320. if(!isempt($tables)){
  2321. $arrse = explode(',', $tables);
  2322. foreach($arrse as $arrses)m($arrses)->delete('mid='.$this->id.'');
  2323. }
  2324. $this->billmodel->delete($this->mwhere);
  2325. $this->todosmodel->delete($this->mwhere);
  2326. $this->checksmodel->delete($this->mwhere);
  2327. $this->chaomodel->delete($this->mwhere);
  2328. m('remind')->delete($this->mwhere); //单据提醒的
  2329. m('todo')->delete($this->mwhere);
  2330. m('todo')->delete($modewhere);
  2331. m('receipt')->delete($this->mwhere); //回执
  2332. m('im_history')->delete("`xgurl`='".$this->modenum."|".$this->id."'");
  2333. $this->delete($this->id);
  2334. $this->flowdeletebill($sm);
  2335. $this->flowzuofeibill($sm);
  2336. $this->gettodosend('bodel','', $sm);
  2337. $dels = '删除模块['.$this->modename.']id为'.$this->id.'的单据';
  2338. $ztss = arrvalue($this->rs,'base_summary');
  2339. if(!isempt($ztss))$dels.=',摘要['.$ztss.']';
  2340. if(!isempt($sm))$dels.=',说明:'.$sm.'';
  2341. m('log')->addlogs('删除单据', $dels, 3);
  2342. foreach($this->wherejoin as $num=>$fields){
  2343. $this->deletebilljoin($num, "`$fields`='$this->id'", $sm);
  2344. }
  2345. return 'ok';
  2346. }
  2347. /**
  2348. * 关联删除
  2349. */
  2350. public function deletebilljoin($num, $where, $sm='')
  2351. {
  2352. $flow = m('flow')->initflow($num);
  2353. $rows = $flow->getall($where);
  2354. foreach($rows as $k1=>$rs1){
  2355. $mid = $rs1['id'];
  2356. $flow->loaddata($mid, false);
  2357. $flow->deletebill($sm, false);
  2358. }
  2359. }
  2360. /**
  2361. * 关联作废
  2362. */
  2363. public function zuofeibilljoin($num, $where, $sm='')
  2364. {
  2365. $flow = m('flow')->initflow($num);
  2366. $rows = $flow->getall($where);
  2367. foreach($rows as $k1=>$rs1){
  2368. $mid = $rs1['id'];
  2369. $flow->loaddata($mid, false);
  2370. $flow->zuofeibill($sm);
  2371. }
  2372. }
  2373. /**
  2374. * 单据作废处理
  2375. */
  2376. public function zuofeibill($sm='')
  2377. {
  2378. $this->addlog(array(
  2379. 'explain' => $sm,
  2380. 'name' => '作废',
  2381. 'status' => 1,
  2382. ));
  2383. $this->update('`status`=5', $this->id);
  2384. $zfarr = array(
  2385. 'status' => 5,
  2386. 'nstatus' => 5,
  2387. 'checksm' => '作废:'.$sm.'',
  2388. 'nowcheckid' => '',
  2389. 'nowcheckname' => '',
  2390. 'nstatustext' => '作废',
  2391. 'updt' => $this->rock->now,
  2392. );
  2393. $this->billmodel->update($zfarr, $this->mwhere);
  2394. $tables = $this->moders['tables'];
  2395. if(!isempt($tables)){
  2396. $arrse = explode(',', $tables);
  2397. foreach($arrse as $arrses)m($arrses)->delete('mid='.$this->id.'');
  2398. }
  2399. $this->flowzuofeibill($sm);
  2400. $this->gettodosend('bozuofei','', $sm);
  2401. foreach($this->wherejoin as $num=>$fields){
  2402. $this->zuofeibilljoin($num, "`$fields`='$this->id'", $sm);
  2403. }
  2404. return 'ok';
  2405. }
  2406. /**
  2407. * 对外接口详情页加载数据
  2408. */
  2409. public function openxiang()
  2410. {
  2411. $xiangdata = $btndata = array();
  2412. $data = $this->flowrsreplace($this->rs,4);
  2413. foreach($this->fieldsarra as $k=>$rs){
  2414. if($rs['iszs']=='1'){
  2415. $xiangdata[] = array(
  2416. 'name' => $rs['name'],
  2417. 'fields'=> $rs['fields'],
  2418. 'value' => $this->rock->repempt(arrvalue($data,$rs['fields']))
  2419. );
  2420. }
  2421. }
  2422. $barr['xiangdata'] = $xiangdata;
  2423. $btnrows = $this->db->getrows('[Q]flow_menu',"`setid`='$this->modeid' and `status`=1 and `num` like 'open%'",'id,wherestr,name,num,issm,type','`sort`');
  2424. foreach($btnrows as $k=>$rs){
  2425. $wherestr = $rs['wherestr'];
  2426. $bo = false;
  2427. if(isempt($wherestr)){
  2428. $bo = true;
  2429. }else{
  2430. $ewet = $this->wheremodel->getstrwhere($this->rock->jm->base64decode($wherestr));
  2431. $ewet = str_replace(array('{asqom}','1=2 and'),'', $ewet);
  2432. $tos = $this->rows("`id`='$this->id' and $ewet");
  2433. if($tos>0)$bo = true;
  2434. }
  2435. if($bo)$btndata[] = array(
  2436. 'id' => $rs['id'],
  2437. 'name' => $rs['name'],
  2438. 'issm' => $rs['issm'],
  2439. );
  2440. }
  2441. $barr['btndata'] = $btndata;
  2442. if(method_exists($this,'flowopenxiang')){
  2443. $lbarr = $this->flowopenxiang($data,$xiangdata,$btndata);
  2444. if(is_array($lbarr))foreach($lbarr as $k=>$v)$barr[$k]=$v;
  2445. }
  2446. return $barr;
  2447. }
  2448. /**
  2449. * 短信催办,需要有短信功能
  2450. */
  2451. public function smschuiban($sm='')
  2452. {
  2453. //有流程和是我催办
  2454. if($this->isflow>0 && $this->adminid==$this->uid){
  2455. $farr = $this->getflow(true);
  2456. $nowcheckid = $farr['nowcheckid']; //当前处理人
  2457. $tplnum = $this->option->getval('sms_cbnum','defnum');//短信模版
  2458. $wxurl = $this->getxiangurlx();
  2459. $barr = c('xinhuapi')->sendsms($nowcheckid, '', $tplnum, array(
  2460. 'modename' => $this->modename,
  2461. 'sericnum' => $this->sericnum,
  2462. 'applyname'=> $this->uname,
  2463. 'deptname' => $this->rs['base_deptname'],
  2464. ),$wxurl, false, false);//短信催办不需要日志和异步
  2465. if(!$barr['success'])return $barr['msg'];
  2466. $this->addlog(array(
  2467. 'explain' => $sm,
  2468. 'name' => '短信催办',
  2469. 'status' => 1,
  2470. ));
  2471. }
  2472. return 'ok';
  2473. }
  2474. /**
  2475. * 加入日程提醒
  2476. */
  2477. public function addschedule($sm='')
  2478. {
  2479. $txdt = $this->rock->post('txdt');
  2480. if(isempt($sm))return '说明不能为空';
  2481. if(isempt($txdt))return '提醒时间不能为空';
  2482. $barr['title'] = $sm;
  2483. $barr['startdt'] = $txdt;
  2484. $barr['uid'] = $this->adminid;
  2485. $barr['optdt'] = $this->rock->now;
  2486. $barr['optname']= $this->adminname;
  2487. $barr['txsj'] = 1;
  2488. m('schedule')->insert($barr);
  2489. return 'ok';
  2490. }
  2491. /*
  2492. * 获取操作菜单 $flx=0 从操作上点出来 1详情上展示的
  2493. */
  2494. public function getoptmenu($flx=0)
  2495. {
  2496. $where = '';
  2497. if($flx==1)$where='and `iszs`=1';
  2498. $rows = $this->db->getrows('[Q]flow_menu',"`setid`='$this->modeid' ".$where." and `status`=1",'id,wherestr,name,statuscolor,statusvalue,num,islog,issm,type,upgcont','`sort`');
  2499. $arr = array();
  2500. $bfrom = $this->rock->post('bfrom');
  2501. $arr[] = array('lx'=>0,'name'=>$this->rock->jm->base64decode('5pyq562!5o6I5peg5rOV5pi!56S66I!c5Y2V'),'optmenuid'=>0,'color'=>'red');
  2502. //--autharstart--
  2503. $arr = array();
  2504. foreach($rows as $k=>$rs){
  2505. $wherestr = $rs['wherestr'];
  2506. $bo = false;
  2507. if(isempt($wherestr)){
  2508. $bo = true;
  2509. }else{
  2510. $ewet = $this->wheremodel->getstrwhere($this->rock->jm->base64decode($wherestr));
  2511. $ewet = str_replace('{asqom}','', $ewet);
  2512. $tos = $this->rows("`id`='$this->id' and $ewet");
  2513. if($tos>0)$bo = true;
  2514. }
  2515. $rs['lx'] = $rs['type'];
  2516. $rs['optnum'] = $rs['num'];
  2517. if(!isempt($rs['num'])){
  2518. $glx = $this->flowgetoptmenu($rs['num']);
  2519. if(is_bool($glx))$bo = $glx;
  2520. if(is_array($glx))foreach($glx as $k1=>$v1)$rs[$k1]=$v1;
  2521. }
  2522. $rs['optmenuid'] = $rs['id'];$rs['color']='';
  2523. if(!isempt($rs['statuscolor']))$rs['color'] = $rs['statuscolor'];
  2524. unset($rs['id']);unset($rs['num']);unset($rs['wherestr']);unset($rs['type']);unset($rs['statuscolor']);
  2525. if($rs['lx']==5 || $rs['lx']==7){
  2526. $upgcont = $this->rock->jm->base64decode($rs['upgcont']);
  2527. $rs['upgcont'] = $this->rock->reparr($upgcont, $this->rs);
  2528. }else{
  2529. unset($rs['upgcont']);
  2530. }
  2531. if($bo)$arr[] = $rs;
  2532. }
  2533. //--autharend--
  2534. if($flx==1)return $arr;
  2535. $status = (int)arrvalue($this->rs,'status','0');
  2536. $isturn = (int)arrvalue($this->rs, 'isturn','0');
  2537. $ismy = ($this->uid == $this->adminid or $this->optid == $this->adminid);
  2538. $isreadbo = $this->isreadqx(1);
  2539. //菜单上参数说明lx 标识类型,nup是否不显示上传框,optmenuid菜单Id负数,issm是否需要说明
  2540. if($this->isflow>0 && $isturn==1){
  2541. //--autharstart--
  2542. if(!in_array($status, array(1,5)) && $isreadbo){
  2543. $arr[] = array('name'=>'追加说明...','lx'=>1,'issm'=>1,'optmenuid'=>-12);
  2544. }
  2545. $isjk = $this->isjiankongqx();//监控权限
  2546. if(!in_array($status, array(1,5)) && ($ismy || $isjk)){
  2547. $arr[] = array('name'=>'作废申请...','lx'=>16,'issm'=>1,'nup'=>1,'optmenuid'=>-16); //可直接作废
  2548. if($isjk){
  2549. $arr[] = array('name'=>'监控转办...','color'=>'blue','lx'=>3,'issm'=>1,'nup'=>1,'optmenuid'=>-18);
  2550. //$arr[] = array('name'=>'撤回上一步处理','color'=>'#ff6600','lx'=>1,'issm'=>1,'nup'=>1,'optmenuid'=>-19);
  2551. }
  2552. }
  2553. if(!in_array($status, array(1,2,5)) && ($ismy || $isjk)){
  2554. $arr[] = array('name'=>'催办...','lx'=>13,'issm'=>1,'nup'=>1,'optmenuid'=>-13);
  2555. if($this->option->getval('sms_iscb')=='1')$arr[] = array('name'=>'短信催办...','lx'=>17,'issm'=>1,'nup'=>1,'optmenuid'=>-17);
  2556. }
  2557. $chearr = $this->getflowinfor();
  2558. if($chearr['ischeck']==1){
  2559. $arr[] = array('name'=>'<b>去处理单据...</b>','color'=>'#1389D3','lx'=>996);
  2560. if(1==2)foreach($chearr['courseact'] as $zv=>$dz){
  2561. if($zv>0){
  2562. $assar = array('name'=>$dz[0],'color'=>$dz[1],'optnum'=>'check','issm'=>1,'islog'=>0,'statusvalue'=>$zv,'lx'=>'10','optmenuid'=>-10);
  2563. if($zv==1)$assar['issm'] = 0;
  2564. $arr[] = $assar;
  2565. }
  2566. }
  2567. }
  2568. //--autharend--
  2569. }
  2570. if($status != 5 && arrvalue($this->moders,'ispl','1')=='1' && $isreadbo){
  2571. $arr[] = array('name'=>'评论','lx'=>15,'nup'=>1,'issm'=>1,'optmenuid'=>-15);
  2572. }
  2573. //回执确认
  2574. if($ismy && arrvalue($this->moders,'ishz')=='1' && $status==1){
  2575. $smcont = $this->getsummary();
  2576. $mid = (int)m('receipt')->getmou('id',"`uid`='$this->adminid' and `modenum`='$this->modenum' and `mid`='$this->id'");
  2577. $namess = '回执确认设置';
  2578. if($mid>0)$namess = '回执确认编辑';
  2579. $arr[] = array('name'=>$namess,'djmid'=>$mid,'optnum'=>'receipt','lx'=>'18','optmenuid'=>-18,'modename'=>$this->modename,'smcont'=>$smcont);
  2580. }
  2581. //定时提醒设置
  2582. if($isreadbo && arrvalue($this->moders,'istxset','1')=='1' && $this->modenum != 'remind' && !in_array($status, array(2,5))){
  2583. $smcont = ''.$this->modename.':'.$this->getsummary();
  2584. $mid = (int)m('remind')->getmou('id',"`uid`='$this->adminid' and `modenum`='$this->modenum' and `mid`='$this->id'");
  2585. $namess = '+添加提醒设置';
  2586. if($mid>0)$namess = '提醒设置编辑';
  2587. $arr[] = array('name'=>$namess,'djmid'=>$mid,'smcont'=>$smcont,'issm'=>1,'optnum'=>'tixing','lx'=>'14','optmenuid'=>-14);
  2588. }
  2589. if($this->iseditqx()==1 && $isreadbo){
  2590. $arr[] = array('name'=>'编辑','optnum'=>'edit','lx'=>'11','optmenuid'=>-11);
  2591. }
  2592. if($this->isdeleteqx()==1){
  2593. $arr[] = array('name'=>'删除','color'=>'red','optnum'=>'del','nup'=>1,'issm'=>0,'islog'=>0,'statusvalue'=>9,'lx'=>'9','optmenuid'=>-9);
  2594. }
  2595. return $arr;
  2596. }
  2597. /**
  2598. * 操作菜单操作
  2599. */
  2600. public function optmenu($czid, $zt, $sm='')
  2601. {
  2602. $msg = '';
  2603. $cname = $this->rock->post('changename');
  2604. $cnameid = $this->rock->post('changenameid');
  2605. $cdate = $this->rock->post('changedate');
  2606. $darr = array(
  2607. 'cname' => $cname,
  2608. 'cnameid' => $cnameid,
  2609. 'cdate' => $cdate,
  2610. 'sm' => $sm,
  2611. );
  2612. if($czid==-9){
  2613. $msg = $this->deletebill($sm);
  2614. }else if($czid==-10){
  2615. $msg = $this->check($zt, $sm);
  2616. if(contain($msg,'成功'))$msg = 'ok';
  2617. }else if($czid==-12){
  2618. $this->zhuijiaexplain($sm);
  2619. }else if($czid==-13){
  2620. $this->chuiban($sm);
  2621. }else if($czid==-14){
  2622. $msg = $this->addschedule($sm);
  2623. }else if($czid==-15){
  2624. $actname = $this->rock->post('name');
  2625. $this->addlog(array(
  2626. 'explain' => $sm,
  2627. 'name' => $actname,
  2628. ));
  2629. //评论时提醒给相关人员
  2630. $uids = arrvalue($this->rs,'uid','0');
  2631. if(isset($this->rs['optid']))$uids.=','.$this->rs['optid'].'';
  2632. $this->nexttodo($uids, 'pinglun', $sm, $actname);
  2633. $this->gettodosend('boping','', $sm);
  2634. }else if($czid==-16){
  2635. $this->zuofeibill($sm); //撤销申请也就是作废了
  2636. }else if($czid==-17){
  2637. $msg = $this->smschuiban($sm); //短信催办
  2638. }else if($czid==-18){
  2639. $msg = $this->jiankongzb($darr);
  2640. }else{
  2641. //--autharstart--
  2642. $ors = m('flow_menu')->getone("`id`='$czid' and `setid`='$this->modeid' and `status`=1");
  2643. if(!$ors)return '菜单不存在';
  2644. $name = str_replace('.', '', $ors['name']);
  2645. $actname = $ors['actname'];if(isempt($actname))$actname=$name;
  2646. if($ors['islog']==1){
  2647. if(!isempt($cname)){
  2648. if(!isempt($sm))$sm.=',';
  2649. $sm.=''.$name.':'.$cname.'';
  2650. }
  2651. $this->addlog(array(
  2652. 'explain' => $sm,
  2653. 'name' => $actname,
  2654. 'statusname'=> $ors['statusname'],
  2655. 'status' => $ors['statusvalue'],
  2656. 'color' => $ors['statuscolor']
  2657. ));
  2658. }
  2659. $barrs = array(
  2660. 'cname' => $cname,
  2661. 'sm' => $sm,
  2662. 'cnameid' => $cnameid,
  2663. 'cdate' => $cdate
  2664. );
  2665. if($ors['type']==4 && !isempt($ors['fields'])){
  2666. $fielsa = explode(',', $ors['fields']);
  2667. $uarrs = array();
  2668. foreach($fielsa as $fielsas){
  2669. $fsdiwe = 'fields_'.$fielsas.'';
  2670. if(isset($_REQUEST[$fsdiwe])){
  2671. $uarrs[$fielsas]=$this->rock->post($fsdiwe);
  2672. $barrs[$fsdiwe] = $uarrs[$fielsas];
  2673. }
  2674. }
  2675. if($uarrs)$this->update($uarrs, $this->id);
  2676. }
  2677. $upgcont = $ors['upgcont'];
  2678. //需要判断当前用户有没有编辑权限
  2679. if(!isempt($upgcont)){
  2680. $upgcont = $this->rock->jm->base64decode($upgcont);
  2681. $upgcont = str_replace(array('{now}','{date}','{uid}','{adminid}','{admin}','{sm}','{cname}','{cnameid}'),array($this->rock->now,$this->rock->date, $this->adminid, $this->adminid, $this->adminname, $sm, $cname, $cnameid), $upgcont);
  2682. $this->update($upgcont, $this->id);
  2683. }
  2684. $this->flowoptmenu($ors, $barrs);
  2685. //--autharend--
  2686. }
  2687. if($msg=='')$msg='ok';
  2688. return $msg;
  2689. }
  2690. /**
  2691. * 监控人操作转办
  2692. */
  2693. public function jiankongzb($darr)
  2694. {
  2695. //--autharstart--
  2696. $cnameid = $darr['cnameid'];
  2697. $cname = $darr['cname'];
  2698. if(isempt($cnameid))return '没有选择人员';
  2699. $barr = $this->getflow();
  2700. $nowcourseid = arrvalue($barr, 'nowcourseid');
  2701. if(isempt($nowcourseid))return '此单据当前没审核步骤';
  2702. $sm = '将['.$this->nowcourse['name'].']转办给:'.$cname.'';
  2703. $this->addlog(array(
  2704. 'explain' => $sm,
  2705. 'name' => '监控转办',
  2706. ));
  2707. $this->addcheckname($nowcourseid, $cnameid, $cname, true, 7);
  2708. $barr = $this->getflow();
  2709. $this->getflowsave($barr, true);
  2710. $this->nexttodo($barr['nowcheckid'], 'next', $sm);
  2711. return 'ok';
  2712. //--autharend--
  2713. return $this->bd6('5peg5L!h5ZG8562!5o6I5peg5q2k5Yqf6IO9');
  2714. }
  2715. /**
  2716. * 单据展示条件搜索
  2717. */
  2718. public function billwhere($uid, $lx)
  2719. {
  2720. $arr['table'] = $this->mtable;
  2721. $arr['tableleft'] = ''; //左关联table
  2722. $arr['fields'] = '';
  2723. $arr['order'] = '';
  2724. $arr['group'] = '';
  2725. $arr['keywhere']= '';
  2726. $arr['asqom'] = ''; //主表别名
  2727. $arr['onlywhere'] = ''; //只要我的一个搜索
  2728. $arr['companywhere']= ''; //多单位显示搜索
  2729. $this->atype = $lx;
  2730. $nas = $this->flowbillwhere($uid, $lx);
  2731. $inwhere = '';
  2732. if(substr($lx,0,5)=='grant'){
  2733. $inwhere = $this->viewmodel->viewwhere($this->moders, $this->adminid, $this->flowviewufieds, 1);
  2734. }
  2735. //抄送的
  2736. if($lx=='chaos'){
  2737. $inwhere = "and {asqom}`id` in(select `mid` from `[Q]flow_chao` where `table`='{$this->mtable}' and ".$this->rock->dbinstr('csnameid', $this->adminid).")";
  2738. }
  2739. //经我处理
  2740. if($lx=='mychuli'){
  2741. $inwhere = "and {asqom}`id` in(select bill.`mid` from `[Q]flow_bill` as `bill` where bill.`modeid`='{$this->modeid}' and ".$this->rock->dbinstr('bill.`allcheckid`', $this->adminid).")";
  2742. }
  2743. $_wehs = '';
  2744. if(is_array($nas)){
  2745. if(isset($nas['where']))$_wehs = $nas['where'];
  2746. $ftears = explode(',','asqom,order,fields,fieldsleft,table,group,companywhere,onlywhere,keywhere,tableleft');
  2747. foreach($ftears as $fid)if(isset($nas[$fid]))$arr[$fid] = $nas[$fid];
  2748. }else{
  2749. $_wehs = $nas;
  2750. }
  2751. $fwhere = $this->getflowwhere($uid, $lx);//流程模块上条件
  2752. $path = ''.P.'/flow/page/rock_page_'.$this->modenum.'.php';
  2753. $table = $arr['table'];
  2754. $temsao = 0;
  2755. if(!contain($table, ' ') && $this->isflow>0){
  2756. $arr['table'] = '`[Q]'.$this->mtable.'` a left join `[Q]flow_bill` b on a.`id`=b.`mid` and b.`table`=\''.$this->mtable.'\'';
  2757. if(!isempt($arr['tableleft']))$arr['table'].=' left join '.$arr['tableleft'].'';
  2758. $arr['asqom'] = 'a.';
  2759. $arr['fields']= 'a.*,b.`uname` as base_name,b.`udeptname` as base_deptname,b.`sericnum`,b.`nowcheckname`';
  2760. if(isset($arr['fieldsleft']) && $arr['fieldsleft'])$arr['fields'].=','.$arr['fieldsleft'].'';
  2761. if($arr['order']=='')$arr['order'] = 'a.`optdt` desc'; //默认操作时间倒序
  2762. $temsao = 1;
  2763. if($this->defaultorder){
  2764. $defa = explode(',', $this->defaultorder);
  2765. $desc = arrvalue($defa, 1, 'desc');
  2766. $arr['order'] = 'a.`'.$defa[0].'` '.$desc.'';
  2767. }
  2768. }
  2769. if(isempt($arr['order'])){
  2770. $arr['order'] = '{asqom}`id` desc';//没有流程默认id倒序
  2771. if($this->defaultorder){
  2772. $defa = explode(',', $this->defaultorder);
  2773. $desc = arrvalue($defa, 1, 'desc');
  2774. $arr['order'] = '{asqom}`'.$defa[0].'` '.$desc.'';
  2775. }
  2776. }
  2777. if(isempt($fwhere) && isempt($inwhere) && $this->moders['isscl']==1){
  2778. $fwhere = 'and 1=2';
  2779. }
  2780. $where = $inwhere;
  2781. $wherestr = $this->moders['where'];
  2782. if(!isempt($wherestr)){
  2783. $wherestr = $this->rock->covexec($wherestr);
  2784. $where .= ' and {asqom}'.$wherestr;
  2785. }
  2786. if($fwhere!='')$where .= ' '.$fwhere;
  2787. if($_wehs!='')$where .= ' '.$_wehs;
  2788. $highwhere = $this->gethighwhere();//高级搜索
  2789. $allfields = array();
  2790. //关键词搜索
  2791. $key = $this->rock->post('key');
  2792. $pnum = $this->rock->post('pnum');
  2793. $status = $this->rock->post('keystatus');
  2794. $ztfields = arrvalue($nas, 'ztfields', 'status');
  2795. //新加搜索2021-06-07,支持子表搜索
  2796. $xhlikea = array('like','=','>=','<=', 'not like');
  2797. $xhfields = $this->rock->post('xhfields');
  2798. $xhlike = (int)$this->rock->post('xhlike','0');
  2799. $xhkeygj = $this->rock->jm->base64decode($this->rock->post('xhkeygj'));
  2800. if(!isempt($xhkeygj) && $xhfields){
  2801. if(substr($xhfields,0,2)=='zb'){
  2802. $xu = substr($xhfields,2,1);
  2803. $zbasr = explode(',', $this->moders['tables']);
  2804. $zbts = arrvalue($zbasr,$xu);
  2805. $xhfields = substr($xhfields,4);
  2806. $wher1 = "`$xhfields` ".$xhlikea[$xhlike]."";
  2807. if($xhlike==0 || $xhlike==4)$wher1.=" '%".$xhkeygj."%'";
  2808. if($xhlike==1 || $xhlike==2 || $xhlike==3)$wher1.=" '$xhkeygj'";
  2809. $wher1 = " and {asqom}`id` in(select `mid` from `[Q]".$zbts."` where ".$wher1.")";
  2810. $where.= $wher1;
  2811. }else{
  2812. $wher1 = " and {asqom}`$xhfields` ".$xhlikea[$xhlike]."";
  2813. if($xhlike==0 || $xhlike==4)$wher1.=" '%".$xhkeygj."%'";
  2814. if($xhlike==1 || $xhlike==2 || $xhlike==3)$wher1.=" '$xhkeygj'";
  2815. $where.= $wher1;
  2816. }
  2817. }
  2818. if(!isempt($status))$where .= ' and {asqom}`'.$ztfields.'`='.$status.'';
  2819. if(!isempt($key) && isempt($arr['keywhere'])){
  2820. $check = c('check');
  2821. $allfields = $this->db->getallfields('[Q]'.$this->mtable.'');
  2822. $_kearr = array();
  2823. //关键词是日期
  2824. if($check->isdate($key) || $check->ismonth($key)){
  2825. $skeay = array('date','datetime','month');
  2826. foreach($this->fieldsarra as $k=>$rs){
  2827. $flx = $rs['fieldstype'];
  2828. $fid = $rs['fields'];
  2829. if($rs['issou']==1 && in_array($flx, $skeay) && in_array($fid, $allfields)){
  2830. if($check->isdate($key)){
  2831. if($flx=='date')$_kearr[] = "{asqom}`".$fid."`='$key'";
  2832. if($flx=='datetime')$_kearr[] = "{asqom}`".$fid."` like '$key%'";
  2833. if($flx=='month')$_kearr[] = "{asqom}`".$fid."`='".substr($key,0,7)."'";
  2834. if($temsao==1){
  2835. $_kearr[] = "b.`applydt`='$key'";
  2836. }
  2837. }
  2838. if($check->ismonth($key)){
  2839. if($flx=='month'){
  2840. $_kearr[] = "{asqom}`".$fid."`='$key'";
  2841. }else{
  2842. $_kearr[] = "{asqom}`".$fid."` like '$key%'";
  2843. }
  2844. if($temsao==1){
  2845. $_kearr[] = "b.`applydt` like '$key%'";
  2846. }
  2847. }
  2848. }
  2849. }
  2850. }
  2851. if(!$_kearr){
  2852. $skeay = array('text','textarea','htmlediter','changeuser','changeusercheck','changedept','changedeptusercheck','selectdatafalse','selectdatatrue','num');
  2853. $xiakk = array('rockcombo','select');
  2854. foreach($this->fieldsarra as $k=>$rs){
  2855. if($rs['issou']==1 && in_array($rs['fields'], $allfields) && substr($rs['fields'],-2) != 'dt'){
  2856. if(in_array($rs['fieldstype'], $skeay))$_kearr[] = "{asqom}`".$rs['fields']."` like '%".$key."%'";
  2857. //if(in_array($rs['fieldstype'], $xiakk))$_kearr[] = "{asqom}`".$rs['fields']."` = '".$key."'";
  2858. }
  2859. }
  2860. if($temsao==1){
  2861. $_kearr[] = "b.`uname` like '%".$key."%'";
  2862. $_kearr[] = "b.`udeptname` like '%".$key."%'";
  2863. $_kearr[] = "b.`sericnum` = '$key'";
  2864. $_kearr[] = "b.`nowcheckname` = '$key'"; //搜索当前处理人
  2865. }
  2866. //其他or字段条件格式:name@1,title
  2867. if(isset($nas['orlikefields'])){
  2868. $owhee = explode(',', $nas['orlikefields']);
  2869. foreach($owhee as $owhees){
  2870. $_owhees = explode('@', $owhees);
  2871. $sle = arrvalue($_owhees, 1);
  2872. if($sle=='1'){
  2873. $_kearr[] = "".$_owhees[0]." ='$key'";
  2874. }else{
  2875. $_kearr[] = "".$_owhees[0]." like '%".$key."%'";
  2876. }
  2877. }
  2878. }
  2879. }
  2880. if($_kearr && $arr['onlywhere']=='')$arr['keywhere'] = "and (".join(' or ',$_kearr).")";
  2881. }
  2882. if(!isempt($arr['companywhere']) && getconfig('companymode'))$where .= ' '.$arr['companywhere'];
  2883. if(!isempt($arr['onlywhere']))$where .= ' '.$arr['onlywhere'];
  2884. if(!isempt($arr['keywhere']))$where .= ' '.$arr['keywhere'];
  2885. if($highwhere!='')$where .= ' '.$highwhere;
  2886. $where = str_replace('{asqom}', $arr['asqom'], $where);
  2887. $arr['order'] = str_replace('{asqom}', $arr['asqom'], $arr['order']);
  2888. $where = str_replace('[A]', $arr['asqom'], $where);
  2889. //字段显示
  2890. $fields = $arr['fields'];
  2891. if($this->flowfieldstype==1 && (isempt($fields) || $fields=='*') && $this->moders['isscl']==1){
  2892. if(!$allfields)$allfields = $this->db->getallfields('[Q]'.$this->mtable.'');
  2893. $fields = '{asqom}`id`';
  2894. $odlvs = $this->option->getval('columns_'.$this->modenum.'_'.$pnum.'');
  2895. if(isempt($odlvs)){
  2896. foreach($this->fieldsarra as $k=>$rs){
  2897. if($rs['islb']==1 && in_array($rs['fields'],$allfields)){
  2898. $fields.=',{asqom}`'.$rs['fields'].'`';
  2899. }
  2900. }
  2901. }else{
  2902. $odlvsa = explode(',', $odlvs);
  2903. foreach($odlvsa as $odlvs1){
  2904. if(in_array($odlvs1, $allfields)){
  2905. $fields.=',{asqom}`'.$odlvs1.'`';
  2906. }
  2907. }
  2908. }
  2909. if($this->isflow>0){
  2910. if(!contain($fields,'`status`'))$fields.=',{asqom}`status`';
  2911. }
  2912. $fields = str_replace('{asqom}', $arr['asqom'], $fields);
  2913. $arr['fields'] = $fields;
  2914. }
  2915. //字段添加上``
  2916. $fields = $arr['fields'];
  2917. if(!isempt($fields) && $fields!='*'){
  2918. $fieldsa = explode(',', $fields);
  2919. $fieldss = '';
  2920. foreach($fieldsa as $fieldsas){
  2921. if(contain($fieldsas,'`') || contain($fieldsas,'.') || contain($fieldsas,' ') || contain($fieldsas,'(')){
  2922. $fieldss.=','.$fieldsas.'';
  2923. }else{
  2924. $fieldss.=',`'.$fieldsas.'`';
  2925. }
  2926. }
  2927. $arr['fields'] = substr($fieldss, 1);
  2928. }
  2929. $arr['where'] = str_replace('{asqom}','', $where);//替换一下
  2930. return $arr;
  2931. }
  2932. /**
  2933. * 获取高级搜索条件
  2934. */
  2935. public function gethighwhere()
  2936. {
  2937. $s = '';
  2938. //--autharstart--
  2939. foreach($this->fieldsarra as $k=>$rs){
  2940. if($rs['issou']!=1)continue;
  2941. $type = $rs['fieldstype'];
  2942. $fields = $rs['fields'];
  2943. $val = $this->rock->post('soufields_'.$fields.'');
  2944. if($type=='date' || $type=='datetime' || $type=='number' || substr($fields,-2)=='dt'){
  2945. $val1 = $this->rock->post('soufields_'.$fields.'_start');
  2946. $val2 = $this->rock->post('soufields_'.$fields.'_end');
  2947. $val3 = $this->rock->post('soufields_'.$fields.'_equal');
  2948. if($type!='number'){
  2949. if(!isempt($val1))$val1 = "'$val1'";
  2950. if(!isempt($val3))$val3 = "'$val3'";
  2951. if(!isempt($val2)){
  2952. if($type=='datetime')$val2 = "$val2 23:59:59";
  2953. $val2 = "'$val2'";
  2954. }
  2955. }
  2956. if(!isempt($val1))$s.=" and {asqom}`$fields`>=".$val1."";
  2957. if(!isempt($val2))$s.=" and {asqom}`$fields`<=".$val2."";
  2958. if(!isempt($val3))$s.=" and {asqom}`$fields`=".$val3."";
  2959. }else{
  2960. if(isempt($val))continue;
  2961. if($type=='select' || $type=='radio' || $type=='rockcombo'){
  2962. $s.=" and {asqom}`$fields`='$val'";
  2963. }else if($type=='month'){
  2964. $s.=" and {asqom}`$fields` like '$val%'";
  2965. }else{
  2966. $s.=" and {asqom}`$fields` like '%$val%'";
  2967. }
  2968. }
  2969. }
  2970. $ofied = $this->rock->post('search_fields');
  2971. $ofval = $this->rock->post('search_value');
  2972. if(!isempt($ofied) && !isempt($ofval)){
  2973. $ofval = $this->adminmodel->gjoin($ofval,'', 'all');
  2974. $s = " and {asqom}`$ofied` in($ofval)";
  2975. }
  2976. //--autharend--
  2977. return $s;
  2978. }
  2979. /**
  2980. * 根据编号获取对应条件flow_where
  2981. */
  2982. public function getflowwhere($uid, $num)
  2983. {
  2984. $where = '';
  2985. $rs = $this->wheremodel->getone("`setid`='$this->modeid' and `num`='$num'");
  2986. if(!$rs)return $where;
  2987. $where = $this->wheremodel->getwherestr($rs, $uid, $this->flowviewufieds);
  2988. return $where;
  2989. }
  2990. /**
  2991. * 根据流程模块条件读取记录和统计
  2992. */
  2993. public function getflowrows($uid, $lx, $limit=5, $swher='')
  2994. {
  2995. $nas = $this->billwhere($uid, $lx);
  2996. $table = $nas['table'];
  2997. if(!contain($table,' '))$table='[Q]'.$table.'';
  2998. if(isempt($nas['fields']))$nas['fields'] = '*';
  2999. $swher = str_replace('{asqom}',$nas['asqom'], $swher);
  3000. $where = '1=1 '.$nas['where'].' '.$swher.'';
  3001. if($limit==0)return $this->db->rows($table, $where );
  3002. $rows = $this->db->getrows($table, $where , $nas['fields'], $nas['order'], $limit);
  3003. foreach($rows as $k=>$rs){
  3004. $rows[$k] = $this->flowrsreplace($rs, 2);
  3005. }
  3006. return $rows;
  3007. }
  3008. /**
  3009. * 读取要提醒的单据
  3010. */
  3011. public function gettodorows($whereid)
  3012. {
  3013. $where = $this->wheremodel->getwherestr($whereid, $this->adminid, $this->flowviewufieds);
  3014. $wherestr = $this->moders['where'];
  3015. if(!isempt($wherestr)){
  3016. $wherestr = $this->rock->covexec($wherestr);
  3017. $where .= ' and '.$wherestr;
  3018. }
  3019. $where = str_replace('{asqom}','', $where);
  3020. $rows = $this->getall('2=2 '.$where.'');
  3021. foreach($rows as $k=>$rs){
  3022. $rows[$k] = $this->flowrsreplace($rs, 1);
  3023. }
  3024. return $rows;
  3025. }
  3026. /**
  3027. * 打印导出
  3028. */
  3029. public function printexecl($event)
  3030. {
  3031. $arr['moders'] = $this->moders;
  3032. $arr['fields'] = $this->getfields();
  3033. $cell = 1;
  3034. foreach($arr['fields'] as $k=>$v)$cell++;
  3035. $arr['cell'] = $cell;
  3036. $where = '1=1';
  3037. $str1 = $this->moders['where'];
  3038. if(!isempt($str1)){
  3039. $str1 = $this->rock->covexec($str1);
  3040. $where = $str1;
  3041. }
  3042. $vwhere = $this->viewmodel->viewwhere($this->moders, $this->adminid);
  3043. $rows = $this->getrows(''.$where.' '.$vwhere.'', '*', 'id desc', 100);
  3044. $arr['rows'] = $this->flowprintrows($rows);
  3045. $arr['count'] = $this->db->count;
  3046. return $arr;
  3047. }
  3048. /**
  3049. * 获取所有多行子表数据
  3050. * $lx=0编辑时读取,1展示时读取
  3051. */
  3052. public function getsuballdata($lx=0, $mid=0)
  3053. {
  3054. $tabless = $this->moders['tables'];
  3055. $subdata = array();
  3056. if($mid==0)$mid = $this->id;
  3057. if(!isempt($tabless)){
  3058. $tablessa = explode(',', $tabless);
  3059. $namessa = explode(',', $this->moders['names']);
  3060. $tabless1 = '['.str_replace(',','],[', $tabless).']';
  3061. foreach($tablessa as $zbx=>$tables){
  3062. $cis = substr_count($tabless1, '['.$tables.']');
  3063. $whes = '';
  3064. if($cis>1)$whes=' and `sslx`='.$zbx.'';
  3065. $data = m($tables)->getall('mid='.$mid.''.$whes.'','*','`sort`');
  3066. $data = $this->flowsubdata($data, $lx, $zbx);
  3067. if($lx == 0){
  3068. $subdata['subdata'.$zbx.''] = $data;
  3069. }else{
  3070. $subdata[$zbx] = array(
  3071. 'data' => $data,
  3072. 'fields'=> 'subdata'.$zbx.'',
  3073. 'name' => $this->rock->arrvalue($namessa, $zbx)
  3074. );
  3075. }
  3076. }
  3077. }
  3078. return $subdata;
  3079. }
  3080. /**
  3081. * 读取通知
  3082. * $act 当前动作有(boturn,boedit,bochang,bodel)
  3083. */
  3084. private $gettodolistarr = null;
  3085. public function gettodolist($act)
  3086. {
  3087. if(is_array($act))return $act;
  3088. if($this->gettodolistarr === null){
  3089. $rows = $this->todomodel->getrows("`setid`='".$this->modeid."' and `status`=1");
  3090. $barr = array();
  3091. foreach($rows as $k=>$rs){
  3092. $whereid = (int)$rs['whereid'];
  3093. if($whereid > 0){
  3094. $bo = $this->wheremanzhu($whereid);
  3095. if(!$bo)continue;
  3096. }
  3097. $barr[] = $rs;
  3098. }
  3099. $this->gettodolistarr = $barr;
  3100. }else{
  3101. $barr = $this->gettodolistarr;
  3102. }
  3103. $garr = array();
  3104. if($barr)foreach($barr as $k=>$rs){
  3105. if(arrvalue($rs,$act)=='1')$garr[] = $rs;
  3106. }
  3107. return $garr;
  3108. }
  3109. /**
  3110. * 发送设置的通知
  3111. */
  3112. public function gettodosend($act, $actname='',$sm='', $courseid=0, $conts='')
  3113. {
  3114. $barr = $this->gettodolist($act);
  3115. if(!$barr)return;
  3116. $changearr = array('boturn'=>'提交','boedit'=>'编辑','bozhuan'=>'转办','bochang'=>'修改字段','bodel'=>'删除','bozuofei'=>'作废','botong'=>'处理同意','bobutong'=>'处理不同意','bofinish'=>'全部处理完成','bozhui'=>'追加说明','boping'=>'评论','bohuiz'=>'回执确认');
  3117. if($actname=='' && is_string($act))$actname = arrvalue($changearr, $act);
  3118. if(isempt($actname))return;
  3119. $cheo = c('check');
  3120. foreach($barr as $k=>$rs){
  3121. //提交发送短信通知
  3122. if ($act == 'boturn') {
  3123. $receids = $this->adminmodel->gjoins($rs['receid']);
  3124. $receids = explode(',', $receids);
  3125. $txnum = $this->option->getval('sms_txnum');
  3126. $wxurl = $this->getxiangurlx();
  3127. foreach ($receids as $rk => $rv) {
  3128. $where = "`id`=" . $rv;
  3129. $admin = m('admin')->getone($where, 'name');
  3130. $barr = c('xinhuapi')->sendsms(
  3131. $rv, '', $txnum, [
  3132. 'modename' => $this->modename,
  3133. 'sericnum' => $this->sericnum,
  3134. 'applyname' => $this->uname,
  3135. 'deptname' => $this->rs['base_deptname'],
  3136. 'name' => $admin['name'],
  3137. 'userName' => $this->uname,
  3138. 'orderName' => $this->modename,
  3139. ], $wxurl
  3140. );
  3141. };
  3142. }
  3143. $receid = $rs['receid'];
  3144. if($act=='botong' || $act=='bobutong'){
  3145. $changewe = $rs['changecourse'];
  3146. if(!isempt($changewe) && !contain(','.$changewe.',',','.$courseid.','))continue;
  3147. }
  3148. if($rs['toturn']==1)$receid.=','.$this->uid.''; //通知给提交人
  3149. if(arrvalue($rs,'tosuper')=='1'){
  3150. $supar = $this->adminmodel->getsuperman($this->uid);
  3151. $shnej = arrvalue($supar, 0);
  3152. if(!isempt($shnej))$receid.=','.$shnej.''; //通知给直属上级,没有就读取部门负责人
  3153. }
  3154. if($rs['tocourse']==1 && $this->billrs){
  3155. $allcheckid = $this->billrs['allcheckid'];
  3156. if(!isempt($allcheckid))$receid.=','.$allcheckid.''; //通知流程所有参与人
  3157. }
  3158. //其他字段
  3159. $todofields = $rs['todofields'];
  3160. if(!isempt($todofields)){
  3161. $toad = explode(',', $todofields);
  3162. foreach($toad as $toads){
  3163. $ttv = arrvalue($this->rs, $toads);
  3164. if(!isempt($ttv) && $cheo->isinnumber($ttv))$receid.=','.$ttv.'';
  3165. }
  3166. }
  3167. if(isempt($receid))continue;
  3168. if(substr($receid,0,1)==',')$receid = substr($receid, 1);
  3169. $cont = $rs['summary'];
  3170. if(isempt($cont))$cont = $conts;
  3171. if(isempt($cont)){
  3172. $cont = ''.$this->adminname.''.$actname.'['.$this->modename.',单号:'.$this->sericnum.']';
  3173. if($sm!='')$cont.=',说明:'.$sm.'';
  3174. }
  3175. $this->push($receid, '', $cont, $this->rock->repempt($rs['name']));
  3176. }
  3177. }
  3178. /**
  3179. * 根据编号发送通知
  3180. */
  3181. public function numtodosend($num, $actname='',$sm='')
  3182. {
  3183. $rows = $this->todomodel->getrows("`setid`='".$this->modeid."' and `num`='$num' and `status`=1");
  3184. if(!$rows)return;
  3185. $this->gettodosend($rows, $actname, $sm);
  3186. }
  3187. /**
  3188. * 统计报表
  3189. */
  3190. public function flowtotal($fields='', $type='')
  3191. {
  3192. if($fields=='')$fields = $this->rock->post('total_fields');
  3193. if($type=='')$type = $this->rock->post('total_type','jls');
  3194. $typea = explode('|', $type);
  3195. $typefields = '';
  3196. $type = $typea[0]; $typefields = arrvalue($typea, 1);
  3197. $rowa = array();
  3198. $rowa[] = array(
  3199. 'name' => '暂无数据',
  3200. 'value' => 0,
  3201. 'bili' => ''
  3202. );
  3203. $tofiels= 'count(1)';
  3204. if($type=='sum')$tofiels = 'sum([A]`'.$typefields.'`)';
  3205. if($type=='avg')$tofiels = 'avg([A]`'.$typefields.'`)';
  3206. $atype = $this->rock->post('atype');
  3207. $table = '[Q]'.$this->mtable.'';
  3208. $narr = $this->billwhere($this->adminid, $atype);
  3209. $where = $narr['where'];
  3210. $table = $narr['table'];
  3211. if(!contain($table,' '))$table = '[Q]'.$table.'';
  3212. $gwhere = $this->rock->post('where');
  3213. if(!isempt($gwhere)){
  3214. $gwhere = $this->rock->jm->uncrypt($this->rock->iconvsql($gwhere));
  3215. $where .= ' '.$gwhere.'';
  3216. }
  3217. $sql = 'select '.$fields.' as `name`,'.$tofiels.' as value from '.$table.' where 1=1 '.$where.' group by '.$fields.'';
  3218. $sql = str_replace('[A]', $narr['asqom'], $sql);
  3219. $rows = $this->db->getall($sql);
  3220. $total = 0;
  3221. if($rows){
  3222. foreach($rows as $k=>$rs)$total+=floatval($rs['value']);
  3223. if($total>0)foreach($rows as $k=>$rs){
  3224. $rows[$k]['bili'] = $this->rock->number($rs['value']*100/$total).'%';
  3225. }
  3226. if($type!='avg' && count($rows)>1)$rows[] = array('name' => '合计','value' => $total,'bili' => '');
  3227. }else{
  3228. $rows = $rowa;
  3229. }
  3230. return $rows;
  3231. }
  3232. /**
  3233. * 回执确认
  3234. */
  3235. public function receiptcheck($hid, $sm)
  3236. {
  3237. //--autharstart--
  3238. $hrs = m('receipt')->getone("`id`='$hid' and `modenum`='$this->modenum' and `mid`='$this->id'");
  3239. if(!$hrs)return;
  3240. $receid = $hrs['receid'];
  3241. $receids = $hrs['receids'];
  3242. if(isempt($receids))$receids = '';
  3243. $uid = $this->adminid;
  3244. if(!contain(','.$receid.',', ','.$uid .','))return;
  3245. $reaa = explode(',', $receids);
  3246. if(!$reaa)$reaa = array();
  3247. if(!in_array($uid, $reaa)){
  3248. if($receids!='')$receids.=',';
  3249. $receids.=''.$uid.'';
  3250. }
  3251. $reaa = explode(',', $receids);
  3252. $ushuy = count($reaa);
  3253. $receids= join(',', $reaa);
  3254. m('receipt')->update(array(
  3255. 'receids' => $receids,
  3256. 'ushuy' => $ushuy,
  3257. ), $hid);
  3258. $this->addlog(array(
  3259. 'explain' => $sm,
  3260. 'name' => '回执确认'
  3261. ));
  3262. //通知给提交人
  3263. $this->rs = $hrs;
  3264. $this->nexttodo($hrs['uid'],'receipt', $sm, '回执确认');
  3265. //--autharend--
  3266. return 'ok';
  3267. }
  3268. /**
  3269. * 获取简单列表数据,返回table表格
  3270. */
  3271. public function getrowstable($atype, $where, $limit=100)
  3272. {
  3273. $rows = $this->getflowrows($this->adminid,$atype,$limit,$where);
  3274. $headstr = '@xuhaos,,center';
  3275. foreach($this->fieldsarra as $k=>$rs){
  3276. if($rs['islb']==1 && $rs['iszb']=='0')
  3277. $headstr.='@'.$rs['fields'].','.$rs['name'].'';
  3278. }
  3279. if($this->isflow>0){
  3280. $headstr.='@statustext,状态';
  3281. if(is_array($rows))foreach($rows as $k=>$rs){
  3282. $rows[$k]['statustext'] = $this->getstatusstr($rs);
  3283. }
  3284. }
  3285. $cont = c('html')->createrows($rows, substr($headstr, 1),'#cccccc','noborder');
  3286. return $cont;
  3287. }
  3288. /**
  3289. * 禁看处理
  3290. */
  3291. public function viewjinfields($rows)
  3292. {
  3293. if(!$rows)return $rows;
  3294. //--autharstart--
  3295. $jinkfarr = $this->viewmodel->viewjinfields($this->moders, $this->adminid, $this->flowviewufieds);
  3296. if($jinkfarr && is_array($jinkfarr)){
  3297. $wherear= array();
  3298. $ids = '';
  3299. foreach($rows as $k=>$rs){
  3300. if(!isset($rs['id']))return $rows;//没有id字段是无法判断
  3301. $ids.=','.$rs['id'].'';
  3302. }
  3303. $ids = substr($ids, 1);
  3304. foreach($jinkfarr as $k1=>$rs1){
  3305. $wherestr = arrvalue($rs1,'wherestr');
  3306. $wherestr2 = arrvalue($rs1,'wherestr2');
  3307. $fieldstr = arrvalue($rs1,'fieldstr');
  3308. if(isempt($fieldstr))continue;
  3309. if($wherestr=='' && $wherestr2=='')continue;
  3310. if($wherestr2!=''){
  3311. if($wherestr!='')$wherestr.=' and ';
  3312. $wherestr.=$wherestr2;
  3313. }
  3314. $wherestr= str_replace('{asqom}','', $wherestr);
  3315. $jinrows = $this->getall('`id` in('.$ids.') and '.$wherestr.'','id');
  3316. if(!$jinrows)continue;
  3317. $jinrow = array();
  3318. foreach($jinrows as $k2=>$rs2)$jinrow[]=$rs2['id'];
  3319. $jinkfarr[$k1]['jinrows'] = $jinrow;
  3320. }
  3321. //隐藏字段设置
  3322. foreach($rows as $k=>$rs){
  3323. $id = $rs['id'];
  3324. if(arrvalue($rs, $this->flowviewufieds)==$this->adminid)continue;//我自己都可以看
  3325. foreach($jinkfarr as $k1=>$rs1){
  3326. $fieldstr = arrvalue($rs1,'fieldstr');
  3327. $jinrows = arrvalue($rs1,'jinrows');
  3328. if($jinrows){
  3329. $farr = explode(',', $fieldstr);
  3330. if(in_array($id, $jinrows)){
  3331. foreach($farr as $fid){
  3332. if(isset($rs[$fid]))$rows[$k][$fid]='';//清空
  3333. }
  3334. }
  3335. }
  3336. }
  3337. }
  3338. }
  3339. //--autharend--
  3340. return $rows;
  3341. }
  3342. /**
  3343. * 判断是否导出子表处理
  3344. */
  3345. public function daochusubtable($rows)
  3346. {
  3347. //--autharstart--
  3348. if(!$this->daochubo || !$rows)return $rows;
  3349. $excelsubtab = $this->rock->post('excelsubtab');
  3350. if(isempt($excelsubtab) || isempt($this->moders['tables']))return $rows;
  3351. $suba = explode(',', $excelsubtab);
  3352. foreach($rows as $k=>$rs){
  3353. if(!isset($rs['id']))return $rows;
  3354. $subdata = $this->getsuballdata(1, $rs['id']);
  3355. foreach($suba as $zb){
  3356. $shuju = $subdata[$zb]['data'];
  3357. if($shuju){
  3358. $this->subsubdatastyle = 'print';
  3359. $rows[$k]['sub_table_'.$zb.''] = $this->getsubdata($zb, $shuju);
  3360. }else{
  3361. $rows[$k]['sub_table_'.$zb.''] = '';
  3362. }
  3363. }
  3364. }
  3365. //--autharend--
  3366. return $rows;
  3367. }
  3368. }