Database.php 225 KB

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