Commit 094839d4 authored by 任国军's avatar 任国军

add menu sort & getUsedRedeemCodeList

parent b6acc0f5
Pipeline #25480 passed with stage
in 4 seconds
......@@ -95,6 +95,16 @@ class BackController extends Controller {
await service.course.back.exportRedeemCode(queryParams);
}
// 已用兑换码列表
async getUsedRedeemCodeList() {
const { ctx, service } = this;
const queryParams = ctx.request.query;
const ret = await service.course.back.getUsedRedeemCodeList(queryParams);
ctx.success(ret);
}
}
module.exports = BackController;
......@@ -16,6 +16,7 @@ module.exports = app => {
path: STRING,
icon: STRING,
parent_id: INTEGER,
sort: INTEGER,
is_deleted: INTEGER,
created_time: {
type: DATE,
......
......@@ -12,4 +12,5 @@ module.exports = app => {
router.get('third', '/class', auth, 'course.back.getClassList');
router.get('third', '/export/order', auth, 'course.back.exportOrder');
router.get('third', '/export/redeem', auth, 'course.back.exportRedeemCode');
router.get('third', '/redeem/used', auth, 'course.back.getUsedRedeemCodeList');
};
......@@ -47,10 +47,10 @@ class BackService extends Service {
let menuList = [];
if (userInfo.is_admin > 0) {
menuList = await ctx.classModel.CourseBackMenu.findAll({ where: { is_deleted: 0 }, attributes: [ 'id', 'title', 'path', 'icon', 'parent_id' ], raw: true });
menuList = await ctx.classModel.CourseBackMenu.findAll({ where: { is_deleted: 0 }, attributes: [ 'id', 'title', 'path', 'icon', 'parent_id' ], order: [[ 'sort', 'asc' ]], raw: true });
} else {
const userToMenuList = await ctx.classModel.CourseBackUserToMenu.findAll({ where: { user_uuid: userUuid, is_deleted: 0 } });
menuList = await ctx.classModel.CourseBackMenu.findAll({ where: { id: { $in: R.pluck('menu_id', userToMenuList) }, is_deleted: 0 }, attributes: [ 'id', 'title', 'path', 'icon', 'parent_id' ], raw: true });
menuList = await ctx.classModel.CourseBackMenu.findAll({ where: { id: { $in: R.pluck('menu_id', userToMenuList) }, is_deleted: 0 }, attributes: [ 'id', 'title', 'path', 'icon', 'parent_id' ], order: [[ 'sort', 'asc' ]], raw: true });
}
for (const i in menuList) {
......@@ -88,7 +88,7 @@ class BackService extends Service {
ctx.failed('用户异常');
}
const filter = { where: { status: 1, is_deleted: 0 }, limit, offset, attributes: [ 'id', 'order_no', 'class_id', 'pay', 'pay_time', 'type', 'redeem', 'address' ], order: [[ 'pay_time', 'desc' ]] };
const filter = { where: { type: 1, status: 1, is_deleted: 0 }, limit, offset, attributes: [ 'id', 'order_no', 'class_id', 'pay', 'pay_time', 'address' ], order: [[ 'pay_time', 'desc' ]] };
let filterClassIds = [];
if (!ctx.isEmpty(input.class_name)) {
const classList = await ctx.classModel.V5.CourseV5Class.findAll({ where: { name: { $like: `%${input.class_name}%` } }, attributes: [ 'id' ] });
......@@ -138,8 +138,6 @@ class BackService extends Service {
class_name: ctx.isEmpty(classList[v.class_id]) ? '' : classList[v.class_id][0].name,
pay: v.pay,
pay_time: v.pay_time,
type: v.type,
redeem: v.redeem,
address: ctx.isEmpty(v.address) ? {} : JSON.parse(v.address),
});
}
......@@ -220,6 +218,78 @@ class BackService extends Service {
}
// 获取已使用兑换码列表
async getUsedRedeemCodeList(input) {
const { ctx } = this;
const userUuid = ctx.userUuid;
const page = Number(input.page) || 1;
const limit = Number(input.limit) || 10;
const offset = (page - 1) * limit;
const userInfo = await ctx.classModel.CourseBackUser.findOne({ where: { id: userUuid, is_deleted: 0 } });
if (ctx.isEmpty(userInfo)) {
ctx.failed('用户异常');
}
const filter = { where: { is_used: 1, status: 1, is_deleted: 0 }, limit, offset, order: [[ 'used_time', 'desc' ]] };
let filterClassIds = [];
if (!ctx.isEmpty(input.class_name)) {
const classList = await ctx.classModel.V5.CourseV5Class.findAll({ where: { name: { $like: `%${input.class_name}%` } }, attributes: [ 'id' ] });
filterClassIds = R.pluck('id', classList);
filter.where.class_id = { $in: filterClassIds };
}
if (!ctx.isEmpty(userInfo.institution_id) && userInfo.institution_id > 0) {
const classList = await ctx.classModel.V5.CourseV5Class.findAll({ where: { institution_id: userInfo.institution_id }, attributes: [ 'id' ] });
filterClassIds = ctx.isEmpty(input.class_name) ? R.pluck('id', classList) : _.intersection(filterClassIds, R.pluck('id', classList));
filter.where.class_id = { $in: filterClassIds };
}
const redeemCodeList = await ctx.classModel.V5.CourseRedeemCode.findAndCountAll(filter);
if (ctx.isEmpty(redeemCodeList.rows)) {
return {
list: [],
page_size: limit,
total_count: redeemCodeList.count,
page,
};
}
let classList = await ctx.classModel.V5.CourseV5Class.findAll({ where: { id: { $in: _.uniq(R.pluck('class_id', redeemCodeList.rows)) } }, attributes: [ 'id', 'name' ], raw: true });
classList = _.groupBy(classList, 'id');
let userList = await ctx.classModel.V5.CourseUser.findAll({ where: { uuid: { $in: _.uniq(R.pluck('user_uuid', redeemCodeList.rows)) } }, attributes: [ 'uuid', 'phone' ], raw: true });
userList = _.groupBy(userList, 'uuid');
let orderList = await ctx.classModel.V5.CourseUserOrder.findAll({ where: { redeem: { $in: _.uniq(R.pluck('code', redeemCodeList.rows)) }, type: 2, status: 1, is_deleted: 0 }, attributes: [ 'redeem', 'order_no' ], raw: true });
orderList = _.groupBy(orderList, 'redeem');
const results = [];
for (const v of redeemCodeList.rows) {
results.push({
id: v.id,
class_id: v.class_id,
class_name: ctx.isEmpty(classList[v.class_id]) ? '' : classList[v.class_id][0].name,
code: v.code,
channel: v.channel,
phone: ctx.isEmpty(userList[v.user_uuid]) ? '' : userList[v.user_uuid][0].phone,
order_no: ctx.isEmpty(orderList[v.code]) ? '' : orderList[v.code][0].order_no,
used_time: v.used_time,
created_time: v.created_time,
});
}
const ret = {
list: results,
page_size: limit,
total_count: redeemCodeList.count,
page,
};
return ret;
}
// 生成兑换码
async addRedeemCode(input) {
const { ctx } = this;
......
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