-
Notifications
You must be signed in to change notification settings - Fork 93
/
items.php
52 lines (51 loc) · 1.47 KB
/
items.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
// 获取分类列表
function getCategory() {
$db = DbFactory::getInstance()->getLifeDB();
$cats_main = $db->getData("select * from category");
$cats_test = array();
//一级分类
foreach ($cats_main as $val_main) {
if ($val_main['parent_id'] == 0) {
$sub_arr = array();
$cats_test[$val_main['id']]['sub'] = $sub_arr;
$cats_test[$val_main['id']]['name'] = $val_main['name'];
}
}
//二级分类
foreach($cats_main as $val_sub) {
if ($val_sub['parent_id'] != 0) {
$sub_arr_cate = array();
$cats_test[$val_sub['parent_id']]['sub'][$val_sub['id']] = " ".$val_sub['name'];
}
}
$cate_result = array();
foreach ($cats_test as $key_cate => $val_cate) {
$cate_result[$key_cate] = $cats_test[$key_cate]['name'];
if (!empty($cats_test[$key_cate]['sub'])) {
foreach ($cats_test[$key_cate]['sub'] as $key_sub => $val_sub) {
$cate_result[$key_sub] = $val_sub;
}
}
}
$return = array();
$return['code'] = 1;
if (false != $cate_result) {
$return['code'] = 0;
$return['cate_list'] = $cate_result;
}
return $return;
}
// 获取地区列表
function getAreaList() {
$db = DbFactory::getInstance()->getLifeDB();
$return = array();
$return['code'] = 1;
$sql = 'select id, name from area';
$ret = $db->getData($sql);
if (false != $ret) {
$return['code'] = 0;
$return['result'] = $ret;
}
return $return;
}