Commit 5c98671d by 庄冰

link

parent e1629844
......@@ -40,6 +40,7 @@ class Template extends APIBase {
opResult = await this.templateinfoSve.updateSwitchStatus(pobj);
break;
case "findAndCountAll"://模板列表查询
pobj.actionBody.company_id = pobj.company_id;
opResult = await this.templateinfoSve.findAndCountAll(pobj.actionBody);
break;
case "findOneByCode"://模板查询
......
const APIBase = require("../../api.base");
const system = require("../../../system");
const settings = require("../../../../config/settings");
/**
* 用户端调用订单相关接口
*/
class Templatelink extends APIBase {
constructor() {
super();
this.templatelinkSve = system.getObject("service.template.templatelinkSve");
}
/**
* 接口跳转-POST请求
* action_process 执行的流程
* action_type 执行的类型
* action_body 执行的参数
*/
async springBoard(pobj, qobj, req) {
if (!pobj.actionType) {
return system.getResult(null, "actionType参数不能为空");
}
var result = await this.opActionProcess(pobj, pobj.actionType, req);
return result;
}
async opActionProcess(pobj, action_type, req) {
var opResult = null;
var self = this;
pobj.xctx = req.xctx;
switch (action_type) {
case "test"://测试
opResult = system.getResultSuccess("测试接口");
break;
case "createTemplateLink"://创建模板链接
opResult = await this.templatelinkSve.createTemplateLink(pobj);
break;
case "editTemplateLink"://修改模板链接
opResult = await this.templatelinkSve.editTemplateLink(pobj);
break;
case "updateLaunchStatus"://修改投放状态
opResult = await this.templatelinkSve.updateLaunchStatus(pobj);
break;
case "findAndCountAll"://链接列表查询
pobj.actionBody.company_id = pobj.company_id;
opResult = await this.templatelinkSve.findAndCountAll(pobj.actionBody);
break;
case "findOneByCode"://获取模板链接详情数据
opResult = await this.templatelinkSve.findOneByCode(pobj);
break;
default:
opResult = system.getResult(null, "action_type参数错误");
break;
}
return opResult;
}
}
module.exports = Templatelink;
const system=require("../../../system");
const Dao=require("../../dao.base");
class TemplateinfoDao extends Dao{
constructor(){
super(Dao.getModelName(TemplateinfoDao));
}
extraWhere(obj,w,qc,linkAttrs){
w["company_id"]=obj.company_id;
return w;
}
}
module.exports=TemplateinfoDao;
\ No newline at end of file
const system=require("../../../system");
const Dao=require("../../dao.base");
class TemplatelinkDao extends Dao{
constructor(){
super(Dao.getModelName(TemplatelinkDao));
}
extraWhere(obj,w,qc,linkAttrs){
w["company_id"]=obj.company_id;
return w;
}
}
module.exports=TemplatelinkDao;
\ No newline at end of file
const system = require("../../../system");
const settings = require("../../../../config/settings");
const appconfig = system.getSysConfig();
/**
* 模板信息表
*/
module.exports = (db, DataTypes) => {
//TODO:
return db.define("templatelink", {
code: DataTypes.STRING,
name: DataTypes.STRING,
delivery_word:DataTypes.STRING,
else_channel_param:DataTypes.STRING,
template_id: DataTypes.INTEGER,
channel_id: DataTypes.INTEGER,
business_type_id: DataTypes.INTEGER,
lauch_type_id: DataTypes.INTEGER,
marketing_subject_id: DataTypes.INTEGER,
template_name: DataTypes.STRING,
channel_name: DataTypes.STRING,
business_type_name: DataTypes.STRING,
lauch_type_name: DataTypes.STRING,
marketing_subject_name: DataTypes.STRING,
is_enabled: DataTypes.INTEGER,
link_url: DataTypes.STRING,
notes: DataTypes.STRING,
user_id: DataTypes.STRING(100),
user_name: DataTypes.STRING(100), //user_name 用户名称
company_id: DataTypes.INTEGER,
}, {
paranoid: true,//假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'b_template_link',
validate: {
},
indexes: [
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
}
......@@ -3,7 +3,7 @@ const ServiceBase = require("../../sve.base");
const settings = require("../../../../config/settings");
class TemplateinfoService extends ServiceBase {
constructor() {
super("common", ServiceBase.getDaoName(TemplateinfoService));
super("template", ServiceBase.getDaoName(TemplateinfoService));
}
async findAndCountAll(obj){
......@@ -64,6 +64,9 @@ class TemplateinfoService extends ServiceBase {
if(!templateInfo || !templateInfo.id){
return system.getResultFail(-300,"未知模板");
}
// if(templateInfo.is_enabled===1){
// return system.getResultFail(-301,"该模板正在使用中,不能执行此操作");
// }
await this.dao.update({id:templateInfo.id,template_content:ab.template_content});
return system.getResultSuccess();
}
......
const system = require("../../../system");
const ServiceBase = require("../../sve.base");
const settings = require("../../../../config/settings");
class TemplatelinkService extends ServiceBase {
constructor() {
super("template", ServiceBase.getDaoName(TemplatelinkService));
}
async findAndCountAll(obj){
var res = await this.dao.findAndCountAll(obj);
return system.getResultSuccess(res);
}
async checkAndPackageParams(ab,xctx){
if(!ab.channel_id){
return system.getResultFail(-101,"渠道主体不能为空");
}
if(!ab.business_type_id){
return system.getResultFail(-102,"业务类型不能为空");
}
if(!ab.lauch_type_id){
return system.getResultFail(-103,"投放方式不能为空");
}
if(!ab.marketing_subject_id){
return system.getResultFail(-104,"营销主体不能为空");
}
if(!ab.delivery_word){
return system.getResultFail(-105,"投放词不能为空");
}
if(!ab.else_channel_param){
return system.getResultFail(-106,"其它渠道参数不能为空");
}
if(!ab.template_id){
return system.getResultFail(-107,"模板参数不能为空");
}
if(!ab.name){
return system.getResultFail(-107,"任务名称不能为空");
}
if(!ab.code){//新增
ab.code = await this.getBusUid("tl");
ab.user_id=xctx.credid;
ab.user_name=xctx.username;
ab.company_id=xctx.companyid;
ab.is_enabled=0;
}else{//修改
var linkinfo = await this.dao.model.findOne({
where:{code:ab.code},raw:true
});
if(!linkinfo || !linkinfo.id){
return system.getResultFail(-300,"未知模板");
}
if(linkinfo.is_enabled===1){
return system.getResultFail(-301,"该链接正在投放中,不能执行此操作");
}
ab.id = linkinfo.id;
}
return ab;
}
/**
* 创建模板链接数据
* @param {*} pobj
*/
async createTemplateLink(pobj){
var ab = pobj.actionBody;
var xctx = pobj.xctx;
if(!ab){
return system.getResultFail(-100,"参数错误");
}
var checkres = await this.checkAndPackageParams(ab,xctx);
if(checkres && checkres.status<0){
return checkres;
}
ab = checkres;
var res = await this.create(ab);
return system.getResultSuccess(res);
}
/**
* 修改模板链接
* @param {*} pobj
*/
async editTemplateLink(pobj){
var ab = pobj.actionBody;
var xctx = pobj.xctx;
if(!ab){
return system.getResultFail(-100,"参数错误");
}
if(!ab.code){
return system.getResultFail(-100,"模板编码不能为空");
}
var checkres = await this.checkAndPackageParams(ab,xctx);
if(checkres && checkres.status<0){
return checkres;
}
ab = checkres;
await this.dao.update(ab);
return system.getResultSuccess();
}
/**
* 获取模板链接详情数据
* @param {*} pobj
*/
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 updateLaunchStatus(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 linkinfo = await this.dao.model.findOne({
where:{code:ab.code},raw:true
});
if(!linkinfo || !linkinfo.id){
return system.getResultFail(-300,"未知链接");
}
await this.dao.update({id:linkinfo.id,is_enabled:ab.is_enabled});
return system.getResultSuccess();
}
/**
* 删除模板链接
* @param {*} pobj
*/
async deleteTemplateLink(pobj){
var ab = pobj.actionBody;
var xctx = pobj.xctx;
if(!ab){
return system.getResultFail(-100,"参数错误");
}
if(!ab.code){
return system.getResultFail(-101,"链接编码不能为空");
}
var linkinfo = await this.dao.model.findOne({
where:{code:ab.code},raw:true
});
if(!linkinfo || !linkinfo.id){
return system.getResultFail(-300,"未知模板链接");
}
if(linkinfo.is_enabled===1){
return system.getResultFail(-301,"该链接正在投放中,不能执行此操作");
}
await this.dao.delete({id:linkinfo.id});
return system.getResultSuccess();
}
}
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