Commit 3299ad37 authored by Hsinli's avatar Hsinli

addd

parent 5d600b90
Pipeline #8689 passed with stage
in 12 seconds
'use strict';
const Controller = require('egg').Controller;
class CollectionController extends Controller {
/**
* 关注
*/
async addCollection() {
const { ctx } = this;
let inputParams = ctx.request.body;
const rule = {
id: {
type: 'integer',
required: true,
},
type: {
type: 'integer',
required: true,
}
};
ctx.validate(rule, inputParams);
let ret = await ctx.service.house.v2.collection.addCollection(inputParams);
ctx.success(ret);
}
/**
* 获取关注列表
*/
async getCollectionList() {
const { ctx } = this;
let ret = await ctx.service.house.v2.collection.getCollectionList();
ctx.success(ret);
}
async unCollection() {
const { ctx } = this;
let inputParams = ctx.request.body;
const rule = {
id: {
type: 'integer',
required: true,
},
type: {
type: 'integer',
required: true,
}
};
ctx.validate(rule, inputParams);
let ret = await ctx.service.house.v2.collection.unCollection(inputParams);
ctx.success(ret);
}
}
module.exports = CollectionController;
'use strict';
const Controller = require('egg').Controller;
class MineController extends Controller {
/**
* 获取我的信息
*/
async getMineInfo() {
const { ctx } = this;
let ret = await ctx.service.house.v2.mine.getMineInfo();
ctx.success(ret);
}
}
module.exports = MineController;
'use strict';
const Controller = require('egg').Controller;
class NewHouseController extends Controller {
/**
* 根据筛选条件获得新房列表
*/
async getNewHouseList() {
const { ctx } = this;
let inputParams = ctx.request.body;
const rule = {
page: { type: 'string', required: false },//页面
page_size: { type: 'string', required: false },//条数
area_code: { type: 'object', required: false },//区域
unit_price: { type: 'object', required: false },//价格
total_price: { type: 'object', required: false },//总价
area: { type: 'object', required: false },//面积
house_type: { type: 'string', required: false },//房型
//通过type选择指定内容 全部all 在售sale 最近开盘open 优惠favourtable 首页home,和上面的筛选项互斥
type: { type: 'string', required: false },//
};
ctx.validate(rule, inputParams);
let ret = {};
ret = await ctx.service.house.v2.newHouse.getNewHouseList(inputParams);
ctx.success(ret);
}
/**
* 新房具体信息
*/
async getNewHouse() {
const { ctx } = this;
let inputParams = ctx.params;
const ret = await ctx.service.house.v2.newHouse.getNewHouse(inputParams.id);
ctx.success(ret);
}
/**
* 新房户型信息
*/
async getNewHouseType() {
const { ctx } = this;
let inputParams = ctx.params;
const ret = await ctx.service.house.newHouse.getNewHouseType(inputParams.id);
ctx.success(ret);
}
}
module.exports = NewHouseController;
'use strict';
const Controller = require('egg').Controller;
class OrderController extends Controller {
/**
* 预约
*/
async addOrder() {
const { ctx } = this;
let inputParams = ctx.request.body;
const rule = {
id: {
type: 'integer',
required: true,
},
type: {
type: 'integer',
required: true,
},
name: {
type: 'string',
required: true,
},
phone: {
type: 'string',
required: true,
},
time: {
type: 'string',
required: true,
},
};
ctx.validate(rule, inputParams);
let ret = await ctx.service.house.v2.order.addOrder(inputParams);
ctx.success(ret);
}
/**
* 获取预约列表
*/
async getOrderList() {
const { ctx } = this;
let ret = await ctx.service.house.v2.order.getOrderList();
ctx.success(ret);
}
}
module.exports = OrderController;
'use strict';
const Controller = require('egg').Controller;
class searchHistoryController extends Controller {
/**
* 获取预约列表
*/
async getSearchHistory() {
const { ctx } = this;
//获取租房2和新房1的搜索记录
let ret = {};
let type = [1, 2];
for (let i in type) {
let tag = type[i] === 1 ? 'new_house' : 'rental_house';
ret[tag] = await ctx.service.house.v2.searchHistory.getSearchHistoryList(type[i]);
}
ctx.success(ret);
}
/**
* 清除搜索记录
*/
async cleanSearchHistory() {
const { ctx } = this;
let inputParams = ctx.params;
const rule = {
type: {
type: 'string',
required: true,
}
};
ctx.validate(rule, inputParams);
if (!['new_house', 'rental_house'].includes(inputParams.type)) {
ctx.failed('error type');
}
let type = inputParams.type === 'new_house' ? 1 : 2;
let ret = await ctx.service.house.v2.searchHistory.cleanSearchHistory(type);
ctx.success(ret);
}
}
module.exports = searchHistoryController;
......@@ -35,10 +35,6 @@ module.exports = app => {
type: INTEGER,
allowNull: true
},
valid: {
type: INTEGER,
allowNull: true
},
created_at: {
type: DATE,
get() {
......
......@@ -4,7 +4,7 @@
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT } = app.Sequelize;
const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize;
const NewHouse = app.realestateModel.define('new_house', {
id: {
......@@ -20,6 +20,10 @@ module.exports = app => {
type: INTEGER,
allowNull: true
},
developer_id: {
type: INTEGER,
allowNull: true
},
address: {
type: STRING,
allowNull: true
......@@ -41,11 +45,11 @@ module.exports = app => {
allowNull: true
},
reference_avg_price: {
type: STRING,
type: DECIMAL,
allowNull: true
},
reference_total_price: {
type: STRING,
type: DECIMAL,
allowNull: true
},
image: {
......@@ -128,15 +132,107 @@ module.exports = app => {
type: STRING,
allowNull: true
},
order_num: {
order_id: {
type: INTEGER,
allowNull: true
},
is_reality: {
type: INTEGER,
allowNull: true
},
state: {
status: {
type: ENUM('offline', 'online'),
allowNull: true
},
valid: {
type: INTEGER,
allowNull: true
},
remark: {
type: STRING,
allowNull: true
},
option_city_code: {
type: INTEGER,
allowNull: true
},
option_district_code: {
type: INTEGER,
allowNull: true
},
option_bizicircle_code: {
type: INTEGER,
allowNull: true
},
province: {
type: INTEGER,
allowNull: true
},
city: {
type: INTEGER,
allowNull: true
},
area: {
type: INTEGER,
allowNull: true
},
residential_property_right_years: {
type: INTEGER,
allowNull: true
},
residential_property_fee: {
type: STRING,
allowNull: true
},
residential_property_company: {
type: STRING,
allowNull: true
},
residential_heat_supply_type: {
type: STRING,
allowNull: true
},
residential_water_suppler_type: {
type: STRING,
allowNull: true
},
residential_power_suppler_type: {
type: STRING,
allowNull: true
},
residential_land_area: {
type: DECIMAL,
allowNull: true
},
residential_house_area: {
type: DECIMAL,
allowNull: true
},
residential_area_ratio: {
type: DECIMAL,
allowNull: true
},
residential_green_ratio: {
type: DECIMAL,
allowNull: true
},
residential_arch_type: {
type: INTEGER,
allowNull: true
},
residential_nearby: {
type: TEXT,
allowNull: true
},
sale_province: {
type: INTEGER,
allowNull: true
},
sale_city: {
type: INTEGER,
allowNull: true
},
sale_area: {
type: INTEGER,
allowNull: true
},
......@@ -163,7 +259,7 @@ module.exports = app => {
const date = this.getDataValue('created_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
}
},
}, {
timestamps: false,
tableName: 'new_house',
......
......@@ -4,7 +4,7 @@
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT } = app.Sequelize;
const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize;
const NewHouseType = app.realestateModel.define('new_house_type', {
id: {
......@@ -56,7 +56,11 @@ module.exports = app => {
type: DECIMAL,
allowNull: true
},
state: {
status: {
type: ENUM('offline', 'online'),
allowNull: true
},
valid: {
type: INTEGER,
allowNull: true
},
......
......@@ -50,10 +50,6 @@ module.exports = app => {
type: INTEGER,
allowNull: true
},
valid: {
type: INTEGER,
allowNull: true
},
created_at: {
type: DATE,
get() {
......
......@@ -31,10 +31,6 @@ module.exports = app => {
type: INTEGER,
allowNull: true
},
valid: {
type: INTEGER,
allowNull: true
},
created_at: {
type: DATE,
get() {
......
......@@ -57,4 +57,27 @@ module.exports = app => {
//足迹
router.get('/v2/foot_print/list', 'house.v2.footPrint.getFootPrintList');//用户浏览记录列表
//新房
router.post('/v2/new_house/list', 'house.v2.newHouse.getNewHouseList');//根据条件筛选列表
router.get('/v2/new_house/:id', 'house.v2.newHouse.getNewHouse');//新房具体信息
router.get('/v2/new_house/options/:city_code', 'house.v2.options.getNewHouseOptions');//筛选项信息
//关注
router.post('/v2/collection', loginAuth, 'house.v2.collection.addCollection');//关注
router.get('/v2/collection/list', loginAuth, 'house.v2.collection.getCollectionList');//关注列表
router.put('/v2/collection', loginAuth, 'house.v2.collection.unCollection');//取消关注
//预约
router.post('/v2/order', loginAuth, 'house.v2.order.addOrder');//预约
router.get('/v2/order/list', loginAuth, 'house.v2.order.getOrderList');//预约列表
//搜索历史
router.get('/v2/search_history', 'house.v2.searchHistory.getSearchHistory');//搜索历史
router.put('/v2/search_history/:type', 'house.v2.searchHistory.cleanSearchHistory');//用户点击清除搜索记录
//我的
router.get('/v2/mine', 'house.v2.mine.getMineInfo');//获取用户的头像昵称和关注等信息
};
\ No newline at end of file
'use strict';
const Service = require('egg').Service;
const moment = require('moment');
class CollectionService extends Service {
/**
* 添加关注
* @param {object} inputParams
*/
async addCollection(inputParams) {
const { ctx } = this;
let filter = {
where: {
state: 1,
house_style: inputParams.type,
connect_id: inputParams.id,
user_id: ctx.userId,
}
}
let collectionHistory = await ctx.realestateModel.Collection.one(filter);
if (collectionHistory.length > 0) {
ctx.failed('已经关注过啦');
}
let data = {
user_id: ctx.userId,
app_user_id: ctx.appUserId,
house_style: inputParams.type,
connect_id: inputParams.id,
state: 1,
}
let ret = await ctx.realestateModel.Collection.add(data);
return { id: ret.id };
}
/**
* 取消关注
* @param {object} inputParams
*/
async unCollection(inputParams) {
const { ctx } = this;
let ret = { status: true };
if (!ctx.appUserId || !ctx.deviceId || !ctx.deviceLoginId || !ctx.userId) {
//如果没有登录就不做处理
return ret;
}
let filter = {
where: {
state: 1,
house_style: inputParams.type,
connect_id: inputParams.id,
user_id: ctx.userId,
}
}
let collectionHistory = await ctx.realestateModel.Collection.one(filter);
if (collectionHistory.length > 0) {
let filter = {
params: { state: 0 },
where: { connect_id: inputParams.id }
}
await ctx.realestateModel.Collection.edit(filter);
}
return ret;
}
/**
* 获取用户关注信息
* @param {object} inputParams
*/
async getCollection(inputParams) {
const { ctx } = this;
if (!inputParams.hasOwnProperty('type')) {
ctx.failed("empty house type");
}
if (!inputParams.hasOwnProperty('id')) {
ctx.failed("empty house id");
}
if (!ctx.userId) {
return [];
}
let filter = {
where: {
state: 1,
house_style: inputParams.type,
connect_id: inputParams.id,
user_id: ctx.userId,
}
}
let ret = await ctx.realestateModel.Collection.all(filter);
return ret;
}
/**
* 获取关注列表 保留最近6个月的记录,条数不超过50条
* @param {object} condition
*/
async getCollectionList() {
const { ctx } = this;
let endDate = moment().subtract(6, 'months').format('YYYY-MM-DD HH:mm:ss');
let filter = {
page: 1,
limit: 50,
where: {
state: 1,
user_id: 1,
created_at: { $gt: endDate },
},
order: [['created_at', 'desc']]
}
let list = [];
let collectionList = await ctx.realestateModel.Collection.all(filter);
if (collectionList.length > 0) {
//整理所有收藏
let taskList = [];
for (let i in collectionList) {
if (collectionList[i].house_style === 1) {//1新房2租房 后续根据情况添加
taskList[i] = ctx.realestateModel.NewHouse.one(collectionList[i].connect_id);
} else {
taskList[i] = ctx.realestateModel.RentalHouse.one(collectionList[i].connect_id);
}
}
let retList = await Promise.all(taskList).then(result => {
return result;
}).catch(error => {
ctx.failed(error);
});
//数据整理
for (let j in retList) {
let type = collectionList.results[j].house_style;
let tmp = {
id: retList[j].id,
name: retList[j].name,
address: retList[j].address,
tags: retList[j].tags ? eval(retList[j].tags) : [],
image: retList[j].image,
area: type === 1 ? retList[j].house_area : '',
price: type === 1 ? (['', 0].includes(Number(retList[j].reference_avg_price)) ? '--' : Number(retList[j].reference_avg_price)) : Number(retList[j].price),
type: type === 1 ? 'new_house' : 'rental_house',
corner: type === 1 ? retList[j].corner : '',
};
list.push(tmp);
}
}
let ret = {
results: list,
count: list.length
};
return ret;
}
/**
* 给我的页面使用 只需要count
*/
async getCollectionCount() {
const { ctx } = this;
if (!ctx.userId) {
return { count: 0 };
}
let endDate = moment().subtract(6, 'months').format('YYYY-MM-DD HH:mm:ss');
let filter = {
page: 1,
limit: 50,
where: {
state: 1,
user_id: ctx.userId,
created_at: { $gt: endDate },
},
order: [['created_at', 'desc']]
}
let collectionList = await ctx.realestateModel.Collection.all(filter);
let ret = {
count: collectionList.length
};
return ret;
}
}
module.exports = CollectionService;
......@@ -102,32 +102,23 @@ class FootPrintService extends Service {
* 我的-获取用户足迹个数
*/
async getFootPrintCount() {
const { ctx, service } = this;
const { ctx } = 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"
page: 1,
limit: 50,
where: {
state: 1,
user_id: ctx.userId,
},
],
orderConditions: [{
key: 'createdAt',
orderSequence: 'desc',
},],
order: [['created_at', 'desc']]
}
const foot_prints_results = await service.houseCommon.footPrint.all(filter);
const footPrintsResults = await realestateModel.footPrint.all(filter);
let ret = {
count: foot_prints_results.rowCount
count: footPrintsResults.length
};
return ret;
}
......
'use strict';
const Service = require('egg').Service;
class MineService extends Service {
/**
* 获取我的信息
*/
async getMineInfo() {
const { ctx, service } = this;
let ret = {
login: false,
user: {
nickname: '',
avatar: '',
phone: ''
},
classification: {
foot_print: {
count: 0,
name: '浏览足迹'
},
collection: {
count: 0,
name: '关注的房产'
},
order: {
count: 0,
name: '预约记录'
},
}
}
if (!ctx.userId) {
return ret;
}
let appUserInfo = await this.getAppUserInfo();
ctx.logger.info('appUserInfo:' + JSON.stringify(appUserInfo));
let footPrintList = await service.house.v2.footPrint.getFootPrintCount();
let collectionList = await service.house.v2.collection.getCollectionCount();
let orderList = await service.house.v2.order.getOrderCount();
let phone = appUserInfo.user.phone || '';
if (phone.length > 0) {
phone = phone.substring(0, 3) + '****' + phone.substring(7, 11);
}
ret.login = true;
ret.user.nickname = appUserInfo.nickname || '';
ret.user.avatar = appUserInfo.avatar || '';
ret.user.phone = phone;
ret.classification.foot_print.count = footPrintList.count;
ret.classification.collection.count = collectionList.count;
ret.classification.order.count = orderList.count;
return ret;
}
/**
* 获取用户信息
*/
async getAppUserInfo() {
const { ctx } = this;
let appUserId = ctx.appUserId;
const result = await ctx.helper.send_request(this.config.USER_CENTER_API_URI + '/v1/appusers/' + appUserId, {}, { method: 'GET', dataType: 'json' });
const ret = result.status === 200 ? result.data : {};
if (ret.avatar && ret.avatar.indexOf('http') === -1) {
ret.avatar = this.config.CDN_BASE_URL + ret.avatar;
}
if (ret.avatar && ret.avatar !== null) {
ret.avatar = ret.avatar.replace(/^(?=^.{3,255}$)(http(s)?:\/\/)?(www\.)?[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+(:\d+)*(\/\w+\.\w+)*/i, 'https://r.51gjj.com');
}
return ret;
}
}
module.exports = MineService;
This diff is collapsed.
'use strict';
const Service = require('egg').Service;
const moment = require('moment');
class OrderService extends Service {
/**
* 添加预约信息
* @param {object} inputParams
*/
async addOrder(inputParams) {
const { ctx, service } = this;
let filter = {
where: {
state: 1,
user_id: ctx.userId,
connect_id: inputParams.id,
house_style: inputParams.type,
},
order: [['created_at', 'desc']],
}
let orderHistory = await ctx.realestateModel.Order.all(filter);
if (orderHistory.length > 0) {
let ret = {
id: orderHistory[0].id,
msg: '已经预约过',
};
return ret;
}
let data = {
user_id: ctx.userId,
app_user_id: ctx.appUserId,
house_style: inputParams.type,
connect_id: inputParams.id,
name: inputParams.name,
phone: inputParams.phone,
order_at: inputParams.time,
state: 1,
};
let ret = await ctx.realestateModel.Order.add(data);
return { id: ret.id, msg: '预约成功' };
}
/**
* 获取预约列表 保留最近6个月的记录,条数不超过50条
*/
async getOrderList() {
const { ctx, service } = this;
if (!ctx.userId) {
return {
results: [],
count: 0
};
}
let endDate = moment().subtract(6, 'months').format('YYYY-MM-DD HH:mm:ss');
let filter = {
page: 1,
limit: 50,
where: {
state: 1,
user_id: ctx.userId,
created_at: { $gt: endDate }
},
order: [['created_at', 'desc']]
}
let list = [];
let orderList = await ctx.realestateModel.Order.all(filter);
if (orderList.length > 0) {
//整理所有预约记录
let taskList = [];
for (let i in orderList) {
if (orderList[i].houseStyle === 1) {
taskList[i] = ctx.realestateModel.NewHouse.one(orderList[i].connectId);
} else {
taskList[i] = ctx.realestateModel.RentalHousel.one(orderList[i].connectId);
}
}
let retList = await Promise.all(taskList).then(result => {
return result;
}).catch(error => {
ctx.failed(error);
});
//数据整理
for (let j in retList) {
let type = orderList[j].house_style;
let tmp = {
id: retList[j].id,
name: retList[j].name,
address: retList[j].address,
tags: retList[j].tags ? eval(retList[j].tags) : [],
image: retList[j].image,
area: type === 1 ? retList[j].house_area : '',
price: type === 1 ? (Number(retList[j].reference_avg_price) === 0 ? '--' : retList[j].reference_avg_price) : Number(retList[j].price),
time: moment().format('YYYY-MM-DD') === moment(orderList[j].order_at).format('YYYY-MM-DD') ? '今天' : moment(orderList[j].order_at).format('YYYY-MM-DD'),
type: type === 1 ? 'new_house' : 'rental_house',
corner: type === 1 ? retList[j].cornerMarker : '',
};
list.push(tmp);
}
}
let ret = {
results: list,
count: list.length
};
return ret;
}
/**
* 我的-获取预约个数
*/
async getOrderCount() {
const { ctx } = this;
if (!ctx.userId) {
return { count: 0 };
}
let endDate = moment().subtract(6, 'months').format('YYYY-MM-DD HH:mm:ss');
let filter = {
page: 1,
limit: 50,
where: {
state: 1,
user_id: ctx.userId,
created_at: { $gt: endDate }
},
order: [['created_at', 'desc']]
}
let orderList = await ctx.realestateModel.Order.all(filter);
let ret = {
count: orderList.length
};
return ret;
}
}
module.exports = OrderService;
'use strict';
const Service = require('egg').Service;
const moment = require('moment');
class searchHistoryService extends Service {
/**
* 添加搜索历史
* @param {object} inputParams
*/
async addSearchHistory(inputParams) {
const { ctx } = this;
if (!ctx.userId) {
return false;
}
let data = {
user_id: ctx.userId,
app_user_id: ctx.appUserId,
key_word: inputParams.key_word,
house_style: inputParams.type,
state: 1,
};
let ret = await ctx.realestateModel.SearchHistory.add(data);
return { id: ret.id };
}
/**
* 获取搜索历史
* 历史记录取用户最近6个月的搜索记录,去重处理,条数不超过50条
* 排序根据搜索时间逆序排列,距离当前时间近的排在前面,重复搜索的关键词取最近一次的搜索时间进行排序
* 如果没有搜索记录的就不显示搜索词
*/
async getSearchHistoryList(type) {
const { ctx } = this;
let ret = {
results: [],
count: 0
};
if (!ctx.appUserId || !ctx.deviceId || !ctx.deviceLoginId || !ctx.userId) {
//如果没有登录就返回空
return ret;
}
let endDate = moment().subtract(180, 'days').format('YYYY-MM-DD HH:mm:ss');
let filter = {
page: 1,
limit: 50,
where: {
state: 1,
user_id: ctx.userId,
created_at: { $gt: endDate }
}
}
if (type) {
filter.where.house_style = type;
}
let list = [];
let searchHistoryList = await ctx.realestateModel.SearchHistory.all(filter);
if (searchHistoryList.length > 0) {
for (let i in searchHistoryList) {
if (list.indexOf(searchHistoryList[i].keyWord) === -1) {
list.push(searchHistoryList[i].keyWord);
}
}
}
ctx.logger.info(list);
ret = {
results: list,
count: list.length
};
return ret;
}
/**
* 用户点击清除搜索记录
*/
async cleanSearchHistory(type) {
const { ctx } = this;
let ret = { status: true };
if (!ctx.appUserId || !ctx.deviceId || !ctx.deviceLoginId || !ctx.userId) {
//如果没有登录就不做处理
return ret;
}
let filter = {
where: {
state: 1,
user_id: ctx.userId,
house_style: type
}
}
let searchHistoryList = await ctx.realestateModel.SearchHistory.all(filter);
if (searchHistoryList.length > 0) {
let updateFilter = {
params: { state: 0 },
where: {
house_style: type,
user_id: ctx.userId
}
}
await ctx.realestateModel.SearchHistory.edit(updateFilter);
}
return ret;
}
}
module.exports = searchHistoryService;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment