Browse Source

修复重复插入权限人员表问题

laiguoran 2 years ago
parent
commit
d819347193
1 changed files with 12 additions and 8 deletions
  1. 12 8
      app/service/payment_permission_audit.js

+ 12 - 8
app/service/payment_permission_audit.js

@@ -23,15 +23,19 @@ module.exports = app => {
         }
 
         async saveAudits(pid, accountList, transaction = null) {
+            // 判断是否已存在该用户,存在则不插入
+            const pauditList = await this.getAllDataByCondition({ where: { pid } });
             const pushData = [];
-            for (const a of accountList) {
-                const data = {
-                    pid,
-                    groupid: a.account_group,
-                    uid: a.id,
-                    create_time: new Date(),
-                };
-                pushData.push(data);
+            for (const a of this._.uniqBy(accountList, 'id')) {
+                if (this._.findIndex(pauditList, { uid: a.id }) === -1) {
+                    const data = {
+                        pid,
+                        groupid: a.account_group,
+                        uid: a.id,
+                        create_time: new Date(),
+                    };
+                    pushData.push(data);
+                }
             }
             if (pushData.length > 0) {
                 return transaction ? await transaction.insert(this.tableName, pushData) : await this.db.insert(this.tableName, pushData);