flow.php 121 KB

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