info_attr.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. $category = Dever::input('search_option_category');
  3. $table = '';
  4. $attr = array();
  5. $create = Dever::config('database')->create;
  6. if ($category) {
  7. $where['category'] = $category;
  8. $attr = Dever::db('category/attr')->one($where);
  9. if ($attr) {
  10. $table = '_' . str_replace(',', '_', $category);
  11. # 自动建表开启并且自动添加字段
  12. $create = false;
  13. $attr = Dever::load('attr/api')->getValue($attr['attr'], $attr['attr_input']);
  14. }
  15. }
  16. $config = array
  17. (
  18. # 表名
  19. 'name' => 'info_attr' . $table,
  20. # 显示给用户看的名称
  21. 'lang' => '需求属性',
  22. 'order' => 100,
  23. 'menu' => false,
  24. 'create' => $create,
  25. 'attr' => $attr,
  26. 'end' => array
  27. (
  28. //'insert' => 'demand/lib/manage.attrUpdate',
  29. //'update' => 'demand/lib/manage.attrUpdate',
  30. ),
  31. # 数据结构 不同的字段放这里
  32. 'struct' => array
  33. (
  34. 'id' => array
  35. (
  36. 'type' => 'int-11',
  37. 'name' => 'ID',
  38. 'default' => '',
  39. 'desc' => '',
  40. 'match' => 'is_numeric',
  41. //'list' => true,
  42. ),
  43. ),
  44. # 管理功能
  45. 'manage' => array
  46. (
  47. ),
  48. # request 请求接口定义
  49. 'request' => array
  50. (
  51. ),
  52. );
  53. # 属性完全自定义吧。这种情况用dever就是方便了。其他框架都需要自己实现
  54. if ($attr) {
  55. foreach ($attr as $k => $v) {
  56. $k = 'attr_' . $v['id'];
  57. $config['struct'][$k] = array();
  58. $option = array();
  59. if ($v['type_option']) {
  60. $v['type_option'] = explode("\n", $v['type_option']);
  61. foreach ($v['type_option'] as $k1 => $v1) {
  62. $option[$k1+1] = $v1;
  63. }
  64. }
  65. $config['struct'][$k]['name'] = $v['name'];
  66. $config['struct'][$k]['default'] = '';
  67. $config['struct'][$k]['desc'] = $v['name'];
  68. switch ($v['type']) {
  69. case 2:
  70. $config['struct'][$k]['update'] = 'textarea';
  71. $config['struct'][$k]['search'] = 'fulltext';
  72. $config['struct'][$k]['type'] = 'varchar-800';
  73. $config['struct'][$k]['match'] = 'is_string';
  74. break;
  75. case 3:
  76. $config['struct'][$k]['type'] = 'text-255';
  77. $config['struct'][$k]['update'] = 'editor';
  78. $config['struct'][$k]['match'] = 'is_string';
  79. $config['struct'][$k]['key'] = 1;
  80. case 4:
  81. $config['struct'][$k]['update'] = 'image';
  82. $config['struct'][$k]['type'] = 'varchar-150';
  83. $config['struct'][$k]['match'] = 'is_string';
  84. $config['struct'][$k]['key'] = 1;
  85. break;
  86. case 5:
  87. $config['struct'][$k]['update'] = 'images';
  88. $config['struct'][$k]['type'] = 'text-255';
  89. $config['struct'][$k]['match'] = 'is_string';
  90. $config['struct'][$k]['key'] = 1;
  91. break;
  92. case 6:
  93. $config['struct'][$k]['type'] = 'varchar-800';
  94. $config['struct'][$k]['match'] = 'is_string';
  95. $config['struct'][$k]['update'] = 'linkage';
  96. $config['struct'][$k]['search'] = 'linkage';
  97. $config['struct'][$k]['option'] = Dever::url('area/api.get');
  98. //$config['struct'][$k]['list'] = 'Dever::load("area/api.string", "{area}")';
  99. break;
  100. case 10:
  101. $config['struct'][$k]['update'] = 'radio';
  102. $config['struct'][$k]['type'] = 'int-11';
  103. $config['struct'][$k]['match'] = 'is_numeric';
  104. $config['struct'][$k]['option'] = $option;
  105. $config['struct'][$k]['search'] = 'select';
  106. $config['struct'][$k]['default'] = 1;
  107. break;
  108. case 11:
  109. $config['struct'][$k]['update'] = 'checkbox';
  110. $config['struct'][$k]['type'] = 'varchar-150';
  111. $config['struct'][$k]['match'] = 'is_string';
  112. $config['struct'][$k]['option'] = $option;
  113. $config['struct'][$k]['search'] = 'select';
  114. $config['struct'][$k]['default'] = 1;
  115. break;
  116. case 12:
  117. $config['struct'][$k]['update'] = 'select';
  118. $config['struct'][$k]['type'] = 'int-11';
  119. $config['struct'][$k]['match'] = 'is_numeric';
  120. $config['struct'][$k]['option'] = $option;
  121. $config['struct'][$k]['search'] = 'select';
  122. $config['struct'][$k]['default'] = 1;
  123. break;
  124. default:
  125. $config['struct'][$k]['update'] = 'text';
  126. $config['struct'][$k]['search'] = 'fulltext';
  127. if ($v['data_type'] == 1) {
  128. $config['struct'][$k]['type'] = 'int-11';
  129. $config['struct'][$k]['match'] = 'is_numeric';
  130. } else {
  131. $config['struct'][$k]['type'] = 'varchar-800';
  132. $config['struct'][$k]['match'] = 'is_string';
  133. }
  134. }
  135. if ($v['option_type'] && $v['option_type'] == 2) {
  136. $config['struct'][$k]['match'] = 'option';
  137. }
  138. }
  139. }
  140. return $config;