Commit 54c5b40c by 王昆

gsb

parent 2680ab05
...@@ -10,6 +10,7 @@ class ActionAPI extends APIBase { ...@@ -10,6 +10,7 @@ class ActionAPI extends APIBase {
this.deliverSve = system.getObject("service.deliver.deliverSve"); this.deliverSve = system.getObject("service.deliver.deliverSve");
this.deliverschemeSve = system.getObject("service.deliver.deliverschemeSve"); this.deliverschemeSve = system.getObject("service.deliver.deliverschemeSve");
this.deliverchannelSve = system.getObject("service.deliver.deliverchannelSve");
this.invoicecontentSve = system.getObject("service.common.invoicecontentSve"); this.invoicecontentSve = system.getObject("service.common.invoicecontentSve");
this.smsinfoSve = system.getObject("service.common.smsinfoSve"); this.smsinfoSve = system.getObject("service.common.smsinfoSve");
...@@ -113,6 +114,12 @@ class ActionAPI extends APIBase { ...@@ -113,6 +114,12 @@ class ActionAPI extends APIBase {
case "deliverEnable": case "deliverEnable":
opResult = await this.deliverSve.enable(action_body); opResult = await this.deliverSve.enable(action_body);
break; break;
case "deliverBindChannel":
opResult = await this.deliverchannelSve.bindChannel(action_body);
break;
case "deliverChannels":
opResult = await this.deliverchannelSve.byCondition(action_body);
break;
case "deliverLogin": case "deliverLogin":
opResult = await this.deliverSve.login(action_body); opResult = await this.deliverSve.login(action_body);
break; break;
......
...@@ -59,7 +59,7 @@ class DeliverDao extends Dao { ...@@ -59,7 +59,7 @@ class DeliverDao extends Dao {
async countChannelDeliver(params) { async countChannelDeliver(params) {
let sql = []; let sql = [];
sql.push("SELECT"); sql.push("SELECT");
sql.push("COUNT(DISTINCT t1.`id`)"); sql.push("COUNT(DISTINCT t1.`id`) AS num");
sql.push("FROM `d_deliver_channel` t2"); sql.push("FROM `d_deliver_channel` t2");
sql.push("INNER JOIN `d_deliver` t1 ON t2.`deliver_id` = t1.`id`"); sql.push("INNER JOIN `d_deliver` t1 ON t2.`deliver_id` = t1.`id`");
sql.push("WHERE 1 = 1"); sql.push("WHERE 1 = 1");
......
...@@ -5,71 +5,25 @@ class DeliverChannelDao extends Dao { ...@@ -5,71 +5,25 @@ class DeliverChannelDao extends Dao {
super(Dao.getModelName(DeliverChannelDao)); super(Dao.getModelName(DeliverChannelDao));
} }
async dics(params) { async byCondition(params) {
var sql = []; let sql = [];
sql.push("SELECT"); sql.push("SELECT");
sql.push(params.attrs || "id, name"); sql.push(params.attrs || "*");
sql.push("FROM"); sql.push(`FROM ${this.model.tableName}`);
sql.push(this.model.tableName); sql.push("WHERE 1 = 1 ");
sql.push("WHERE deleted_at IS NULL ");
if (params.deliver_id) { if (params.deliver_id) {
sql.push("AND deliver_id = :deliver_id"); sql.push("AND deliver_id = :deliver_id");
} }
sql.push("ORDER BY created_at ASC"); if (params.channel_id) {
return await this.customQuery(sql.join(" "), params); sql.push("AND channel_id = :channel_id");
}
async countByCondition(params) {
var sql = [];
sql.push("SELECT");
sql.push("count(1) as num");
sql.push("FROM");
sql.push(this.model.tableName);
sql.push("WHERE deleted_at IS NULL");
this.setCondition(sql, params);
var list = await this.customQuery(sql.join(" "), params);
if (!list || list.length == 0) {
return 0;
} }
return list[0].num;
}
async listByCondition(params) {
params.startRow = Number(params.startRow || 0);
params.pageSize = Number(params.pageSize || 10);
var sql = [];
sql.push("SELECT");
sql.push(params.attrs || "*");
sql.push("FROM");
sql.push(this.model.tableName);
sql.push("WHERE deleted_at IS NULL");
this.setCondition(sql, params); return this.customQuery(sql.join(" "), params);
sql.push("ORDER BY created_at DESC");
sql.push("LIMIT :startRow, :pageSize");
return await this.customQuery(sql.join(" "), params);
} }
setCondition(sql, params) { async delByDC(params) {
if (!params || !sql) { let sql = `DELETE FROM ${this.model.tableName} WHERE deliver_id = :deliver_id AND channel_id = :channel_id`;
return; this.customUpdate(sql, params);
}
if (params.deliver_id) {
sql.push("AND deliver_id = :deliver_id");
}
if (params.name) {
params.nameLike = `%${params.name}%`;
sql.push("AND name LIKE :nameLike");
}
if (params.createBegin) {
sql.push("AND created_at >= :createBegin");
}
if (params.createEnd) {
sql.push("AND created_at <= :createEnd");
}
} }
async findListByIds(ids) { async findListByIds(ids) {
......
...@@ -3,7 +3,6 @@ const settings = require("../../../../config/settings"); ...@@ -3,7 +3,6 @@ const settings = require("../../../../config/settings");
const uiconfig = system.getUiConfig2(settings.appKey); const uiconfig = system.getUiConfig2(settings.appKey);
module.exports = (db, DataTypes) => { module.exports = (db, DataTypes) => {
return db.define("deliverchannel", { return db.define("deliverchannel", {
saas_id: DataTypes.STRING,
channel_id: DataTypes.STRING, channel_id: DataTypes.STRING,
deliver_id: DataTypes.STRING, deliver_id: DataTypes.STRING,
}, { }, {
......
...@@ -7,90 +7,34 @@ class DeliverChannelService extends ServiceBase { ...@@ -7,90 +7,34 @@ class DeliverChannelService extends ServiceBase {
super("deliver", ServiceBase.getDaoName(DeliverChannelService)); super("deliver", ServiceBase.getDaoName(DeliverChannelService));
} }
async save(params) { async byCondition(params) {
let id = params.id; let rs = await this.dao.byCondition(params);
let scheme; return system.getResultSuccess(rs);
if (id) {
scheme = await this.dao.findById(id);
} else {
scheme = {};
}
scheme.name = this.trim(params.name);
if (params.common_tax_ladder) {
scheme.common_tax_ladder = JSON.stringify(params.common_tax_ladder || "");
}
if (params.common_other_ladder) {
scheme.common_other_ladder = JSON.stringify(params.common_other_ladder || "");
}
if (params.special_tax_ladder) {
scheme.special_tax_ladder = JSON.stringify(params.special_tax_ladder || "");
}
if(params.special_other_ladder) {
scheme.special_other_ladder = JSON.stringify(params.special_other_ladder || "");
}
scheme.cost_rate = system.y2f(params.cost_rate || 0);
scheme.tax_rate = system.y2f(params.tax_rate || 0);
scheme.add_value_up_type = this.trim(params.add_value_up_type);
scheme.tax_up_type = this.trim(params.tax_up_type);
if (scheme.id) {
scheme = await scheme.save();
} else {
scheme.deliver_id = this.trim(params.deliver_id);
scheme = await this.dao.create(scheme);
}
return system.getResultSuccess(scheme);
}
async info(params) {
let item = await this.dao.getById(params.id);
this.handleDate(item, ["created_at"], null);
this.transField([item]);
return system.getResultSuccess(item);
} }
async pageByCondition(params) { async bindChannel(pobj) {
let page = { let deliver_id = this.trim(pobj.deliver_id);
count: 0, let channel_id = this.trim(pobj.channel_id);
rows: [] if (!deliver_id || !channel_id) {
}; return system.getResult(null, `参数错误deliver_id[${deliver_id}], channel_id${channel_id}`);
params.currentPage = Number(params.currentPage || 1);
params.pageSize = Number(params.pageSize || 10);
params.startRow = (params.currentPage - 1) * params.pageSize;
page.count = await this.dao.countByCondition(params);
if (page.count == 0) {
return system.getResultSuccess(page);
}
page.rows = await this.dao.listByCondition(params);
if (page.rows) {
for (let row of page.rows) {
this.handleDate(row, ["created_at"], null);
}
this.transField(page.rows);
}
return system.getResultSuccess(page);
}
transField(rows) {
if (!rows || rows.length == 0) {
return;
}
for (let row of rows) {
if (!row) {
continue;
}
try {
row.common_tax_ladder = JSON.parse(row.common_tax_ladder ? row.common_tax_ladder : null);
row.common_other_ladder = JSON.parse(row.common_other_ladder ? row.common_other_ladder : null);
row.special_tax_ladder = JSON.parse(row.special_tax_ladder ? row.special_tax_ladder : null);
row.special_other_ladder = JSON.parse(row.special_other_ladder ? row.special_other_ladder : null);
} catch (e) {
console.log(e);
}
row.cost_rate = system.f2y(row.cost_rate);
row.tax_rate = system.f2y(row.tax_rate);
} }
let dc = {
deliver_id: deliver_id,
channel_id: channel_id,
};
// 取消绑定
if (pobj.type == "unbind") {
let rs = await this.dao.delByDC(dc);
return system.getResultSuccess(rs);
}
// 绑定
let exists = await this.dao.findOne(dc);
if (exists) {
return system.getResultSuccess(exists);
}
dc.autoIncrement = true;
dc = await this.dao.create(dc);
return system.getResultSuccess(dc);
} }
} }
......
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