2026-03-27 17:57:44 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
const Service = require('../core/base_service');
|
|
|
|
|
|
|
|
|
|
const { Op } = require('sequelize');
|
|
|
|
|
|
|
|
|
|
const shunt = (uid) => {
|
|
|
|
|
return uid[uid.length - 1];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const fileName = 'home';
|
|
|
|
|
|
|
|
|
|
class HomeService extends Service {
|
|
|
|
|
// 获取SN号
|
|
|
|
|
async getSN(uid) {
|
|
|
|
|
const { ctx } = this;
|
|
|
|
|
try {
|
|
|
|
|
const where = { user_uid: uid };
|
|
|
|
|
const uidLastCode = shunt(uid);
|
|
|
|
|
const model = {
|
|
|
|
|
"B": ctx.model.BuserSNBind,
|
|
|
|
|
"C": ctx.model2.CuserSNBind,
|
|
|
|
|
"T": ctx.model4.TuserSNBind,
|
|
|
|
|
};
|
|
|
|
|
const result = await model[uidLastCode].findOne({ where });
|
|
|
|
|
return result || false;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
const blockName = fileName + "--" + "getSN";
|
|
|
|
|
ctx.app.middleware.utils.log('../../../serviceLog', blockName + ">>>>" + error);
|
|
|
|
|
return 'error';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 搜索SN号
|
|
|
|
|
async searchSN(snNumber) {
|
|
|
|
|
const { ctx } = this;
|
|
|
|
|
try {
|
|
|
|
|
const where = { sn_number: snNumber };
|
|
|
|
|
const result = await ctx.model3.SNNumber.findOne({ where });
|
|
|
|
|
return result || false;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
const blockName = fileName + "--" + "searchSN";
|
|
|
|
|
ctx.app.middleware.utils.log('../../../serviceLog', blockName + ">>>>" + error);
|
|
|
|
|
return 'error';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 搜索可绑定的SN号
|
|
|
|
|
async searchBindSN(uid) {
|
|
|
|
|
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 resultAdminSN = await ctx.model.BuserSNAdmin.findOne({ attributes: ['sn_set'], where: { user_uid: uid } });
|
|
|
|
|
if (!resultAdminSN) return false;
|
|
|
|
|
const adminSN = [];
|
|
|
|
|
resultAdminSN.sn_set.split(',').forEach(element => {
|
|
|
|
|
adminSN.push(element);
|
|
|
|
|
});
|
|
|
|
|
const where = { sn_number: { [Op.in]: adminSN }, status: 4 };
|
|
|
|
|
const resultBindSN = await ctx.model3.SNNumber.findAll({ attributes: ['sn_number'], where });
|
|
|
|
|
if (resultBindSN.length == 0) return false;
|
|
|
|
|
const bindSN = [];
|
|
|
|
|
resultBindSN.forEach(element => {
|
|
|
|
|
bindSN.push(element.dataValues.sn_number);
|
|
|
|
|
});
|
|
|
|
|
const resultData = adminSN.filter(item => bindSN.includes(item));
|
|
|
|
|
return resultData;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
const blockName = fileName + "--" + "searchBindSN";
|
|
|
|
|
ctx.app.middleware.utils.log('../../../serviceLog', blockName + ">>>>" + error);
|
|
|
|
|
return 'error';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 搜索可绑定的单位用户
|
|
|
|
|
async searchBindUser(uid) {
|
|
|
|
|
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 resultAdminUser = await ctx.model.BSide.findAll({ attributes: ['uid', 'account_name'], where: { status: { [Op.not]: 2 }, organization: result.organization } });
|
|
|
|
|
const uidArr = [];
|
|
|
|
|
resultAdminUser.forEach(element => {
|
|
|
|
|
uidArr.push(element.dataValues.uid);
|
|
|
|
|
});
|
|
|
|
|
const where = { user_uid: { [Op.in]: uidArr } };
|
|
|
|
|
const resultBindUser = await ctx.model.BuserSNBind.findAll({ attributes: ['user_uid'], where });
|
|
|
|
|
if (resultBindUser.length == 0) return resultAdminUser;
|
|
|
|
|
const adminUser = [];
|
|
|
|
|
resultAdminUser.forEach(element => {
|
|
|
|
|
adminUser.push(element.dataValues);
|
|
|
|
|
});
|
|
|
|
|
const bindUser = [];
|
|
|
|
|
resultBindUser.forEach(element => {
|
|
|
|
|
bindUser.push(element.dataValues);
|
|
|
|
|
});
|
|
|
|
|
const resultData = [];
|
2026-04-08 17:39:56 +08:00
|
|
|
const bindUserUids = new Set(resultBindUser.map(element => element.dataValues.user_uid));
|
2026-03-27 17:57:44 +08:00
|
|
|
resultAdminUser.forEach(item => {
|
2026-04-08 17:39:56 +08:00
|
|
|
if (!bindUserUids.has(item.dataValues.uid)) {
|
|
|
|
|
resultData.push(item);
|
|
|
|
|
}
|
2026-03-27 17:57:44 +08:00
|
|
|
});
|
|
|
|
|
return resultData;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
const blockName = fileName + "--" + "searchBindUser";
|
|
|
|
|
ctx.app.middleware.utils.log('../../../serviceLog', blockName + ">>>>" + error);
|
|
|
|
|
return 'error';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 绑定SN号
|
|
|
|
|
async bindSN(uid, body) {
|
|
|
|
|
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 where = { sn_number: snNumber };
|
|
|
|
|
const sn = await ctx.model3.SNNumber.findOne({ where });
|
|
|
|
|
if (!sn) return false;
|
|
|
|
|
const model = {
|
|
|
|
|
"B": ctx.model.BuserSNBind,
|
|
|
|
|
"C": ctx.model2.CuserSNBind,
|
|
|
|
|
"T": ctx.model2.TuserSNBind
|
|
|
|
|
};
|
|
|
|
|
const uidLastCode = shunt(userUid);
|
|
|
|
|
const bindCheck = await model[uidLastCode].findOne({ where: { user_uid: userUid } });
|
|
|
|
|
if (bindCheck) return false;
|
|
|
|
|
if (shunt(userUid) == 'B' && sn.status !== 4 || shunt(userUid) !== 'B' && sn.status !== 0) {
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
const status = shunt(userUid) == 'B' ? 1 : shunt(userUid) == 'C' ? 2 : 3;
|
|
|
|
|
const snResult = await ctx.model3.SNNumber.update({ status }, { where });
|
|
|
|
|
const bindForm = {
|
|
|
|
|
user_uid: userUid,
|
|
|
|
|
sn_number: snNumber
|
|
|
|
|
};
|
|
|
|
|
const resultForm = {
|
|
|
|
|
user_uid: userUid,
|
|
|
|
|
sn_number: snNumber,
|
|
|
|
|
type: 1,
|
|
|
|
|
created_at: new Date()
|
|
|
|
|
};
|
|
|
|
|
const modelName = {
|
|
|
|
|
"B": ctx.model.BindBSNrecord,
|
|
|
|
|
"C": ctx.model2.BindCSNrecord
|
|
|
|
|
};
|
|
|
|
|
const bindResult = await model[uidLastCode].create(bindForm);
|
|
|
|
|
const recordResult = await modelName[uidLastCode].create(resultForm);
|
|
|
|
|
return snResult[0] && bindResult && recordResult ? true : false;
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
const blockName = fileName + "--" + "bindSN";
|
|
|
|
|
ctx.app.middleware.utils.log('../../../serviceLog', blockName + ">>>>" + error);
|
|
|
|
|
return 'error';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 解绑SN号
|
2026-04-08 17:39:56 +08:00
|
|
|
async unBindingSN(uid, modelType, password, requestMsg) {
|
2026-03-27 17:57:44 +08:00
|
|
|
const { ctx } = this;
|
|
|
|
|
try {
|
|
|
|
|
const result = await ctx.model.BSide.findOne({ where: { uid, status: { [Op.not]: 2 }, role: 1 } });
|
2026-04-08 17:39:56 +08:00
|
|
|
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 };
|
2026-03-27 17:57:44 +08:00
|
|
|
}
|
2026-04-08 17:39:56 +08:00
|
|
|
|
|
|
|
|
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;
|
2026-03-27 17:57:44 +08:00
|
|
|
} catch (error) {
|
|
|
|
|
const blockName = fileName + "--" + "unBindingSN";
|
|
|
|
|
ctx.app.middleware.utils.log('../../../serviceLog', blockName + ">>>>" + error);
|
|
|
|
|
return 'error';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取绑定记录
|
|
|
|
|
async getRecord(uid, body) {
|
|
|
|
|
const { ctx } = this;
|
|
|
|
|
try {
|
|
|
|
|
let { offset, limit, searchOptions, sortOptions } = body;
|
|
|
|
|
offset = (offset - 1) * limit;
|
|
|
|
|
let attributes = ['user_uid', 'sn_number', 'type', 'created_at'],
|
2026-05-19 17:12:10 +08:00
|
|
|
where = {}, order = [], dbOptions, joinSubstring = [],
|
|
|
|
|
substring = ['user_uid', 'sn_number'], key = ['type'], between = ['created_at'];
|
2026-03-27 17:57:44 +08:00
|
|
|
const uidLastCode = shunt(uid);
|
|
|
|
|
attributes.forEach(element => {
|
|
|
|
|
if (searchOptions[element]) {
|
2026-05-19 17:12:10 +08:00
|
|
|
if (searchOptions[element] == '*空') {
|
|
|
|
|
if (joinSubstring.includes(element)) {
|
|
|
|
|
where[element] = null;
|
2026-03-27 17:57:44 +08:00
|
|
|
} else {
|
2026-05-19 17:12:10 +08:00
|
|
|
where[element] = [null, ''];
|
2026-03-27 17:57:44 +08:00
|
|
|
}
|
2026-05-19 17:12:10 +08:00
|
|
|
} else if (substring.includes(element)) {
|
2026-03-27 17:57:44 +08:00
|
|
|
where[element] = { [Op.substring]: searchOptions[element] };
|
|
|
|
|
} else if (key.includes(element)) {
|
|
|
|
|
where[element] = searchOptions[element] == "1" ? uidLastCode === 'B' ? 1 : 2 : 0;
|
|
|
|
|
} else if (between.includes(element)) {
|
|
|
|
|
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (sortOptions[element] == true) {
|
|
|
|
|
order.push([element, 'ASC']);
|
|
|
|
|
} else if (sortOptions[element] == false) {
|
|
|
|
|
order.push([element, 'DESC']);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
dbOptions = { attributes, offset, limit, where, order };
|
|
|
|
|
const model = {
|
|
|
|
|
"B": ctx.model.BSide,
|
|
|
|
|
"C": ctx.model2.CSide,
|
|
|
|
|
};
|
|
|
|
|
const modelName = {
|
|
|
|
|
"B": ctx.model.BindBSNrecord,
|
|
|
|
|
"C": ctx.model2.BindCSNrecord,
|
|
|
|
|
};
|
|
|
|
|
const user = await model[uidLastCode].findAll({ attributes: ['uid', 'account_name'] });
|
|
|
|
|
const result = await modelName[uidLastCode].findAndCountAll(dbOptions);
|
|
|
|
|
result.rows.forEach(element => {
|
|
|
|
|
element.dataValues.account_name = '';
|
|
|
|
|
user.filter(item => {
|
|
|
|
|
if (item.dataValues.uid == element.dataValues.user_uid) {
|
|
|
|
|
element.dataValues.account_name = item.dataValues.account_name;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
return result.rows.length == 0 ? false : result;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
const blockName = fileName + "--" + "getRecord";
|
|
|
|
|
ctx.app.middleware.utils.log('../../../serviceLog', blockName + ">>>>" + error);
|
|
|
|
|
return 'error';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 存储消息记录
|
|
|
|
|
async shortMsg(form) {
|
|
|
|
|
const { ctx } = this;
|
|
|
|
|
try {
|
|
|
|
|
const where = { sn_number: form.sn_number };
|
|
|
|
|
const SN = await ctx.model3.SNNumber.findOne({ where });
|
|
|
|
|
if (!SN) {
|
2026-04-30 14:22:01 +08:00
|
|
|
ctx.app.middleware.utils.log('../../../unknownSNLog', JSON.stringify(form));
|
2026-03-27 17:57:44 +08:00
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
const model = {
|
|
|
|
|
1: ctx.model.BuserSNBind,
|
|
|
|
|
2: ctx.model2.CuserSNBind,
|
|
|
|
|
3: ctx.model4.TuserSNBind,
|
|
|
|
|
};
|
|
|
|
|
const bind = await model[SN.dataValues.status].findOne({ where });
|
|
|
|
|
if (!bind) return false;
|
|
|
|
|
form.user_uid = bind.dataValues.user_uid;
|
|
|
|
|
const uidLastCode = shunt(form.user_uid);
|
|
|
|
|
const modelName = {
|
|
|
|
|
"B": ctx.model.BSNMsg,
|
|
|
|
|
"C": ctx.model2.CSNMsg,
|
|
|
|
|
"T": ctx.model4.TSNMsg,
|
|
|
|
|
};
|
|
|
|
|
const result = await modelName[uidLastCode].create(form);
|
|
|
|
|
return result || false;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
const blockName = fileName + "--" + "shortMsg";
|
|
|
|
|
ctx.app.middleware.utils.log('../../../serviceLog', blockName + ">>>>" + error);
|
|
|
|
|
return 'error';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-19 17:12:10 +08:00
|
|
|
// 保存未知消息
|
|
|
|
|
async saveUnknown(form) {
|
|
|
|
|
const { ctx } = this;
|
|
|
|
|
try {
|
2026-06-01 17:47:16 +08:00
|
|
|
const result = await ctx.model3.UnknownSN.create(form);
|
2026-05-19 17:12:10 +08:00
|
|
|
return result || false;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
const blockName = fileName + "--" + "saveUnknown";
|
|
|
|
|
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
|
|
|
|
return 'error';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-27 17:57:44 +08:00
|
|
|
// 获取历史消息
|
|
|
|
|
async getHistoryMsg(uid, body) {
|
|
|
|
|
const { ctx } = this;
|
|
|
|
|
try {
|
|
|
|
|
let { offset, limit, searchOptions, sortOptions } = body;
|
|
|
|
|
offset = (offset - 1) * limit;
|
|
|
|
|
let attributes = ['original_msg', 'sn_number', 'msg_data', 'created_at'],
|
2026-05-19 17:12:10 +08:00
|
|
|
where = { user_uid: uid }, order = [], dbOptions, joinSubstring = [],
|
|
|
|
|
substring = ['original_msg', 'sn_number', 'msg_data'], key = [], between = ['created_at'];
|
2026-03-27 17:57:44 +08:00
|
|
|
attributes.forEach(element => {
|
|
|
|
|
if (searchOptions[element]) {
|
2026-05-19 17:12:10 +08:00
|
|
|
if (searchOptions[element] == '*空') {
|
|
|
|
|
if (joinSubstring.includes(element)) {
|
|
|
|
|
where[element] = null;
|
2026-03-27 17:57:44 +08:00
|
|
|
} else {
|
2026-05-19 17:12:10 +08:00
|
|
|
where[element] = [null, ''];
|
2026-03-27 17:57:44 +08:00
|
|
|
}
|
|
|
|
|
} else if (substring.includes(element)) {
|
|
|
|
|
where[element] = { [Op.substring]: searchOptions[element] };
|
|
|
|
|
} else if (key.includes(element)) {
|
|
|
|
|
where[element] = searchOptions[element] == "1" ? true : false;
|
|
|
|
|
} else if (between.includes(element)) {
|
|
|
|
|
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (sortOptions[element] == true) {
|
|
|
|
|
order.push([element, 'ASC']);
|
|
|
|
|
} else if (sortOptions[element] == false) {
|
|
|
|
|
order.push([element, 'DESC']);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
dbOptions = { attributes, offset, limit, where, order };
|
|
|
|
|
const uidLastCode = shunt(uid);
|
|
|
|
|
const model = {
|
|
|
|
|
"B": ctx.model.BSNMsg,
|
|
|
|
|
"C": ctx.model2.CSNMsg,
|
|
|
|
|
"T": ctx.model4.TSNMsg,
|
|
|
|
|
};
|
|
|
|
|
const result = await model[uidLastCode].findAndCountAll(dbOptions);
|
|
|
|
|
return result.rows.length == 0 ? false : result;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
const blockName = fileName + "--" + "getHistoryMsg";
|
|
|
|
|
ctx.app.middleware.utils.log('../../../serviceLog', blockName + ">>>>" + error);
|
|
|
|
|
return 'error';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 删除历史消息
|
|
|
|
|
async delHistoryMsg(uid, modelType, password, requestMsg) {
|
|
|
|
|
const { ctx } = this;
|
|
|
|
|
try {
|
|
|
|
|
const uidLastCode = shunt(uid);
|
|
|
|
|
const model = {
|
|
|
|
|
"B": ctx.model.BSide,
|
|
|
|
|
"C": ctx.model2.CSide,
|
|
|
|
|
"T": ctx.model4.Account,
|
|
|
|
|
};
|
|
|
|
|
const result = await model[uidLastCode].findOne({ where: { uid } });
|
|
|
|
|
if (!result || result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt))) return false;
|
|
|
|
|
let where = {};
|
|
|
|
|
if (modelType == "single") {
|
|
|
|
|
const { sn_number, msg_data, origin_time } = requestMsg;
|
|
|
|
|
where = { user_uid: uid, sn_number, msg_data, created_at: origin_time };
|
|
|
|
|
} else if (modelType == "multiple") {
|
|
|
|
|
let sn_number = [], msg_data = [], created_at = [];
|
|
|
|
|
for (const key in requestMsg) {
|
|
|
|
|
requestMsg[key].forEach(element => {
|
|
|
|
|
sn_number.push(element.sn_number),
|
2026-05-19 17:12:10 +08:00
|
|
|
msg_data.push(element.msg_data),
|
|
|
|
|
created_at.push(element.origin_time)
|
2026-03-27 17:57:44 +08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
where = { user_uid: uid, sn_number, msg_data, created_at };
|
|
|
|
|
} else if (modelType == "all") {
|
|
|
|
|
where = { user_uid: uid };
|
|
|
|
|
}
|
|
|
|
|
const modelName = {
|
|
|
|
|
"B": ctx.model.BSNMsg,
|
|
|
|
|
"C": ctx.model2.CSNMsg,
|
|
|
|
|
"T": ctx.model4.TSNMsg,
|
|
|
|
|
};
|
|
|
|
|
const resetList = await modelName[uidLastCode].destroy({ where });
|
2026-06-04 10:35:40 +08:00
|
|
|
return resetList == 0 ? false : resetList;
|
2026-03-27 17:57:44 +08:00
|
|
|
} catch (error) {
|
|
|
|
|
const blockName = fileName + "--" + "delHistoryMsg";
|
|
|
|
|
ctx.app.middleware.utils.log('../../../serviceLog', blockName + ">>>>" + error);
|
|
|
|
|
return 'error';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取单位用户
|
|
|
|
|
async bsideUserManager(uid, body) {
|
|
|
|
|
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;
|
|
|
|
|
let { offset, limit, searchOptions } = body;
|
|
|
|
|
offset = (offset - 1) * limit;
|
|
|
|
|
let attributes = ['account_name', 'user_name', 'phone'],
|
2026-05-19 17:12:10 +08:00
|
|
|
where = { organization: result.organization }, dbOptions, joinSubstring = [];
|
2026-03-27 17:57:44 +08:00
|
|
|
attributes.forEach(element => {
|
|
|
|
|
if (searchOptions[element]) {
|
2026-05-19 17:12:10 +08:00
|
|
|
if (searchOptions[element] == '*空') {
|
|
|
|
|
if (joinSubstring.includes(element)) {
|
|
|
|
|
where[element] = null;
|
2026-03-27 17:57:44 +08:00
|
|
|
} else {
|
2026-05-19 17:12:10 +08:00
|
|
|
where[element] = [null, ''];
|
2026-03-27 17:57:44 +08:00
|
|
|
}
|
2026-05-19 17:12:10 +08:00
|
|
|
} else {
|
2026-03-27 17:57:44 +08:00
|
|
|
where[element] = { [Op.substring]: searchOptions[element] };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
dbOptions = { attributes, offset, limit, where };
|
|
|
|
|
const userList = await ctx.model.BSide.findAndCountAll(dbOptions);
|
|
|
|
|
return userList.rows.length == 0 ? false : userList;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
const blockName = fileName + "--" + "bsideUserManager";
|
|
|
|
|
ctx.app.middleware.utils.log('../../../serviceLog', blockName + ">>>>" + error);
|
|
|
|
|
return 'error';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取可管理的SN号
|
|
|
|
|
async bsideSNManager(uid) {
|
|
|
|
|
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;
|
|
|
|
|
let attributes = ['length', 'sn_set'],
|
2026-05-19 17:12:10 +08:00
|
|
|
where = { user_uid: uid }, dbOptions;
|
2026-03-27 17:57:44 +08:00
|
|
|
dbOptions = { attributes, where };
|
|
|
|
|
const snMsg = await ctx.model.BuserSNAdmin.findOne(dbOptions);
|
|
|
|
|
if (!snMsg) return false;
|
|
|
|
|
const snList = snMsg.dataValues.sn_set.split(',');
|
|
|
|
|
const snResult = await ctx.model3.SNNumber.findAll({ attributes: ['sn_number', 'status', 'updated_at'], where: { sn_number: { [Op.in]: snList } } });
|
|
|
|
|
return snResult.length == 0 ? false : snResult;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
const blockName = fileName + "--" + "bsideSNManager";
|
|
|
|
|
ctx.app.middleware.utils.log('../../../serviceLog', blockName + ">>>>" + error);
|
|
|
|
|
return 'error';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = HomeService;
|