|
@@ -247,6 +247,7 @@ module.exports = app => {
|
|
|
|
|
|
const renderData = {
|
|
|
accountData,
|
|
|
+ fujianOssPath: ctx.app.config.fujianOssPath,
|
|
|
};
|
|
|
await this.layout('profile/sign.ejs', renderData);
|
|
|
}
|
|
@@ -351,12 +352,22 @@ module.exports = app => {
|
|
|
|
|
|
// 获取账号数据
|
|
|
const accountData = await ctx.service.projectAccount.getDataByCondition({ id: sessionUser.accountId });
|
|
|
-
|
|
|
- if (accountData.sign_path === '') {
|
|
|
- throw '不存在签名';
|
|
|
+ const data = JSON.parse(ctx.request.body.data);
|
|
|
+ let result = false;
|
|
|
+ if (data.type && data.type === 'stamp') {
|
|
|
+ if (!accountData.stamp_path) {
|
|
|
+ throw '不存在签章';
|
|
|
+ }
|
|
|
+ // 删除oss文件
|
|
|
+ await ctx.app.fujianOss.delete(ctx.app.config.fujianOssFolder + accountData.stamp_path);
|
|
|
+ // 删除库
|
|
|
+ result = await ctx.service.projectAccount.update({ stamp_path: null }, { id: sessionUser.accountId });
|
|
|
+ } else {
|
|
|
+ if (accountData.sign_path === '') {
|
|
|
+ throw '不存在签名';
|
|
|
+ }
|
|
|
+ result = await ctx.service.projectAccount.update({ sign_path: '' }, { id: sessionUser.accountId });
|
|
|
}
|
|
|
-
|
|
|
- const result = await ctx.service.projectAccount.update({ sign_path: '' }, { id: sessionUser.accountId });
|
|
|
if (!result) {
|
|
|
throw '移除签名失败';
|
|
|
}
|
|
@@ -412,15 +423,29 @@ module.exports = app => {
|
|
|
const stream = await ctx.getFileStream();
|
|
|
const create_time = Date.parse(new Date()) / 1000;
|
|
|
const fileInfo = path.parse(stream.filename);
|
|
|
- const dirName = 'public/upload/sign';
|
|
|
- const fileName = moment().format('YYYYMMDD') + '_sign_' + create_time + fileInfo.ext;
|
|
|
- await ctx.helper.saveStreamFile(stream, path.join(this.app.baseDir, 'app', dirName, fileName));
|
|
|
- await sendToWormhole(stream);
|
|
|
- const result = await ctx.service.projectAccount.update({ sign_path: fileName }, { id: ctx.session.sessionUser.accountId });
|
|
|
- if (result) {
|
|
|
- responseData.data = { sign_path: fileName };
|
|
|
+ if (stream.fields && stream.fields.type && stream.fields.type === 'stamp') {
|
|
|
+ // const dirName = 'app/public/upload/sign/profile';
|
|
|
+ // const fileName = moment().format('YYYYMMDD') + '_sign_' + create_time + fileInfo.ext;
|
|
|
+ const filepath = `app/public/upload/sign/profile/qianzhang_${create_time + fileInfo.ext}`;
|
|
|
+ await ctx.app.fujianOss.put(ctx.app.config.fujianOssFolder + filepath, stream);
|
|
|
+ await sendToWormhole(stream);
|
|
|
+ const result = await ctx.service.projectAccount.update({ stamp_path: filepath }, { id: ctx.session.sessionUser.accountId });
|
|
|
+ if (result) {
|
|
|
+ responseData.data = { stamp_path: filepath };
|
|
|
+ } else {
|
|
|
+ throw '添加数据库失败';
|
|
|
+ }
|
|
|
} else {
|
|
|
- throw '添加数据库失败';
|
|
|
+ const dirName = 'public/upload/sign';
|
|
|
+ const fileName = moment().format('YYYYMMDD') + '_sign_' + create_time + fileInfo.ext;
|
|
|
+ await ctx.helper.saveStreamFile(stream, path.join(this.app.baseDir, 'app', dirName, fileName));
|
|
|
+ await sendToWormhole(stream);
|
|
|
+ const result = await ctx.service.projectAccount.update({ sign_path: fileName }, { id: ctx.session.sessionUser.accountId });
|
|
|
+ if (result) {
|
|
|
+ responseData.data = { sign_path: fileName };
|
|
|
+ } else {
|
|
|
+ throw '添加数据库失败';
|
|
|
+ }
|
|
|
}
|
|
|
} catch (err) {
|
|
|
this.log(err);
|