Database.php 126 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536
  1. <?php
  2. # 此类很大,以后优化,放到Database目录中,拆分为工厂模式
  3. # 必须要优化了...当时为了快速实现直接扔这一个里面了,近期优化
  4. namespace Manage\Src;
  5. use Dever;
  6. use Manage\Src\Lib\Input as Html;
  7. use Manage\Src\Lib\Log;
  8. class Database
  9. {
  10. /**
  11. * project
  12. *
  13. * @var string
  14. */
  15. private $project;
  16. /**
  17. * table
  18. *
  19. * @var string
  20. */
  21. private $table;
  22. /**
  23. * menu
  24. *
  25. * @var string
  26. */
  27. private $menu;
  28. /**
  29. * menu_id
  30. *
  31. * @var string
  32. */
  33. private $menu_id;
  34. /**
  35. * id
  36. *
  37. * @var string
  38. */
  39. private $id;
  40. /**
  41. * config
  42. *
  43. * @var array
  44. */
  45. private $config;
  46. /**
  47. * search
  48. *
  49. * @var bool
  50. */
  51. private $search = false;
  52. /**
  53. * __construct
  54. *
  55. * @return mixed
  56. */
  57. public function __construct()
  58. {
  59. $this->project = Dever::input('project');
  60. $this->table = Dever::input('table');
  61. $this->menu = Dever::input('menu');
  62. $this->menu_id = Dever::input('menu_id');
  63. $this->id = Dever::input('update_where_id', Dever::input('where_id'));
  64. $this->name = $this->project . '/' . $this->table;
  65. $this->top = Dever::input('top');
  66. if ($this->top) {
  67. Dever::load('manage/top.update_action', $this->top);
  68. }
  69. }
  70. /**
  71. * 提供给异步获取数据的接口
  72. *
  73. * @return array
  74. */
  75. public function getAjax($data)
  76. {
  77. $key = Dever::input('key');
  78. $value = Dever::input('value');
  79. $source = Dever::input('source');
  80. $config = Dever::db($source)->config['struct'][$key];
  81. $config['value'] = $value;
  82. $config['option'] = $data;
  83. return $this->create_update_html($key, $config);
  84. }
  85. /**
  86. * url
  87. *
  88. * @return array
  89. */
  90. public function url($key = false, $id = 0, $table = false, $suffix = '')
  91. {
  92. $table = $table ? $table : $this->table;
  93. if (strpos($table, 'http://') !== false || strpos($table, 'javascript') !== false) {
  94. return $table;
  95. }
  96. $config = array
  97. (
  98. 'project' => 'project/database?project=' . $this->project,
  99. 'list' => 'project/database/list?{param}',
  100. 'search' => 'project/database/list?{param}',
  101. 'add' => 'project/database/update?{param}',
  102. 'update' => 'project/database/update?{param}&where_id=' . $id,
  103. # 增加快捷更新
  104. 'edit' => 'project/database/update?{param}&where_id=' . $id,
  105. 'updateAction' => 'database.update_action',
  106. 'url' => '',
  107. 'delete' => 'database.delete_action?{param}&where_id=' . $id,
  108. 'recovery' => 'database.recovery_action?{param}&where_id=' . $id,
  109. 'stat' => 'project/database/stat?{param}',
  110. 'excel' => 'database.list_excel?{param}',
  111. 'stat_excel' => 'database.stat_excel?{param}',
  112. 'diy' => 'list?{param}',
  113. );
  114. $state = $this->getState();
  115. if ($key == 'delete' && $state == 2) {
  116. $key = 'recovery';
  117. }
  118. if (strpos($key, 'list') !== false) {
  119. $config[$key] = $config['list'];
  120. } elseif (strpos($key, 'add') !== false) {
  121. $config[$key] = $config['add'];
  122. } elseif (strpos($key, 'edit') !== false) {
  123. $config[$key] = $config['edit'];
  124. }
  125. if (isset($config[$key])) {
  126. if (strpos($config[$key], '{param}')) {
  127. $param = $this->getUrlParam($key, $table, $suffix, $state);
  128. $config[$key] = str_replace('{param}', $param, $config[$key]);
  129. }
  130. return Dever::url($config[$key]);
  131. }
  132. return $config;
  133. }
  134. /**
  135. * 获取url需要的参数
  136. *
  137. * @return string
  138. */
  139. private function getUrlParam($key, $table, $suffix, $state)
  140. {
  141. $param = '';
  142. $array = array('project', 'search', 'add', 'list', 'update', 'edit');
  143. if (in_array($key, $array) && !strstr($table, 'oper_')) {
  144. $where = Dever::preInput('search_');
  145. if ($where) {
  146. if (isset($where['where_id'])) {
  147. //unset($where['where_id']);
  148. }
  149. unset($where['search_option_state']);
  150. $param .= '&' . http_build_query($where);
  151. }
  152. $oper = Dever::preInput('oper_');
  153. if ($oper) {
  154. $param .= '&' . http_build_query($oper);
  155. }
  156. }
  157. if ($key == 'search' && $search_limit = Dever::input('search_limit')) {
  158. $param .= '&search_limit=' . $search_limit;
  159. }
  160. if (strpos($suffix, 'search_option_state') !== false) {
  161. $state = '';
  162. } else {
  163. $state = '&search_option_state=' . $state;
  164. }
  165. $page_type = Dever::input('page_type');
  166. if ($page_type) {
  167. $param .= '&page_type=' . $page_type . '';
  168. }
  169. $param = 'project=' . $this->project . $param . '&table=' . $table . '&menu=' . $this->menu . '&menu_id=' . $this->menu_id . $state . $suffix;
  170. return $param;
  171. }
  172. /**
  173. * 获得refer
  174. *
  175. * @return string
  176. */
  177. private function refer($type = 'project')
  178. {
  179. return '';
  180. switch ($type) {
  181. case 'project':
  182. $name = '数据库操作';
  183. break;
  184. case 'list':
  185. $name = '数据列表';
  186. break;
  187. case 'url':
  188. $name = '项目列表';
  189. break;
  190. }
  191. $name = '返回上一级';
  192. $url = $this->url($type);
  193. $refer = '-[<a href="' . $url . '">' . $name . '</a>]';
  194. return $refer;
  195. }
  196. /**
  197. * getAdminInfo
  198. *
  199. * @return array
  200. */
  201. private function getAdminInfo($data)
  202. {
  203. $admin = Dever::load('manage/auth.info');
  204. $data['my_admin_id'] = $admin['id'];
  205. $data['my_role_id'] = $admin['role'];
  206. return $data;
  207. }
  208. /**
  209. * cookie 处理cookie
  210. *
  211. * @return array
  212. */
  213. public function cookie()
  214. {
  215. $cookie = $_COOKIE;
  216. $array = array();
  217. # 判断手机版
  218. $mobile = Dever::mobile();
  219. if ((isset($cookie['left_menu']) && $cookie['left_menu'] == 'close') || $mobile) {
  220. $array['wrapper'] = 'enlarged forced';
  221. } else {
  222. $array['wrapper'] = 'forced';
  223. }
  224. return $array;
  225. }
  226. /**
  227. * listStyle
  228. *
  229. * @return array
  230. */
  231. public function listStyle()
  232. {
  233. $mobile = Dever::mobile();
  234. if ($mobile) {
  235. $style = '.container_list .panel-heading .form-control,#mul .form-control,#page .form-control
  236. {
  237. width:70%;
  238. }
  239. .row
  240. {
  241. margin-right: -15px;
  242. margin-left: -15px;
  243. }
  244. #dever_modal_body img
  245. {
  246. max-width:300px;
  247. }
  248. ';
  249. } else {
  250. $style = '#dever_modal_body img
  251. {
  252. max-width:300px;
  253. }';
  254. }
  255. return $style;
  256. }
  257. /**
  258. * info 处理一些基本的信息,供模板使用
  259. *
  260. * @return array
  261. */
  262. public function info()
  263. {
  264. $config = $this->config();
  265. $menu = isset($config['lang']) ? $config['lang'] : $this->project . '-' . $this->table;
  266. if (isset($config['state']) && $config['state'] == 2) {
  267. $menu .= '[回收站]';
  268. }
  269. $top = Dever::load('manage/top.get');
  270. //print_r($top);die;
  271. $display = '';
  272. # 新增权限
  273. $insert_state = Dever::load('manage/auth.oper', 4);
  274. if ((isset($config['manage']['insert']) && $config['manage']['insert'] == false) || !isset($config['manage']['insert']) || $insert_state == false) {
  275. $display = 'display:none';
  276. }
  277. $info = array
  278. (
  279. 'action' => $this->url('updateAction'),
  280. 'list' => $this->url('list'),
  281. 'search' => $this->url('search'),
  282. 'mul' => $this->url('list'),
  283. //'add' => 'location.href=\'' . $this->url('add') . '\'',
  284. 'add' => $this->url('add'),
  285. 'add_state' => $display,
  286. 'state' => $this->getState(),
  287. 'l' => 'project/database/list',
  288. 'project' => $this->project,
  289. 'table' => $this->table,
  290. 'menu' => $this->menu,
  291. 'menu_id' => $this->menu_id,
  292. 'id' => $this->id,
  293. 'main' => '数据管理' . $this->refer('url'),
  294. 'list_header' => $menu,
  295. 'list_desc' => '数据列表',
  296. 'project_name' => Dever::load('manage/project.name', $this->project),
  297. 'update_header' => $menu,
  298. 'update_desc' => '更新数据',
  299. 'updateMul' => (!$this->id && isset($config['manage']['updateMul']) && $config['manage']['updateMul']) ? '增加一条' : false,
  300. 'updateDesc' => isset($config['manage']['desc']) ? $config['manage']['desc'] : '',
  301. 'listDesc' => isset($config['desc']) ? $config['desc'] : '',
  302. 'struct' => isset($config['manage']['struct']) ? $config['manage']['struct'] : '',
  303. 'stat_desc' => '主动统计',
  304. 'search_param' => '',
  305. );
  306. $info['parent'] = Dever::input('oper_parent');
  307. if ($info['parent']) {
  308. $oper = Dever::preInput('oper_');
  309. if ($oper) {
  310. $info['parent'] .= '&' . str_replace('oper_', '', http_build_query($oper));
  311. //$info['parent'] .= '&' . http_build_query($oper);
  312. }
  313. if ($top = Dever::input('top_parent')) {
  314. $info['parent'] .= '&oper_parent=' . $top;
  315. }
  316. //$info['parent'] = 'location.href=\'' . $this->url(Dever::input('oper_index', 11), 0, $info['parent']) . '\'';
  317. $info['parent'] = $this->url(Dever::input('oper_index', 'listData'), 0, $info['parent']);
  318. $info['parent_state'] = '';
  319. } else {
  320. $info['parent_state'] = 'display:none';
  321. }
  322. $info['save'] = Dever::input('oper_save_jump');
  323. if ($info['save']) {
  324. $info['list'] = $this->url(Dever::input('oper_index', 'listData'), 0, $info['save']);
  325. }
  326. $search = Dever::preInput('search_');
  327. if ($search) {
  328. $info['mul'] .= '&' . http_build_query($search);
  329. if (layadmin()) {
  330. foreach ($search as $k => $v) {
  331. if (!strstr($k, 'search_option_')) {
  332. if (is_array($v)) {
  333. $v = implode(',', $v);
  334. }
  335. $info['search_param'] .= '<input type="hidden" name="'.$k.'" value="'.$v.'"/>';
  336. }
  337. }
  338. }
  339. }
  340. if ($this->id) {
  341. $info['update_header'] = $menu . '-更新数据' . $this->refer('list');
  342. }
  343. return $info;
  344. }
  345. /**
  346. * 获取表名
  347. *
  348. * @return array
  349. */
  350. public function getTableName($project, $table)
  351. {
  352. if ($project == 'other') {
  353. return '无数据表';
  354. }
  355. $path = Dever::load('manage/project.path', $project);
  356. $config = $this->config($project, $path, $table);
  357. $data = isset($config['lang']) ? $config['lang'] : $project;
  358. return $data;
  359. }
  360. private function getState()
  361. {
  362. return Dever::input('search_option_state', 1);
  363. }
  364. /**
  365. * config
  366. *
  367. * @return array
  368. */
  369. public function config($project = false, $path = false, $table = false)
  370. {
  371. if (!$project) {
  372. $project = $this->project;
  373. $table = $this->table;
  374. }
  375. if (!$project) {
  376. return array();
  377. }
  378. Dever::$global['manage']['project'] = $project;
  379. $config = Dever::load('manage/project.config', $project);
  380. if (!is_array($config)) {
  381. Dever::alert($project . ' error');
  382. }
  383. $project = $config['name'];
  384. if (!$path) {
  385. if (isset($config['base']) && isset($config['rel'])) {
  386. $path = DEVER_INCLUDE_PATH . $config['rel'];
  387. } else {
  388. $path = $config['path'];
  389. }
  390. }
  391. if ($project && $path && empty($this->config[$path])) {
  392. $this->config[$path] = array();
  393. $dir = $path . 'database/';
  394. if (is_dir($dir)) {
  395. $database = scandir($dir);
  396. foreach ($database as $k => $v) {
  397. if (strpos($v, '.php') !== false) {
  398. $k = str_replace('.php', '', $v);
  399. $this->config[$path][$k] = $this->struct($dir . $v, $project);
  400. }
  401. }
  402. }
  403. }
  404. return ($table && isset($this->config[$path][$table])) ? $this->config[$path][$table] : $this->config[$path];
  405. }
  406. /**
  407. * 对database配置文件进行解析
  408. *
  409. * @return array
  410. */
  411. private function struct($file, $project = false)
  412. {
  413. $config = include $file;
  414. if (isset($config['struct']) && is_array($config['struct']['id'])) {
  415. $config['update'] = false;
  416. $config['manage']['struct'] = '<table border=1 width=100% height=100%>';
  417. $config['level'] = 1;
  418. foreach ($config['struct'] as $k => $v) {
  419. if (isset($v['level'])) {
  420. $config['level'] = 3;
  421. }
  422. if (isset($v['search_parent'])) {
  423. $config['manage']['search_parent'][$v['search_parent']] = $k;
  424. $config['manage']['search_child'][$k] = $v['search_parent'];
  425. }
  426. if (isset($v['search']) && is_string($v['search'])) {
  427. if (strpos($v['search'], 'time') !== false) {
  428. $config['manage']['search']['time'][$k] = $v['name'];
  429. }
  430. if (strpos($v['search'], 'date') !== false) {
  431. $config['manage']['search']['date'][$k] = $v['name'];
  432. }
  433. if (strpos($v['search'], 'exp') !== false) {
  434. $config['manage']['search']['exp'][$k] = $v['name'];
  435. }
  436. if (strpos($v['search'], 'fulltext') !== false) {
  437. $config['manage']['search']['fulltext'][$k] = $v['name'];
  438. isset($v['match']) && $config['request']['list']['option'][$k] = array('option', 'like_score');
  439. } elseif (strpos($v['search'], 'text') !== false) {
  440. $config['manage']['search']['text'][$k] = $v['name'];
  441. }
  442. if (isset($v['exist']) && strpos($v['search'], 'exist') !== false) {
  443. $config['manage']['search']['exist'][$k]['option'] = $v['exist'];
  444. $config['manage']['search']['exist'][$k]['lang'] = $v['name'];
  445. }
  446. if (isset($v['option']) && strpos($v['search'], 'select') !== false) {
  447. $config['manage']['search']['select'][$k]['option'] = $v['option'];
  448. $config['manage']['search']['select'][$k]['lang'] = $v['name'];
  449. if (isset($v['default'])) {
  450. $config['manage']['search']['select'][$k]['default'] = $v['default'];
  451. }
  452. }
  453. if (isset($v['option']) && strpos($v['search'], 'group') !== false) {
  454. $config['manage']['search']['group'][$k]['option'] = $v['option'];
  455. $config['manage']['search']['group'][$k]['lang'] = $v['name'];
  456. if (isset($v['default'])) {
  457. $config['manage']['search']['group'][$k]['default'] = $v['default'];
  458. }
  459. }
  460. if (isset($v['option']) && strpos($v['search'], 'linkage') !== false) {
  461. $config['manage']['search']['linkage'][$k]['option'] = $v['option'];
  462. $config['manage']['search']['linkage'][$k]['lang'] = $v['name'];
  463. if (isset($v['default'])) {
  464. $config['manage']['search']['linkage'][$k]['default'] = $v['default'];
  465. }
  466. }
  467. } elseif (isset($v['search']) && is_array($v['search'])) {
  468. if (isset($v['search']['api'])) {
  469. $config['manage']['search']['api'][$k] = $v['search'];
  470. $config['manage']['search']['api'][$k]['lang'] = $v['name'];
  471. }
  472. }
  473. /*
  474. if (isset($v['table']) && !isset($config['end'])) {
  475. $config['end']['insert'] = $v['value'];
  476. }
  477. */
  478. if (isset($v['update'])) {
  479. if (!isset($config['manage']['insert'])) {
  480. $config['manage']['insert'] = true;
  481. }
  482. $config['update'] = true;
  483. }
  484. if (isset($v['type'])) {
  485. $config['manage']['struct'] .= Dever::tbody(array($k, $v['type'], $v['name']));
  486. }
  487. }
  488. $config['manage']['struct'] .= '</table>';
  489. $config['manage']['_list'] = array
  490. (
  491. 'col' => 'manage',
  492. 'name' => '管理',
  493. 'value' => array(),
  494. );
  495. if (!isset($config['manage']['edit']) || (!isset($config['manage']['edit']) && $config['manage']['edit'] == true)) {
  496. if (!isset($config['manage']['list_button']['update'])) {
  497. $config['manage']['_list']['value']['update'] = '编辑';
  498. }
  499. }
  500. if (isset($config['manage']['list'][0]) && is_array($config['manage']['list'][0])) {
  501. $config['manage']['_list']['value'] += $config['manage']['list'][0];
  502. unset($config['manage']['list'][0]);
  503. } elseif (isset($config['manage']['list_button'])) {
  504. $config['manage']['_list']['value'] += $config['manage']['list_button'];
  505. }
  506. if (!isset($config['manage']['delete']) || (isset($config['manage']['delete']) && $config['manage']['delete'] == true)) {
  507. if (!isset($config['manage']['list_button']['delete'])) {
  508. $config['manage']['_list']['value']['delete'] = '删除';
  509. }
  510. }
  511. if (!$config['manage']['_list']['value']) {
  512. unset($config['manage']['_list']);
  513. }
  514. }
  515. $config['state'] = $this->getState();
  516. $config['project'] = $project;
  517. return $config;
  518. }
  519. /**
  520. * 自定义列表页面
  521. *
  522. * @return array
  523. */
  524. public function page($key = 'list')
  525. {
  526. $key = Dever::input('page_value', $key);
  527. $type = Dever::input('page_type', 1);
  528. $config = $this->config();
  529. $result = array();
  530. $result['s1'] = 'display:none';
  531. $result['s2'] = 'display:';
  532. $result['content'] = '';
  533. $key = 'page_' . $key;
  534. if (isset($config['manage'][$key])) {
  535. if ($config['manage'][$key] == 'photo' && isset($config['manage']['photo'])) {
  536. $result['content'] = Dever::view('list/photo', false, 'manage');
  537. } else {
  538. $result['content'] = Dever::view($config['manage'][$key], 'manage', $this->project);
  539. }
  540. //echo $result['content'];die;
  541. if ($result['content']) {
  542. Dever::setInput('page_content', 1);
  543. $result['s1'] = 'display:';
  544. $result['s2'] = 'display:none';
  545. # 添加底部
  546. if ($key != 'page_list_table') {
  547. $result['content'] .= Dever::view('inc/foot', false, 'manage');
  548. }
  549. }
  550. } elseif (strstr($key, 'list_table')) {
  551. Dever::setInput('page_type', 2);
  552. }
  553. return $result;
  554. }
  555. /**
  556. * 自定义列表页面
  557. *
  558. * @return array
  559. */
  560. public function page_list()
  561. {
  562. return $this->page('list');
  563. }
  564. /**
  565. * 自定义列表页面 只接管table部分,同时必须传值page_type=1
  566. *
  567. * @return array
  568. */
  569. public function page_list_table()
  570. {
  571. $type = Dever::input('page_type', 2);
  572. if ($type == 1) {
  573. return $this->page('list_table');
  574. } else {
  575. return $this->page('list_table_default');
  576. }
  577. }
  578. /**
  579. * 自定义列表页面
  580. *
  581. * @return array
  582. */
  583. public function page_update()
  584. {
  585. return $this->page('update');
  586. }
  587. /**
  588. * 载入自定义资源
  589. *
  590. * @return array
  591. */
  592. public function res()
  593. {
  594. $result = array
  595. (
  596. 'js' => '',
  597. 'css' => '',
  598. );
  599. if (!$this->project) {
  600. return $result;
  601. }
  602. $config = $this->config();
  603. if (isset($config['manage']['res'])) {
  604. foreach ($config['manage']['res'] as $k => $v) {
  605. $result[$k] = $this->getRes($k, $v);
  606. }
  607. }
  608. return $result;
  609. }
  610. /**
  611. * getRes
  612. *
  613. * @return string
  614. */
  615. protected function getRes($path, $value)
  616. {
  617. if (is_array($value)) {
  618. $res = '';
  619. foreach ($value as $k => $v) {
  620. $res .= $this->getRes($path, $v);
  621. }
  622. return $res;
  623. } else {
  624. if ($this->project != 'manage') {
  625. $base = str_replace('assets/', 'assets/manage/', Dever::config('host', $this->project)->$path);
  626. } else {
  627. $base = Dever::config('host', $this->project)->$path;
  628. }
  629. $file = $base . $value . '.' . $path;
  630. if ($path == 'js') {
  631. $res = '<script type="text/javascript" src="'.$file.'"></script>';
  632. } else {
  633. $res = '<link rel="stylesheet" type="text/css" href="'.$file.'">
  634. ';
  635. }
  636. return $res;
  637. }
  638. }
  639. /**
  640. * 头部banner
  641. *
  642. * @return array
  643. */
  644. public function banner()
  645. {
  646. if (!$this->project) {
  647. return '';
  648. }
  649. $config = $this->config();
  650. $result = '';
  651. if (isset($config['manage']['banner'])) {
  652. foreach ($config['manage']['banner'] as $k => $v) {
  653. $config['manage']['banner'][$k] = $this->value($v, 'yes');
  654. }
  655. if (empty($config['manage']['banner']['link'])) {
  656. $config['manage']['banner']['link'] = '#';
  657. $config['manage']['banner']['target'] = '_self';
  658. }
  659. if (empty($config['manage']['banner']['target'])) {
  660. $config['manage']['banner']['target'] = '_blank';
  661. }
  662. $result = '<a target="' . $config['manage']['banner']['target'] . '" href="' . $config['manage']['banner']['link'] . '"><img src="' . $config['manage']['banner']['img'] . '"></a>
  663. <span>' . $config['manage']['banner']['name'] . '</span>';
  664. }
  665. return $result;
  666. }
  667. /**
  668. * 列表页搜索
  669. *
  670. * @return array
  671. */
  672. public function list_search_select(&$result, $search, $name, $lang, $option, $default = false, $bind = array(), $parent = '')
  673. {
  674. $value = array();
  675. if (strpos($lang, '-')) {
  676. $temp = explode('-', $lang);
  677. $lang = $temp[0];
  678. }
  679. $value['name'] = $name;
  680. $value['lang'] = $lang;
  681. $value['option'] = $option;
  682. if (isset($search[$name])) {
  683. $value['value'] = $search[$name];
  684. }
  685. if ($default) {
  686. //$value['default'] = $default;
  687. }
  688. if ($bind) {
  689. $value['bind'] = $bind;
  690. }
  691. $value['parent'] = $parent;
  692. $result .= Html::select($value, false);
  693. }
  694. /**
  695. * 列表页搜索
  696. *
  697. * @return array
  698. */
  699. public function list_search_group(&$result, $search, $name, $lang, $option, $default = false)
  700. {
  701. $value = array();
  702. $value['name'] = $name;
  703. $value['lang'] = $lang;
  704. $value['option'] = $option;
  705. if (isset($search[$name])) {
  706. $value['value'] = $search[$name];
  707. }
  708. if ($default) {
  709. //$value['default'] = $default;
  710. }
  711. $result .= Html::group($value, false);
  712. }
  713. /**
  714. * 列表页搜索
  715. *
  716. * @return array
  717. */
  718. public function list_search_linkage(&$result, $search, $name, $lang, $option, $default = false)
  719. {
  720. $value = array();
  721. $value['name'] = $name;
  722. $value['lang'] = $lang;
  723. $value['option'] = $option;
  724. $value['search_state'] = true;
  725. if (isset($search[$name])) {
  726. $value['value'] = $search[$name];
  727. }
  728. if ($default) {
  729. //$value['default'] = $default;
  730. }
  731. $result .= Html::linkage($value, 'span');
  732. }
  733. /**
  734. * 列表页搜索
  735. *
  736. * @return array
  737. */
  738. public function list_search_time(&$result, $search, $prefix, $key, $lang, $type = 'time')
  739. {
  740. $value['name'] = $prefix . 'option_start_' . $key;
  741. $value['lang'] = '>=' . $lang;
  742. if (isset($search[$value['name']])) {
  743. $value['value'] = Dever::maketime($search[$value['name']]);
  744. Dever::setInput($value['name'], $value['value'], 'search_');
  745. }
  746. $result .= Html::$type($value, false);
  747. $value['name'] = $prefix . 'option_end_' . $key;
  748. $value['lang'] = '<=' . $lang;
  749. if (isset($search[$value['name']])) {
  750. $value['value'] = Dever::maketime($search[$value['name']]);
  751. Dever::setInput($value['name'], $value['value'], 'search_');
  752. }
  753. $result .= Html::$type($value, false);
  754. }
  755. /**
  756. * 列表页头部按钮
  757. *
  758. * @return array
  759. */
  760. public function list_button()
  761. {
  762. if (Dever::load('manage/auth.oper', 2) == false) {
  763. return '';
  764. }
  765. $config = $this->config();
  766. $result = '';
  767. # 增加主动统计按钮
  768. if (isset($config['manage']['stat'])) {
  769. $name = '数据统计';
  770. if (is_string($config['manage']['stat'])) {
  771. $name = $config['manage']['stat'];
  772. }
  773. $config['manage']['button'][$name] = $this->url('stat');
  774. }
  775. # 增加下载报表按钮
  776. if (isset($config['manage']['excel'])) {
  777. $name = '导出数据';
  778. if (is_string($config['manage']['excel'])) {
  779. $name = $config['manage']['excel'];
  780. }
  781. $config['manage']['button'][$name] = 'onclick="jump(\''.$this->url('excel').'\', \'#form1\')"';
  782. }
  783. # 增加回收站
  784. if (isset($config['struct']['state']) && (!isset($config['manage']['delete']) || (isset($config['manage']['delete']) && $config['manage']['delete'] && isset($config['manage']['_list']['value']['delete'])))) {
  785. if ($config['state'] == 2) {
  786. $config['manage']['button']['返回数据列表'] = $this->url('list', 0, false, '&search_option_state=1');
  787. } else {
  788. $config['manage']['button']['回收站'] = $this->url('list', 0, false, '&search_option_state=2');
  789. }
  790. }
  791. # 列表页按钮
  792. if (isset($config['manage']['button'])) {
  793. $result .= $this->button_list($config['manage']['button']);
  794. }
  795. return $result;
  796. }
  797. /**
  798. * 更新页按钮
  799. *
  800. * @return array
  801. */
  802. public function update_button()
  803. {
  804. # 新增权限
  805. if (Dever::load('manage/auth.oper', 2) == false) {
  806. Dever::alert('你没有权限');
  807. }
  808. $info = $this->info();
  809. $result = '<button type="button" class="btn btn-primary save-data layui-btn layuiadmin-btn-list"><i class="fa fa-save"></i> 提交保存</button>
  810. <a href="' . $info['list'] . '" class="btn btn-danger layui-btn layuiadmin-btn-list layui-btn-danger" onclicks="msg({status:1,msg:\'yes\'})">放弃保存</a>';
  811. $config = $this->config();
  812. if (isset($config['manage']['update_button']) && $config['manage']['update_button']) {
  813. $result = '';
  814. foreach ($config['manage']['update_button'] as $k => $v) {
  815. if ($v == 'save-data') {
  816. $result .= '<button type="button" class="btn btn-primary save-data layui-btn layuiadmin-btn-list"><i class="fa fa-save"></i> ' . $k . '</button>';
  817. } elseif ($v == 'copy-data') {
  818. $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>';
  819. } elseif ($v == 'copy-datas') {
  820. $result .= '<a href="javascript:;" class="btn btn-danger layui-btn layuiadmin-btn-list layui-btn-danger" onclick="copy_data($(this))">' . $k . '</a>';
  821. } else {
  822. $result .= '<a href="javascript:;" class="btn btn-danger layui-btn layuiadmin-btn-list layui-btn-danger" onclick="' . $v . '">' . $k . '</a>';
  823. }
  824. }
  825. }
  826. return $result;
  827. }
  828. private function button_list($button)
  829. {
  830. $result = '';
  831. foreach ($button as $k => $v) {
  832. if (is_array($v)) {
  833. if ($v[0] == 'location') {
  834. if ($v[1] == 'add') {
  835. $url = $this->url('add');
  836. } elseif ($v[1] == 'list') {
  837. $url = $this->url('list');
  838. } else {
  839. $url = Dever::url($v[1]);
  840. }
  841. $result .= '&nbsp;&nbsp;<a class="btn btn-default layui-btn layuiadmin-btn-list" onclick="location.href=\''.$url.'\'">' . $k . '</a>';
  842. } elseif ($v[0] == 'show') {
  843. $url = Dever::url($v[1]);
  844. $submit = '';
  845. if (isset($v[2])) {
  846. $submit = Dever::url($v[2]);
  847. }
  848. $result .= '&nbsp;&nbsp;<a class="btn btn-default layui-btn layuiadmin-btn-list" onclick="loadPage(\''.$url.'\', \''.$k.'\',\''.$submit.'\')">' . $k . '</a>';
  849. } elseif ($v[0] == 'fast') {
  850. if (isset($v[2]) && $v[2]) {
  851. $url = $this->url('add', $v[1], $v[2]);
  852. } elseif (isset($v[1]) && $v[1]) {
  853. $url = Dever::url($v[1]);
  854. } else {
  855. $url = $this->url('add');
  856. }
  857. $result .= '&nbsp;&nbsp;<a class="btn btn-default layui-btn layuiadmin-btn-list" href="javascript:;" onclick="fastEdit($(this),\''.$url.'\',\''.$k.'\', \'\')">' . $k . '</a>';
  858. } elseif ($v[0] == 'fasts') {
  859. $result .= '&nbsp;&nbsp;<a class="btn btn-default layui-btn layuiadmin-btn-list" href="javascript:;" onclick="fastEdit($(this),\''.$this->url('add').'\',\''.$k.'\', \'\', 1)">' . $k . '</a>';
  860. } else {
  861. $result .= '&nbsp;&nbsp;<a class="btn btn-default layui-btn layuiadmin-btn-list" href="' . $this->url($v[0], false, $v[1]) . '">' . $k . '</a>';
  862. }
  863. } elseif (strpos($v, 'modal|') !== false) {
  864. $t = explode('modal|', $v);
  865. $result .= '&nbsp;&nbsp;<a href="javascript:;" class="btn btn-default layui-btn layuiadmin-btn-list" onclick="showAlert(\'' . $t[1] . '\')">' . $k . '</a>';
  866. } elseif (strpos($v, '|') !== false) {
  867. $t = explode('|', $v);
  868. $result .= $t[0] . '&nbsp;&nbsp;<a href="javascript:;" class="btn btn-warning layui-btn layuiadmin-btn-list layui-btn-warm" ' . $t[1] . '>' . $k . '</a>';
  869. } elseif (strpos($v, 'onclick') !== false) {
  870. $result .= '&nbsp;&nbsp;<a href="javascript:;" class="btn btn-warning layui-btn layuiadmin-btn-list layui-btn-warm" ' . $v . '>' . $k . '</a>';
  871. } elseif (strpos($v, 'http://') !== false || strpos($v, 'https://') !== false) {
  872. //$result .= '&nbsp;&nbsp;<a href="javascript:;" class="btn btn-default" onclick="jump(\''.Dever::url($v).'\')">'.$k.'</a>';
  873. $result .= '&nbsp;&nbsp;<a class="btn btn-default layui-btn layuiadmin-btn-list" href="' . Dever::url($v) . '">' . $k . '</a>';
  874. } else {
  875. $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>';
  876. }
  877. }
  878. return $result;
  879. }
  880. /**
  881. * 列表页搜索
  882. *
  883. * @return array
  884. */
  885. public function list_search()
  886. {
  887. # 新增权限
  888. if (Dever::load('manage/auth.oper', 2) == false) {
  889. return '';
  890. }
  891. $config = $this->config();
  892. $result = '';
  893. # 搜索
  894. if (isset($config['struct']) && isset($config['manage']['search'])) {
  895. $search = Dever::preInput('search_');
  896. $node = Html::node(array(' style="margin-top:0px;"', ''));
  897. $btn = '<div class="layui-inline"><input type="hidden" value="2" name="excel" id="excel"><button class="btn btn-primary layui-btn layuiadmin-btn-list" onclick="$(\'#form1\').attr(\'action\', \'' . $this->url('search') . '\');list_search($(this))" type="button" style="height: 38px;margin-left:0px;margin-top:-2px;">搜索</button></div>';
  898. //$result .= '<form id="f1" action="'.$this->url('list').'" method="post">';
  899. $prefix = 'search_';
  900. $result .= $node[0];
  901. if (isset($config['manage']['search']['linkage'])) {
  902. foreach ($config['manage']['search']['linkage'] as $k => $v) {
  903. $this->list_search_linkage($result, $search, $prefix . 'linkage_' . $k, $v['lang'], $this->option($v['option']), $v['default']);
  904. if (!layadmin()) {
  905. $result .= '<br />';
  906. }
  907. }
  908. }
  909. if (isset($config['manage']['search']['time'])) {
  910. foreach ($config['manage']['search']['time'] as $k => $v) {
  911. $this->list_search_time($result, $search, $prefix, $k, $v);
  912. }
  913. }
  914. if (isset($config['manage']['search']['date'])) {
  915. foreach ($config['manage']['search']['date'] as $k => $v) {
  916. $this->list_search_time($result, $search, $prefix, $k, $v, 'date');
  917. }
  918. }
  919. if (isset($config['manage']['search']['select'])) {
  920. $this->list_search_br($result);
  921. foreach ($config['manage']['search']['select'] as $k => $v) {
  922. $bind = array();
  923. $parent = '';
  924. $option = $this->option($v['option']);
  925. if (isset($config['manage']['search_parent'][$k])) {
  926. $bind = array
  927. (
  928. 'onchange',
  929. 'setOption',
  930. 'search_option_' . $config['manage']['search_parent'][$k]
  931. );
  932. }
  933. elseif (isset($config['manage']['search_child'][$k])) {
  934. $parent = $config['manage']['search_child'][$k];
  935. }
  936. $this->list_search_select($result, $search, $prefix . 'option_' . $k, $v['lang'], $option, $v['default'], $bind, $parent);
  937. }
  938. }
  939. if (isset($config['manage']['search']['exist'])) {
  940. $this->list_search_br($result);
  941. foreach ($config['manage']['search']['exist'] as $k => $v) {
  942. $this->list_search_select($result, $search, $prefix . 'exist_' . $k, $v['lang'], $this->option($v['option']), '');
  943. }
  944. }
  945. if (isset($config['manage']['search']['group'])) {
  946. $this->list_search_br($result);
  947. foreach ($config['manage']['search']['group'] as $k => $v) {
  948. $this->list_search_group($result, $search, $prefix . 'option_' . $k, $v['lang'], $this->option($v['option']), $v['default']);
  949. }
  950. }
  951. if (isset($config['manage']['search']['api'])) {
  952. $this->list_search_br($result);
  953. foreach ($config['manage']['search']['api'] as $k => $v) {
  954. $value = array();
  955. $value['name'] = $prefix . 'api_' . $k;
  956. $value['class'] = 'form-control';
  957. if (isset($search[$value['name']])) {
  958. $value['value'] = $search[$value['name']];
  959. }
  960. if (strpos($v['lang'], '-') !== false) {
  961. $t = explode('-', $v['lang']);
  962. $v['lang'] = $t[0];
  963. }
  964. $value['placeholder'] = $v['lang'];
  965. $result .= Html::text($value, false);
  966. }
  967. }
  968. if (isset($config['manage']['search']['text'])) {
  969. $this->list_search_br($result);
  970. foreach ($config['manage']['search']['text'] as $k => $v) {
  971. $value = array();
  972. $value['name'] = $prefix . 'option_' . $k;
  973. $value['class'] = 'form-control';
  974. if (isset($search[$value['name']])) {
  975. $value['value'] = $search[$value['name']];
  976. }
  977. if (strpos($v, '-') !== false) {
  978. $t = explode('-', $v);
  979. $v = $t[0];
  980. }
  981. $value['placeholder'] = $v;
  982. $result .= Html::text($value, false);
  983. }
  984. }
  985. if (isset($config['manage']['search']['fulltext'])) {
  986. $this->list_search_br($result);
  987. foreach ($config['manage']['search']['fulltext'] as $k => $v) {
  988. $value = array();
  989. $value['name'] = $prefix . 'fulltext_' . $k;
  990. $value['class'] = 'form-control';
  991. if (isset($search[$value['name']])) {
  992. $value['value'] = $search[$value['name']];
  993. }
  994. if (strpos($v, '-') !== false) {
  995. $t = explode('-', $v);
  996. $v = $t[0];
  997. }
  998. $value['placeholder'] = $v;
  999. $result .= Html::text($value, false);
  1000. }
  1001. }
  1002. if (isset($config['manage']['search']['exp'])) {
  1003. $result .= '<br />';
  1004. $this->list_search_select($result, $search, $prefix . 'exp_col', '选择检索项', $config['manage']['search']['exp']);
  1005. $this->list_search_select($result, $search, $prefix . 'exp_type', '', array
  1006. (
  1007. 3 => '大于',
  1008. 4 => '大于等于',
  1009. 5 => '小于',
  1010. 6 => '小于等于',
  1011. ), 1);
  1012. $value = array();
  1013. $value['name'] = $prefix . 'exp_value';
  1014. $value['class'] = 'form-control';
  1015. if (isset($search[$value['name']])) {
  1016. $value['value'] = $search[$value['name']];
  1017. }
  1018. $value['placeholder'] = '填写值';
  1019. $result .= Html::text($value, false);
  1020. }
  1021. # 列表页按钮
  1022. if (isset($config['manage']['search_button'])) {
  1023. $btn .= $this->button_list($config['manage']['search_button']);
  1024. }
  1025. $result .= $btn . $node[1];
  1026. //$result .= '</form>';
  1027. # 增加每页显示条数
  1028. $config['manage']['num'] = $this->getNumConfig($config);
  1029. if ($config['manage']['num']) {
  1030. $result = $this->num($result, $config['manage']['num']);
  1031. }
  1032. }
  1033. //print_r($result);die;
  1034. $oper = Dever::preInput('oper_');
  1035. if ($oper) {
  1036. foreach ($oper as $k => $v) {
  1037. $result .= '<input type="hidden" value="'.$v.'" name="'.$k.'" id="'.$k.'" />';
  1038. }
  1039. }
  1040. return $result;
  1041. }
  1042. private function list_search_br(&$result)
  1043. {
  1044. if (strpos($result, '&nbsp;&nbsp;') && !strpos($result, '<br />')) {
  1045. $result .= '<br />';
  1046. }
  1047. }
  1048. /**
  1049. * 获取条数配置
  1050. *
  1051. * @return array
  1052. */
  1053. private function getNumConfig($config)
  1054. {
  1055. if (isset($config['manage']['list_type'])) {
  1056. return false;
  1057. }
  1058. if (isset($config['manage']['num']) && $config['manage']['num'] == false) {
  1059. return false;
  1060. }
  1061. if (!isset($config['manage']['num'])) {
  1062. $config['manage']['num'] = array(20,50,100);
  1063. }
  1064. return $config['manage']['num'];
  1065. }
  1066. /**
  1067. * 生成条数的html
  1068. *
  1069. * @return string
  1070. */
  1071. private function num($result, $config)
  1072. {
  1073. $limit = '';
  1074. $cur = Dever::input('search_limit', 0);
  1075. foreach($config as $k => $v) {
  1076. if ($cur == $k) {
  1077. $btn = 'success';
  1078. } else {
  1079. $btn = 'default';
  1080. }
  1081. $url = $this->url('list', 0, false, '&search_limit=' . $k);
  1082. $limit .= '<a href="'.$url.'" style="width:60px;font-weight:bold;" class="btn btn-'.$btn.'">'.$v.'</a> ';
  1083. }
  1084. $num = '<div class="form-group layui-inline"><div style="padding-top:20px;margin-bottom: -30px;"><label style="color:#bababa;margin-left:8px;margin-right:10px;font-size:14px;font-weight:bold;">每页显示条数:</label>'.$limit.'</div></div>';
  1085. if (layadmin()) {
  1086. $num = '';
  1087. }
  1088. $result .= $num;
  1089. return $result;
  1090. }
  1091. /**
  1092. * 列表页表格头
  1093. *
  1094. * @return array
  1095. */
  1096. public function list_thead($type = false)
  1097. {
  1098. # 新增权限
  1099. if (Dever::load('manage/auth.oper', 1) == false) {
  1100. Dever::alert('你没有权限');
  1101. }
  1102. $config = $this->config();
  1103. $result = array();
  1104. if (isset($config['struct'])) {
  1105. if (isset($config['manage']['list']) && $config['manage']['list'] == 'update') {
  1106. # 验证头部权限 这里如果是多个选择权限的话,暂时无法实现。。。
  1107. if (isset($config['top']) && is_string($config['top'])) {
  1108. $top = Dever::load('manage/auth.getTop', array($config['top']));
  1109. if ($top) {
  1110. $url = $this->url('update', $top['value']);
  1111. }
  1112. } else {
  1113. $url = $this->url('update', 1);
  1114. }
  1115. return Dever::location($url);
  1116. } else {
  1117. if (isset($config['manage']['mul'])) {
  1118. if ($type == 'layui') {
  1119. $layui = array
  1120. (
  1121. 'field' => 'checkbox',
  1122. 'title' => '<input type="checkbox" class="checkbox-checkall" name="checkall" id="checkall" value="list" lay-ignore/>',
  1123. 'fixed' => 'left',
  1124. );
  1125. $result[] = $layui;
  1126. } else {
  1127. $result[] = '<th><input type="checkbox" class="checkbox-checkall" name="checkall" id="checkall" value="list"/></th>';
  1128. }
  1129. }
  1130. $data = array();
  1131. $data = $this->getAdminInfo($data);
  1132. foreach ($config['struct'] as $k => $v) {
  1133. if (isset($v['list']) && $v['list']) {
  1134. # 处理权限
  1135. if (isset($v['auth'])) {
  1136. $auth = $this->value($v['auth'], $data);
  1137. if (!$auth) {
  1138. continue;
  1139. }
  1140. }
  1141. if (isset($v['list_name'])) {
  1142. $v['name'] = $v['list_name'];
  1143. } else {
  1144. $temp = Html::cue(array('name' => $v['name']));
  1145. $v['name'] = $temp['name'];
  1146. }
  1147. if (!isset($v['level'])) {
  1148. $v['level'] = $config['level'];
  1149. }
  1150. if (isset($v['search']) && is_string($v['search']) && strpos($v['search'], 'order') !== false) {
  1151. $link = Dever::url();
  1152. $order = 'search_order_' . $k . '';
  1153. if (strpos($link, $order) !== false) {
  1154. $link = preg_replace('/[?|&]' . $order . '=(desc|asc)/i', '{order}', $link);
  1155. } else {
  1156. $link .= '{order}';
  1157. }
  1158. $search = Dever::input($order);
  1159. $cancel = '';
  1160. if ($search) {
  1161. $asc = $search;
  1162. $cancel = '&nbsp;<a class="glyphicon glyphicon-remove-sign" style="color:black;" href="' . str_replace('{order}', '', $link) . '" title="取消排序"></a>';
  1163. } else {
  1164. $asc = 'desc';
  1165. if (!isset($v['order']) && $k != 'id') {
  1166. $cancel = '&nbsp;<a class="glyphicon glyphicon-circle-arrow-down" style="color:black;" href="' . str_replace('{order}', '&' . $order . '=desc', $link) . '" title="降序"></a>';
  1167. }
  1168. }
  1169. if ($asc == 'asc') {
  1170. $asc = 'desc';
  1171. $icon = 'down';
  1172. $text = '降序';
  1173. } else {
  1174. $asc = 'asc';
  1175. $icon = 'up';
  1176. $text = '升序';
  1177. }
  1178. $link = str_replace('{order}', '&' . $order . '=' . $asc, $link);
  1179. if ($type == 'layui') {
  1180. $layui = array
  1181. (
  1182. 'field' => $k,
  1183. 'title' => '<a href="' . $link . '" title="' . $text . '" style="color:black;">' . $v['name'] . '&nbsp;<span class="layui-icon layui-icon-' . $icon . '"></span></a>',
  1184. );
  1185. $result[] = $layui;
  1186. } else {
  1187. $result[] = '<th data-priority="'.$v['level'].'"><a href="' . $link . '" title="' . $text . '" style="color:black;">' . $v['name'] . '&nbsp;<span class="glyphicon glyphicon-circle-arrow-' . $icon . '"></span></a>' . $cancel . '</th>';
  1188. }
  1189. } else {
  1190. if ($type == 'layui') {
  1191. if ($k == 'id' || isset($v['fixed'])) {
  1192. $layui = array
  1193. (
  1194. 'field' => $k,
  1195. 'title' => $v['name'],
  1196. //'fixed' => 'left',
  1197. );
  1198. } else {
  1199. $layui = array
  1200. (
  1201. 'field' => $k,
  1202. 'title' => $v['name'],
  1203. );
  1204. }
  1205. $result[] = $layui;
  1206. } else {
  1207. $result[] = '<th data-priority="'.$v['level'].'">' . $v['name'] . '</th>';
  1208. }
  1209. }
  1210. }
  1211. }
  1212. if ((Dever::load('manage/auth.oper', 3) != false || Dever::load('manage/auth.oper', 5) != false) && isset($config['manage']['_list']['value'])) {
  1213. if ($type == 'layui') {
  1214. $layui = array
  1215. (
  1216. 'field' => $config['manage']['_list']['col'],
  1217. 'title' => $config['manage']['_list']['name'],
  1218. //'fixed' => 'right',
  1219. );
  1220. $result[] = $layui;
  1221. } else {
  1222. $result[] = '<th data-priority="1" class="dever-manage">' . $config['manage']['_list']['name'] . '</th>';
  1223. }
  1224. }
  1225. }
  1226. }
  1227. return $result;
  1228. }
  1229. # layui表头
  1230. public function list_thead_layui()
  1231. {
  1232. $html = 'config.table = {};config.table.cols = [];';
  1233. $data = array($this->list_thead('layui'));
  1234. $data = Dever::json_encode($data);
  1235. $html .= 'config.table.cols = ' . $data;
  1236. return $html;
  1237. }
  1238. # layui表的数据 没有使用其异步方式
  1239. public function list_tbody_layui()
  1240. {
  1241. $html = 'config.table.data = [];';
  1242. $data = $this->list_tbody(false, 'layui');
  1243. $data = Dever::json_encode($data);
  1244. $html .= 'config.table.data = ' . $data;
  1245. return $html;
  1246. }
  1247. /**
  1248. * 导出列表
  1249. *
  1250. * @return array
  1251. */
  1252. public function list_excel_api()
  1253. {
  1254. Dever::$global['base']['excel'] = 1;
  1255. $this->list_search();
  1256. $data = $this->list_tbody(true);
  1257. if ($data) {
  1258. $config = $this->config();
  1259. if (isset($config['manage']['excel']) && $config['manage']['excel']) {
  1260. $method = 'excel';
  1261. $info = $this->info();
  1262. $data = $this->getAdminInfo($data);
  1263. $this->excel($info, $data, $config);
  1264. }
  1265. }
  1266. //print_r($data);die;
  1267. }
  1268. private function excel($info, $data, $config)
  1269. {
  1270. $file = $info['list_header'] . '的' . $info['list_desc'] . '-' . $info['project_name'];
  1271. $header = $body = array();
  1272. $i = 0;
  1273. foreach ($config['struct'] as $k => $v) {
  1274. if (isset($v['list']) && $v['list']) {
  1275. # 处理权限
  1276. if (isset($v['auth'])) {
  1277. $auth = $this->value($v['auth'], $data);
  1278. if (!$auth) {
  1279. continue;
  1280. }
  1281. }
  1282. //$v['name'] = mb_convert_encoding($v['name'],'gb2312','utf-8');
  1283. $header[$i] = $v['name'];
  1284. $i++;
  1285. $j = 0;
  1286. foreach ($data as $ki => $vi) {
  1287. if (is_array($vi)) {
  1288. $body[$j][$i] = '';
  1289. //if (isset($vi[$k])) {
  1290. if (true) {
  1291. $value = $vi[$k];
  1292. if (is_string($v['list'])) {
  1293. $value = $this->value($v['list'], $data[$ki], $config['struct']);
  1294. }
  1295. if (isset($v['option'])) {
  1296. $value = $this->getOptionValue($value, $v);
  1297. }
  1298. //$value = mb_convert_encoding($value,'gb2312','utf-8');
  1299. $body[$j][$i] = $value;
  1300. $j++;
  1301. }
  1302. }
  1303. }
  1304. }
  1305. }
  1306. Dever::excelExport($body, $header, $file);
  1307. }
  1308. private function getOptionValue($value, $v)
  1309. {
  1310. # 验证option是否是匿名函数
  1311. $v['option'] = $this->option($v['option']);
  1312. # 位运算
  1313. if (isset($v['bit'])) {
  1314. $ts = array();
  1315. foreach ($v['option'] as $tm => $tv) {
  1316. if (isset($v['bit'][$tm]) && ($value & $tm) > 0) {
  1317. $ts[] = $tv;
  1318. }
  1319. }
  1320. $value = implode(',', $ts);
  1321. }
  1322. if ((isset($v['child_name']) || (isset($v['show']) && is_string($v['show'])))) {
  1323. if (isset($v['option'][$value]) && is_array($v['option'][$value])) {
  1324. $value = $v['option'][$value]['name'];
  1325. } else {
  1326. $value = isset($v['option'][$value]) ? $v['option'][$value] : $value;
  1327. }
  1328. } else {
  1329. if (strstr($value, ',')) {
  1330. $temp = explode(',', $value);
  1331. $t = array();
  1332. foreach ($temp as $vv) {
  1333. if (isset($v['option'][$vv]) && is_array($v['option'][$vv])) {
  1334. $t[] = $v['option'][$vv]['name'];
  1335. } elseif(isset($v['option'][$vv])) {
  1336. $t[] = $v['option'][$vv];
  1337. } else {
  1338. $t[] = $vv;
  1339. }
  1340. }
  1341. $value = implode("\r\n", $t);
  1342. } elseif (isset($v['option'][$value]) && is_array($v['option'][$value])) {
  1343. $value = $v['option'][$value]['name'];
  1344. } else {
  1345. $value = isset($v['option'][$value]) ? $v['option'][$value] : $value;
  1346. }
  1347. }
  1348. return $value;
  1349. }
  1350. private function _getChr($start, $num)
  1351. {
  1352. $num = $start + $num;
  1353. $max = floor($num / 91);
  1354. if ($max > 0) {
  1355. $num = $num - (91 * $max) + $start;
  1356. $num = chr($start) . chr($num);
  1357. } else {
  1358. $num = chr($num);
  1359. }
  1360. return $num;
  1361. }
  1362. /**
  1363. * 列表页数据列表 检索
  1364. *
  1365. * @return array
  1366. */
  1367. private function list_tbody_search($config, $param, $high, $search)
  1368. {
  1369. # 根据api的数据检索到id
  1370. $api = Dever::preInput('search_api_');
  1371. if ($api) {
  1372. foreach ($api as $k => $v) {
  1373. if ($v) {
  1374. unset($search[$k]);
  1375. $k = str_replace('search_api_', '', $k);
  1376. # 设定检索高亮
  1377. $high[$k] = $v;
  1378. if (isset($config['manage']['search']['api'][$k]['api'])) {
  1379. $col = $config['manage']['search']['api'][$k]['col'];
  1380. $option = array($col => $v);
  1381. $v = Dever::load($config['manage']['search']['api'][$k]['api'], $option);
  1382. $result = $config['manage']['search']['api'][$k]['result'];
  1383. if ($v && is_array($v)) {
  1384. if (isset($v[$result])) {
  1385. $v = $v[$result];
  1386. } else {
  1387. if ($result == 'id') {
  1388. $v = array_keys($v);
  1389. } else {
  1390. $t = array();
  1391. foreach ($v as $k1 => $v1) {
  1392. $t[] = $v1[$result];
  1393. }
  1394. $v = $t;
  1395. }
  1396. if (isset($config['manage']['search']['api'][$k]['search'])) {
  1397. $param['option'][$config['manage']['search']['api'][$k]['search']] = array('yes', 'in');
  1398. } else {
  1399. $param['option'][$k] = array('yes', 'in');
  1400. }
  1401. }
  1402. } else {
  1403. $v = '-100';
  1404. }
  1405. }
  1406. if (isset($config['manage']['search']['api'][$k]['search'])) {
  1407. $param['option_' . $config['manage']['search']['api'][$k]['search']] = $v;
  1408. } else {
  1409. $param['option_' . $k] = $v;
  1410. }
  1411. }
  1412. }
  1413. }
  1414. # 检索有无值
  1415. $exist = Dever::preInput('search_exist_');
  1416. if ($exist) {
  1417. foreach ($exist as $k => $v) {
  1418. if ($v) {
  1419. unset($search[$k]);
  1420. $k = str_replace('search_exist_', '', $k);
  1421. if ($v == 'yes') {
  1422. # 有值
  1423. $param['option'][$k] = array('yes', '!=');
  1424. $param['option_' . $k] = 'null';
  1425. } elseif ($v == 'no') {
  1426. # 无值
  1427. $param['option'][$k] = array('yes', '=');
  1428. $param['option_' . $k] = 'null';
  1429. } elseif (strpos($v, '|')) {
  1430. # 有无值或者自定义的值
  1431. $temp = explode('|', $v);
  1432. $param['option_' . $k] = $temp[1];
  1433. if ($temp[0] == 'yes') {
  1434. $param['option'][$k] = array('yes', '!=');
  1435. $param['option'][$k . '_t1'] = array('yes-' . $k, '!=');
  1436. } else {
  1437. $param['option'][$k] = array('yes', '=', 'and(');
  1438. $param['option'][$k . '_t1'] = array('yes-' . $k, '=', 'or)');
  1439. }
  1440. $param['option_' . $k . '_t1'] = 'null';
  1441. } else {
  1442. # 自定义的值
  1443. $param['option_' . $k] = $v;
  1444. }
  1445. }
  1446. }
  1447. }
  1448. $fulltext = Dever::preInput('search_fulltext_');
  1449. if ($fulltext) {
  1450. $fulltext_state = false;
  1451. foreach ($fulltext as $k => $v) {
  1452. if ($v) {
  1453. unset($search[$k]);
  1454. $k = str_replace('search_fulltext_', '', $k);
  1455. $param['option_' . $k] = $v;
  1456. # 设定检索高亮
  1457. $high[$k] = $v;
  1458. $fulltext_state = true;
  1459. }
  1460. }
  1461. $this->search = true;
  1462. }
  1463. $linkage = Dever::preInput('search_linkage_');
  1464. if ($linkage) {
  1465. foreach ($linkage as $k => $v) {
  1466. if ($v && $v != -1) {
  1467. unset($search[$k]);
  1468. $k = str_replace('search_linkage_', '', $k);
  1469. if (isset($config['struct'][$k]['search_col'])) {
  1470. $temp = explode(',', $config['struct'][$k]['search_col']);
  1471. if (!is_array($v)) {
  1472. $v = explode(',', $v);
  1473. }
  1474. foreach ($temp as $k1 => $v1) {
  1475. if (isset($v[$k1]) && $v[$k1] != -1) {
  1476. $param['option_' . $v1] = $v[$k1];
  1477. }
  1478. }
  1479. } else {
  1480. if (is_array($v)) {
  1481. $v = implode(',', $v);
  1482. }
  1483. if ($v != -1) {
  1484. $v = Dever::defaultValue($v);
  1485. $param['option_' . $k] = $v;
  1486. # 设定检索高亮
  1487. $high[$k] = $v;
  1488. }
  1489. }
  1490. }
  1491. }
  1492. $this->search = true;
  1493. }
  1494. $exp = Dever::preInput('search_exp_');
  1495. if ($exp) {
  1496. $k = $search['search_exp_col'];
  1497. $v = $search['search_exp_value'];
  1498. $param['option_' . $k] = $v;
  1499. $param['search_type'] = $search['search_exp_type'];
  1500. $this->search = true;
  1501. }
  1502. $order = Dever::preInput('search_order_');
  1503. if ($order) {
  1504. foreach ($order as $k => $v) {
  1505. $k = str_replace('search_order_', '', $k);
  1506. $param['order'][0][$k] = $v;
  1507. unset($search[$k]);
  1508. }
  1509. }
  1510. foreach ($search as $k => $v) {
  1511. if ($v) {
  1512. if (strpos($k, 'option_') !== false) {
  1513. //Dever::setInput(str_replace('search_', '', $k), $v);
  1514. if (is_array($v)) {
  1515. if ($v[0] == 0) {
  1516. continue;
  1517. }
  1518. $v = str_replace(',0', '', implode(',', $v));
  1519. $t = explode(',', $v);
  1520. $parent = end($t);
  1521. $v .= '%';
  1522. }
  1523. $param[str_replace('search_', '', $k)] = $v;
  1524. $this->search = true;
  1525. } elseif ($k == 'search_limit') {
  1526. $num = $this->getNumConfig($config);
  1527. if ($num) {
  1528. $param['page'][0] = $num[$v];
  1529. }
  1530. }
  1531. }
  1532. }
  1533. return array($param, $high);
  1534. }
  1535. private function list_tbody_mul($param)
  1536. {
  1537. $mul = Dever::load('manage/auth.oper', 3) ? Dever::preInput('mul_') : false;
  1538. if (Dever::input('method') == 'mul' && $mul && $mul['mul_type'] > 0) {
  1539. if ($mul['mul_type'] == 1 && empty($mul['mul_where_id'])) {
  1540. Dever::alert('您还未选择任何数据条目');
  1541. }
  1542. Dever::config('base')->mul_type = $mul['mul_type'];
  1543. if (isset($param['page'])) {
  1544. unset($param['page']);
  1545. }
  1546. unset($mul['mul_type']);
  1547. foreach ($mul as $k => $v) {
  1548. if ($v) {
  1549. if (is_array($v)) {
  1550. $v = implode(',', $v);
  1551. }
  1552. $param[str_replace('mul_', '', $k)] = $v;
  1553. }
  1554. }
  1555. if (isset($param)) {
  1556. $method = $this->project . '/' . $this->table . '-updatemul';
  1557. $state = Dever::load($method, $param);
  1558. }
  1559. Dever::alert('reload');
  1560. }
  1561. }
  1562. /**
  1563. * 列表页数据列表:图片形式
  1564. *
  1565. * @return array
  1566. */
  1567. public function list_photo()
  1568. {
  1569. $config = $this->config();
  1570. $result = array();
  1571. if (isset($config['manage']['photo'])) {
  1572. $high = array();
  1573. $search = Dever::load('manage/auth.oper', 2) ? Dever::preInput('search_') : false;
  1574. $param = array();
  1575. $parent = 0;
  1576. if ($search) {
  1577. list($param, $high) = $this->list_tbody_search($config, $param, $high, $search);
  1578. }
  1579. if (empty($param['page'])) {
  1580. $num = $this->getNumConfig($config);
  1581. if ($num) {
  1582. $param['page'][0] = $num[0];
  1583. }
  1584. }
  1585. $method = $this->project . '/' . $this->table . '-list';
  1586. $result = Dever::load($method, $param);
  1587. if ($result) {
  1588. foreach ($result as $k => $v) {
  1589. $result[$k] = Dever::load($config['manage']['photo'], $v);
  1590. $result[$k]['button'] = $this->list_tbody_button($config, $v, 'div');
  1591. }
  1592. }
  1593. }
  1594. return $result;
  1595. }
  1596. /**
  1597. * 列表页数据列表:表格形式
  1598. *
  1599. * @return array
  1600. */
  1601. public function list_tbody($excel = false, $type = false)
  1602. {
  1603. # 新增权限
  1604. if (Dever::load('manage/auth.oper', 1) == false) {
  1605. Dever::alert('你没有权限');
  1606. }
  1607. if (Dever::input('page_content') == 1) {
  1608. return;
  1609. }
  1610. $config = $this->config();
  1611. $high = array();
  1612. $search = Dever::load('manage/auth.oper', 2) ? Dever::preInput('search_') : false;
  1613. $param = array();
  1614. $parent = 0;
  1615. if ($search) {
  1616. list($param, $high) = $this->list_tbody_search($config, $param, $high, $search);
  1617. }
  1618. if (empty($param['page'])) {
  1619. $num = $this->getNumConfig($config);
  1620. if ($num) {
  1621. $param['page'][0] = $num[0];
  1622. }
  1623. }
  1624. # 批量更新
  1625. $this->list_tbody_mul($param);
  1626. $result = $return = array();
  1627. if (isset($config['top_option']) && $config['top_option']) {
  1628. if (isset($config['top_option'][0])) {
  1629. foreach ($config['top_option'] as $k => $v) {
  1630. $param['option'][$v['col']] = array($v['value'], 'in');
  1631. }
  1632. } else {
  1633. $param['option'][$config['top_option']['col']] = array($config['top_option']['value'], 'in');
  1634. }
  1635. }
  1636. if ($excel == true) {
  1637. $method = $this->project . '/' . $this->table . '-all';
  1638. } else {
  1639. $method = $this->project . '/' . $this->table . '-list';
  1640. }
  1641. //print_r($param);die;
  1642. $data = Dever::load($method, $param);
  1643. if (isset($config['manage']['list_type']) && $config['manage']['list_type'] == 'parent') {
  1644. $parent = array();
  1645. $child = array();
  1646. foreach ($data as $k => $v) {
  1647. if ($v[$config['name'] . '_id'] <= 0) {
  1648. $parent[$k] = $v;
  1649. } else {
  1650. $v['name'] = '|-----' . $v['name'];
  1651. $child[$v[$config['name'] . '_id']][$k] = $v;
  1652. }
  1653. }
  1654. if ($parent) {
  1655. $data = array();
  1656. foreach ($parent as $k => $v) {
  1657. $data[$v['id']] = $v;
  1658. if (isset($child[$v['id']])) {
  1659. foreach ($child[$v['id']] as $i => $j) {
  1660. $data[$j['id']] = $j;
  1661. }
  1662. }
  1663. }
  1664. }
  1665. } elseif (isset($config['manage']['list_type']) && $config['manage']['list_type'] == 'tree') {
  1666. $data = $this->tree($data, $config, -1);
  1667. }
  1668. if ($excel == true) {
  1669. return $data;
  1670. }
  1671. if (Dever::input('page_type') == 1) {
  1672. Dever::$global['manage']['list_data'] = $data;
  1673. return;
  1674. }
  1675. //print_r($data);die;
  1676. //print_r(Helper::page("current"));die;
  1677. if ($data && isset($config['struct'])) {
  1678. $i = 0;
  1679. $pg = Dever::input('pg', 1);
  1680. $cur = Dever::input('search_limit', 0);
  1681. $num = $this->getNumConfig($config);
  1682. foreach ($data as $k => $v) {
  1683. $data[$k] = $this->getAdminInfo($data[$k]);
  1684. $data[$k]['i'] = $i;
  1685. $ii = intval($num[$cur])*($pg-1);
  1686. $data[$k]['r'] = $i+1+$ii;
  1687. $result[$k] = '<tr>';
  1688. $return[$i] = array();
  1689. if (isset($config['manage']['mul'])) {
  1690. $mul_state = false;
  1691. if ($config['manage']['mul'] && is_string($config['manage']['mul'])) {
  1692. $mul_state = $this->value($config['manage']['mul'], $data[$k]);
  1693. } else {
  1694. $mul_state = true;
  1695. }
  1696. if ($mul_state) {
  1697. $checkbox = '<input type="checkbox" name="mul_where_id[]" class="checkbox-checkall-list" lay-ignore value="' . $v['id'] . '"/>';
  1698. } else {
  1699. $checkbox = '<input type="checkbox" name="mul_where_id[]" class="checkbox-checkall-list" lay-ignore value="-1" disabled/>';
  1700. }
  1701. $result[$k] .= '<td>'.$checkbox.'</td>';
  1702. $return[$i]['checkbox'] = $checkbox;
  1703. }
  1704. foreach ($config['struct'] as $ki => $vi) {
  1705. # 处理同步
  1706. if (isset($vi['sync']) && strpos($ki, '-')) {
  1707. $temp = explode('-', $ki);
  1708. $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', array('option_' . $vi['sync'][1] => $v[$vi['sync'][0]]));
  1709. $v[$ki] = isset($load[$temp[2]]) ? $load[$temp[2]] : $vi['default'];
  1710. }
  1711. if (isset($vi['list']) && $vi['list']) {
  1712. if (empty($v[$ki])) {
  1713. $v[$ki] = $vi['default'];
  1714. }
  1715. # 处理权限
  1716. if (isset($vi['auth'])) {
  1717. $auth = $this->value($vi['auth'], $data[$k]);
  1718. if (!$auth) {
  1719. continue;
  1720. }
  1721. }
  1722. $show = $v[$ki];
  1723. if (is_string($vi['list'])) {
  1724. $show = $this->value($vi['list'], $data[$k], $config['struct']);
  1725. }
  1726. if (isset($vi['key']) && $vi['update'] != 'editor') {
  1727. $show = Dever::upload($show);
  1728. }
  1729. if (isset($vi['modal'])) {
  1730. $show = Html::modal($this->value($vi['modal'], $data[$k], $config['struct']), $show);
  1731. } elseif (isset($vi['option'])) {
  1732. # 验证option是否是匿名函数
  1733. if ((isset($vi['edit']) && $vi['edit'])) {
  1734. $vi['option'] = $this->option($vi['option'], $vi['edit']);
  1735. } else {
  1736. $vi['option'] = $this->option($vi['option']);
  1737. }
  1738. # 位运算
  1739. if (isset($vi['bit'])) {
  1740. $ts = array();
  1741. foreach ($vi['option'] as $tm => $tv) {
  1742. if (isset($vi['bit'][$tm]) && ($show & $tm) > 0) {
  1743. $ts[] = $tv;
  1744. }
  1745. }
  1746. $show = implode(',', $ts);
  1747. }
  1748. if ((isset($vi['child_name']) || (isset($vi['show']) && is_string($vi['show'])))) {
  1749. if (isset($vi['option'][$show]) && is_array($vi['option'][$show])) {
  1750. $show = $vi['option'][$show]['name'];
  1751. } else {
  1752. $show = isset($vi['option'][$show]) ? $vi['option'][$show] : $show;
  1753. }
  1754. }
  1755. //elseif ($config['state'] == 1 && (isset($vi['edit']) && $vi['edit']) || $ki == 'status')
  1756. elseif ($config['state'] == 1 && (isset($vi['edit']) && $vi['edit']))
  1757. {
  1758. $vi['name'] = 'up_col_' . $ki;
  1759. $vi['value'] = $v[$ki];
  1760. $m = 'select';
  1761. if (isset($vi['update']) && $vi['update'] == 'group') {
  1762. $m = 'group';
  1763. }
  1764. $show = Html::$m($vi, 'form-list', '', 'style="min-width: 100px;" data-old="'.$show.'" onchange="update($(this), \'' . $v['id'] . '\', \'' . $this->project . '\', \'' . $this->table . '\')"');
  1765. } else {
  1766. if (strstr($show, ',')) {
  1767. $temp = explode(',', $show);
  1768. $t = array();
  1769. foreach ($temp as $vv) {
  1770. if (isset($vi['option'][$vv]) && is_array($vi['option'][$vv])) {
  1771. $t[] = $vi['option'][$vv]['name'];
  1772. } elseif(isset($vi['option'][$vv])) {
  1773. $t[] = $vi['option'][$vv];
  1774. } else {
  1775. $t[] = $vv;
  1776. }
  1777. }
  1778. $show = implode('<br />', $t);
  1779. } elseif (isset($vi['option'][$show]) && is_array($vi['option'][$show])) {
  1780. $show = $vi['option'][$show]['name'];
  1781. } else {
  1782. $show = isset($vi['option'][$show]) ? $vi['option'][$show] : $show;
  1783. }
  1784. }
  1785. }
  1786. $text = $show;
  1787. if ($high && isset($high[$ki])) {
  1788. if (isset($v['s_' . $ki])) {
  1789. $text = $v['s_' . $ki];
  1790. $text = str_replace('<em class="dever_highlight">', '<font color="red" class="dever_highlight">', $text);
  1791. $text = str_replace('</em>', '</font>', $text);
  1792. } else {
  1793. $text = preg_replace('/('.$high[$ki].')/i', '<font color="red" class="dever_highlight">${1}</font>', $text);
  1794. }
  1795. }
  1796. if (!isset($vi['option']) && isset($vi['edit']) && $vi['edit']) {
  1797. //$url = Dever::url($vi['edit'] . '?where_id=' . $v['id'] . '&col=' . $vi['col']. '&key=' . $this->project . '&table=' . $this->table);
  1798. $url = $this->url('updateAction');
  1799. $vi['edit'] = $vi['edit'] == 'textarea' ? $vi['edit'] : 'text';
  1800. $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>';
  1801. $result[$k] .= '<td >' . $text . '</td>';
  1802. if (isset($return[$i][$ki])) {
  1803. $text = $return[$i][$ki] . $text;
  1804. }
  1805. $return[$i][$ki] = $text;
  1806. } else {
  1807. $result[$k] .= '<td>' . $text . '</td>';
  1808. if (isset($return[$i][$ki])) {
  1809. $text = $return[$i][$ki] . $text;
  1810. }
  1811. $return[$i][$ki] = $text;
  1812. }
  1813. }
  1814. }
  1815. $button = $this->list_tbody_button($config, $data[$k]);
  1816. $result[$k] .= $button;
  1817. $return[$i]['manage'] = str_replace(array('<td>', '</td>'), '', $button);
  1818. $result[$k] .= '</tr>';
  1819. $i++;
  1820. }
  1821. }
  1822. /*
  1823. if ($result) {
  1824. $thead = $this->list_thead();
  1825. if ($thead) {
  1826. $k = $k + 1;
  1827. $result[$k] = '<tr>';
  1828. foreach ($thead as $k => $v) {
  1829. $result[$k] .= $v;
  1830. }
  1831. $result[$k] .= '</tr>';
  1832. }
  1833. }
  1834. */
  1835. if ($type) {
  1836. return $return;
  1837. }
  1838. return $result;
  1839. }
  1840. private function list_tbody_button($config, $data, $type = 'td')
  1841. {
  1842. $result = '';
  1843. if (isset($config['manage']['_list']['value'])) {
  1844. $result = '<'.$type.'>';
  1845. if ($config['state'] == 2) {
  1846. if (isset($config['manage']['_list']['value']['update'])) {
  1847. unset($config['manage']['_list']['value']['update']);
  1848. }
  1849. if (isset($config['manage']['_list']['value']['delete'])) {
  1850. $config['manage']['_list']['value']['delete'] = '恢复';
  1851. }
  1852. }
  1853. foreach ($config['manage']['_list']['value'] as $kj => $vj) {
  1854. $pj = false;
  1855. $h = '<span class="am-icon-pencil-square-o"></span>';
  1856. $oper = true;
  1857. if ($kj == 'update') {
  1858. $oper = Dever::load('manage/auth.oper', 3);
  1859. } elseif ($kj == 'delete') {
  1860. $oper = Dever::load('manage/auth.oper', 5);
  1861. $h = '<span class="am-icon-trash-o"></span>';
  1862. }
  1863. if (is_array($vj) && isset($vj[1])) {
  1864. if (isset($vj[2])) {
  1865. $oper = $this->value($vj[2], $data);
  1866. }
  1867. if ($oper && strpos($vj[1], 'modal|') === false) {
  1868. $pj = $this->value($vj[1], $data);
  1869. $vjn = $vj[0];
  1870. }
  1871. } else {
  1872. $vjn = $vj;
  1873. }
  1874. if ($oper == true) {
  1875. if ($kj == 'delete') {
  1876. $class = 'layui-btn layui-btn-danger';
  1877. } else {
  1878. $class = 'layui-btn';
  1879. }
  1880. if (layadmin()) {
  1881. $class .= ' layui-btn-xs';
  1882. }
  1883. if (strpos($kj, 'edits') !== false) {
  1884. if (!isset($vj[1])) {
  1885. $vj[1] = '';
  1886. }
  1887. $result .= '<a href="javascript:;" onclick="fastEdit($(this), \'' . $this->url($kj, $data['id']) . '\', \''.$vj[0].'\', \''.$vj[1].'\', 1)"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 '.$class.'">' . $vj[0] . '</button></a>&nbsp;&nbsp;';
  1888. } elseif (strpos($kj, 'edit') !== false) {
  1889. if (!isset($vj[1])) {
  1890. $vj[1] = '';
  1891. }
  1892. if (strstr($vj[1], 'http')) {
  1893. $url = $vj[1] . '&id=' . $data['id'];
  1894. } else {
  1895. $url = $this->url($kj, $data['id']);
  1896. }
  1897. $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;';
  1898. } elseif (strpos($kj, 'oper') !== false) {
  1899. $result .= '<a href="javascript:;" onclick="load(\'' . Dever::url($pj) . '\')"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 '.$class.'">' . $vj[0] . '</button></a>&nbsp;&nbsp;';
  1900. } elseif (isset($vj[1]) && strpos($vj[1], 'modal|') !== false) {
  1901. $t = explode('|', $vj[1]);
  1902. $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;';
  1903. } elseif (isset($vj[1])) {
  1904. $result .= '<a href="' . $this->url($kj, $data['id'], $pj) . '" class="oper_' . $kj . '"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 '.$class.'">' . $h . $vjn . '</button></a>&nbsp;&nbsp;';
  1905. } else {
  1906. $result .= '<span style="margin-left:5px;margin-right:10px;">' . $vj[0] . '</span>';
  1907. }
  1908. }
  1909. }
  1910. $result .= '</'.$type.'>';
  1911. }
  1912. return $result;
  1913. }
  1914. /**
  1915. * 多级分类
  1916. *
  1917. * @return array
  1918. */
  1919. private function tree($data, $config, $parent = 0)
  1920. {
  1921. $key = $config['name'] . '_id';
  1922. $result = array();
  1923. $this->treeData($data, $result, $key, $parent);
  1924. return $result;
  1925. }
  1926. private function treeData($array, &$result, $key, $parent_id = 0, $level = 0)
  1927. {
  1928. if (empty($array)) {
  1929. return;
  1930. }
  1931. $level++;
  1932. foreach ($array as $k => $v) {
  1933. if (isset($v[$key]) && $v[$key] == $parent_id) {
  1934. $v['level'] = $level;
  1935. $v['name'] = $this->treeName($v['name'], $level);
  1936. $result[] = $v;
  1937. unset($array[$k]);
  1938. $this->treeData($array, $result, $key, $v['id'], $level);
  1939. }
  1940. }
  1941. }
  1942. private function treeName($name, $level = 1)
  1943. {
  1944. $string = '';
  1945. if ($level > 1) {
  1946. /*
  1947. $num = 4;
  1948. $string = '-';
  1949. //STR_PAD_LEFT
  1950. $string = str_pad('|', $level * $num, $string);
  1951. */
  1952. $string = str_repeat(' ',$level-1);
  1953. $string .= '|—';
  1954. }
  1955. return $string . $name;
  1956. }
  1957. /**
  1958. * 列表页批量管理
  1959. *
  1960. * @return array
  1961. */
  1962. public function list_mul()
  1963. {
  1964. # 新增权限:更新权限
  1965. if (Dever::load('manage/auth.oper', 3) == false) {
  1966. return '';
  1967. }
  1968. $config = $this->config();
  1969. $result = '';
  1970. if (isset($config['struct']) && isset($config['manage']['mul'])) {
  1971. $mul = Dever::preInput('mul_');
  1972. $node = Html::node(array('class="am-u-sm-12" style="margin-top:10px;"', 'class="am-form-group am-input-group-sm"'));
  1973. $btn = '<button class="btn btn-danger layui-btn layui-btn-danger" onclick="$(\'#form1\').attr(\'action\', \'' . $this->url('list') . '\');list_mul($(this))" type="button" style="height: 38px;margin-left:10px;">更新</button>';
  1974. $prefix = 'mul_';
  1975. $result .= $node[0];
  1976. $default = 0;
  1977. $option = array
  1978. (
  1979. 1 => '本页选中的数据',
  1980. );
  1981. # 只有当有搜索条件时才会出现
  1982. if (Dever::load('manage/auth.oper', 2) && $this->search == true) {
  1983. $option[2] = '所有页面的数据';
  1984. $default = 2;
  1985. }
  1986. $this->list_search_select($result, $mul, $prefix . 'type' . '" id="' . $prefix . 'type', '请选择要更新的数据', $option, $default);
  1987. foreach ($config['struct'] as $k => $v) {
  1988. if ($k == 'state' && (!isset($config['manage']['delete']) || (isset($config['manage']['delete']) && $config['manage']['delete']))) {
  1989. $v['option'] = Dever::config('base')->state;
  1990. if ($this->getState() == 2) {
  1991. unset($v['option'][2]);
  1992. } else {
  1993. unset($v['option'][1]);
  1994. }
  1995. $v['edit'] = true;
  1996. }
  1997. $select = false;
  1998. if (isset($v['mul'])) {
  1999. $select = $v['mul'];
  2000. } elseif (isset($v['edit'])) {
  2001. $select = $v['edit'];
  2002. }
  2003. if ($select && isset($v['option']) && (is_array($v['option']) || is_object($v['option']))) {
  2004. $result .= '&nbsp;&nbsp;';
  2005. $this->list_search_select($result, $mul, $prefix . 'set_' . $k, $v['name'], $this->option($v['option'], $select), $v['default']);
  2006. }
  2007. }
  2008. $result .= $btn . $node[1];
  2009. }
  2010. //print_r($result);die;
  2011. return $result;
  2012. }
  2013. private function value($value, $data, $struct = array())
  2014. {
  2015. if (!$data) {
  2016. return $value;
  2017. }
  2018. if (strstr($value, '={') && !strstr($value, '"')) {
  2019. $value = '"' . $value . '"';
  2020. }
  2021. if (is_string($data)) {
  2022. $eval = '$value = ' . $value . ';';
  2023. eval($eval);
  2024. return $value;
  2025. }
  2026. if ($value == 'table' && $struct) {
  2027. $result = $this->struct_data($struct, $data);
  2028. $value = Dever::table($result);
  2029. } elseif (strpos($value, '{') !== false) {
  2030. # 这里用到了/e,注意这里无论如何不能传入$_GET之类的用户参数 2015/7/21更新为callback方式
  2031. //$eval = '$value = ' . preg_replace('/{(.*?)}/e', "\$data['$1']", $value) . ';';
  2032. $func = function ($r) use ($data) {
  2033. if (isset($data[$r[1]])) {
  2034. return $data[$r[1]];
  2035. }
  2036. return false;
  2037. };
  2038. $value = preg_replace_callback('/{(.*?)}/', $func, $value);
  2039. if (strstr($value, '<script>')) {
  2040. $value = str_replace('<script>', '<script>$(document).ready(function(){', $value);
  2041. $value = str_replace('</script>', '});</script>', $value);
  2042. }
  2043. $eval = '$value = ' . $value . ';';
  2044. eval($eval);
  2045. }
  2046. return $value;
  2047. }
  2048. /**
  2049. * update
  2050. *
  2051. * @return array
  2052. */
  2053. public function update()
  2054. {
  2055. $config = $this->config();
  2056. $result = array();
  2057. $prefix = 'update';
  2058. $data = array();
  2059. if ($this->id) {
  2060. # 新增权限
  2061. if (Dever::load('manage/auth.oper', 3) == false) {
  2062. Dever::alert('你没有权限');
  2063. }
  2064. $data = $this->load('one', $this->id);
  2065. if ($data) {
  2066. //$prefix = 'set';
  2067. }
  2068. } else {
  2069. # 新增权限
  2070. if (Dever::load('manage/auth.oper', 4) == false) {
  2071. Dever::alert('你没有权限');
  2072. }
  2073. }
  2074. //print_r($config['manage']['update']);die;
  2075. $data = $this->getAdminInfo($data);
  2076. $col = Dever::input('col');
  2077. foreach ($config['struct'] as $k => $v) {
  2078. if (isset($v['update'])) {
  2079. if ($col && !strstr(',' . $col . ',', ',' . $k . ',')) {
  2080. continue;
  2081. }
  2082. //处理权限
  2083. if (isset($v['auth'])) {
  2084. $auth = $this->value($v['auth'], $data);
  2085. if (!$auth) {
  2086. continue;
  2087. }
  2088. }
  2089. # 处理show模式下的class
  2090. $class = $this->update_class($k, $v, '', $data);
  2091. $result[$k] = '<div class="form-group ' . $class . '"><div class="margin-top">';
  2092. if (layadmin()) {
  2093. $result[$k] = '<div class="layui-form-item ' . $class . '"><div classs="layui-col-lg6">';
  2094. if (isset($v['update']) && is_array($v['update'])) {
  2095. $result[$k] = '<div class="layui-form-item ' . $class . '"><div class="layui-tab-card">';
  2096. }
  2097. }
  2098. $result[$k] .= $this->create_update_html($k, $v, $data);
  2099. $result[$k] .= '</div></div>';
  2100. } elseif (!$col && isset($v['class'])) {
  2101. # 分割线
  2102. $v['name'] = $this->value($v['name'], array('test' => 1));
  2103. if (isset($v['right'])) {
  2104. $this->card_right = true;
  2105. }
  2106. $this->card = true;
  2107. $result[$k] = Html::hr($v);
  2108. }
  2109. }
  2110. if (Dever::input('ajax') == 1) {
  2111. return implode('', $result);
  2112. }
  2113. //print_r($result);die;
  2114. return $result;
  2115. }
  2116. public function card()
  2117. {
  2118. if (isset($this->card_right)) {
  2119. return 'layui-col-md6';
  2120. }
  2121. return 'layui-col-md12';
  2122. }
  2123. public function layui_card()
  2124. {
  2125. if (isset($this->card)) {
  2126. return false;
  2127. }
  2128. return true;
  2129. }
  2130. /**
  2131. * update_class
  2132. *
  2133. * @return string
  2134. */
  2135. public function update_class($name, $param, $prefix = '', $data = array())
  2136. {
  2137. $class = '';
  2138. $key = 'show';
  2139. if (isset($param[$key]) && $param[$key]) {
  2140. $parent = array();
  2141. $child = array();
  2142. if (is_string($param[$key])) {
  2143. parse_str($param[$key], $param[$key]);
  2144. }
  2145. if (is_array($param[$key])) {
  2146. foreach ($param[$key] as $k => $v) {
  2147. if ($k == 'no') {
  2148. $child[$k . '_' . $v] = $key . '_no';
  2149. } elseif (strpos($v, '/')) {
  2150. $parent[$k] = $key . '_' . $k;
  2151. $k = $k . '_ajax';
  2152. $value = '';
  2153. if (isset($data[$name])) {
  2154. $value = $data[$name];
  2155. }
  2156. $v = str_replace('?', '?key='.$name.'&value='.$value.'&source='.$this->name.'&', $v);
  2157. $child[$k] = $key . '_' . $k .'" dever-ajax="'.Dever::url($v).'"';
  2158. } else {
  2159. if (strpos($v, ',')) {
  2160. $temp = explode(',', $v);
  2161. foreach ($temp as $v1) {
  2162. $show = $k . '_' . $v1;
  2163. if ($prefix) {
  2164. $k = str_replace($name, $k, $prefix);
  2165. $show = str_replace($name, $show, $prefix);
  2166. }
  2167. $parent[$k] = $key . '_' . $k;
  2168. $child[$show] = $key . '_' . $show;
  2169. }
  2170. } else {
  2171. $show = $k . '_' . $v;
  2172. if ($prefix) {
  2173. $k = str_replace($name, $k, $prefix);
  2174. $show = str_replace($name, $show, $prefix);
  2175. }
  2176. $parent[$k] = $key . '_' . $k;
  2177. $child[$show] = $key . '_' . $show;
  2178. }
  2179. }
  2180. }
  2181. }
  2182. $class = implode(' ', $parent) . ' ' . implode(' ', $child);
  2183. }
  2184. if (isset($param['control'])) {
  2185. $class .= ' ' . $key . '_input';
  2186. }
  2187. return $class;
  2188. }
  2189. /**
  2190. * update_html
  2191. *
  2192. * @return string
  2193. */
  2194. public function create_update_html($key, $value, $data = array())
  2195. {
  2196. $result = '';
  2197. $value['ext'] = $value['col'] = $key;
  2198. $value['update'] = $value['update'] ? $value['update'] : 'text';
  2199. if (isset($value['match']) && $value['match'] != 'option') {
  2200. if (is_string($value['match']) && strpos($value['match'], '/') !== false) {
  2201. if (strstr($value['match'], 'option||')) {
  2202. $value['valid'] = 'validate[custom[' . $key . ']]';
  2203. } else {
  2204. $value['valid'] = 'validate[required,custom[' . $key . ']]';
  2205. }
  2206. } else {
  2207. $value['valid'] = 'validate[required]';
  2208. }
  2209. }
  2210. if (is_string($value['update']) && strpos($value['update'], 'copy.') !== false) {
  2211. $value['value'] = $value['update'];
  2212. $value['update'] = 'hidden';
  2213. }
  2214. $this->update_html($value, $key, $key, $data, $result);
  2215. return $result;
  2216. }
  2217. /**
  2218. * update_html
  2219. *
  2220. * @return string
  2221. */
  2222. public function update_html($param, $key, $index, $data, &$result)
  2223. {
  2224. if (isset($param['name']) && $param['update'] != 'hidden' && isset($param['update'])) {
  2225. $result .= Html::pageLeft($param);
  2226. }
  2227. if ($param['update']) {
  2228. # 名称带前缀
  2229. $param['name'] = 'update_' . $param['ext'];
  2230. $param['index'] = $index;
  2231. //$param['value'] = '';
  2232. # 得到当前的值
  2233. if (isset($data[$index]) && !isset($param['value'])) {
  2234. $param['value'] = $data[$index];
  2235. }
  2236. # 得到下级的值
  2237. if (isset($param['child_value']) && isset($data['id'])) {
  2238. $param['child_value'] = $this->value($param['child_value'], $data);
  2239. }
  2240. # 验证option是否是匿名函数
  2241. if (isset($param['option'])) {
  2242. $param['option'] = $this->option($param['option']);
  2243. }
  2244. if (isset($data[$index]) && !isset($param['value']) && isset($param['key']) && $param['update'] != 'editor') {
  2245. $param['value'] = Dever::upload($data[$index]);
  2246. }
  2247. # 处理下级字段
  2248. if (isset($param['child'])) {
  2249. $param['child'] = $this->option($param['child']);
  2250. if (isset($data[$key . '_parent'])) {
  2251. $param['parent_value'] = $data[$key . '_parent'];
  2252. }
  2253. }
  2254. # 设置默认值
  2255. if (isset($param['default'])) {
  2256. $param['default'] = $this->option($param['default']);
  2257. }
  2258. # 处理同步
  2259. if (isset($param['sync']) && isset($data[$param['sync'][0]]) && strpos($key, '-')) {
  2260. $temp = explode('-', $key);
  2261. $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', array('option_' . $param['sync'][1] => $data[$param['sync'][0]]));
  2262. $param['value'] = isset($load[$temp[2]]) ? $load[$temp[2]] : $param['default'];
  2263. }
  2264. $method = $param['update'];
  2265. if (is_array($method)) {
  2266. $c = '';
  2267. if (layadmin()) {
  2268. $c = 'layui-tab-title';
  2269. }
  2270. $delete = true;
  2271. if (isset($param['option'])) {
  2272. $delete = false;
  2273. $result .= '<ul class="nav nav-tabs '.$c.'">{tab}</ul>';
  2274. $order = array
  2275. (
  2276. 'col' => $key,
  2277. 'name' => $param['desc'],
  2278. 'default' => '1',
  2279. 'desc' => $param['desc'],
  2280. 'match' => 'is_string',
  2281. 'update' => 'hidden',
  2282. 'option' => $param['option']
  2283. );
  2284. array_unshift($method, $order);
  2285. if (isset($param['value']) && $param['value']) {
  2286. $value = json_decode(base64_decode($param['value']), true);
  2287. $param['value'] = array();
  2288. foreach ($param['option'] as $k => $v) {
  2289. foreach ($value[$k-1] as $k1 => $v1) {
  2290. $param['value'][$v][$k1] = $v1;
  2291. }
  2292. }
  2293. } else {
  2294. $param['value'] = array();
  2295. foreach ($param['option'] as $k => $v) {
  2296. $param['value'][$v][$key] = $k;
  2297. }
  2298. }
  2299. } else {
  2300. $result .= '<ul class="nav nav-tabs '.$c.'">{tab}<li><a href="javascript:;" class="dever_form_add" toggle_key="' . $key . '">增加一条</a></li></ul>';
  2301. $order = array
  2302. (
  2303. 'col' => 'order',
  2304. 'name' => '排序-按照数字正序排列',
  2305. 'default' => '1',
  2306. 'desc' => '排序',
  2307. 'match' => 'is_string',
  2308. 'update' => 'text',
  2309. );
  2310. array_unshift($method, $order);
  2311. }
  2312. $tab = '';
  2313. $this->update_child(array(), $method, $key, $result, -1, $delete);
  2314. if (isset($param['value']) && $param['value']) {
  2315. if (!is_array($param['value'])) {
  2316. $param['value'] = json_decode(base64_decode($param['value']), true);
  2317. }
  2318. if (is_array($param['value'])) {
  2319. $i = 0;
  2320. foreach ($param['value'] as $k => $v) {
  2321. $n = $k;
  2322. if (is_string($k)) {
  2323. $k = $i;
  2324. }
  2325. $this->update_child($v, $method, $key, $result, $k, $delete);
  2326. $active = '';
  2327. if ($k == 0) {
  2328. $active = 'active';
  2329. }
  2330. if (layadmin() && $active) {
  2331. $active .= ' layui-this';
  2332. }
  2333. $k = $k + 1;
  2334. if (!is_string($n)) {
  2335. $n = '第' . $k . '条';
  2336. }
  2337. $tab .= '<li class="' . $active . '"><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>';
  2338. $i++;
  2339. }
  2340. }
  2341. } else {
  2342. $this->update_child(array(), $method, $key, $result, 0, $delete);
  2343. $tab = '<li class="active layui-this"><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>';
  2344. }
  2345. $result = str_replace('{tab}', $tab, $result);
  2346. } else {
  2347. if (isset($param['update_input']) && isset($data[$index . '_input'])) {
  2348. $param['update_input_data'] = explode(',', $data[$index . '_input']);
  2349. }
  2350. $result .= Html::$method($param);
  2351. }
  2352. if (isset($param['desc']) && ($param['update'] == 'text' || $param['update'] == 'password')) {
  2353. $result .= Html::desc($param['desc']);
  2354. }
  2355. }
  2356. }
  2357. /**
  2358. * update_action
  2359. *
  2360. * @return array
  2361. */
  2362. private function update_child($data, $param, $key, &$result, $index, $delete = true)
  2363. {
  2364. $style = '';
  2365. if ($index != 0) {
  2366. $style = 'style="display:none;"';
  2367. }
  2368. $result .= '<div id="' . $key . '-child-' . ($index + 1) . '" class="dever_' . $key . '_child dever_form_add_child" ' . $style . '>';
  2369. if ($delete) {
  2370. $result .= '<div class="dever_form_delete">[删除]</div>';
  2371. }
  2372. foreach ($param as $k => $v) {
  2373. $v['type'] = $v['update'];
  2374. $prefix = '';
  2375. if ($index < 0) {
  2376. $v['ext'] = $key . '_c_' . $v['col'];
  2377. $prefix = $v['ext'];
  2378. } else {
  2379. $v['ext'] = $key . '_c_' . $index . '_i_' . $v['col'];
  2380. $prefix = $v['ext'];
  2381. }
  2382. if ($v['col'] == 'order') {
  2383. $v['default'] = $index+1;
  2384. }
  2385. $class = $this->update_class($v['col'], $v, $prefix);
  2386. $result .= '<div class="form-group ' . $class . '">';
  2387. $this->update_html($v, $key, $v['col'], $data, $result);
  2388. $result .= '</div>';
  2389. }
  2390. $result .= '</div>';
  2391. }
  2392. /**
  2393. * update_action
  2394. *
  2395. * @return array
  2396. */
  2397. public function update_action_api()
  2398. {
  2399. $method = false;
  2400. $config = $this->config();
  2401. $input = Dever::preInput('update_');
  2402. if ($this->id) {
  2403. # 新增权限
  2404. if (Dever::load('manage/auth.oper', 3) == false) {
  2405. Dever::alert('你没有权限');
  2406. }
  2407. Dever::setInput('where_id', $this->id);
  2408. //Dever::setInput('update_where_id', $this->id);
  2409. $info = $this->load('one', $this->id);
  2410. if ($info) {
  2411. $method = 'update';
  2412. $col = Dever::input('col');
  2413. $value = Dever::input('value');
  2414. if ($col && $value) {
  2415. $method = 'update_' . $col;
  2416. //Dever::setInput('set_' . $col, $value);
  2417. //Dever::setInput('update_' . $col, $value);
  2418. $param['where_id'] = $this->id;
  2419. $param['set_' . $col] = $value;
  2420. $this->load($method, $param);
  2421. $struct = $this->struct_data($config['struct'], array($col => $value));
  2422. Log::add($this->project, $this->table, array('method' => $method, 'input' => $struct, 'struct' => $config['struct']), $this->id);
  2423. Dever::out('yes');
  2424. return;
  2425. }
  2426. $prefix = 'set';
  2427. } else {
  2428. $method = 'insert';
  2429. $prefix = 'add';
  2430. }
  2431. }
  2432. if (!$method) {
  2433. # 新增权限
  2434. if (Dever::load('manage/auth.oper', 4) == false) {
  2435. Dever::alert('你没有权限');
  2436. }
  2437. $method = 'insert';
  2438. $prefix = 'add';
  2439. }
  2440. if ($method && $input) {
  2441. $update = $order = array();
  2442. $i = 0;
  2443. $c = array();
  2444. foreach ($input as $k => $v) {
  2445. if ($v === '') {
  2446. $v = 'null';
  2447. }
  2448. if ($v && is_string($v) && strpos($v, 'copy.') !== false) {
  2449. $temp = str_replace('copy.', '', $v);
  2450. if (isset($input['update_' . $temp])) {
  2451. $v = $input['update_' . $temp];
  2452. }
  2453. }
  2454. if (strpos($k, '_c_') !== false) {
  2455. if ($v == 'null') {
  2456. $v = '';
  2457. }
  2458. $temp = explode('_c_', $k);
  2459. $k = str_replace('update_', $prefix . '_', $temp[0]);
  2460. if (!isset($c[$k])) {
  2461. $c[$k] = array();
  2462. }
  2463. if (strpos($temp[1], '_i_') !== false) {
  2464. $temp = explode('_i_', $temp[1]);
  2465. if (!isset($c[$k][$temp[1]])) {
  2466. $c[$k][$temp[1]] = 0;
  2467. } else {
  2468. $c[$k][$temp[1]]++;
  2469. }
  2470. $num = $c[$k][$temp[1]];
  2471. $update[$i][$k][$num][$temp[1]] = $v;
  2472. if ($temp[1] == 'order') {
  2473. $order[$i][$k][$num] = $v;
  2474. }
  2475. } else {
  2476. //$update[$i][$k][$c][$temp[1]] = $v;
  2477. }
  2478. } elseif (strpos($k, '__') !== false) {
  2479. $temp1 = explode('__', $k);
  2480. $temp2 = explode('_', $temp1[0]);
  2481. $i = $temp2[1] - 1;
  2482. if (strpos($k, 'where_id') !== false) {
  2483. //$update[$i]['where_id'] = $v;
  2484. } else {
  2485. $update[$i]['add_' . $temp1[1]] = $v;
  2486. }
  2487. } else {
  2488. $ki = str_replace('update_', $prefix . '_', $k);
  2489. if (strpos($ki, 'where_id') !== false) {
  2490. if ($method != 'insert') {
  2491. $update[$i]['where_id'] = $v;
  2492. }
  2493. } else {
  2494. if (strpos($k, '-')) {
  2495. $k = str_replace('update_', '', $k);
  2496. if (isset($config['struct'][$k]) && isset($config['struct'][$k]['sync'])) {
  2497. $s_col = $config['struct'][$k]['sync'][0];
  2498. $m_col = $config['struct'][$k]['sync'][1];
  2499. if ($s_col == 'id') {
  2500. $s_value = $this->id;
  2501. } else {
  2502. $s_one = $this->load('one', $this->id);
  2503. $s_value = $s_one[$s_col];
  2504. }
  2505. $temp = explode('-', $k);
  2506. $index = $temp[0] . '/' . $temp[1];
  2507. $update_other_set[$index]['set_' . $temp[2]] = $v;
  2508. //$update_other_set[$index]['set_' . $m_col] = $s_value;
  2509. $update_other_add[$index]['add_' . $temp[2]] = $v;
  2510. $update_other_add[$index]['add_' . $m_col] = $s_value;
  2511. $update_other_id[$index]['option_' . $m_col] = $s_value;
  2512. }
  2513. } else {
  2514. if (is_array($v)) {
  2515. $k = str_replace('update_', '', $k);
  2516. $kd = $k . '_id';
  2517. if (isset($config['struct'][$kd])) {
  2518. foreach ($v as $vk => $vt) {
  2519. if ($vt == -1) {
  2520. if ($vk != 0) {
  2521. unset($v[$vk]);
  2522. }
  2523. }
  2524. }
  2525. if ($v) {
  2526. $vd = end($v);
  2527. $kdi = $prefix . '_' . $kd;
  2528. $update[$i][$kdi] = $vd;
  2529. }
  2530. }
  2531. if (isset($config['struct'][$k]) && strpos($config['struct'][$k]['type'], 'int') !== false) {
  2532. $v = end($v);
  2533. }
  2534. }
  2535. $update[$i][$ki] = $v;
  2536. }
  2537. }
  2538. }
  2539. }
  2540. //print_r($update_other_set);die;
  2541. //print_r($input);
  2542. //print_r($update_other);die;
  2543. //print_r($config['struct']);die;
  2544. # 增加复制的数量
  2545. $copy_num = Dever::input('copy_num');
  2546. if ($copy_num > 0) {
  2547. $update[0]['where_id'] = 0;
  2548. for ($i = 1; $i < $copy_num; $i++) {
  2549. $update[$i] = $update[0];
  2550. # 缓存处理
  2551. $update[$i]['rank'] = $i;
  2552. }
  2553. }
  2554. if ($this->id && !$info) {
  2555. $update[0]['add_id'] = $this->id;
  2556. }
  2557. //print_r($update);die;
  2558. foreach ($update as $k => $v) {
  2559. $method = 'insert';
  2560. $old = array();
  2561. if (isset($v['where_id']) && $v['where_id']) {
  2562. $method = 'update';
  2563. $old = $this->load('one', $v['where_id']);
  2564. }
  2565. if (isset($order[$k])) {
  2566. foreach ($order[$k] as $i => $j) {
  2567. array_multisort($j, SORT_ASC, $v[$i]);
  2568. }
  2569. }
  2570. if (isset($v['set_password']) && (!$v['set_password'] || $v['set_password'] == 'null')) {
  2571. unset($v['set_password']);
  2572. }
  2573. $id = $this->load($method, $v);
  2574. if ($id) {
  2575. $struct = $this->struct_data($config['struct'], $v, $old);
  2576. Log::add($this->project, $this->table, array('method' => $method, 'input' => $struct), $this->id ? $this->id : $id);
  2577. }
  2578. if (isset($update_other_id) && $update_other_id) {
  2579. foreach ($update_other_set as $k => $v) {
  2580. $check = Dever::load($k . '-one', $update_other_id[$k]);
  2581. //print_r($check);die;
  2582. if ($check) {
  2583. $v['where_id'] = $check['id'];
  2584. Dever::load($k . '-update', $v);
  2585. } else {
  2586. Dever::load($k . '-insert', $update_other_add[$k]);
  2587. }
  2588. }
  2589. }
  2590. }
  2591. }
  2592. Dever::out('yes');
  2593. }
  2594. private function struct_data($struct, $data, $old = array())
  2595. {
  2596. $log = $tlog = array();
  2597. foreach ($struct as $i => $j) {
  2598. if (isset($j['list_name'])) {
  2599. $j['name'] = $j['list_name'];
  2600. } elseif (strpos($j['name'], '-')) {
  2601. $temp = explode('-', $j['name']);
  2602. $j['name'] = $temp[0];
  2603. }
  2604. if (isset($j['list_table'])) {
  2605. $j['list'] = $j['list_table'];
  2606. if ($j['list'] == false) {
  2607. $data[$i] = false;
  2608. }
  2609. }
  2610. $list = (isset($j['list']) && is_string($j['list']) && $j['list'] != 'table');
  2611. if (isset($data['where_' . $i]) && $data['where_' . $i]) {
  2612. $log[$j['name']] = $data['where_' . $i];
  2613. } elseif (isset($data['set_' . $i]) && $data['set_' . $i]) {
  2614. $log[$j['name']] = $data['set_' . $i];
  2615. } elseif (isset($data['add_' . $i]) && $data['add_' . $i]) {
  2616. $log[$j['name']] = $data['add_' . $i];
  2617. } elseif (isset($data[$i]) && $data[$i]) {
  2618. $log[$j['name']] = $list ? $this->value($j['list'], $data) : $data[$i];
  2619. }
  2620. if (isset($log[$j['name']])) {
  2621. $tlog[$j['name']] = $log[$j['name']];
  2622. if (is_array($tlog[$j['name']])) {
  2623. if (isset($tlog[$j['name']][0]) && is_array($tlog[$j['name']][0])) {
  2624. $tlog[$j['name']] = json_encode($tlog[$j['name']]);
  2625. if (isset($old[$i]) && is_array($old[$i])) {
  2626. $old[$i] = json_encode($old[$i]);
  2627. }
  2628. } elseif (isset($tlog[$j['name']][0])) {
  2629. $tlog[$j['name']] = implode(',', $tlog[$j['name']]);
  2630. if (isset($old[$i]) && is_array($old[$i])) {
  2631. $old[$i] = implode(',', $old[$i]);
  2632. }
  2633. }
  2634. } 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) {
  2635. $log[$j['name']] = '<img layer-src="' . $log[$j['name']] . '" src="' . $log[$j['name']] . '" width="150">';
  2636. if (isset($old[$i]) && $old[$i]) {
  2637. $old[$i] = '<img layer-src="' . $old[$i] . '" src="' . $old[$i] . '" width="150">';
  2638. }
  2639. } elseif (is_numeric($log[$j['name']]) && (strpos($i, 'time') !== false || strpos($i, 'date') !== false)) {
  2640. $log[$j['name']] = date("Y-m-d H:i:s", $log[$j['name']]);
  2641. if (isset($old[$i]) && $old[$i]) {
  2642. $old[$i] = date("Y-m-d H:i:s", $old[$i]);
  2643. }
  2644. } elseif (isset($j['decode'])) {
  2645. $log[$j['name']] = json_decode(base64_decode($log[$j['name']]), true);
  2646. if (isset($old[$i]) && $old[$i]) {
  2647. $old[$i] = json_decode(base64_decode($old[$i]), true);
  2648. }
  2649. }
  2650. if (isset($j['option']) && !$list) {
  2651. $name = array();
  2652. $option = $this->option($j['option']);
  2653. if (is_array($option)) {
  2654. foreach ($option as $a => $b) {
  2655. if (!is_array($log[$j['name']])) {
  2656. if ($a == $log[$j['name']]) {
  2657. $name[] = (is_array($b) && isset($b['name'])) ? $b['name'] : $b;
  2658. }
  2659. } elseif (in_array($a, $log[$j['name']])) {
  2660. $name[] = (is_array($b) && isset($b['name'])) ? $b['name'] : $b;
  2661. }
  2662. }
  2663. }
  2664. $log[$j['name']] = implode(',', $name);
  2665. }
  2666. if (isset($old[$i]) && $old[$i] != $tlog[$j['name']]) {
  2667. $log[$j['name']] = array('old' => $old[$i], 'new' => $log[$j['name']]);
  2668. }
  2669. }
  2670. }
  2671. return $log;
  2672. }
  2673. /**
  2674. * delete_action
  2675. *
  2676. * @return array
  2677. */
  2678. public function delete_action_api()
  2679. {
  2680. if (Dever::load('manage/auth.oper', 5) == false) {
  2681. Dever::alert('您没有权限');
  2682. }
  2683. $config = $this->config();
  2684. if (isset($config['manage']['delete']) && $config['manage']['delete'] === 2) {
  2685. $this->load('delete', array('where_id' => $this->id));
  2686. } elseif (isset($config['struct']['state']) && (!isset($config['manage']['delete']) || (isset($config['manage']['delete']) && $config['manage']['delete']))) {
  2687. $this->load('update', array('where_id' => $this->id, 'state' => 2));
  2688. }
  2689. return 'reload';
  2690. return 'reloaderror';
  2691. }
  2692. /**
  2693. * recovery_action
  2694. *
  2695. * @return array
  2696. */
  2697. public function recovery_action_api()
  2698. {
  2699. if (Dever::load('manage/auth.oper', 5) == false) {
  2700. Dever::alert('您没有权限');
  2701. }
  2702. $this->load('update', array('where_id' => $this->id, 'state' => 1));
  2703. return 'reload';
  2704. }
  2705. /**
  2706. * stat 为主动统计提供相关数据
  2707. *
  2708. * @return array
  2709. */
  2710. public function stat()
  2711. {
  2712. //bundle 包依赖工具
  2713. $config = $this->config();
  2714. if (empty($config['manage']['stat'])) {
  2715. Dever::alert('该项目主动统计功能未开放');
  2716. }
  2717. $data = $config['manage'];
  2718. $data['table'] = '';
  2719. $method = $this->project . '/' . $this->table . '-all';
  2720. $gp = Dever::input('gp', 'month,day');
  2721. $col = is_string($gp) ? explode(',', $gp) : $gp;
  2722. $data['search'] = $this->stat_search($config['struct'], $gp, $config['manage']['stat'], $config['manage']['search']);
  2723. foreach ($col as $k => $v) {
  2724. $this->stat_data($data, $config['struct'], $v, $method);
  2725. }
  2726. return $data;
  2727. }
  2728. /**
  2729. * stat 为主动统计提供导出数据 后续优化
  2730. *
  2731. * @return array
  2732. */
  2733. public function stat_excel()
  2734. {
  2735. Dever::$global['base']['excel'] = 1;
  2736. //print_r($data['thead']);die;
  2737. $data = $this->stat();
  2738. if ($data && isset($data['list'])) {
  2739. $xls = new \PHPExcel();
  2740. $xls->getProperties()->setCreator("Maze Stat Excel")
  2741. ->setLastModifiedBy("Maze Stat Excel")
  2742. ->setTitle("Office 2007 XLSX Maze Document")
  2743. ->setSubject("Office 2007 XLSX Maze Document")
  2744. ->setDescription("Mazephp Stat Excel")
  2745. ->setKeywords("Mazephp Stat Excel")
  2746. ->setCategory("Mazephp Stat Excel");
  2747. $info = $this->info();
  2748. $name = $info['list_header'] . '的' . $info['stat_desc'] . '-' . $info['project_name'];
  2749. $start = 65;
  2750. $s = 0;
  2751. foreach ($data['thead'] as $k => $v) {
  2752. if ($s > 0) {
  2753. $xls->createSheet();
  2754. }
  2755. $act = $xls->setActiveSheetIndex($s);
  2756. $act->setTitle($v[0]);
  2757. $s++;
  2758. $i = 0;
  2759. foreach ($v as $kj => $vj) {
  2760. $num = 1;
  2761. $cell = $this->_getChr($start, $i);
  2762. $act->setCellValue($cell . '' . $num, $vj);
  2763. $act->getColumnDimension($cell)->setWidth(20);
  2764. $i++;
  2765. if (isset($data['list'][$k])) {
  2766. foreach ($data['list'][$k] as $ki => $vi) {
  2767. if (isset($vi[$kj])) {
  2768. $num += 1;
  2769. $act->setCellValue($cell . $num, $vi[$kj]);
  2770. }
  2771. }
  2772. }
  2773. }
  2774. }
  2775. //$act->getStyle('A1:'.$k.'20')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER); // 垂直居中
  2776. //$act->getStyle('A1:'.$k.'20')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);// 水平居中
  2777. $xls->setActiveSheetIndex(0);
  2778. $filename = $name . '.xlsx';
  2779. header('Pragma: public');
  2780. header('Expires: 0');
  2781. header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
  2782. header('Content-Type:application/force-download');
  2783. header('Content-Type:application/vnd.ms-execl');
  2784. header('Content-Type:application/octet-stream');
  2785. header('Content-Type:application/download');
  2786. header("Content-Disposition:attachment;filename='" . $filename . "'");
  2787. header('Content-Transfer-Encoding:binary');
  2788. $write = \PHPExcel_IOFactory::createWriter($xls, 'Excel2007');
  2789. $write->save('php://output');
  2790. }
  2791. }
  2792. /**
  2793. * stat_search
  2794. *
  2795. * @return mixed
  2796. */
  2797. private function stat_search($struct, $col, $stat, $search)
  2798. {
  2799. unset($struct['id']);
  2800. unset($struct['cdate']);
  2801. if ($stat) {
  2802. $stat = explode(',', $stat);
  2803. foreach ($stat as $k => $v) {
  2804. if (isset($struct[$v])) {
  2805. unset($struct[$v]);
  2806. }
  2807. }
  2808. }
  2809. $struct['day']['name'] = '天';
  2810. $struct['month']['name'] = '月';
  2811. $struct['year']['name'] = '年';
  2812. $param['update'] = 'checkbox';
  2813. $param['name'] = 'gp';
  2814. $param['value'] = $col;
  2815. $param['option'] = $struct;
  2816. $html = '<form action="' . $this->url('stat') . '" method="post" id="f1">';
  2817. $html .= '<div class="form-group">';
  2818. $html .= Html::pageLeft(array('name' => '统计项', 'col' => 'col'));
  2819. $html .= Html::radio($param);
  2820. $html .= '</div>';
  2821. $input = Dever::preInput('search_');
  2822. if (isset($search['date'])) {
  2823. foreach ($search['date'] as $k => $v) {
  2824. $html .= '<div class="form-group">';
  2825. $this->list_search_time($html, $input, 'search_', $k, $v, 'date');
  2826. $html .= '</div>';
  2827. }
  2828. $input = Dever::preInput('search_');
  2829. if ($input) {
  2830. foreach ($input as $k => $v) {
  2831. if ($v && strpos($k, 'option_') !== false) {
  2832. Dever::setInput(str_replace('search_', '', $k), $v);
  2833. }
  2834. }
  2835. }
  2836. }
  2837. if (isset($search['fulltext'])) {
  2838. $html .= '<div class="form-group">';
  2839. $this->list_search_select($html, $input, 'search_fulltext', '选择检索项', $search['fulltext']);
  2840. $this->list_search_select($html, $input, 'search_fulltext_type', '', array
  2841. (
  2842. 1 => '精确匹配',
  2843. 2 => '模糊匹配',
  2844. 3 => '大于',
  2845. 4 => '大于等于',
  2846. 5 => '小于',
  2847. 6 => '小于等于',
  2848. ), 1);
  2849. $value = array();
  2850. $value['name'] = 'search_fulltext_value';
  2851. $value['class'] = 'form-control';
  2852. if (isset($input[$value['name']])) {
  2853. $value['value'] = $input[$value['name']];
  2854. $fix = '';
  2855. if ($input['search_fulltext_type'] == 2) {
  2856. $fix = '%';
  2857. }
  2858. Dever::setInput('option_' . $input['search_fulltext'], $fix . $value['value'] . $fix);
  2859. //print_r(Dever::input('option_name'));die;
  2860. }
  2861. $html .= Html::text($value, false);
  2862. $html .= '</div>';
  2863. }
  2864. $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>';
  2865. $html .= '&nbsp;&nbsp;<a href="javascript:;" class="btn btn-warning" onclick="$(\'#f1\').attr(\'action\', \'' . $this->url('stat_excel') . '\').submit();">下载报表</a>';
  2866. $html .= '</form>';
  2867. return $html;
  2868. }
  2869. /**
  2870. * stat_data
  2871. *
  2872. * @return mixed
  2873. */
  2874. private function stat_data(&$data, $struct, $col, $method)
  2875. {
  2876. Dever::setInput('group', $col);
  2877. switch ($col) {
  2878. case 'year':
  2879. $name = '按年统计';
  2880. break;
  2881. case 'month':
  2882. $name = '按月统计';
  2883. break;
  2884. case 'day':
  2885. $name = '按天统计';
  2886. break;
  2887. default:
  2888. $name = $struct[$col]['name'];
  2889. break;
  2890. }
  2891. $list = Dever::load($method, array('group' => $col, 'col' => 'count(1) as total,id'));
  2892. $data['table'] .= '<div style="overflow-y:auto;width:100%;max-height:600px;"><table class="table table-bordered table-striped">';
  2893. $data['table'] .= '<thead><tr><th>' . $name . '</th><th>统计数字</th></tr></thead>';
  2894. $data['thead'][$col] = array($name, '统计数字');
  2895. if ($list) {
  2896. $data['table'] .= '<tbody>';
  2897. $total = 0;
  2898. foreach ($list as $k => $v) {
  2899. if (isset($v[$col])) {
  2900. if (isset($struct[$col]['option'])) {
  2901. $option = $this->option($struct[$col]['option']);
  2902. if (isset($option[$v[$col]])) {
  2903. $v[$col] = $option[$v[$col]];
  2904. if (is_array($v[$col])) {
  2905. $v[$col] = $v[$col]['name'];
  2906. }
  2907. }
  2908. }
  2909. $data['table'] .= '<tr><td width="60%" style="word-break:break-all;word-wrap:break-word;">' . $v[$col] . '</td><td>' . $v['total'] . '</td></tr>';
  2910. $total += $v['total'];
  2911. $data['list'][$col][] = array($v[$col], $v['total']);
  2912. }
  2913. }
  2914. $data['table'] .= '</tbody>';
  2915. if ($total > 0 && $k > 0) {
  2916. $data['table'] .= '<tr><td style="font-weight:bold">汇总</td><td style="font-weight:bold">' . $total . '</td></tr>';
  2917. $data['list'][$col][] = array('汇总', $total);
  2918. }
  2919. }
  2920. $data['table'] .= '</table></div>';
  2921. }
  2922. /**
  2923. * load
  2924. *
  2925. * @return mixed
  2926. */
  2927. private function load($method = 'one', $param = array())
  2928. {
  2929. return Dever::load($this->project . '/' . $this->table . '-' . $method, $param);
  2930. }
  2931. /**
  2932. * __call
  2933. *
  2934. * @return object
  2935. */
  2936. public function __call($method, $param)
  2937. {
  2938. if (strpos($method, 'html_') !== false) {
  2939. return Html::text($param);
  2940. }
  2941. return $this;
  2942. }
  2943. /**
  2944. * option
  2945. *
  2946. * @return string
  2947. */
  2948. private function option($option, $value = false)
  2949. {
  2950. if (is_object($option)) {
  2951. $function = $option;
  2952. $option = $function();
  2953. }
  2954. if ($value && is_array($value)) {
  2955. $state = false;
  2956. foreach ($value as $k => $v) {
  2957. if ($v === true) {
  2958. $state = true;
  2959. break;
  2960. }
  2961. }
  2962. if ($state) {
  2963. $option = array_intersect_key($option, $value);
  2964. } else {
  2965. $option = $value;
  2966. }
  2967. }
  2968. return $option;
  2969. }
  2970. /**
  2971. * option
  2972. *
  2973. * @return string
  2974. */
  2975. public function manage()
  2976. {
  2977. $config = $this->config();
  2978. return $config;
  2979. }
  2980. /**
  2981. * valid
  2982. *
  2983. * @return string
  2984. */
  2985. public function valid()
  2986. {
  2987. //http://placehold.it/350x150
  2988. $config = $this->config();
  2989. if (isset($config['struct'])) {
  2990. $rule = array();
  2991. $rule['required']['regex'] = 'none';
  2992. $rule['required']['alertText'] = '此项不能为空';
  2993. $rule['required']['alertTextCheckboxMultiple'] = '请选择一个选项';
  2994. $rule['required']['alertTextCheckboxe'] = '请选择一个选项';
  2995. $rule['required']['alertTextDateRange'] = '日期范围不可空白';
  2996. foreach ($config['struct'] as $k => $v) {
  2997. if (isset($v['match']) && $v['match'] != 'option' && is_string($v['match']) && strpos($v['match'], '/') !== false) {
  2998. if (strstr($v['match'], 'option||')) {
  2999. $v['match'] = str_replace('option||', '', $v['match']);
  3000. }
  3001. $rule[$k]['regex'] = $v['match'];
  3002. $rule[$k]['alertText'] = $v['desc'];
  3003. }
  3004. }
  3005. }
  3006. $script = '<script>';
  3007. //参考https://blog.csdn.net/wangzl1163/article/details/51071826
  3008. //http://code.ciaoca.com/jquery/validation-engine/demo/demoOnForm
  3009. $script .= '(function($){
  3010. $.fn.validationEngineLanguage = function(){
  3011. };
  3012. $.validationEngineLanguage = {
  3013. newLang: function(){
  3014. $.validationEngineLanguage.allRules = ';
  3015. //此处进行了转义过滤,其实也可以使用json_encode的第二个参数,不过只支持5.4以上版本,考虑到虚拟主机就放弃了
  3016. $script .= str_replace(array('\\\\', '\\/', '"/', '/"', '/u"', '/g"', '/i"', '\x{4e00}-\x{9fa5}', '\x'), array('\\', '/', '/', '/', '/u', '/g', '/i', '\u4e00-\u9fa5', '\u'), json_encode($rule)) . ';';
  3017. $script .= '}
  3018. };
  3019. $.validationEngineLanguage.newLang();
  3020. })(jQuery);';
  3021. $script .= '$(document).ready(function(){
  3022. $(".form1").validationEngine("attach",{onSuccess:function(){submit();},onFailure:function(){submit();}});
  3023. });';
  3024. $script .= '</script>';
  3025. //print_r($script);die;
  3026. return $script;
  3027. }
  3028. /**
  3029. * save
  3030. *
  3031. * @return string
  3032. */
  3033. public function save()
  3034. {
  3035. $config = $this->config();
  3036. if (isset($config['manage']['save'])) {
  3037. return 'yes';
  3038. }
  3039. return 'no';
  3040. }
  3041. }