用于的优惠券增加过期时间
This commit is contained in:
parent
3484c58254
commit
72492f8403
@ -59,7 +59,7 @@ class CouponController extends BaseController {
|
|||||||
const record = await UserCoupon.findOne({ sid: id, accountId: sender })
|
const record = await UserCoupon.findOne({ sid: id, accountId: sender })
|
||||||
const recordNew = record.copy()
|
const recordNew = record.copy()
|
||||||
recordNew.accountId = accountId
|
recordNew.accountId = accountId
|
||||||
recordNew.source = 'share'
|
recordNew.source = 'receive'
|
||||||
recordNew.activityId = record.id
|
recordNew.activityId = record.id
|
||||||
await recordNew.save()
|
await recordNew.save()
|
||||||
const shop = await Shop.fetchByID(record.shop)
|
const shop = await Shop.fetchByID(record.shop)
|
||||||
|
@ -52,6 +52,8 @@ class UserCouponClass extends BaseModule {
|
|||||||
public count: number
|
public count: number
|
||||||
/**
|
/**
|
||||||
* 来源
|
* 来源
|
||||||
|
* receive: 领取别人分享的
|
||||||
|
* share: 分享成就
|
||||||
*/
|
*/
|
||||||
@prop()
|
@prop()
|
||||||
public source: string
|
public source: string
|
||||||
@ -78,6 +80,11 @@ class UserCouponClass extends BaseModule {
|
|||||||
*/
|
*/
|
||||||
@prop()
|
@prop()
|
||||||
public status: number
|
public status: number
|
||||||
|
/**
|
||||||
|
* 过期时间
|
||||||
|
*/
|
||||||
|
@prop({ default: 0 })
|
||||||
|
public expire: number
|
||||||
|
|
||||||
public static async fetchCount({ accountId, shop, item }: { accountId: string; shop: string; item: string }) {
|
public static async fetchCount({ accountId, shop, item }: { accountId: string; shop: string; item: string }) {
|
||||||
let record = await UserCoupon.findOne({ accountId, shop, item })
|
let record = await UserCoupon.findOne({ accountId, shop, item })
|
||||||
@ -89,6 +96,7 @@ class UserCouponClass extends BaseModule {
|
|||||||
record.shop = this.shop
|
record.shop = this.shop
|
||||||
record.item = this.item
|
record.item = this.item
|
||||||
record.count = this.count
|
record.count = this.count
|
||||||
|
record.expire = this.expire || 0
|
||||||
record.status = 0
|
record.status = 0
|
||||||
return record
|
return record
|
||||||
}
|
}
|
||||||
@ -104,6 +112,7 @@ class UserCouponClass extends BaseModule {
|
|||||||
source,
|
source,
|
||||||
activityId,
|
activityId,
|
||||||
rewardId,
|
rewardId,
|
||||||
|
expire,
|
||||||
}: {
|
}: {
|
||||||
accountId: string
|
accountId: string
|
||||||
shop: string
|
shop: string
|
||||||
@ -112,6 +121,7 @@ class UserCouponClass extends BaseModule {
|
|||||||
source: string
|
source: string
|
||||||
activityId: string
|
activityId: string
|
||||||
rewardId: string
|
rewardId: string
|
||||||
|
expire: number
|
||||||
}) {
|
}) {
|
||||||
for (let i = 0; i < count; i++) {
|
for (let i = 0; i < count; i++) {
|
||||||
let record = new UserCoupon({})
|
let record = new UserCoupon({})
|
||||||
@ -123,6 +133,7 @@ class UserCouponClass extends BaseModule {
|
|||||||
record.source = source
|
record.source = source
|
||||||
record.rewardId = rewardId
|
record.rewardId = rewardId
|
||||||
record.status = 0
|
record.status = 0
|
||||||
|
record.expire = expire
|
||||||
await record.save()
|
await record.save()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,11 @@ class UserRewardClass extends BaseModule {
|
|||||||
await saveRecord(0, count)
|
await saveRecord(0, count)
|
||||||
let cdata = await Coupon.findById(itemId)
|
let cdata = await Coupon.findById(itemId)
|
||||||
name = cdata.name
|
name = cdata.name
|
||||||
await UserCoupon.addOne({ accountId, shop, item: itemId, count, source, activityId, rewardId })
|
let expire = 0
|
||||||
|
if (cdata.validDays) {
|
||||||
|
expire = Date.now() + cdata.validDays * 24 * 60 * 60 * 1000
|
||||||
|
}
|
||||||
|
await UserCoupon.addOne({ accountId, shop, item: itemId, count, source, activityId, rewardId, expire })
|
||||||
await Coupon.updateCount(itemId, count)
|
await Coupon.updateCount(itemId, count)
|
||||||
url = getCouponUrl(shop, itemId)
|
url = getCouponUrl(shop, itemId)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user