Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
5
51business
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
方斌
51business
Commits
d6fdb750
Commit
d6fdb750
authored
Apr 09, 2019
by
方斌
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://t-git.51gjj.com/fangbin/51business
parents
40899e05
89786eda
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
203 additions
and
12 deletions
+203
-12
house_bizcircle.js
app/model/block/house_bizcircle.js
+80
-0
house_district.js
app/model/block/house_district.js
+80
-0
house.js
app/router/house.js
+2
-2
option.js
app/service/house/option.js
+41
-10
No files found.
app/model/block/house_bizcircle.js
0 → 100644
View file @
d6fdb750
'use strict'
;
module
.
exports
=
app
=>
{
const
{
STRING
,
INTEGER
}
=
app
.
Sequelize
;
const
HouseBizcircle
=
app
.
blockModel
.
define
(
'house_bizcircle'
,
{
id
:
{
type
:
INTEGER
,
allowNull
:
false
,
primaryKey
:
true
,
autoIncrement
:
true
,
},
name
:
STRING
,
spell
:
STRING
,
district_id
:
INTEGER
,
},
{
timestamps
:
false
,
tableName
:
'house_bizcircle'
,
freezeTableName
:
true
,
});
HouseBizcircle
.
one
=
async
(
data
)
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
return
await
HouseBizcircle
.
findOne
({
attributes
:
attributes
,
where
:
where
,
});
}
HouseBizcircle
.
all
=
async
(
data
)
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
return
await
HouseBizcircle
.
findAll
({
attributes
:
attributes
,
where
:
where
,
});
}
HouseBizcircle
.
list
=
async
(
data
=
{})
=>
{
const
limit
=
data
.
limit
?
data
.
limit
:
10
;
const
page
=
data
.
page
?
data
.
page
:
1
;
const
order
=
data
.
order
?
data
.
order
:
[];
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
const
condition
=
{
offset
:
(
page
-
1
)
*
limit
,
limit
,
where
:
where
,
order
:
order
,
attributes
:
attributes
,
};
const
{
count
,
rows
}
=
await
HouseBizcircle
.
findAndCountAll
(
condition
);
return
{
page
,
count
,
rows
};
}
HouseBizcircle
.
add
=
async
(
data
)
=>
{
try
{
//返回promise对象实力 instance
const
res
=
await
HouseBizcircle
.
create
(
data
);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return
res
.
id
;
}
catch
(
error
)
{
ctx
.
status
=
500
;
throw
(
error
);
}
}
HouseBizcircle
.
edit
=
async
(
data
)
=>
{
const
where
=
data
.
where
;
const
params
=
data
.
params
;
HouseBizcircle
.
update
(
params
,
{
where
:
where
}).
catch
(
e
=>
res
.
json
({
status
:
500
,
error
:
e
}));
}
return
HouseBizcircle
;
};
app/model/block/house_district.js
0 → 100644
View file @
d6fdb750
'use strict'
;
module
.
exports
=
app
=>
{
const
{
STRING
,
INTEGER
}
=
app
.
Sequelize
;
const
HouseDistrict
=
app
.
blockModel
.
define
(
'house_district'
,
{
id
:
{
type
:
INTEGER
,
allowNull
:
false
,
primaryKey
:
true
,
autoIncrement
:
true
,
},
name
:
STRING
,
spell
:
STRING
,
city_id
:
INTEGER
,
},
{
timestamps
:
false
,
tableName
:
'house_district'
,
freezeTableName
:
true
,
});
HouseDistrict
.
one
=
async
(
data
)
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
return
await
HouseDistrict
.
findOne
({
attributes
:
attributes
,
where
:
where
,
});
}
HouseDistrict
.
all
=
async
(
data
)
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
return
await
HouseDistrict
.
findAll
({
attributes
:
attributes
,
where
:
where
,
});
}
HouseDistrict
.
list
=
async
(
data
=
{})
=>
{
const
limit
=
data
.
limit
?
data
.
limit
:
10
;
const
page
=
data
.
page
?
data
.
page
:
1
;
const
order
=
data
.
order
?
data
.
order
:
[];
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
const
condition
=
{
offset
:
(
page
-
1
)
*
limit
,
limit
,
where
:
where
,
order
:
order
,
attributes
:
attributes
,
};
const
{
count
,
rows
}
=
await
HouseDistrict
.
findAndCountAll
(
condition
);
return
{
page
,
count
,
rows
};
}
HouseDistrict
.
add
=
async
(
data
)
=>
{
try
{
//返回promise对象实力 instance
const
res
=
await
HouseDistrict
.
create
(
data
);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return
res
.
id
;
}
catch
(
error
)
{
ctx
.
status
=
500
;
throw
(
error
);
}
}
HouseDistrict
.
edit
=
async
(
data
)
=>
{
const
where
=
data
.
where
;
const
params
=
data
.
params
;
HouseDistrict
.
update
(
params
,
{
where
:
where
}).
catch
(
e
=>
res
.
json
({
status
:
500
,
error
:
e
}));
}
return
HouseDistrict
;
};
app/router/house.js
View file @
d6fdb750
...
...
@@ -4,7 +4,7 @@ module.exports = app => {
const
router
=
app
.
router
.
namespace
(
app
.
config
.
projectRootPath
+
'/house'
);
// const loginAuth = app.middleware.loginAuth({type: 'new'});//登录中间件
router
.
get
(
'/options
'
,
'house.options.getOptions'
);
//首页
信息
router
.
get
(
'/rental_house'
,
'house.rentalHouse.getRentHouses'
);
//
首页信息
router
.
get
(
'/options
/:city_code'
,
'house.options.getOptions'
);
//筛选项
信息
router
.
get
(
'/rental_house'
,
'house.rentalHouse.getRentHouses'
);
//
租房列表
};
app/service/house/option.js
View file @
d6fdb750
...
...
@@ -29,15 +29,6 @@ class OptionService extends Service {
async
getOptions
(
city_code
)
{
const
{
ctx
}
=
this
;
const
city
=
ctx
.
blockModel
.
City
.
one
({
where
:
{
code
:
city_code
}
});
if
(
!
city
||
!
city
.
name
)
{
ctx
.
failed
(
'city code error'
);
}
const
district
=
ctx
.
blockModel
.
District
.
all
({
where
:
{
city_id
:
city
.
code
}
});
if
(
!
district
||
district
){
ctx
.
failed
(
'district error'
);
}
const
bizcircle
=
ctx
.
blockModel
.
Bizcircle
.
all
({
where
:
{}});
const
developers_results
=
await
ctx
.
service
.
houseCommon
.
developer
.
all
({});
const
developers
=
developers_results
.
results
;
const
brands
=
[];
...
...
@@ -51,8 +42,48 @@ class OptionService extends Service {
}
const
house_types
=
HOUSE_TYPE
;
const
prices
=
PRICE_RANGE
;
const
areas
=
await
this
.
getAreaOptions
(
city_code
);
return
{
brands
,
prices
,
house_types
,
areas
};
}
async
getAreaOptions
(
city_code
)
{
const
{
ctx
}
=
this
;
const
city
=
await
ctx
.
blockModel
.
City
.
one
({
where
:
{
code
:
city_code
}
});
if
(
!
city
||
!
city
.
name
)
{
ctx
.
failed
(
'city code error'
);
}
const
districts
=
await
ctx
.
blockModel
.
HouseDistrict
.
all
({
where
:
{
city_id
:
city
.
code
}
});
if
(
!
districts
||
districts
.
length
===
0
)
{
ctx
.
failed
(
'district error'
);
}
const
ret
=
[]
for
(
let
j
in
districts
)
{
const
district
=
districts
[
j
];
const
_children
=
[];
const
bizcircles
=
await
ctx
.
blockModel
.
HouseBizcircle
.
all
({
where
:
{
district_id
:
district
.
id
}
});
if
(
!
bizcircles
||
bizcircles
.
length
===
0
)
{
continue
;
}
for
(
let
i
in
bizcircles
)
{
const
bizcircle
=
bizcircles
[
i
];
_children
.
push
({
id
:
bizcircle
.
id
,
name
:
bizcircle
.
name
,
district_id
:
bizcircle
.
district_id
,
});
}
ret
.
push
({
id
:
district
.
id
,
name
:
district
.
name
,
city_id
:
district
.
city_id
,
_children
:
_children
,
})
}
return
{
brands
,
prices
,
house_types
}
;
return
ret
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment