diff --git a/doc/api.md b/doc/api.md index 828f60e..a08e9fb 100644 --- a/doc/api.md +++ b/doc/api.md @@ -31,6 +31,7 @@ 1. 增加[开始分享优惠券](#223), [领取分享的优惠券](#224) 接口 2. [用户券列表](#211), [抽奖](#214), [邀请奖励信息](#215), [领取邮件附件](#217)等接口返回的优惠券信息, 增加expire字段 +3. [获取店铺信息](#208) 的gamecfg增加返回 default_desc_txt, 用于首页介绍文字 @@ -387,7 +388,8 @@ "game_single_btn": "主页上单人赛按钮文字", "game_multi_btn": "主页上多人赛按钮名字", "default_share_pic":"默认分享图", - "default_share_txt": "默认分享语" + "default_share_txt": "默认分享语", + "default_desc_txt": "配置的介绍文字" } } ``` diff --git a/src/api/controllers/coupon.controller.ts b/src/api/controllers/coupon.controller.ts index bbe6d2b..e875efb 100644 --- a/src/api/controllers/coupon.controller.ts +++ b/src/api/controllers/coupon.controller.ts @@ -14,7 +14,33 @@ class CouponController extends BaseController { @role('anon') @router('get /pub/coupon/:shop/:id') async info(req: any) { - return {} + const { id, shop } = req.params + if (!id || !shop) { + throw new ZError(10, '缺少必要参数') + } + const record = await UserCoupon.findOne({ sid: id, shop }) + if (!record) { + throw new ZError(11, 'no matched records') + } + if (record.expire) { + // 如果有过期时间设置, 且已经过期, 则将未使用和已分享但未被领取的记录更新为已过期 + if (Date.now() >= record.expire && (record.status === 0 || record.status === 2)) { + record.status = 9 + await record.save() + } + } + const shopData = await Shop.fetchByID(record.shop) + const coupon = await Coupon.findById(record.item) + return { + id: record.sid, + shop: record.shop, + shopName: shopData.showName, + coupon: record.item, + couponName: coupon.name, + couponUrl: getCouponUrl(shopData.id, record.item), + status: record.status, + expire: record.expire, + } } /** * 核销 @@ -22,6 +48,26 @@ class CouponController extends BaseController { @role('anon') @router('post /pub/coupon/:shop/:id') async use(req: any) { + const { id, shop } = req.params + if (!id || !shop) { + throw new ZError(10, '缺少必要参数') + } + const record = await UserCoupon.findOne({ sid: id, shop }) + if (!record) { + throw new ZError(11, 'no matched records') + } + if (record.expire) { + // 如果有过期时间设置, 且已经过期, 则将未使用和已分享但未被领取的记录更新为已过期 + if (Date.now() >= record.expire && (record.status === 0 || record.status === 2)) { + record.status = 9 + await record.save() + } + } + if (record.status !== 0) { + throw new ZError(12, 'record status not matched') + } + record.status = 1 + await record.save() return {} } /** diff --git a/src/models/shop/ShopGameExt.ts b/src/models/shop/ShopGameExt.ts index 9548d1d..d429c29 100644 --- a/src/models/shop/ShopGameExt.ts +++ b/src/models/shop/ShopGameExt.ts @@ -29,6 +29,7 @@ export class ShopGameExtClass extends BaseModule { * game_multi_btn: 主页上多人赛按钮名字 * default_share_pic: 默认的分享图 * default_share_txt: 默认的分享语 + * default_desc_txt: 默认的介绍文字 */ @prop({ type: mongoose.Schema.Types.Mixed }) public cfg: {} diff --git a/src/models/user/UserCoupon.ts b/src/models/user/UserCoupon.ts index 1b81a31..9fb0bde 100644 --- a/src/models/user/UserCoupon.ts +++ b/src/models/user/UserCoupon.ts @@ -157,7 +157,7 @@ class UserCouponClass extends BaseModule { let sid = record.shop if (record.expire) { // 如果有过期时间设置, 且已经过期, 则将未使用和已分享但未被领取的记录更新为已过期 - if (Date.now() >= record.expire && (record.status === 0 || record.status === 2) ) { + if (Date.now() >= record.expire && (record.status === 0 || record.status === 2)) { record.status = 9 await record.save() }