Commit fc05270e authored by 任国军's avatar 任国军

fix bugs

parent a2e913ea
Pipeline #26455 passed with stage
in 8 seconds
...@@ -387,11 +387,44 @@ class InstitutionSubService extends Service { ...@@ -387,11 +387,44 @@ class InstitutionSubService extends Service {
async getSearchRecommend(input) { async getSearchRecommend(input) {
const { ctx } = this; const { ctx } = this;
const word = input.word || '';
const limit = 10; const limit = 10;
const offset = 0; const offset = 0;
const filter = { where: { status: 1, is_deleted: 0 }, order: [[ 'sort', 'asc' ], [ 'id', 'desc' ]], limit, offset, attributes: [ 'id', 'name' ], raw: true };
let filterIds = [];
let flag = false;
const classList = await ctx.classModel.V5.CourseV5Class.findAll({ where: { name: { $like: `%${word}%` }, status: 1, is_deleted: 0 }, attributes: [ 'id', 'name' ], raw: true, limit, offset }); // 年龄筛选
if (!ctx.isEmpty(input.age)) {
const filterByAge = await ctx.classModel.V5.CourseV5ClassToAge.findAll({ where: { age_id: input.age, status: 1, is_deleted: 0 }, attributes: [ 'class_id' ] });
filterIds = R.pluck('class_id', filterByAge);
flag = true;
}
// 科目类型
if (!ctx.isEmpty(input.category)) {
const filterByCategory = await ctx.classModel.V5.CourseV5ClassToCat.findAll({ where: { cat_id: input.category, status: 1, is_deleted: 0 }, attributes: [ 'class_id' ] });
filterIds = flag ? _.intersection(filterIds, R.pluck('class_id', filterByCategory)) : R.pluck('class_id', filterByCategory);
flag = true;
}
// 课程状态
if (!ctx.isEmpty(input.mode)) {
filter.where.mode = input.mode;
}
// 课程类型
if (!ctx.isEmpty(input.price_type)) {
filter.where.price_type = input.price_type;
}
// 搜索
if (!ctx.isEmpty(input.word)) {
// 先查询机构名称的
const institutionList = await ctx.classModel.V5.CourseV5Institution.findAll({ where: { name: { $like: `%${input.word}%` }, status: 1, is_deleted: 0 }, attributes: [ 'id', 'name' ], raw: true });
const institutionIds = R.pluck('id', institutionList);
filter.where.$or = [{ name: { $like: `%${input.word}%` } }, { institution_id: { $in: institutionIds } }];
}
if (flag) {
filter.where.id = { $in: filterIds };
}
const classList = await ctx.classModel.V5.CourseV5Class.findAll(filter);
const ret = { list: classList }; const ret = { list: classList };
return ret; return ret;
} }
......
...@@ -19,13 +19,15 @@ class UserService extends Service { ...@@ -19,13 +19,15 @@ class UserService extends Service {
ctx.failed('手机号不正确'); ctx.failed('手机号不正确');
} }
const redisCode = await ctx.app.memcache.get(`course_verify_code_${phone}`); // const redisCode = await ctx.app.memcache.get(`course_verify_code_${phone}`);
if (!ctx.isEmpty(redisCode)) { const redisCheck = await ctx.app.memcache.get(`course_verify_code_check_${phone}`);
if (!ctx.isEmpty(redisCheck)) {
ctx.failed('请勿频繁操作'); ctx.failed('请勿频繁操作');
} }
if (ctx.app.config.env === 'local') { if (ctx.app.config.env === 'local') {
await ctx.app.memcache.set(`course_verify_code_${phone}`, '12345', 300); await ctx.app.memcache.set(`course_verify_code_${phone}`, '12345', 300);
await ctx.app.memcache.set(`course_verify_code_check_${phone}`, '1', 59);
return { result: true }; return { result: true };
} }
...@@ -49,6 +51,7 @@ class UserService extends Service { ...@@ -49,6 +51,7 @@ class UserService extends Service {
if (ret.status === 201 || ret.status === 200) { if (ret.status === 201 || ret.status === 200) {
await ctx.app.memcache.set(`course_verify_code_${phone}`, code, 300); await ctx.app.memcache.set(`course_verify_code_${phone}`, code, 300);
await ctx.app.memcache.set(`course_verify_code_check_${phone}`, '1', 59);
} else { } else {
ctx.logger.info('course_send_verify_code_error: ' + JSON.stringify(ret.data)); ctx.logger.info('course_send_verify_code_error: ' + JSON.stringify(ret.data));
ctx.failed('发送验证码失败'); ctx.failed('发送验证码失败');
......
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