瀏覽代碼

feat: 费率模块 3-10

max 4 月之前
父節點
當前提交
610fbc0618

+ 4 - 3
src/config/config.max.ts

@@ -10,9 +10,10 @@ export default {
     dataSource: {
       default: {
         type: 'mysql',
-        host: '124.221.51.4',
-        port: 6806,
-        username: 'root',
+        // host: '124.221.51.4',
+        host: '192.168.2.105',
+        port: 3306,
+        username: 'va_sandBox',
         password: 'asAf12u7YuszdHgfdVneq!',
         // host: '127.0.0.1',
         // port: 3390,

+ 41 - 0
src/modules/api/controller/admin/open_profit.ts

@@ -0,0 +1,41 @@
+import { CoolController, BaseController } from '@cool-midway/core';
+import {
+  ALL,
+  Body,
+  Get,
+  Inject,
+  Param,
+  Post,
+  Provide,
+  Query,
+} from '@midwayjs/decorator';
+import { Context } from '@midwayjs/koa';
+import {OpenPayeeService} from "../../service/admin/OpenPayee";
+import {OpenProfitEntity} from "../../entity/open_profit";
+import {openProfitService} from "../../service/admin/OpenProfit";
+
+/**
+ * 收款人
+ */
+@Provide()
+@CoolController({
+  api: ['add', 'delete', 'update', 'info', 'page', 'list'],
+  entity: OpenProfitEntity,
+  service: openProfitService,
+  pageQueryOp: {
+    where: async (ctx: Context) => {
+      const { merchant, roleIds } = ctx.admin;
+      if (roleIds.includes(1) || roleIds.includes(3)) {
+        return [['mch_id=:mch_id', { mch_id: merchant.mch_id }]];
+      }
+      return [];
+    },
+  },
+})
+export class openProfitController extends BaseController {
+  @Inject()
+  openProfitService: openProfitService;
+
+  @Inject()
+  ctx: Context;
+}

+ 26 - 0
src/modules/api/controller/admin/withdrawChannel.ts

@@ -0,0 +1,26 @@
+import { Provide, Post, Inject, Body, ALL } from '@midwayjs/decorator';
+import { CoolController, BaseController } from '@cool-midway/core';
+import { WithdrawChannelEntity } from '../../entity/withdrawChannel';
+import {WithdrawChannelService} from "../../service/admin/withdrawChannel";
+
+@Provide()
+@CoolController({
+  api: ['add', 'delete', 'update', 'list', 'info', 'page'],
+  entity: WithdrawChannelEntity,
+  service: WithdrawChannelService,
+  pageQueryOp: {
+    keyWordLikeFields: ['name', 'code', 'currency'],
+  },
+})
+export class WithdrawChannelController extends BaseController {
+  @Inject()
+  withdrawChannelService: WithdrawChannelService;
+
+  // @Inject()
+  // dispatchService: DispatchService;
+  //
+  // @Post('/queryChannelBalance', { summary: '获取通道余额' })
+  // async queryChannelBalance(@Body(ALL) payload: any) {
+  //   return this.ok(await this.dispatchService.queryBalance(payload.code));
+  // }
+}

+ 38 - 0
src/modules/api/entity/open_profit.ts

@@ -0,0 +1,38 @@
+import { Column, Entity } from 'typeorm';
+import { BaseEntity } from '@cool-midway/core';
+
+export enum StatusType {
+  SUBMITTED = 'SUBMITTED', // 已提交
+  ACTIVE = 'ACTIVE', // 激活
+  FAILED = 'FAILED', // 失败
+  SUSPENDED = 'SUSPENDED', // 冻结
+  TERMINATED = 'TERMINATED', // 关闭
+}
+
+export const OrderTypeEnum = {
+  PAYMENT: '付款',
+  TRANSFER: '转账',
+  DEPOSIT: '入账',
+  EXCHANGE: '换汇',
+};
+
+/**
+ * 费率
+ */
+@Entity('open_profit')
+export class OpenProfitEntity extends BaseEntity {
+  @Column({ length: 255, comment: '商户编号', default: '' })
+  mch_id: string;
+
+  @Column({ length: 255, comment: '用户编号', default: '' })
+  account_id?: string;
+
+  @Column({ length: 100, comment: '订单类型', default: '' })
+  order_type?: string; // 使用枚举类型
+
+  @Column({ comment: '费率', default: 0 })
+  profit: number;
+
+  @Column({ length: 255, comment: '客户来源', default: '' })
+  source?: string;
+}

+ 45 - 0
src/modules/api/entity/withdrawChannel.ts

@@ -0,0 +1,45 @@
+import { BaseEntity } from '@cool-midway/core';
+import { Column, Entity, Index } from 'typeorm';
+
+/**
+ * 字典信息
+ */
+@Entity('open_withdraw_channel')
+export class WithdrawChannelEntity extends BaseEntity {
+  @Column({ comment: '通道名' })
+  name: string;
+
+  @Index({ unique: true })
+  @Column({ comment: '通道编码' })
+  code: string;
+
+  @Column({ comment: '代码服务' })
+  service: string;
+
+  @Column({ comment: '货币' })
+  currency: string;
+
+  @Column({ comment: '费率' })
+  rate: string;
+
+  @Column({ length: 100, comment: '订单类型', default: '' })
+  order_type?: string; // 使用枚举类型
+
+  @Column({ comment: '单笔固定费用', type: 'decimal', precision: 10, scale: 2 })
+  basicFee: string;
+
+  @Column({ comment: '单笔最低费用', type: 'decimal', precision: 10, scale: 2 })
+  feeMin: number;
+
+  @Column({ comment: '单笔最大', type: 'decimal', precision: 10, scale: 2 })
+  max: number;
+
+  @Column({ comment: '单笔最小', type: 'decimal', precision: 10, scale: 2 })
+  min: number;
+
+  @Column({ comment: '状态 0-未启用 1 启用', type: 'tinyint', default: 1 })
+  status: number;
+
+  @Column({ comment: '备注', nullable: true })
+  remark: string;
+}

+ 41 - 0
src/modules/api/service/admin/OpenProfit.ts

@@ -0,0 +1,41 @@
+import {BaseService} from '@cool-midway/core';
+import {ILogger, Provide} from '@midwayjs/core';
+import {Inject} from '@midwayjs/decorator';
+import {InjectEntityModel} from '@midwayjs/typeorm';
+import {Repository} from 'typeorm';
+import {CustomerEntity} from '../../../payment/entity/customer';
+import {PaymentService} from '../../../payment/service/payment';
+import {SunPayAdapter} from '../../../payment/adapter/sunpay.adapter';
+import {OpenPaymentAccountEntity} from '../../entity/open_payment_account';
+import {OpenAccountEntity} from "../../entity/open_account";
+import {OpenProfitEntity} from "../../entity/open_profit";
+
+/**
+ * 描述
+ */
+@Provide()
+export class openProfitService extends BaseService {
+  @InjectEntityModel(OpenProfitEntity)
+  openProfitEntity: Repository<OpenProfitEntity>;
+  @InjectEntityModel(CustomerEntity)
+  customerEntity: Repository<CustomerEntity>;
+  @Inject()
+  paymentService: PaymentService;
+
+  @Inject()
+  sunPayAdapter: SunPayAdapter;
+
+  @Inject()
+  ctx;
+
+  @Inject()
+  logger: ILogger;
+
+  @InjectEntityModel(OpenPaymentAccountEntity)
+  openPaymentAccountEntity: Repository<OpenPaymentAccountEntity>;
+
+
+  @InjectEntityModel(OpenAccountEntity)
+  openAccountEntity: Repository<OpenAccountEntity>;
+
+}

+ 35 - 0
src/modules/api/service/admin/withdrawChannel.ts

@@ -0,0 +1,35 @@
+import { Provide } from '@midwayjs/decorator';
+import { BaseService } from '@cool-midway/core';
+import { InjectEntityModel } from '@midwayjs/typeorm';
+import { Repository } from 'typeorm';
+import * as _ from 'lodash';
+import {WithdrawChannelEntity} from "../../entity/withdrawChannel";
+
+@Provide()
+export class WithdrawChannelService extends BaseService {
+  @InjectEntityModel(WithdrawChannelEntity)
+  withdrawChannelEntity: Repository<WithdrawChannelEntity>;
+
+  async queryByCurrency(currency) {
+    return await this.withdrawChannelEntity.findBy({
+      status: 1,
+      currency,
+    });
+  }
+
+  async queryByCode(code) {
+    return await this.withdrawChannelEntity.findOneBy({
+      status: 1,
+      code,
+    });
+  }
+
+  async getWithdrawChannelList() {
+    return await this.withdrawChannelEntity.find({
+      where: {
+        status: 1
+      },
+      select: ['name', 'code', 'currency']
+    })
+  }
+}

+ 47 - 32
src/modules/api/service/webhook.ts

@@ -8,6 +8,10 @@ import { CustomerEntity } from '../../payment/entity/customer';
 import { PaymentService } from '../../payment/service/payment';
 import { PayeeEntity } from '../../payment/entity/payee';
 import { SunPayAdapter } from '../../payment/adapter/sunpay.adapter';
+import {
+  OpenPaymentOrderEntity,
+  OrderType,
+} from '../entity/open_payment_order';
 
 /**
  * 描述
@@ -16,8 +20,13 @@ import { SunPayAdapter } from '../../payment/adapter/sunpay.adapter';
 export class OpenApiWebhookService extends BaseService {
   @InjectEntityModel(PayeeEntity)
   payeeEntity: Repository<PayeeEntity>;
+
   @InjectEntityModel(CustomerEntity)
   customerEntity: Repository<CustomerEntity>;
+
+  @InjectEntityModel(OpenPaymentOrderEntity)
+  openPaymentOrderEntity: Repository<OpenPaymentOrderEntity>;
+
   @Inject()
   paymentService: PaymentService;
 
@@ -58,44 +67,17 @@ export class OpenApiWebhookService extends BaseService {
       // 付款失败       payment_failed
       // 付款银行退回    payment_refunded
       // 转账失败        transfer_failed
-      
+
       //  const {type} = params
       switch (params.type) {
         case 'deposit_success':
           // 入账成功       deposit_success
-          // 如果入账成功,则收取手续费
-          /* 
-          {
-            "type": "deposit_success",
-            "data": {
-                "id": "29091e03092c42a681f0921118925e84",
-                "bank_account_id": "262874c798b1452682acd96fb0317bae",
-                "order_no": "20250310155503589841",
-                "account_id": "2bd64372841a54bf8b41f879ff07884b",
-                "bic_number": null,
-                "account_number": "79765000155",
-                "inward_amount": 1000,
-                "fee": 0,
-                "amount": 1000,
-                "currency": "GBP",
-                "payer": "付款信息 格式:{sender.name};{sender.address};{sender.country};{sender.account_number} or {sender.iban};{sender.bic};{sender.routing_code};附言",
-                "comment": "附言",
-                "payment_type": "SWIFT",
-                "order_type": "DEPOSIT",
-                "payment_id": null,
-                "clearing_system": null,
-                "status": "SUCCESS",
-                "create_time": "2025-03-10T15:55:04+08:00",
-                "update_time": "2025-03-10T15:55:04+08:00",
-                "completed_time": "2025-03-10T15:55:03+08:00"
-            }
-          }
-          */
+          return this.deposit_success(params)
           break;
         case 'exchange_success':
           // 换汇成功       exchange_success
           // 如果换汇成功,则收取手续费
-          /* 
+          /*
           params
           {
             "type": "exchange_success",
@@ -128,7 +110,7 @@ export class OpenApiWebhookService extends BaseService {
         case 'payment_success':
           // 付款成功       payment_success
           // 如果付款成功,则收取手续费
-          /* 
+          /*
           params
           {
             "type": "string",
@@ -163,7 +145,7 @@ export class OpenApiWebhookService extends BaseService {
         case 'transfer_success':
           // 转账成功       transfer_success
           // 如果付款成功,则收取手续费
-          /* 
+          /*
           params
           {
             "type": "string",
@@ -205,4 +187,37 @@ export class OpenApiWebhookService extends BaseService {
       }, settime);
     });
   }
+  //
+  deposit_success(params) {
+    // 如果入账成功,则收取手续费
+    /*
+    {
+      "type": "deposit_success",
+      "data": {
+          "id": "29091e03092c42a681f0921118925e84",
+          "bank_account_id": "262874c798b1452682acd96fb0317bae",
+          "order_no": "20250310155503589841",
+          "account_id": "2bd64372841a54bf8b41f879ff07884b",
+          "bic_number": null,
+          "account_number": "79765000155",
+          "inward_amount": 1000,
+          "fee": 0,
+          "amount": 1000,
+          "currency": "GBP",
+          "payer": "付款信息 格式:{sender.name};{sender.address};{sender.country};{sender.account_number} or {sender.iban};{sender.bic};{sender.routing_code};附言",
+          "comment": "附言",
+          "payment_type": "SWIFT",
+          "order_type": "DEPOSIT",
+          "payment_id": null,
+          "clearing_system": null,
+          "status": "SUCCESS",
+          "create_time": "2025-03-10T15:55:04+08:00",
+          "update_time": "2025-03-10T15:55:04+08:00",
+          "completed_time": "2025-03-10T15:55:03+08:00"
+      }
+    }
+    */
+
+
+  }
 }