'use strict'; const MainService = require('../../main'); class accountService extends MainService { constructor(ctx) { super(ctx); const _noNeedLogin = ''; const _noNeedRight = 'getAccountInfo,updatePassword,list,add,delete,update,getBindWechatCode,unbindWechat'; const _noNeedLog = '*'; const _noNeedAuth = 'getAccountInfo,updatePassword,list,add,delete,update,getBindWechatCode,unbindWechat'; this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth); } async callSystemAccount(methodName, data, defaultMessage) { const { service } = this; try { const result = await service.systems.setting.account[methodName](data); return this.success('ok', result); } catch (error) { return this.fail(error.message || defaultMessage, { code: Number(error.code) || 500, }); } } /** * 账号列表。 * @param {Object} data 请求体 */ async list(data = {}) { const { service } = this; try { this.prepareWhereContext(data, { specialFieldMap: { employee_id: { field: 'id', }, account_id: { field: 'account_id', }, username: { field: '$account.username$', }, phone: { field: '$account.phone$', }, email: { field: '$account.email$', }, quickWhere: { bucket: 'quick', }, }, }); const result = await service.systems.setting.account.list(data); return this.success('ok', result); } catch (error) { return this.fail(error.message || '获取工号列表失败', { code: Number(error.code) || 500, }); } } /** * 新增工号。 * @param {Object} data 请求体 */ async add(data = {}) { return this.callSystemAccount('add', data, '添加工号失败'); } /** * 删除工号。 * @param {Object} data 请求体 */ async delete(data = {}) { return this.callSystemAccount('delete', data, '删除工号失败'); } /** * 更新工号。 * @param {Object} data 请求体 */ async update(data = {}) { return this.callSystemAccount('update', data, '更新工号失败'); } /** * 为其他账号获取微信绑定码。 * @param {Object} data 请求体 */ async getBindWechatCode(data = {}) { return this.callSystemAccount('getBindWechatCode', data, '获取账号绑定微信码失败'); } /** * 为其他账号解绑微信。 * @param {Object} data 请求体 */ async unbindWechat(data = {}) { return this.callSystemAccount('unbindWechat', data, '解绑账号微信失败'); } } module.exports = accountService;