max 7 месяцев назад
Родитель
Сommit
b885126251
1 измененных файлов с 25 добавлено и 26 удалено
  1. 25 26
      src/modules/payment/service/customer.ts

+ 25 - 26
src/modules/payment/service/customer.ts

@@ -40,43 +40,40 @@ export class CustomerService extends BaseService {
         message: '不支持的类型',
       };
     }
+    // 白标用户
     const customer = await this.customerEntity.findOne({
       where: {
         customer_id: data.customer_id,
-        merchantId: data.out_user_id,
       },
     });
+    const isWhiteLabel = customer?.out_user_id.length > 0;
     if (!customer) {
-      // 获取商户的回调
-      await this.request(customer.webhook_url, {
-        biz_status: 'FAIL',
-        biz_type: 'CREATECUSTOMER',
-        data: data
-      })
       return {
         is_success: false,
         message: '客户不存在',
       };
     }
     if (customer.status == 'SUCCESS') {
-      // 获取商户的回调
-      await this.request(customer.webhook_url, {
-        biz_status: 'SUCCESS',
-        biz_type: 'CREATECUSTOMER',
-        data: data
-      })
+      if(isWhiteLabel) {
+        // 获取商户的回调
+        await this.request(customer?.webhook_url, {
+          biz_status: 'SUCCESS',
+          biz_type: 'CREATECUSTOMER',
+          data: data
+        })
+      }
       return {
         is_success: true,
         message: '成功',
       };
     }
+    
     const status = biz_status === 'FAIL' ? -1 : 1;
-    customer.status = biz_status;
+    customer.status = biz_status;    
+    // 平台用户
     const business = await this.businessEntity.findOne({
       where: {
-        merchant: {
-          id: data.out_user_id,
-        },
+        customer_id: data.customer_id,
       },
     });
     if (business) {
@@ -90,9 +87,7 @@ export class CustomerService extends BaseService {
     } else {
       const individual = await this.individualEntity.findOne({
         where: {
-          merchant: {
-            id: data.out_user_id,
-          },
+          customer_id: data.customer_id
         },
       });
       if (individual) {
@@ -106,12 +101,16 @@ export class CustomerService extends BaseService {
       }
     }
     await this.customerEntity.save(customer);
-    // 获取商户的回调
-    await this.request(customer.webhook_url, {
-      biz_status: 'SUCCESS',
-      biz_type: 'CREATECUSTOMER',
-      data: data
-    })
+    // 白标用户
+    if(isWhiteLabel) {
+      // 通知商户的回调
+      const whiteRes =  await this.request(customer?.webhook_url, {
+        biz_status: biz_status,
+        biz_type: 'CREATECUSTOMER',
+        data: data
+      })
+      // return whiteRes TODO Max 白标用户的回调是否通知到上游
+    }
     return {
       is_success: true,
       message: '成功',