Database.php 200 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175
  1. <?php
  2. # 此类很大,以后优化,放到Database目录中,拆分为工厂模式
  3. # 必须要优化了...当时为了快速实现直接扔这一个里面了,近期优化
  4. namespace Manage\Src;
  5. use Dever;
  6. use Manage\Src\Lib\Input as Html;
  7. use Manage\Src\Lib\Log;
  8. class Database
  9. {
  10. /**
  11. * project
  12. *
  13. * @var string
  14. */
  15. private $project;
  16. /**
  17. * table
  18. *
  19. * @var string
  20. */
  21. private $table;
  22. /**
  23. * menu
  24. *
  25. * @var string
  26. */
  27. private $menu;
  28. /**
  29. * menu_id
  30. *
  31. * @var string
  32. */
  33. private $menu_id;
  34. /**
  35. * id
  36. *
  37. * @var string
  38. */
  39. private $id;
  40. /**
  41. * config
  42. *
  43. * @var array
  44. */
  45. private $config;
  46. /**
  47. * search
  48. *
  49. * @var bool
  50. */
  51. private $search = false;
  52. /**
  53. * chart
  54. *
  55. * @var array
  56. */
  57. private $chart = false;
  58. /**
  59. * manage_button
  60. *
  61. * @var array
  62. */
  63. private $manage_button = false;
  64. /**
  65. * info
  66. *
  67. * @var array
  68. */
  69. private $info = array();
  70. /**
  71. * state
  72. *
  73. * @var array
  74. */
  75. private $state = false;
  76. /**
  77. * lang_set
  78. *
  79. * @var array
  80. */
  81. private $lang_set = false;
  82. /**
  83. * __construct
  84. *
  85. * @return mixed
  86. */
  87. public function __construct()
  88. {
  89. $this->setting();
  90. $this->top = Dever::input('top');
  91. if ($this->top) {
  92. Dever::load('manage/top.update_action', $this->top);
  93. }
  94. $this->lang_set = Dever::config('base')->lang_set && count(Dever::config('base')->lang_set) > 1;
  95. }
  96. public function setting()
  97. {
  98. $this->project = Dever::input('project');
  99. $this->table = Dever::input('table');
  100. $this->menu = Dever::input('menu');
  101. $this->menu_id = Dever::input('menu_id');
  102. $this->id = Dever::input('update_where_id', Dever::input('where_id'));
  103. $this->name = $this->project . '/' . $this->table;
  104. return $this;
  105. }
  106. /**
  107. * 提供给异步获取数据的接口
  108. *
  109. * @return array
  110. */
  111. public function getAjax($data)
  112. {
  113. $key = Dever::input('key');
  114. $value = Dever::input('value');
  115. $source = Dever::input('source');
  116. $config = Dever::db($source)->config['struct'][$key];
  117. $config['value'] = $value;
  118. $config['option'] = $data;
  119. return $this->create_update_html($key, $config);
  120. }
  121. /**
  122. * url
  123. *
  124. * @return array
  125. */
  126. public function url($key = false, $id = 0, $table = false, $suffix = '', $project = '', $param = array())
  127. {
  128. $table = $table ? $table : $this->table;
  129. if (strpos($table, 'http://') !== false || strpos($table, 'javascript') !== false) {
  130. return $table;
  131. }
  132. if ($id) {
  133. $id = '&where_id=' . $id;
  134. }
  135. $config = array
  136. (
  137. 'project' => 'project/database?project=' . $this->project,
  138. 'list' => 'project/database/list?{param}',
  139. 'search' => 'project/database/list?{param}',
  140. 'add' => 'project/database/update?{param}',
  141. 'update' => 'project/database/update?{param}' . $id,
  142. # 增加快捷更新
  143. 'edit' => 'project/database/update?{param}' . $id,
  144. 'updateAction' => 'database.update_action',
  145. 'url' => '',
  146. 'delete' => 'database.delete_action?{param}' . $id,
  147. 'recovery' => 'database.recovery_action?{param}' . $id,
  148. 'stat' => 'project/database/stat?{param}',
  149. 'excel' => 'database.list_excel?{param}',
  150. 'stat_excel' => 'database.stat_excel?{param}',
  151. 'reset' => 'project/database/list?project=' . $this->project . '&table=' . $table . '&menu=' . $this->menu . '&menu_id=' . $this->menu_id,
  152. 'diy' => 'list?{param}',
  153. );
  154. $state = $this->getState();
  155. if ($key == 'delete' && $state == 2) {
  156. $key = 'recovery';
  157. }
  158. if (strpos($key, 'list') !== false) {
  159. $config[$key] = $config['list'];
  160. } elseif (strpos($key, 'add') !== false) {
  161. $config[$key] = $config['add'];
  162. } elseif (strpos($key, 'edit') !== false) {
  163. $config[$key] = $config['edit'];
  164. }
  165. if (isset($config[$key])) {
  166. if (strpos($config[$key], '{param}')) {
  167. $param = $this->getUrlParam($key, $table, $suffix, $state, $project, $param);
  168. $config[$key] = str_replace('{param}', $param, $config[$key]);
  169. }
  170. return Dever::url($config[$key]);
  171. }
  172. return $config;
  173. }
  174. /**
  175. * 获取url需要的参数
  176. *
  177. * @return string
  178. */
  179. private function getUrlParam($key, $table, $suffix, $state, $project = '', $input = array())
  180. {
  181. $index = md5($key . '_' . $project . '_' . $table . '_' . $suffix . '_' . http_build_query($input));
  182. if (isset($this->param[$index])) {
  183. //return $this->param[$index];
  184. }
  185. $param = '';
  186. $array = array('project', 'search', 'add', 'list', 'update', 'edit');
  187. //if (in_array($key, $array) && !strstr($table, 'oper_')) {
  188. if (!strstr($table, 'oper_')) {
  189. $where = Dever::preInput('search_', $input);
  190. if ($where) {
  191. if (isset($where['where_id'])) {
  192. //unset($where['where_id']);
  193. }
  194. unset($where['search_option_state']);
  195. $param .= '&' . http_build_query($where);
  196. }
  197. $oper = Dever::preInput('send_', $input);
  198. if ($oper) {
  199. $param .= '&' . http_build_query($oper);
  200. }
  201. if ($key != 'listData') {
  202. $oper = Dever::preInput('oper_', $input);
  203. if ($oper) {
  204. $param .= '&' . http_build_query($oper);
  205. }
  206. }
  207. $top = Dever::preInput('top_', $input);
  208. if ($top) {
  209. $param .= '&' . http_build_query($top);
  210. }
  211. }
  212. if ($key == 'search' && $search_limit = Dever::input('search_limit')) {
  213. $param .= '&search_limit=' . $search_limit;
  214. }
  215. if (strpos($suffix, 'search_option_state') !== false) {
  216. $state = '';
  217. } else {
  218. $state = '&search_option_state=' . $state;
  219. }
  220. $page_type = Dever::input('page_type');
  221. if ($page_type) {
  222. $param .= '&page_type=' . $page_type . '';
  223. }
  224. /*
  225. $where_id = Dever::input('where_id');
  226. if ($where_id) {
  227. $param .= '&where_id=' . $where_id . '';
  228. }
  229. */
  230. $menu_id = Dever::input('menu_id');
  231. if ($menu_id && !strstr($param, 'menu_id')) {
  232. $param .= '&menu_id=' . $menu_id . '';
  233. }
  234. if (!$project) {
  235. if ($key == 'add' || $key == 'update' || $key == 'delete' || $key == 'recovery') {
  236. $project = $this->project;
  237. } else {
  238. $project = Dever::input('oper_project', $this->project);
  239. }
  240. }
  241. $param = 'project=' . $project . $param . '&table=' . $table . '&menu=' . $this->menu . '&menu_id=' . $this->menu_id . $state . $suffix;
  242. //echo $key . "\r\n";
  243. //echo $param ."\r\n";
  244. $this->param[$index] = $param;
  245. return $param;
  246. }
  247. /**
  248. * 获得refer
  249. *
  250. * @return string
  251. */
  252. private function refer($type = 'project')
  253. {
  254. return '';
  255. switch ($type) {
  256. case 'project':
  257. $name = '数据库操作';
  258. break;
  259. case 'list':
  260. $name = '数据列表';
  261. break;
  262. case 'url':
  263. $name = '项目列表';
  264. break;
  265. }
  266. $name = '返回上一级';
  267. $url = $this->url($type);
  268. $refer = '-[<a href="' . $url . '">' . $name . '</a>]';
  269. return $refer;
  270. }
  271. /**
  272. * getAdminInfo
  273. *
  274. * @return array
  275. */
  276. private function getAdminInfo($data)
  277. {
  278. $admin = Dever::load('manage/auth.info');
  279. $data['my_admin_id'] = $admin['id'];
  280. $data['my_role_id'] = $admin['role'];
  281. return $data;
  282. }
  283. /**
  284. * cookie 处理cookie
  285. *
  286. * @return array
  287. */
  288. public function cookie()
  289. {
  290. $cookie = $_COOKIE;
  291. $array = array();
  292. # 判断手机版
  293. $mobile = Dever::mobile();
  294. if ((isset($cookie['left_menu']) && $cookie['left_menu'] == 'close') || $mobile) {
  295. $array['wrapper'] = 'enlarged forced';
  296. } else {
  297. $array['wrapper'] = 'forced';
  298. }
  299. return $array;
  300. }
  301. /**
  302. * listStyle
  303. *
  304. * @return array
  305. */
  306. public function listStyle()
  307. {
  308. $mobile = Dever::mobile();
  309. if ($mobile) {
  310. $style = '.container_list .panel-heading .form-control,#mul .form-control,#page .form-control
  311. {
  312. width:70%;
  313. }
  314. .row
  315. {
  316. margin-right: -15px;
  317. margin-left: -15px;
  318. }
  319. #dever_modal_body img
  320. {
  321. max-width:300px;
  322. }
  323. ';
  324. } else {
  325. $style = '#dever_modal_body img
  326. {
  327. max-width:300px;
  328. }';
  329. }
  330. return $style;
  331. }
  332. /**
  333. * info 处理一些基本的信息,供模板使用
  334. *
  335. * @return array
  336. */
  337. public function info()
  338. {
  339. if ($this->info) {
  340. return $this->info;
  341. }
  342. $config = $this->config();
  343. $menu = isset($config['lang']) ? $config['lang'] : $this->project . '-' . $this->table;
  344. if (isset($config['state']) && $config['state'] == 2) {
  345. $menu .= '[回收站]';
  346. }
  347. $top = Dever::load('manage/top.get');
  348. //print_r($top);die;
  349. $this->info = array
  350. (
  351. 'action' => $this->url('updateAction'),
  352. 'list' => $this->url('list'),
  353. 'search' => $this->url('search'),
  354. 'mul' => $this->url('list'),
  355. //'add' => 'location.href=\'' . $this->url('add') . '\'',
  356. 'add' => $this->url('add'),
  357. 'state' => $this->getState(),
  358. 'l' => 'project/database/list',
  359. 'project' => $this->project,
  360. 'table' => $this->table,
  361. 'menu' => $this->menu,
  362. 'menu_id' => $this->menu_id,
  363. 'id' => $this->id,
  364. 'main' => '数据管理' . $this->refer('url'),
  365. 'list_header' => $menu,
  366. 'list_desc' => '数据列表',
  367. 'project_name' => Dever::load('manage/project.name', $this->project),
  368. 'update_header' => $menu,
  369. 'update_desc' => '更新数据',
  370. 'updateMul' => (!$this->id && isset($config['manage']['updateMul']) && $config['manage']['updateMul']) ? '增加一条' : false,
  371. 'updateDesc' => isset($config['manage']['desc']) ? $config['manage']['desc'] : '',
  372. 'listInfo' => isset($config['info']) ? $config['info'] : '',
  373. 'listDesc' => isset($config['desc']) ? $config['desc'] : '',
  374. 'struct' => isset($config['manage']['struct']) ? $config['manage']['struct'] : '',
  375. 'stat_desc' => '主动统计',
  376. 'search_param' => '',
  377. );
  378. # 此处为了兼容旧版本的一些设置
  379. $this->info['parent'] = Dever::input('oper_table', Dever::input('oper_parent'));
  380. # 返回上一页
  381. if ($this->info['parent']) {
  382. $oper = Dever::preInput('oper_');
  383. if ($oper) {
  384. $this->info['parent'] .= '&' . str_replace('oper_', '', http_build_query($oper));
  385. }
  386. $search = Dever::preInput('search_');
  387. if ($search) {
  388. $this->info['parent'] .= '&' . http_build_query($search);
  389. }
  390. $send = Dever::preInput('send_');
  391. if ($send) {
  392. $this->info['parent'] .= '&' . http_build_query($send);
  393. }
  394. $top = Dever::preInput('top_');
  395. if ($top) {
  396. $top_query = http_build_query($top);
  397. if (strstr($top_query, '.')) {
  398. foreach ($top as $k => $v) {
  399. $temp = explode('.', $v);
  400. $k = str_replace('top_', '', $k);
  401. $this->info['parent'] .= '&oper_' . $k . '=' . $temp[0];
  402. if (isset($temp[1])) {
  403. $this->info['parent'] .= '&top_' . $k . '=' . $temp[1];
  404. }
  405. }
  406. } else {
  407. $this->info['parent'] .= '&' . str_replace('top_', 'oper_', $top_query);
  408. }
  409. }
  410. $this->info['parent_project'] = Dever::input('oper_project');
  411. $this->info['parent'] = $this->url(Dever::input('oper_index', 'listData'), 0, $this->info['parent'], '', $this->info['parent_project']);
  412. }
  413. # 保存页面
  414. $this->info['save'] = Dever::input('oper_save_table', Dever::input('oper_save_jump'));
  415. if ($this->info['save']) {
  416. $this->info['save_project'] = Dever::input('oper_save_project');
  417. $this->info['list'] = $this->url(Dever::input('oper_index', 'list'), 0, $this->info['save'], '', $this->info['save_project']);
  418. }
  419. $search = Dever::preInput('search_');
  420. if ($search) {
  421. $this->info['mul'] .= '&' . http_build_query($search);
  422. if (layadmin()) {
  423. foreach ($search as $k => $v) {
  424. if (!strstr($k, 'search_option_')) {
  425. if (is_array($v)) {
  426. $v = implode(',', $v);
  427. }
  428. $this->info['search_param'] .= '<input type="hidden" name="'.$k.'" value="'.$v.'"/>';
  429. }
  430. }
  431. }
  432. }
  433. if ($this->id) {
  434. $this->info['update_header'] = $menu . '-更新数据' . $this->refer('list');
  435. }
  436. return $this->info;
  437. }
  438. /**
  439. * 获取表名
  440. *
  441. * @return array
  442. */
  443. public function getTableName($project, $table)
  444. {
  445. if ($project == 'other') {
  446. return '无数据表';
  447. }
  448. $path = Dever::load('manage/project.path', $project);
  449. $config = $this->config($project, $path, $table);
  450. $data = isset($config['lang']) ? $config['lang'] : $project;
  451. return $data;
  452. }
  453. private function getState()
  454. {
  455. return Dever::input('search_option_state', 1);
  456. }
  457. /**
  458. * config
  459. *
  460. * @return array
  461. */
  462. public function config($project = false, $path = false, $table = false)
  463. {
  464. if (!$project) {
  465. $project = $this->project;
  466. $table = $this->table;
  467. }
  468. if (!$project) {
  469. return array();
  470. }
  471. Dever::$global['manage']['project'] = $project;
  472. $config = Dever::load('manage/project.config', $project);
  473. if (!is_array($config)) {
  474. Dever::alert($project . ' error');
  475. }
  476. $project = $config['name'];
  477. if (!$path) {
  478. if (isset($config['base']) && isset($config['rel'])) {
  479. $path = DEVER_INCLUDE_PATH . $config['rel'];
  480. } else {
  481. $path = $config['path'];
  482. }
  483. }
  484. if ($project && $path && empty($this->config[$path])) {
  485. $this->config[$path] = array();
  486. $dir = $path . 'database/';
  487. if (is_dir($dir)) {
  488. $database = scandir($dir);
  489. foreach ($database as $k => $v) {
  490. if (strpos($v, '.php') !== false) {
  491. $k = str_replace('.php', '', $v);
  492. $this->config[$path][$k] = $this->struct($dir . $v, $project);
  493. }
  494. }
  495. }
  496. }
  497. if (isset($this->config[$path][$table])) {
  498. return $this->config[$path][$table];
  499. }
  500. return $this->config[$path];
  501. }
  502. # 得到重写的配置
  503. public function getConfig()
  504. {
  505. $config = $this->config();
  506. if (!isset($config['info'])) {
  507. $config['info'] = '';
  508. }
  509. if (!isset($config['desc'])) {
  510. $config['desc'] = '';
  511. }
  512. $manage = Dever::config('base')->manage;
  513. if ($manage) {
  514. if (isset($manage['info'])) {
  515. $config['info'] = $manage['info'];
  516. }
  517. if (isset($manage['desc'])) {
  518. $config['desc'] = $manage['desc'];
  519. }
  520. }
  521. return $config;
  522. }
  523. /**
  524. * 对database配置文件进行解析
  525. *
  526. * @return array
  527. */
  528. private function struct($file, $project = false)
  529. {
  530. $config = include $file;
  531. if (isset($config['struct']) && is_array($config['struct']['id'])) {
  532. $config['update'] = false;
  533. $config['manage']['struct'] = '<table border=1 width=100% height=100%>';
  534. $config['level'] = 1;
  535. foreach ($config['struct'] as $k => $v) {
  536. if (isset($v['level'])) {
  537. $config['level'] = 3;
  538. }
  539. if (isset($v['search_parent'])) {
  540. $config['manage']['search_parent'][$v['search_parent']] = $k;
  541. $config['manage']['search_child'][$k] = $v['search_parent'];
  542. }
  543. if (!isset($config['search'])) {
  544. if (isset($v['search']) && is_string($v['search'])) {
  545. if ($v['search'] == 'sday') {
  546. $config['manage']['search']['sday'][$k]['key'] = $v['search'];
  547. $config['manage']['search']['sday'][$k]['lang'] = $v['name'];
  548. } elseif ($v['search'] == 'sdate') {
  549. $config['manage']['search']['sdate'][$k]['key'] = $v['search'];
  550. $config['manage']['search']['sdate'][$k]['lang'] = $v['name'];
  551. } elseif (strpos($v['search'], 'time') !== false || strpos($v['search'], 'day') !== false) {
  552. $config['manage']['search']['day'][$k]['key'] = $v['search'];
  553. $config['manage']['search']['day'][$k]['lang'] = $v['name'];
  554. } elseif (strpos($v['search'], 'date') !== false) {
  555. $config['manage']['search']['date'][$k]['key'] = $v['search'];
  556. $config['manage']['search']['date'][$k]['lang'] = $v['name'];
  557. } elseif (strpos($v['search'], 'year') !== false) {
  558. $config['manage']['search']['year'][$k]['key'] = $v['search'];
  559. $config['manage']['search']['year'][$k]['lang'] = $v['name'];
  560. } elseif (strpos($v['search'], 'month') !== false) {
  561. $config['manage']['search']['month'][$k]['key'] = $v['search'];
  562. $config['manage']['search']['month'][$k]['lang'] = $v['name'];
  563. }
  564. if (strpos($v['search'], 'exp') !== false) {
  565. $config['manage']['search']['exp'][$k] = $v['name'];
  566. }
  567. if (strpos($v['search'], 'ins') !== false) {
  568. $config['manage']['search']['ins'][$k] = $v['name'];
  569. }
  570. if (strpos($v['search'], 'fulltext') !== false) {
  571. $config['manage']['search']['fulltext'][$k] = $v['name'];
  572. isset($v['match']) && $config['request']['list']['option'][$k] = array('option', 'like_score');
  573. } elseif (strpos($v['search'], 'text') !== false) {
  574. $config['manage']['search']['text'][$k] = $v['name'];
  575. } elseif (strpos($v['search'], 'hidden') !== false) {
  576. $config['manage']['search']['hidden'][$k] = $v['name'];
  577. }
  578. if (isset($v['exist']) && strpos($v['search'], 'exist') !== false) {
  579. $config['manage']['search']['exist'][$k]['option'] = $v['exist'];
  580. $config['manage']['search']['exist'][$k]['lang'] = $v['name'];
  581. }
  582. if (isset($v['option']) && strpos($v['search'], 'selects') !== false) {
  583. $config['manage']['search']['selects'][$k]['option'] = $v['option'];
  584. $config['manage']['search']['selects'][$k]['lang'] = $v['name'];
  585. if (isset($v['default'])) {
  586. $config['manage']['search']['selects'][$k]['default'] = $v['default'];
  587. }
  588. } elseif (isset($v['option']) && strpos($v['search'], 'select') !== false) {
  589. $config['manage']['search']['select'][$k]['option'] = $v['option'];
  590. $config['manage']['search']['select'][$k]['lang'] = $v['name'];
  591. if (isset($v['default'])) {
  592. $config['manage']['search']['select'][$k]['default'] = $v['default'];
  593. }
  594. }
  595. if (isset($v['option']) && strpos($v['search'], 'group') !== false) {
  596. $config['manage']['search']['group'][$k]['option'] = $v['option'];
  597. $config['manage']['search']['group'][$k]['lang'] = $v['name'];
  598. if (isset($v['default'])) {
  599. $config['manage']['search']['group'][$k]['default'] = $v['default'];
  600. }
  601. }
  602. if (isset($v['option']) && strpos($v['search'], 'linkage') !== false) {
  603. $config['manage']['search']['linkage'][$k]['option'] = $v['option'];
  604. $config['manage']['search']['linkage'][$k]['lang'] = $v['name'];
  605. if (isset($v['default'])) {
  606. $config['manage']['search']['linkage'][$k]['default'] = $v['default'];
  607. }
  608. }
  609. } elseif (isset($v['search']) && is_array($v['search'])) {
  610. if (isset($v['search']['api'])) {
  611. $config['manage']['search']['api'][$k] = $v['search'];
  612. $config['manage']['search']['api'][$k]['lang'] = $v['name'];
  613. }
  614. }
  615. if (isset($v['search_button'])) {
  616. $config['manage']['search']['button'][$k] = $v['search_button'];
  617. }
  618. }
  619. /*
  620. if (isset($v['table']) && !isset($config['end'])) {
  621. $config['end']['insert'] = $v['value'];
  622. }
  623. */
  624. if (isset($v['update'])) {
  625. if (!isset($config['manage']['insert'])) {
  626. $config['manage']['insert'] = true;
  627. }
  628. $config['update'] = true;
  629. }
  630. if (isset($v['type'])) {
  631. $config['manage']['struct'] .= Dever::tbody(array($k, $v['type'], $v['name']));
  632. }
  633. }
  634. $config['manage']['struct'] .= '</table>';
  635. $config['manage']['_list'] = array
  636. (
  637. 'col' => 'manage',
  638. 'name' => '管理',
  639. 'value' => array(),
  640. );
  641. if (!isset($config['manage']['edit']) || (isset($config['manage']['edit']) && $config['manage']['edit'] == true)) {
  642. if (!isset($config['manage']['list_button']['update'])) {
  643. $config['manage']['_list']['value']['update'] = '编辑';
  644. }
  645. }
  646. if (isset($config['manage']['list'][0]) && is_array($config['manage']['list'][0])) {
  647. $config['manage']['_list']['value'] += $config['manage']['list'][0];
  648. unset($config['manage']['list'][0]);
  649. } elseif (isset($config['manage']['list_button'])) {
  650. $config['manage']['_list']['value'] += $config['manage']['list_button'];
  651. }
  652. if (!isset($config['manage']['delete']) || (isset($config['manage']['delete']) && $config['manage']['delete'] == true)) {
  653. if (!isset($config['manage']['list_button']['delete'])) {
  654. $config['manage']['_list']['value']['delete'] = '删除';
  655. }
  656. }
  657. if (!$config['manage']['_list']['value']) {
  658. unset($config['manage']['_list']);
  659. }
  660. if (isset($config['manage']['list_type'])) {
  661. $config['manage']['list_table'] = 'html';
  662. }
  663. # 新增排序
  664. $l = isset($_GET['l']) ? $_GET['l'] : '';
  665. if ($l == 'project/database/list' || $l == 'database.list_excel') {
  666. $list_order = array();
  667. $i = 0;
  668. foreach ($config['struct'] as $ki => $vi) {
  669. if (isset($vi['list_order'])) {
  670. $list_order[] = $vi['list_order'];
  671. } else {
  672. $config['struct'][$ki]['list_order'] = $i;
  673. $list_order[] = $i;
  674. }
  675. $i++;
  676. }
  677. if ($list_order) {
  678. array_multisort($list_order, SORT_ASC, SORT_NUMERIC, $config['struct']);
  679. }
  680. }
  681. } else {
  682. echo $file;die;
  683. }
  684. $config['state'] = $this->getState();
  685. $config['project'] = $project;
  686. return $config;
  687. }
  688. /**
  689. * 自定义列表页面
  690. *
  691. * @return array
  692. */
  693. public function page($key = 'list')
  694. {
  695. $key = Dever::input('page_value', $key);
  696. $type = Dever::input('page_type', 1);
  697. $config = $this->config();
  698. $result = array();
  699. $result['s1'] = 'display:none';
  700. $result['s2'] = 'display:';
  701. $result['content'] = '';
  702. $key = 'page_' . $key;
  703. if (isset($config['manage'][$key]) && $type == 1) {
  704. if ($config['manage'][$key] == 'photo' && isset($config['manage']['photo'])) {
  705. $result['content'] = Dever::view('list/photo', false, 'manage');
  706. } else {
  707. $result['content'] = Dever::view($config['manage'][$key], 'manage', $this->project);
  708. }
  709. //echo $result['content'];die;
  710. if ($result['content']) {
  711. Dever::setInput('page_content', 1);
  712. $result['s1'] = 'display:';
  713. $result['s2'] = 'display:none';
  714. # 添加底部
  715. if ($key != 'page_list_table') {
  716. $result['content'] .= Dever::view('inc/foot', false, 'manage');
  717. }
  718. }
  719. } elseif (strstr($key, 'list_table')) {
  720. Dever::setInput('page_type', 2);
  721. }
  722. return $result;
  723. }
  724. /**
  725. * 自定义列表页面
  726. *
  727. * @return array
  728. */
  729. public function page_list()
  730. {
  731. return $this->page('list');
  732. }
  733. /**
  734. * 自定义列表页面 只接管table部分,同时必须传值page_type=1
  735. *
  736. * @return array
  737. */
  738. public function page_list_table()
  739. {
  740. $type = Dever::input('page_type', 2);
  741. if ($type == 1) {
  742. return $this->page('list_table');
  743. } else {
  744. return $this->page('list_table_default');
  745. }
  746. }
  747. /**
  748. * 自定义列表页面
  749. *
  750. * @return array
  751. */
  752. public function page_update()
  753. {
  754. return $this->page('update');
  755. }
  756. /**
  757. * 载入自定义资源
  758. *
  759. * @return array
  760. */
  761. public function res()
  762. {
  763. $result = array
  764. (
  765. 'js' => '',
  766. 'css' => '',
  767. );
  768. if (!$this->project) {
  769. return $result;
  770. }
  771. $config = $this->config();
  772. if (isset($config['manage']['res'])) {
  773. foreach ($config['manage']['res'] as $k => $v) {
  774. $result[$k] = $this->getRes($k, $v);
  775. }
  776. }
  777. return $result;
  778. }
  779. /**
  780. * 载入默认样式
  781. *
  782. * @return array
  783. */
  784. public function css()
  785. {
  786. $css = '';
  787. $fast = Dever::input('fast');
  788. if ($fast == 1) {
  789. $css = '.layui-input,.xm-select-parent
  790. {
  791. width: 100%;
  792. }';
  793. } else {
  794. $css = '.layui-input,.xm-select-parent
  795. {
  796. width: 50%;
  797. }
  798. @media screen and (max-width: 1024px) {
  799. .layui-input,.xm-select-parent
  800. {
  801. width: 90%;
  802. }
  803. }';
  804. }
  805. return $css;
  806. }
  807. /**
  808. * getRes
  809. *
  810. * @return string
  811. */
  812. protected function getRes($path, $value)
  813. {
  814. if (is_array($value)) {
  815. $res = '';
  816. foreach ($value as $k => $v) {
  817. $res .= $this->getRes($path, $v);
  818. }
  819. return $res;
  820. } else {
  821. if ($this->project != 'manage') {
  822. $base = str_replace('assets/', 'assets/manage/', Dever::config('host', $this->project)->$path);
  823. } else {
  824. $base = Dever::config('host', $this->project)->$path;
  825. }
  826. $file = $base . $value . '.' . $path;
  827. if ($path == 'js') {
  828. $res = '<script type="text/javascript" src="'.$file.'"></script>';
  829. } else {
  830. $res = '<link rel="stylesheet" type="text/css" href="'.$file.'">
  831. ';
  832. }
  833. return $res;
  834. }
  835. }
  836. /**
  837. * 头部banner
  838. *
  839. * @return array
  840. */
  841. public function banner()
  842. {
  843. if (!$this->project) {
  844. return '';
  845. }
  846. $config = $this->config();
  847. $result = '';
  848. if (isset($config['manage']['banner'])) {
  849. foreach ($config['manage']['banner'] as $k => $v) {
  850. $config['manage']['banner'][$k] = $this->value($v, 'yes');
  851. }
  852. if (empty($config['manage']['banner']['link'])) {
  853. $config['manage']['banner']['link'] = '#';
  854. $config['manage']['banner']['target'] = '_self';
  855. }
  856. if (empty($config['manage']['banner']['target'])) {
  857. $config['manage']['banner']['target'] = '_blank';
  858. }
  859. $result = '<a target="' . $config['manage']['banner']['target'] . '" href="' . $config['manage']['banner']['link'] . '"><img src="' . $config['manage']['banner']['img'] . '"></a>
  860. <span>' . $config['manage']['banner']['name'] . '</span>';
  861. }
  862. return $result;
  863. }
  864. /**
  865. * 列表页搜索
  866. *
  867. * @return array
  868. */
  869. public function list_search_select(&$result, $search, $name, $lang, $option, $default = false, $bind = array(), $parent = '', $mul = false)
  870. {
  871. $value = array();
  872. if (strpos($lang, '-')) {
  873. $temp = explode('-', $lang);
  874. $lang = $temp[0];
  875. }
  876. $value['name'] = $name;
  877. $value['lang'] = $lang;
  878. $value['option'] = $option;
  879. if (isset($search[$name])) {
  880. $value['value'] = $search[$name];
  881. }
  882. if ($default) {
  883. //$value['default'] = $default;
  884. }
  885. if ($bind) {
  886. $value['bind'] = $bind;
  887. }
  888. $value['parent'] = $parent;
  889. if ($mul) {
  890. $value['update'] = 'selects';
  891. $value['match'] = 'option';
  892. }
  893. $result .= Html::select($value, false);
  894. }
  895. /**
  896. * 列表页搜索
  897. *
  898. * @return array
  899. */
  900. public function list_search_group(&$result, $search, $name, $lang, $option, $default = false)
  901. {
  902. $value = array();
  903. $value['name'] = $name;
  904. $value['lang'] = $lang;
  905. $value['option'] = $option;
  906. if (isset($search[$name])) {
  907. $value['value'] = $search[$name];
  908. }
  909. if ($default) {
  910. //$value['default'] = $default;
  911. }
  912. $result .= Html::group($value, false);
  913. }
  914. /**
  915. * 列表页搜索
  916. *
  917. * @return array
  918. */
  919. public function list_search_linkage(&$result, $search, $name, $lang, $option, $default = false)
  920. {
  921. $value = array();
  922. $value['name'] = $name;
  923. $value['lang'] = $lang;
  924. $value['option'] = $option;
  925. $value['search_state'] = true;
  926. if (isset($search[$name])) {
  927. $value['value'] = $search[$name];
  928. }
  929. if ($default) {
  930. //$value['default'] = $default;
  931. }
  932. $result .= Html::linkage($value, 'span');
  933. }
  934. /**
  935. * 列表页搜索
  936. *
  937. * @return array
  938. */
  939. public function list_search_time(&$result, $search, $prefix, $key, $config, $type = 'time')
  940. {
  941. $start = $end = true;
  942. $eq = $eqs = false;
  943. if (is_array($config)) {
  944. $lang = $config['lang'];
  945. $search_key = $config['key'];
  946. if (strstr($search_key, '_')) {
  947. $temp = explode('_', $search_key);
  948. $start = $end = false;
  949. if (isset($temp[1])) {
  950. if ($temp[1] == 'start') {
  951. $start = true;
  952. } elseif ($temp[1] == 'end') {
  953. $end = true;
  954. } elseif ($temp[1] == 'eq') {
  955. $eq = true;
  956. } elseif ($temp[1] == 'eqs') {
  957. $eqs = true;
  958. }
  959. }
  960. }
  961. } else {
  962. $lang = $config;
  963. }
  964. if ($eqs) {
  965. $value['name'] = $prefix . 'option_' . $key;
  966. Dever::setInput($value['name'], '', 'search_');
  967. $value['lang'] = $lang;
  968. if (isset($search[$value['name']]) && $search[$value['name']]) {
  969. $value['value'] = Dever::maketime($search[$value['name']]);
  970. $start_value = $end_value = $value['value'];
  971. if ($type == 'time' || $type == 'day' || $type == 'date') {
  972. $start_value = Dever::maketime($search[$value['name']] . ' 00:00:00');
  973. $end_value = Dever::maketime($search[$value['name']] . ' 23:59:59');
  974. } elseif ($type == 'month') {
  975. $start_value = Dever::maketime($search[$value['name']] . '-01 00:00:00');
  976. $end_value = date('t', $start_value);
  977. $end_value = Dever::maketime($search[$value['name']] . '-'.$end_value.' 23:59:59');
  978. } elseif ($type == 'year') {
  979. $start_value = Dever::maketime($search[$value['name']] . '-01-01 00:00:00');
  980. $end_value = date('12-t', $start_value);
  981. $end_value = Dever::maketime($search[$value['name']] . '-'.$end_value.' 23:59:59');
  982. }
  983. Dever::setInput($prefix . 'option_start_' . $key, $start_value, 'search_');
  984. Dever::setInput($prefix . 'option_end_' . $key, $end_value, 'search_');
  985. }
  986. $result .= Html::$type($value, false);
  987. } elseif ($eq) {
  988. $value['name'] = $prefix . 'option_' . $key;
  989. $value['lang'] = $lang;
  990. if (isset($search[$value['name']]) && $search[$value['name']]) {
  991. $value['value'] = Dever::maketime($search[$value['name']]);
  992. Dever::setInput($value['name'], $value['value'], 'search_');
  993. }
  994. $result .= Html::$type($value, false);
  995. } else {
  996. if ($start) {
  997. $value['name'] = $prefix . 'option_start_' . $key;
  998. $value['lang'] = '>=' . $lang;
  999. if (isset($search[$value['name']]) && $search[$value['name']]) {
  1000. $value['value'] = Dever::maketime($search[$value['name']]);
  1001. Dever::setInput($value['name'], $value['value'], 'search_');
  1002. }
  1003. $result .= Html::$type($value, false);
  1004. }
  1005. if ($end) {
  1006. $value['name'] = $prefix . 'option_end_' . $key;
  1007. $value['lang'] = '<=' . $lang;
  1008. if (isset($search[$value['name']]) && $search[$value['name']]) {
  1009. $value['value'] = Dever::maketime($search[$value['name']]);
  1010. Dever::setInput($value['name'], $value['value'], 'search_');
  1011. }
  1012. $result .= Html::$type($value, false);
  1013. }
  1014. }
  1015. }
  1016. /**
  1017. * 列表页头部按钮
  1018. *
  1019. * @return array
  1020. */
  1021. public function list_button()
  1022. {
  1023. /*
  1024. if (Dever::load('manage/auth.oper', 2) == false) {
  1025. return '';
  1026. }
  1027. */
  1028. $button = array();
  1029. $config = $this->config();
  1030. $result = '';
  1031. # 增加返回上一页按钮
  1032. $info = $this->info();
  1033. if ($info['parent']) {
  1034. $parent_name = '返回上一页';
  1035. $parent_show = false;
  1036. if (isset($config['manage']['parent']) && $config['manage']['parent']) {
  1037. if (is_string($config['manage']['parent'])) {
  1038. $parent_name = $config['manage']['parent'];
  1039. }
  1040. $parent_show = true;
  1041. } elseif (!isset($config['manage']['parent'])) {
  1042. $parent_show = true;
  1043. }
  1044. if ($parent_show) {
  1045. $button[$parent_name] = $info['parent'];
  1046. }
  1047. }
  1048. if ($info['add']) {
  1049. $add_name = '新增';
  1050. $add_show = false;
  1051. if (isset($config['manage']['insert']) && $config['manage']['insert']) {
  1052. if (is_string($config['manage']['insert'])) {
  1053. $add_name = $config['manage']['insert'];
  1054. }
  1055. $add_show = true;
  1056. } elseif (!isset($config['manage']['insert'])) {
  1057. $add_show = true;
  1058. }
  1059. $insert_state = Dever::load('manage/auth.oper', 4);
  1060. if ($insert_state) {
  1061. if ($add_show) {
  1062. $button[$add_name] = $info['add'];
  1063. }
  1064. } elseif (isset($config['manage']['button']['新增'])) {
  1065. unset($config['manage']['button']['新增']);
  1066. }
  1067. }
  1068. # 增加主动统计按钮
  1069. if ($this->state && isset($config['manage']['stat'])) {
  1070. $name = '数据统计';
  1071. if (is_string($config['manage']['stat'])) {
  1072. $name = $config['manage']['stat'];
  1073. }
  1074. $button[$name] = $this->url('stat');
  1075. }
  1076. if (isset($config['manage']['button']) && $config['manage']['button']) {
  1077. $button += $config['manage']['button'];
  1078. }
  1079. # 增加下载报表按钮
  1080. if ($this->state && isset($config['manage']['excel']) && $config['manage']['excel']) {
  1081. $url = $this->url('excel');
  1082. if (is_array($config['manage']['excel'])) {
  1083. foreach ($config['manage']['excel'] as $k => $v) {
  1084. if (is_array($v)) {
  1085. $name = $v[0];
  1086. $u = $url . '&excel_name='.$v[1].'&excel_load=' . $v[2];
  1087. $button[$name] = 'onclick="jump(\''.$u.'\', \'#form1\')"';
  1088. } else {
  1089. $name = $v;
  1090. $button[$name] = 'onclick="jump(\''.$url.'\', \'#form1\')"';
  1091. }
  1092. }
  1093. } else {
  1094. $name = '导出数据';
  1095. if (is_string($config['manage']['excel']) && !strstr($config['manage']['excel'], '.')) {
  1096. $name = $config['manage']['excel'];
  1097. }
  1098. $button[$name] = 'onclick="jump(\''.$url.'\', \'#form1\')"';
  1099. }
  1100. }
  1101. # 增加回收站
  1102. if (Dever::load('manage/auth.oper', 5) != false && isset($config['struct']['state']) && (!isset($config['manage']['delete']) || (isset($config['manage']['delete']) && $config['manage']['delete'] && isset($config['manage']['_list']['value']['delete'])))) {
  1103. if ($config['state'] == 2) {
  1104. $button['返回数据列表'] = $this->url('list', 0, false, '&search_option_state=1', $this->project);
  1105. } else {
  1106. $button['回收站'] = $this->url('list', 0, false, '&search_option_state=2', $this->project);
  1107. }
  1108. }
  1109. # 列表页按钮
  1110. if ($button) {
  1111. $result .= $this->list_button_show($button);
  1112. }
  1113. /*
  1114. if (Dever::load('manage/auth.oper', 6) != false && isset($config['manage']['button'])) {
  1115. $result .= $this->list_button_show($config['manage']['button']);
  1116. }*/
  1117. return $result;
  1118. }
  1119. /**
  1120. * 更新页按钮
  1121. *
  1122. * @return array
  1123. */
  1124. public function update_button()
  1125. {
  1126. # 新增权限
  1127. /*
  1128. if (Dever::load('manage/auth.oper', 2) == false) {
  1129. Dever::alert('你没有权限');
  1130. }
  1131. */
  1132. $info = $this->info();
  1133. $result = '<button type="button" class="btn btn-primary save-data layui-btn layuiadmin-btn-list"><i class="fa fa-save"></i> 提交保存</button>
  1134. <a href="' . $info['list'] . '" class="btn btn-danger layui-btn layuiadmin-btn-list layui-btn-danger" onclicks="msg({status:1,msg:\'yes\'})">放弃保存</a>';
  1135. $config = $this->config();
  1136. if (isset($config['manage']['update_button']) && $config['manage']['update_button']) {
  1137. $result = '';
  1138. foreach ($config['manage']['update_button'] as $k => $v) {
  1139. if ($v == 'save-data') {
  1140. $result .= '<button type="button" class="btn btn-primary save-data layui-btn layuiadmin-btn-list"><i class="fa fa-save"></i> ' . $k . '</button>';
  1141. } elseif ($v == 'copy-data') {
  1142. $result .= '<a href="javascript:;" class="btn btn-danger layui-btn layuiadmin-btn-list layui-btn-danger" onclick="set_update(\'#copy_num\', 1);set_update(\'#update_where_id\', 0);submit_action();">' . $k . '</a>';
  1143. } elseif ($v == 'copy-datas') {
  1144. $result .= '<a href="javascript:;" class="btn btn-danger layui-btn layuiadmin-btn-list layui-btn-danger" onclick="copy_data($(this))">' . $k . '</a>';
  1145. } else {
  1146. $result .= '<a href="javascript:;" class="btn btn-danger layui-btn layuiadmin-btn-list layui-btn-danger" onclick="' . $v . '">' . $k . '</a>';
  1147. }
  1148. }
  1149. }
  1150. return $result;
  1151. }
  1152. private function list_button_show($button)
  1153. {
  1154. $result = '';
  1155. $refer = Dever::input('refer');
  1156. if ($refer) {
  1157. $button['返回上一页'] = array('location', Dever::decode($refer));
  1158. }
  1159. # 不显示哪个按钮
  1160. $manage = Dever::config('base')->manage;
  1161. foreach ($button as $k => $v) {
  1162. if ($manage && isset($manage['deleteButton']) && in_array($k, $manage['deleteButton'])) {
  1163. continue;
  1164. }
  1165. # 增加细分权限
  1166. /*
  1167. if (!Dever::load('manage/auth.check', $k, $this->menu_id)) {
  1168. continue;
  1169. }
  1170. */
  1171. if (is_array($v)) {
  1172. if ($v[0] == 'location') {
  1173. if ($v[1] == 'add') {
  1174. $url = $this->url('add');
  1175. } elseif ($v[1] == 'list') {
  1176. $url = $this->url('list');
  1177. } else {
  1178. $url = Dever::url($v[1]);
  1179. }
  1180. $result .= '&nbsp;&nbsp;<a class="btn btn-default layui-btn layuiadmin-btn-list" onclick="location.href=\''.$url.'\'">' . $k . '</a>';
  1181. } elseif ($v[0] == 'import') {
  1182. $result .= '&nbsp;&nbsp;<a href="javascript:;" class="btn btn-default layui-btn layuiadmin-btn-list" onclick="showAlert(\'' . $v[1] . '\')">' . $k . '</a>';
  1183. } elseif ($v[0] == 'excel' || $v[0] == 'search') {
  1184. $url = Dever::url($v[1]);
  1185. $result .= '&nbsp;&nbsp;<a class="btn btn-default layui-btn layuiadmin-btn-list" href="javascript:;" onclick="jump(\''.$url.'\', \'#form1\')">' . $k . '</a>';
  1186. } elseif ($v[0] == 'oper') {
  1187. $url = Dever::url($v[1]);
  1188. $content = '';
  1189. if (isset($v[2])) {
  1190. $content = $v[2];
  1191. }
  1192. $title = '';
  1193. if (isset($v[3])) {
  1194. $title = $v[3];
  1195. }
  1196. $url .= '&manage_log=update.' . $this->project . '.' . $this->table . '&manage_oper=' . $k;
  1197. $result .= '&nbsp;&nbsp;<a class="btn btn-default layui-btn layuiadmin-btn-list layui-btn-danger" href="javascript:;"onclick="load(\'' . $url . '\', \'' . $content . '\', \'' . $title . '\')">' . $k . '</a>';
  1198. } elseif ($v[0] == 'oper_mul') {
  1199. $url = Dever::url($v[1]);
  1200. if (!isset($v[2])) {
  1201. $v[2] = 1;
  1202. }
  1203. //$url .= '&manage_log=update.' . $this->project . '.' . $this->table . '&manage_oper=' . $k;
  1204. $result .= '&nbsp;&nbsp;<a class="btn btn-default layui-btn layuiadmin-btn-list layui-btn-danger" href="javascript:;" onclick="$(\'#form1\').attr(\'action\', \'' . $this->url('list') . '\');list_mul($(this), 1, \''.$url.'\')">' . $k . '</a>';
  1205. } elseif ($v[0] == 'show') {
  1206. $url = Dever::url($v[1]);
  1207. $submit = '';
  1208. if (isset($v[2])) {
  1209. $submit = Dever::url($v[2]);
  1210. }
  1211. $result .= '&nbsp;&nbsp;<a class="btn btn-default layui-btn layuiadmin-btn-list" onclick="loadPage(\''.$url.'\', \''.$k.'\',\''.$submit.'\')">' . $k . '</a>';
  1212. } elseif ($v[0] == 'fast') {
  1213. if (isset($v[2]) && $v[2]) {
  1214. $url = $this->url('add', $v[1], $v[2]);
  1215. } elseif (isset($v[1]) && $v[1]) {
  1216. $url = Dever::url($v[1]);
  1217. } else {
  1218. $url = $this->url('add');
  1219. }
  1220. $result .= '&nbsp;&nbsp;<a class="btn btn-default layui-btn layuiadmin-btn-list" href="javascript:;" onclick="fastEdit($(this),\''.$url.'\',\''.$k.'\', \'\')">' . $k . '</a>';
  1221. } elseif ($v[0] == 'fasts') {
  1222. $result .= '&nbsp;&nbsp;<a class="btn btn-default layui-btn layuiadmin-btn-list" href="javascript:;" onclick="fastEdit($(this),\''.$this->url('add').'\',\''.$k.'\', \'\', 1)">' . $k . '</a>';
  1223. } elseif ($v[0] == 'onclick') {
  1224. $result .= '&nbsp;&nbsp;<a href="javascript:;" class="btn btn-warning layui-btn layuiadmin-btn-list layui-btn-warm" onclick="' . $v[1] . '">' . $k . '</a>';
  1225. } else {
  1226. $result .= '&nbsp;&nbsp;<a class="btn btn-default layui-btn layuiadmin-btn-list" href="' . $this->url($v[0], false, $v[1]) . '">' . $k . '</a>';
  1227. }
  1228. } elseif (strpos($v, 'modal|') !== false) {
  1229. $t = explode('modal|', $v);
  1230. $result .= '&nbsp;&nbsp;<a href="javascript:;" class="btn btn-default layui-btn layuiadmin-btn-list" onclick="showAlert(\'' . $t[1] . '\')">' . $k . '</a>';
  1231. } elseif (strpos($v, '|') !== false) {
  1232. $t = explode('|', $v);
  1233. $result .= $t[0] . '&nbsp;&nbsp;<a href="javascript:;" class="btn btn-warning layui-btn layuiadmin-btn-list layui-btn-warm" ' . $t[1] . '>' . $k . '</a>';
  1234. } elseif (strpos($v, 'onclick') !== false) {
  1235. $result .= '&nbsp;&nbsp;<a href="javascript:;" class="btn btn-warning layui-btn layuiadmin-btn-list layui-btn-warm" ' . $v . '>' . $k . '</a>';
  1236. } elseif (strpos($v, 'http://') !== false || strpos($v, 'https://') !== false) {
  1237. //$result .= '&nbsp;&nbsp;<a href="javascript:;" class="btn btn-default" onclick="jump(\''.Dever::url($v).'\')">'.$k.'</a>';
  1238. $result .= '&nbsp;&nbsp;<a class="btn btn-default layui-btn layuiadmin-btn-list" href="' . Dever::url($v) . '">' . $k . '</a>';
  1239. } else {
  1240. $result .= '&nbsp;&nbsp;<a href="javascript:;" class="btn btn-danger layui-btn layuiadmin-btn-list layui-btn-danger" onclick="load(\'' . Dever::url($v) . '\')">' . $k . '</a>';
  1241. }
  1242. }
  1243. $result = ltrim($result, '&nbsp;&nbsp;');
  1244. return $result;
  1245. }
  1246. /**
  1247. * 列表页搜索
  1248. *
  1249. * @return array
  1250. */
  1251. public function list_search()
  1252. {
  1253. if (Dever::load('manage/auth.oper', 2) == false) {
  1254. return '';
  1255. }
  1256. # 将以下判断合并
  1257. # 权限验证
  1258. /*
  1259. if (!Dever::load('manage/auth.check', '搜索', $this->menu_id)) {
  1260. return '';
  1261. }
  1262. */
  1263. /*
  1264. # 新增权限
  1265. if (Dever::load('manage/auth.oper', 2) == false) {
  1266. return '';
  1267. }
  1268. if (!Dever::load('manage/auth.checkFunc', $this->menu_id, false, '搜索')) {
  1269. return '';
  1270. }
  1271. */
  1272. $config = $this->config();
  1273. $result = '';
  1274. $top_result = '';
  1275. # 搜索
  1276. if (isset($config['struct']) && isset($config['manage']['search']) && $config['manage']['search']) {
  1277. $search = Dever::preInput('search_');
  1278. $node = Html::node(array(' style="margin-top:0px;"', ''));
  1279. $btn = '<div class="layui-inline"><input type="hidden" value="2" name="excel" id="excel">';
  1280. if (isset($config['manage']['search']['button'])) {
  1281. foreach ($config['manage']['search']['button'] as $k => $v) {
  1282. $i = 0;
  1283. foreach ($v['option'] as $k1 => $v1) {
  1284. $value = $k . '~' . $v['sum'] . '~' . $k1;
  1285. if (isset($v['group'])) {
  1286. $value .= '~' . $v['group'];
  1287. }
  1288. if (!isset($search['search_button']) && $i == 0) {
  1289. $search['search_button'] = $value;
  1290. }
  1291. if (isset($search['search_button']) && $search['search_button'] == $value) {
  1292. $class = 'layui-btn-normal';
  1293. } else {
  1294. $class = 'layui-btn-primary';
  1295. }
  1296. $url = $this->url('list', 0, false, '&search_button=' . $value);
  1297. $btn .= '<a class="btn btn-primary layui-btn layuiadmin-btn-list '.$class.'" href="'.$url.'" type="button" style="height: 38px;margin-left:0px;margin-top:-2px;">'.$v1.'</a>&nbsp;&nbsp;';
  1298. }
  1299. }
  1300. }
  1301. $btn .= '<button class="btn btn-primary layui-btn layuiadmin-btn-list" id="search_button" onclick="$(\'#form1\').attr(\'action\', \'' . $this->url('search') . '\');list_search($(this))" type="button" style="height: 38px;margin-left:0px;margin-top:-2px;">搜索</button><a class="btn btn-primary layui-btn layuiadmin-btn-list layui-btn-primary" href=" '. $this->url('reset') . '" type="button" style="height: 38px;margin-right:5px;margin-top:-2px;display:none;">重置</a></div>';
  1302. //$result .= '<form id="f1" action="'.$this->url('list').'" method="post">';
  1303. $prefix = 'search_';
  1304. $result .= $node[0];
  1305. if (isset($config['manage']['search']['linkage'])) {
  1306. foreach ($config['manage']['search']['linkage'] as $k => $v) {
  1307. $this->list_search_linkage($result, $search, $prefix . 'linkage_' . $k, $v['lang'], $this->option($v['option']), $v['default']);
  1308. if (!layadmin()) {
  1309. $result .= '<br />';
  1310. }
  1311. }
  1312. }
  1313. if (isset($config['manage']['search']['selects'])) {
  1314. $this->list_search_br($result);
  1315. foreach ($config['manage']['search']['selects'] as $k => $v) {
  1316. $bind = array();
  1317. $parent = '';
  1318. $option = $this->option($v['option']);
  1319. if (isset($config['manage']['search_parent'][$k])) {
  1320. $bind = array
  1321. (
  1322. 'onchange',
  1323. 'setOption',
  1324. 'search_option_' . $config['manage']['search_parent'][$k]
  1325. );
  1326. }
  1327. elseif (isset($config['manage']['search_child'][$k])) {
  1328. $parent = $config['manage']['search_child'][$k];
  1329. }
  1330. $this->list_search_select($result, $search, $prefix . 'option_' . $k, $v['lang'], $option, $v['default'], $bind, $parent, true);
  1331. }
  1332. }
  1333. if (isset($config['manage']['search']['select'])) {
  1334. $this->list_search_br($result);
  1335. foreach ($config['manage']['search']['select'] as $k => $v) {
  1336. $bind = array();
  1337. $parent = '';
  1338. $option = $this->option($v['option']);
  1339. if (isset($config['manage']['search_parent'][$k])) {
  1340. $bind = array
  1341. (
  1342. 'onchange',
  1343. 'setOption',
  1344. 'search_option_' . $config['manage']['search_parent'][$k]
  1345. );
  1346. }
  1347. elseif (isset($config['manage']['search_child'][$k])) {
  1348. $parent = $config['manage']['search_child'][$k];
  1349. }
  1350. $this->list_search_select($result, $search, $prefix . 'option_' . $k, $v['lang'], $option, $v['default'], $bind, $parent);
  1351. }
  1352. }
  1353. if (isset($config['manage']['search']['exist'])) {
  1354. $this->list_search_br($result);
  1355. foreach ($config['manage']['search']['exist'] as $k => $v) {
  1356. $this->list_search_select($result, $search, $prefix . 'exist_' . $k, $v['lang'], $this->option($v['option']), '');
  1357. }
  1358. }
  1359. if (isset($config['manage']['search']['group'])) {
  1360. $this->list_search_br($result);
  1361. foreach ($config['manage']['search']['group'] as $k => $v) {
  1362. $this->list_search_group($result, $search, $prefix . 'option_' . $k, $v['lang'], $this->option($v['option']), $v['default']);
  1363. }
  1364. }
  1365. if (isset($config['manage']['search']['api'])) {
  1366. $this->list_search_br($result);
  1367. foreach ($config['manage']['search']['api'] as $k => $v) {
  1368. $value = array();
  1369. $value['name'] = $prefix . 'api_' . $k;
  1370. $value['class'] = 'form-control';
  1371. if (isset($search[$value['name']])) {
  1372. $value['value'] = $search[$value['name']];
  1373. }
  1374. if (strpos($v['lang'], '-') !== false) {
  1375. $t = explode('-', $v['lang']);
  1376. $v['lang'] = $t[0];
  1377. }
  1378. $value['placeholder'] = $v['lang'];
  1379. if (isset($v['option']) && $v['option']) {
  1380. $value['option'] = $this->option($v['option']);
  1381. $value['lang'] = $v['lang'];
  1382. if (isset($v['top']) && $v['top']) {
  1383. $top_result .= Html::select($value, false);
  1384. } else {
  1385. $result .= Html::select($value, false);
  1386. }
  1387. } else {
  1388. $result .= Html::text($value, false);
  1389. }
  1390. }
  1391. }
  1392. if (isset($config['manage']['search']['text'])) {
  1393. $this->list_search_br($result);
  1394. foreach ($config['manage']['search']['text'] as $k => $v) {
  1395. $value = array();
  1396. $value['name'] = $prefix . 'option_' . $k;
  1397. $value['class'] = 'form-control';
  1398. if (isset($search[$value['name']])) {
  1399. $value['value'] = $search[$value['name']];
  1400. }
  1401. if (strpos($v, '-') !== false) {
  1402. $t = explode('-', $v);
  1403. $v = $t[0];
  1404. }
  1405. $value['placeholder'] = $v;
  1406. $result .= Html::text($value, false);
  1407. }
  1408. }
  1409. if (isset($config['manage']['search']['hidden'])) {
  1410. $this->list_search_br($result);
  1411. foreach ($config['manage']['search']['hidden'] as $k => $v) {
  1412. $value = array();
  1413. $value['name'] = $prefix . 'option_' . $k;
  1414. $value['class'] = 'form-control';
  1415. if (isset($search[$value['name']])) {
  1416. $value['value'] = $search[$value['name']];
  1417. }
  1418. if (strpos($v, '-') !== false) {
  1419. $t = explode('-', $v);
  1420. $v = $t[0];
  1421. }
  1422. $value['placeholder'] = $v;
  1423. $value['type'] = 'hidden';
  1424. $result .= Html::hidden($value, false);
  1425. }
  1426. }
  1427. if (isset($config['manage']['search']['ins'])) {
  1428. $this->list_search_br($result);
  1429. foreach ($config['manage']['search']['ins'] as $k => $v) {
  1430. $value = array();
  1431. $value['name'] = $prefix . 'option_' . $k;
  1432. $value['class'] = 'form-control';
  1433. if (isset($search[$value['name']])) {
  1434. $value['value'] = $search[$value['name']];
  1435. }
  1436. if (strpos($v, '-') !== false) {
  1437. $t = explode('-', $v);
  1438. $v = $t[0];
  1439. }
  1440. $value['placeholder'] = $v;
  1441. $result .= Html::text($value, false);
  1442. }
  1443. }
  1444. if (isset($config['manage']['search']['fulltext'])) {
  1445. $this->list_search_br($result);
  1446. foreach ($config['manage']['search']['fulltext'] as $k => $v) {
  1447. $value = array();
  1448. $value['name'] = $prefix . 'fulltext_' . $k;
  1449. $value['class'] = 'form-control';
  1450. if (isset($search[$value['name']])) {
  1451. $value['value'] = $search[$value['name']];
  1452. }
  1453. if (strpos($v, '-') !== false) {
  1454. $t = explode('-', $v);
  1455. $v = $t[0];
  1456. }
  1457. $value['placeholder'] = $v;
  1458. $result .= Html::text($value, false);
  1459. }
  1460. }
  1461. if (isset($config['manage']['search']['exp'])) {
  1462. $result .= '<br />';
  1463. $this->list_search_select($result, $search, $prefix . 'exp_col', '选择检索项', $config['manage']['search']['exp']);
  1464. $this->list_search_select($result, $search, $prefix . 'exp_type', '', array
  1465. (
  1466. 3 => '大于',
  1467. 4 => '大于等于',
  1468. 5 => '小于',
  1469. 6 => '小于等于',
  1470. ), 1);
  1471. $value = array();
  1472. $value['name'] = $prefix . 'exp_value';
  1473. $value['class'] = 'form-control';
  1474. if (isset($search[$value['name']])) {
  1475. $value['value'] = $search[$value['name']];
  1476. }
  1477. $value['placeholder'] = '填写值';
  1478. $result .= Html::text($value, false);
  1479. }
  1480. if (isset($config['manage']['search']['day'])) {
  1481. foreach ($config['manage']['search']['day'] as $k => $v) {
  1482. $this->list_search_time($result, $search, $prefix, $k, $v, 'day');
  1483. }
  1484. }
  1485. if (isset($config['manage']['search']['date'])) {
  1486. foreach ($config['manage']['search']['date'] as $k => $v) {
  1487. $this->list_search_time($result, $search, $prefix, $k, $v, 'date');
  1488. }
  1489. }
  1490. if (isset($config['manage']['search']['year'])) {
  1491. foreach ($config['manage']['search']['year'] as $k => $v) {
  1492. $this->list_search_time($result, $search, $prefix, $k, $v, 'year');
  1493. }
  1494. }
  1495. if (isset($config['manage']['search']['month'])) {
  1496. foreach ($config['manage']['search']['month'] as $k => $v) {
  1497. $this->list_search_time($result, $search, $prefix, $k, $v, 'month');
  1498. }
  1499. }
  1500. if (isset($config['manage']['search']['sday'])) {
  1501. $result .= '<br />';
  1502. foreach ($config['manage']['search']['sday'] as $k => $v) {
  1503. $this->list_search_time($result, $search, $prefix, $k, $v, 'sday');
  1504. }
  1505. $sday = Dever::input('search_option_sday');
  1506. $s1 = $s2 = $s3 = '';
  1507. if ($sday == 7) {
  1508. $s2 = 'sday_button_border';
  1509. } elseif ($sday == 30) {
  1510. $s3 = 'sday_button_border';
  1511. } elseif ($sday) {
  1512. $s1 = 'sday_button_border';
  1513. }
  1514. $result .= '<button class="btn btn-primary layui-btn layuiadmin-btn-list layui-btn-primary sday_button '.$s1.'" type="button" style="height: 38px;margin-right:5px;margin-top:-4px;" onclick="setDay($(this), 0)">今日</button>';
  1515. $result .= '<button class="btn btn-primary layui-btn layuiadmin-btn-list layui-btn-primary sday_button '.$s2.'" onclick="setDay($(this), 7)" type="button" style="height: 38px;margin-right:5px;margin-top:-4px;">7日</button>';
  1516. $result .= '<button class="btn btn-primary layui-btn layuiadmin-btn-list layui-btn-primary sday_button '.$s3.'" onclick="setDay($(this), 30)" type="button" style="height: 38px;margin-right:20px;margin-top:-4px;">30日</button><style>.sday_button_border{border-color: #009688;}</style>';
  1517. $result .= '<input type="hidden" name="search_option_sday" id="search_option_sday" value="0">';
  1518. } elseif (isset($config['manage']['search']['sdate'])) {
  1519. $result .= '<br />';
  1520. foreach ($config['manage']['search']['sdate'] as $k => $v) {
  1521. $this->list_search_time($result, $search, $prefix, $k, $v, 'sdate');
  1522. }
  1523. $sdate = Dever::input('search_option_sdate');
  1524. $s1 = $s2 = $s3 = '';
  1525. if ($sdate == 7) {
  1526. $s2 = 'sdate_button_border';
  1527. } elseif ($sdate == 30) {
  1528. $s3 = 'sdate_button_border';
  1529. } elseif ($sdate) {
  1530. $s1 = 'sdate_button_border';
  1531. }
  1532. $result .= '<button class="btn btn-primary layui-btn layuiadmin-btn-list layui-btn-primary sdate_button '.$s1.'" type="button" style="height: 38px;margin-right:5px;margin-top:-4px;" onclick="setDate($(this), 0)">今日</button>';
  1533. $result .= '<button class="btn btn-primary layui-btn layuiadmin-btn-list layui-btn-primary sdate_button '.$s2.'" onclick="setDate($(this), 7)" type="button" style="height: 38px;margin-right:5px;margin-top:-4px;">7日</button>';
  1534. $result .= '<button class="btn btn-primary layui-btn layuiadmin-btn-list layui-btn-primary sdate_button '.$s3.'" onclick="setDate($(this), 30)" type="button" style="height: 38px;margin-right:20px;margin-top:-4px;">30日</button><style>.sdate_button_border{border-color: #009688;}</style>';
  1535. $result .= '<input type="hidden" name="search_option_sdate" id="search_option_sdate" value="0">';
  1536. }
  1537. # 列表页按钮
  1538. if (isset($config['manage']['search_button'])) {
  1539. $btn .= $this->list_button_show($config['manage']['search_button']);
  1540. }
  1541. $result .= $btn . $node[1];
  1542. //$result .= '</form>';
  1543. # 增加每页显示条数
  1544. $config['manage']['num'] = $this->getNumConfig($config);
  1545. /*
  1546. if ($config['manage']['num']) {
  1547. $result = $this->num($result, $config['manage']['num']);
  1548. }
  1549. */
  1550. }
  1551. $oper = Dever::preInput('oper_');
  1552. if ($oper) {
  1553. foreach ($oper as $k => $v) {
  1554. $result .= '<input type="hidden" value="'.$v.'" name="'.$k.'" id="'.$k.'" />';
  1555. }
  1556. }
  1557. $top = Dever::input('top_parent');
  1558. if ($top) {
  1559. $result .= '<input type="hidden" value="'.$top.'" name="top_parent" id="top_parent" />';
  1560. }
  1561. $page_type = Dever::input('page_type');
  1562. if ($page_type) {
  1563. $result .= '<input type="hidden" value="'.$page_type.'" name="page_type" id="page_type" />';
  1564. }
  1565. if ($top_result) {
  1566. $result = $top_result . $result;
  1567. }
  1568. return $result;
  1569. }
  1570. private function list_search_br(&$result)
  1571. {
  1572. if (strpos($result, '&nbsp;&nbsp;') && !strpos($result, '<br />')) {
  1573. $result .= '<br />';
  1574. }
  1575. }
  1576. /**
  1577. * 获取条数配置
  1578. *
  1579. * @return array
  1580. */
  1581. private function getNumConfig($config)
  1582. {
  1583. if (isset($config['manage']['list_type'])) {
  1584. return false;
  1585. }
  1586. if (isset($config['manage']['num']) && $config['manage']['num'] == false) {
  1587. return false;
  1588. }
  1589. if (!isset($config['manage']['num'])) {
  1590. $config['manage']['num'] = array(20,30,40,50,60,70,80,90,100);
  1591. }
  1592. Dever::config('base')->page_num = $config['manage']['num'];
  1593. return $config['manage']['num'];
  1594. }
  1595. /**
  1596. * 生成条数的html
  1597. *
  1598. * @return string
  1599. */
  1600. private function num($result, $config)
  1601. {
  1602. return $result;
  1603. $limit = '';
  1604. $cur = Dever::input('search_limit', 0);
  1605. foreach($config as $k => $v) {
  1606. if ($cur == $k) {
  1607. $btn = 'success';
  1608. } else {
  1609. $btn = 'default';
  1610. }
  1611. $url = $this->url('list', 0, false, '&search_limit=' . $k);
  1612. $limit .= '<a href="'.$url.'" style="width:60px;font-weight:bold;" class="btn btn-'.$btn.' layui-btn layui-btn-radius layui-btn-primary">'.$v.'</a> ';
  1613. }
  1614. $num = '<div class="form-group layui-inline"><div style="padding-top:10px;margin-bottom: -10px;"><label style="color:#bababa;margin-left:8px;margin-right:10px;font-size:14px;font-weight:bold;">每页显示条数:</label>'.$limit.'</div></div>';
  1615. /*
  1616. if (layadmin()) {
  1617. $num = '';
  1618. }*/
  1619. $result .= $num;
  1620. return $result;
  1621. }
  1622. /**
  1623. * 列表页表格头
  1624. *
  1625. * @return array
  1626. */
  1627. public function list_thead($type = false)
  1628. {
  1629. if (Dever::load('manage/auth.oper', 1) == false) {
  1630. Dever::alert('你没有权限');
  1631. }
  1632. $config = $this->config();
  1633. if ($type == 'layui') {
  1634. if (!isset($config['manage']['list_table']) || (isset($config['manage']['list_table']) && $config['manage']['list_table'] == 'html')) {
  1635. return false;
  1636. }
  1637. } else {
  1638. if (isset($config['manage']['list_table']) && $config['manage']['list_table'] == 'js') {
  1639. return '';
  1640. }
  1641. }
  1642. $result = array();
  1643. /*
  1644. $tbody = Dever::load('manage/database.list_tbody');
  1645. if (!$tbody) {
  1646. return $result;
  1647. }
  1648. */
  1649. if (isset($config['struct'])) {
  1650. if (isset($config['manage']['list']) && $config['manage']['list'] == 'update') {
  1651. # 验证头部权限 这里如果是多个选择权限的话,暂时无法实现。。。
  1652. if (isset($config['top']) && is_string($config['top'])) {
  1653. $top = Dever::load('manage/auth.getTop', array($config['top']));
  1654. if ($top) {
  1655. $url = $this->url('update', $top['value']);
  1656. }
  1657. } else {
  1658. $url = $this->url('update', Dever::input('where_id', 1));
  1659. }
  1660. return Dever::location($url);
  1661. } else {
  1662. if (isset($config['manage']['mul']) && $config['manage']['mul']) {
  1663. if ($type == 'layui') {
  1664. $layui = array
  1665. (
  1666. 'field' => 'checkbox',
  1667. 'title' => '<input type="checkbox" class="checkbox-checkall" name="checkall" id="checkall" value="list" lay-ignore/>',
  1668. //'fixed' => 'left',
  1669. );
  1670. $result[] = $layui;
  1671. } else {
  1672. $result[] = '<th><input type="checkbox" class="checkbox-checkall" name="checkall" id="checkall" value="list"/></th>';
  1673. }
  1674. }
  1675. $data = array();
  1676. $data = $this->getAdminInfo($data);
  1677. foreach ($config['struct'] as $k => $v) {
  1678. if (isset($v['list']) && $v['list']) {
  1679. # 处理权限
  1680. if (isset($v['auth'])) {
  1681. $auth = $this->value($v['auth'], $data);
  1682. if (!$auth) {
  1683. continue;
  1684. }
  1685. }
  1686. if (isset($v['list_name'])) {
  1687. $v['name'] = $v['list_name'];
  1688. } else {
  1689. $temp = Html::cue(array('name' => $v['name']));
  1690. $v['name'] = $temp['name'];
  1691. }
  1692. if (!isset($v['level'])) {
  1693. $v['level'] = $config['level'];
  1694. }
  1695. if (isset($v['search']) && is_string($v['search']) && strpos($v['search'], 'order') !== false) {
  1696. $link = Dever::url();
  1697. $order = 'search_order_' . $k . '';
  1698. if (strpos($link, $order) !== false) {
  1699. $link = preg_replace('/[?|&]' . $order . '=(desc|asc)/i', '{order}', $link);
  1700. } else {
  1701. $link .= '{order}';
  1702. }
  1703. $search = Dever::input($order);
  1704. $cancel = '';
  1705. if ($search) {
  1706. $asc = $search;
  1707. $cancel = '&nbsp;<a class="glyphicon glyphicon-remove-sign layui-icon layui-icon-close" style="color:black;" href="' . str_replace('{order}', '', $link) . '" title="取消排序"></a>';
  1708. } else {
  1709. $asc = 'desc';
  1710. if (!isset($v['order']) && $k != 'id') {
  1711. //$cancel = '&nbsp;<a class="glyphicon glyphicon-circle-arrow-down layui-icon layui-icon-up" style="color:black;" href="' . str_replace('{order}', '&' . $order . '=desc', $link) . '" title="降序"></a>';
  1712. }
  1713. }
  1714. if ($asc == 'asc') {
  1715. $asc = 'desc';
  1716. $icon = 'down';
  1717. $text = '降序';
  1718. } else {
  1719. $asc = 'asc';
  1720. $icon = 'up';
  1721. $text = '升序';
  1722. }
  1723. $link = str_replace('{order}', '&' . $order . '=' . $asc, $link);
  1724. if ($type == 'layui') {
  1725. $layui = array
  1726. (
  1727. 'field' => $k,
  1728. 'title' => '<a href="' . $link . '" title="' . $text . '" style="color:black;">' . $v['name'] . '&nbsp;<span class="layui-icon layui-icon-' . $icon . '" style="font-size:12px"></span></a>',
  1729. );
  1730. $result[] = $layui;
  1731. } else {
  1732. $result[] = '<th data-priority="'.$v['level'].'"><a href="' . $link . '" title="' . $text . '" style="color:black;">' . $v['name'] . '&nbsp;<span class="glyphicon glyphicon-circle-arrow-' . $icon . ' layui-icon layui-icon-' . $icon . '"></span></a>' . $cancel . '</th>';
  1733. }
  1734. } else {
  1735. if ($type == 'layui') {
  1736. if ($k == 'id' || isset($v['fixed'])) {
  1737. $layui = array
  1738. (
  1739. 'field' => $k,
  1740. 'title' => $v['name'],
  1741. //'fixed' => 'left',
  1742. );
  1743. } else {
  1744. $layui = array
  1745. (
  1746. 'field' => $k,
  1747. 'title' => $v['name'],
  1748. );
  1749. }
  1750. if (isset($v['list_header']) && $v['list_header']) {
  1751. $layui += $v['list_header'];
  1752. }
  1753. $result[] = $layui;
  1754. } else {
  1755. $result[] = '<th data-priority="'.$v['level'].'">' . $v['name'] . '</th>';
  1756. }
  1757. }
  1758. }
  1759. }
  1760. //if ((Dever::load('manage/auth.oper', 3) != false || Dever::load('manage/auth.oper', 5) != false) && isset($config['manage']['_list']['value'])) {
  1761. if (isset($config['manage']['_list']['value']) && $this->manage_button) {
  1762. if ($type == 'layui') {
  1763. $layui = array
  1764. (
  1765. 'field' => $config['manage']['_list']['col'],
  1766. 'title' => $config['manage']['_list']['name'],
  1767. //'fixed' => 'right',
  1768. );
  1769. $result[] = $layui;
  1770. } else {
  1771. $result[] = '<th data-priority="1" class="dever-manage">' . $config['manage']['_list']['name'] . '</th>';
  1772. }
  1773. }
  1774. }
  1775. }
  1776. return $result;
  1777. }
  1778. # layui表头
  1779. /*
  1780. public function list_thead_layui()
  1781. {
  1782. $html = 'config.table = {};config.table.cols = [];';
  1783. $data = $this->list_thead('layui');
  1784. if ($data) {
  1785. $data = array($data);
  1786. $data = Dever::json_encode($data);
  1787. $html .= 'config.table.cols = ' . $data;
  1788. return $html;
  1789. } else {
  1790. $html .= 'config.table.cols = []';
  1791. return $html;
  1792. }
  1793. }
  1794. # layui表的数据 没有使用其异步方式
  1795. public function list_tbody_layui()
  1796. {
  1797. $html = 'config.table.data = [];';
  1798. $data = $this->list_tbody(false, 'layui');
  1799. $data = Dever::json_encode($data);
  1800. $html .= 'config.table.data = ' . $data;
  1801. return $html;
  1802. }
  1803. */
  1804. /**
  1805. * 导出列表
  1806. *
  1807. * @return array
  1808. */
  1809. public function list_excel_api()
  1810. {
  1811. Dever::$global['base']['excel'] = 1;
  1812. $this->list_search();
  1813. $data = $this->list_tbody(true);
  1814. if ($data) {
  1815. $config = $this->config();
  1816. if (isset($config['manage']['excel']) && $config['manage']['excel']) {
  1817. $method = 'excel';
  1818. $info = $this->info();
  1819. $load = Dever::input('excel_load');
  1820. if ($load) {
  1821. return Dever::load($load, $data);
  1822. } elseif (is_string($config['manage']['excel']) && strstr($config['manage']['excel'], '.')) {
  1823. return Dever::load($config['manage']['excel'], $data);
  1824. } else {
  1825. $data = $this->getAdminInfo($data);
  1826. return $this->excel($info, $data, $config);
  1827. }
  1828. }
  1829. } else {
  1830. Dever::alert('无导出数据');
  1831. }
  1832. //print_r($data);die;
  1833. }
  1834. private function excel($info, $data, $config)
  1835. {
  1836. $file = Dever::input('excel_name');
  1837. if (!$file) {
  1838. $file = $info['list_header'] . '的' . $info['list_desc'] . '-' . $info['project_name'];
  1839. }
  1840. $header = $body = array();
  1841. $i = 0;
  1842. foreach ($config['struct'] as $k => $v) {
  1843. if (isset($v['list']) && $v['list']) {
  1844. # 处理权限
  1845. if (isset($v['auth'])) {
  1846. $auth = $this->value($v['auth'], $data);
  1847. if (!$auth) {
  1848. continue;
  1849. }
  1850. }
  1851. //$v['name'] = mb_convert_encoding($v['name'],'gb2312','utf-8');
  1852. if (isset($v['list_name']) && $v['list_name']) {
  1853. $v['name'] = $v['list_name'];
  1854. }
  1855. $header[$i] = $v['name'];
  1856. $j = 0;
  1857. foreach ($data as $ki => $vi) {
  1858. if (is_array($vi)) {
  1859. $body[$j][$i] = '';
  1860. //if (isset($vi[$k])) {
  1861. # 处理同步
  1862. if (isset($v['sync']) && strpos($k, '-')) {
  1863. $temp = explode('-', $k);
  1864. if ($vi[$v['sync'][0]] > 0) {
  1865. $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', array('option_' . $v['sync'][1] => $vi[$v['sync'][0]]));
  1866. } else {
  1867. $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', array('option_' . $v['sync'][3] => $vi[$v['sync'][2]], 'option_' . $v['sync'][4] => $vi[$v['sync'][0]]));
  1868. }
  1869. if (isset($temp[2])) {
  1870. $data[$ki][$k] = $vi[$k] = isset($load[$temp[2]]) ? $load[$temp[2]] : $v['default'];
  1871. }
  1872. }
  1873. if (true) {
  1874. $value = $vi[$k];
  1875. if (is_string($v['list'])) {
  1876. $value = $this->value($v['list'], $data[$ki], $config['struct']);
  1877. }
  1878. if (isset($v['option'])) {
  1879. $value = $this->getOptionValue($value, $v);
  1880. }
  1881. //$value = mb_convert_encoding($value,'gb2312','utf-8');
  1882. $body[$j][$i] = $value;
  1883. $j++;
  1884. }
  1885. }
  1886. }
  1887. $i++;
  1888. }
  1889. }
  1890. return Dever::excelExport($body, $header, $file);
  1891. }
  1892. private function getOptionValue($value, $v)
  1893. {
  1894. # 验证option是否是匿名函数
  1895. $v['option'] = $this->option($v['option']);
  1896. # 位运算
  1897. if (isset($v['bit'])) {
  1898. $ts = array();
  1899. foreach ($v['option'] as $tm => $tv) {
  1900. if (isset($v['bit'][$tm]) && ($value & $tm) > 0) {
  1901. $ts[] = $tv;
  1902. }
  1903. }
  1904. $value = implode(',', $ts);
  1905. }
  1906. if ((isset($v['child_name']) || (isset($v['show']) && is_string($v['show'])))) {
  1907. if (isset($v['option'][$value]) && is_array($v['option'][$value])) {
  1908. $value = $v['option'][$value]['name'];
  1909. } else {
  1910. $value = isset($v['option'][$value]) ? $v['option'][$value] : $value;
  1911. }
  1912. } else {
  1913. if (strstr($value, ',')) {
  1914. $temp = explode(',', $value);
  1915. $t = array();
  1916. foreach ($temp as $vv) {
  1917. if (isset($v['option'][$vv]) && is_array($v['option'][$vv])) {
  1918. $t[] = $v['option'][$vv]['name'];
  1919. } elseif(isset($v['option'][$vv])) {
  1920. $t[] = $v['option'][$vv];
  1921. } else {
  1922. $t[] = $vv;
  1923. }
  1924. }
  1925. $value = implode("\r\n", $t);
  1926. } elseif (isset($v['option'][$value]) && is_array($v['option'][$value])) {
  1927. $value = $v['option'][$value]['name'];
  1928. } else {
  1929. $value = isset($v['option'][$value]) ? $v['option'][$value] : $value;
  1930. }
  1931. }
  1932. return $value;
  1933. }
  1934. private function _getChr($start, $num)
  1935. {
  1936. $num = $start + $num;
  1937. $max = floor($num / 91);
  1938. if ($max > 0) {
  1939. $num = $num - (91 * $max) + $start;
  1940. $num = chr($start) . chr($num);
  1941. } else {
  1942. $num = chr($num);
  1943. }
  1944. return $num;
  1945. }
  1946. /**
  1947. * 列表页数据列表 检索
  1948. *
  1949. * @return array
  1950. */
  1951. private function list_tbody_search($config, $param, $high, $search)
  1952. {
  1953. # 根据api的数据检索到id
  1954. $api = Dever::preInput('search_api_');
  1955. if ($api) {
  1956. foreach ($api as $k => $v) {
  1957. if ($v) {
  1958. unset($search[$k]);
  1959. $k = str_replace('search_api_', '', $k);
  1960. # 设定检索高亮
  1961. $high[$k] = $v;
  1962. if (isset($config['manage']['search']['api'][$k]['api'])) {
  1963. $col = $config['manage']['search']['api'][$k]['col'];
  1964. $v = ltrim($v);
  1965. $v = rtrim($v);
  1966. if ($v == 'no') {
  1967. $param['option_no'] = $config['manage']['search']['api'][$k]['no'];
  1968. } else {
  1969. $option = array($col => $v, 'clear_top' => true);
  1970. # 此处可以增加关联关系
  1971. $v = Dever::load($config['manage']['search']['api'][$k]['api'], $option);
  1972. $result = $config['manage']['search']['api'][$k]['result'];
  1973. if ($v && is_array($v)) {
  1974. if (isset($v[$result])) {
  1975. $v = $v[$result];
  1976. } else {
  1977. if ($result == 'id') {
  1978. $v = array_keys($v);
  1979. } else {
  1980. $t = array();
  1981. foreach ($v as $k1 => $v1) {
  1982. $t[] = $v1[$result];
  1983. }
  1984. $v = $t;
  1985. }
  1986. if (isset($config['manage']['search']['api'][$k]['search'])) {
  1987. $param['option'][$config['manage']['search']['api'][$k]['search']] = array('yes', 'in');
  1988. } else {
  1989. $param['option'][$k] = array('yes', 'in');
  1990. }
  1991. }
  1992. } else {
  1993. $v = '-100';
  1994. }
  1995. }
  1996. }
  1997. if (!isset($param['option_no'])) {
  1998. if (isset($config['manage']['search']['api'][$k]['search'])) {
  1999. $param['option_' . $config['manage']['search']['api'][$k]['search']] = $v;
  2000. } else {
  2001. $param['option_' . $k] = $v;
  2002. }
  2003. }
  2004. }
  2005. }
  2006. }
  2007. # 检索有无值
  2008. $exist = Dever::preInput('search_exist_');
  2009. if ($exist) {
  2010. foreach ($exist as $k => $v) {
  2011. if ($v) {
  2012. unset($search[$k]);
  2013. $k = str_replace('search_exist_', '', $k);
  2014. if ($v == 'yes') {
  2015. # 有值
  2016. $param['option'][$k] = array('yes', '!=');
  2017. //$param['option_' . $k] = 'null';
  2018. } elseif ($v == 'no') {
  2019. # 无值
  2020. $param['option'][$k] = array('yes', '=');
  2021. //$param['option_' . $k] = 'null';
  2022. } elseif (strpos($v, '|')) {
  2023. # 有无值或者自定义的值
  2024. $temp = explode('|', $v);
  2025. $param['option_' . $k] = $temp[1];
  2026. if ($temp[0] == 'yes') {
  2027. $param['option'][$k] = array('yes', '!=');
  2028. $param['option'][$k . '_t1'] = array('yes-' . $k, '!=');
  2029. } else {
  2030. $param['option'][$k] = array('yes', '=', 'and(');
  2031. $param['option'][$k . '_t1'] = array('yes-' . $k, '=', 'or)');
  2032. }
  2033. //$param['option_' . $k . '_t1'] = 'null';
  2034. } else {
  2035. # 自定义的值
  2036. $param['option_' . $k] = $v;
  2037. }
  2038. }
  2039. }
  2040. }
  2041. # 检索in
  2042. $in = Dever::preInput('search_in_');
  2043. if ($in) {
  2044. $in_state = false;
  2045. foreach ($in as $k => $v) {
  2046. if ($v) {
  2047. unset($search[$k]);
  2048. $k = str_replace('search_in_', '', $k);
  2049. $param['option'][$k] = array('yes', 'in');
  2050. $param['option_' . $k] = $v;
  2051. # 设定检索高亮
  2052. //$high[$k] = $v;
  2053. $in_state = true;
  2054. }
  2055. }
  2056. $this->search = true;
  2057. }
  2058. $fulltext = Dever::preInput('search_fulltext_');
  2059. if ($fulltext) {
  2060. $fulltext_state = false;
  2061. foreach ($fulltext as $k => $v) {
  2062. if ($v) {
  2063. unset($search[$k]);
  2064. $k = str_replace('search_fulltext_', '', $k);
  2065. $param['option_' . $k] = $v;
  2066. # 设定检索高亮
  2067. $high[$k] = $v;
  2068. $fulltext_state = true;
  2069. }
  2070. }
  2071. $this->search = true;
  2072. }
  2073. $linkage = Dever::preInput('search_linkage_');
  2074. if ($linkage) {
  2075. foreach ($linkage as $k => $v) {
  2076. if ($v && $v != -1) {
  2077. unset($search[$k]);
  2078. $k = str_replace('search_linkage_', '', $k);
  2079. if (isset($config['struct'][$k]['search_col'])) {
  2080. $temp = explode(',', $config['struct'][$k]['search_col']);
  2081. if (!is_array($v)) {
  2082. $v = explode(',', $v);
  2083. }
  2084. foreach ($temp as $k1 => $v1) {
  2085. if (isset($v[$k1]) && $v[$k1] != -1) {
  2086. $param['option_' . $v1] = $v[$k1];
  2087. }
  2088. }
  2089. } else {
  2090. if (is_array($v)) {
  2091. $v = implode(',', $v);
  2092. }
  2093. if ($v != -1) {
  2094. $v = Dever::defaultValue($v);
  2095. $param['option_' . $k] = $v;
  2096. # 设定检索高亮
  2097. $high[$k] = $v;
  2098. }
  2099. }
  2100. }
  2101. }
  2102. $this->search = true;
  2103. }
  2104. $exp = Dever::preInput('search_exp_');
  2105. if ($exp) {
  2106. $k = $search['search_exp_col'];
  2107. $v = $search['search_exp_value'];
  2108. $param['option_' . $k] = $v;
  2109. $param['search_type'] = $search['search_exp_type'];
  2110. $this->search = true;
  2111. }
  2112. $order = Dever::preInput('search_order_');
  2113. if ($order) {
  2114. foreach ($order as $k => $v) {
  2115. $k = str_replace('search_order_', '', $k);
  2116. $param['order'][0][$k] = $v;
  2117. unset($search[$k]);
  2118. }
  2119. }
  2120. foreach ($search as $k => $v) {
  2121. if ($v) {
  2122. if (strpos($k, '-') !== false) {
  2123. $k = str_replace('search_option_', '', $k);
  2124. $temp = explode('-', $k);
  2125. if (isset($config['struct'][$k]) && isset($config['struct'][$k]['sync'])) {
  2126. }
  2127. $struct = $config['struct'][$k];
  2128. if (isset($struct['search_col']) && $struct['search_col']) {
  2129. $param[$struct['search_col']] = $v;
  2130. } else {
  2131. $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', array('option_' . $struct['sync'][1] => $v));
  2132. /*
  2133. if ($v[$vi['sync'][0]] > 0) {
  2134. $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', array('option_' . $vi['sync'][1] => $v[$vi['sync'][0]]));
  2135. } else {
  2136. $lw = array('option_' . $vi['sync'][3] => $v[$vi['sync'][2]], 'option_' . $vi['sync'][4] => $v[$vi['sync'][0]]);
  2137. $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', $lw);
  2138. }*/
  2139. if (isset($temp[2])) {
  2140. $v = isset($load[$temp[2]]) ? $load[$temp[2]] : $struct['default'];
  2141. $param[str_replace('search_', '', $k)] = $v;
  2142. }
  2143. }
  2144. } elseif (strpos($k, 'dever_') !== false) {
  2145. continue;
  2146. } elseif (strpos($k, 'option_') !== false) {
  2147. //Dever::setInput(str_replace('search_', '', $k), $v);
  2148. if (is_array($v)) {
  2149. if ($v[0] == 0) {
  2150. continue;
  2151. }
  2152. $v = str_replace(',0', '', implode(',', $v));
  2153. $t = explode(',', $v);
  2154. $parent = end($t);
  2155. $v .= '%';
  2156. }
  2157. $param[str_replace('search_', '', $k)] = $v;
  2158. $this->search = true;
  2159. } elseif ($k == 'search_limit') {
  2160. $num = $this->getNumConfig($config);
  2161. if ($num) {
  2162. $param['page'][0] = $num[$v];
  2163. }
  2164. }
  2165. }
  2166. }
  2167. return array($param, $high);
  2168. }
  2169. private function list_tbody_mul($config, $send)
  2170. {
  2171. $mul = Dever::load('manage/auth.oper', 3) ? Dever::preInput('mul_') : false;
  2172. $method = Dever::input('method');
  2173. if (strstr($method, 'mul') && $mul && $mul['mul_type'] > 0) {
  2174. if ($mul['mul_type'] == 1 && empty($mul['mul_where_id'])) {
  2175. Dever::alert('您还未选择任何数据条目');
  2176. }
  2177. Dever::config('base')->mul_type = $mul['mul_type'];
  2178. unset($mul['mul_type']);
  2179. $param = $send;
  2180. if (isset($param['page'])) {
  2181. unset($param['page']);
  2182. }
  2183. foreach ($mul as $k => $v) {
  2184. if ($v) {
  2185. if (is_array($v)) {
  2186. $v = implode(',', $v);
  2187. }
  2188. $param[str_replace('mul_', '', $k)] = $v;
  2189. if (strstr($k, 'mul_set_')) {
  2190. $k = str_replace('mul_set_', '', $k);
  2191. if (isset($config['struct'][$k]) && isset($config['struct'][$k]['mul_where'])) {
  2192. $param = array_merge(Dever::prefix($config['struct'][$k]['mul_where'], 'option_'), $param);
  2193. }
  2194. }
  2195. }
  2196. }
  2197. //print_r($param);die;
  2198. if (isset($param)) {
  2199. $data = Dever::db($this->project . '/' . $this->table)->getmul($param);
  2200. if ($data) {
  2201. Dever::config('base')->mul_data = array_keys($data);
  2202. if (strstr($method, 'mul.')) {
  2203. $url = str_replace('mul.', '', $method);
  2204. if ($url) {
  2205. $send = array();
  2206. foreach ($param as $k => $v) {
  2207. $send['search_' . $k] = $v;
  2208. }
  2209. $send['search_ids'] = implode(',', Dever::config('base')->mul_data);
  2210. if (strstr($url, '?')) {
  2211. $url .= '&' . http_build_query($send);
  2212. } else {
  2213. $url .= '?' . http_build_query($send);
  2214. }
  2215. Dever::alert($url, 2);
  2216. }
  2217. }
  2218. $method = $this->project . '/' . $this->table . '-updatemul';
  2219. $state = Dever::load($method, $param);
  2220. }
  2221. }
  2222. Dever::alert('reload');
  2223. }
  2224. }
  2225. /**
  2226. * 列表页数据列表:图片形式
  2227. *
  2228. * @return array
  2229. */
  2230. public function list_photo()
  2231. {
  2232. $config = $this->config();
  2233. $result = array();
  2234. if (isset($config['manage']['photo'])) {
  2235. $high = array();
  2236. $search = Dever::load('manage/auth.oper', 2) ? Dever::preInput('search_') : false;
  2237. $param = array();
  2238. $parent = 0;
  2239. if ($search) {
  2240. list($param, $high) = $this->list_tbody_search($config, $param, $high, $search);
  2241. }
  2242. if (empty($param['page'])) {
  2243. $num = $this->getNumConfig($config);
  2244. if ($num) {
  2245. $param['page'][0] = $num[0];
  2246. }
  2247. }
  2248. $method = $this->project . '/' . $this->table . '-list';
  2249. $result = Dever::load($method, $param);
  2250. if ($result) {
  2251. foreach ($result as $k => $v) {
  2252. $result[$k] = Dever::load($config['manage']['photo'], $v);
  2253. $result[$k]['button'] = $this->list_tbody_button($config, $v, 'div');
  2254. }
  2255. }
  2256. }
  2257. return $result;
  2258. }
  2259. /**
  2260. * 列表页数据列表:表格形式
  2261. *
  2262. * @return array
  2263. */
  2264. public function list_tbody($excel = false, $type = false)
  2265. {
  2266. $this->state = false;
  2267. # 新增权限
  2268. if (Dever::load('manage/auth.oper', 1) == false) {
  2269. Dever::alert('你没有权限');
  2270. }
  2271. if (Dever::input('page_content') == 1) {
  2272. return '';
  2273. }
  2274. $config = $this->config();
  2275. $high = array();
  2276. $search = Dever::load('manage/auth.oper', 2) ? Dever::preInput('search_') : false;
  2277. $param = array();
  2278. $parent = 0;
  2279. if ($search) {
  2280. list($param, $high) = $this->list_tbody_search($config, $param, $high, $search);
  2281. }
  2282. $num = $this->getNumConfig($config);
  2283. if (empty($param['page']) && $num) {
  2284. $param['page'][0] = $num[0];
  2285. }
  2286. # 批量更新
  2287. $this->list_tbody_mul($config, $param);
  2288. $result = $return = array();
  2289. if (isset($config['top_option']) && $config['top_option']) {
  2290. if (isset($config['top_option'][0])) {
  2291. foreach ($config['top_option'] as $k => $v) {
  2292. if (isset($v['join'])) {
  2293. $param['join'][] = $v['join'];
  2294. $col = 't_2.' . $v['col'];
  2295. $param['option']['state'] = 'yes-t_1.state';
  2296. } else {
  2297. $col = $v['col'];
  2298. }
  2299. if ($v['value']) {
  2300. $param['option'][$v['col']] = array('yes-' . $col, 'in');
  2301. $param[$v['col']] = $v['value'];
  2302. }
  2303. }
  2304. } else {
  2305. $param['option'][$config['top_option']['col']] = array($config['top_option']['value'], 'in');
  2306. }
  2307. }
  2308. if (isset($config['manage']['company']) && is_array($config['manage']['company']) && isset($config['manage']['company']['join'])) {
  2309. $param['join'][] = $config['manage']['company']['join'];
  2310. }
  2311. if ($excel == true) {
  2312. $method = $this->project . '/' . $this->table . '-list';//all
  2313. } else {
  2314. $method = $this->project . '/' . $this->table . '-list';
  2315. }
  2316. //print_r($param);
  2317. $data = Dever::load($method, $param);
  2318. //print_r(Dever::sql());die;
  2319. if (isset($config['manage']['list_type']) && $config['manage']['list_type'] == 'parent') {
  2320. $parent = array();
  2321. $child = array();
  2322. foreach ($data as $k => $v) {
  2323. if ($v[$config['name'] . '_id'] <= 0) {
  2324. $parent[$k] = $v;
  2325. } else {
  2326. $v['name'] = '|-----' . $v['name'];
  2327. $child[$v[$config['name'] . '_id']][$k] = $v;
  2328. }
  2329. }
  2330. if ($parent) {
  2331. $data = array();
  2332. foreach ($parent as $k => $v) {
  2333. $data[$v['id']] = $v;
  2334. if (isset($child[$v['id']])) {
  2335. foreach ($child[$v['id']] as $i => $j) {
  2336. $data[$j['id']] = $j;
  2337. }
  2338. }
  2339. }
  2340. }
  2341. } elseif (isset($config['manage']['list_type']) && $config['manage']['list_type'] == 'tree') {
  2342. $data = $this->tree($data, $config, -1);
  2343. }
  2344. if ($excel == true) {
  2345. return $data;
  2346. }
  2347. if (Dever::input('page_type') == 1) {
  2348. Dever::$global['manage']['list_data'] = $data;
  2349. return;
  2350. }
  2351. //print_r($data);die;
  2352. //print_r(Helper::page("current"));die;
  2353. $this->manage_button = false;
  2354. if ($data && isset($config['struct'])) {
  2355. $i = 0;
  2356. $pg = Dever::input('pg', 1);
  2357. $cur = Dever::input('search_limit', 0);
  2358. foreach ($data as $k => $v) {
  2359. $data[$k] = $this->getAdminInfo($data[$k]);
  2360. $data[$k]['i'] = $i;
  2361. $ii = isset($num[$cur]) ? intval($num[$cur])*($pg-1) : 0;
  2362. $data[$k]['r'] = $i+1+$ii;
  2363. $result[$k] = '<tr>';
  2364. $return[$i] = array();
  2365. if (isset($config['manage']['mul']) && $config['manage']['mul']) {
  2366. $mul_state = false;
  2367. if ($config['manage']['mul'] && is_string($config['manage']['mul'])) {
  2368. $mul_state = $this->value($config['manage']['mul'], $data[$k]);
  2369. } else {
  2370. $mul_state = true;
  2371. }
  2372. if ($mul_state) {
  2373. $checkbox = '<input type="checkbox" name="mul_where_id[]" class="checkbox-checkall-list" lay-ignore value="' . $v['id'] . '"/>';
  2374. } else {
  2375. $checkbox = '<input type="checkbox" name="mul_where_id[]" class="checkbox-checkall-list" lay-ignore value="-1" disabled/>';
  2376. }
  2377. $result[$k] .= '<td>'.$checkbox.'</td>';
  2378. $return[$i]['checkbox'] = $checkbox;
  2379. }
  2380. foreach ($config['struct'] as $ki => $vi) {
  2381. # 处理同步
  2382. if (isset($vi['sync']) && strpos($ki, '-')) {
  2383. $temp = explode('-', $ki);
  2384. if ($v[$vi['sync'][0]] > 0) {
  2385. $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', array('option_' . $vi['sync'][1] => $v[$vi['sync'][0]]));
  2386. } else {
  2387. $lw = array('option_' . $vi['sync'][3] => $v[$vi['sync'][2]], 'option_' . $vi['sync'][4] => $v[$vi['sync'][0]]);
  2388. $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', $lw);
  2389. }
  2390. if (isset($temp[2])) {
  2391. $data[$k][$ki] = $v[$ki] = isset($load[$temp[2]]) ? $load[$temp[2]] : $vi['default'];
  2392. }
  2393. }
  2394. if (isset($vi['list']) && $vi['list']) {
  2395. if (empty($v[$ki])) {
  2396. $v[$ki] = isset($vi['default']) ? $vi['default'] : '';
  2397. }
  2398. # 处理权限
  2399. if (isset($vi['auth'])) {
  2400. $auth = $this->value($vi['auth'], $data[$k]);
  2401. if (!$auth) {
  2402. continue;
  2403. }
  2404. }
  2405. $show = $v[$ki];
  2406. if (is_string($vi['list'])) {
  2407. $show = $this->value($vi['list'], $data[$k], $config['struct']);
  2408. }
  2409. if (isset($vi['key']) && $vi['update'] != 'editor') {
  2410. $show = Dever::upload($show);
  2411. }
  2412. if (isset($vi['modal'])) {
  2413. $show = Html::modal($this->value($vi['modal'], $data[$k], $config['struct']), $show);
  2414. } elseif (isset($vi['option']) && !is_string($vi['list'])) {
  2415. # 验证option是否是匿名函数
  2416. if ((isset($vi['edit']) && $vi['edit'])) {
  2417. $vi['option'] = $this->option($vi['option'], $vi['edit']);
  2418. } else {
  2419. $vi['option'] = $this->option($vi['option']);
  2420. }
  2421. # 位运算
  2422. if (isset($vi['bit'])) {
  2423. $ts = array();
  2424. foreach ($vi['option'] as $tm => $tv) {
  2425. if (isset($vi['bit'][$tm]) && ($show & $tm) > 0) {
  2426. $ts[] = $tv;
  2427. }
  2428. }
  2429. $show = implode(',', $ts);
  2430. }
  2431. if ((isset($vi['child_name']) || (isset($vi['show']) && is_string($vi['show'])))) {
  2432. if (isset($vi['option'][$show]) && is_array($vi['option'][$show])) {
  2433. $show = $vi['option'][$show]['name'];
  2434. } else {
  2435. $show = isset($vi['option'][$show]) ? $vi['option'][$show] : $show;
  2436. }
  2437. }
  2438. //elseif ($config['state'] == 1 && (isset($vi['edit']) && $vi['edit']) || $ki == 'status')
  2439. elseif ($config['state'] == 1 && (isset($vi['edit']) && $vi['edit']))
  2440. {
  2441. $vi['name'] = 'up_col_' . $ki;
  2442. $vi['value'] = $v[$ki];
  2443. $m = 'select';
  2444. if (isset($vi['update']) && $vi['update'] == 'group') {
  2445. $m = 'group';
  2446. }
  2447. $show_edit = $this->value($vi['edit'], $data[$k], $config['struct']);
  2448. if ($show_edit) {
  2449. $show = Html::$m($vi, 'form-list', '', 'style="min-width: 100px;" data-old="'.$show.'" onchange="update($(this), \'' . $v['id'] . '\', \'' . $this->project . '\', \'' . $this->table . '\', \'\', \'' . $this->menu_id . '\')"');
  2450. } else {
  2451. if (isset($vi['option'][$show]) && is_array($vi['option'][$show])) {
  2452. $show = $vi['option'][$show]['name'];
  2453. } else {
  2454. $show = isset($vi['option'][$show]) ? $vi['option'][$show] : $show;
  2455. }
  2456. $show = '';
  2457. }
  2458. } else {
  2459. if (strstr($show, ',')) {
  2460. $temp = explode(',', $show);
  2461. $t = array();
  2462. foreach ($temp as $vv) {
  2463. if (isset($vi['option'][$vv]) && is_array($vi['option'][$vv])) {
  2464. $t[] = $vi['option'][$vv]['name'];
  2465. } elseif(isset($vi['option'][$vv])) {
  2466. $t[] = $vi['option'][$vv];
  2467. } else {
  2468. $t[] = $vv;
  2469. }
  2470. }
  2471. $show = implode('<br />', $t);
  2472. } elseif (isset($vi['option'][$show]) && is_array($vi['option'][$show])) {
  2473. if (isset($vi['option'][$show]['style'])) {
  2474. $vi['option'][$show]['name'] = '<font style="'.$vi['option'][$show]['style'].'">' . $vi['option'][$show]['name'] . '</font>';
  2475. }
  2476. $show = $vi['option'][$show]['name'];
  2477. } else {
  2478. $show = isset($vi['option'][$show]) ? $vi['option'][$show] : $show;
  2479. }
  2480. }
  2481. }
  2482. $text = $show;
  2483. if ($high && isset($high[$ki])) {
  2484. if (isset($v['s_' . $ki])) {
  2485. $text = $v['s_' . $ki];
  2486. $text = str_replace('<em class="dever_highlight">', '<font color="red" class="dever_highlight">', $text);
  2487. $text = str_replace('</em>', '</font>', $text);
  2488. } elseif (strlen($high[$ki]) > 1) {
  2489. $text = preg_replace('/('.$high[$ki].')/i', '<font color="red" class="dever_highlight">${1}</font>', $text, 1);
  2490. }
  2491. }
  2492. if (!isset($vi['option']) && isset($vi['edit']) && $vi['edit']) {
  2493. //$url = Dever::url($vi['edit'] . '?where_id=' . $v['id'] . '&col=' . $vi['col']. '&key=' . $this->project . '&table=' . $this->table);
  2494. $url = $this->url('updateAction');
  2495. $vi['edit'] = $vi['edit'] == 'textarea' ? $vi['edit'] : 'text';
  2496. $text = '<span class="edit" data-col="' . $ki . '" data-url="' . $url . '" data-id="' . $v['id'] . '" data-project="' . $this->project . '" data-table="' . $this->table . '" data-content="' . $show . '" data-type="' . $vi['edit'] . '">'.$text.'</span>';
  2497. $result[$k] .= '<td >' . $text . '</td>';
  2498. if (isset($return[$i][$ki])) {
  2499. $text = $return[$i][$ki] . $text;
  2500. }
  2501. $return[$i][$ki] = $text;
  2502. } else {
  2503. $result[$k] .= '<td>' . $text . '</td>';
  2504. if (isset($return[$i][$ki])) {
  2505. $text = $return[$i][$ki] . $text;
  2506. }
  2507. $return[$i][$ki] = $text;
  2508. }
  2509. if (isset($config['manage']['chart'])) {
  2510. $this->chart($config['manage']['chart'], $ki, $return[$i][$ki], $vi);
  2511. }
  2512. }
  2513. }
  2514. $button = $this->list_tbody_button($config, $data[$k]);
  2515. if ($button == '<td></td>') {
  2516. $button = str_replace('<td></td>', '<td>&nbsp;</td>', $button);
  2517. }
  2518. $result[$k] .= $button;
  2519. $return[$i]['manage'] = str_replace(array('<td>', '</td>'), '', $button);
  2520. $result[$k] .= '</tr>';
  2521. $i++;
  2522. }
  2523. }
  2524. if ($result) {
  2525. $this->state = true;
  2526. $result = implode('', $result);
  2527. if (!$this->manage_button) {
  2528. $result = str_replace('<td>&nbsp;</td>', '', $result);
  2529. }
  2530. } else {
  2531. $result = '';
  2532. }
  2533. if ($type) {
  2534. return $return;
  2535. }
  2536. return $result;
  2537. }
  2538. private function list_tbody_button($config, $data, $type = 'td')
  2539. {
  2540. $result = '';
  2541. $auth = Dever::load('manage/auth.oper', 3) != false || Dever::load('manage/auth.oper', 5) != false;
  2542. if (isset($config['manage']['_list']['value']['list']) && isset($config['manage']['_list']['value']['list'][0]) && $config['manage']['_list']['value']['list'][0] == '查看详情') {
  2543. $auth = true;
  2544. }
  2545. if ($auth && isset($config['manage']['_list']['value'])) {
  2546. //if (isset($config['manage']['_list']['value'])) {
  2547. $result = '<'.$type.'>';
  2548. if ($config['state'] == 2) {
  2549. if (isset($config['manage']['_list']['value']['update'])) {
  2550. unset($config['manage']['_list']['value']['update']);
  2551. }
  2552. if (isset($config['manage']['_list']['value']['delete'])) {
  2553. $config['manage']['_list']['value']['delete'] = '恢复';
  2554. }
  2555. }
  2556. foreach ($config['manage']['_list']['value'] as $kj => $vj) {
  2557. $pj = false;
  2558. $h = '<span class="am-icon-pencil-square-o"></span>';
  2559. if (strstr($kj, 'new') || strstr($kj, 'location') || strstr($kj, 'list')) {
  2560. $oper = true;
  2561. } elseif ($kj == 'delete') {
  2562. $oper = Dever::load('manage/auth.oper', 5);
  2563. $h = '<span class="am-icon-trash-o"></span>';
  2564. } else {
  2565. $oper = Dever::load('manage/auth.oper', 3);
  2566. }
  2567. if (is_array($vj) && isset($vj[1])) {
  2568. if (isset($vj[2])) {
  2569. $oper = $this->value($vj[2], $data);
  2570. }
  2571. if ($oper && strpos($vj[1], 'modal|') === false) {
  2572. $pj = $this->value($vj[1], $data);
  2573. $vjn = $vj[0];
  2574. }
  2575. } else {
  2576. $vjn = $vj;
  2577. }
  2578. if ($oper == true) {
  2579. $this->manage_button = true;
  2580. if ($kj == 'delete') {
  2581. $class = 'layui-btn layui-btn-danger';
  2582. } else {
  2583. $class = 'layui-btn';
  2584. }
  2585. if (layadmin()) {
  2586. $class .= ' layui-btn-xs';
  2587. }
  2588. if (strpos($kj, 'fast_list') !== false) {
  2589. if (!isset($vj[3])) {
  2590. $vj[3] = '';
  2591. }
  2592. $result .= '<a href="javascript:;" onclick="fastEdit($(this), \'' . $this->url('list', $data['id'], $pj) . '\', \''.$vj[0].'\', \''.$vj[3].'\', 1, 1)"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 '.$class.'">' . $vj[0] . '</button></a>&nbsp;&nbsp;';
  2593. } elseif (strpos($kj, 'fast_add') !== false) {
  2594. if (!isset($vj[3])) {
  2595. $vj[3] = '';
  2596. }
  2597. $result .= '<a href="javascript:;" onclick="fastEdit($(this), \'' . $this->url('update', false, $pj) . '\', \''.$vj[0].'\', \''.$vj[3].'\', 1)"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 '.$class.'">' . $vj[0] . '</button></a>&nbsp;&nbsp;';
  2598. } elseif (strpos($kj, 'fast') !== false) {
  2599. if (!isset($vj[3])) {
  2600. $vj[3] = '';
  2601. }
  2602. $result .= '<a href="javascript:;" onclick="fastEdit($(this), \'' . $this->url('update', $data['id'], $pj) . '\', \''.$vj[0].'\', \''.$vj[3].'\', 1)"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 '.$class.'">' . $vj[0] . '</button></a>&nbsp;&nbsp;';
  2603. } elseif (strpos($kj, 'edits') !== false) {
  2604. if (!isset($vj[1])) {
  2605. $vj[1] = '';
  2606. }
  2607. $result .= '<a href="javascript:;" onclick="fastEdit($(this), \'' . $this->url($kj, $data['id']) . '\', \''.$vj[0].'\', \''.$vj[1].'\', 1)"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 '.$class.'">' . $vj[0] . '</button></a>&nbsp;&nbsp;';
  2608. } elseif (strpos($kj, 'copy') !== false) {
  2609. $vj[1] = $this->value($vj[1], $data);
  2610. $vj[1] = Dever::load($vj[1]);
  2611. $result .= '<a style="cursor:pointer" data-clipboard-text="'.$vj[1].'" class="clipboard"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 '.$class.'">' . $vj[0] . '</button></a>&nbsp;&nbsp;';
  2612. } elseif (strpos($kj, 'edit') !== false) {
  2613. if (!isset($vj[1])) {
  2614. $vj[1] = '';
  2615. }
  2616. if (strstr($vj[1], 'http')) {
  2617. $url = $vj[1] . '&id=' . $data['id'];
  2618. } else {
  2619. $url = $this->url($kj, $data['id']);
  2620. }
  2621. $result .= '<a href="javascript:;" onclick="fastEdit($(this), \'' . $url . '\', \''.$vj[0].'\', \''.$vj[1].'\')"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 '.$class.'">' . $vj[0] . '</button></a>&nbsp;&nbsp;';
  2622. } elseif (strpos($kj, 'location') !== false) {
  2623. if (!isset($vj[1])) {
  2624. $vj[1] = '';
  2625. }
  2626. if (strstr($vj[1], 'http')) {
  2627. $url = $vj[1] . '&id=' . $data['id'];
  2628. } else {
  2629. $url = $this->url($kj, $data['id']);
  2630. }
  2631. $result .= '<a href="'.$url.'"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 '.$class.'">' . $vj[0] . '</button></a>&nbsp;&nbsp;';
  2632. } elseif (strpos($kj, 'oper') !== false) {
  2633. $content = '';
  2634. $title = '';
  2635. if (isset($vj[3])) {
  2636. $content = $this->value($vj[3], $data);
  2637. }
  2638. if (isset($vj[4])) {
  2639. $title = $vj[4];
  2640. }
  2641. $url = Dever::url($pj) . '&manage_log=update.' . $this->project . '.' . $this->table . '&manage_oper=' . $vj[0];
  2642. $result .= '<a href="javascript:;" onclick="load(\'' . $url . '\', \'' . $content . '\', \'' . $title . '\')"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 '.$class.'">' . $vj[0] . '</button></a>&nbsp;&nbsp;';
  2643. } elseif (strpos($kj, 'new') !== false) {
  2644. if (!isset($vj[1])) {
  2645. $vj[1] = '';
  2646. }
  2647. if (!isset($vj[2])) {
  2648. $vj[2] = '';
  2649. }
  2650. if (strstr($vj[1], 'http')) {
  2651. $url = $vj[1] . '&id=' . $data['id'];
  2652. } elseif($vj[2]) {
  2653. $url = Dever::url($this->value($vj[1], $data), $vj[2]);
  2654. } else {
  2655. $url = $this->url($kj, $data['id']);
  2656. }
  2657. $result .= '<a href="' . $url . '" target="_blank" class="oper_' . $kj . '"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 '.$class.'">' . $h . $vjn . '</button></a>&nbsp;&nbsp;';
  2658. } elseif (isset($vj[1]) && strpos($vj[1], 'modal|') !== false) {
  2659. $t = explode('|', $vj[1]);
  2660. $result .= '<a href="#dever_modal" data-toggle="modal" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 '.$class.'" onclick=' . $t[1] . ' msg-send="' . $this->value($t[2], $data) . '">' . $vj[0] . '</a>&nbsp;&nbsp;';
  2661. } elseif (isset($vj[1])) {
  2662. $result .= '<a href="' . $this->url($kj, $data['id'], $pj) . '" class="oper_' . $kj . '"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 '.$class.'">' . $h . $vjn . '</button></a>&nbsp;&nbsp;';
  2663. } elseif ($vj) {
  2664. $result .= '<span style="margin-left:5px;margin-right:10px;">' . $vj[0] . '</span>';
  2665. }
  2666. }
  2667. }
  2668. $result .= '</'.$type.'>';
  2669. }
  2670. return $result;
  2671. }
  2672. /**
  2673. * 多级分类
  2674. *
  2675. * @return array
  2676. */
  2677. private function tree($data, $config, $parent = 0)
  2678. {
  2679. $key = $config['name'] . '_id';
  2680. $result = array();
  2681. $this->treeData($data, $result, $key, $parent);
  2682. return $result;
  2683. }
  2684. private function treeData($array, &$result, $key, $parent_id = 0, $level = 0)
  2685. {
  2686. if (empty($array)) {
  2687. return;
  2688. }
  2689. $level++;
  2690. foreach ($array as $k => $v) {
  2691. if ((isset($v[$key]) && $v[$key] == $parent_id) || (isset($v['parent_id']) && $v['parent_id'] == $parent_id)) {
  2692. $v['level'] = $level;
  2693. $v['name'] = $this->treeName($v['name'], $level);
  2694. $result[] = $v;
  2695. unset($array[$k]);
  2696. $this->treeData($array, $result, $key, $v['id'], $level);
  2697. }
  2698. }
  2699. }
  2700. private function treeName($name, $level = 1)
  2701. {
  2702. $string = '';
  2703. if ($level > 1) {
  2704. /*
  2705. $num = 4;
  2706. $string = '-';
  2707. //STR_PAD_LEFT
  2708. $string = str_pad('|', $level * $num, $string);
  2709. */
  2710. $string = str_repeat(' ',$level-1);
  2711. $string .= '|—';
  2712. }
  2713. return $string . $name;
  2714. }
  2715. /**
  2716. * 列表页批量管理
  2717. *
  2718. * @return array
  2719. */
  2720. public function list_mul()
  2721. {
  2722. # 新增权限:更新权限
  2723. if (Dever::load('manage/auth.oper', 3) == false) {
  2724. return '';
  2725. }
  2726. $config = $this->config();
  2727. $result = '';
  2728. if ($this->state && isset($config['struct']) && isset($config['manage']['mul']) && $config['manage']['mul']) {
  2729. $mul = Dever::preInput('mul_');
  2730. $node = Html::node(array('class="am-u-sm-12" style="margin-top:10px;"', 'class="am-form-group am-input-group-sm"'));
  2731. $btn = '<button class="btn btn-danger layui-btn layui-btn-danger" onclick="$(\'#form1\').attr(\'action\', \'' . $this->url('list') . '\');list_mul($(this), 1)" type="button" style="height: 38px;margin-left:10px;">批量操作</button>';
  2732. $prefix = 'mul_';
  2733. $result .= $node[0];
  2734. $default = 0;
  2735. $option = array
  2736. (
  2737. 1 => '本页选中的数据',
  2738. );
  2739. # 只有当有搜索条件时才会出现
  2740. if (Dever::load('manage/auth.oper', 2) && $this->search == true) {
  2741. $option[2] = '所有页面的数据';
  2742. $default = 2;
  2743. }
  2744. $this->list_search_select($result, $mul, $prefix . 'type' . '" id="' . $prefix . 'type', '请选择要批量操作的数据', $option, $default);
  2745. foreach ($config['struct'] as $k => $v) {
  2746. if ($k == 'state' && (!isset($config['manage']['delete']) || (isset($config['manage']['delete']) && $config['manage']['delete']))) {
  2747. $v['option'] = Dever::config('base')->state;
  2748. if ($this->getState() == 2) {
  2749. unset($v['option'][2]);
  2750. } else {
  2751. unset($v['option'][1]);
  2752. }
  2753. $v['edit'] = true;
  2754. }
  2755. $select = false;
  2756. if (isset($v['mul'])) {
  2757. $select = $v['mul'];
  2758. } elseif (isset($v['edit'])) {
  2759. $select = $v['edit'];
  2760. }
  2761. if ($select) {
  2762. if (isset($v['mul_option']) && (is_array($v['mul_option']) || is_object($v['mul_option']))) {
  2763. $result .= '&nbsp;&nbsp;';
  2764. $this->list_search_select($result, $mul, $prefix . 'set_' . $k, $v['name'], $this->option($v['mul_option'], $select), $v['default']);
  2765. } elseif (isset($v['option']) && (is_array($v['option']) || is_object($v['option']))) {
  2766. $result .= '&nbsp;&nbsp;';
  2767. $this->list_search_select($result, $mul, $prefix . 'set_' . $k, $v['name'], $this->option($v['option'], $select), $v['default']);
  2768. }
  2769. }
  2770. }
  2771. $result .= $btn . $node[1];
  2772. }
  2773. //print_r($result);die;
  2774. return $result;
  2775. }
  2776. private function value($value, $data, $struct = array())
  2777. {
  2778. if (!$data) {
  2779. return $value;
  2780. }
  2781. if (strstr($value, '={') && !strstr($value, '"')) {
  2782. $value = '"' . $value . '"';
  2783. }
  2784. if (is_string($data)) {
  2785. $eval = '$value = ' . $value . ';';
  2786. eval($eval);
  2787. return $value;
  2788. }
  2789. if ($value == 'table' && $struct) {
  2790. $result = $this->struct_data($struct, $data);
  2791. $value = Dever::table($result);
  2792. } elseif (strpos($value, '{') !== false && strpos($value, '{"') === false) {
  2793. # 这里用到了/e,注意这里无论如何不能传入$_GET之类的用户参数 2015/7/21更新为callback方式
  2794. //$eval = '$value = ' . preg_replace('/{(.*?)}/e', "\$data['$1']", $value) . ';';
  2795. $func = function ($r) use ($data) {
  2796. if (isset($data[$r[1]])) {
  2797. return $data[$r[1]];
  2798. }
  2799. return false;
  2800. };
  2801. $value = preg_replace_callback('/{(.*?)}/', $func, $value);
  2802. if (strstr($value, '<script>')) {
  2803. $value = str_replace('<script>', '<script>$(document).ready(function(){', $value);
  2804. $value = str_replace('</script>', '});</script>', $value);
  2805. }
  2806. $eval = '$value = ' . $value . ';';
  2807. eval($eval);
  2808. }
  2809. return $value;
  2810. }
  2811. /**
  2812. * update
  2813. *
  2814. * @return array
  2815. */
  2816. public function update()
  2817. {
  2818. $config = $this->config();
  2819. $data = array();
  2820. if ($this->id) {
  2821. # 新增权限
  2822. if (isset($config['manage']['list']) && $config['manage']['list'] == 'update') {
  2823. $auth = 1;
  2824. } else {
  2825. $auth = 3;
  2826. }
  2827. if (Dever::load('manage/auth.oper', $auth) == false) {
  2828. Dever::alert('你没有权限');
  2829. }
  2830. $data = $this->load('one', $this->id);
  2831. } else {
  2832. # 新增权限
  2833. if (isset($config['manage']['list']) && $config['manage']['list'] == 'update') {
  2834. $auth = 1;
  2835. } else {
  2836. $auth = 4;
  2837. }
  2838. if (Dever::load('manage/auth.oper', $auth) == false) {
  2839. Dever::alert('你没有权限');
  2840. }
  2841. }
  2842. $data = $this->getAdminInfo($data);
  2843. $col = Dever::input('col');
  2844. $result = $this->update_struct($config, $col, $data);
  2845. //print_r($result);die;
  2846. return $result;
  2847. }
  2848. public function update_content()
  2849. {
  2850. $config = $this->config();
  2851. $data = array();
  2852. if ($this->id) {
  2853. # 新增权限
  2854. if (isset($config['manage']['list']) && $config['manage']['list'] == 'update') {
  2855. $auth = 1;
  2856. } else {
  2857. $auth = 3;
  2858. }
  2859. if (Dever::load('manage/auth.oper', $auth) == false) {
  2860. Dever::alert('你没有权限');
  2861. }
  2862. $data = $this->load('one', $this->id);
  2863. } else {
  2864. # 新增权限
  2865. if (isset($config['manage']['list']) && $config['manage']['list'] == 'update') {
  2866. $auth = 1;
  2867. } else {
  2868. $auth = 4;
  2869. }
  2870. if (Dever::load('manage/auth.oper', $auth) == false) {
  2871. Dever::alert('你没有权限');
  2872. }
  2873. }
  2874. $data = $this->getAdminInfo($data);
  2875. $col = Dever::input('col');
  2876. Dever::setInput('ajax', 1);
  2877. $result = '<div class="layui-col-md12"><div class="layui-card" {style}><div class="layui-card-body">';
  2878. $desc = Dever::load('manage/database.info#updateDesc');
  2879. if ($desc) {
  2880. $result .= $desc;
  2881. }
  2882. if (isset($config['manage']['lang']) && $this->lang_set) {
  2883. $result .= '<div class="layui-tab layui-tab-card"><ul class="layui-tab-title">';
  2884. $tab = '<div class="layui-tab-content">';
  2885. $i = 0;
  2886. if ($col) {
  2887. $col = explode(',', $col);
  2888. $config['manage']['lang'] = explode(',', $config['manage']['lang']);
  2889. $config['manage']['lang'] = array_intersect($config['manage']['lang'], $col);
  2890. $config['manage']['lang'] = implode(',', $config['manage']['lang']);
  2891. $col = implode(',', $col);
  2892. }
  2893. foreach (Dever::config('base')->lang_set as $k => $v) {
  2894. if ($i == 0) {
  2895. $prefix = '';
  2896. } else {
  2897. $prefix = $k;
  2898. $col = $config['manage']['lang'];
  2899. //$prefix = 'l-l' . $k . 'l-l';
  2900. //$data = $this->load('one', $this->id, $this->table . '__' . $k);
  2901. }
  2902. if (isset($config['manage']['tab']) && $config['manage']['tab']) {
  2903. $content = '<div class="layui-tab layui-tab-brief" lay-filter="component-tabs-brief"><ul class="layui-tab-title">';
  2904. $tab_content = '<div class="layui-tab-content">';
  2905. $j = 0;
  2906. foreach ($config['manage']['tab'] as $k1 => $v1) {
  2907. $html = $this->update_struct($config, $col, $data, $k1, $prefix);
  2908. if ($html) {
  2909. $class_0 = $class_1 = '';
  2910. if ($j == 0) {
  2911. $class_0 = 'layui-this';
  2912. $class_1 = 'layui-show';
  2913. }
  2914. $content .= '<li class="'.$class_0.'">'.$v1.'</li>';
  2915. $tab_content .= '<div class="layui-tab-item '.$class_1.'">'.$html.'</div>';
  2916. $j++;
  2917. }
  2918. }
  2919. $tab_content .= '</div>';
  2920. $content .= '</ul>' . $tab_content . '</div>';
  2921. if ($content) {
  2922. $class_0 = $class_1 = '';
  2923. if ($i == 0) {
  2924. $class_0 = 'layui-this';
  2925. $class_1 = 'layui-show';
  2926. }
  2927. $result .= '<li class="'.$class_0.'">'.$v.'</li>';
  2928. $tab .= '<div class="layui-tab-item '.$class_1.'">'.$content.'</div>';
  2929. $i++;
  2930. }
  2931. } else {
  2932. $content = $this->update_struct($config, $col, $data, -1, $prefix);
  2933. if ($content) {
  2934. $class_0 = $class_1 = '';
  2935. if ($i == 0) {
  2936. $class_0 = 'layui-this';
  2937. $class_1 = 'layui-show';
  2938. }
  2939. $result .= '<li class="'.$class_0.'">'.$v.'</li>';
  2940. $tab .= '<div class="layui-tab-item '.$class_1.'">'.$content.'</div>';
  2941. $i++;
  2942. }
  2943. }
  2944. }
  2945. $tab .= '</div>';
  2946. $result .= '</ul>' . $tab . '</div>';
  2947. } elseif (isset($config['manage']['tab']) && $config['manage']['tab']) {
  2948. $result .= '<div class="layui-tab layui-tab-brief" lay-filter="component-tabs-brief"><ul class="layui-tab-title">';
  2949. $tab = '<div class="layui-tab-content">';
  2950. $i = 0;
  2951. foreach ($config['manage']['tab'] as $k => $v) {
  2952. $content = $this->update_struct($config, $col, $data, $k);
  2953. if ($content) {
  2954. $class_0 = $class_1 = '';
  2955. if ($i == 0) {
  2956. $class_0 = 'layui-this';
  2957. $class_1 = 'layui-show';
  2958. }
  2959. $result .= '<li class="'.$class_0.'">'.$v.'</li>';
  2960. $tab .= '<div class="layui-tab-item '.$class_1.'">'.$content.'</div>';
  2961. $i++;
  2962. }
  2963. }
  2964. $tab .= '</div>';
  2965. $result .= '</ul>' . $tab . '</div>';
  2966. } else {
  2967. $result .= $this->update_struct($config, $col, $data);
  2968. }
  2969. if (isset($this->card) && $this->card) {
  2970. $result = str_replace('{style}', 'style="display:none"', $result);
  2971. }
  2972. $button = '';
  2973. if (Dever::input('fast') != 1) {
  2974. $button = '<div class="layui-card-body" id="update_button"><div class="layui-form-item">' . $this->update_button() . '</div></div>';
  2975. }
  2976. $result .= '</div>'.$button.'</div></div>';
  2977. //print_r($result);die;
  2978. return $result;
  2979. }
  2980. public function update_struct($config, $col, $data, $tab = -1, $prefix = '', $layadmin = false)
  2981. {
  2982. if (!$layadmin) {
  2983. $layadmin = layadmin();
  2984. }
  2985. $result = array();
  2986. $upload_call = '';
  2987. if (isset($config['manage']['upload'])) {
  2988. $upload_call = $this->value($config['manage']['upload'], $data);
  2989. }
  2990. foreach ($config['struct'] as $k => $v) {
  2991. if (isset($config['manage']['lang']) && $this->lang_set && isset($v['sync']) && strpos($k, '-')) {
  2992. continue;
  2993. }
  2994. $state = false;
  2995. if ($tab == 0) {
  2996. if (!isset($v['tab']) || (isset($v['tab']) && $v['tab'] == $tab)) {
  2997. $state = true;
  2998. }
  2999. } elseif ($tab > 0) {
  3000. if (isset($v['tab']) && $v['tab'] == $tab) {
  3001. $state = true;
  3002. }
  3003. } else {
  3004. $state = true;
  3005. }
  3006. if (isset($v['update']) && $v['update'] && $state) {
  3007. if ($col && !strstr(',' . $col . ',', ',' . $k . ',')) {
  3008. continue;
  3009. }
  3010. //处理权限
  3011. if (isset($v['auth'])) {
  3012. $auth = $this->value($v['auth'], $data);
  3013. if (!$auth) {
  3014. continue;
  3015. }
  3016. }
  3017. $index = $k;
  3018. if ($prefix && !strstr($k, '-')) {
  3019. $k = $prefix . '_' . $k;
  3020. }
  3021. # 处理show模式下的class
  3022. $class = $this->update_class($k, $v, '', $data);
  3023. $result[$k] = '<div class="form-group ' . $class . '"><div class="margin-top">';
  3024. $style = '';
  3025. if ($v['update'] == 'hidden') {
  3026. $style = 'style="display:none"';
  3027. }
  3028. if ($layadmin) {
  3029. $result[$k] = '<div class="layui-form-item ' . $class . '" '.$style.'><div classs="layui-col-lg6">';
  3030. if (is_array($v['update'])) {
  3031. $result[$k] = '<div class="layui-form-item ' . $class . '" '.$style.'><div class="layui-tab layui-tab-card">';
  3032. }
  3033. }
  3034. if ($upload_call) {
  3035. $v['upload_call'] = $upload_call . '&key=' . $k;
  3036. }
  3037. if (isset($config['manage']['sku']) && $v['update'] == 'sku') {
  3038. $v['sku'] = $config['manage']['sku'];
  3039. $v['data'] = $data;
  3040. }
  3041. $result[$k] .= $this->create_update_html($k, $v, $data, false, $prefix);
  3042. $result[$k] .= '</div></div>';
  3043. } elseif (!$col && isset($v['class'])) {
  3044. # 分割线
  3045. $v['name'] = $this->value($v['name'], array('test' => 1));
  3046. if (isset($v['right'])) {
  3047. $this->card_right = true;
  3048. }
  3049. $this->card = true;
  3050. $result[$k] = Html::hr($v);
  3051. }
  3052. }
  3053. if (Dever::input('ajax') == 1) {
  3054. return implode('', $result);
  3055. }
  3056. return $result;
  3057. }
  3058. public function card()
  3059. {
  3060. if (isset($this->card_right)) {
  3061. return 'layui-col-md6';
  3062. }
  3063. return 'layui-col-md12';
  3064. }
  3065. public function layui_card()
  3066. {
  3067. if (isset($this->card)) {
  3068. return false;
  3069. }
  3070. return true;
  3071. }
  3072. /**
  3073. * update_class
  3074. *
  3075. * @return string
  3076. */
  3077. public function update_class($name, $param, $prefix = '', $data = array())
  3078. {
  3079. $class = '';
  3080. $key = 'show';
  3081. if (isset($param[$key]) && $param[$key]) {
  3082. $parent = array();
  3083. $child = array();
  3084. if (is_string($param[$key])) {
  3085. parse_str($param[$key], $param[$key]);
  3086. }
  3087. if (is_array($param[$key])) {
  3088. foreach ($param[$key] as $k => $v) {
  3089. if ($k == 'no') {
  3090. $child[$k . '_' . $v] = $key . '_no';
  3091. } elseif (strpos($v, '/')) {
  3092. $parent[$k] = $key . '_' . $k;
  3093. $k = $k . '_ajax';
  3094. $value = '';
  3095. if (isset($data[$name])) {
  3096. $value = $data[$name];
  3097. }
  3098. $v = str_replace('?', '?key='.$name.'&value='.$value.'&source='.$this->name.'&', $v);
  3099. $child[$k] = $key . '_' . $k .'" dever-ajax="'.Dever::url($v).'"';
  3100. } else {
  3101. if (strpos($v, ',')) {
  3102. $temp = explode(',', $v);
  3103. foreach ($temp as $v1) {
  3104. $show = $k . '_' . $v1;
  3105. if ($prefix) {
  3106. $k = str_replace($name, $k, $prefix);
  3107. $show = str_replace($name, $show, $prefix);
  3108. }
  3109. $parent[$k] = $key . '_' . $k;
  3110. $child[$show] = $key . '_' . $show;
  3111. }
  3112. } else {
  3113. $show = $k . '_' . $v;
  3114. if ($prefix) {
  3115. $k = str_replace($name, $k, $prefix);
  3116. $show = str_replace($name, $show, $prefix);
  3117. }
  3118. $parent[$k] = $key . '_' . $k;
  3119. $child[$show] = $key . '_' . $show;
  3120. }
  3121. }
  3122. }
  3123. }
  3124. $class = implode(' ', $parent) . ' ' . implode(' ', $child);
  3125. }
  3126. if (isset($param['control'])) {
  3127. $class .= ' ' . $key . '_input';
  3128. }
  3129. return $class;
  3130. }
  3131. /**
  3132. * update_html
  3133. *
  3134. * @return string
  3135. */
  3136. public function create_update_html($key, $value, $data = array(), $index = false, $prefix = '')
  3137. {
  3138. $result = '';
  3139. $value['ext'] = $value['col'] = $key;
  3140. $value['update'] = $value['update'] ? $value['update'] : 'text';
  3141. if (isset($value['match']) && $value['match'] != 'option') {
  3142. if (is_string($value['match']) && strpos($value['match'], '/') !== false) {
  3143. if (strstr($value['match'], 'option||')) {
  3144. $value['valid'] = 'validate[custom[' . $key . ']]';
  3145. } else {
  3146. $value['valid'] = 'validate[required,custom[' . $key . ']]';
  3147. }
  3148. } else {
  3149. $value['valid'] = 'validate[required]';
  3150. }
  3151. }
  3152. if (is_string($value['update']) && strpos($value['update'], 'copy.') !== false) {
  3153. $value['value'] = $value['update'];
  3154. $value['update'] = 'hidden';
  3155. }
  3156. if (!$index) {
  3157. $index = $key;
  3158. }
  3159. $this->update_html($value, $key, $index, $data, $result, $prefix);
  3160. return $result;
  3161. }
  3162. /**
  3163. * update_html
  3164. *
  3165. * @return string
  3166. */
  3167. public function update_html($param, $key, $index, $data, &$result, $prefix = '', $ext = 'update')
  3168. {
  3169. if (isset($param['name']) && isset($param['update']) && $param['update'] != 'hidden' && $param['update'] != 'load') {
  3170. $result .= Html::pageLeft($param);
  3171. }
  3172. if ($param['update']) {
  3173. $order = true;
  3174. # 名称带前缀
  3175. $param['name'] = $ext . '_' . $param['ext'];
  3176. $param['index'] = $index;
  3177. //$param['value'] = '';
  3178. # 得到当前的值
  3179. //if (isset($data[$index]) && !isset($param['value'])) {
  3180. if (isset($data[$index])) {
  3181. $param['value'] = $data[$index];
  3182. }
  3183. # 得到下级的值
  3184. if (isset($param['child_value']) && isset($data['id'])) {
  3185. $param['child_value'] = $this->value($param['child_value'], $data);
  3186. }
  3187. # 验证option是否是匿名函数
  3188. if (isset($param['option'])) {
  3189. $param['option'] = $this->option($param['option']);
  3190. }
  3191. if (isset($data[$index]) && !isset($param['value']) && isset($param['key']) && $param['update'] != 'editor') {
  3192. $param['value'] = Dever::upload($data[$index]);
  3193. }
  3194. # 处理下级字段
  3195. if (isset($param['child'])) {
  3196. $param['child'] = $this->option($param['child']);
  3197. if (isset($data[$key . '_parent'])) {
  3198. $param['parent_value'] = $data[$key . '_parent'];
  3199. }
  3200. }
  3201. # 设置默认值
  3202. if (isset($param['default'])) {
  3203. $param['default'] = $this->option($param['default']);
  3204. }
  3205. # 处理同步
  3206. if (isset($param['sync']) && strpos($key, '-') && $param['update'] != 'load') {
  3207. $temp = explode('-', $key);
  3208. if (isset($data[$param['sync'][0]])) {
  3209. if (isset($temp[2])) {
  3210. $m = 'one';
  3211. } else {
  3212. $m = 'select';
  3213. }
  3214. if ($data[$param['sync'][0]] > 0) {
  3215. $load = Dever::load($temp[0] . '/' . $temp[1] . '-' . $m, array('option_' . $param['sync'][1] => $data[$param['sync'][0]], 'orders' => array('id' => 'asc')));
  3216. } else {
  3217. $load = Dever::load($temp[0] . '/' . $temp[1] . '-' . $m, array('option_' . $param['sync'][3] => $data[$param['sync'][2]], 'option_' . $param['sync'][4] => $data[$param['sync'][0]], 'orders' => array('id' => 'asc')));
  3218. }
  3219. if ($m == 'one') {
  3220. $param['value'] = isset($load[$temp[2]]) ? $load[$temp[2]] : $param['default'];
  3221. } else {
  3222. $param['value'] = $load;
  3223. }
  3224. }
  3225. if (!isset($temp[2]) && is_array($param['update'])) {
  3226. $order = false;
  3227. if (isset($param['update'][0]) && is_string($param['update'][0]) && strstr($param['update'][0], '.')) {
  3228. if (isset($param['update'][1]) && $param['update'][1]) {
  3229. $param['update_load'] = $param['update'][0];
  3230. $param['update'] = 'load';
  3231. } else {
  3232. $param['update'] = Dever::load($param['update'][0]);
  3233. }
  3234. } else {
  3235. $config = Dever::db($temp[0] . '/' . $temp[1])->config;
  3236. $param['update'] = $config['struct'];
  3237. }
  3238. if (isset($config['manage']['tab'])) {
  3239. $param['prefix'] = $prefix;
  3240. $param['tab_config'] = $config['manage']['tab'];
  3241. if (isset($config['manage']['tab'])) {
  3242. $param['lang'] = $config['manage']['lang'];
  3243. }
  3244. }
  3245. //$param['value'] = Dever::db($temp[0] . '/' . $temp[1]);
  3246. }
  3247. }
  3248. $method = $param['update'];
  3249. if (is_array($method)) {
  3250. $c = '';
  3251. if (layadmin()) {
  3252. $c = 'layui-tab-title';
  3253. }
  3254. $delete = true;
  3255. if (isset($param['update_type']) && $param['update_type'] == 2) {
  3256. $table = '<style>.layui-table .layui-input, .layui-table .xm-select-parent{width:100%}</style>';
  3257. $table .= '<table class="layui-table">';
  3258. $table_header = '<thead><tr>';
  3259. $table_body = '<tbody>';
  3260. $table_body .= '<tr class="table_copy" style="display:none;">';
  3261. foreach ($param['update'] as $hk => $hv) {
  3262. if ($this->id && $hk === 'id') {
  3263. $hv['update'] = 'hidden';
  3264. }
  3265. if (isset($hv['update']) && $hv['update']) {
  3266. $n = $hv['name'];
  3267. unset($hv['name']);
  3268. $s = '';
  3269. $hv['ext'] = $param['name'] . '_c_-1_i_' . $hk;
  3270. $this->update_html($hv, $hk, $hk, array(), $s, '', 'up');
  3271. if ($hv['update'] == 'hidden') {
  3272. $table_header .= '<td style="display:none;">'.$n.'</td>';
  3273. $table_body .= '<td style="display:none;">'.$s.'</td>';
  3274. } else {
  3275. $table_header .= '<td>'.$n.'</td>';
  3276. $table_body .= '<td>'.$s.'</td>';
  3277. }
  3278. }
  3279. }
  3280. $table_header .= '<td>操作</td>';
  3281. $table_body .= '<td><a href="javascript:;" onclick="var self = $(this);var index = layer.confirm(\'确定进行此项操作吗?\', function(i, l){self.parent().parent().remove();layer.close(index);});" class="layui-btn layui-btn-xs">删除</a></td>';
  3282. $table_body .= '</tr>';
  3283. if (isset($param['value']) && $param['value']) {
  3284. if (!is_array($param['value'])) {
  3285. $param['value'] = Dever::json_decode($param['value']);
  3286. }
  3287. foreach ($param['value'] as $bk => $bv) {
  3288. $table_body .= '<tr>';
  3289. foreach ($param['update'] as $hk => $hv) {
  3290. if ($this->id && $hk === 'id') {
  3291. $hv['update'] = 'hidden';
  3292. }
  3293. if (isset($hv['update']) && $hv['update']) {
  3294. unset($hv['name']);
  3295. $s = '';
  3296. $hv['ext'] = $param['name'] . '_c_' . $bk . '_i_' . $hk;
  3297. $this->update_html($hv, $hk, $hk, $bv, $s);
  3298. if ($hv['update'] == 'hidden') {
  3299. $table_body .= '<td style="display:none;">'.$s.'</td>';
  3300. } else {
  3301. $table_body .= '<td>'.$s.'</td>';
  3302. }
  3303. }
  3304. }
  3305. $table_body .= '<td><a href="javascript:;" onclick="var self = $(this);var index = layer.confirm(\'确定进行此项操作吗?\', function(i, l){self.parent().parent().remove();layer.close(index);});" class="layui-btn layui-btn-xs">删除</a></td>';
  3306. $table_body .= '</tr>';
  3307. }
  3308. }
  3309. $table_body .= '</tbody>';
  3310. $table_header .= '</tr></thead>';
  3311. $table .= $table_body . $table_header;
  3312. $table .= '</table>';
  3313. $result .= $table;
  3314. } else {
  3315. if (isset($param['option'])) {
  3316. $delete = false;
  3317. $result .= '<ul class="nav nav-tabs '.$c.'" style="height:100%;">{tab}</ul>';
  3318. $order = array
  3319. (
  3320. 'col' => $key,
  3321. 'name' => $param['desc'],
  3322. 'default' => '1',
  3323. 'desc' => $param['desc'],
  3324. 'match' => 'is_string',
  3325. 'update' => 'hidden',
  3326. 'option' => $param['option']
  3327. );
  3328. array_unshift($method, $order);
  3329. if (isset($param['value']) && $param['value']) {
  3330. $value = Dever::array_decode($param['value']);
  3331. $param['value'] = array();
  3332. if (!$value) {
  3333. foreach ($param['option'] as $k => $v) {
  3334. if (isset($v['name'])) {
  3335. $v = $v['name'];
  3336. }
  3337. $param['value'][$v][$key] = $k;
  3338. }
  3339. } else {
  3340. foreach ($param['option'] as $k => $v) {
  3341. if (isset($v['name'])) {
  3342. $v = $v['name'];
  3343. }
  3344. foreach ($value[$k-1] as $k1 => $v1) {
  3345. $param['value'][$v][$k1] = $v1;
  3346. }
  3347. }
  3348. }
  3349. } else {
  3350. $param['value'] = array();
  3351. foreach ($param['option'] as $k => $v) {
  3352. if (isset($v['name'])) {
  3353. $v = $v['name'];
  3354. }
  3355. $param['value'][$v][$key] = $k;
  3356. }
  3357. }
  3358. } else {
  3359. $result .= '<ul class="nav nav-tabs '.$c.'" style="height:100%;">{tab}<li style="margin:0px;padding:0 15px;"><a href="javascript:;" class="dever_form_add" toggle_key="' . $key . '">增加一条</a></li></ul>';
  3360. if ($order) {
  3361. $order = array
  3362. (
  3363. 'col' => 'order',
  3364. 'name' => '排序-按照数字正序排列',
  3365. 'default' => '1',
  3366. 'desc' => '排序',
  3367. 'match' => 'is_string',
  3368. 'update' => 'text',
  3369. );
  3370. array_unshift($method, $order);
  3371. }
  3372. }
  3373. $tab = '';
  3374. $this->update_child(array(), $method, $key, $result, -1, $param, $delete);
  3375. if (isset($param['value']) && $param['value']) {
  3376. if (!is_array($param['value'])) {
  3377. $param['value'] = Dever::array_decode($param['value']);
  3378. }
  3379. if (is_array($param['value'])) {
  3380. $i = 0;
  3381. foreach ($param['value'] as $k => $v) {
  3382. $n = $k;
  3383. if (is_string($k)) {
  3384. $k = $i;
  3385. }
  3386. $this->update_child($v, $method, $key, $result, $k, $param, $delete);
  3387. $active = '';
  3388. if ($k == 0) {
  3389. $active = 'active';
  3390. }
  3391. if (layadmin() && $active) {
  3392. $active .= ' layui-this';
  3393. }
  3394. $k = $k + 1;
  3395. if (!is_string($n)) {
  3396. $n = '第' . $k . '条';
  3397. }
  3398. if (isset($param['option']) && count($param['option']) <= 1) {
  3399. } else {
  3400. $tab .= '<li class="' . $active . '" style="margin:0px;padding:0 15px;"><a href="javascript:;" id="tab-' . $key . '-child-' . $k . '" toggle_key="' . $key . '" toggle_id="' . $k . '" toggle_child=".dever_' . $key . '_child" toggle="#' . $key . '-child-' . $k . '" onclick="showToggle($(this))">'.$n.'</a></li>';
  3401. $i++;
  3402. }
  3403. }
  3404. }
  3405. } else {
  3406. $this->update_child(array(), $method, $key, $result, 0, $param, $delete);
  3407. $tab = '<li class="active layui-this" style="margin:0px;padding:0 15px;"><a href="javascript:;" id="tab-' . $key . '-child-1" toggle_key="' . $key . '" toggle_id="1" toggle_child=".dever_' . $param['col'] . '_child" toggle="#' . $key . '-child-1" onclick="showToggle($(this))">第1条</a></li>';
  3408. }
  3409. if ($tab) {
  3410. $result = str_replace('{tab}', $tab, $result);
  3411. } else {
  3412. $result = str_replace('<ul class="nav nav-tabs layui-tab-title" style="height:100%;">{tab}</ul>', '', $result);
  3413. }
  3414. }
  3415. } else {
  3416. if (isset($param['update_input']) && isset($data[$index . '_input'])) {
  3417. $param['update_input_data'] = explode(',', $data[$index . '_input']);
  3418. }
  3419. $param['project'] = $this->project;
  3420. $param['table'] = $this->table;
  3421. if (isset($param['upload_search'])) {
  3422. $param['upload_search'] = $this->value($param['upload_search'], $data + $param);
  3423. }
  3424. if (isset($param['upload_search_value'])) {
  3425. $param['upload_search_value'] = $this->value($param['upload_search_value'], $data + $param);
  3426. }
  3427. $param['where_id'] = $this->id;
  3428. $result .= Html::$method($param);
  3429. }
  3430. if (isset($param['desc']) && ($param['update'] == 'text' || $param['update'] == 'password')) {
  3431. $result .= Html::desc($param['desc']);
  3432. }
  3433. }
  3434. }
  3435. /**
  3436. * update_action
  3437. *
  3438. * @return array
  3439. */
  3440. private function update_child($data, $param, $key, &$result, $index, $config, $delete = true)
  3441. {
  3442. if (isset($config['tab_config']) && $config['tab_config']) {
  3443. if ($index != 0) {
  3444. $style = 'display:none;';
  3445. } else {
  3446. $style = '';
  3447. }
  3448. $result .= '<div class="layui-tab layui-tab-brief dever_' . $key . '_child dever_form_add_child" lay-filter="component-tabs-brief" style="'.$style.'" id="' . $key . '-child-' . ($index + 1) . '"><ul class="layui-tab-title">';
  3449. $tab = '<div class="layui-tab-content">';
  3450. $i = 0;
  3451. foreach ($config['tab_config'] as $k => $v) {
  3452. $content = $this->update_child_data($data, $param, $key, $index, $k, $config);
  3453. if ($content) {
  3454. $class_0 = $class_1 = '';
  3455. if ($i == 0) {
  3456. $class_0 = 'layui-this';
  3457. $class_1 = 'layui-show';
  3458. }
  3459. $result .= '<li class="'.$class_0.'">'.$v.'</li>';
  3460. $tab .= '<div class="layui-tab-item '.$class_1.'">'.$content.'</div>';
  3461. $i++;
  3462. }
  3463. }
  3464. $tab .= '</div>';
  3465. $result .= '</ul>' . $tab . '</div>';
  3466. } else {
  3467. $style = 'margin:10px;';
  3468. if ($index != 0) {
  3469. $style = 'display:none;margin:10px;';
  3470. }
  3471. $result .= '<div id="' . $key . '-child-' . ($index + 1) . '" class="dever_' . $key . '_child dever_form_add_child" style="' . $style . '">';
  3472. if ($delete) {
  3473. $result .= '<div class="dever_form_delete" style="cursor:pointer">[删除]</div>';
  3474. }
  3475. $result .= $content = $this->update_child_data($data, $param, $key, $index, 0, $config);
  3476. $result .= '</div>';
  3477. }
  3478. }
  3479. private function update_child_data($data, $param, $key, $index, $tab = -1, $config = array())
  3480. {
  3481. $result = '';
  3482. foreach ($param as $k => $v) {
  3483. if (is_string($k)) {
  3484. $v['col'] = $k;
  3485. }
  3486. if ($this->id && $v['col'] == 'id') {
  3487. $v['update'] = 'hidden';
  3488. }
  3489. if (!isset($v['update'])) {
  3490. continue;
  3491. }
  3492. if (isset($config['prefix']) && $config['prefix']) {
  3493. if (isset($config['lang']) && $config['lang'] && !in_array($v['col'], $config['lang'])) {
  3494. continue;
  3495. }
  3496. $v['col'] = $config['prefix'] . '_' . $v['col'];
  3497. }
  3498. $state = false;
  3499. if ($tab == 0) {
  3500. if (!isset($v['tab']) || (isset($v['tab']) && $v['tab'] == $tab)) {
  3501. $state = true;
  3502. }
  3503. } elseif ($tab > 0) {
  3504. if (isset($v['tab']) && $v['tab'] == $tab) {
  3505. $state = true;
  3506. }
  3507. } else {
  3508. $state = true;
  3509. }
  3510. if (isset($v['update']) && $v['update'] && $state) {
  3511. $v['type'] = $v['update'];
  3512. $prefix = '';
  3513. if ($index < 0) {
  3514. $v['ext'] = $key . '_c_' . $v['col'];
  3515. $prefix = $v['ext'];
  3516. } else {
  3517. $v['ext'] = $key . '_c_' . $index . '_i_' . $v['col'];
  3518. $prefix = $v['ext'];
  3519. }
  3520. if ($v['col'] == 'order') {
  3521. $v['default'] = $index+1;
  3522. }
  3523. $class = $this->update_class($v['col'], $v, $prefix);
  3524. if ($v['update'] == 'hidden') {
  3525. $result .= '<div class="form-group ' . $class . '" style="display:none">';
  3526. $this->update_html($v, $key, $v['col'], $data, $result);
  3527. $result .= '</div>';
  3528. } else {
  3529. $result .= '<div class="form-group ' . $class . '" style="margin-top:10px">';
  3530. $this->update_html($v, $key, $v['col'], $data, $result);
  3531. $result .= '</div>';
  3532. }
  3533. }
  3534. }
  3535. return $result;
  3536. }
  3537. /**
  3538. * update_action
  3539. *
  3540. * @return array
  3541. */
  3542. public function update_action_api()
  3543. {
  3544. $method = false;
  3545. $config = $this->config();
  3546. $input = Dever::preInput('update_');
  3547. if ($this->id) {
  3548. # 新增权限
  3549. if (isset($config['manage']['list']) && $config['manage']['list'] == 'update') {
  3550. $auth = 1;
  3551. } else {
  3552. $auth = 3;
  3553. }
  3554. if (Dever::load('manage/auth.oper', $auth) == false) {
  3555. Dever::alert('你没有权限');
  3556. }
  3557. Dever::setInput('where_id', $this->id);
  3558. //Dever::setInput('update_where_id', $this->id);
  3559. $info = $this->load('one', $this->id);
  3560. if ($info) {
  3561. $method = 'update';
  3562. $col = Dever::input('col');
  3563. $value = Dever::input('value');
  3564. if ($col && $value) {
  3565. $method = 'update_' . $col;
  3566. //Dever::setInput('set_' . $col, $value);
  3567. //Dever::setInput('update_' . $col, $value);
  3568. $param['where_id'] = $this->id;
  3569. $param['set_' . $col] = $value;
  3570. $this->load($method, $param);
  3571. $struct = $this->struct_data($config['struct'], array($col => $value));
  3572. Log::add($this->project, $this->table, $this->menu_id, '', $method, $struct, $this->id);
  3573. Dever::out('yes');
  3574. return;
  3575. }
  3576. $prefix = 'set';
  3577. } else {
  3578. $method = 'insert';
  3579. $prefix = 'add';
  3580. }
  3581. }
  3582. if (!$method) {
  3583. # 新增权限
  3584. if (isset($config['manage']['list']) && $config['manage']['list'] == 'update') {
  3585. $auth = 1;
  3586. } else {
  3587. $auth = 4;
  3588. }
  3589. if (Dever::load('manage/auth.oper', $auth) == false) {
  3590. Dever::alert('你没有权限');
  3591. }
  3592. $method = 'insert';
  3593. $prefix = 'add';
  3594. }
  3595. if ($method && $input) {
  3596. $update = $order = $update_other = array();
  3597. $i = 0;
  3598. $c = array();
  3599. foreach ($input as $k => $v) {
  3600. if ($v === '') {
  3601. $v = 'null';
  3602. }
  3603. if ($v && is_string($v) && strpos($v, 'copy.') !== false) {
  3604. $temp = str_replace('copy.', '', $v);
  3605. if (isset($input['update_' . $temp])) {
  3606. $v = $input['update_' . $temp];
  3607. }
  3608. }
  3609. if (strpos($k, '_c_') !== false) {
  3610. if ($v == 'null') {
  3611. $v = '';
  3612. }
  3613. $temp = explode('_c_', $k);
  3614. $h = $temp[0];
  3615. $k = str_replace('update_', $prefix . '_', $h);
  3616. if (!isset($c[$k])) {
  3617. $c[$k] = array();
  3618. }
  3619. if (strpos($temp[1], '_i_') !== false) {
  3620. $temp = explode('_i_', $temp[1]);
  3621. if (!isset($c[$k][$temp[1]])) {
  3622. $c[$k][$temp[1]] = 0;
  3623. } else {
  3624. $c[$k][$temp[1]]++;
  3625. }
  3626. $num = $c[$k][$temp[1]];
  3627. if (strpos($h, '-')) {
  3628. $h = str_replace('update_', '', $h);
  3629. if (isset($config['struct'][$h]) && isset($config['struct'][$h]['sync'])) {
  3630. $s_col = $config['struct'][$h]['sync'][0];
  3631. $m_col = $config['struct'][$h]['sync'][1];
  3632. if ($s_col == 'id') {
  3633. $s_value = $this->id;
  3634. } else {
  3635. $s_one = $this->load('one', $this->id);
  3636. $s_value = $s_one[$s_col];
  3637. }
  3638. $t = explode('-', $h);
  3639. $index = $t[0] . '/' . $t[1];
  3640. if (Dever::zero($v)) {
  3641. $v = (string) $v;
  3642. } elseif (!$v) {
  3643. $v = 'null';
  3644. }
  3645. $update_col[$i][$index] = $m_col;
  3646. $update_set[$i][$index][$num]['set_' . $temp[1]] = $v;
  3647. $update_add[$i][$index][$num]['add_' . $temp[1]] = $v;
  3648. $update_add[$i][$index][$num]['add_' . $m_col] = $s_value;
  3649. $update_deletes[$i][$index][$m_col] = $s_value;
  3650. $update_id[$i][$index][$num][$m_col] = $s_value;
  3651. if ($this->id && $temp[1] == 'id') {
  3652. $update_id[$i][$index][$num]['id'] = $v;
  3653. }
  3654. }
  3655. } else {
  3656. $update[$i][$k][$num][$temp[1]] = $v;
  3657. if ($temp[1] == 'order') {
  3658. $order[$i][$k][$num] = $v;
  3659. }
  3660. }
  3661. } else {
  3662. //$update[$i][$k][$c][$temp[1]] = $v;
  3663. }
  3664. } elseif (strpos($k, '__') !== false) {
  3665. $temp1 = explode('__', $k);
  3666. $temp2 = explode('_', $temp1[0]);
  3667. $i = $temp2[1] - 1;
  3668. if (strpos($k, 'where_id') !== false) {
  3669. //$update[$i]['where_id'] = $v;
  3670. } else {
  3671. $update[$i]['add_' . $temp1[1]] = $v;
  3672. }
  3673. } else {
  3674. $ki = str_replace('update_', $prefix . '_', $k);
  3675. if (strpos($ki, 'where_id') !== false) {
  3676. if ($method != 'insert') {
  3677. $update[$i]['where_id'] = $v;
  3678. }
  3679. } else {
  3680. if (strpos($k, 'l-l')) {
  3681. $temp = explode('l-l', $k);
  3682. $k = str_replace('_', '', $temp[2]);
  3683. $update_other[$i][$temp[1]][$k] = $v;
  3684. } elseif (strpos($k, '-')) {
  3685. $k = str_replace('update_', '', $k);
  3686. if (isset($config['struct'][$k]) && isset($config['struct'][$k]['sync'])) {
  3687. $s_col = $config['struct'][$k]['sync'][0];
  3688. $m_col = $config['struct'][$k]['sync'][1];
  3689. if ($s_col == 'id') {
  3690. $s_value = $this->id;
  3691. } else {
  3692. $s_one = $this->load('one', $this->id);
  3693. $s_value = $s_one[$s_col];
  3694. }
  3695. $temp = explode('-', $k);
  3696. $index = $temp[0] . '/' . $temp[1];
  3697. if (isset($temp[2])) {
  3698. $update_col[$i][$index] = $m_col;
  3699. $update_set[$i][$index][0]['set_' . $temp[2]] = $v;
  3700. //$update_set[$i][$index][0]['set_' . $m_col] = $s_value;
  3701. $update_add[$i][$index][0]['add_' . $temp[2]] = $v;
  3702. $update_add[$i][$index][0]['add_' . $m_col] = $s_value;
  3703. $update_id[$i][$index][0][$m_col] = $s_value;
  3704. }
  3705. } else {
  3706. $temp = explode('-', $k);
  3707. if (isset($temp[2])) {
  3708. $k = $temp[0] . '-' . $temp[1];
  3709. if (isset($config['struct'][$k]) && isset($config['struct'][$k]['sync'])) {
  3710. $s_col = $config['struct'][$k]['sync'][0];
  3711. $m_col = $config['struct'][$k]['sync'][1];
  3712. if ($s_col == 'id') {
  3713. $s_value = $this->id;
  3714. } else {
  3715. $s_one = $this->load('one', $this->id);
  3716. $s_value = $s_one[$s_col];
  3717. }
  3718. $index = $temp[0] . '/' . $temp[1];
  3719. $temp[2] = ltrim($temp[2], '_');
  3720. $temp = explode('_', $temp[2]);
  3721. $update_col[$i][$index] = $m_col;
  3722. $up = array();
  3723. $up['add_' . $temp[0] . '_id'] = $temp[1];
  3724. $up['add_' . $temp[0] . '_value'] = $v;
  3725. $up['add_' . $m_col] = $s_value;
  3726. $update_add[$i][$index][] = $up;
  3727. $update_delete[$i][$index][][$m_col] = $s_value;
  3728. }
  3729. }
  3730. }
  3731. } else {
  3732. if (is_array($v)) {
  3733. $k = str_replace('update_', '', $k);
  3734. $kd = $k . '_id';
  3735. if (isset($config['struct'][$kd])) {
  3736. foreach ($v as $vk => $vt) {
  3737. if ($vt == -1) {
  3738. if ($vk != 0) {
  3739. unset($v[$vk]);
  3740. }
  3741. }
  3742. }
  3743. if ($v) {
  3744. $vd = end($v);
  3745. $kdi = $prefix . '_' . $kd;
  3746. $update[$i][$kdi] = $vd;
  3747. }
  3748. }
  3749. if (isset($config['struct'][$k]) && strpos($config['struct'][$k]['type'], 'int') !== false) {
  3750. $v = end($v);
  3751. }
  3752. }
  3753. $update[$i][$ki] = $v;
  3754. }
  3755. }
  3756. }
  3757. }
  3758. //print_r($update_set);
  3759. //print_r($update_id);
  3760. //print_r($update_add);die;
  3761. //print_r($input);
  3762. //print_r($update_other);die;
  3763. //print_r($config['struct']);die;
  3764. # 增加复制的数量
  3765. $copy_num = Dever::input('copy_num');
  3766. if ($copy_num > 0) {
  3767. $update[0]['where_id'] = 0;
  3768. for ($i = 1; $i < $copy_num; $i++) {
  3769. $update[$i] = $update[0];
  3770. # 缓存处理
  3771. $update[$i]['rank'] = $i;
  3772. }
  3773. }
  3774. if ($this->id && !$info) {
  3775. $update[0]['add_id'] = $this->id;
  3776. }
  3777. //print_r($update);die;
  3778. foreach ($update as $k => $v) {
  3779. $method = 'insert';
  3780. $old = array();
  3781. if (isset($v['where_id']) && $v['where_id']) {
  3782. $method = 'update';
  3783. $old = $this->load('one', $v['where_id']);
  3784. }
  3785. if (isset($order[$k])) {
  3786. foreach ($order[$k] as $i => $j) {
  3787. array_multisort($j, SORT_ASC, $v[$i]);
  3788. }
  3789. }
  3790. if (isset($v['set_password']) && (!$v['set_password'] || $v['set_password'] == 'null')) {
  3791. unset($v['set_password']);
  3792. }
  3793. $id = $this->load($method, $v);
  3794. if ($id) {
  3795. $struct = $this->struct_data($config['struct'], $v, $old);
  3796. Log::add($this->project, $this->table, $this->menu_id, '', $method, $struct, $id ? $id : $this->id);
  3797. if ($update_other && isset($update_other[$k])) {
  3798. foreach ($update_other[$k] as $k1 => $v1) {
  3799. $v1['id'] = $id;
  3800. $this->load($method, $v1, $this->table . '__' . $k1);
  3801. }
  3802. }
  3803. if (isset($update_add[$k]) && $update_add[$k]) {
  3804. if (isset($update_deletes[$k]) && $update_deletes[$k]) {
  3805. foreach ($update_deletes[$k] as $k1 => $v1) {
  3806. $v1['set_state'] = 2;
  3807. Dever::load($k1 . '-updates', $v1);
  3808. }
  3809. }
  3810. foreach ($update_add[$k] as $k1 => $v1) {
  3811. $col = $update_col[$k][$k1];
  3812. foreach ($v1 as $k2 => $v2) {
  3813. if (isset($update_set[$k][$k1][$k2]['set_' . $col])) {
  3814. $update_set[$k][$k1][$k2]['set_' . $col] = $id;
  3815. }
  3816. if (isset($v2['add_' . $col])) {
  3817. $v2['add_' . $col] = $id;
  3818. }
  3819. $check = false;
  3820. if (isset($update_id[$k][$k1][$k2])) {
  3821. if (isset($update_id[$k][$k1][$k2][$col])) {
  3822. $update_id[$k][$k1][$k2][$col] = $id;
  3823. }
  3824. $check = Dever::load($k1 . '-one', $update_id[$k][$k1][$k2]);
  3825. } elseif (isset($update_delete[$k][$k1][$k2])) {
  3826. # 清理
  3827. Dever::load($k1 . '-delete', $update_delete[$k][$k1][$k2]);
  3828. }
  3829. if ($check) {
  3830. unset($update_set[$k][$k1][$k2]['set_id']);
  3831. $update_set[$k][$k1][$k2]['where_id'] = $check['id'];
  3832. $update_set[$k][$k1][$k2]['set_state'] = 1;
  3833. Dever::load($k1 . '-update', $update_set[$k][$k1][$k2]);
  3834. } else {
  3835. Dever::load($k1 . '-insert', $v2);
  3836. }
  3837. }
  3838. }
  3839. }
  3840. $this->spec($id, $config);
  3841. }
  3842. }
  3843. }
  3844. Dever::out('yes');
  3845. }
  3846. private function spec($id, $config)
  3847. {
  3848. if (isset($config['manage']['sku'])) {
  3849. $spec_table = $config['manage']['sku']['spec'];
  3850. $sku_table = $config['manage']['sku']['sku'];
  3851. }
  3852. if (!isset($sku_table)) {
  3853. $sku_table = 'info_sku';
  3854. }
  3855. $sku_table = $this->project . '/' . $sku_table;
  3856. $spec_type = Dever::input('update_spec_type');
  3857. if ($spec_type == 2) {
  3858. $spec = Dever::input('spec');
  3859. $sku = Dever::input('skus');
  3860. if ($spec && $sku) {
  3861. if (!isset($spec_table)) {
  3862. $spec_table = 'info_spec';
  3863. }
  3864. $spec_table = $this->project . '/' . $spec_table;
  3865. $spec_value_table = $spec_table . '_value';
  3866. $spec = Dever::json_decode($spec);
  3867. if ($spec) {
  3868. $sku_id = array();
  3869. Dever::db($spec_table)->updates(array('option_info_id' => $id, 'set_state' => 2));
  3870. Dever::db($spec_value_table)->updates(array('option_info_id' => $id, 'set_state' => 2));
  3871. foreach ($spec as $k1 => $v1) {
  3872. $order = $k1 + 1;
  3873. if (is_numeric($v1['id'])) {
  3874. $spec_id = Dever::db($spec_table)->update(array('where_id' => $v1['id'], 'set_state' => 1, 'set_reorder' => $order));
  3875. } else {
  3876. $spec_id = Dever::db($spec_table)->insert(array('name' => $v1['title'], 'info_id' => $id, 'reorder' => $order));
  3877. }
  3878. foreach ($v1['child'] as $k2 => $v2) {
  3879. $v2['checked'] = $v2['checked'] ? 1 : 2;
  3880. if (is_numeric($v2['id'])) {
  3881. Dever::db($spec_value_table)->update(array('where_id' => $v2['id'], 'set_state' => 1, 'set_is_checked' => $v2['checked']));
  3882. } else {
  3883. $sku_id[$v2['id']] = Dever::db($spec_value_table)->insert(array('value' => $v2['title'], 'is_checked' => $v2['checked'], 'info_id' => $id, 'spec_id' => $spec_id));
  3884. }
  3885. }
  3886. }
  3887. Dever::db($spec_table)->delete(array('info_id' => $id, 'state' => 2));
  3888. Dever::db($spec_value_table)->delete(array('info_id' => $id, 'state' => 2));
  3889. $this->sku($id, $sku_table, $sku, $sku_id);
  3890. }
  3891. }
  3892. } else {
  3893. $sku = Dever::input('skus');
  3894. if ($sku) {
  3895. $this->sku($id, $sku_table, $sku);
  3896. //Dever::db($spec_table)->delete(array('info_id' => $id));
  3897. //Dever::db($spec_value_table)->delete(array('info_id' => $id));
  3898. }
  3899. }
  3900. }
  3901. private function sku($id, $sku_table, $sku, $sku_id = false)
  3902. {
  3903. Dever::db($sku_table)->updates(array('option_info_id' => $id, 'set_state' => 2));
  3904. foreach ($sku as $k1 => $v1) {
  3905. if ($sku_id) {
  3906. foreach ($sku_id as $k2 => $v2) {
  3907. $k1 = str_replace($k2, $v2, $k1);
  3908. }
  3909. }
  3910. $sku_data = array();
  3911. $sku_data['info_id'] = $id;
  3912. $sku_data['key'] = $k1;
  3913. $sku_info = Dever::db($sku_table)->one($sku_data);
  3914. foreach ($v1 as $k3 => $v3) {
  3915. $sku_data[$k3] = $v3;
  3916. }
  3917. if ($sku_info) {
  3918. $sku_data['where_id'] = $sku_info['id'];
  3919. $sku_data['state'] = 1;
  3920. Dever::db($sku_table)->update($sku_data);
  3921. } else {
  3922. Dever::db($sku_table)->insert($sku_data);
  3923. }
  3924. }
  3925. Dever::db($sku_table)->delete(array('info_id' => $id, 'state' => 2));
  3926. }
  3927. public function struct_data($struct, $data, $old = array())
  3928. {
  3929. $log = $tlog = array();
  3930. foreach ($struct as $i => $j) {
  3931. /*
  3932. if ($i == 'reorder' || $i == 'id') {
  3933. continue;
  3934. }
  3935. */
  3936. if (isset($j['list_name'])) {
  3937. $j['name'] = $j['list_name'];
  3938. } elseif (strpos($j['name'], '-')) {
  3939. $temp = explode('-', $j['name']);
  3940. $j['name'] = $temp[0];
  3941. }
  3942. if (isset($j['list_table'])) {
  3943. $j['list'] = $j['list_table'];
  3944. if ($j['list'] == false) {
  3945. $data[$i] = false;
  3946. }
  3947. }
  3948. $list = (isset($j['list']) && is_string($j['list']) && $j['list'] != 'table');
  3949. $update = true;
  3950. if ($old && isset($j['update'])) {
  3951. $update = (is_string($j['update']) && $j['update'] != 'linkage');
  3952. }
  3953. if (isset($data['where_' . $i]) && $data['where_' . $i]) {
  3954. $log[$j['name']] = $data['where_' . $i];
  3955. } elseif (isset($data['set_' . $i]) && $data['set_' . $i]) {
  3956. $log[$j['name']] = $data['set_' . $i];
  3957. } elseif (isset($data['add_' . $i]) && $data['add_' . $i]) {
  3958. $log[$j['name']] = $data['add_' . $i];
  3959. } elseif (isset($data[$i]) && $data[$i]) {
  3960. if ($i == 'id') {
  3961. $log[$j['name']] = $data[$i];
  3962. } else {
  3963. $log[$j['name']] = $list ? $this->value($j['list'], $data) : $data[$i];
  3964. }
  3965. }
  3966. if (isset($log[$j['name']])) {
  3967. $tlog[$j['name']] = $log[$j['name']];
  3968. if (is_array($tlog[$j['name']])) {
  3969. if (isset($tlog[$j['name']][0]) && is_array($tlog[$j['name']][0])) {
  3970. $tlog[$j['name']] = json_encode($tlog[$j['name']]);
  3971. if (isset($old[$i]) && is_array($old[$i])) {
  3972. $old[$i] = json_encode($old[$i]);
  3973. }
  3974. } elseif (isset($tlog[$j['name']][0])) {
  3975. $tlog[$j['name']] = implode(',', $tlog[$j['name']]);
  3976. if (isset($old[$i]) && is_array($old[$i])) {
  3977. $old[$i] = implode(',', $old[$i]);
  3978. }
  3979. }
  3980. } elseif (strpos($log[$j['name']], 'http://wx.qlogo.cn/') !== false || strpos($log[$j['name']], '.jpg') !== false || strpos($log[$j['name']], '.gif') !== false || strpos($log[$j['name']], '.png') !== false) {
  3981. $log[$j['name']] = '<img layer-src="' . $log[$j['name']] . '" src="' . $log[$j['name']] . '" width="150">';
  3982. if (isset($old[$i]) && $old[$i]) {
  3983. $old[$i] = Dever::pic($old[$i]);
  3984. $old[$i] = '<img layer-src="' . $old[$i] . '" src="' . $old[$i] . '" width="150">';
  3985. }
  3986. } elseif (is_numeric($log[$j['name']]) && (strpos($i, 'time') !== false || strpos($i, 'date') !== false)) {
  3987. $log[$j['name']] = date("Y-m-d H:i:s", $log[$j['name']]);
  3988. if (isset($old[$i]) && $old[$i]) {
  3989. $old[$i] = date("Y-m-d H:i:s", $old[$i]);
  3990. }
  3991. } elseif (isset($j['decode'])) {
  3992. $log[$j['name']] = Dever::array_decode($log[$j['name']]);
  3993. if (isset($old[$i]) && $old[$i]) {
  3994. $old[$i] = Dever::array_decode($old[$i]);
  3995. }
  3996. }
  3997. if (isset($j['option']) && !$list && $update) {
  3998. $name = array();
  3999. $old_name = array();
  4000. $option = $this->option($j['option']);
  4001. if (is_array($option)) {
  4002. foreach ($option as $a => $b) {
  4003. if (!is_array($log[$j['name']])) {
  4004. if ($a == $log[$j['name']]) {
  4005. $name[] = (is_array($b) && isset($b['name'])) ? $b['name'] : $b;
  4006. }
  4007. } elseif (in_array($a, $log[$j['name']])) {
  4008. $name[] = (is_array($b) && isset($b['name'])) ? $b['name'] : $b;
  4009. }
  4010. if ($old && isset($old[$i])) {
  4011. if (!is_array($old[$i])) {
  4012. if ($a == $old[$i]) {
  4013. $old_name[] = (is_array($b) && isset($b['name'])) ? $b['name'] : $b;
  4014. }
  4015. } elseif (in_array($a, $old[$i])) {
  4016. $old_name[] = (is_array($b) && isset($b['name'])) ? $b['name'] : $b;
  4017. }
  4018. }
  4019. }
  4020. }
  4021. $log[$j['name']] = implode(',', $name);
  4022. if ($old_name) {
  4023. $old[$i] = implode(',', $old_name);
  4024. }
  4025. }
  4026. if ($log[$j['name']] == 'null') {
  4027. unset($log[$j['name']]);
  4028. }
  4029. if ($old && strstr($i, 'area')) {
  4030. $old[$i] = Dever::load('area/api')->string($old[$i]);
  4031. if (isset($log[$j['name']]) && $log[$j['name']]) {
  4032. $log[$j['name']] = Dever::load('area/api')->string($log[$j['name']]);
  4033. }
  4034. }
  4035. if (isset($log[$j['name']]) && isset($old[$i]) && $old[$i] != $tlog[$j['name']] && $old[$i] != $log[$j['name']]) {
  4036. $log[$j['name']] = array('更新前' => $old[$i], '更新后' => $log[$j['name']]);
  4037. } elseif ($old) {
  4038. //unset($log[$j['name']]);
  4039. }
  4040. }
  4041. }
  4042. return $log;
  4043. }
  4044. /**
  4045. * delete_action
  4046. *
  4047. * @return array
  4048. */
  4049. public function delete_action_api()
  4050. {
  4051. if (Dever::load('manage/auth.oper', 5) == false) {
  4052. Dever::alert('您没有权限');
  4053. }
  4054. $config = $this->config();
  4055. if (isset($config['struct']['state']) && (!isset($config['manage']['delete']) || (isset($config['manage']['delete']) && $config['manage']['delete']))) {
  4056. $name = '逻辑删除';
  4057. $this->load('update', array('where_id' => $this->id, 'state' => 2));
  4058. } else {
  4059. $name = '物理删除';
  4060. $this->load('delete', $this->id);
  4061. }
  4062. Log::add($this->project, $this->table, $this->menu_id, '', 3, array('ID' => $this->id, '方式' => $name), $this->id);
  4063. return 'reload';
  4064. return 'reloaderror';
  4065. }
  4066. /**
  4067. * recovery_action
  4068. *
  4069. * @return array
  4070. */
  4071. public function recovery_action_api()
  4072. {
  4073. if (Dever::load('manage/auth.oper', 5) == false) {
  4074. Dever::alert('您没有权限');
  4075. }
  4076. $this->load('update', array('where_id' => $this->id, 'state' => 1));
  4077. Log::add($this->project, $this->table, $this->menu_id, '', 4, array('ID' => $this->id, '方式' => '逻辑恢复'), $this->id);
  4078. return 'reload';
  4079. }
  4080. /**
  4081. * list_data
  4082. *
  4083. * @return array
  4084. */
  4085. public function list_data()
  4086. {
  4087. $config = $this->config();
  4088. $data = array();
  4089. if (isset($config['manage']['data']) && $config['manage']['data']) {
  4090. $num = count($config['manage']['data']);
  4091. if ($num <= 4) {
  4092. $xs = '3';
  4093. } else {
  4094. $xs = '1';
  4095. }
  4096. foreach ($config['manage']['data'] as $k => $v) {
  4097. if (is_object($v[1])) {
  4098. $function = $v[1];
  4099. $v[1] = $function();
  4100. }
  4101. $link = '';
  4102. if (isset($v[2]) && $v[2]) {
  4103. $link = 'project/database/list?project=' . $this->project . '&table=' . $this->table . '&' . $v[2];
  4104. $link = 'href="' . Dever::url($link, 'manage') . '"';
  4105. }
  4106. $data[] = '<li class="layui-col-xs'.$xs.'" style="min-width: 12%;">
  4107. <a class="layadmin-backlog-body" '.$link.'><h3>'.$v[0].'</h3>
  4108. <p><cite>'.$v[1].'</cite></p></a></li>';
  4109. }
  4110. }
  4111. return $data;
  4112. }
  4113. /**
  4114. * list_data
  4115. *
  4116. * @return array
  4117. */
  4118. public function list_data_show()
  4119. {
  4120. $config = $this->config();
  4121. if (isset($config['manage']['data']) && $config['manage']['data']) {
  4122. return 'display:block';
  4123. }
  4124. return 'display:none';
  4125. }
  4126. /**
  4127. * chart
  4128. *
  4129. * @return array
  4130. */
  4131. public function chart($config, $key, $data, $struct)
  4132. {
  4133. if (!$this->chart) {
  4134. $this->chart = array();
  4135. $this->chart['x'] = array();
  4136. $this->chart['data'] = array();
  4137. }
  4138. if ($config['x'] == $key) {
  4139. $this->chart['x'][] = $data;
  4140. } elseif (in_array($key, $config['data'])) {
  4141. if (!isset($this->chart['data'][$key])) {
  4142. $this->chart['data'][$key] = array
  4143. (
  4144. 'name' => $struct['name'],
  4145. 'type' => 'line',
  4146. 'stack' => 'Total',
  4147. 'data' => array(),
  4148. );
  4149. }
  4150. $this->chart['data'][$key]['data'][] = $data;
  4151. }
  4152. }
  4153. /**
  4154. * chart_data
  4155. *
  4156. * @return array
  4157. */
  4158. public function list_chart()
  4159. {
  4160. $config = $this->config();
  4161. $chart = '';
  4162. if (isset($config['manage']['chart']) && $this->chart) {
  4163. $this->chart['x'] = array_reverse($this->chart['x']);
  4164. $x = Dever::json_encode($this->chart['x']);
  4165. $this->chart['data'] = array_values($this->chart['data']);
  4166. foreach ($this->chart['data'] as $k => $v) {
  4167. $this->chart['data'][$k]['data'] = array_reverse($this->chart['data'][$k]['data']);
  4168. }
  4169. $data = Dever::json_encode($this->chart['data']);
  4170. $echarts = Dever::assets('lib/echarts/echarts.common.min.js', 'script');
  4171. $chart = '<script type="text/javascript" src="'.$echarts.'"></script><script>var chartDom = document.getElementById("chart");var myChart = echarts.init(chartDom);';
  4172. $chart .= "var option = {
  4173. tooltip: {
  4174. trigger: 'axis'
  4175. },
  4176. toolbox: {
  4177. feature: {
  4178. saveAsImage: {}
  4179. }
  4180. },
  4181. xAxis: {
  4182. type: 'category',
  4183. boundaryGap: false,
  4184. data: ".$x."
  4185. },
  4186. yAxis: {
  4187. type: 'value'
  4188. },
  4189. series: ".$data."
  4190. };option && myChart.setOption(option);</script>";
  4191. }
  4192. return $chart;
  4193. }
  4194. /**
  4195. * chart_data
  4196. *
  4197. * @return array
  4198. */
  4199. public function list_chart_show()
  4200. {
  4201. $config = $this->config();
  4202. if (isset($config['manage']['chart'])) {
  4203. return 'display:block';
  4204. }
  4205. return 'display:none';
  4206. }
  4207. /**
  4208. * stat 为主动统计提供相关数据
  4209. *
  4210. * @return array
  4211. */
  4212. public function stat()
  4213. {
  4214. //bundle 包依赖工具
  4215. $config = $this->config();
  4216. if (empty($config['manage']['stat'])) {
  4217. Dever::alert('该项目主动统计功能未开放');
  4218. }
  4219. $data = $config['manage'];
  4220. $data['table'] = '';
  4221. $method = $this->project . '/' . $this->table . '-all';
  4222. $gp = Dever::input('gp', 'month,day');
  4223. $col = is_string($gp) ? explode(',', $gp) : $gp;
  4224. $data['search'] = $this->stat_search($config['struct'], $gp, $config['manage']['stat'], $config['manage']['search']);
  4225. foreach ($col as $k => $v) {
  4226. $this->stat_data($data, $config['struct'], $v, $method);
  4227. }
  4228. return $data;
  4229. }
  4230. /**
  4231. * stat 为主动统计提供导出数据 后续优化
  4232. *
  4233. * @return array
  4234. */
  4235. public function stat_excel()
  4236. {
  4237. Dever::$global['base']['excel'] = 1;
  4238. //print_r($data['thead']);die;
  4239. $data = $this->stat();
  4240. if ($data && isset($data['list'])) {
  4241. $xls = new \PHPExcel();
  4242. $xls->getProperties()->setCreator("Maze Stat Excel")
  4243. ->setLastModifiedBy("Maze Stat Excel")
  4244. ->setTitle("Office 2007 XLSX Maze Document")
  4245. ->setSubject("Office 2007 XLSX Maze Document")
  4246. ->setDescription("Dever Stat Excel")
  4247. ->setKeywords("Dever Stat Excel")
  4248. ->setCategory("Dever Stat Excel");
  4249. $info = $this->info();
  4250. $name = $info['list_header'] . '的' . $info['stat_desc'] . '-' . $info['project_name'];
  4251. $start = 65;
  4252. $s = 0;
  4253. foreach ($data['thead'] as $k => $v) {
  4254. if ($s > 0) {
  4255. $xls->createSheet();
  4256. }
  4257. $act = $xls->setActiveSheetIndex($s);
  4258. $act->setTitle($v[0]);
  4259. $s++;
  4260. $i = 0;
  4261. foreach ($v as $kj => $vj) {
  4262. $num = 1;
  4263. $cell = $this->_getChr($start, $i);
  4264. $act->setCellValue($cell . '' . $num, $vj);
  4265. $act->getColumnDimension($cell)->setWidth(20);
  4266. $i++;
  4267. if (isset($data['list'][$k])) {
  4268. foreach ($data['list'][$k] as $ki => $vi) {
  4269. if (isset($vi[$kj])) {
  4270. $num += 1;
  4271. $act->setCellValue($cell . $num, $vi[$kj]);
  4272. }
  4273. }
  4274. }
  4275. }
  4276. }
  4277. //$act->getStyle('A1:'.$k.'20')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER); // 垂直居中
  4278. //$act->getStyle('A1:'.$k.'20')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);// 水平居中
  4279. $xls->setActiveSheetIndex(0);
  4280. $filename = $name . '.xlsx';
  4281. header('Pragma: public');
  4282. header('Expires: 0');
  4283. header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
  4284. header('Content-Type:application/force-download');
  4285. header('Content-Type:application/vnd.ms-execl');
  4286. header('Content-Type:application/octet-stream');
  4287. header('Content-Type:application/download');
  4288. header("Content-Disposition:attachment;filename='" . $filename . "'");
  4289. header('Content-Transfer-Encoding:binary');
  4290. $write = \PHPExcel_IOFactory::createWriter($xls, 'Excel2007');
  4291. $write->save('php://output');
  4292. }
  4293. }
  4294. /**
  4295. * stat_search
  4296. *
  4297. * @return mixed
  4298. */
  4299. private function stat_search($struct, $col, $stat, $search)
  4300. {
  4301. unset($struct['id']);
  4302. unset($struct['cdate']);
  4303. if ($stat) {
  4304. $stat = explode(',', $stat);
  4305. foreach ($stat as $k => $v) {
  4306. if (isset($struct[$v])) {
  4307. unset($struct[$v]);
  4308. }
  4309. }
  4310. }
  4311. $struct['day']['name'] = '天';
  4312. $struct['month']['name'] = '月';
  4313. $struct['year']['name'] = '年';
  4314. $param['update'] = 'checkbox';
  4315. $param['name'] = 'gp';
  4316. $param['value'] = $col;
  4317. $param['option'] = $struct;
  4318. $html = '<form action="' . $this->url('stat') . '" method="post" id="f1">';
  4319. $html .= '<div class="form-group">';
  4320. $html .= Html::pageLeft(array('name' => '统计项', 'col' => 'col'));
  4321. $html .= Html::radio($param);
  4322. $html .= '</div>';
  4323. $input = Dever::preInput('search_');
  4324. if (isset($search['date'])) {
  4325. foreach ($search['date'] as $k => $v) {
  4326. $html .= '<div class="form-group">';
  4327. $this->list_search_time($html, $input, 'search_', $k, $v, 'date');
  4328. $html .= '</div>';
  4329. }
  4330. $input = Dever::preInput('search_');
  4331. if ($input) {
  4332. foreach ($input as $k => $v) {
  4333. if ($v && strpos($k, 'option_') !== false) {
  4334. Dever::setInput(str_replace('search_', '', $k), $v);
  4335. }
  4336. }
  4337. }
  4338. }
  4339. if (isset($search['fulltext'])) {
  4340. $html .= '<div class="form-group">';
  4341. $this->list_search_select($html, $input, 'search_fulltext', '选择检索项', $search['fulltext']);
  4342. $this->list_search_select($html, $input, 'search_fulltext_type', '', array
  4343. (
  4344. 1 => '精确匹配',
  4345. 2 => '模糊匹配',
  4346. 3 => '大于',
  4347. 4 => '大于等于',
  4348. 5 => '小于',
  4349. 6 => '小于等于',
  4350. ), 1);
  4351. $value = array();
  4352. $value['name'] = 'search_fulltext_value';
  4353. $value['class'] = 'form-control';
  4354. if (isset($input[$value['name']])) {
  4355. $value['value'] = $input[$value['name']];
  4356. $fix = '';
  4357. if ($input['search_fulltext_type'] == 2) {
  4358. $fix = '%';
  4359. }
  4360. Dever::setInput('option_' . $input['search_fulltext'], $fix . $value['value'] . $fix);
  4361. //print_r(Dever::input('option_name'));die;
  4362. }
  4363. $html .= Html::text($value, false);
  4364. $html .= '</div>';
  4365. }
  4366. $html .= '<input type="hidden" name="excel" id="excel" value="2"><a href="javascript:;" class="btn btn-primary" onclick="$(\'#f1\').attr(\'action\', \'' . $this->url('stat') . '\').submit();">确定</a>';
  4367. $html .= '&nbsp;&nbsp;<a href="javascript:;" class="btn btn-warning" onclick="$(\'#f1\').attr(\'action\', \'' . $this->url('stat_excel') . '\').submit();">下载报表</a>';
  4368. $html .= '</form>';
  4369. return $html;
  4370. }
  4371. /**
  4372. * stat_data
  4373. *
  4374. * @return mixed
  4375. */
  4376. private function stat_data(&$data, $struct, $col, $method)
  4377. {
  4378. Dever::setInput('group', $col);
  4379. switch ($col) {
  4380. case 'year':
  4381. $name = '按年统计';
  4382. break;
  4383. case 'month':
  4384. $name = '按月统计';
  4385. break;
  4386. case 'day':
  4387. $name = '按天统计';
  4388. break;
  4389. default:
  4390. $name = $struct[$col]['name'];
  4391. break;
  4392. }
  4393. $list = Dever::load($method, array('group' => $col, 'col' => 'count(1) as total,id'));
  4394. $data['table'] .= '<div style="overflow-y:auto;width:100%;max-height:600px;"><table class="table table-bordered table-striped">';
  4395. $data['table'] .= '<thead><tr><th>' . $name . '</th><th>统计数字</th></tr></thead>';
  4396. $data['thead'][$col] = array($name, '统计数字');
  4397. if ($list) {
  4398. $data['table'] .= '<tbody>';
  4399. $total = 0;
  4400. foreach ($list as $k => $v) {
  4401. if (isset($v[$col])) {
  4402. if (isset($struct[$col]['option'])) {
  4403. $option = $this->option($struct[$col]['option']);
  4404. if (isset($option[$v[$col]])) {
  4405. $v[$col] = $option[$v[$col]];
  4406. if (is_array($v[$col])) {
  4407. $v[$col] = $v[$col]['name'];
  4408. }
  4409. }
  4410. }
  4411. $data['table'] .= '<tr><td width="60%" style="word-break:break-all;word-wrap:break-word;">' . $v[$col] . '</td><td>' . $v['total'] . '</td></tr>';
  4412. $total += $v['total'];
  4413. $data['list'][$col][] = array($v[$col], $v['total']);
  4414. }
  4415. }
  4416. $data['table'] .= '</tbody>';
  4417. if ($total > 0 && $k > 0) {
  4418. $data['table'] .= '<tr><td style="font-weight:bold">汇总</td><td style="font-weight:bold">' . $total . '</td></tr>';
  4419. $data['list'][$col][] = array('汇总', $total);
  4420. }
  4421. }
  4422. $data['table'] .= '</table></div>';
  4423. }
  4424. /**
  4425. * load
  4426. *
  4427. * @return mixed
  4428. */
  4429. private function load($method = 'one', $param = array(), $table = false)
  4430. {
  4431. if (!$table) {
  4432. $table = $this->table;
  4433. }
  4434. return Dever::load($this->project . '/' . $table . '-' . $method, $param);
  4435. }
  4436. /**
  4437. * __call
  4438. *
  4439. * @return object
  4440. */
  4441. public function __call($method, $param)
  4442. {
  4443. if (strpos($method, 'html_') !== false) {
  4444. return Html::text($param);
  4445. }
  4446. return $this;
  4447. }
  4448. /**
  4449. * option
  4450. *
  4451. * @return string
  4452. */
  4453. private function option($option, $value = false)
  4454. {
  4455. if (is_object($option)) {
  4456. $function = $option;
  4457. $option = $function();
  4458. }
  4459. if ($value && is_array($value)) {
  4460. $state = false;
  4461. foreach ($value as $k => $v) {
  4462. if ($v === true) {
  4463. $state = true;
  4464. break;
  4465. }
  4466. }
  4467. if ($state) {
  4468. $option = array_intersect_key($option, $value);
  4469. } else {
  4470. $option = $value;
  4471. }
  4472. }
  4473. return $option;
  4474. }
  4475. /**
  4476. * option
  4477. *
  4478. * @return string
  4479. */
  4480. public function manage()
  4481. {
  4482. $config = $this->config();
  4483. return $config;
  4484. }
  4485. /**
  4486. * valid
  4487. *
  4488. * @return string
  4489. */
  4490. public function valid()
  4491. {
  4492. //http://placehold.it/350x150
  4493. $config = $this->config();
  4494. if (isset($config['struct'])) {
  4495. $rule = array();
  4496. $rule['required']['regex'] = 'none';
  4497. $rule['required']['alertText'] = '此项不能为空';
  4498. $rule['required']['alertTextCheckboxMultiple'] = '请选择一个选项';
  4499. $rule['required']['alertTextCheckboxe'] = '请选择一个选项';
  4500. $rule['required']['alertTextDateRange'] = '日期范围不可空白';
  4501. foreach ($config['struct'] as $k => $v) {
  4502. if (isset($v['match']) && $v['match'] != 'option' && is_string($v['match']) && strpos($v['match'], '/') !== false) {
  4503. if (strstr($v['match'], 'option||')) {
  4504. $v['match'] = str_replace('option||', '', $v['match']);
  4505. }
  4506. $rule[$k]['regex'] = $v['match'];
  4507. $rule[$k]['alertText'] = $v['desc'];
  4508. }
  4509. }
  4510. }
  4511. $script = '<script>';
  4512. //参考https://blog.csdn.net/wangzl1163/article/details/51071826
  4513. //http://code.ciaoca.com/jquery/validation-engine/demo/demoOnForm
  4514. $script .= '(function($){
  4515. $.fn.validationEngineLanguage = function(){
  4516. };
  4517. $.validationEngineLanguage = {
  4518. newLang: function(){
  4519. $.validationEngineLanguage.allRules = ';
  4520. //此处进行了转义过滤,其实也可以使用json_encode的第二个参数,不过只支持5.4以上版本,考虑到虚拟主机就放弃了
  4521. $script .= str_replace(array('\\\\', '\\/', '"/', '/"', '/u"', '/g"', '/i"', '\x{4e00}-\x{9fa5}', '\x'), array('\\', '/', '/', '/', '/u', '/g', '/i', '\u4e00-\u9fa5', '\u'), json_encode($rule)) . ';';
  4522. $script .= '}
  4523. };
  4524. $.validationEngineLanguage.newLang();
  4525. })(jQuery);';
  4526. $script .= '$(document).ready(function(){
  4527. $(".form1").validationEngine("attach",{onSuccess:function(){submit();},onFailure:function(){submit();}});
  4528. });';
  4529. $script .= '</script>';
  4530. //print_r($script);die;
  4531. return $script;
  4532. }
  4533. /**
  4534. * save
  4535. *
  4536. * @return string
  4537. */
  4538. public function save()
  4539. {
  4540. $config = $this->config();
  4541. if (isset($config['manage']['save'])) {
  4542. return 'yes';
  4543. }
  4544. return 'no';
  4545. }
  4546. }