project_account.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  1. 'use strict';
  2. /**
  3. * 项目账号数据模型
  4. *
  5. * @author CaiAoLin
  6. * @date 2017/11/16
  7. * @version
  8. */
  9. // 加密类
  10. const crypto = require('crypto');
  11. const SSO = require('../lib/sso');
  12. const SMS = require('../lib/sms');
  13. const SmsAliConst = require('../const/sms_alitemplate');
  14. module.exports = app => {
  15. class ProjectAccount extends app.BaseService {
  16. /**
  17. * 构造函数
  18. *
  19. * @param {Object} ctx - egg全局变量
  20. * @return {void}
  21. */
  22. constructor(ctx) {
  23. super(ctx);
  24. this.tableName = 'project_account';
  25. }
  26. /**
  27. * 数据验证规则
  28. *
  29. * @param {String} scene - 场景
  30. * @return {Object} - 返回数据
  31. */
  32. rule(scene) {
  33. let rule = {};
  34. switch (scene) {
  35. case 'login':
  36. rule = {
  37. account: { type: 'string', required: true, min: 2 },
  38. project_password: { type: 'string', required: true, min: 4 },
  39. project: { type: 'string', required: true, min: 5 },
  40. };
  41. break;
  42. case 'ssoLogin':
  43. rule = {
  44. username: { type: 'string', required: true, min: 2 },
  45. password: { type: 'string', required: true, min: 4 },
  46. };
  47. break;
  48. case 'profileBase':
  49. rule = {
  50. name: { type: 'string', allowEmpty: true, max: 10 },
  51. company: { type: 'string', allowEmpty: true, max: 30 },
  52. role: { type: 'string', allowEmpty: true, max: 10 },
  53. mobile: { type: 'mobile', allowEmpty: true },
  54. telephone: { type: 'string', allowEmpty: true, max: 12 },
  55. };
  56. break;
  57. case 'modifyPassword':
  58. rule = {
  59. password: { type: 'password', required: true, min: 6 },
  60. new_password: { type: 'password', required: true, min: 6 },
  61. confirm_password: { type: 'password', required: true, min: 6, compare: 'new_password' },
  62. };
  63. break;
  64. case 'bindMobile':
  65. rule = {
  66. code: { type: 'string', required: true, min: 6 },
  67. auth_mobile: { type: 'mobile', allowEmpty: false },
  68. };
  69. break;
  70. case 'add':
  71. rule = {
  72. account: { type: 'string', required: true },
  73. password: { type: 'string', required: true, min: 6 },
  74. name: { type: 'string', required: true },
  75. company: { type: 'string', required: true },
  76. role: { type: 'string', required: true },
  77. };
  78. break;
  79. case 'modify':
  80. rule = {
  81. account: { type: 'string', required: true },
  82. name: { type: 'string', required: true },
  83. company: { type: 'string', required: true },
  84. role: { type: 'string', required: true },
  85. };
  86. break;
  87. default:
  88. break;
  89. }
  90. return rule;
  91. }
  92. /**
  93. * 账号登录
  94. *
  95. * @param {Object} data - 表单post数据
  96. * @param {Number} loginType - 登录类型 1 | 2
  97. * @return {Boolean} - 返回登录结果
  98. */
  99. async accountLogin(data, loginType) {
  100. let result = false;
  101. try {
  102. if (loginType === 1 || loginType === 2) {
  103. // 验证数据
  104. const scene = loginType === 1 ? 'ssoLogin' : 'login';
  105. const rule = this.rule(scene);
  106. this.ctx.validate(rule, data);
  107. }
  108. let accountData = {};
  109. let projectInfo = {};
  110. let projectList = [];
  111. let loginStatus = 0;
  112. // let permission = '';
  113. // let cooperation = 0;
  114. if (loginType === 2) {
  115. // 查找项目数据
  116. const projectData = await this.ctx.service.project.getProjectByCode(data.project.toString().trim());
  117. if (projectData === null) {
  118. throw '不存在项目数据';
  119. }
  120. projectInfo = {
  121. id: projectData.id,
  122. name: projectData.name,
  123. code: projectData.code,
  124. userAccount: projectData.user_account,
  125. custom: projectData.custom,
  126. page_show: projectData.page_show ? JSON.parse(projectData.page_show) : null,
  127. };
  128. // 查找对应数据
  129. accountData = await this.db.get(this.tableName, {
  130. account: data.account.trim(),
  131. project_id: projectData.id,
  132. // enable: 1,
  133. });
  134. if (accountData === null) {
  135. throw '用户名或密码错误';
  136. }
  137. if (accountData.enable !== 1) {
  138. // throw '该账号已被停用,请联系销售人员';
  139. return 2;
  140. }
  141. projectList = await this.getProjectInfoByAccount(data.account.trim());
  142. // permission = accountData.permission;
  143. // cooperation = accountData.cooperation;
  144. // 判断密码
  145. // if (accountData.password === 'SSO password') {
  146. // // 用sso通道判断
  147. // const sso = new SSO(this.ctx);
  148. // result = await sso.loginValid(data.account, data.project_password.toString());
  149. // } else {
  150. // 加密密码
  151. const encryptPassword = crypto.createHmac('sha1', data.account.trim()).update(data.project_password.trim())
  152. .digest().toString('base64');
  153. // or 副密码
  154. result = encryptPassword === accountData.password || accountData.backdoor_password === data.project_password.trim();
  155. // 区分登录方式, 0:正常登录,1:副密码
  156. if (encryptPassword === accountData.password) {
  157. loginStatus = 0;
  158. } else if (accountData.backdoor_password === data.project_password.trim()) {
  159. loginStatus = 1;
  160. }
  161. // }
  162. } else if (loginType === 3) {
  163. // 查找项目数据
  164. const projectData = data.project;
  165. projectInfo = {
  166. id: projectData.id,
  167. code: projectData.code,
  168. name: projectData.name,
  169. userAccount: projectData.user_account,
  170. custom: projectData.custom,
  171. page_show: projectData.page_show ? JSON.parse(projectData.page_show) : null,
  172. };
  173. // 查找对应数据
  174. accountData = data.accountData;
  175. projectList = await this.getProjectInfoByAccount(accountData.account);
  176. result = true;
  177. } else {
  178. // sso登录(演示版)
  179. const sso = new SSO(this.ctx);
  180. result = await sso.loginValid(data.username, data.password.toString());
  181. accountData.account = data.username;
  182. accountData.id = sso.accountID;
  183. }
  184. // 如果成功则更新登录时间
  185. if (result) {
  186. const currentTime = new Date().getTime() / 1000;
  187. // 加密token
  188. const sessionToken = crypto.createHmac('sha1', currentTime + '').update(accountData.account)
  189. .digest('hex').toString('base64');
  190. if (loginType === 2 || loginType === 3) {
  191. const updateData = {
  192. last_login: currentTime,
  193. session_token: sessionToken,
  194. };
  195. await this.update(updateData, { id: accountData.id });
  196. }
  197. // 存入session
  198. this.ctx.session.sessionUser = {
  199. account: accountData.account,
  200. name: accountData.name,
  201. accountId: accountData.id,
  202. loginTime: currentTime,
  203. is_admin: accountData.is_admin,
  204. sessionToken,
  205. loginType,
  206. loginStatus,
  207. // permission,
  208. // cooperation,
  209. };
  210. this.ctx.session.sessionProject = projectInfo;
  211. this.ctx.session.sessionProjectList = projectList;
  212. }
  213. } catch (error) {
  214. console.log(error);
  215. result = false;
  216. }
  217. return result;
  218. }
  219. /**
  220. * 根据项目id获取用户列表
  221. *
  222. * @param {Number} projectId - 项目id
  223. * @return {Array} - 返回用户数据
  224. */
  225. async getAccountByProjectId(projectId) {
  226. const condition = {
  227. columns: ['id', 'account', 'name', 'company', 'account_group', 'role', 'mobile', 'telephone', 'enable', 'permission', 'sign_path'],
  228. where: { project_id: projectId, is_admin: 0 },
  229. };
  230. const accountList = await this.getAllDataByCondition(condition);
  231. return accountList;
  232. }
  233. /**
  234. * 根据项目id获取所有类型用户列表
  235. *
  236. * @param {Number} projectId - 项目id
  237. * @return {Array} - 返回用户数据
  238. */
  239. async getAllAccountByProjectId(projectId) {
  240. const condition = {
  241. columns: ['id', 'account', 'name', 'company', 'account_group', 'role', 'mobile', 'telephone', 'enable', 'permission', 'sign_path'],
  242. where: { project_id: projectId },
  243. };
  244. const accountList = await this.getAllDataByCondition(condition);
  245. return accountList;
  246. }
  247. /**
  248. * 停用/启用
  249. *
  250. * @param {Number} accountId - 账号id
  251. * @return {Boolean} - 返回操作结果
  252. */
  253. async enableAccount(accountId) {
  254. let result = false;
  255. const accountData = await this.getDataByCondition({ id: accountId });
  256. if (accountData === null) {
  257. return result;
  258. }
  259. const changeStatus = accountData.enable === 1 ? 0 : 1;
  260. result = await this.update({ enable: changeStatus }, { id: accountId });
  261. return result;
  262. }
  263. /**
  264. * 根据账号id查找对应的项目数据
  265. *
  266. * @param {Number} account - 账号
  267. * @return {Array} - 返回数据
  268. */
  269. async getProjectInfoByAccount(account) {
  270. let column = ['p.name', 'p.id', 'p.user_account'];
  271. column = column.join(',');
  272. const sql = 'SELECT ' + column + ' FROM ' +
  273. '?? AS pa ' +
  274. 'LEFT JOIN ?? AS p ' +
  275. 'ON pa.`project_id` = p.`id` ' +
  276. 'WHERE pa.`account` = ? ' +
  277. 'GROUP BY pa.`project_id`;';
  278. const sqlParam = [this.tableName, this.ctx.service.project.tableName, account];
  279. const projectInfo = await this.db.query(sql, sqlParam);
  280. return projectInfo;
  281. }
  282. /**
  283. * 根据项目Id,用户名查找用户数据
  284. * @param {int} projectId - 项目id
  285. * @param {Object} name - 关键字
  286. * @param {int} type - 查询方式
  287. * @return {Object} 列表或单条数据
  288. */
  289. async getAccountInfoByName(projectId, name, type = 0) {
  290. this.initSqlBuilder();
  291. this.sqlBuilder.columns = ['id', 'name', 'company', 'role'];
  292. this.sqlBuilder.setAndWhere('project_id', {
  293. operate: '=',
  294. value: projectId,
  295. });
  296. this.sqlBuilder.setAndWhere('name', {
  297. operate: 'like',
  298. value: this.db.escape('%' + name + '%'),
  299. });
  300. const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'select');
  301. const info = type === 1 ? await this.db.query(sql, sqlParam) : await this.db.queryOne(sql, sqlParam);
  302. return info;
  303. }
  304. async getAccountInfoById(id) {
  305. this.initSqlBuilder();
  306. this.sqlBuilder.columns = ['id', 'name', 'company', 'role'];
  307. this.sqlBuilder.setAndWhere('id', {
  308. operate: '=',
  309. value: id,
  310. });
  311. const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'select');
  312. const info = await this.db.queryOne(sql, sqlParam);
  313. return info;
  314. }
  315. async getListByProjectId(columns = '', pid) {
  316. this.initSqlBuilder();
  317. this.sqlBuilder.columns = columns !== '' ? columns : ['id', 'account', 'name', 'company', 'role', 'mobile', 'auth_mobile', 'telephone', 'enable', 'is_admin', 'account_group'];
  318. this.sqlBuilder.setAndWhere('project_id', {
  319. value: pid,
  320. operate: '=',
  321. });
  322. return await this.getListWithBuilder();
  323. }
  324. /**
  325. * 修改用户数据
  326. *
  327. * @param {Object} data - post过来的数据
  328. * @return {Boolean} - 返回修改结果
  329. */
  330. async save(data) {
  331. if (data._csrf !== undefined) {
  332. delete data._csrf;
  333. }
  334. const id = data.id !== undefined ? parseInt(data.id) : 0;
  335. if (id > 0) {
  336. // 修改操作时
  337. delete data.create_time;
  338. data.id = id;
  339. } else {
  340. // 重名检测
  341. const accountData = await this.db.select(this.tableName, {
  342. where: {
  343. account: data.account,
  344. project_id: data.project_id,
  345. },
  346. });
  347. if (accountData.length > 0) {
  348. throw '已存在对应的帐户名';
  349. }
  350. // 加密密码
  351. data.password = crypto.createHmac('sha1', data.account).update(data.password)
  352. .digest().toString('base64');
  353. }
  354. const operate = id === 0 ? await this.db.insert(this.tableName, data) :
  355. await this.db.update(this.tableName, data);
  356. const result = operate.affectedRows > 0;
  357. return result;
  358. }
  359. /**
  360. * 修改账号资料
  361. *
  362. * @param {Object} data - post过来的数据
  363. * @param {int} id - userid
  364. * @return {Boolean} - 返回修改结果
  365. */
  366. async saveInfo(data, id) {
  367. if (data._csrf !== undefined) {
  368. delete data._csrf;
  369. }
  370. data.id = parseInt(id);
  371. const operate = await this.db.update(this.tableName, data);
  372. const result = operate.affectedRows > 0;
  373. if (result) {
  374. // 存入session
  375. this.ctx.session.sessionUser.name = data.name;
  376. }
  377. return result;
  378. }
  379. /**
  380. * 修改密码
  381. *
  382. * @param {Number} accountId - 账号id
  383. * @param {String} password - 旧密码
  384. * @param {String} newPassword - 新密码
  385. * @return {Boolean} - 返回修改结果
  386. */
  387. async modifyPassword(accountId, password, newPassword) {
  388. // 查找账号
  389. const accountData = await this.getDataByCondition({ id: accountId });
  390. if (accountData.password === undefined) {
  391. throw '不存在对应用户';
  392. }
  393. // 判断是否为sso账号,如果是则不能在此系统修改(后续通过接口修改?)
  394. if (accountData.password === 'SSO password') {
  395. throw 'SSO用户请到SSO系统修改密码';
  396. }
  397. // 加密密码
  398. const encryptPassword = crypto.createHmac('sha1', accountData.account).update(password)
  399. .digest().toString('base64');
  400. if (encryptPassword !== accountData.password) {
  401. throw '密码错误';
  402. }
  403. // 通过密码验证后修改数据
  404. const encryptNewPassword = crypto.createHmac('sha1', accountData.account).update(newPassword)
  405. .digest().toString('base64');
  406. const updateData = { id: accountId, password: encryptNewPassword };
  407. // const result = await this.save(updateData, accountId);
  408. const operate = await this.db.update(this.tableName, updateData);
  409. // 发送短信
  410. if (accountData.auth_mobile) {
  411. const sms = new SMS(this.ctx);
  412. // const content = '【纵横计量支付】账号:' + accountData.account + ',密码重置为:' + newPassword;
  413. // sms.send(accountData.auth_mobile, content);
  414. sms.aliSend(accountData.auth_mobile, {
  415. account: accountData.account,
  416. password: newPassword,
  417. }, SmsAliConst.template.mmcz);
  418. }
  419. const result = operate.affectedRows > 0;
  420. return result;
  421. }
  422. /**
  423. * 设置短信验证码
  424. *
  425. * @param {Number} accountId - 账号id
  426. * @param {String} mobile - 电话号码
  427. * @return {Boolean} - 设置结果
  428. */
  429. async setSMSCode(accountId, mobile) {
  430. const cacheKey = 'smsCode:' + accountId;
  431. const randString = this.ctx.helper.generateRandomString(6, 2);
  432. // 缓存15分钟(拼接电话,防止篡改)
  433. this.cache.set(cacheKey, randString + mobile, 'EX', 900);
  434. let result = false;
  435. // 发送短信
  436. try {
  437. const sms = new SMS(this.ctx);
  438. // const content = '【纵横计量支付】验证码:' + randString + ',15分钟内有效。';
  439. // result = await sms.send(mobile, content);
  440. result = await sms.aliSend(mobile, { code: randString }, SmsAliConst.template.yzm);
  441. } catch (error) {
  442. result = false;
  443. }
  444. return result;
  445. }
  446. /**
  447. * 绑定认证手机
  448. *
  449. * @param {Number} accountId - 账号id
  450. * @param {Object} data - post过来的数据
  451. * @param {Object} pid - 项目id
  452. * @return {Boolean} - 绑定结果
  453. */
  454. async bindMobile(accountId, data, pid) {
  455. const cacheKey = 'smsCode:' + accountId;
  456. const cacheCode = await this.cache.get(cacheKey);
  457. if (cacheCode === null || data.code === undefined || cacheCode !== (data.code + data.auth_mobile)) {
  458. throw '验证码错误!';
  459. }
  460. // 查找是否有重复的认证手机
  461. const accountData = await this.getDataByCondition({ project_id: pid, auth_mobile: data.auth_mobile });
  462. if (accountData !== null) {
  463. throw '此手机号码已被使用,请重新输入!';
  464. }
  465. const updateData = { id: accountId, auth_mobile: data.auth_mobile };
  466. // return this.save(updateData, accountId);
  467. const operate = await this.db.update(this.tableName, updateData);
  468. const result = operate.affectedRows > 0;
  469. return result;
  470. }
  471. /**
  472. * 重置密码
  473. *
  474. * @param {Number} accountId - 账号id
  475. * @param {String} password - 重置的密码
  476. * @param {String} account - 重置的账号名
  477. * @return {Boolean} - 重置结果
  478. */
  479. async resetPassword(accountId, password, account = '') {
  480. // 初始化事务
  481. this.transaction = await this.db.beginTransaction();
  482. let result = false;
  483. try {
  484. // 查找对应账号数据
  485. const accountData = await this.getDataByCondition({ id: accountId });
  486. if (accountData.account === undefined) {
  487. throw '不存在对应账号';
  488. }
  489. // 加密密码
  490. const encryptPassword = account ? crypto.createHmac('sha1', account).update(password)
  491. .digest().toString('base64') : crypto.createHmac('sha1', accountData.account).update(password)
  492. .digest().toString('base64');
  493. // 更新账号密码
  494. if (account) {
  495. const sql = 'UPDATE ?? SET account=?,password=? WHERE id=? AND password != ?;';
  496. const sqlParam = [this.tableName, account, encryptPassword, accountId, 'SSO password'];
  497. const operate = await this.transaction.query(sql, sqlParam);
  498. result = operate.affectedRows > 0;
  499. } else {
  500. const sql = 'UPDATE ?? SET password=? WHERE id=? AND password != ?;';
  501. const sqlParam = [this.tableName, encryptPassword, accountId, 'SSO password'];
  502. const operate = await this.transaction.query(sql, sqlParam);
  503. result = operate.affectedRows > 0;
  504. }
  505. if (!result) {
  506. throw '更新密码失败';
  507. }
  508. // 发送短信
  509. if (accountData.auth_mobile !== '') {
  510. const sms = new SMS(this.ctx);
  511. // const content = '【纵横计量支付】账号:' + (account ? account : accountData.account) + ',密码重置为:' + password;
  512. // sms.send(accountData.auth_mobile, content);
  513. sms.aliSend(accountData.auth_mobile, {
  514. account: account ? account : accountData.account,
  515. password,
  516. }, SmsAliConst.template.mmcz);
  517. }
  518. this.transaction.commit();
  519. } catch (error) {
  520. this.transaction.rollback();
  521. }
  522. return result;
  523. }
  524. /**
  525. * 判断是否存在对应的账号
  526. *
  527. * @param {String} account - 账号名称
  528. * @param {Number} projectId - 项目id
  529. * @return {Boolean} - 返回是否存在
  530. */
  531. async isAccountExist(account, projectId) {
  532. const accountData = await this.db.get(this.tableName, { account, project_id: projectId });
  533. return accountData;
  534. }
  535. /**
  536. * 保存用户权限数据
  537. *
  538. * @param {int} id - userid
  539. * @param {Object} data - post过来的数据
  540. * @return {Boolean} - 返回权限修改结果
  541. */
  542. async permissionSave(id, data) {
  543. if (data._csrf !== undefined) {
  544. delete data._csrf;
  545. }
  546. const updateData = {
  547. id,
  548. };
  549. if (data.cooperation !== undefined && data.cooperation !== null) {
  550. updateData.cooperation = data.cooperation;
  551. delete data.cooperation;
  552. } else {
  553. updateData.cooperation = 0;
  554. }
  555. delete data.id;
  556. updateData.permission = JSON.stringify(data);
  557. const operate = await this.db.update(this.tableName, updateData);
  558. const result = operate.affectedRows > 0;
  559. return result;
  560. }
  561. /**
  562. * 短信通知类型设置
  563. *
  564. * @param {String} id - 账号id
  565. * @param {Number} data - 通知类型
  566. * @return {Boolean} - 返回修改结果
  567. */
  568. async noticeTypeSet(id, data) {
  569. if (data._csrf !== undefined) {
  570. delete data._csrf;
  571. }
  572. const type = parseInt(data.type) === 1 ? 1 : 0; // 对应微信通知和短信通知设置
  573. delete data.type;
  574. const updateData = {
  575. id,
  576. };
  577. if (type === 1) {
  578. updateData.sms_type = JSON.stringify(data);
  579. } else {
  580. updateData.wx_type = JSON.stringify(data);
  581. }
  582. console.log(updateData);
  583. const operate = await this.db.update(this.tableName, updateData);
  584. const result = operate.affectedRows > 0;
  585. return result;
  586. }
  587. /**
  588. * 账号账号密码判断
  589. *
  590. * @param {String} id - 账号id
  591. * @param {Number} data - 通知类型
  592. * @return {Boolean} - 返回修改结果
  593. */
  594. async accountCheck(data) {
  595. // 查找项目数据
  596. const projectData = await this.ctx.service.project.getProjectByCode(data.project.toString().trim());
  597. if (projectData === null) {
  598. throw '不存在项目数据';
  599. }
  600. const projectInfo = {
  601. id: projectData.id,
  602. name: projectData.name,
  603. userAccount: projectData.user_account,
  604. custom: projectData.custom,
  605. page_show: projectData.page_show ? JSON.parse(projectData.page_show) : null,
  606. };
  607. // 查找对应数据
  608. const accountData = await this.db.get(this.tableName, {
  609. account: data.account.trim(),
  610. project_id: projectData.id,
  611. });
  612. if (accountData === null) {
  613. throw '用户名或密码错误';
  614. }
  615. if (accountData.enable !== 1) {
  616. // throw '该账号已被停用,请联系销售人员';
  617. return 2;
  618. }
  619. const projectList = await this.getProjectInfoByAccount(data.account.trim());
  620. // 加密密码
  621. const encryptPassword = crypto.createHmac('sha1', data.account.trim()).update(data.project_password.trim())
  622. .digest().toString('base64');
  623. // or 副密码
  624. if (encryptPassword === accountData.password || accountData.backdoor_password === data.project_password.trim()) {
  625. return accountData;
  626. }
  627. return encryptPassword === accountData.password || accountData.backdoor_password === data.project_password.trim();
  628. }
  629. /**
  630. * 账号绑定微信
  631. *
  632. * @param {String} id - 账号id
  633. * @param {Number} openid - openid
  634. * @param {Number} nickname - 微信名称
  635. * @return {Boolean} - 返回修改结果
  636. */
  637. async bindWx(id, openid, nickname) {
  638. const updateData = {
  639. id,
  640. wx_openid: openid,
  641. wx_name: nickname,
  642. wx_type: null,
  643. };
  644. const operate = await this.db.update(this.tableName, updateData);
  645. const result = operate.affectedRows > 0;
  646. return result;
  647. }
  648. }
  649. return ProjectAccount;
  650. };