|
@@ -69,38 +69,157 @@ class Api
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 设置数据库的结构信息
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function setDatabaseConfig($attr, &$config)
|
|
|
+ {
|
|
|
+ if ($attr) {
|
|
|
+ foreach ($attr as $k => $v) {
|
|
|
+ $k = 'attr_' . $v['id'];
|
|
|
+ $config['struct'][$k] = array();
|
|
|
+
|
|
|
+ $option = array();
|
|
|
+ if ($v['type_option']) {
|
|
|
+ $v['type_option'] = explode("\n", $v['type_option']);
|
|
|
+ foreach ($v['type_option'] as $k1 => $v1) {
|
|
|
+ $option[$k1+1] = $v1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $config['struct'][$k]['name'] = $v['name'];
|
|
|
+ $config['struct'][$k]['default'] = '';
|
|
|
+ $config['struct'][$k]['desc'] = $v['name'];
|
|
|
+
|
|
|
+ switch ($v['type']) {
|
|
|
+ case 3:
|
|
|
+ $config['struct'][$k]['update'] = 'textarea';
|
|
|
+ $config['struct'][$k]['search'] = 'fulltext';
|
|
|
+ $config['struct'][$k]['type'] = 'varchar-800';
|
|
|
+ $config['struct'][$k]['match'] = 'is_string';
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ $config['struct'][$k]['type'] = 'text-255';
|
|
|
+ $config['struct'][$k]['update'] = 'editor';
|
|
|
+ $config['struct'][$k]['match'] = 'is_string';
|
|
|
+ $config['struct'][$k]['key'] = 1;
|
|
|
+ case 5:
|
|
|
+ $config['struct'][$k]['update'] = 'image';
|
|
|
+ $config['struct'][$k]['type'] = 'varchar-150';
|
|
|
+ $config['struct'][$k]['match'] = 'is_string';
|
|
|
+ $config['struct'][$k]['key'] = 1;
|
|
|
+ break;
|
|
|
+ case 6:
|
|
|
+ $config['struct'][$k]['update'] = 'images';
|
|
|
+ $config['struct'][$k]['type'] = 'text-255';
|
|
|
+ $config['struct'][$k]['match'] = 'is_string';
|
|
|
+ $config['struct'][$k]['key'] = 1;
|
|
|
+ break;
|
|
|
+ case 7:
|
|
|
+ $config['struct'][$k]['type'] = 'varchar-800';
|
|
|
+ $config['struct'][$k]['match'] = 'is_string';
|
|
|
+ $config['struct'][$k]['update'] = 'linkage';
|
|
|
+ $config['struct'][$k]['search'] = 'linkage';
|
|
|
+ $config['struct'][$k]['option'] = Dever::url('area/api.get');
|
|
|
+ //$config['struct'][$k]['list'] = 'Dever::load("area/api.string", "{area}")';
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 10:
|
|
|
+ $config['struct'][$k]['update'] = 'radio';
|
|
|
+ $config['struct'][$k]['type'] = 'varchar-11';
|
|
|
+ $config['struct'][$k]['match'] = 'is_numeric';
|
|
|
+ $config['struct'][$k]['option'] = $option;
|
|
|
+ $config['struct'][$k]['search'] = 'select';
|
|
|
+ $config['struct'][$k]['default'] = '1';
|
|
|
+
|
|
|
+ break;
|
|
|
+ case 11:
|
|
|
+ $config['struct'][$k]['update'] = 'checkbox';
|
|
|
+ $config['struct'][$k]['type'] = 'varchar-150';
|
|
|
+ $config['struct'][$k]['match'] = 'is_string';
|
|
|
+ $config['struct'][$k]['option'] = $option;
|
|
|
+ $config['struct'][$k]['search'] = 'select';
|
|
|
+ $config['struct'][$k]['default'] = '1';
|
|
|
+ break;
|
|
|
+ case 12:
|
|
|
+ $config['struct'][$k]['update'] = 'select';
|
|
|
+ $config['struct'][$k]['type'] = 'varchar-11';
|
|
|
+ $config['struct'][$k]['match'] = 'is_numeric';
|
|
|
+ $config['struct'][$k]['option'] = $option;
|
|
|
+ $config['struct'][$k]['search'] = 'select';
|
|
|
+ $config['struct'][$k]['default'] = '1';
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ $config['struct'][$k]['update'] = 'text';
|
|
|
+ $config['struct'][$k]['search'] = 'fulltext';
|
|
|
+ if ($v['data_type'] == 1 || $v['type'] == 1) {
|
|
|
+ $config['struct'][$k]['type'] = 'varchar-11';
|
|
|
+ $config['struct'][$k]['match'] = 'is_numeric';
|
|
|
+ } else {
|
|
|
+ $config['struct'][$k]['type'] = 'varchar-800';
|
|
|
+ $config['struct'][$k]['match'] = 'is_string';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($v['option_type'] && $v['option_type'] == 2) {
|
|
|
+ $config['struct'][$k]['match'] = 'option';
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($v['value']) {
|
|
|
+ $config['struct'][$k]['default'] = $v['value'];
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($v['state'] == 2) {
|
|
|
+ unset($config['struct'][$k]['update']);
|
|
|
+ }
|
|
|
+
|
|
|
+ # 还要根据搜索来建立索引,另外,如果数据结构改了怎么办。暂时用varchar
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 获取属性的值,无类别
|
|
|
*
|
|
|
* @return mixed
|
|
|
*/
|
|
|
- public function getValue($ids, $value)
|
|
|
+ public function getValue($ids, $value, $order = 'all')
|
|
|
{
|
|
|
$result = array();
|
|
|
if ($ids) {
|
|
|
$where['ids'] = $ids;
|
|
|
- $data = Dever::db('attr/info')->getAllByIds($where);
|
|
|
+ $method = 'getAllByIds';
|
|
|
+ if ($order == 'list') {
|
|
|
+ $method = 'getListByIds';
|
|
|
+ } elseif ($order == 'search') {
|
|
|
+ $method = 'getSearchByIds';
|
|
|
+ } elseif ($order == 'view') {
|
|
|
+ $method = 'getViewByIds';
|
|
|
+ }
|
|
|
+ $data = Dever::db('attr/info')->$method($where);
|
|
|
|
|
|
$ids = explode(',', $ids);
|
|
|
$value = explode(',', $value);
|
|
|
if ($data) {
|
|
|
foreach ($ids as $k => $v) {
|
|
|
if (isset($data[$v])) {
|
|
|
- $result[$v] = $data[$v];
|
|
|
if (isset($value) && $value[$k]) {
|
|
|
- $result[$v]['value'] = $value[$k];
|
|
|
+ $data[$v]['value'] = $value[$k];
|
|
|
} else {
|
|
|
- $result[$v]['value'] = '';
|
|
|
+ $data[$v]['value'] = '';
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return $result;
|
|
|
+ return $data;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取属性的值,无类别
|
|
|
+ * 获取属性的值,字符类型
|
|
|
*
|
|
|
* @return mixed
|
|
|
*/
|
|
@@ -118,4 +237,24 @@ class Api
|
|
|
|
|
|
return Dever::table($table);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取某个分类下的搜索列表
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function search($ids)
|
|
|
+ {
|
|
|
+ $data = Dever::db('attr/info')->($where);
|
|
|
+
|
|
|
+ $table = array();
|
|
|
+ foreach ($result as $k => $v) {
|
|
|
+ $table[$v['name']] = '';
|
|
|
+ foreach ($v['attr'] as $k1 => $v1) {
|
|
|
+ $table[$v['name']] .= $v1['name'] . " ";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return Dever::table($table);
|
|
|
+ }
|
|
|
}
|