flow.php 123 KB

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