wuyi 1 rok pred
rodič
commit
13d08db8a9

+ 4 - 0
src/pay-order/entities/pay-order.entiy.ts

@@ -1,4 +1,5 @@
 import { Column, CreateDateColumn, Entity, PrimaryGeneratedColumn } from 'typeorm'
 import { Column, CreateDateColumn, Entity, PrimaryGeneratedColumn } from 'typeorm'
+import { Exclude } from 'class-transformer'
 
 
 export enum PayOrderStatus {
 export enum PayOrderStatus {
     PENDING = 'pending',
     PENDING = 'pending',
@@ -53,4 +54,7 @@ export class PayOrder {
     @Column({ nullable: true })
     @Column({ nullable: true })
     hash: string
     hash: string
 
 
+    @Exclude()
+    rechargeBalance: number
+
 }
 }

+ 8 - 1
src/pay-order/pay-order.controller.ts

@@ -6,6 +6,8 @@ import { In } from 'typeorm'
 import { UsersService } from '../users/users.service'
 import { UsersService } from '../users/users.service'
 import { OperationLogService } from '../operation-log/operation-log.service'
 import { OperationLogService } from '../operation-log/operation-log.service'
 import { OperationType } from '../operation-log/entities/operation-log.entity'
 import { OperationType } from '../operation-log/entities/operation-log.entity'
+import { SysConfigService } from '../sys-config/sys-config.service'
+import Decimal from 'decimal.js'
 
 
 @Controller('payOrder')
 @Controller('payOrder')
 export class PayOrderController {
 export class PayOrderController {
@@ -13,7 +15,8 @@ export class PayOrderController {
     constructor(
     constructor(
         private readonly payOrderService: PayOrderService,
         private readonly payOrderService: PayOrderService,
         private readonly userService: UsersService,
         private readonly userService: UsersService,
-        private readonly operationLogService: OperationLogService
+        private readonly operationLogService: OperationLogService,
+        private readonly sysConfigService: SysConfigService
     ) {
     ) {
     }
     }
 
 
@@ -39,6 +42,10 @@ export class PayOrderController {
             order.userName = req.user.username
             order.userName = req.user.username
             const payOrder = await this.payOrderService.create(order)
             const payOrder = await this.payOrderService.create(order)
             await this.operationLogService.create(req, payOrder, 'PayOrder', OperationType.INSERT, '创建充值订单')
             await this.operationLogService.create(req, payOrder, 'PayOrder', OperationType.INSERT, '创建充值订单')
+            const rechargeRatio = await this.sysConfigService.getString('recharge_ratio', '')
+            const ratio = new Decimal(rechargeRatio)
+            const balanceDecimal = new Decimal(payOrder.amount).mul(ratio)
+            payOrder.rechargeBalance = balanceDecimal.toNumber()
             return payOrder
             return payOrder
         } catch (e) {
         } catch (e) {
             console.log(e.message)
             console.log(e.message)