From 6812eac16e83f84a4c5f288085d10c13e354f16b Mon Sep 17 00:00:00 2001 From: qubiaobiao <3294694717@qq.com> Date: Wed, 8 Apr 2026 17:39:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=AB=E6=98=9F=E9=80=9A=E4=BF=A1=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=B9=B3=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/home.js | 5 ++- app/service/home.js | 84 +++++++++++++++++++++----------------- controllerLog/2026/4/8.txt | 1 + serviceLog/2026/4/8.txt | 1 + 4 files changed, 52 insertions(+), 39 deletions(-) create mode 100644 controllerLog/2026/4/8.txt create mode 100644 serviceLog/2026/4/8.txt diff --git a/app/controller/home.js b/app/controller/home.js index 1ff827a..f2906e9 100644 --- a/app/controller/home.js +++ b/app/controller/home.js @@ -222,7 +222,10 @@ class HomeController extends Controller { } const uid = JSON.parse(rdmcode).uid; const body = ctx.request.body; - const result = await ctx.service.home.unBindingSN(uid, body); + const model = decryptRequest(body.model); + const password = decryptRequest(body.password); + const requestMsg = body.userMsg; + const result = await ctx.service.home.unBindingSN(uid, model, password, requestMsg); if(result == "error") { setResponse(ctx, 500, '服务器错误', "none"); return; diff --git a/app/service/home.js b/app/service/home.js index 73d5d2f..d8eaf3b 100644 --- a/app/service/home.js +++ b/app/service/home.js @@ -96,12 +96,11 @@ class HomeService extends Service { bindUser.push(element.dataValues); }); const resultData = []; + const bindUserUids = new Set(resultBindUser.map(element => element.dataValues.user_uid)); resultAdminUser.forEach(item => { - resultBindUser.forEach(element => { - if (item.dataValues.uid !== element.dataValues.user_uid) { - resultData.push(item); - } - }); + if (!bindUserUids.has(item.dataValues.uid)) { + resultData.push(item); + } }); return resultData; } catch (error) { @@ -160,41 +159,50 @@ class HomeService extends Service { } // 解绑SN号 - async unBindingSN(uid, body) { + async unBindingSN(uid, modelType, password, requestMsg) { const { ctx } = this; try { const result = await ctx.model.BSide.findOne({ where: { uid, status: { [Op.not]: 2 }, role: 1 } }); - if (!result || result.organization == null) return false; - const { snNumber, userUid } = body; - const snWhere = { sn_number: snNumber }; - const snResult = await ctx.model3.SNNumber.update({ status: 0 }, { where: snWhere }); - if (snResult[0] !== 0) { - const where = { - user_uid: userUid, - sn_number: snNumber - }; - const form = { - user_uid: userUid, - sn_number: snNumber, - type: 0, - created_at: new Date() - }; - const uidLastCode = shunt(userUid); - const model = { - "B": ctx.model.BuserSNBind, - "C": ctx.model2.CuserSNBind, - "T": ctx.model2.TuserSNBind, - }; - const modelName = { - "B": ctx.model.BindBSNrecord, - "C": ctx.model2.BindCSNrecord - }; - const bindResult = await model[uidLastCode].destroy({ where }); - const recordResult = await modelName[uidLastCode].create(form); - return bindResult && recordResult ? true : false; - } else { - return false; + if (!result || result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt))) return false; + let where = {}; + let attributes = ['uid']; + if (modelType == "single") { + where = requestMsg; + } else if (modelType == "multiple") { + let account_name = [], user_name = [], phone = []; + for (const key in requestMsg) { + requestMsg[key].forEach(element => { + account_name.push(element.account_name), + user_name.push(element.user_name), + phone.push(element.phone) + }); + } + where = { account_name, user_name, phone }; + } else if (modelType == "all") { + where = { organization: result.dataValues.organization }; } + + const userResult = await ctx.model.BSide.findAll({ attributes, where }); + if (!userResult[0]) return false; + let user_uid = []; + userResult.forEach(element => { + user_uid.push(element.dataValues.uid); + }); + attributes = ['sn_number']; + where = { user_uid }; + const bindResult = await ctx.model.BuserSNBind.findAll({ attributes, where }); + if (!bindResult[0]) return false; + let sn_number = [], recordForm = []; + bindResult.forEach((element, index) => { + sn_number.push(element.dataValues.sn_number); + recordForm.push({ user_uid: user_uid[index], sn_number: sn_number[index], type: 0, created_at: new Date() }); + }); + where = { user_uid, sn_number }; + const unbindResult = await ctx.model.BuserSNBind.destroy({ where }); + const recordResult = await ctx.model.BindBSNrecord.bulkCreate(recordForm); + where = { sn_number }; + const cardResult = await ctx.model3.SNNumber.update({ status: 4 }, { where }); + return unbindResult !== 0 && recordResult[0] && cardResult[0] !== 0 ? true : false; } catch (error) { const blockName = fileName + "--" + "unBindingSN"; ctx.app.middleware.utils.log('../../../serviceLog', blockName + ">>>>" + error); @@ -209,7 +217,7 @@ class HomeService extends Service { let { offset, limit, searchOptions, sortOptions } = body; offset = (offset - 1) * limit; let attributes = ['user_uid', 'sn_number', 'type', 'created_at'], - where = { user_uid: uid }, order = [], dbOptions, joinSubstring = [], + where = {}, order = [], dbOptions, joinSubstring = [], substring = ['user_uid', 'sn_number'], key = ['type'], between = ['created_at']; const uidLastCode = shunt(uid); attributes.forEach(element => { @@ -393,7 +401,7 @@ class HomeService extends Service { let { offset, limit, searchOptions } = body; offset = (offset - 1) * limit; let attributes = ['account_name', 'user_name', 'phone'], - where = { organization: result.organization, role: { [Op.not]: 1 } }, dbOptions, joinSubstring = []; + where = { organization: result.organization }, dbOptions, joinSubstring = []; attributes.forEach(element => { if (searchOptions[element]) { if(searchOptions[element] == '*空') { diff --git a/controllerLog/2026/4/8.txt b/controllerLog/2026/4/8.txt new file mode 100644 index 0000000..804ae27 --- /dev/null +++ b/controllerLog/2026/4/8.txt @@ -0,0 +1 @@ +[2026-4-8>>>15:45:36]>>>home--unBindingSN>>>>Error: WHERE parameter "sn_number" has invalid "undefined" value diff --git a/serviceLog/2026/4/8.txt b/serviceLog/2026/4/8.txt new file mode 100644 index 0000000..686e11d --- /dev/null +++ b/serviceLog/2026/4/8.txt @@ -0,0 +1 @@ +[2026-4-8>>>15:28:20]>>>home--unBindingSN>>>>Error: WHERE parameter "sn_number" has invalid "undefined" value