Commit 5cfee64c by 钟占达

zzd

parent 11d23aab
......@@ -12,8 +12,8 @@ class Templateconfig extends APIBase {
super();
this.imginfoSve = system.getObject("service.configmag.imginfoSve");
this.forminfoSve = system.getObject("service.configmag.forminfoSve")
this.templateinfoSve = system.getObject("service.template.templateinfoSve.js");
// this.templatelinkSve = system.getObject("service.template.templatelinkSve");
this.templateinfoSve = system.getObject("service.template.templateinfoSve");
this.templatelinkSve = system.getObject("service.template.templatelinkSve");
}
/**
* 接口跳转-POST请求
......@@ -47,11 +47,20 @@ class Templateconfig extends APIBase {
opResult = await this.templateinfoSve.getTemplateList(pobj.actionBody);
// opResult = await this.templateinfoSve.findByCompanyId(pobj.actionBody);
break;
case "editTemplate": // 编辑模板信息
opResult = await this.templateinfoSve.editTemplate(pobj);
break;
case "getFormList": // 获取表单列表
var actionBody = pobj.actionBody || {};
actionBody["company_id"] = pobj.company_id;
opResult = await this.forminfoSve.getFormList(pobj.actionBody);
break;
case "getTemplateAndLinkInfo": // 根据链接参数获取模板链接信息
opResult = await this.templatelinkSve.getTemplateAndLinkInfo2(pobj);
break;
case "copyForm": // 复制表单
opResult = await this.forminfoSve.copyForm(pobj.actionBody);
break;
default:
opResult = system.getResult(null, "action_type参数错误");
break;
......
const system = require("../../../system");
const ServiceBase = require("../../sve.base");
const settings = require("../../../../config/settings");
const sha256 = require("sha256");
class TemplateinfoService extends ServiceBase {
constructor() {
super("template", ServiceBase.getDaoName(TemplateinfoService));
this.templatelinkDao = system.getObject("db.template.templatelinkDao")
this.redisClient = system.getObject("util.redisClient");
}
async findByCompanyId(obj){
......@@ -197,5 +200,75 @@ class TemplateinfoService extends ServiceBase {
return system.getResultSuccess();
}
/**
* 编辑模板2
* @param {*} pobj
*/
async editTemplate (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,"模板内容不能为空");
}
// 获取对应模板
let template = await this.findOne({code: ab.code});
if (!template || !template.id) {
return system.getResultFail(-300, "未知模板");
}
if (!template.is_enable === 1) {
return system.getResultFail(-301, "该模板使用中,不能执行此操作");
}
// 更新模板
let obj = {template_content: ab.template_content};
await template.update(obj);
// 获取模板对应模板链接,并删除其redis缓存
let template_id = template.id;
console.log("template_id is " + template_id);
let tls = await this.templatelinkDao.findAll({"template_id": template_id});
console.log("tls.length: " + tls.length);
tls.forEach(async (tl) => {
console.log(tl);
let obj = {
template_id: tl.template_id,
channel_code: tl.channel_code,
else_channel_param: tl.else_channel_param,
business_type_code: tl.business_type_code,
lauch_type_code: tl.lauch_type_code,
marketing_subject_code: tl.marketing_subject_code
};
let shaStr = sha256(JSON.stringify(obj));
await this.redisClient.delete(shaStr);
});
return system.getResultSuccess();
//根据模板编码获取模板信息
// var templateInfo = await this.dao.model.findOne({
// where:{code:ab.code},raw:true
// });
// if(!templateInfo || !templateInfo.id){
// return system.getResultFail(-300,"未知模板");
// }
// if(templateInfo.is_enabled===1){
// return system.getResultFail(-301,"该模板正在使用中,不能执行此操作");
// }
// var updateObj = {id:templateInfo.id,template_content:ab.template_content};
// if(ab.form_id){
// updateObj["form_id"] = ab.form_id;
// }
// await this.dao.update(updateObj);
// return system.getResultSuccess();
}
}
module.exports = TemplateinfoService;
\ No newline at end of file
const system = require("../../../system");
const ServiceBase = require("../../sve.base");
const settings = require("../../../../config/settings");
const sha256 = require("sha256");
class TemplatelinkService extends ServiceBase {
constructor() {
super("template", ServiceBase.getDaoName(TemplatelinkService));
......@@ -10,6 +11,7 @@ class TemplatelinkService extends ServiceBase {
this.launchchannelDao = system.getObject("db.configmag.launchchannelDao");
this.launchtypeDao = system.getObject("db.configmag.launchtypeDao");
this.marketingsubjectDao = system.getObject("db.configmag.marketingsubjectDao");
this.redisClient = system.getObject("util.redisClient");
}
/**
* 获取模板链接配置参数
......@@ -372,5 +374,106 @@ class TemplatelinkService extends ServiceBase {
return system.getResultSuccess();
}
async getTemplateAndLinkInfo2(pobj){
let ab = pobj.actionBody;
// 校验传入的参数
if(!ab){
return system.getResultFail(-100,"参数错误");
}
if(!ab.channel_code){
return system.getResultFail(-101,"渠道主体编码不能为空");
}
if(!ab.business_type_code){
return system.getResultFail(-102,"业务类型编码不能为空");
}
if(!ab.lauch_type_code){
return system.getResultFail(-103,"投放方式编码不能为空");
}
if(!ab.marketing_subject_code){
return system.getResultFail(-104,"营销主体编码不能为空");
}
if(!ab.else_channel_param){
return system.getResultFail(-110,"其它渠道参数不能为空");
}
if(!ab.template_id){
return system.getResultFail(-111,"模板参数不能为空");
}
if(!ab.device){
return system.getResultFail(-112,"投放终端参数不能为空");
}
let linkObj; // 用于查询模板链接的参数,actionBody去除device参数
let shaStr; // 将linkObj转为字符串并计算出sha256的值
let rtn; // 根据shaStr从redis库中查询返回的值。
let rtnObj; // 1.如果从redis中查到数据,则是redis中返回的数据,2.否则就是将要储存到redis中的数据。
let linkinfo; // 模板链接信息
let addObj; // 储存访问信息
linkObj = {
template_id:ab.template_id,
channel_code:ab.channel_code,
else_channel_param:ab.else_channel_param,
business_type_code:ab.business_type_code,
lauch_type_code:ab.lauch_type_code,
marketing_subject_code:ab.marketing_subject_code
};
// linkObj = {...ab};
// delete linkObj.device;
shaStr = await sha256(JSON.stringify(linkObj));
rtn = await this.redisClient.get(shaStr); // 先试图从redis读取数据
//---- 从redis中读取到数据
if (!!rtn) {
rtnObj = JSON.parse(rtn);
linkinfo = rtnObj["linkinfo"];
console.log("========================================================\n从redis中读取数据\n=============================================================");
//---- 未从redis中读取到数据
} else {
// 获取模板链接信息
linkinfo = await this.dao.model.findOne({
where:linkObj,raw:true
});
if(!linkinfo || !linkinfo.id){
return system.getResultFail(-300,"未知链接");
}
if(!linkinfo.is_enabled || linkinfo.is_enabled!==1){
return system.getResultFail(-301,"无效链接,该链接未投放");
}
// 模板链接存在,获取模板信息
let tempObj = {id:ab.template_id}; // 用于查询templateinfo的条件
let templateinfo = await this.templateinfoDao.model.findOne({ // 查询结果
where:tempObj,raw:true
});
if(!templateinfo || !templateinfo.id){
return system.getResultFail(-400,"未知模板");
}
if(!templateinfo.is_enabled || templateinfo.is_enabled!==1){
return system.getResultFail(-401,"无效模板,该模板未启用");
}
rtnObj = { // 组合模板链接和模板信息
templateinfo,
linkinfo
};
// 将数据保存到redis中
await this.redisClient.set(shaStr, JSON.stringify(rtnObj));
}
addObj = { // 需要保存到浏览记录的内容
...ab,
link_code:linkinfo.code,
link_name:linkinfo.name,
channel_name:linkinfo.channel_name,
business_type_name:linkinfo.business_type_name,
lauch_type_name:linkinfo.lauch_type_name,
marketing_subject_name:linkinfo.marketing_subject_name,
client_ip:pobj.clientIp
};
await this.browsingrecordsDao.create(addObj);//添加链接浏览记录
return system.getResultSuccess(rtnObj);
}
}
module.exports = TemplatelinkService;
\ 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