feat: dev
This commit is contained in:
@@ -54,7 +54,7 @@ export class Order {
|
||||
couponDiscount: number;
|
||||
|
||||
@Column({ name: 'user_coupon_id', type: 'bigint', unsigned: true, nullable: true, comment: '使用的用户优惠券ID' })
|
||||
userCouponId: number;
|
||||
userCouponId: number | null;
|
||||
|
||||
@Column({ name: 'total_amount', type: 'decimal', precision: 10, scale: 2, unsigned: true, comment: '订单总金额' })
|
||||
totalAmount: number;
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// 统一导出所有财务相关 DTO
|
||||
export * from './withdrawal.dto';
|
||||
export * from './transaction.dto';
|
||||
export * from './account.dto';
|
||||
export * from './settlement.dto';
|
||||
export * from './reconciliation.dto';
|
||||
export * from './report.dto';
|
||||
@@ -5,11 +5,11 @@ import { ConfigService } from '@nestjs/config';
|
||||
import { Order } from '@/entities/order.entity';
|
||||
import { PlatformAccount } from '@/entities/platform-account.entity';
|
||||
import { PlatformTransaction } from '@/entities/platform-transaction.entity';
|
||||
import { Wechatpay } from 'wechatpay-node-v3';
|
||||
import Wechatpay = require('wechatpay-node-v3');
|
||||
|
||||
@Injectable()
|
||||
export class RefundService {
|
||||
private wechatpayClient: Wechatpay;
|
||||
private wechatpayClient: Wechatpay | null;
|
||||
|
||||
constructor(
|
||||
@InjectRepository(Order)
|
||||
@@ -45,9 +45,10 @@ export class RefundService {
|
||||
this.wechatpayClient = new Wechatpay({
|
||||
appid,
|
||||
mchid,
|
||||
publicKey: Buffer.from(privateKey, 'utf-8'),
|
||||
privateKey: Buffer.from(privateKey, 'utf-8'),
|
||||
serialNo,
|
||||
apiv3Key,
|
||||
serial_no: serialNo,
|
||||
key: apiv3Key,
|
||||
});
|
||||
console.log('[微信支付] 客户端初始化成功');
|
||||
} catch (error) {
|
||||
@@ -153,7 +154,7 @@ export class RefundService {
|
||||
const totalAmount = Math.round(order.payAmount * 100);
|
||||
|
||||
// 调用微信支付退款API
|
||||
const result = await this.wechatpayClient.refunds({
|
||||
const result: any = await this.wechatpayClient.refunds({
|
||||
transaction_id: order.transactionId,
|
||||
out_refund_no: refundNo,
|
||||
reason: '用户申请退款',
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
} from '@nestjs/common';
|
||||
import { GuestService } from './guest.service';
|
||||
import { CreateGuestDto, UpdateGuestDto } from './dto/guest.dto';
|
||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||
import { JwtAuthGuard } from '@/common/guards/jwt-auth.guard';
|
||||
|
||||
@Controller('user/guests')
|
||||
@UseGuards(JwtAuthGuard)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Controller, Get, Query, UseGuards } from '@nestjs/common';
|
||||
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
|
||||
import { JwtAuthGuard } from '@/modules/auth/jwt-auth.guard';
|
||||
import { RolesGuard } from '@/modules/auth/roles.guard';
|
||||
import { Roles } from '@/modules/auth/roles.decorator';
|
||||
import { CurrentUser } from '@/modules/auth/current-user.decorator';
|
||||
import { JwtAuthGuard } from '@/common/guards/jwt-auth.guard';
|
||||
import { RolesGuard } from '@/common/guards/roles.guard';
|
||||
import { Roles } from '@/common/decorators/roles.decorator';
|
||||
import { CurrentUser } from '@/common/decorators/current-user.decorator';
|
||||
import { StatisticsService } from './statistics.service';
|
||||
|
||||
@ApiTags('商家统计')
|
||||
|
||||
@@ -63,7 +63,7 @@ export class StatisticsService {
|
||||
month: monthData,
|
||||
roomCount,
|
||||
balance: account?.balance || 0,
|
||||
availableBalance: account?.availableBalance || 0,
|
||||
availableBalance: account ? Number(account.balance) - Number(account.frozenBalance) : 0,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ export class OrderService {
|
||||
|
||||
// 处理优惠券
|
||||
let couponDiscount = 0;
|
||||
let userCouponId = null;
|
||||
let userCouponId: number | null = null;
|
||||
|
||||
if (dto.couponId) {
|
||||
// 查询用户可用优惠券
|
||||
@@ -138,7 +138,7 @@ export class OrderService {
|
||||
serviceFee,
|
||||
merchantIncome,
|
||||
couponDiscount,
|
||||
userCouponId,
|
||||
userCouponId: userCouponId !== null ? userCouponId : undefined,
|
||||
totalAmount,
|
||||
payAmount,
|
||||
contactName: dto.contactName,
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { Cron } from '@nestjs/schedule';
|
||||
import { SettlementService } from '@/modules/finance/settlement.service';
|
||||
|
||||
@Injectable()
|
||||
export class SettlementSchedule {
|
||||
private readonly logger = new Logger(SettlementSchedule.name);
|
||||
|
||||
constructor(
|
||||
private readonly settlementService: SettlementService,
|
||||
) {}
|
||||
|
||||
// 每天凌晨2点执行自动结算
|
||||
@Cron('0 2 * * *')
|
||||
async autoSettle() {
|
||||
try {
|
||||
this.logger.log('开始执行自动结算任务');
|
||||
// 调用 SettlementService 的周结算方法
|
||||
await this.settlementService.handleWeeklySettlement();
|
||||
this.logger.log('自动结算任务执行完成');
|
||||
} catch (error) {
|
||||
this.logger.error('自动结算任务执行失败', error.stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user