Manage.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. foreach ($struct as $k => $v) {
  33. if (strstr($k, 'col_')) {
  34. $config[$k] = $v;
  35. $config[$k]['update'] = $v['update_bak'];
  36. }
  37. }
  38. } else {
  39. $config['type_id']['update'] = 'select';
  40. $config['type_id']['update_search'] = 'page/lib/manage.search?type=' . $value;
  41. if ($data && $data['type_id']) {
  42. $config['type_id']['update_search_value'] = $info['type_id'];
  43. }
  44. $func = Dever::db('page/func')->find($value);
  45. if ($func && $func['col']) {
  46. $func['col'] = Dever::array_decode($func['col']);
  47. $col = array();
  48. foreach ($func['col'] as $v) {
  49. $col['col_' . $v['col_id']] = 1;
  50. }
  51. foreach ($struct as $k => $v) {
  52. if (strstr($k, 'col_') && !isset($col[$k])) {
  53. $config[$k] = $v;
  54. $config[$k]['update'] = 'hidden';
  55. }
  56. }
  57. }
  58. }
  59. $data = Dever::load('manage/database')->update_struct(array('struct' => $config), false, $data, -1, '', false, false);
  60. return $data;
  61. }
  62. # 查看图片
  63. public function pic($pic)
  64. {
  65. $table = array();
  66. return '<img src="'.$pic.'" width=“150”/>';
  67. return Dever::table($table);
  68. }
  69. public function show($id)
  70. {
  71. $table = Dever::load('page/lib/data')->getOne($id);
  72. if (count($table) == 1) {
  73. $table = $table[0];
  74. }
  75. return Dever::table($table);
  76. }
  77. # 查看模板
  78. public function template()
  79. {
  80. $data = Dever::db('page/template')->state();
  81. foreach ($data as $k => $v) {
  82. if (!$v['pic']) {
  83. $v['pic'] = '';
  84. }
  85. $data[$k]['name'] = '<img src="'.$v['pic'].'" style="margin-bottom: 34px;width:300px" alt="'.$v['name'].'"/>';
  86. }
  87. return $data;
  88. }
  89. public function getPic($col, $id)
  90. {
  91. $info = $this->getData($col, $id);
  92. return $this->pic($info);
  93. }
  94. public function getData($col, $id)
  95. {
  96. $data = Dever::db('page/data')->find($id);
  97. if ($data['type'] > 0 && $data['type_id'] > 0) {
  98. $func = Dever::db('page/func')->find($data['type']);
  99. if ($func['col']) {
  100. $info = Dever::load($func['api'], $data['type_id']);
  101. if ($info) {
  102. $func['col'] = Dever::json_decode($func['col']);
  103. foreach ($func['col'] as $k => $v) {
  104. if ($v['col_id'] == $col) {
  105. return $info[$v['name']];
  106. }
  107. }
  108. }
  109. }
  110. }
  111. return $data['col_' . $col];
  112. }
  113. }