Commit 2dbbdcde authored by 任国军's avatar 任国军

add categoryTip

parent 8db9062e
Pipeline #21953 passed with stage
in 16 seconds
......@@ -54,6 +54,19 @@ class OptionController extends Controller {
const ret = await service.course.v5.option.addFeedback(params);
ctx.success(ret);
}
// 获取分类年龄提示
async getCategoryTip() {
const { ctx, service } = this;
const queryParams = ctx.request.query;
if (ctx.isEmpty(queryParams) || ctx.isEmpty(queryParams.cat_id)) {
ctx.failed('cat_id is empty');
}
const ret = await service.course.v5.option.getCategoryTip(queryParams);
ctx.success(ret);
}
}
module.exports = OptionController;
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE } = app.Sequelize;
const CourseV5CategoryTip = app.classModel.define('course_v5_category_tip', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
cat_id: INTEGER,
content: STRING,
advice: STRING,
button_text: STRING,
button_url: STRING,
status: INTEGER,
is_deleted: INTEGER,
created_time: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('created_time');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_time: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('updated_time');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'course_v5_category_tip',
});
return CourseV5CategoryTip;
};
......@@ -12,13 +12,14 @@ module.exports = app => {
router.get('third', '/user/info', auth, 'course.v5.user.getUserInfo');// 获取用户信息
router.post('third', '/user/baby', auth, 'course.v5.user.addUserBaby');// 上传用户宝宝信息
router.get('third', '/category/all', 'course.v5.option.getCategoryList');// 获取分类列表
router.get('third', '/category/all', auth, 'course.v5.option.getCategoryList');// 获取分类列表
router.get('third', '/banner/all', 'course.v5.option.getBannerList');// 获取banner列表
router.get('third', '/options', 'course.v5.option.getOptions');// 获取配置项
router.post('third', '/wechat/qrcode', 'course.v5.wechat.getQRCode');// 获取二维码
router.post('third', '/wechat/unlimited_code', 'course.v5.wechat.getUnlimitedCode');// 获取小程序码
router.get('third', '/feedback/type', 'course.v5.option.getFeedbackTypeList');// 获取反馈分类
router.post('third', '/feedback', auth, 'course.v5.option.addFeedback');// 反馈
router.get('third', '/category/tip', auth, 'course.v5.option.getCategoryTip');// 获取分类提示(年龄不符合)
router.get('third', '/class/all', auth, 'course.v5.institution.getClassList');// 获取课程列表
router.get('third', '/class/:class_id', auth, 'course.v5.institution.getClassInfo');// 获取课程详情
......
......@@ -11,13 +11,21 @@ const MODE = [
value: 1,
}, {
id: 2,
name: '录播',
name: '录播(动画)',
value: 2,
}, {
id: 3,
name: '直播+回放',
name: '录播(真人)',
value: 3,
}, {
id: 4,
name: 'APP',
value: 4,
}, {
id: 5,
name: '小程序',
value: 5,
}, {
id: 0,
name: '全部',
value: 0,
......@@ -27,11 +35,11 @@ const MODE = [
const PRICE_TYPE = [
{
id: 1,
name: '低价体验课',
name: '免费公益课',
value: 1,
}, {
id: 2,
name: '公益免费课',
name: '低价体验课',
value: 2,
}, {
id: 3,
......@@ -125,6 +133,24 @@ class OptionService extends Service {
const categoryList = await ctx.classModel.V5.CourseV5Category.findAll(filter);
const filterIds = [];
// 智能选课要判断年龄
if (type === 3) {
const userBabyInfo = await ctx.classModel.V5.CourseV5UserBaby.findOne({ where: { user_uuid: ctx.userUuid, status: 1, is_deleted: 0 } });
if (!ctx.isEmpty(userBabyInfo)) {
switch (userBabyInfo.baby_age) {
case 1:
filterIds.push(17);
break;
case 2:
filterIds.push(17);
break;
default:
break;
}
}
}
const results = [];
for (const v of categoryList) {
results.push({
......@@ -136,6 +162,7 @@ class OptionService extends Service {
unselected_icon: v.unselected_icon,
is_open: v.is_open,
url: v.url,
is_valid: filterIds.includes(v.id) ? 0 : 1,
sort: v.sort,
});
}
......@@ -181,6 +208,33 @@ class OptionService extends Service {
return { result: true };
}
// 获取分类提示(年龄不符合)
async getCategoryTip(input) {
const { ctx } = this;
const catId = Number(input.cat_id) || 0;
const tip = await ctx.classModel.V5.CourseV5CategoryTip.findOne({ where: { cat_id: catId, status: 1, is_deleted: 0 } });
if (ctx.isEmpty(tip)) {
return {};
}
const category = await ctx.classModel.V5.CourseV5Category.findOne({ where: { id: catId }, attributes: [ 'name' ] });
const userBabyInfo = await ctx.classModel.V5.CourseV5UserBaby.findOne({ where: { user_uuid: ctx.userUuid, status: 1, is_deleted: 0 } });
let age = ctx.isEmpty(userBabyInfo) ? 0 : userBabyInfo.baby_age;
age = await ctx.classModel.V5.CourseV5Age.findOne({ where: { id: age }, attributes: [ 'name' ] });
age = ctx.isEmpty(age) ? '' : age.name;
const ret = ctx.isEmpty(tip) ? {} : {
id: tip.id,
category: ctx.isEmpty(category) ? '' : category.name,
content: `您的孩子当前处于【${age}】阶段,` + tip.content,
advice: tip.advice,
button_text: tip.button_text,
button_url: tip.button_url,
};
return ret;
}
}
module.exports = OptionService;
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