Ver código fonte

修复KYCBUG

test 7 meses atrás
pai
commit
67138cc2fc

+ 14 - 17
src/modules/dj/service/kyc.ts

@@ -129,24 +129,11 @@ export class KycService extends BaseService {
       data.level = +kyc.level + 1;
       data.customerId = kyc.customerId
     }
-    if (data.level > 3) {
-      data.payUrl = await this.validAndGetPayUrl(orderNo, data);
-      return data;
-    }
-    const dailyLevel = this.getAmountLevel(order.amount, order.currency);
-    if (dailyLevel === 3) {
-      data.levelEnd = dailyLevel;
-      data.payUrl = await this.validAndGetPayUrl(orderNo, data);
-      return data;
-    }
+    const daily = await this.getDailyLevel(order, order.currency);
     const weekly = await this.getWeekLyLevel(order, order.currency);
-    if (weekly === 3) {
-      data.levelEnd = dailyLevel;
-      data.payUrl = await this.validAndGetPayUrl(orderNo, data);
-      return data;
-    }
     const monthly = await this.getMonthlyLevel(order, order.currency);
-    data.levelEnd = Math.max(dailyLevel, weekly, monthly);
+    data.levelEnd = Math.max(daily, weekly, monthly);
+    console.log('---------', daily, weekly, monthly, data.level, data.levelEnd, data.customerId)
     data.payUrl = await this.validAndGetPayUrl(orderNo, data);
     return data;
   }
@@ -159,6 +146,7 @@ export class KycService extends BaseService {
         });
         return payUrl;
       } catch (e) {
+        console.log('----发起订单失败-----')
         return "";
       }
     } else {
@@ -166,6 +154,15 @@ export class KycService extends BaseService {
     }
   }
 
+  async getDailyLevel(order, currency) {
+    const daily = await this.orderService.getDailyAmount(order.mchId, order.userId, order.code);
+    let amount = 0;
+    if (daily && daily[0]) {
+      amount = +daily[0].total;
+    }
+    return this.getAmountLevel(amount + +order.amount, currency);
+  }
+
   async getMonthlyLevel(order, currency) {
     const month = await this.orderService.getMonthlyAmount(order.mchId, order.userId, order.code);
     let amount = 0;
@@ -186,7 +183,7 @@ export class KycService extends BaseService {
 
   getAmountLevel(amount: number, currency) {
     const eur = this.toEur(amount, currency)
-    console.log('-----------------------', eur)
+    console.log('转换为欧元:', amount, eur)
     if (eur <= 1000) {
       return 1;
     } else if (eur <= 5000) {

+ 14 - 0
src/modules/dj/service/order.ts

@@ -300,6 +300,20 @@ export class OrderService extends BaseService {
     return this.sqlRenderPage(sql, query);
   }
 
+  async getDailyAmount(mchId, userId, code) {
+    const time = [
+      moment().startOf('day').format('YYYY-MM-DD') + ' 00:00:00',
+      moment().endOf('day').format('YYYY-MM-DD') + ' 23:59:59',
+    ];
+    const sql = `SELECT SUM(IF(a.status = 1, a.amount, 0)) as total FROM dj_order a WHERE 1=1 
+    ${this.setSql(mchId, 'and a.mchId = ?', [`${mchId}`])}
+    ${this.setSql(userId, 'and a.userId = ?', [`${userId}`])}
+    ${this.setSql(code, 'and a.code = ?', [`${code}`])}
+    ${this.setSql(true, 'and (a.createTime between ? and ?)', time)}
+    `
+    return await this.nativeQuery(sql);
+  }
+
   async getWeeklyAmount(mchId, userId, code) {
     const time = [
       moment().startOf('week').format('YYYY-MM-DD') + ' 00:00:00',

+ 0 - 1
src/modules/plugin/entity/info.ts

@@ -1,7 +1,6 @@
 import { BaseEntity } from '@cool-midway/core';
 import { Column, Entity, DataSource, Index } from 'typeorm';
 
-console.log(DataSource);
 
 /**
  * 插件信息