Database.php 230 KB

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