feat: 初始化 WWJ Cloud 企业级框架项目
- 后端:基于 NestJS 的分层架构设计 - 前端:基于 VbenAdmin + Element Plus 的管理系统 - 支持 SaaS + 独立版双架构模式 - 完整的用户权限管理系统 - 系统设置、文件上传、通知等核心功能 - 多租户支持和插件化扩展架构
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { Body, Controller, Get, Put, UseGuards } from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
import { PaymentSettingsService } from './payment-settings.service';
|
||||
import { UpdatePaymentSettingsDto, type PaymentSettingsVo } from './payment-settings.dto';
|
||||
import { JwtAuthGuard } from '../../auth/guards/jwt-auth.guard';
|
||||
import { Roles } from '../../auth/roles.decorator';
|
||||
import { RolesGuard } from '../../auth/guards/roles.guard';
|
||||
|
||||
@ApiTags('Settings/Payment')
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles('super', 'admin')
|
||||
@Controller('settings/payment')
|
||||
export class PaymentSettingsController {
|
||||
constructor(private readonly service: PaymentSettingsService) {}
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: '获取支付设置' })
|
||||
async get(): Promise<{ code: number; data: PaymentSettingsVo }> {
|
||||
const data = await this.service.getSettings();
|
||||
return { code: 0, data };
|
||||
}
|
||||
|
||||
@Put()
|
||||
@ApiOperation({ summary: '更新支付设置' })
|
||||
async update(
|
||||
@Body() dto: UpdatePaymentSettingsDto,
|
||||
): Promise<{ code: number; data: PaymentSettingsVo }> {
|
||||
const data = await this.service.updateSettings(dto);
|
||||
return { code: 0, data };
|
||||
}
|
||||
}
|
||||
20
wwjcloud/src/common/settings/payment/payment-settings.dto.ts
Normal file
20
wwjcloud/src/common/settings/payment/payment-settings.dto.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { IsBoolean, IsObject, IsOptional } from 'class-validator';
|
||||
|
||||
export class UpdatePaymentSettingsDto {
|
||||
@IsBoolean()
|
||||
enabled!: boolean;
|
||||
|
||||
@IsOptional()
|
||||
@IsObject()
|
||||
alipay?: Record<string, string>;
|
||||
|
||||
@IsOptional()
|
||||
@IsObject()
|
||||
wechatpay?: Record<string, string>;
|
||||
}
|
||||
|
||||
export interface PaymentSettingsVo {
|
||||
enabled: boolean;
|
||||
alipay?: Record<string, string>;
|
||||
wechatpay?: Record<string, string>;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import type { PaymentSettingsVo } from './payment-settings.dto';
|
||||
|
||||
const SETTINGS_DIR = path.resolve(process.cwd(), 'config', 'runtime');
|
||||
const SETTINGS_FILE = path.resolve(SETTINGS_DIR, 'payment.settings.json');
|
||||
|
||||
const DEFAULT_SETTINGS: PaymentSettingsVo = {
|
||||
enabled: false,
|
||||
alipay: {},
|
||||
wechatpay: {},
|
||||
};
|
||||
|
||||
@Injectable()
|
||||
export class PaymentSettingsService {
|
||||
async getSettings(): Promise<PaymentSettingsVo> {
|
||||
try {
|
||||
const buf = await fs.promises.readFile(SETTINGS_FILE, 'utf8');
|
||||
const json = JSON.parse(buf);
|
||||
return { ...DEFAULT_SETTINGS, ...json };
|
||||
} catch {
|
||||
return { ...DEFAULT_SETTINGS };
|
||||
}
|
||||
}
|
||||
|
||||
async updateSettings(patch: Partial<PaymentSettingsVo>): Promise<PaymentSettingsVo> {
|
||||
const current = await this.getSettings();
|
||||
const next: PaymentSettingsVo = { ...current, ...patch };
|
||||
await fs.promises.mkdir(SETTINGS_DIR, { recursive: true });
|
||||
await fs.promises.writeFile(SETTINGS_FILE, JSON.stringify(next, null, 2), 'utf8');
|
||||
return next;
|
||||
}
|
||||
|
||||
static getSettingsPath() {
|
||||
return SETTINGS_FILE;
|
||||
}
|
||||
}
|
||||
11
wwjcloud/src/common/settings/payment/payment.module.ts
Normal file
11
wwjcloud/src/common/settings/payment/payment.module.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { PaymentService } from './payment.service';
|
||||
import { PaymentSettingsService } from './payment-settings.service';
|
||||
import { PaymentSettingsController } from './payment-settings.controller';
|
||||
|
||||
@Module({
|
||||
providers: [PaymentService, PaymentSettingsService],
|
||||
controllers: [PaymentSettingsController],
|
||||
exports: [PaymentService, PaymentSettingsService],
|
||||
})
|
||||
export class PaymentModule {}
|
||||
8
wwjcloud/src/common/settings/payment/payment.service.ts
Normal file
8
wwjcloud/src/common/settings/payment/payment.service.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class PaymentService {
|
||||
async createPayment(orderId: string, amount: number) {
|
||||
return { orderId, amount, status: 'mock' };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user