Commit bead271e by 庄冰

文档

parent 3a9ffb59
......@@ -33,9 +33,18 @@ class Template extends APIBase {
case "createTemplate"://创建模板
opResult = await this.templateinfoSve.createTemplate(pobj);
break;
case "editTemplateContent"://修改模板内容
opResult = await this.templateinfoSve.editTemplateContent(pobj);
break;
case "updateSwitchStatus"://修改模板启用状态
opResult = await this.templateinfoSve.updateSwitchStatus(pobj);
break;
case "findAndCountAll"://模板列表查询
opResult = await this.templateinfoSve.findAndCountAll(pobj.actionBody);
break;
case "findOneByCode"://模板查询
opResult = await this.templateinfoSve.findOneByCode(pobj);
break;
case "editTemplateTdk"://编辑模板TDK
opResult = await this.templateinfoSve.editTemplateTdk(pobj);
break;
......
......@@ -14,7 +14,7 @@ module.exports = (db, DataTypes) => {
describe: DataTypes.STRING,
pic_url: DataTypes.STRING,
is_enabled: DataTypes.INTEGER,
template_content: DataTypes.STRING,
template_content: DataTypes.JSON,
form_id: DataTypes.INTEGER,
notes: DataTypes.STRING,
user_id: DataTypes.STRING(100),
......
......@@ -5,6 +5,11 @@ class TemplateinfoService extends ServiceBase {
constructor() {
super("common", ServiceBase.getDaoName(TemplateinfoService));
}
async findAndCountAll(obj){
var res = await this.dao.findAndCountAll(obj);
return system.getResultSuccess(res);
}
/**
* 创建模板
* @param {*} pobj
......@@ -20,9 +25,76 @@ class TemplateinfoService extends ServiceBase {
ab.user_name=xctx.username;
ab.company_id=xctx.companyid;
ab.is_enabled=0;
return this.create(ab);
var res = await this.create(ab);
return system.getResultSuccess(res);
}
async findOneByCode(pobj){
var ab = pobj.actionBody;
var xctx = pobj.xctx;
if(!ab){
return system.getResultFail(-100,"参数错误");
}
if(!ab.code){
return system.getResultFail(-101,"模板编码不能为空");
}
var templateInfo = await this.dao.model.findOne({
where:{code:ab.code},raw:true
});
return system.getResultSuccess(templateInfo);
}
/**
* 编辑模板
* @param {*} pobj
*/
async editTemplateContent(pobj){
var ab = pobj.actionBody;
var xctx = pobj.xctx;
if(!ab){
return system.getResultFail(-100,"参数错误");
}
if(!ab.code){
return system.getResultFail(-101,"模板编码不能为空");
}
if(!ab.hasOwnProperty("template_content")){
return system.getResultFail(-102,"模板内容不能为空");
}
var templateInfo = await this.dao.model.findOne({
where:{code:ab.code},raw:true
});
if(!templateInfo || !templateInfo.id){
return system.getResultFail(-300,"未知模板");
}
await this.dao.update({id:templateInfo.id,template_content:ab.template_content});
return system.getResultSuccess();
}
/**
* 修改启用状态
* @param {*} pobj
*/
async updateSwitchStatus(pobj){
var ab = pobj.actionBody;
var xctx = pobj.xctx;
if(!ab){
return system.getResultFail(-100,"参数错误");
}
if(!ab.code){
return system.getResultFail(-101,"模板编码不能为空");
}
if(!ab.hasOwnProperty("is_enabled")){
return system.getResultFail(-102,"启用状态不能为空");
}
if(ab.is_enabled!==0 && ab.is_enabled!==1){
return system.getResultFail(-103,"启用状态参数错误");
}
var templateInfo = await this.dao.model.findOne({
where:{code:ab.code},raw:true
});
if(!templateInfo || !templateInfo.id){
return system.getResultFail(-300,"未知模板");
}
await this.dao.update({id:templateInfo.id,is_enabled:ab.is_enabled});
return system.getResultSuccess();
}
async editTemplateTdk(pobj){
var ab = pobj.actionBody;
var xctx = pobj.xctx;
......
const url = require("url");
const system = require("../../base/system");
const fs = require('fs');
const marked = require("marked");
module.exports = function (app) {
app.get('/doc', function (req, res) {
// if (!req.query.key) {
// res.send("文件不存在!!!");
// return;
// }
// if (req.query.key != "doc12345789") {
// res.send("文件不存在!!!!!!");
// return;
// }
var path = process.cwd() + "/app/front/entry/public/apidoc/README.md";
fs.readFile(path, function (err, data) {
if (err) {
console.log(err);
res.send("文件不存在!");
} else {
str = marked(data.toString());
res.render('apidoc', { str });
}
});
});
app.get('/doc/:forder', function (req, res) {
var path = process.cwd() + "/app/front/entry/public/apidoc/README.md";
fs.readFile(path, function (err, data) {
if (err) {
console.log(err);
res.send("文件不存在!");
} else {
str = marked(data.toString());
res.render('apidoc', { str });
}
});
});
app.get('/doc/api/:forder/:fileName', function (req, res) {
// if (req.url != "/doc/api/platform/fgbusinesschance.md") {
// if (!req.query.key) {
// res.send("文件不存在!!!");
// return;
// }
// if (req.query.key != "doc12345789") {
// res.send("文件不存在!!!!!!");
// return;
// }
// }
var forder = req.params["forder"];
var fileName = req.params["fileName"] || "README.md";
var path = process.cwd() + "/app/front/entry/public/apidoc";
if (forder) {
path = path + "/" + forder + "/" + fileName;
} else {
path = path + "/" + fileName;
}
fs.readFile(path, function (err, data) {
if (err) {
console.log(err);
res.send("文件不存在!");
} else {
str = marked(data.toString());
res.render('apidoc', { str });
}
});
});
};
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="keywords" content="api文档">
<meta name="baidu-site-verification" content="lATAxZAm8y" />
<meta name="viewport" content="width=device-width, initial-scale=0.8, maximum-scale=0.8, user-scalable=1">
<link href="https://cdn.bootcss.com/github-markdown-css/2.8.0/github-markdown.min.css" rel="stylesheet">
</head>
<body>
<div style="width:100%;text-align: center;font-size: 20px;">
API文档
</div>
<div class="markdown-body" style="margin-left:40px;" id="doc-page">
<%- str%>
</div>
</body>
</html>
\ No newline at end of file
## 调用接口方式
## 1. 营销模板相关接口
  1 [营销模板接口](doc/api/customer/template.md)
\ No newline at end of file
<a name="menu" href="/doc">返回主目录</a>
1. [创建模板](#createTemplate)
1. [编辑模板](#editTemplateContent)
1. [修改模板启用状态](#updateSwitchStatus)
1. [获取模板信息](#findOneByCode)
1. [模板列表查询](#findAndCountAll)
1. [编辑模板TDK](#editTemplateTdk)
## **<a name="createTemplate"> 创建模板</a>**
[返回到目录](#menu)
##### URL
[/api/action/template/springBoard]
#### 参数格式 `JSON`
#### HTTP请求方式 `POST`
#### 渠道执行的类型 actionType:createTemplate
``` javascript
{
"actionType":"createTemplate",
"actionBody":{
"template_content":{}
}
}
```
#### 返回结果
```javascript
{
"status": 0,
"msg": "success",
"data": {
"version": 0,
"id": 8,
"template_content": {},
"code": "MT202008071137lsUEvo",
"name": "营销模板",
"company_id": null,
"is_enabled": 0,
"updated_at": "2020-08-07T03:37:06.463Z",
"created_at": "2020-08-07T03:37:06.463Z"
},
"requestId": "de0f3ec095ba4a7b96a197493735b670"
}
```
## **<a name="editTemplateContent"> 编辑模板</a>**
[返回到目录](#menu)
##### URL
[/api/action/template/springBoard]
#### 参数格式 `JSON`
#### HTTP请求方式 `POST`
#### 渠道执行的类型 actionType:editTemplateContent
``` javascript
{
"actionType":"editTemplateContent",
"actionBody":{
"code":"MT202008070923Q71RQ5",
"template_content":{"aaa":1234}
}
}
```
#### 返回结果
```javascript
{
"status": 0,
"msg": "success",
"requestId": "c4658cf6f2f74c23aeee4f821c2476d6"
}
```
## **<a name="updateSwitchStatus"> 修改模板启用状态</a>**
[返回到目录](#menu)
##### URL
[/api/action/template/springBoard]
#### 参数格式 `JSON`
#### HTTP请求方式 `POST`
#### 渠道执行的类型 actionType:updateSwitchStatus
``` javascript
{
"actionType":"updateSwitchStatus",
"actionBody":{
"code":"MT202008070923Q71RQ5",
"is_enabled":1
}
}
```
#### 返回结果
```javascript
{
"status": 0,
"msg": "success",
"requestId": "ea997b55b8ef4f2a9e9389e57077e630"
}
```
## **<a name="findOneByCode"> 获取模板信息</a>**
[返回到目录](#menu)
##### URL
[/api/action/template/springBoard]
#### 参数格式 `JSON`
#### HTTP请求方式 `POST`
#### 渠道执行的类型 actionType:findOneByCode
``` javascript
{
"actionType":"findOneByCode",
"actionBody":{
"code":"MT202008070923Q71RQ5"
}
}
```
#### 返回结果
```javascript
{
"status": 0,
"msg": "success",
"data": {
"id": 5,
"code": "MT202008070923Q71RQ5",
"name": "营销模板",
"title": "鸟啼2",
"keyword": "关键词2",
"describe": "描述2",
"pic_url": "https://gsb-zc.oss-cn-beijing.aliyuncs.com/zc_picUrl371415960733478082020630.jpg",
"is_enabled": 1,
"template_content": "{\"aaa\":1234}",
"form_id": null,
"notes": null,
"user_id": null,
"user_name": null,
"company_id": null,
"created_at": "2020-08-07T01:24:22.000Z",
"updated_at": "2020-08-07T03:26:39.000Z",
"deleted_at": null,
"version": 0
},
"requestId": "38f332552bae47e4b6ad1fb2c4cc4eaa"
}
```
## **<a name="findAndCountAll"> 模板列表查询</a>**
[返回到目录](#menu)
##### URL
[/api/action/template/springBoard]
#### 参数格式 `JSON`
#### HTTP请求方式 `POST`
#### 渠道执行的类型 actionType:findAndCountAll
``` javascript
{
"actionType":"findAndCountAll",
"actionBody":{
"pageInfo":{
"pageNo":1,
"pageSize":10
},
"search":{
"is_enabled":""
}
}
}
```
#### 返回结果
```javascript
{
"status": 0,
"msg": "success",
"data": {
"results": {
"count": 8,
"rows": [
{
"id": 8,
"code": "MT202008071137lsUEvo",
"name": "营销模板",
"title": null,
"keyword": null,
"describe": null,
"pic_url": null,
"is_enabled": 0,
"template_content": "{}",
"form_id": null,
"notes": null,
"user_id": null,
"user_name": null,
"company_id": null,
"created_at": "2020-08-07T03:37:06.000Z",
"updated_at": "2020-08-07T03:37:06.000Z",
"deleted_at": null,
"version": 0
},
{
"id": 7,
"code": "MT202008071136DGoQ5s",
"name": "营销模板",
"title": null,
"keyword": null,
"describe": null,
"pic_url": null,
"is_enabled": 0,
"template_content": "{}",
"form_id": null,
"notes": null,
"user_id": null,
"user_name": null,
"company_id": null,
"created_at": "2020-08-07T03:36:16.000Z",
"updated_at": "2020-08-07T03:36:16.000Z",
"deleted_at": null,
"version": 0
}
]
},
"aggresult": {}
},
"requestId": "3a88164f9b9d445bb1fad8ec271cd79f"
}
```
## **<a name="editTemplateTdk"> 编辑模板TDK</a>**
[返回到目录](#menu)
##### URL
[/api/action/template/springBoard]
#### 参数格式 `JSON`
#### HTTP请求方式 `POST`
#### 渠道执行的类型 actionType:editTemplateTdk
``` javascript
{
"actionType":"editTemplateTdk",
"actionBody":{
"code":"MT202008070923Q71RQ5",
"title":"鸟啼2",
"keyword":"关键词2",
"pic_url":"https://gsb-zc.oss-cn-beijing.aliyuncs.com/zc_picUrl371415960733478082020630.jpg",
"describe":"描述2"
}
}
```
#### 返回结果
```javascript
{
"status": 0,
"msg": "success",
"requestId": "13126433a9e044c58912d0f00f5a33c5"
}
```
......@@ -37,6 +37,7 @@
"gm": "^1.23.1",
"jsonwebtoken": "^8.5.1",
"log4js": "^2.10.0",
"marked": "^1.1.1",
"method-override": "^2.3.10",
"moment": "^2.26.0",
"morgan": "^1.9.0",
......@@ -65,4 +66,4 @@
"imagemin-pngquant": "^8.0.0",
"merge-stream": "^2.0.0"
}
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment