diff --git a/src/controller/admin/channel.js b/src/controller/admin/channel.js index df7626a886ae8d5069ca065b384379e132b7c2ea..c035f5a81e1b8b0725f6c960b97ada142ea40684 100644 --- a/src/controller/admin/channel.js +++ b/src/controller/admin/channel.js @@ -84,8 +84,17 @@ module.exports = class extends think.cmswing.admin { if (think.isEmpty(id)) { this.fail('请选择要操作的数据!'); } + let channel = this.model('channel'); + let loca = 0; + do{ + let list = await channel.where({pid:id[loca]}).field('id').select(); + for(let _id of list) + id.push(_id.id); + loca++; + }while (loca < id.length); + // 开始删除 const map = {id: ['IN', id]}; - const res = await this.model('channel').where(map).delete(); + const res = await channel.where(map).delete(); if (res) { await this.model('cmswing/action').log('update_channel', 'channel', id, this.user.uid, this.ip, this.ctx.url);// 记录行为 this.cache('get_channel_cache', null);// 更新频道缓存信息 diff --git a/src/controller/admin/template.js b/src/controller/admin/template.js index 8f567355ca80ca4ec9722f3116f02ac1fb0ff241..171287b9883003b4174e4bcf8de4b5f2462023a0 100644 --- a/src/controller/admin/template.js +++ b/src/controller/admin/template.js @@ -309,11 +309,30 @@ module.exports = class extends think.cmswing.admin { } const templateFile = `${temppath}${data.controller}${this.config('view.nunjucks.sep')}${data.action}${this.config('view.nunjucks.extname')}`; // console.log(templateFile); - const res = await this.model('temp').add(data); - if (!think.isEmpty(res)) { - fs.writeFileSync(templateFile, data.html); - return this.success({name: '添加成功!'}); + let model = this.model('temp'); + + // 检查是否重复 + let cond ={}; + think.extend(cond,data); + delete cond.html; + delete cond.temptype; + delete cond.name; + let empty = await model.where(cond).find(); + if(!think.isEmpty(empty)){ + return this.fail('模板已存在!'); } + return model.transaction(async()=>{ + let res = await model.add(data); + if (!think.isEmpty(res)) { + try{ + fs.writeFileSync(templateFile, data.html); + }catch (e){ + await model.rollback(); + return this.fail('模板创建失败!'); + } + return this.success({name: '添加成功!',id:res}); + } + }); } else { const type = this.get('type'); const temptype = this.get('temptype'); @@ -358,7 +377,7 @@ module.exports = class extends think.cmswing.admin { } else { temppath = `${think.ROOT_PATH}/view/${temp.module}/`; } - const templateFile = `${temppath}${temp.controller}${think.config('view', undefined, 'topic').file_depr}${temp.action}${this.config('view.file_ext')}`; + const templateFile = `${temppath}${temp.controller}${this.config('view.nunjucks.sep')}${temp.action}${this.config('view.nunjucks.extname')}`; // console.log(templateFile); if (think.isFile(templateFile)) { fs.unlinkSync(templateFile); diff --git a/view/admin/template_add.html b/view/admin/template_add.html index 186d82d2079fed966d1e1162ba544458dfb86883..413f564b225c6fbc58bc9b7fe2fa509933d76d45 100644 --- a/view/admin/template_add.html +++ b/view/admin/template_add.html @@ -149,7 +149,7 @@ confirmButtonColor: "#DD6B55", confirmButtonText: "OK", }, function () { - location.reload(); + location.href= "/admin/template/edit?id="+res.data.id; }); }else { swal(res.errmsg,"",'warning')