123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841 |
- 'use strict';
- /**
- *
- *
- * @author Mai
- * @date
- * @version
- */
- const officeList = require('../const/cld_office').list;
- const settingConst = require('../const/setting.js');
- const settingMenu = require('../../config/menu').settingMenu;
- const accountGroup = require('../const/account_group').group;
- const permission = require('../const/account_permission').permission;
- const projectLog = require('../const/project_log');
- const imType = require('../const/tender').imType;
- const S2b = require('../lib/s2b');
- const measureType = require('../const/tender').measureType;
- module.exports = app => {
- class SettingController extends app.BaseController {
- /**
- * 构造函数
- *
- * @param {Object} ctx - egg全局context
- * @return {void}
- */
- constructor(ctx) {
- super(ctx);
- ctx.subMenu = settingMenu;
- }
- async _checkMenu(pid) {
- const ctx = this.ctx;
- await this.ctx.service.s2bProj.refreshSessionS2b(pid);
- ctx.subMenu.s2b.display = !!ctx.session.sessionProject.gxby || !!ctx.session.sessionProject.dagl;
- // this.ctx.subMenu.s2b.display = false;
- }
- /**
- * 项目信息页面(Get)
- *
- * @param {Object} ctx - egg全局变量
- * @return {void}
- */
- async info(ctx) {
- try {
- // 获取项目数据
- const projectId = ctx.session.sessionProject.id;
- await this._checkMenu(projectId);
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) {
- throw '没有对应的项目数据';
- }
- // 获取销售人员数据
- const salesmanData = await ctx.service.manager.getDataById(projectData.manager_id);
- // 数据规则
- const rule = ctx.service.project.rule('saveInfo');
- const jsValidator = await this.jsValidator.convert(rule).build();
- const officeName = officeList[salesmanData.office];
- const date = new Date(projectData.create_time * 1000);// 如果date为10位不需要乘1000
- const Y = date.getFullYear() + '-';
- const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
- const D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
- const h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
- const m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
- const s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
- const dateStr = Y + M + D + h + m + s;
- const renderData = {
- projectData,
- salesmanData,
- officeName,
- officeList,
- jsValidator,
- dateStr,
- };
- await this.layout('setting/info.ejs', renderData);
- } catch (error) {
- console.log(error);
- ctx.redirect('/dashboard');
- }
- }
- /**
- * 项目设置 -- 账号设置(Get)
- * @param ctx
- * @return {Promise<void>}
- */
- async user(ctx) {
- try {
- // 获取项目数据
- const projectId = ctx.session.sessionProject.id;
- await this._checkMenu(projectId);
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) {
- throw '没有对应的项目数据';
- }
- if (ctx.session.sessionUser.is_admin === 0) {
- throw '没有访问权限';
- }
- let keyword = '';
- if (ctx.query.keyword) {
- keyword = ctx.query.keyword;
- }
- const page = ctx.page;
- const pageSize = ctx.pageSize;
- // 过滤数据
- ctx.service.projectAccount.searchFilter(ctx.request.query, projectId);
- ctx.sort = ['id', 'desc'];
- const total = await ctx.service.projectAccount.getCountWithBuilder();
- // 获取数据规则
- // const rule = ctx.service.projectAccount.rule('updateUser');
- // const frontRule = ctx.helper.validateConvert(rule);
- // const total = await ctx.service.projectAccount.count({ project_id: projectId });
- // 获取项目用户列表
- // const accountData = await ctx.service.projectAccount.getAllDataByCondition({
- // where: { project_id: projectId },
- // columns: ['id', 'account', 'name', 'company', 'role', 'mobile', 'auth_mobile', 'telephone', 'enable', 'is_admin', 'account_group'],
- // limit: (app.config.pageSize * (page - 1)),
- // offset: app.config.pageSize,
- // });
- // const columns = ['id', 'account', 'name', 'company', 'role', 'mobile', 'auth_mobile', 'telephone', 'enable', 'is_admin', 'account_group', 'bind'];
- // const accountData = await ctx.service.projectAccount.getListByProjectId(columns, projectId);
- const accountData = await ctx.service.projectAccount.getListWithBuilder();
- // 获取账号个数
- const user_total = await ctx.service.projectAccount.count({ project_id: projectId });
- // 分页相关
- const pageInfo = {
- page,
- pageSizeSelect: 1,
- pageSize,
- total_num: total,
- total: Math.ceil(total / pageSize),
- queryData: JSON.stringify(ctx.urlInfo.query),
- };
- const renderData = {
- projectData,
- accountData,
- accountGroup,
- permission,
- pageInfo,
- keyword,
- user_total,
- // rule: JSON.stringify(frontRule),
- };
- await this.layout('setting/user.ejs', renderData, 'setting/user_modal.ejs');
- } catch (error) {
- console.log(error);
- ctx.redirect('/dashboard');
- }
- }
- /**
- * 项目设置 -- 账号解绑设置(Post)
- * @param ctx
- * @return {Promise<void>}
- */
- async userUnbind(ctx) {
- const projectData = ctx.session.sessionProject;
- try {
- if (projectData.id === undefined) {
- throw '不存在对应的项目数据';
- }
- if (ctx.session.sessionUser.is_admin === 0) {
- throw '非管理员无权解绑账号';
- }
- const accountId = parseInt(ctx.request.body.id);
- const result = await ctx.service.projectAccount.update({ bind: 0 }, { id: accountId });
- if (!result) {
- throw '解绑失败';
- }
- this.setMessage('解绑成功', this.messageType.SUCCESS);
- } catch (error) {
- console.log(error);
- this.setMessage(error.toString(), this.messageType.ERROR);
- }
- ctx.redirect(ctx.request.header.referer);
- }
- /**
- * 项目权限 -- 账号设置(Get)
- * @param ctx
- * @return {Promise<void>}
- */
- async userPermissionSet(ctx) {
- try {
- // 获取项目数据
- const projectId = ctx.session.sessionProject.id;
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) {
- throw '没有对应的项目数据';
- }
- if (ctx.session.sessionUser.is_admin === 0) {
- throw '没有访问权限';
- }
- // 获取数据规则
- // const rule = ctx.service.projectAccount.rule('updateUser');
- // const frontRule = ctx.helper.validateConvert(rule);
- const page = ctx.page;
- const pageSize = ctx.pageSize;
- ctx.sort = ['id', 'desc'];
- const total = await ctx.service.projectAccount.count({ project_id: projectId });
- // 获取项目用户列表
- // const accountData = await ctx.service.projectAccount.getAllDataByCondition({
- // where: { project_id: projectId },
- // columns: ['id', 'account', 'name', 'company', 'role', 'is_admin', 'account_group', 'permission', 'cooperation'],
- // });
- const columns = ['id', 'account', 'name', 'company', 'role', 'is_admin', 'account_group', 'permission', 'cooperation'];
- const accountData = await ctx.service.projectAccount.getListByProjectId(columns, projectId);
- // 分页相关
- const pageInfo = {
- page,
- pageSizeSelect: 1,
- pageSize,
- total_num: total,
- total: Math.ceil(total / pageSize),
- queryData: JSON.stringify(ctx.urlInfo.query),
- };
- const renderData = {
- projectData,
- accountData,
- accountGroup,
- permission,
- permissionStr: JSON.stringify(permission),
- pageInfo,
- // rule: JSON.stringify(frontRule),
- };
- await this.layout('setting/user_permission.ejs', renderData, 'setting/user_permission_modal.ejs');
- } catch (error) {
- console.log(error);
- ctx.redirect('/dashboard');
- }
- }
- /**
- * 项目设置 -- 账号启用和停用设置(Post)
- * @param ctx
- * @return {Promise<void>}
- */
- async userSwitch(ctx) {
- const responseData = {
- err: 0, msg: '', data: null,
- };
- try {
- // 获取项目数据
- const projectId = ctx.session.sessionProject.id;
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) {
- throw '没有对应的项目数据';
- }
- if (ctx.session.sessionUser.is_admin === 0) {
- throw '没有访问权限';
- }
- const data = JSON.parse(ctx.request.body.data);
- const result = await ctx.service.projectAccount.update(data, { id: data.id });
- if (!result) {
- throw '提交数据失败';
- }
- } catch (err) {
- this.log(err);
- responseData.err = 1;
- responseData.msg = err;
- }
- ctx.body = responseData;
- }
- /**
- * 项目设置 -- 账号添加(Post)
- * @param ctx
- * @return {Promise<void>}
- */
- async addUser(ctx) {
- const projectData = ctx.session.sessionProject;
- try {
- // 验证数据
- if (projectData.id === undefined) {
- throw '不存在对应的项目数据';
- }
- // 获取验证规则
- const rule = ctx.service.projectAccount.rule('add');
- ctx.validate(rule);
- ctx.request.body.project_id = projectData.id;
- const result = await ctx.service.projectAccount.save(ctx.request.body);
- if (!result) {
- throw '保存账号数据失败';
- }
- this.setMessage('保存账号数据成功', this.messageType.SUCCESS);
- ctx.redirect('/' + ctx.controllerName + '/user');
- } catch (error) {
- console.log(error);
- this.setMessage(error.toString(), this.messageType.ERROR);
- ctx.redirect(ctx.request.header.referer);
- }
- }
- /**
- * 项目设置 -- 账号编辑(Post)
- * @param ctx
- * @return {Promise<void>}
- */
- async updateUser(ctx) {
- const projectData = ctx.session.sessionProject;
- try {
- // 验证数据
- if (projectData.id === undefined) {
- throw '不存在对应的项目数据';
- }
- // 获取验证规则
- const rule = ctx.service.projectAccount.rule('modify');
- ctx.validate(rule);
- const result = await ctx.service.projectAccount.save(ctx.request.body);
- if (!result) {
- throw '保存账号数据失败';
- }
- this.setMessage('保存账号数据成功', this.messageType.SUCCESS);
- ctx.redirect(ctx.request.header.referer);
- } catch (error) {
- console.log(error);
- this.setMessage(error.toString(), this.messageType.ERROR);
- ctx.redirect(ctx.request.header.referer);
- }
- }
- async resetUserPassword(ctx) {
- try {
- // 获取项目数据
- const projectId = ctx.session.sessionProject.id;
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) {
- throw '没有对应的项目数据';
- }
- if (ctx.session.sessionUser.is_admin === 0) {
- throw '没有访问权限';
- }
- const accountId = parseInt(ctx.request.body.id);
- let password = ctx.request.body.reset_password;
- password = password.toString();
- const account = ctx.request.body.account !== undefined ? ctx.request.body.account : '';
- if (isNaN(accountId) || accountId <= 0 || password.length < 6) {
- throw '参数错误';
- }
- const result = await ctx.service.projectAccount.resetPassword(accountId, password, account);
- if (!result) {
- throw '重置密码失败!';
- }
- this.setMessage('保存账号数据成功', this.messageType.SUCCESS);
- ctx.redirect(ctx.request.header.referer);
- } catch (error) {
- console.log(error);
- this.setMessage(error.toString(), this.messageType.ERROR);
- ctx.redirect(ctx.request.header.referer);
- }
- }
- /**
- * 项目设置 -- 账号权限编辑(Post)
- * @param ctx
- * @return {Promise<void>}
- */
- async permission(ctx) {
- const projectData = ctx.session.sessionProject;
- try {
- // 验证数据
- if (projectData.id === undefined) {
- throw '不存在对应的项目数据';
- }
- const accountId = parseInt(ctx.request.body.id);
- const accountInfo = await ctx.service.projectAccount.getDataById(accountId);
- if (accountInfo === null) {
- throw '不存在该客户';
- }
- const result = await ctx.service.projectAccount.permissionSave(accountId, ctx.request.body);
- if (!result) {
- throw '修改权限失败!';
- }
- this.setMessage('保存账号数据成功', this.messageType.SUCCESS);
- ctx.redirect(ctx.request.header.referer);
- } catch (error) {
- console.log(error);
- this.setMessage(error.toString(), this.messageType.ERROR);
- ctx.redirect(ctx.request.header.referer);
- }
- }
- /**
- * 项目设置 -- 自定义标段分类(Get)
- *
- * @param ctx
- * @return {Promise<void>}
- */
- async category(ctx) {
- try {
- // 获取项目数据
- const projectId = ctx.session.sessionProject.id;
- await this._checkMenu(projectId);
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) {
- throw '没有对应的项目数据';
- }
- if (ctx.session.sessionUser.is_admin === 0) {
- throw '没有访问权限';
- }
- const categoryData = await ctx.service.category.getAllCategory(projectId);
- const tenderData = await ctx.service.tender.getList('', null, 1);
- const renderData = {
- projectData,
- categoryType: settingConst.cType,
- categoryData,
- tenderData,
- };
- await this.layout('setting/category.ejs', renderData, 'setting/category_modal.ejs');
- } catch (error) {
- console.log(error);
- ctx.redirect('/dashboard');
- }
- }
- /**
- * 新增分类(Ajax)
- *
- * @param ctx
- * @return {Promise<void>}
- */
- async addCategory(ctx) {
- try {
- const projectId = ctx.session.sessionProject.id;
- const responseData = {
- err: 0, msg: '', data: null,
- };
- const data = JSON.parse(ctx.request.body.data);
- if (!data.name) {
- throw '提交数据错误';
- }
- responseData.data = await ctx.service.category.addCategory(projectId, data.name, settingConst.cType.key.dropDown);
- ctx.body = responseData;
- } catch (err) {
- this.log(err);
- ctx.body = { err: 1, msg: err.toString(), data: null };
- }
- }
- /**
- * 编辑分类(Ajax)
- *
- * @param ctx
- * @return {Promise<void>}
- */
- async updateCategory(ctx) {
- try {
- const projectId = ctx.session.sessionProject.id;
- const responseData = { err: 0, msg: '', data: null };
- const data = JSON.parse(ctx.request.body.data);
- if (!data.id) {
- throw '提交数据错误';
- }
- if (data.name) {
- const count = await ctx.service.category.count({ pid: projectId, name: data.name });
- if (count >= 1) {
- throw '存在同名类别';
- }
- }
- const result = await ctx.service.category.update(data, { id: data.id });
- if (!result) {
- throw '提交数据失败';
- }
- responseData.data = await ctx.service.category.getCategory(data.id);
- ctx.body = responseData;
- } catch (err) {
- this.log(err);
- ctx.body = { err: 1, msg: err.toString(), data: null };
- }
- }
- async setCategoryValue(ctx) {
- try {
- const responseData = { err: 0, msg: '', data: {} };
- const data = JSON.parse(ctx.request.body.data);
- if (!data.id) {
- throw '提交数据错误';
- }
- await ctx.service.categoryValue.setCategoryValue(data.id, data.updateValue);
- responseData.data.category = await ctx.service.category.getCategory(data.id);
- responseData.data.tenders = await ctx.service.tender.getList('', null, 1);
- ctx.body = responseData;
- } catch (err) {
- this.log(err);
- ctx.body = { err: 1, msg: err instanceof String ? err : '提交数据失败', data: null };
- }
- }
- /**
- * 删除分类(Ajax)
- *
- * @param ctx
- * @return {Promise<void>}
- */
- async deleteCategory(ctx) {
- try {
- const projectId = ctx.session.sessionProject.id;
- const responseData = {
- err: 0, msg: '', data: null,
- };
- const data = JSON.parse(ctx.request.body.data);
- if (!data.id) {
- throw '提交数据错误';
- }
- await ctx.service.category.deleteCategory(projectId, data.id);
- ctx.body = responseData;
- } catch (err) {
- this.log(err);
- ctx.body = { err: 1, msg: err.toString(), data: null };
- }
- }
- /**
- * 调整分类层次排序(Ajax)
- *
- * @param ctx
- * @return {Promise<void>}
- */
- async resetCategoryLevel(ctx) {
- try {
- const projectId = ctx.session.sessionProject.id;
- const responseData = {
- err: 0, msg: '', data: null,
- };
- const data = JSON.parse(ctx.request.body.data);
- await ctx.service.category.resetCategoryLevel(data);
- responseData.data = await ctx.service.category.getAllCategory(projectId);
- ctx.body = responseData;
- } catch (err) {
- this.log(err);
- ctx.body = { err: 1, msg: err.toString(), data: null };
- }
- }
- /** update porject info
- * @author wangfeng
- * @date 2018-10-12 15:48:05
- * @param ctx
- * @return {Promise<void>}
- */
- async updateinfo(ctx) {
- try {
- const projectId = ctx.params.id;
- const responseData = {
- err: 0, msg: '', data: null,
- };
- const conditionData = {
- id: projectId,
- };
- const data = ctx.request.body;
- const result = await ctx.service.project.update(data, conditionData);
- if (!result) {
- throw '提交数据失败';
- }
- ctx.redirect('/setting/info');
- } catch (err) {
- this.log(err);
- ctx.body = { err: 1, msg: err.toString(), data: null };
- }
- }
- /**
- * 检测账户是否存在
- *
- * @param {Object} ctx -egg全局变量
- * @return {void}
- */
- async accountExist(ctx) {
- const projectData = ctx.session.sessionProject;
- const responseData = {
- err: 0, msg: '', data: null,
- };
- try {
- const data = JSON.parse(ctx.request.body.data);
- const account = data.account;
- if (projectData.id === undefined) {
- throw '不存在对应项目';
- }
- responseData.data = await ctx.service.projectAccount.isAccountExist(account, projectData.id);
- ctx.body = responseData;
- } catch (error) {
- ctx.body = { err: 1, msg: error.toString(), data: null };
- }
- }
- /**
- * 显示设置(Get)
- * @param {Object} ctx -egg全局变量
- * @return {void}
- */
- async show(ctx) {
- try {
- // 获取项目数据
- const projectId = ctx.session.sessionProject.id;
- await this._checkMenu(projectId);
- const projectData = await ctx.service.project.getDataById(projectId);
- if (!projectData) {
- throw '没有对应的项目数据';
- }
- if (ctx.session.sessionUser.is_admin === 0) {
- throw '没有访问权限';
- }
- const showList = await ctx.service.settingShow.getList(projectData.page_path);
- const renderData = { projectData, showList };
- await this.layout('setting/show.ejs', renderData);
- } catch (error) {
- this.log(error);
- ctx.redirect('/dashboard');
- }
- }
- /**
- * 更新显示设置列表
- * @param {Object} ctx -egg全局变量
- * @return {void}
- */
- async showListUpdate(ctx) {
- try {
- // 获取项目id
- const projectId = ctx.session.sessionProject.id;
- const { data } = ctx.request.body;
- const { id } = JSON.parse(data);
- const result = await ctx.service.settingShow.setDefaultLabel(id, projectId);
- const responseData = { err: 0, msg: '', data: result };
- ctx.body = responseData;
- } catch (error) {
- this.log(error);
- ctx.body = { err: 1, msg: error.toString(), data: null };
- }
- }
- async logs(ctx) {
- try {
- // 获取项目数据
- const projectId = ctx.session.sessionProject.id;
- await this._checkMenu(projectId);
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) {
- throw '没有对应的项目数据';
- }
- if (ctx.session.sessionUser.is_admin === 0) {
- throw '没有访问权限';
- }
- const settingType = ctx.params.type ? parseInt(ctx.params.type) : 0;
- const logs = await ctx.service.projectLog.getLogs(projectId, settingType);
- const renderData = {
- projectData,
- officeList,
- projectLog,
- settingType,
- logs,
- };
- await this.layout('setting/logs.ejs', renderData);
- } catch (error) {
- console.log(error);
- ctx.redirect('/dashboard');
- }
- }
- async fun(ctx) {
- try {
- const projectId = ctx.session.sessionProject.id;
- await this._checkMenu(projectId);
- const projectData = await ctx.service.project.getDataById(projectId);
- const funRela = await ctx.service.project.getFunRela(projectId);
- if (projectData === null) {
- throw '没有对应的项目数据';
- }
- if (ctx.session.sessionUser.is_admin === 0) {
- throw '没有访问权限';
- }
- await this.layout('setting/fun.ejs', {
- projectData,
- funRela,
- imType,
- })
- } catch (error) {
- ctx.helper.log(error);
- ctx.redirect('/dashboard');
- }
- }
- /**
- * 保存功能设置相关
- * @param ctx
- * @returns {Promise<void>}
- */
- async updateFun(ctx) {
- try {
- const projectId = ctx.session.sessionProject.id;
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) {
- throw '没有对应的项目数据';
- }
- if (ctx.session.sessionUser.is_admin === 0) {
- throw '没有访问权限';
- }
- const data = JSON.parse(ctx.request.body.data);
- if (data) ctx.request.body = data;
- const rule = ctx.service.project.rule('fun');
- ctx.validate(rule);
- const result = await ctx.service.project.updateFunRela(projectId, ctx.request.body);
- if (!result) throw '保存数据失败';
- ctx.body = {err: 0, msg: '', data: null};
- } catch(error) {
- ctx.helper.log(error);
- this.ajaxErrorBody(error, '保存数据失败');
- }
- }
- async s2b (ctx) {
- try {
- const projectId = ctx.session.sessionProject.id;
- await this._checkMenu(projectId);
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) throw '没有对应的项目数据';
- if (ctx.session.sessionUser.is_admin === 0) throw '没有访问权限';
- const tenders = await ctx.service.tender.getAllDataByCondition({ where: { project_id: projectId } });
- for (const t of tenders) {
- t.measure_type_str = t.measure_type === measureType.tz.value ? measureType.tz.title : measureType.gcl.title;
- const stages = await ctx.service.stage.getAllDataByCondition({ where: { tid: t.id } });
- t.stage_count_str = `第${stages.length || 0}期`;
- const user = await ctx.service.projectAccount.getAccountInfoById(t.user_id);
- t.user_str = user.name + '-' + user.company;
- t.show_time = stages.length > 0 ? stages[stages.length - 1].cache_time_r || stages[stages.length - 1].in_time : t.create_time;
- }
- await this.layout('setting/s2b.ejs', {
- projectData,
- tenders,
- })
- } catch (error) {
- ctx.helper.log(error);
- ctx.redirect('/dashboard');
- }
- }
- async s2bUpdate(ctx) {
- try {
- const projectId = ctx.session.sessionProject.id;
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) throw '没有对应的项目数据';
- if (ctx.session.sessionUser.is_admin === 0) throw '没有访问权限';
- const data = JSON.parse(ctx.request.body.data);
- if (!data.tid) throw '提交数据错误';
- const updateData = {};
- if (data.gxby_limit !== undefined) updateData.s2b_gxby_limit = data.gxby_limit;
- if (data.gxby_check !== undefined) updateData.s2b_gxby_check = data.gxby_check;
- if (data.dagl_limit !== undefined) updateData.s2b_dagl_limit = data.dagl_limit;
- if (data.dagl_check !== undefined) updateData.s2b_dagl_check = data.dagl_check;
- await ctx.service.tender.saveApiRela(data.tid, updateData);
- ctx.body = { err: 0, msg: '', data: null };
- } catch (error) {
- ctx.helper.log(error);
- this.ajaxErrorBody(error, '保存数据失败');
- }
- }
- async s2bUpdateStatus(ctx) {
- try {
- const projectId = ctx.session.sessionProject.id;
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) throw '没有对应的项目数据';
- if (ctx.session.sessionUser.is_admin === 0) throw '没有访问权限';
- const data = JSON.parse(ctx.request.body.data);
- console.log(data);
- if (!data.type || data.status === undefined) throw '提交数据错误';
- const responseData = { err: 0, msg: '', data: null };
- switch (data.type) {
- case 'gxby':
- responseData.data = await this.ctx.service.s2bProj.updateGxbyStatus(projectId, data.status, data.limit, data.ratio);
- break;
- case 'dagl':
- responseData.data = await this.ctx.service.s2bProj.updateDaglStatus(projectId, data.status, data.limit, data.ratio);
- break;
- default: throw '提交数据错误';
- }
- ctx.body = responseData;
- } catch (error) {
- console.log(error);
- ctx.helper.log(error);
- this.ajaxErrorBody(error, '保存数据失败');
- }
- }
- }
- return SettingController;
- };
|