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
e2b4d6c6
Commit
e2b4d6c6
authored
Apr 12, 2019
by
李尚科
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add house tool
parent
bcf7a71c
Pipeline
#5938
passed with stage
in 2 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
349 additions
and
25 deletions
+349
-25
tool.js
app/controller/house/tool.js
+29
-5
house_invest_plan.js
app/model/block/house_invest_plan.js
+32
-15
house_price_increase.js
app/model/block/house_price_increase.js
+93
-0
house_price_trend.js
app/model/block/house_price_trend.js
+93
-0
house_question.js
app/model/block/house_question.js
+93
-0
house.js
app/router/house.js
+2
-1
tool.js
app/service/house/tool.js
+7
-4
No files found.
app/controller/house/tool.js
View file @
e2b4d6c6
'use strict'
;
const
Controller
=
require
(
'egg'
).
Controller
;
const
MAP_POINT_FUNCTION
=
{
used_house
:
'getUsedHouseMapPoint'
,
new_house
:
'getNewHouseMapPoint'
,
}
class
ToolController
extends
Controller
{
...
...
@@ -26,7 +22,7 @@ class ToolController extends Controller {
let
ret
=
[];
if
(
house_style
===
'used_house'
)
{
ret
=
await
ctx
.
service
.
house
.
tool
.
getUsedHouseMapPoint
(
area_code
,
level
);
}
else
if
(
house_style
===
'new_house'
)
{
}
else
if
(
house_style
===
'new_house'
)
{
ret
=
await
ctx
.
service
.
house
.
tool
.
getNewHouseMapPoint
(
area_code
,
level
);
}
...
...
@@ -64,6 +60,34 @@ class ToolController extends Controller {
ctx
.
success
({
results
:
ret
});
}
//type类型;trend:房价指数;increase:房价涨跌 ;question: 购房问题
async
getHousePriceFeature
()
{
const
{
ctx
}
=
this
;
const
input_parmas
=
ctx
.
params
;
const
rule
=
{
type
:
{
type
:
'string'
,
required
:
true
},
area_code
:
{
type
:
'string'
,
required
:
true
},
}
ctx
.
validate
(
rule
,
input_parmas
);
const
type
=
input_parmas
.
type
;
const
area_code
=
input_parmas
.
area_code
;
let
ret
=
[];
if
(
type
===
'trend'
)
{
ret
=
await
ctx
.
blockModel
.
HousePriceTrend
.
one
({
where
:
{
id
:
area_code
}
});
ret
=
ret
.
trend_json
;
}
else
if
(
type
===
'increase'
)
{
ret
=
await
ctx
.
blockModel
.
HousePriceIncrease
.
one
({
where
:
{
id
:
area_code
}
});
ret
=
ret
.
increase_json
;
}
else
if
(
type
===
'question'
)
{
ret
=
await
ctx
.
blockModel
.
HouseQuestion
.
one
({
where
:
{
id
:
area_code
}
});
ret
=
ret
.
question_json
;
}
ctx
.
success
(
ret
);
}
}
module
.
exports
=
ToolController
;
app/model/block/house_invest_plan.js
View file @
e2b4d6c6
'use strict'
;
module
.
exports
=
app
=>
{
const
{
STRING
,
INTEGER
}
=
app
.
Sequelize
;
const
{
STRING
,
INTEGER
,
FLOAT
}
=
app
.
Sequelize
;
const
HouseInvestPlan
=
app
.
blockModel
.
define
(
'house_invest_
map
'
,
{
const
HouseInvestPlan
=
app
.
blockModel
.
define
(
'house_invest_
plan
'
,
{
id
:
{
type
:
INTEGER
,
allowNull
:
false
,
...
...
@@ -10,24 +10,41 @@ module.exports = app => {
autoIncrement
:
true
,
},
alias
:
STRING
,
condition
:
STRING
,
// condition: STRING,
condition_min
:
FLOAT
,
condition_max
:
FLOAT
,
period
:
STRING
,
items
:
STRING
,
items
:
{
type
:
STRING
,
allowNull
:
true
,
field
:
'items'
,
get
()
{
const
items
=
this
.
getDataValue
(
'items'
);
if
(
items
)
{
try
{
return
JSON
.
parse
(
items
);
}
catch
(
error
)
{
return
[];
}
}
return
[];
},
},
status
:
INTEGER
,
remark
:
STRING
,
valid
:
INTEGER
,
},
{
timestamps
:
false
,
tableName
:
'house_invest_map
'
,
freezeTableName
:
true
,
});
timestamps
:
false
,
tableName
:
'house_invest_plan
'
,
freezeTableName
:
true
,
});
HouseInvestPlan
.
one
=
async
(
data
)
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
return
await
HouseInvestPlan
.
findOne
({
attributes
:
attributes
,
where
:
where
,
where
:
where
,
});
}
...
...
@@ -37,7 +54,7 @@ module.exports = app => {
const
where
=
data
.
where
?
data
.
where
:
{};
return
await
HouseInvestPlan
.
findAll
({
attributes
:
attributes
,
where
:
where
,
where
:
where
,
});
}
...
...
@@ -55,7 +72,7 @@ module.exports = app => {
attributes
:
attributes
,
};
const
{
count
,
rows
}
=
await
HouseInvestPlan
.
findAndCountAll
(
condition
);
const
{
count
,
rows
}
=
await
HouseInvestPlan
.
findAndCountAll
(
condition
);
return
{
page
,
count
,
rows
};
}
...
...
@@ -64,11 +81,11 @@ module.exports = app => {
//返回promise对象实力 instance
const
res
=
await
HouseInvestPlan
.
create
(
data
);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return
res
.
id
;
}
catch
(
error
)
{
return
res
.
id
;
}
catch
(
error
)
{
ctx
.
status
=
500
;
throw
(
error
);
}
}
}
HouseInvestPlan
.
edit
=
async
(
data
)
=>
{
...
...
@@ -76,7 +93,7 @@ module.exports = app => {
const
params
=
data
.
params
;
HouseInvestPlan
.
update
(
params
,
{
where
:
where
}).
catch
(
e
=>
res
.
json
({
status
:
500
,
error
:
e
}));
}).
catch
(
e
=>
res
.
json
({
status
:
500
,
error
:
e
}));
}
return
HouseInvestPlan
;
...
...
app/model/block/house_price_increase.js
0 → 100644
View file @
e2b4d6c6
'use strict'
;
module
.
exports
=
app
=>
{
const
{
INTEGER
,
TEXT
}
=
app
.
Sequelize
;
const
HousePriceIncrease
=
app
.
blockModel
.
define
(
'house_price_increase'
,
{
id
:
{
type
:
INTEGER
,
allowNull
:
false
,
primaryKey
:
true
,
autoIncrement
:
true
,
},
increase_json
:
{
type
:
TEXT
,
allowNull
:
true
,
field
:
'increase_json'
,
get
()
{
const
increase_json
=
this
.
getDataValue
(
'increase_json'
);
if
(
increase_json
)
{
try
{
return
JSON
.
parse
(
increase_json
);
}
catch
(
error
)
{
return
[];
}
}
return
[];
},
},
},
{
timestamps
:
false
,
tableName
:
'house_price_increase'
,
freezeTableName
:
true
,
});
HousePriceIncrease
.
one
=
async
(
data
)
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
return
await
HousePriceIncrease
.
findOne
({
attributes
:
attributes
,
where
:
where
,
});
}
HousePriceIncrease
.
all
=
async
(
data
)
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
return
await
HousePriceIncrease
.
findAll
({
attributes
:
attributes
,
where
:
where
,
});
}
HousePriceIncrease
.
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
HousePriceIncrease
.
findAndCountAll
(
condition
);
return
{
page
,
count
,
rows
};
}
HousePriceIncrease
.
add
=
async
(
data
)
=>
{
try
{
//返回promise对象实力 instance
const
res
=
await
HousePriceIncrease
.
create
(
data
);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return
res
.
id
;
}
catch
(
error
)
{
ctx
.
status
=
500
;
throw
(
error
);
}
}
HousePriceIncrease
.
edit
=
async
(
data
)
=>
{
const
where
=
data
.
where
;
const
params
=
data
.
params
;
HousePriceIncrease
.
update
(
params
,
{
where
:
where
}).
catch
(
e
=>
res
.
json
({
status
:
500
,
error
:
e
}));
}
return
HousePriceIncrease
;
};
app/model/block/house_price_trend.js
0 → 100644
View file @
e2b4d6c6
'use strict'
;
module
.
exports
=
app
=>
{
const
{
INTEGER
,
TEXT
}
=
app
.
Sequelize
;
const
HousePriceTrend
=
app
.
blockModel
.
define
(
'house_price_trend'
,
{
id
:
{
type
:
INTEGER
,
allowNull
:
false
,
primaryKey
:
true
,
autoIncrement
:
true
,
},
trend_json
:
{
type
:
TEXT
,
allowNull
:
true
,
field
:
'trend_json'
,
get
()
{
const
trend_json
=
this
.
getDataValue
(
'trend_json'
);
if
(
trend_json
)
{
try
{
return
JSON
.
parse
(
trend_json
);
}
catch
(
error
)
{
return
[];
}
}
return
[];
},
},
},
{
timestamps
:
false
,
tableName
:
'house_price_trend'
,
freezeTableName
:
true
,
});
HousePriceTrend
.
one
=
async
(
data
)
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
return
await
HousePriceTrend
.
findOne
({
attributes
:
attributes
,
where
:
where
,
});
}
HousePriceTrend
.
all
=
async
(
data
)
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
return
await
HousePriceTrend
.
findAll
({
attributes
:
attributes
,
where
:
where
,
});
}
HousePriceTrend
.
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
HousePriceTrend
.
findAndCountAll
(
condition
);
return
{
page
,
count
,
rows
};
}
HousePriceTrend
.
add
=
async
(
data
)
=>
{
try
{
//返回promise对象实力 instance
const
res
=
await
HousePriceTrend
.
create
(
data
);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return
res
.
id
;
}
catch
(
error
)
{
ctx
.
status
=
500
;
throw
(
error
);
}
}
HousePriceTrend
.
edit
=
async
(
data
)
=>
{
const
where
=
data
.
where
;
const
params
=
data
.
params
;
HousePriceTrend
.
update
(
params
,
{
where
:
where
}).
catch
(
e
=>
res
.
json
({
status
:
500
,
error
:
e
}));
}
return
HousePriceTrend
;
};
app/model/block/house_question.js
0 → 100644
View file @
e2b4d6c6
'use strict'
;
module
.
exports
=
app
=>
{
const
{
INTEGER
,
TEXT
}
=
app
.
Sequelize
;
const
HouseQuestion
=
app
.
blockModel
.
define
(
'house_question'
,
{
id
:
{
type
:
INTEGER
,
allowNull
:
false
,
primaryKey
:
true
,
autoIncrement
:
true
,
},
question_json
:
{
type
:
TEXT
,
allowNull
:
true
,
field
:
'question_json'
,
get
()
{
const
question_json
=
this
.
getDataValue
(
'question_json'
);
if
(
question_json
)
{
try
{
return
JSON
.
parse
(
question_json
);
}
catch
(
error
)
{
return
[];
}
}
return
[];
},
},
},
{
timestamps
:
false
,
tableName
:
'house_question'
,
freezeTableName
:
true
,
});
HouseQuestion
.
one
=
async
(
data
)
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
return
await
HouseQuestion
.
findOne
({
attributes
:
attributes
,
where
:
where
,
});
}
HouseQuestion
.
all
=
async
(
data
)
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
return
await
HouseQuestion
.
findAll
({
attributes
:
attributes
,
where
:
where
,
});
}
HouseQuestion
.
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
HouseQuestion
.
findAndCountAll
(
condition
);
return
{
page
,
count
,
rows
};
}
HouseQuestion
.
add
=
async
(
data
)
=>
{
try
{
//返回promise对象实力 instance
const
res
=
await
HouseQuestion
.
create
(
data
);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return
res
.
id
;
}
catch
(
error
)
{
ctx
.
status
=
500
;
throw
(
error
);
}
}
HouseQuestion
.
edit
=
async
(
data
)
=>
{
const
where
=
data
.
where
;
const
params
=
data
.
params
;
HouseQuestion
.
update
(
params
,
{
where
:
where
}).
catch
(
e
=>
res
.
json
({
status
:
500
,
error
:
e
}));
}
return
HouseQuestion
;
};
app/router/house.js
View file @
e2b4d6c6
...
...
@@ -4,8 +4,9 @@ module.exports = app => {
const
router
=
app
.
router
.
namespace
(
app
.
config
.
projectRootPath
+
'/house'
);
const
loginAuth
=
app
.
middleware
.
loginAuth
({
type
:
'new'
});
//登录中间件
router
.
get
(
'/tool/:
city_code
'
,
'house.tool.getMapPoint'
);
//购房计划地图点位
router
.
get
(
'/tool/:
house_style/:area_code/:level
'
,
'house.tool.getMapPoint'
);
//购房计划地图点位
router
.
post
(
'/tool/plan'
,
'house.tool.generateBuyHousePlan'
);
//生成购房计划
router
.
get
(
'/tool/:type/:area_code'
,
'house.tool.getHousePriceFeature'
);
//房价指数 涨跌
//租房
router
.
get
(
'/rental_house/home'
,
'house.rentalHouse.home'
);
//租房首页信息
...
...
app/service/house/tool.js
View file @
e2b4d6c6
...
...
@@ -74,11 +74,11 @@ class ToolService extends Service {
const
balance
=
down_payment
-
invest_payment
;
let
notice
=
''
;
let
status
=
0
;
let
plan
=
[];
let
invest_items
=
[];
if
(
balance
<
0
)
{
status
=
2
;
//完全有能力买到房
notice
=
'您的资金已满足本项目首付条件,还有更多项目在您预算范围内。一键预约,轻松看房!'
;
return
{
status
,
notice
,
plan
};
return
{
status
,
notice
,
invest_items
};
}
const
rate
=
balance
/
invest_payment
;
if
(
rate
>=
0.5
)
{
...
...
@@ -87,10 +87,13 @@ class ToolService extends Service {
}
else
{
status
=
1
;
//j加把劲还是有希望买到房
notice
=
'恭喜您!依据以上计划,您即将完成XXX项目首付款准备。您现阶段首付预算可以购买以下项目房源:'
;
const
invest_plans
=
await
ctx
.
blockModel
.
HouseInvestPlan
({
where
:
{}
});
const
invest_plans
=
await
ctx
.
blockModel
.
HouseInvestPlan
.
one
({
where
:
{
condition_min
:
{
$lt
:
rate
},
condition_max
:
{
$gte
:
rate
},
status
:
'online'
,
valid
:
1
}
});
if
(
Object
.
keys
(
invest_plans
).
length
!==
0
&&
invest_plans
.
items
)
{
invest_items
=
invest_plans
.
items
;
}
}
return
{
status
,
notice
,
plan
};
return
{
status
,
notice
,
invest_items
};
}
}
...
...
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