Database.php 220 KB

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