1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- 'use strict';
- const assert = require('assert');
- const _ = require('lodash');
- const { ObjectId } = require('mongoose').Types;
- const { CrudService } = require('naf-framework-mongoose/lib/service');
- const { BusinessError, ErrorCode } = require('naf-core').Error;
- class CompanyidentifyService extends CrudService {
- constructor(ctx) {
- super(ctx, 'company_identify');
- this.model = this.ctx.model.Companyidentify;
- this.cmodel = this.ctx.model.Company;
- this.umodel = this.ctx.model.Companyuser;
- this.pmodel = this.ctx.model.Profession;
- this.dmodel = this.ctx.model.Dictionary;
- }
- // 修改企业认证信息表的状态
- async status({ id }, { status }) {
- // 根据id查询企业认证信息表的数据
- const companyidentify = await this.model.findById(id);
- // 如果修改状态为1(审核通过)
- if (status === '1') {
- // 将企业认证信息表中的部分字段提取出来,创建用户对应的企业信息表
- // const newdata = _.pick(companyidentify, [ 'uid', 'company_name', 'introduction', 'registered_addr', 'business_addr', 'profession_one', 'profession_two', 'profession_three', 'profession_four' ]);
- const newdata = _.pick(companyidentify, [ 'uid', 'company_name', 'reg_num', 'type', 'address', 'business', 'capital', 'establish_date', 'valid_period', 'person' ]);
- // 将企业用户表中的权限改为1(认证)
- const companyuser = await this.umodel.findById(companyidentify.uid);
- companyuser.roles = '1';
- await companyuser.save();
- // 给用户发送消息告知认证通过
- this.ctx.service.viewnews.insertViewNews('认证成功', '恭喜您通过了企业认证,您现在可以体验平台更多功能', companyidentify.uid);
- // 增加月报
- const financeinfo = [];
- const now_date = new Date();
- const year = now_date.getFullYear();
- const month = [ '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12' ];
- for (const elm of month) {
- const report_time = year + '-' + elm + '月报';
- const status = '0';
- const fidata = { report_time, status };
- financeinfo.push(fidata);
- }
- // 增加年报
- const yeardata = { report_time: year + '年报', status: '0' };
- financeinfo.push(yeardata);
- newdata.finance_info = financeinfo;
- await this.cmodel.create(newdata);
- }
- companyidentify.status = status;
- await companyidentify.save();
- }
- async fetch({ id }) {
- const companyidentify = await this.model.findById(id);
- if (companyidentify.profession_one) {
- const profession_one = await this.pmodel.findOne({
- code: companyidentify.profession_one,
- });
- companyidentify.profession_one = profession_one.name;
- }
- if (companyidentify.profession_two) {
- const profession_two = await this.pmodel.findOne({
- code: companyidentify.profession_two,
- });
- companyidentify.profession_two = profession_two.name;
- }
- if (companyidentify.profession_three) {
- const profession_three = await this.pmodel.findOne({
- code: companyidentify.profession_three,
- });
- companyidentify.profession_three = profession_three.name;
- }
- if (companyidentify.profession_four) {
- const profession_four = await this.pmodel.findOne({
- code: companyidentify.profession_four,
- });
- companyidentify.profession_four = profession_four.name;
- }
- if (companyidentify.belong_addr_city) {
- const belong_addr_city = await this.dmodel.findOne({
- code: companyidentify.belong_addr_city,
- });
- companyidentify.belong_addr_city = belong_addr_city.name;
- }
- if (companyidentify.belong_addr_city) {
- const belong_addr_area = await this.dmodel.findOne({
- code: companyidentify.belong_addr_area,
- });
- companyidentify.belong_addr_area = belong_addr_area.name;
- }
- return companyidentify;
- }
- }
- module.exports = CompanyidentifyService;
|