v3数据表更改
This commit is contained in:
@@ -15,6 +15,7 @@ import { PrismaService } from '../../common/prisma/prisma.module';
|
||||
import { RedisService } from '../../common/redis/redis.service';
|
||||
import { serializeBigInt } from '../../common/decorators/current-user.decorator';
|
||||
import { SettlementService } from '../settlement/settlement.service';
|
||||
import { buildBenefitLedgerEvent } from '../../common/event/event.helpers';
|
||||
|
||||
@Injectable()
|
||||
export class RedeemService {
|
||||
@@ -57,17 +58,6 @@ export class RedeemService {
|
||||
const token = randomBytes(16).toString('hex');
|
||||
const expireAt = new Date(Date.now() + REDEEM_TOKEN_TTL_SECONDS * 1000);
|
||||
|
||||
await this.prisma.redeemToken.create({
|
||||
data: {
|
||||
token,
|
||||
userId,
|
||||
couponId: primaryCouponId,
|
||||
storeId: body.storeId ? BigInt(body.storeId) : null,
|
||||
amount: body.amount,
|
||||
expireAt,
|
||||
},
|
||||
});
|
||||
|
||||
await this.redis.setJson(
|
||||
`redeem:token:${token}`,
|
||||
{
|
||||
@@ -130,7 +120,7 @@ export class RedeemService {
|
||||
}
|
||||
|
||||
const amount = Number(cached.amount);
|
||||
const cityRule = await this.prisma.cityCommissionRule.findFirst({
|
||||
const cityRule = await this.prisma.commonCityCommissionRule.findFirst({
|
||||
where: { city: { stores: { some: { id: account.storeId } } } },
|
||||
});
|
||||
const settlementRate = cityRule ? Number(cityRule.storeSettlementRate) : 0.6;
|
||||
@@ -154,8 +144,8 @@ export class RedeemService {
|
||||
if (updated.count === 0) throw new BadRequestException('核销失败,请重试');
|
||||
|
||||
const newBalance = Number(coupon.balance) - allocAmount;
|
||||
await tx.benefitLedger.create({
|
||||
data: {
|
||||
await tx.commonEvent.create({
|
||||
data: buildBenefitLedgerEvent({
|
||||
userId: coupon.userId,
|
||||
couponId: coupon.id,
|
||||
type: 'REDEEM',
|
||||
@@ -163,7 +153,7 @@ export class RedeemService {
|
||||
balanceAfter: newBalance,
|
||||
refType: 'STORE',
|
||||
refId: account.storeId,
|
||||
},
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -178,11 +168,6 @@ export class RedeemService {
|
||||
},
|
||||
});
|
||||
|
||||
await tx.redeemToken.updateMany({
|
||||
where: { token: body.token },
|
||||
data: { status: 'USED', usedAt: new Date(), storeId: account.storeId },
|
||||
});
|
||||
|
||||
return redeemRecord;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user