Manage.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace Page\Lib;
  3. use Dever;
  4. class Manage
  5. {
  6. public function search_api()
  7. {
  8. $keyword = Dever::input('keyword');
  9. $yes = Dever::input('yes');
  10. $where = array();
  11. $type = Dever::input('type');
  12. $func = Dever::db('page/module')->config['func'];
  13. $func = $func();
  14. $method = false;
  15. if ($func && $type && isset($func[$type]['search'])) {
  16. $method = $func[$type]['search'];
  17. }
  18. if (!$method) {
  19. Dever::alert('暂无数据');
  20. }
  21. if ($yes) {
  22. $yes = Dever::db($method)->search(array('ids' => $yes));
  23. }
  24. if (!$keyword) {
  25. $where['limit'] = '0,50';
  26. $data = Dever::db($method)->search($where);
  27. } else {
  28. $where['name'] = $keyword;
  29. $data = Dever::db($method)->search($where);
  30. }
  31. $result = array();
  32. if ($yes) {
  33. foreach ($yes as $k => $v) {
  34. if (isset($data[$k])) {
  35. unset($data[$k]);
  36. }
  37. $yes[$k]['selected'] = 'selected';
  38. }
  39. $data = $yes + $data;
  40. $data = array_merge($data, array());
  41. } else {
  42. $data = array_merge($data, array());
  43. }
  44. if (!$data) {
  45. Dever::alert('暂无数据');
  46. }
  47. return $data;
  48. }
  49. public function showType()
  50. {
  51. $value = Dever::input('value');
  52. $config['type_id'] = Dever::db('page/data')->config['struct']['type_id'];
  53. $config['type_id']['name'] = '';
  54. $config['type_id']['update'] = 'select';
  55. $config['type_id']['update_search'] = 'page/lib/manage.search?type=' . $value;
  56. $data = Dever::load('manage/database')->update_struct(array('struct' => $config), false, $data, -1, '', true, false);
  57. return array('data' => $data, 'html' => '', 'remove' => '');
  58. }
  59. # 查看图片
  60. public function pic($pic)
  61. {
  62. $table = array();
  63. $table[0] = '<img src="'.$pic.'" width=“150”/>';
  64. return Dever::table($table);
  65. }
  66. public function show($id)
  67. {
  68. $table = Dever::load('page/lib/data')->getOne($id, 1);
  69. if (count($table) == 1) {
  70. $table = $table[0];
  71. }
  72. return Dever::table($table);
  73. }
  74. # 查看模板
  75. public function template()
  76. {
  77. $data = Dever::db('page/template')->state();
  78. foreach ($data as $k => $v) {
  79. if (!$v['pic']) {
  80. $v['pic'] = '';
  81. }
  82. $data[$k]['name'] = '<img src="'.$v['pic'].'" style="margin-bottom: 34px;width:300px" alt="'.$v['name'].'"/>';
  83. }
  84. return $data;
  85. }
  86. public function getData($col, $id)
  87. {
  88. $data = Dever::db('page/data')->find($id);
  89. if ($data['type'] > 0) {
  90. $func = Dever::db('page/func')->find($data['type']);
  91. $info = Dever::load($func['api'], $id);
  92. $func['col'] = Dever::json_decode($func['col']);
  93. foreach ($func['col'] as $k => $v) {
  94. if ($v['col_id'] == $col) {
  95. return $info[$v['name']];
  96. }
  97. }
  98. }
  99. return $data['col_' . $col];
  100. }
  101. }