Database.php 221 KB

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