|
@@ -77,6 +77,25 @@ class Api
|
|
|
{
|
|
|
if ($attr) {
|
|
|
foreach ($attr as $k => $v) {
|
|
|
+ if ($v['type'] == 9) {
|
|
|
+
|
|
|
+ $k = 'attr_' . $v['id'] . '_s';
|
|
|
+ $config['struct'][$k]['name'] = $v['name'];
|
|
|
+ $config['struct'][$k]['default'] = '';
|
|
|
+ $config['struct'][$k]['desc'] = $v['name'];
|
|
|
+ $config['struct'][$k]['update'] = 'hidden';
|
|
|
+ $config['struct'][$k]['type'] = 'varchar-11';
|
|
|
+ $config['struct'][$k]['match'] = 'is_numeric';
|
|
|
+
|
|
|
+ $k = 'attr_' . $v['id'] . '_e';
|
|
|
+ $config['struct'][$k]['name'] = $v['name'];
|
|
|
+ $config['struct'][$k]['default'] = '';
|
|
|
+ $config['struct'][$k]['desc'] = $v['name'];
|
|
|
+ $config['struct'][$k]['update'] = 'hidden';
|
|
|
+ $config['struct'][$k]['type'] = 'varchar-11';
|
|
|
+ $config['struct'][$k]['match'] = 'is_numeric';
|
|
|
+ }
|
|
|
+
|
|
|
$k = 'attr_' . $v['id'];
|
|
|
$config['struct'][$k] = array();
|
|
|
|
|
@@ -154,7 +173,11 @@ class Api
|
|
|
default:
|
|
|
$config['struct'][$k]['update'] = 'text';
|
|
|
$config['struct'][$k]['search'] = 'fulltext';
|
|
|
- if ($v['data_type'] == 1 || $v['type'] == 1) {
|
|
|
+ if ($v['type'] == 9) {
|
|
|
+ $config['struct'][$k]['name'] .= '-这是一个区间数值,后台填写请用半角逗号,隔开';
|
|
|
+ $config['struct'][$k]['type'] = 'varchar-100';
|
|
|
+ $config['struct'][$k]['match'] = 'is_string';
|
|
|
+ } elseif ($v['data_type'] == 1 || $v['type'] == 1) {
|
|
|
$config['struct'][$k]['type'] = 'varchar-11';
|
|
|
$config['struct'][$k]['match'] = 'is_numeric';
|
|
|
} else {
|
|
@@ -195,6 +218,9 @@ class Api
|
|
|
$method = 'getListByIds';
|
|
|
} elseif ($order == 'search') {
|
|
|
$method = 'getSearchByIds';
|
|
|
+ } elseif ($order == 'search_reorder') {
|
|
|
+ $method = 'getSearchByIds';
|
|
|
+ $where['search_reorder'] = 1;
|
|
|
} elseif ($order == 'view') {
|
|
|
$method = 'getViewByIds';
|
|
|
}
|
|
@@ -286,13 +312,15 @@ class Api
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public function getAttrByCate($category, $order = 'list_reorder')
|
|
|
+ public function getAttrByCate($category, $order = 'list_reorder', $total = false)
|
|
|
{
|
|
|
$data = array();
|
|
|
+
|
|
|
if ($category && Dever::project('category')) {
|
|
|
$array = explode(',', $category);
|
|
|
$cate = array();
|
|
|
- $total = count($array)-1;
|
|
|
+ $total = $total ? $total : count($array);
|
|
|
+ $total -= 1;
|
|
|
foreach ($array as $k => $v) {
|
|
|
$cate[$k] = $v;
|
|
|
if ($k < $total) {
|
|
@@ -301,7 +329,7 @@ class Api
|
|
|
$where['category'] = $cate;
|
|
|
$info = Dever::db('category/attr')->one($where);
|
|
|
if ($info) {
|
|
|
- $data += Dever::load('attr/api')->getList($info['attr'], $info['attr_input']);
|
|
|
+ $data += Dever::load('attr/api')->getList($info['attr'], $info['attr_input'], $order);
|
|
|
}
|
|
|
}
|
|
|
$this->attrSort($data, $order);
|
|
@@ -315,20 +343,20 @@ class Api
|
|
|
*
|
|
|
* @return mixed
|
|
|
*/
|
|
|
- public function getSearch($ids, $cate = true, $city = false, $search_value = false)
|
|
|
+ public function getSearch($ids, $cate = true, $city = false, $search_value = false, $total = 3)
|
|
|
{
|
|
|
$value = array();
|
|
|
$search_value = Dever::preInput('attr_', $search_value);
|
|
|
|
|
|
if ($cate && $ids && Dever::project('category')) {
|
|
|
- $data = $this->getAttrByCate($ids, 'search_reorder');
|
|
|
+ $data = $this->getAttrByCate($ids, 'search_reorder', $total);
|
|
|
if (!$data) {
|
|
|
return array('search' => array(), 'value' => $value);
|
|
|
}
|
|
|
} else {
|
|
|
$where['ids'] = $ids;
|
|
|
$where['search_reorder'] = 1;
|
|
|
- $data = Dever::db('attr/info')->getSearch($where);
|
|
|
+ $data = Dever::db('attr/info')->getSearchByIds($where);
|
|
|
}
|
|
|
|
|
|
if ($data) {
|
|
@@ -366,4 +394,67 @@ class Api
|
|
|
|
|
|
return array('search' => $data, 'value' => $value);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ * 获取搜索sql
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function getSql($attr, $where, $sql = array(), $tname = 't_1')
|
|
|
+ {
|
|
|
+ if (!$attr) {
|
|
|
+ return $sql;
|
|
|
+ }
|
|
|
+ foreach ($attr as $k => $v) {
|
|
|
+ $key = 'attr_' . $v['id'];
|
|
|
+ if (isset($where[$key]) && $where[$key]) {
|
|
|
+
|
|
|
+ if ($v['type'] == 7) {
|
|
|
+
|
|
|
+ $county = Dever::db('area/county')->one($where[$key]);
|
|
|
+ if ($county) {
|
|
|
+ $city = Dever::db('area/city')->one($county['city_id']);
|
|
|
+ if ($city) {
|
|
|
+ $province = Dever::db('area/province')->one($city['province_id']);
|
|
|
+ if ($province) {
|
|
|
+ $value = $province['id'] . ',' . $city['id'] . ',' . $county['id'];
|
|
|
+
|
|
|
+ $sql[] = ' '.$tname.'.'.$key.' = "'.$value.'"';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } elseif ($v['type'] == 1 && $v['type_option']) {
|
|
|
+ $temp = explode("\n", $v['type_option']);
|
|
|
+ if (isset($temp[$where[$key]-1])) {
|
|
|
+ $temp = explode(',', $temp[$where[$key]-1]);
|
|
|
+ $match = $temp[1];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $match = str_replace('{v}', $tname . '.' . $key, $match);
|
|
|
+ $sql[] = $match;
|
|
|
+ }
|
|
|
+ } elseif ($v['type'] == 9 && $v['type_option']) {
|
|
|
+ $temp = explode("\n", $v['type_option']);
|
|
|
+ if (isset($temp[$where[$key]-1])) {
|
|
|
+ $temp = explode(',', $temp[$where[$key]-1]);
|
|
|
+ $match = $temp[1];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $match = str_replace('{s}', $tname . '.' . $key . '_s', $match);
|
|
|
+ $match = str_replace('{e}', $tname . '.' . $key . '_e', $match);
|
|
|
+ $match = str_replace('{v}', $tname . '.' . $key . '_e', $match);
|
|
|
+ $sql[] = $match;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $sql[] = ' '.$tname.'.'.$key.' = "'.$where[$key].'"';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $sql;
|
|
|
+ }
|
|
|
}
|