Commit a906d7bd authored by 任国军's avatar 任国军
parents 12226915 98f5af10
Pipeline #8884 passed with stage
in 5 seconds
'use strict';
const Controller = require('egg').Controller;
class AnswerController extends Controller {
/**
* 回答
*/
async answer() {
const { ctx } = this;
let inputParams = ctx.request.body;
const rule = {
answer: { type: 'string', required: true },
question_id: { type: 'integer', required: true },
city_code: { type: 'integer', required: true },
};
ctx.validate(rule, inputParams);
if (inputParams.answer.length > 500) {
ctx.failed('最多输入500个字符');
}
let ret = await ctx.service.house.v2.hotQuestionAnswer.addAnswer(inputParams);
ctx.success(ret);
}
}
module.exports = AnswerController;
'use strict';
const Controller = require('egg').Controller;
class HouseAnalysisController extends Controller {
//购房解析列表
async getHouseAnalysisList() {
const { ctx } = this;
const input_params = ctx.request.body;
if (!input_params.city_code) {
ctx.failed('city_code error');
}
let results = await ctx.service.house.v2.houseAnalysis.getHouseAnalysisByFilter(input_params);
const format_rows = await ctx.service.house.v2.houseAnalysis.formatHouseAnalysis(results.results);
results.results = format_rows;
ctx.success(results);
}
//购房解析详情
async getHouseAnalysisInfo() {
const { ctx } = this;
const house_analysis_id = ctx.params.house_analysis_id;
const city_code = ctx.query.city_code;
const results = await ctx.service.house.v2.houseAnalysis.getHouseAnalysis(house_analysis_id);
//推荐楼盘
let where = { corner: { $ne: '' } };
if (city_code) {
where.option_city_code = city_code;
}
let new_houses_rows = await ctx.realestateModel.NewHouse.list({ page: 1, limit: 3, where: where, order: [['order_id', 'asc']] });
const similar_list = [];
for (let i in new_houses_rows.rows) {
const new_house = new_houses_rows.rows[i];
similar_list.push({
id: new_house.id,
name: new_house.name,
image: new_house.image,
corner: new_house.corner,
});
}
ctx.success({ results: { info: results, similar_list } });
}
async uploadHouseAnalysis() {
const { ctx } = this;
const input_params = ctx.request.body;
const rule = {
name: { type: 'string', required: true },
city_code: { type: 'string', required: true },
house_type: { type: 'string', required: true },
area: { type: 'string', required: true },
image: { type: 'string', required: true },
}
ctx.validate(rule, input_params);
const result = await ctx.service.house.v2.houseAnalysis.addHouseAnalysis(input_params);
ctx.success({ result });
}
async getUserHouseAnalysis() {
const { ctx } = this;
const input_params = ctx.query;
const results = await ctx.service.house.v2.houseAnalysis.getMineHouseAnalysis(input_params);
const format_rows = await ctx.service.house.v2.houseAnalysis.formatHouseAnalysis(results.rows);
ctx.success({ page: results.page, count: results.count, results: format_rows });
}
}
module.exports = HouseAnalysisController;
'use strict';
const Controller = require('egg').Controller;
class LikeController extends Controller {
/**
* 点赞
*/
async like() {
const { ctx } = this;
let inputParams = ctx.params;
let ret = await ctx.service.house.v2.answerLike.like(Number(inputParams.id));
ctx.success(ret);
}
/**
* 取消点赞
*/
async unLike() {
const { ctx } = this;
let inputParams = ctx.params;
let ret = await ctx.service.house.v2.answerLike.unLike(Number(inputParams.id));
ctx.success(ret);
}
}
module.exports = LikeController;
'use strict';
const Controller = require('egg').Controller;
class QuestionController extends Controller {
/**
* 提问
*/
async addQuestion() {
const { ctx } = this;
let inputParams = ctx.request.body;
const rule = {
question: { type: 'string', required: true },
city_code: { type: 'integer', required: true },
};
ctx.validate(rule, inputParams);
if (inputParams.question.length > 100) {
ctx.failed('提问最多100个字符');
}
let ret = await ctx.service.house.v2.hotQuestionPut.addQuestion(inputParams);
ctx.success(ret);
}
/**
* 我的问题
*/
async mineQuestion() {
const { ctx } = this;
let inputParams = ctx.request.body;
const rule = {
page: { type: 'integer', required: false },
limit: { type: 'integer', required: false },
};
ctx.validate(rule, inputParams);
let ret = await ctx.service.house.v2.hotQuestionPut.mineQuestion(inputParams);
ctx.success(ret);
}
/**
* 问题列表
*/
async questionList() {
const { ctx } = this;
let inputParams = ctx.request.body;
const rule = {
page: { type: 'integer', required: false },
limit: { type: 'integer', required: false },
key_word: { type: 'string', required: false },
city_code: { type: 'integer', required: true },
};
ctx.validate(rule, inputParams);
let ret = await ctx.service.house.v2.hotQuestionPut.questionList(inputParams);
ctx.success(ret);
}
/**
* 问题详情
*/
async questionDetail() {
const { ctx } = this;
let inputParams = ctx.request.body;
const rule = {
id: { type: 'integer', required: true },
page: { type: 'integer', required: false },
limit: { type: 'integer', required: false },
};
ctx.validate(rule, inputParams);
let ret = await ctx.service.house.v2.hotQuestionPut.questionDetail(inputParams);
ctx.success(ret);
}
}
module.exports = QuestionController;
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, ENUM, DATE } = app.Sequelize;
const AnswerLike = app.realestateModel.define('answer_like', {
id: {
type: INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
user_id: {
type: STRING,
allowNull: true
},
app_user_id: {
type: STRING,
allowNull: true
},
app_id: {
type: STRING,
allowNull: true
},
app_type_id: {
type: STRING,
allowNull: true
},
answer_id: {
type: INTEGER,
allowNull: true
},
state: {
type: INTEGER,
allowNull: true
},
created_at: {
type: DATE,
get() {
const date = this.getDataValue('created_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_at: {
type: DATE,
get() {
const date = this.getDataValue('updated_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
deleted_at: {
type: DATE,
get() {
const date = this.getDataValue('deleted_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'answer_like',
});
AnswerLike.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await AnswerLike.findOne({
attributes: attributes,
where: where,
});
}
AnswerLike.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await AnswerLike.findAll({
attributes: attributes,
where: where,
order,
});
}
AnswerLike.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 AnswerLike.findAndCountAll(condition);
return { page, count, rows };
}
AnswerLike.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await AnswerLike.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
}
AnswerLike.edit = async (data) => {
const where = data.where;
const params = data.params;
try {
return await AnswerLike.update(params, { where: where })
} catch (error) {
throw (error);
}
}
return AnswerLike;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, ENUM, DATE } = app.Sequelize;
const HotQuestionAnswer = app.realestateModel.define('hot_question_answer', {
id: {
type: INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
user_id: {
type: STRING,
allowNull: true
},
app_user_id: {
type: STRING,
allowNull: true
},
app_id: {
type: STRING,
allowNull: true
},
app_type_id: {
type: STRING,
allowNull: true
},
question_id: {
type: INTEGER,
allowNull: true
},
answer: {
type: STRING,
allowNull: true
},
city: {
type: INTEGER,
allowNull: true
},
status: {
type: ENUM('pass', 'refuse', 'wait'),
allowNull: true
},
created_at: {
type: DATE,
get() {
const date = this.getDataValue('created_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_at: {
type: DATE,
get() {
const date = this.getDataValue('updated_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
deleted_at: {
type: DATE,
get() {
const date = this.getDataValue('deleted_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'hot_question_answer',
});
HotQuestionAnswer.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await HotQuestionAnswer.findOne({
attributes: attributes,
where: where,
});
}
HotQuestionAnswer.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await HotQuestionAnswer.findAll({
attributes: attributes,
where: where,
order,
});
}
HotQuestionAnswer.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 HotQuestionAnswer.findAndCountAll(condition);
return { page, count, rows };
}
HotQuestionAnswer.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await HotQuestionAnswer.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
}
HotQuestionAnswer.edit = async (data) => {
const where = data.where;
const params = data.params;
try {
return await HotQuestionAnswer.update(params, { where: where })
} catch (error) {
throw (error);
}
}
return HotQuestionAnswer;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, ENUM, DATE } = app.Sequelize;
const HotQuestionPut = app.realestateModel.define('hot_question_put', {
id: {
type: INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
user_id: {
type: STRING,
allowNull: true
},
app_user_id: {
type: STRING,
allowNull: true
},
app_id: {
type: STRING,
allowNull: true
},
app_type_id: {
type: STRING,
allowNull: true
},
question: {
type: STRING,
allowNull: true
},
city: {
type: INTEGER,
allowNull: true
},
status: {
type: ENUM('pass', 'refuse', 'wait'),
allowNull: true
},
created_at: {
type: DATE,
get() {
const date = this.getDataValue('created_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_at: {
type: DATE,
get() {
const date = this.getDataValue('updated_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
deleted_at: {
type: DATE,
get() {
const date = this.getDataValue('deleted_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'hot_question_put',
});
HotQuestionPut.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await HotQuestionPut.findOne({
attributes: attributes,
where: where,
});
}
HotQuestionPut.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await HotQuestionPut.findAll({
attributes: attributes,
where: where,
order,
});
}
HotQuestionPut.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 HotQuestionPut.findAndCountAll(condition);
return { page, count, rows };
}
HotQuestionPut.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await HotQuestionPut.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
}
HotQuestionPut.edit = async (data) => {
const where = data.where;
const params = data.params;
try {
return await HotQuestionPut.update(params, { where: where })
} catch (error) {
throw (error);
}
}
return HotQuestionPut;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, ENUM, DATE } = app.Sequelize;
const HouseAnalysis = app.realestateModel.define('house_analysis', {
id: {
type: INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
user_id: STRING,
app_user_id: STRING,
app_id: STRING,
app_type_id: STRING,
residential: STRING,
city: STRING,
house_type: STRING,
house_area: STRING,
image: STRING,
text: STRING,
status: ENUM('pass', 'refuse', 'wait'),
created_at: {
type: DATE,
get() {
const date = this.getDataValue('created_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_at: {
type: DATE,
get() {
const date = this.getDataValue('updated_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
deleted_at: {
type: DATE,
get() {
const date = this.getDataValue('deleted_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'house_analysis',
});
HouseAnalysis.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await HouseAnalysis.findOne({
attributes: attributes,
where: where,
});
}
HouseAnalysis.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await HouseAnalysis.findAll({
attributes: attributes,
where: where,
order,
});
}
HouseAnalysis.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 HouseAnalysis.findAndCountAll(condition);
return { page, count, rows };
}
HouseAnalysis.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await HouseAnalysis.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
}
HouseAnalysis.edit = async (data) => {
const where = data.where;
const params = data.params;
try {
return res = await HouseAnalysis.update(params, { where: where })
} catch (error) {
throw (error);
}
}
return HouseAnalysis;
};
......@@ -48,6 +48,14 @@ module.exports = app => {
//房产v2
router.get('/v2/tool/:house_style/:area_code/:level', 'house.tool.getMapPoint');//购房计划地图点位
router.post('/v2/tool/plan', 'house.tool.generateBuyHousePlan');//生成购房计划
router.get('/v2/tool/:type/:area_code', 'house.tool.getHousePriceFeature');//房价指数 房价涨跌 购房资格、贷款额度问答
router.post('/v2/tool/calculate_price', 'house.tool.calculateHousePrice');//房产估价
router.get('/v2/tool/qfang_area_list', 'house.tool.getQFangAreaList');//房产估价模糊匹配到的小区列表
router.get('/v2/tool/map_houses', 'house.tool.getMapHouses');//房产估价模糊匹配到的小区列表
//租房列表
router.get('/v2/rental_house/home', 'house.v2.rentalHouse.home');//租房首页信息
router.get('/v2/rental_house/list', 'house.v2.rentalHouse.getRentalHouses');//租房列表
......@@ -81,6 +89,28 @@ module.exports = app => {
router.get('/v2/mine', 'house.v2.mine.getMineInfo');//获取用户的头像昵称和关注等信息
//
router.get('/tool/gjj/loan/measure/:area', 'house.v2.tool.gjjLoanMeasureInfo');//貸款測算
router.get('/v2/tool/gjj/loan/measure/:area', 'house.v2.tool.gjjLoanMeasureInfo');//貸款測算
//户型解析
router.get('/v2/house_analysis/list', 'house.v2.houseAnalysis.getHouseAnalysisList');//户型解析列表
router.post('/v2/house_analysis/list', 'house.v2.houseAnalysis.getHouseAnalysisList');//户型解析列表
router.get('/v2/house_analysis/info/:house_analysis_id', 'house.v2.houseAnalysis.getHouseAnalysisInfo');//户型解析列表
router.post('/v2/house_analysis/', loginAuth, 'house.v2.houseAnalysis.uploadHouseAnalysis');//上传户型信息
router.get('/v2/house_analysis/mine', loginAuth, 'house.v2.houseAnalysis.getUserHouseAnalysis');//我的户型
//提问
router.post('/v2/question', loginAuth, 'house.v2.question.addQuestion');//提问
router.post('/v2/question/mine', loginAuth, 'house.v2.question.mineQuestion');//我的问题
router.post('/v2/question/list', 'house.v2.question.questionList');//问题列表
router.post('/v2/question/detail', 'house.v2.question.questionDetail');//问题详情
//回答
router.post('/v2/answer', loginAuth, 'house.v2.answer.answer');//回答
//点赞回答
router.post('/v2/answer/like/:id', loginAuth, 'house.v2.like.like');//点赞
router.put('/v2/answer/like/:id', loginAuth, 'house.v2.like.unLike');//取消点赞
};
\ No newline at end of file
'use strict';
const Service = require('egg').Service;
const moment = require('moment');
class AnswerLikeService extends Service {
/**
* 回答
* @param {object} inputParams
*/
async like(id) {
const { ctx } = this;
let filter = {
where: {
answer_id: id,
user_id: ctx.userId,
state: 1
}
}
let likeInfo = await ctx.realestateModel.AnswerLike.one(filter);
if (likeInfo !== null) {
return { id: likeInfo.id };
}
let data = {
user_id: ctx.userId,
app_user_id: ctx.appUserId,
app_id: ctx.appId,
app_type_id: ctx.appTypeId,
answer_id: id,
state: 1,
};
let retId = await ctx.realestateModel.AnswerLike.add(data);
return { id: retId };
}
/**
* 取消点赞
* @param {*} inputParams
*/
async unLike(id) {
const { ctx } = this;
let filter = {
params: {
state: 0
},
where: {
answer_id: id,
user_id: ctx.userId,
state: 1
}
}
let res = await ctx.realestateModel.AnswerLike.edit(filter);
return { status: true };
}
/**
* 是否点赞某个回答
* @param {*} id
*/
async isLike(id) {
const { ctx } = this;
let isLike = false;
if (!ctx.userId) {
return isLike;
}
let filter = {
where: {
answer_id: id,
state: 1,
user_id: ctx.userId
}
}
let likeInfo = await ctx.realestateModel.AnswerLike.all(filter);
isLike = likeInfo.length > 0 ? true : false;
return ret;
}
/**
* 获取某个回答被点赞的数量
* @param {*} id
*/
async getLikeCount(id) {
const { ctx } = this;
let likeFilter = {
attributes: ['id'],
where: {
answer_id: Number(id),
state: 1
}
}
let answerLikeList = await ctx.realestateModel.AnswerLike.all(likeFilter);
return answerLikeList.length;
}
}
module.exports = AnswerLikeService;
'use strict';
const Service = require('egg').Service;
const moment = require('moment');
class HotQuestionAnswerService extends Service {
/**
* 回答
* @param {object} inputParams
*/
async addAnswer(inputParams) {
const { ctx } = this;
let data = {
user_id: ctx.userId,
app_user_id: ctx.appUserId,
app_id: ctx.appId,
app_type_id: ctx.appTypeId,
question_id: inputParams.question_id,
answer: inputParams.answer,
city: inputParams.city_code,
status: 'wait',
};
let retId = await ctx.realestateModel.HotQuestionAnswer.add(data);
return { id: retId };
}
/**
* 回答列表
* @param {*} condition
*/
async answerList(condition) {
const { ctx } = this;
let filter = {
page: condition.page || 1,
limit: condition.limit || 10,
where: {
question_id: Number(condition.question_id),
status: 'pass',
},
order: [['created_at', 'desc']]
}
let res = await ctx.realestateModel.HotQuestionAnswer.list(filter);
let taskList = [];
for (let i in res.rows) {
taskList[i] = this.formatAnswer(res.rows[i]);
}
let retList = await Promise.all(taskList).then(result => {
return result;
}).catch(error => {
ctx.failed(error);
});
let ret = {
results: retList,
count: res.count
}
return ret;
}
/**
* 获取该回答的点赞数量
* 用户头像昵称
* 本人是否点赞
* @param {*} data
*/
async formatAnswer(data) {
const { ctx } = this;
//回答的用户信息
let answerUserInfo = await ctx.service.house.v2.mine.getAppUserInfo(data.app_user_id);
//点赞的数量
let LikeCount = await ctx.service.house.v2.answerLike.getLikeCount(Number(data.id));
//本人是否点赞
let isLike = await ctx.service.house.v2.answerLike.isLike(Number(data.id));
let ret = {
id: data.id,
question: data.question,
time: data.created_at,
avatar: answerUserInfo.avatar || '',
nickname: answerUserInfo.nickname || '',
like: isLike,
count: LikeCount,
}
return ret;
}
}
module.exports = HotQuestionAnswerService;
'use strict';
const Service = require('egg').Service;
const moment = require('moment');
class HotQuestionPutService extends Service {
/**
* 添加预约信息
* @param {object} inputParams
*/
async addQuestion(inputParams) {
const { ctx } = this;
let data = {
user_id: ctx.userId,
app_user_id: ctx.appUserId,
app_id: ctx.appId,
app_type_id: ctx.appTypeId,
question: inputParams.question,
city: Number(inputParams.city_code),
status: 'wait',
};
let retId = await ctx.realestateModel.HotQuestionPut.add(data);
return { id: retId };
}
/**
* 根据条件获取热门问题列表
* 默认城市北京110000
* 默认取20条
* @param {object} condition
*/
async questionList(condition) {
const { ctx } = this;
let filter = {
attributes: ['id', 'question'],
page: condition.page || 1,
limit: condition.limit || 20,
where: {
city: condition.city_code || 110000,
status: 'pass',
},
order: [['created_at', 'desc']]
}
if (condition.key_word) {//关键词搜索 模糊查询
//增加搜索历史
// let addHistory = {
// type: 1,
// key_word: condition.name
// };
// await ctx.service.house.v2.searchHistory.addSearchHistory(addHistory);
filter.where.question = { $like: '%' + condition.key_word + '%' }
}
let res = await ctx.realestateModel.HotQuestionPut.list(filter);
let ret = {
count: res.count,
results: res.rows
}
return ret;
}
/**
* 问题详情
* @param {*} condition
*/
async questionDetail(condition) {
const { ctx } = this;
//问题内容
let filter = {
attributes: ['question'],
where: {
id: Number(condition.id),
status: "pass"
}
}
let question = await ctx.realestateModel.HotQuestionPut.one(filter);
//回答的列表
let answerFliter = {
page: Number(condition.page) || 1,
limit: Number(condition.limit) || 10,
question_id: Number(condition.id),
}
let answerLsit = await ctx.service.house.v2.hotQuestionAnswer.answerList(answerFliter);
let ret = {
question: question.question,
answerList: answerLsit
}
return ret;
}
async mineQuestion(condition) {
const { ctx } = this;
let filter = {
page: condition.page || 1,
limit: condition.limit || 10,
attributes: ['id', 'question', 'status'],
where: {
user_id: ctx.userId,
},
order: [['created_at', 'desc']]
}
let res = await ctx.realestateModel.HotQuestionPut.list(filter);
let ret = {
results: res.rows,
count: res.count
}
return ret;
}
}
module.exports = HotQuestionPutService;
'use strict';
const Service = require('egg').Service;
const R = require('ramda');
const moment = require('moment');
class HouseAnalysisService extends Service {
//户型解析列表
async getHouseAnalysisByFilter(condition) {
const { ctx } = this;
let { city_code, keyword, page } = condition;
page = page ? page : 1;
let where = { status: 'pass' };
if (city_code) {
where.city = city_code;
}
if (keyword && keyword.length !== 0) {
where.residential = { $like: `%${keyword}%` }
}
const house_analysis_rows = await ctx.realestateModel.HouseAnalysis.list({ page: page, where: where, order: [['id', 'desc']] });
const house_analysis = R.project(['id', 'image', 'residential', 'house_type', 'house_area', 'text'])(house_analysis_rows.rows);
return { page: page, count: house_analysis_rows.count, results: house_analysis };
}
//户型解析详情
async getHouseAnalysis(house_analysis_id) {
const { ctx } = this;
const house_analysis = await ctx.realestateModel.HouseAnalysis.one({ where: { id: house_analysis_id } });
return {
id: house_analysis.id,
image: house_analysis.image,
name: house_analysis.residential,
house_type: house_analysis.house_type,
area: house_analysis.house_area,
description: house_analysis.text,
status: house_analysis.status,
}
}
async addHouseAnalysis(params) {
const { ctx } = this;
const user_id = ctx.userId;
const app_user_id = ctx.appUserId;
const app_id = ctx.appId;
const app_type_id = ctx.appTypeId;
if (!user_id || !app_user_id || !app_id || !app_type_id) {
ctx.failed('login error');
}
const data = {
user_id,
app_user_id,
app_id,
app_type_id,
residential: params.name,
house_type: params.house_type,
city: params.city_code,
house_area: params.area,
image: params.image,
created_at: moment(new Date()).format('YYYY-MM-DD HH:mm:ss'),
}
const ret = await ctx.realestateModel.HouseAnalysis.add(data);
return ret;
}
async getMineHouseAnalysis(condition) {
const { ctx } = this;
const page = condition.page ? condition.page : 1;
const limit = condition.page_size ? condition.page_size : 10;
const user_id = ctx.userId;
const app_type_id = ctx.appTypeId;
if (!user_id || !app_type_id) {
ctx.failed('login error');
}
const results = await ctx.realestateModel.HouseAnalysis.list({ page: page, limit: limit, where: { user_id: user_id, app_type_id: app_type_id }, order: [['id', 'desc']] });
return results;
}
async formatHouseAnalysis(house_analysis) {
const { ctx } = this;
if (!Array.isArray(house_analysis) || house_analysis.length === 0) {
return [];
}
const ret = house_analysis.map(item => { return { id: item.id, name: item.residential, status: item.status, house_type: item.house_type, area: item.house_area, description: item.text, image: item.image } });
return ret;
}
}
module.exports = HouseAnalysisService;
......@@ -34,7 +34,7 @@ class MineService extends Service {
if (!ctx.userId) {
return ret;
}
let appUserInfo = await this.getAppUserInfo();
let appUserInfo = await this.getAppUserInfo(ctx.appUserId);
ctx.logger.info('appUserInfo:' + JSON.stringify(appUserInfo));
let footPrintList = await service.house.v2.footPrint.getFootPrintCount();
let collectionList = await service.house.v2.collection.getCollectionCount();
......@@ -59,9 +59,8 @@ class MineService extends Service {
/**
* 获取用户信息
*/
async getAppUserInfo() {
async getAppUserInfo(appUserId) {
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) {
......
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