Manage.php 4.2 KB

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