Database.php 227 KB

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