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

fix redeemCode

parent a72c4a07
Pipeline #24692 passed with stage
in 6 seconds
...@@ -123,13 +123,13 @@ class UserController extends Controller { ...@@ -123,13 +123,13 @@ class UserController extends Controller {
// 兑换课程 // 兑换课程
async redeemClass() { async redeemClass() {
const { ctx, service } = this; const { ctx, service } = this;
const params = ctx.params; const params = ctx.request.body;
if (ctx.isEmpty(params) || ctx.isEmpty(params.redeem_code)) { if (ctx.isEmpty(params) || ctx.isEmpty(params.code)) {
ctx.failed('redeem_code is failed'); ctx.failed('code is failed');
} }
const ret = await service.course.v5.user.redeemClass(params.redeem_code); const ret = await service.course.v5.user.redeemClass(params);
ctx.success(ret); ctx.success(ret);
} }
} }
......
...@@ -18,6 +18,14 @@ module.exports = app => { ...@@ -18,6 +18,14 @@ module.exports = app => {
is_used: INTEGER, is_used: INTEGER,
status: INTEGER, status: INTEGER,
is_deleted: INTEGER, is_deleted: INTEGER,
used_time: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('used_time');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
created_time: { created_time: {
type: DATE, type: DATE,
allowNull: true, allowNull: true,
......
...@@ -15,7 +15,7 @@ module.exports = app => { ...@@ -15,7 +15,7 @@ module.exports = app => {
router.post('third', '/user/address', auth({ is_force: 1 }), 'course.v5.user.addUserAddress');// 新增用户收货地址 router.post('third', '/user/address', auth({ is_force: 1 }), 'course.v5.user.addUserAddress');// 新增用户收货地址
router.get('third', '/user/address', auth({ is_force: 1 }), 'course.v5.user.getUserAddress');// 获取用户收货地址 router.get('third', '/user/address', auth({ is_force: 1 }), 'course.v5.user.getUserAddress');// 获取用户收货地址
router.get('third', '/user/order/all', auth({ is_force: 1 }), 'course.v5.user.getUserOrderList');// 获取订单列表 router.get('third', '/user/order/all', auth({ is_force: 1 }), 'course.v5.user.getUserOrderList');// 获取订单列表
router.post('third', '/user/redeem/class/:redeem_code', auth({ is_force: 1 }), 'course.v5.user.redeemClass');// 兑换课程 router.post('third', '/user/redeem/class', auth({ is_force: 1 }), 'course.v5.user.redeemClass');// 兑换课程
router.get('third', '/category/all', auth({ is_force: 0 }), 'course.v5.option.getCategoryList');// 获取分类列表 router.get('third', '/category/all', auth({ is_force: 0 }), 'course.v5.option.getCategoryList');// 获取分类列表
router.get('third', '/banner/all', 'course.v5.option.getBannerList');// 获取banner列表 router.get('third', '/banner/all', 'course.v5.option.getBannerList');// 获取banner列表
......
...@@ -65,6 +65,26 @@ class BackService extends Service { ...@@ -65,6 +65,26 @@ class BackService extends Service {
return { list: results }; return { list: results };
} }
// 订单列表
async getOrderList(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: { status: 1, is_deleted: 0 }, limit, offset, attributes: [ 'id', 'order_no', 'class_id', 'pay', 'pay_time', 'type', 'redeem', 'address' ] };
if (userInfo.is_admin === 0) {
const classList = await ctx.classModel.V5.CourseClass.findAll({ where: { institution_id: { $in: userInfo.institution_id } }, attributes: [ 'id' ] });
}
}
} }
module.exports = BackService; module.exports = BackService;
...@@ -459,9 +459,11 @@ class UserService extends Service { ...@@ -459,9 +459,11 @@ class UserService extends Service {
// 兑换课程 // 兑换课程
async redeemClass(redeemCode) { async redeemClass(input) {
const { ctx } = this; const { ctx } = this;
const userUuid = ctx.userUuid; const userUuid = ctx.userUuid;
const redeemCode = input.code;
const classId = Number(input.class_id) || 0;
if (ctx.isEmpty(userUuid)) { if (ctx.isEmpty(userUuid)) {
ctx.failed('用户异常'); ctx.failed('用户异常');
} }
...@@ -483,6 +485,21 @@ class UserService extends Service { ...@@ -483,6 +485,21 @@ class UserService extends Service {
ctx.failed('地址不能为空'); ctx.failed('地址不能为空');
} }
const classInfo = await ctx.classModel.V5.CourseV5Class.findOne({ where: { id: codeInfo.class_id, status: 1, is_deleted: 0 }, attributes: [ 'id', 'institution_id', 'name', 'button_url' ] });
if (ctx.isEmpty(classInfo)) {
ctx.failed('课程不存在');
}
// 判断是否是同一个课程
if (classId > 0 && classId !== codeInfo.class_id) {
const institution = await ctx.classModel.V5.CourseV5Institution.findOne({ where: { id: classInfo.institution_id } });
return {
class_id: codeInfo.class_id,
result: false,
text: `您输入的兑换码只可兑换【${institution.name}】的【${classInfo.name}】 是否需要兑换`,
};
}
// 订单处理 // 订单处理
const orderInfo = await ctx.classModel.V5.CourseUserOrder.findOne({ where: { user_uuid: userUuid, class_id: codeInfo.class_id, is_deleted: 0 } }); const orderInfo = await ctx.classModel.V5.CourseUserOrder.findOne({ where: { user_uuid: userUuid, class_id: codeInfo.class_id, is_deleted: 0 } });
if (ctx.isEmpty(orderInfo)) { if (ctx.isEmpty(orderInfo)) {
...@@ -496,9 +513,9 @@ class UserService extends Service { ...@@ -496,9 +513,9 @@ class UserService extends Service {
} }
} }
await ctx.classModel.V5.CourseRedeemCode.update({ user_uuid: userUuid, is_used: 1 }, { where: { id: codeInfo.id } }); await ctx.classModel.V5.CourseRedeemCode.update({ user_uuid: userUuid, is_used: 1, used_time: moment().format('YYYY-MM-DD HH:mm:ss') }, { where: { id: codeInfo.id } });
return { class_id: codeInfo.class_id }; return { class_id: codeInfo.class_id, result: true, url: classInfo.button_url };
} }
} }
......
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