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
ff5bccaa
Commit
ff5bccaa
authored
Jun 05, 2019
by
李尚科
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add controller v2
parent
4bd643a3
Pipeline
#8591
passed with stage
in 3 seconds
Changes
4
Pipelines
1
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
209 additions
and
0 deletions
+209
-0
rental_house.js
app/controller/house/v2/rental_house.js
+63
-0
house.js
app/router/house.js
+8
-0
foot_print.js
app/service/house/v2/foot_print.js
+138
-0
rental_house.js
app/service/house/v2/rental_house.js
+0
-0
No files found.
app/controller/house/v2/rental_house.js
0 → 100644
View file @
ff5bccaa
'use strict'
;
const
Controller
=
require
(
'egg'
).
Controller
;
class
RentalHouseController
extends
Controller
{
//租房首页信息
async
home
()
{
const
{
ctx
}
=
this
;
const
input_params
=
ctx
.
query
;
const
city_code
=
input_params
.
city_code
?
input_params
.
city_code
:
330100
;
//banners
const
headers
=
{
cookie
:
ctx
.
request
.
headers
.
cookie
}
const
banners_result
=
await
ctx
.
helper
.
send_request
(
this
.
config
.
NODE_BASE_URL
+
'/51app/api/block/all'
,
{
alias
:
'51fangc_rental_home_banners'
},
{
method
:
'GET'
,
dataType
:
'json'
,
headers
:
headers
});
let
banners
=
[];
if
(
banners_result
.
status
===
200
)
{
banners
=
banners_result
.
data
.
results
;
}
const
developers
=
await
ctx
.
service
.
house
.
option
.
getDevelopers
(
city_code
);
//品牌信息
ctx
.
success
({
banners
,
developers
});
}
//租房列表
async
getRentalHouses
()
{
const
{
ctx
}
=
this
;
const
input_params
=
ctx
.
request
.
body
;
const
rule
=
{
brand
:
{
type
:
'string'
,
required
:
false
},
//品牌
area_code
:
{
type
:
'object'
,
required
:
false
},
//区域
price
:
{
type
:
'object'
,
required
:
false
},
//价格
house_type
:
{
type
:
'string'
,
required
:
false
},
//房型
name
:
{
type
:
'string'
,
required
:
false
},
//楼盘名称
page
:
{
type
:
'string'
,
required
:
false
},
page_size
:
{
type
:
'string'
,
required
:
false
},
};
ctx
.
validate
(
rule
,
input_params
);
const
ret
=
await
ctx
.
service
.
house
.
v2
.
rentalHouse
.
getRentalHousesByFilter
(
input_params
);
ctx
.
success
({
input_params
,
results
:
ret
.
results
,
count
:
ret
.
count
});
}
//租房详情
async
getRentalHouse
()
{
const
{
ctx
}
=
this
;
const
input_params
=
ctx
.
params
;
if
(
!
input_params
.
rental_house_id
)
{
ctx
.
failed
(
'rental_house_id error'
);
}
const
rental_house_id
=
input_params
.
rental_house_id
;
const
ret
=
await
ctx
.
service
.
house
.
v2
.
rentalHouse
.
getRentalHouse
(
rental_house_id
);
ctx
.
success
(
ret
);
}
}
module
.
exports
=
RentalHouseController
;
app/router/house.js
View file @
ff5bccaa
...
...
@@ -46,4 +46,12 @@ module.exports = app => {
//房产v2
//租房列表
router
.
get
(
'/v2/rental_house/list'
,
'house.v2.rentalHouse.getRentalHouses'
);
//租房列表
router
.
post
(
'/v2/rental_house/list'
,
'house.v2.rentalHouse.getRentalHouses'
);
//租房列表
router
.
get
(
'/v2/rental_house/info/:rental_house_id'
,
'house.v2.rentalHouse.getRentalHouse'
);
//住房详情
};
app/service/house/v2/foot_print.js
0 → 100644
View file @
ff5bccaa
'use strict'
;
const
Service
=
require
(
'egg'
).
Service
;
const
moment
=
require
(
'moment'
);
class
FootPrintService
extends
Service
{
/**
* 添加足迹
* @param {object} inputParams {id: XX, type: XX, remark: XX}
*/
async
addFootPrint
(
inputParams
)
{
const
{
ctx
}
=
this
;
const
user_id
=
ctx
.
userId
;
const
app_user_id
=
ctx
.
appUserId
;
const
app_type_id
=
ctx
.
appTypeId
;
const
app_id
=
ctx
.
app_id
;
if
(
!
user_id
||
!
app_user_id
)
{
return
false
;
}
const
data
=
{
user_id
:
user_id
,
app_type_id
:
app_type_id
,
app_id
:
app_id
,
house_style
:
inputParams
.
type
,
connectId
:
inputParams
.
id
,
state
:
1
,
remark
:
inputParams
.
remark
||
''
,
}
let
ret
=
await
ctx
.
realestateModel
.
footPrint
.
add
(
data
);
return
{
id
:
ret
.
id
};
}
/**
* 获取用户足迹列表 保留最近6个月的记录,条数不超过50条
* @param {object} condition
*/
async
getFootPrintList
()
{
const
{
ctx
}
=
this
;
const
user_id
=
ctx
.
userId
;
const
app_type_id
=
ctx
.
appTypeId
;
if
(
!
user_id
||
!
app_type_id
)
{
return
{
results
:
[],
count
:
0
};
}
const
foot_prints_rows
=
await
ctx
.
realestateModel
.
FootPrint
.
list
({
page
:
1
,
limit
:
50
,
where
:
{
user_id
:
user_id
,
app_type_id
:
app_type_id
,
state
:
1
,
order
:
[[
'id'
,
'desc'
]]
}
});
const
foot_prints
=
foot_prints_rows
.
rows
;
const
p_houses
=
[];
for
(
let
i
in
foot_prints
)
{
let
foot_print
=
foot_prints
[
i
];
if
(
foot_print
.
house_style
===
1
)
{
//获取房源信息
p_houses
[
i
]
=
ctx
.
realestateModel
.
NewHouse
.
one
(
foot_print
.
connect_id
);
}
else
{
p_houses
[
i
]
=
ctx
.
realestateModel
.
RentalHouse
.
one
(
foot_print
.
connect_id
);
}
}
const
houses
=
await
Promise
.
all
(
p_houses
).
then
(
result
=>
{
//等待所有异步内容获取完成
return
result
;
}).
catch
(
error
=>
{
ctx
.
failed
(
error
);
});
const
now_time
=
moment
(
new
Date
()).
format
(
'X'
);
//处理足迹数据
const
foot_print_records
=
[];
for
(
let
j
in
houses
)
{
const
house
=
houses
[
j
];
const
foot_print
=
foot_prints
[
j
];
const
type
=
foot_print
.
house_style
===
1
?
'new_house'
:
'rental_house'
;
const
create_time
=
moment
(
foot_print
.
created_at
).
format
(
'X'
);
let
time
=
moment
(
foot_print
.
created_at
).
format
(
'YYYY-MM-DD'
);
const
du_time
=
now_time
-
create_time
;
if
(
du_time
<
86400
)
{
const
hours
=
parseInt
(
du_time
/
3600
);
const
mins
=
parseInt
(
du_time
/
60
);
time
=
hours
?
`
${
hours
}
小时前`
:
(
mins
>
5
?
`
${
mins
}
分钟前`
:
'刚刚'
);
}
foot_print_records
.
push
({
id
:
foot_print
.
id
,
house_id
:
house
.
id
,
name
:
house
.
name
,
time
:
time
,
type
:
type
,
});
}
return
{
results
:
foot_print_records
,
count
:
foot_prints_results
.
rowCount
};
}
/**
* 我的-获取用户足迹个数
*/
async
getFootPrintCount
()
{
const
{
ctx
,
service
}
=
this
;
if
(
!
ctx
.
userId
)
{
return
{
count
:
0
};
}
const
filter
=
{
pageIndex
:
1
,
pageSize
:
50
,
queryConditions
:
[{
key
:
"state"
,
value
:
1
,
operator
:
"equal"
},
{
key
:
"userId"
,
value
:
ctx
.
userId
,
operator
:
"equal"
},
],
orderConditions
:
[{
key
:
'createdAt'
,
orderSequence
:
'desc'
,
},],
}
const
foot_prints_results
=
await
service
.
houseCommon
.
footPrint
.
all
(
filter
);
let
ret
=
{
count
:
foot_prints_results
.
rowCount
};
return
ret
;
}
}
module
.
exports
=
FootPrintService
;
app/service/house/v2/rental_house.js
View file @
ff5bccaa
This diff is collapsed.
Click to expand it.
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