فهرست منبع

Merge branch 'dev' of http://192.168.1.41:3000/maixinrong/Calculation into dev

Tony Kang 1 سال پیش
والد
کامیت
738e9458ea
2فایلهای تغییر یافته به همراه61 افزوده شده و 25 حذف شده
  1. 28 0
      app/service/notice_again.js
  2. 33 25
      app/service/project_account.js

+ 28 - 0
app/service/notice_again.js

@@ -64,6 +64,34 @@ module.exports = app => {
             const sqlParam = [table_name, sp_id];
             return await this.db.queryOne(sql, sqlParam);
         }
+
+        async updateUserNoticeAgain(transaction, uid, notice_again) {
+            const list = await transaction.select(this.tableName, { where: { uid } });
+            const uncheckedList = this._.filter(list, function(item) {
+                return item.status !== 2;
+            });
+            if (uncheckedList.length > 0) {
+                if (!notice_again.checked) { // 关闭时所有数据暂停为0
+                    const updateData = uncheckedList.map(x => { return { id: x.id, status: 0 }; });
+                    await transaction.updateRows(this.tableName, updateData);
+                } else {
+                    const updateData = [];
+                    // 分批次查看并是否插入
+                    for (const sp in notice_again.sp) {
+                        const splist = this._.filter(uncheckedList, function(item) {
+                            return item.sp_type === sp;
+                        });
+                        if (splist.length > 0) {
+                            const spUpData = splist.map(x => { return { id: x.id, status: notice_again.sp[sp] ? 1 : 0 }; });
+                            updateData.push(...spUpData);
+                        }
+                    }
+                    if (updateData.length > 0) {
+                        await transaction.updateRows(this.tableName, updateData);
+                    }
+                }
+            }
+        }
     }
     return NoticeAgain;
 };

+ 33 - 25
app/service/project_account.js

@@ -673,32 +673,40 @@ module.exports = app => {
             if (data._csrf_j !== undefined) {
                 delete data._csrf_j;
             }
-            const updateData = {
-                id,
-            };
-            if (data.cooperation !== undefined && data.cooperation !== null) {
-                updateData.cooperation = data.cooperation;
-                delete data.cooperation;
-            } else {
-                updateData.cooperation = 0;
-            }
-            const notice_again = {
-                checked: data.again_all !== undefined && data.again_all !== null,
-                sp: {},
-            };
-            delete data.again_all;
-            for (const sp in noticeAgainConst.sp) {
-                notice_again.sp[sp] = data['again_' + sp] !== undefined && data['again_' + sp] !== null;
-                delete data['again_' + sp];
+            let result = false;
+            const transaction = await this.db.beginTransaction();
+            try {
+                const updateData = {
+                    id,
+                };
+                if (data.cooperation !== undefined && data.cooperation !== null) {
+                    updateData.cooperation = data.cooperation;
+                    delete data.cooperation;
+                } else {
+                    updateData.cooperation = 0;
+                }
+                const notice_again = {
+                    checked: data.again_all !== undefined && data.again_all !== null,
+                    sp: {},
+                };
+                delete data.again_all;
+                for (const sp in noticeAgainConst.sp) {
+                    notice_again.sp[sp] = data['again_' + sp] !== undefined && data['again_' + sp] !== null;
+                    delete data['again_' + sp];
+                }
+                // 应该暂对应的重新发送的开关通知,并重新
+                await this.ctx.service.noticeAgain.updateUserNoticeAgain(transaction, id, notice_again);
+                updateData.notice_again = JSON.stringify(notice_again);
+                delete data.id;
+                updateData.permission = JSON.stringify(data);
+
+                const operate = await transaction.update(this.tableName, updateData);
+                result = operate.affectedRows > 0;
+                await transaction.commit();
+            } catch (err) {
+                await transaction.rollback();
+                throw err;
             }
-            updateData.notice_again = JSON.stringify(notice_again);
-            delete data.id;
-            updateData.permission = JSON.stringify(data);
-
-            const operate = await this.db.update(this.tableName, updateData);
-
-            const result = operate.affectedRows > 0;
-
             return result;
         }