Explorar o código

change: 优化钱包的创建

max hai 7 meses
pai
achega
5a8f2a20b3

+ 2 - 2
src/modules/payment/entity/business.ts

@@ -76,10 +76,10 @@ export class BusinessEntity extends BaseEntity {
   @Column({ comment: '拒绝原因', nullable: true })
   refused?: string;
 
-  @Column({ comment: '商户编号' })
+  @Column({ comment: '商户编号', nullable: true })
   merchantId!: string;
 
-  @Column({ comment: '用户编号' })
+  @Column({ comment: '用户编号', nullable: true })
   customer_id!: string;
 
   // @OneToOne(() => MerchantEntity, {

+ 2 - 2
src/modules/payment/entity/individual.ts

@@ -52,10 +52,10 @@ export class IndividualEntity extends BaseEntity {
   @Column({ comment: '拒绝原因', nullable: true })
   refused?: string;
 
-  @Column({ comment: '商户编号' })
+  @Column({ comment: '商户编号', nullable: true })
   merchantId!: string;
 
-  @Column({ comment: '用户编号' })
+  @Column({ comment: '用户编号', nullable: true })
   customer_id!: string;
   //
   // @OneToOne(() => MerchantEntity, {

+ 2 - 2
src/modules/payment/entity/merchant.ts

@@ -21,8 +21,8 @@ export class MerchantEntity extends BaseEntity {
   @Column({ comment: '邮箱' })
   email: string;
 
-  @Column({ comment: 'API Secret', default: '' })
-  apiSecret: string;
+  @Column({ comment: 'API Secret', default: '' , nullable: true})
+  apiSecret!: string;
 
   @Column({ comment: '状态 0-禁用 1-启用', default: 1 })
   status: number;

+ 1 - 1
src/modules/payment/entity/wallet.ts

@@ -15,7 +15,7 @@ export class WalletEntity extends BaseEntity {
   channel: string;
   @Column({ comment: '客户ID', length: 100 })
   customerId: string;
-  @Column({ comment: '回调地址'})
+  @Column({ comment: '回调地址', nullable: true})
   webhook_url!: string;
   @Column({ comment: '货币类型', length: 20 })
   currency: string;

+ 2 - 0
src/modules/payment/service/individual.ts

@@ -46,6 +46,8 @@ export class IndividualService extends BaseService {
     if (!params?.registration_date) {
       params.registration_date = this.utils.getNewTime()
     }
+    console.log(49, merchantId);
+    return merchantId
     const custom = {
       ...params,
       out_user_id: merchantId,

+ 12 - 6
src/modules/payment/service/wallet.ts

@@ -33,17 +33,22 @@ export class WalletService extends BaseService {
     // 商户给自己的用户创建钱包
     // 商户给自己创建钱包
 
+    let customer;
+
     if(!param.customer_id) {
       // 查找商户的 customer_id
       // api访问
       // 网页中访问
       const { merchant } = this.ctx.admin;
-      console.log(41, merchant)
+      customer = await this.customerEntity.findOneBy({
+        merchantId: merchant.mchId,
+        out_user_id: null
+      });
+    } else {
+      customer = await this.customerEntity.findOneBy({
+        customer_id: param.customer_id
+      });
     }
-
-    const customer = await this.customerEntity.findOneBy({
-      customer_id: param.customer_id
-    });
     if (!customer) {
       throw new CoolCommException('客户不存在,请先创建认证');
     }
@@ -133,7 +138,8 @@ export class WalletService extends BaseService {
     console.log('getWallet',param)
       // TODO setChannel 需要调整为动态的
     const res = await this.paymentService.setChannel('SUNPAY').getWallet({
-      customer_id: param,
+      // customer_id: param,
+      ...param
     });
     return res;
   }