Commit ea30c904 by Sxy

fix: 代码规范

parent 6c5ca1fb
......@@ -58,9 +58,9 @@ class UserCtl extends CtlBase {
// let v = await this.smsS.sendVCode(mobile);
// return system.getResult({ vcodestr: v });
// }
async exit(pobj, qobj, req) {
// async exit(pobj, qobj, req) {
}
// }
// 应用的自由用户注册,无需验证,需要前端头设置公司KEY
async pmregisterByFreeUser(p, q, req) {
// 检查是否有用户名和密码
......
......@@ -25,8 +25,8 @@ class VCodeCache extends CacheBase {
if (!tmplCode && !signName) {
console.log('=============================');
this.smsUtil.sendMsg(mobile, vcode);
} // tmplCode为发送短信编码,需在阿里开通,signName为短信头描述信息,二者没有传递则用默认的发送验证码
else {
// tmplCode为发送短信编码,需在阿里开通,signName为短信头描述信息,二者没有传递则用默认的发送验证码
} else {
this.smsUtil.aliSendMsg(mobile, tmplCode, signName, JSON.stringify({ code: vcode }));
}
return JSON.stringify({ vcode });
......
......@@ -9,11 +9,11 @@ class UserDao extends Dao {
return this.model.findOne({
where: { id: userid },
include: [{ model: self.db.models.account, attributes: ['id', 'isSuper', 'referrerOnlyCode'] },
{
model: self.db.models.role, as: 'Roles', attributes: ['id', 'code'], include: [
{ model: self.db.models.product, as: 'Products', attributes: ['id', 'code'] },
],
},
{
model: self.db.models.role, as: 'Roles', attributes: ['id', 'code'], include: [
{ model: self.db.models.product, as: 'Products', attributes: ['id', 'code'] },
],
},
],
});
}
......@@ -22,14 +22,12 @@ class UserDao extends Dao {
const tUser = await this.model.findOne({
where: { userName: username, app_id: app.id },
include: [{ model: this.db.models.app, raw: true },
// {model:this.db.models.partnerinfo,attributes:["id","user_id","app_id","userName","applyType","applyName","workPic","tagInfo","mobile","tel","applyProvince","applyCity",
// "applyArea","applyAddr","identityCardPic","identityCard","businessLicensePic","businessLicenseNum","entName","cardNo","realName"]},
{ model: this.db.models.account, attributes: ['id', 'isSuper', 'referrerOnlyCode'], raw: true },
{
model: this.db.models.role, as: 'Roles', attributes: ['id', 'code'], include: [
{ model: this.db.models.product, as: 'Products', attributes: ['id', 'code'], raw: true },
],
},
{ model: this.db.models.account, attributes: ['id', 'isSuper', 'referrerOnlyCode'], raw: true },
{
model: this.db.models.role, as: 'Roles', attributes: ['id', 'code'], include: [
{ model: this.db.models.product, as: 'Products', attributes: ['id', 'code'], raw: true },
],
},
],
}, { transaction: t });
// if(tUser!=null){
......@@ -43,35 +41,31 @@ class UserDao extends Dao {
let tUser = await this.model.findOne({
where: { openId: popenid },
include: [{ model: this.db.models.app, raw: true },
// {model:this.db.models.partnerinfo,attributes:["id","user_id","app_id","userName","applyType","applyName","workPic","tagInfo","mobile","tel","applyProvince","applyCity",
// "applyArea","applyAddr","identityCardPic","identityCard","businessLicensePic","businessLicenseNum","entName","cardNo","realName"]},
{ model: this.db.models.account, attributes: ['id', 'isSuper', 'referrerOnlyCode'], raw: true },
{
model: this.db.models.role, as: 'Roles', attributes: ['id', 'code'], include: [
{ model: this.db.models.product, as: 'Products', attributes: ['id', 'code'], raw: true },
],
},
{ model: this.db.models.account, attributes: ['id', 'isSuper', 'referrerOnlyCode'], raw: true },
{
model: this.db.models.role, as: 'Roles', attributes: ['id', 'code'], include: [
{ model: this.db.models.product, as: 'Products', attributes: ['id', 'code'], raw: true },
],
},
],
}, { transaction: t });
if (tUser != null) {
tUser = tUser.get({ plain: true });
tUser.partnerinfo = await this.partnerinfoDao.model.findOne({ where: { onlyCode: tUser.onlyCode }, raw: true });
}
// console.log("tUser.partnerinfo...................................>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>999sy");
// console.log(tUser);
return tUser;
}
async setAccount(user, account, t) {
var user = await user.setAccount(account, { transaction: t });
const user = await user.setAccount(account, { transaction: t });
return user;
}
async setApp(user, app, t) {
// 按照APPId,获取app对象
var user = await user.setApp(app, { transaction: t });
const user = await user.setApp(app, { transaction: t });
return user;
}
extraModelFilter() {
// return {"key":"include","value":[{model:this.db.models.app,},{model:this.db.models.role,as:"Roles",attributes:["id","name"],joinTableAttributes:['created_at']}]};
return {
key: 'include', value: [
// {model:this.db.models.app,},
......@@ -145,8 +139,8 @@ class UserDao extends Dao {
}
// 修改用户(user表)公司的唯一码
async putUserCompanyOnlyCode(userId, company_only_code, result) {
const customerObj = { companyOnlyCode: company_only_code };
async putUserCompanyOnlyCode(userId, companyOnlyCode, result) {
const customerObj = { companyOnlyCode };
const putSqlWhere = { where: { id: userId } };
this.updateByWhere(customerObj, putSqlWhere);
return result;
......
......@@ -200,7 +200,7 @@ class OrgService extends ServiceBase {
code: `root${company.id}`,
name: company.name,
isLeaf: false,
isPostion: false,
isPosition: false,
isMain: false,
orgpath: '/',
company_id: company.id,
......
......@@ -94,13 +94,21 @@ class UserService extends ServiceBase {
// 设置默认普通角色,由于有了租户概念,所以注册时,需要知道当前租户和应用的id 才可以设置默认角色 todo
// 如果是非租户,那么按照当前应用ID是找不到指定的角色,所以是空的
/* if (p.isAdmin) {
//var roles = await self.roleDao.model.findAll({ where: { id: { [self.db.Op.in]: rolecodes }, app_id: roleappid, company_id: settings.pmcompanyid }, transaction: t });
//var roles = await self.roleDao.model.findAll({ where:
{
id: { [self.db.Op.in]: rolecodes },
app_id: roleappid,
company_id: settings.pmcompanyid
}, transaction: t });
var roles = await self.roleDao.model.findAll({ where: { id: { [self.db.Op.in]: rolecodes }}, transaction: t });
if (roles && roles.length > 0) {
await u.setRoles(roles, { transaction: t });
}
} else {
var roles = await self.roleDao.model.findAll({ where: { id: { [self.db.Op.in]: rolecodes }, app_id: roleappid, company_id: p.company_id }, transaction: t });
var roles = await self.roleDao.model.findAll({ where: {
id: { [self.db.Op.in]: rolecodes },
app_id: roleappid,
company_id: p.company_id }, transaction: t });
if (roles && roles.length > 0) {
await u.setRoles(roles, { transaction: t });
}
......@@ -246,7 +254,11 @@ class UserService extends ServiceBase {
return rtn;
}
// 先按照用户名查续身份信息,获取key,secret,
const regrtn = await this.pmregister({ userName: mobile, nickName: mobile, rolecodes: p.rolecodes, company_id: p.company_id, app_id: p.app_id });
const regrtn = await this.pmregister({
userName: mobile, nickName: mobile,
rolecodes: p.rolecodes, company_id: p.company_id,
app_id: p.app_id,
});
const token = await this.cmakejwt(regrtn.user.jwtkey, regrtn.user.jwtsecret, null);
// rtn.token = token;
// rtn.user = u;
......@@ -344,14 +356,14 @@ class UserService extends ServiceBase {
// 登录统一账号
async clogin(uname) {
// 检查是否存在重名
// async clogin(uname) {
// // 检查是否存在重名
}
// 按用户名查询统一用户
async findCUser(uname) {
// }
// // 按用户名查询统一用户
// async findCUser(uname) {
}
// }
async resetPassword(uname, pwd) {
const inpassword = this.getEncryptStr(pwd, true);
const self = this;
......@@ -436,19 +448,15 @@ class UserService extends ServiceBase {
if (u.isAllocated && u.isSalesman && u.skilltags.indexOf(productCatName) >= 0) {
if (u.regiontags.indexOf(regionName) >= 0 || u.isAllArea) {
return true;
}
return false;
}
}
return false;
}
if (u.isAllocated && u.isSalesman && u.isAllArea && u.skilltags.indexOf(productCatName) >= 0) {
return true;
}
return false;
}
return false;
}
if (u.isAllocated && u.isSalesman && u.isAllArea && u.skilltags.indexOf(productCatName) >= 0) {
return true;
}
return false;
});
console.log(`getBizUserForBizChance可以接单的业务员:${JSON.stringify(cansels)}服务商id:${companyFind.id}`);
const lngth = cansels.length;
......@@ -551,19 +559,15 @@ class UserService extends ServiceBase {
if (u.isAllocated && u.isDelivery && u.skilltags.indexOf(productCatName) >= 0) {
if (u.regiontags.indexOf(regionName) >= 0 || u.isAllArea) {
return true;
}
return false;
}
return false;
}
if (u.isAllocated && u.isDelivery && u.isAllArea && u.skilltags.indexOf(productCatName) >= 0) {
return true;
}
}
return false;
}
return false;
}
if (u.isAllocated && u.isDelivery && u.isAllArea && u.skilltags.indexOf(productCatName) >= 0) {
return true;
}
return false;
});
console.log(`getBizUserForDelivery可以接单的交付员:${JSON.stringify(cansels)}服务商id:${companyFind.id}`);
const lngth = cansels.length;
......
......@@ -10,107 +10,6 @@ class MsgNoticeService extends ServiceBase {
return this.cacheManager.AppCache.cacheApp(appkey);
}
async getUserList(userId) {
const list = await this.dao.model.findAll({
where: {
fromId: userId,
},
order: [
['updated_at', 'DESC'],
],
raw: true,
});
if (!list || list.length == 0) {
return [];
}
const msgIds = [];
const businessLicenseIds = [];
const userIds = [];
for (const item of list) {
msgIds.push(item.lastMsgId);
businessLicenseIds.push(item.businessLicense_id);
userIds.push(item.toId);
}
const msgMap = [];
const businessLicenseMap = [];
const userMap = [];
const unreadMap = [];
// 最后一条聊天记录
if (msgIds.length > 0) {
const msgList = await this.msghistoryDao.customQuery(`SELECT * FROM msghistory WHERE id IN (${msgIds.join(',')}) `);
msgList.forEach((item) => {
msgMap[`id${item.id}`] = item;
});
}
// 最后一次聊天关联执照
if (businessLicenseIds.length > 0) {
const licenseList = await this.businesslicenseDao.customQuery(`SELECT * FROM yz_business_license WHERE id IN (${businessLicenseIds.join(',')}) `);
const serviceTypeIds = [];
for (const item of licenseList) {
serviceTypeIds.push(item.serviceTypeOneId);
serviceTypeIds.push(item.serviceTypeTwoId);
}
if (serviceTypeIds.length > 0) {
const sql = `SELECT id, name FROM \`p_service_type\` WHERE id IN (${serviceTypeIds.join(',')}) `;
const typeList = await this.dao.customQuery(sql);
const typeMap = [];
if (typeList && typeList.length > 0) {
for (const t of typeList) {
typeMap[`type_id_${t.id}`] = t.name;
if (t.id == item.serviceTypeOneId) {
item.serviceTypeOneName = t.name;
} else if (t.id == item.serviceTypeTwoId) {
item.serviceTypeTwoName = t.name;
} else {
console.log('what~~~~');
}
}
}
}
for (const item of licenseList) {
item.serviceTypeOneName = typeMap[`type_id_${item.serviceTypeOneId}`];
item.serviceTypeTwoName = typeMap[`type_id_${item.serviceTypeTwoId}`];
}
licenseList.forEach((item) => {
businessLicenseMap[`id${item.id}`] = item;
});
}
// 聊天好友用户信息
if (userIds.length > 0) {
const userList = await this.userDao.customQuery(`SELECT * FROM p_user WHERE id IN (${userIds.join(',')}) `);
userList.forEach((item) => {
userMap[`id${item.id}`] = item;
});
}
// 未读消息数量
const unreadList = await this.userDao.customQuery(`SELECT senderId, COUNT(1) AS num FROM \`msghistory\` WHERE isRead = 0 AND targetId = ${userId} GROUP BY senderId `);
unreadList.forEach((item) => {
unreadMap[`id${item.senderId}`] = item.num;
});
const rs = [];
for (const i in list) {
const item = list[i];
item.lastMsg = msgMap[`id${item.lastMsgId}`];
item.businessLicense = businessLicenseMap[`id${item.businessLicense_id}`];
item.friend = userMap[`id${item.toId}`];
item.unreadCount = unreadMap[`id${item.toId}`] || 0;
rs.push(item);
}
return rs;
}
async countUnread(userId) {
const unreadList = await this.userDao.customQuery(`SELECT COUNT(1) AS num FROM \`msghistory\` WHERE isRead = 0 AND targetId = ${userId}`);
let count = 0;
......
......@@ -85,10 +85,10 @@ module.exports = function (app) {
const invokeObj = System.getObject(`api.${classPath}`);
if (invokeObj.doexec) {
p = invokeObj.doexec.apply(invokeObj, params);
p.then((r) => {
// res.end(JSON.stringify(r));
res.json(r);
});
}
p.then((r) => {
// res.end(JSON.stringify(r));
res.json(r);
});
});
};
......@@ -40,10 +40,10 @@ module.exports = function (app) {
const invokeObj = system.getObject(`web.${classPath}`);
if (invokeObj.doexec) {
p = invokeObj.doexec.apply(invokeObj, params);
p.then((r) => {
// res.end(JSON.stringify(r));
res.json(r);
});
}
p.then((r) => {
// res.end(JSON.stringify(r));
res.json(r);
});
});
};
......@@ -45,15 +45,15 @@ class MsgHandler {
const invokeObj = system.getObject(`web.${msg.pkgname}.${msg.cls}`);
if (invokeObj[msg.method]) {
p = invokeObj[msg.method].apply(invokeObj, [msg.data]);
p.then((r) => {
fn(r);
}).then(() => {
console.log('call success');
})
.catch((err) => {
console.log(err);
});
}
p.then((r) => {
fn(r);
}).then(() => {
console.log('call success');
})
.catch((err) => {
console.log(err);
});
});
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment