project_account.js 27 KB

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