Database.php 229 KB

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