diff --git a/src/rest/wechat/add.js b/src/rest/wechat/add.js new file mode 100644 index 0000000..487e8b3 --- /dev/null +++ b/src/rest/wechat/add.js @@ -0,0 +1,28 @@ +const dbUtils = require("../../utils/dbUitls"); +module.exports = { + action: "/node/wxmp/addOrUpdate", + method: "post", + execute: (request, response) => { + let {appid, privateKey, projectPath, version, miniapp_appid} = request.body, + form = {appid, privateKey, projectPath, version}, sql + if (form.appid) {//编辑 + let arr = Object.keys(form).filter(e => form[e]).map(e => `${e}='${form[e]}'`) + sql = `update node_wxmp_config set ${arr.join(",")} where appid='${form.appid}'` + } else {//新增 + let cols = [], arr = [] + form.appid = miniapp_appid + Object.keys(form).map(e => { + if (form[e]) { + cols.push(e) + arr.push(`'${form[e]}'`) + } + }) + sql = `insert into node_wxmp_config (${cols.join(",")}) values(${arr.join(",")})` + } + dbUtils.query(sql).then(() => { + response.send({code: 0}) + }).catch(err => { + response.send({code: 1, err: err.sqlMessage}) + }) + } +} diff --git a/src/rest/wechat/confirmZip.js b/src/rest/wechat/confirmZip.js new file mode 100644 index 0000000..dfc5fcb --- /dev/null +++ b/src/rest/wechat/confirmZip.js @@ -0,0 +1,17 @@ +const dbUtils = require("../../utils/dbUitls"); +module.exports = { + action: "/node/wxmp/confirmZip", + method: "post", + execute: (request, response) => { + let id = request.query?.appid, sql = `select * from node_wxmp_config where appid='${id}'` + dbUtils.query(sql).then(res => { + let info = res?.[0] + if (info?.appid) { + response.send({code: 0, data: info}) + } else response.send({code: 1, err: "无法找到小程序信息"}) + }).catch(err => { + console.log(err) + response.send({code: 1, err: err.sqlMessage}) + }) + } +} diff --git a/src/rest/wechat/detail.js b/src/rest/wechat/detail.js new file mode 100644 index 0000000..0feacf0 --- /dev/null +++ b/src/rest/wechat/detail.js @@ -0,0 +1,16 @@ +const dbUtils = require("../../utils/dbUitls"); +module.exports = { + action: "/node/wxmp/detail", + method: "post", + execute: (request, response) => { + let {appid} = request.query + dbUtils.query(`select * from node_dvcp_config where appid='${appid}' limit 0,1`).then(res => { + response.send({ + code: 0, + data: res?.[0] + }) + }).catch(err => { + response.send({code: 1, err: err.sqlMessage}) + }) + } +} diff --git a/src/rest/wechat/getZip.js b/src/rest/wechat/getZip.js new file mode 100644 index 0000000..9da4b28 --- /dev/null +++ b/src/rest/wechat/getZip.js @@ -0,0 +1,32 @@ +const db = require("../../utils/dbUitls"); +const execute = require("../../tools/exec") +const dayjs = require("dayjs") +const fse = require("fs-extra"); +module.exports = { + action: "/node/wxmp/getZip", + method: "post", + execute: (request, response) => { + let id = request.query?.appid, sql = `select * from node_dvcp_config where appid='${id}'` + db.query(sql).then(res => { + let info = res?.[0] + if (info?.appid) { + db.query(`update node_wxmp_config set error=null where appid='${info.appid}'`).then(() => setTimeout(() => { + response.send({code: 0}) + }, 2000)) + execute(`cd /root/node-service/dvcp_v2_wechat&&node bin/pages.js ${id}&&npm run build`) + .then(() => fse.emptyDir(`../wxmpZips/${id}/`)) + .then(() => fse.copy('../dvcp_v2_wechat/dist/build/mp-weixin/', `../wxmpZips/${id}/`)) + .then(() => fse.emptyDir('../dvcp_v2_wechat/dist/build')) + .then(() => { + db.query(`update node_wxmp_config set error='打包时间:${dayjs().format("YYYY-MM-DD HH:mm:ss")}' where appid='${info.appid}'`) + }).catch(err => { + console.log(err) + db.query(`update node_wxmp_config set error='${err}' where appid='${info.appid}'`) + }) + } else response.send({code: 1, err: "无法找到小程序信息"}) + }).catch(err => { + console.log(err) + response.send({code: 1, err: err.sqlMessage}) + }) + } +} diff --git a/src/rest/wechat/list.js b/src/rest/wechat/list.js new file mode 100644 index 0000000..00c10ee --- /dev/null +++ b/src/rest/wechat/list.js @@ -0,0 +1,28 @@ +const dbUtils = require("../../utils/dbUitls"); +module.exports = { + action: "/node/wxmp/list", + method: "post", + execute: (request, response) => { + let total = 0, records = [], {size, current, name} = request.query + Promise.all([ + dbUtils.query(`select 1 from node_dvcp_config`).then(res => { + return total = res.length + }), + new Promise(resolve => { + let sql = `select * from node_dvcp_config where name like '%${name}%' limit ${(current-1)*size},${size}` + dbUtils.query(sql).then(res => { + records = res + resolve() + }).catch(err => { + response.send({code: 1, err: err.sqlMessage}) + }) + }) + + ]).then(() => { + response.send({ + code: 0, + data: {records, total} + }) + }) + } +}