Prechádzať zdrojové kódy

feat: 转账手续费 3-13

max 4 mesiacov pred
rodič
commit
ec959f713f

+ 37 - 42
src/modules/api/service/webhook_utils/deposit_success.ts

@@ -122,48 +122,43 @@ export class DepositSuccessService extends BaseService {
       // 通知上游之后,间隔10秒执行利润截取操作
       Promise.resolve().then(async () => {
         await this.webHookCommonService.waitByTime(10000);
-        let accountInfo = null;
-        // 获取回调用户的详情
-        let withdrawChannelFee = null;
-        if (accountInfo && withdrawChannelFee) {
-          // 收取手续费: 转账
-          // /v1/transfers
-          const transfers_params = {
-            // ...openOrderObj,
-            request_id: md5(`${accountInfo.mch_id}_${params.data.id}`),
-            from_account_id: params.data.account_id,
-            to_account_id: this.easyPayAdapter.baseInfo.account_id,
-            currency: params.data.currency,
-            amount: withdrawChannelFee * 100,
-            purpose: '收取手续费用',
-          };
-          this.logger.info(
-            `记录入账流水的费率, ${JSON.stringify(transfers_params)}`
-          );
-          // 截取流水的转账
-          const res = await this.easyPayAdapter.request(
-            'POST',
-            '/v1/transfers',
-            transfers_params
-          );
-          // 记录入账手续费的流水
-          await this.openPaymentOrderEntity.insert({
-            request_id: transfers_params.request_id,
-            mch_id: accountInfo.mch_id,
-            amount: withdrawChannelFee,
-            account_id: params.data.account_id,
-            from_account_id: params.data.account_id,
-            to_account_id: this.easyPayAdapter.baseInfo.account_id,
-            event_id: params.data.id,
-            currency: params.data.currency,
-            status: params.data.status,
-            order_type: OrderType.TRANSACTION_FEE_ORDER,
-            payment_type: params.data.payment_type,
-            order_id: res.data.order_no, // 这里是转账的订单编号
-            fee: 0,
-            additional_info: {},
-          });
-        }
+        // 收取手续费: 转账
+        // /v1/transfers
+        const transfers_params = {
+          // ...openOrderObj,
+          request_id: md5(`${accountInfo.mch_id}_${params.data.id}`),
+          from_account_id: params.data.account_id,
+          to_account_id: this.easyPayAdapter.baseInfo.account_id,
+          currency: params.data.currency,
+          amount: withdrawChannelFee * 100,
+          purpose: '收取手续费用',
+        };
+        this.logger.info(
+          `记录入账流水的费率, ${JSON.stringify(transfers_params)}`
+        );
+        // 截取流水的转账
+        const res = await this.easyPayAdapter.request(
+          'POST',
+          '/v1/transfers',
+          transfers_params
+        );
+        // 记录入账手续费的流水
+        await this.openPaymentOrderEntity.insert({
+          request_id: transfers_params.request_id,
+          mch_id: accountInfo.mch_id,
+          amount: withdrawChannelFee,
+          account_id: params.data.account_id,
+          from_account_id: params.data.account_id,
+          to_account_id: this.easyPayAdapter.baseInfo.account_id,
+          event_id: params.data.id,
+          currency: params.data.currency,
+          status: params.data.status,
+          order_type: OrderType.TRANSACTION_FEE_ORDER,
+          payment_type: params.data.payment_type,
+          order_id: res.data.order_no, // 这里是转账的订单编号
+          fee: 0,
+          additional_info: {},
+        });
       });
       this.ctx.status = 200;
       this.ctx.body = {};

+ 42 - 44
src/modules/api/service/webhook_utils/payment_success.ts

@@ -126,54 +126,52 @@ export class PaymentSuccessService extends BaseService {
       // 通知上游之后,间隔10秒执行利润截取操作
       Promise.resolve().then(async () => {
         await this.webHookCommonService.waitByTime(10000);
-        let accountInfo = null;
-        // 获取回调用户的详情
-        let withdrawChannelFee = null;
-        if (accountInfo && withdrawChannelFee) {
-          // 收取手续费: 转账
-          // /v1/transfers
-          const transfers_params = {
-            // ...openOrderObj,
-            request_id: md5(`${accountInfo.mch_id}_${params.data.id}`),
-            from_account_id: params.data.account_id,
-            to_account_id: this.easyPayAdapter.baseInfo.account_id,
-            currency: params.data.currency,
-            amount: withdrawChannelFee * 100,
-            purpose: '收取手续费用',
-          };
-          this.logger.info(
-            `记录入账流水的费率, ${JSON.stringify(transfers_params)}`
-          );
-          // 截取流水的转账
-          const res = await this.easyPayAdapter.request(
-            'POST',
-            '/v1/transfers',
-            transfers_params
-          );
-          // 记录入账手续费的流水
-          await this.openPaymentOrderEntity.insert({
-            request_id: transfers_params.request_id,
-            mch_id: accountInfo.mch_id,
-            amount: withdrawChannelFee,
-            account_id: params.data.account_id,
-            from_account_id: params.data.account_id,
-            to_account_id: this.easyPayAdapter.baseInfo.account_id,
-            event_id: params.data.id,
-            currency: params.data.currency,
-            status: params.data.status,
-            order_type: OrderType.TRANSACTION_FEE_ORDER,
-            payment_type: params.data.payment_type,
-            order_id: res.data.order_no, // 这里是转账的订单编号
-            fee: 0,
-            additional_info: {},
-          });
-        }
+        // 收取手续费: 转账
+        // /v1/transfers
+        const transfers_params = {
+          // ...openOrderObj,
+          request_id: md5(`${accountInfo.mch_id}_${params.data.id}`),
+          from_account_id: params.data.account_id,
+          to_account_id: this.easyPayAdapter.baseInfo.account_id,
+          currency: params.data.currency,
+          amount: withdrawChannelFee * 100,
+          purpose: '收取手续费用',
+        };
+        this.logger.info(
+          `记录入账流水的费率, ${JSON.stringify(transfers_params)}`
+        );
+
+        // 截取流水的转账
+        const res = await this.easyPayAdapter.request(
+          'POST',
+          '/v1/transfers',
+          transfers_params
+        );
+        // 记录入账手续费的流水
+        await this.openPaymentOrderEntity.insert({
+          request_id: transfers_params.request_id,
+          mch_id: accountInfo.mch_id,
+          amount: withdrawChannelFee,
+          account_id: params.data.account_id,
+          from_account_id: params.data.account_id,
+          to_account_id: this.easyPayAdapter.baseInfo.account_id,
+          event_id: params.data.id,
+          currency: params.data.currency,
+          status: params.data.status,
+          order_type: OrderType.TRANSACTION_FEE_ORDER,
+          payment_type: params.data.payment_type,
+          order_id: res.data.order_no, // 这里是转账的订单编号
+          fee: 0,
+          additional_info: {},
+        });
       });
       this.ctx.status = 200;
       this.ctx.body = {};
       return;
-    } catch (error) {}
-
+    } catch (error) {
+      this.logger.error(`记录入账流水失败, ${JSON.stringify(params)}`);
+      this.logger.error(error);
+    }
     return params;
   }
 }