Commit 0de6e9b8 by 王昆

gsb

parent 9b97d264
const system = require("../../../system");
const Dao = require("../../dao.base");
class SaasMerchantDao extends Dao {
constructor() {
super(Dao.getModelName(SaasMerchantDao));
}
async listByIds(ids, attrs) {
if (!ids || ids.length == 0) {
return [];
}
attrs = attrs || "*";
let sql = `SELECT ${attrs} FROM ${this.model.tableName} WHERE id IN (:ids) `;
return await this.customQuery(sql, {
ids: ids
});
}
async mapByIds(ids, attrs) {
let result = {};
let list = await this.listByIds(ids, attrs);
if (!list || list.length == 0) {
return result;
}
for (var item of list) {
result[item.id] = item;
}
return result;
}
async bySaasId(saasId, attrs) {
attrs = attrs || "*";
let sql = `SELECT ${attrs} FROM ${this.model.tableName} WHERE saas_id = :saasId `;
return await this.customQuery(sql, {
saasId: saasId
});
}
async byChannelId(channelId, attrs) {
attrs = attrs || "*";
let sql = `SELECT ${attrs} FROM ${this.model.tableName} WHERE channel_id = :channelId `;
return await this.customQuery(sql, {
channelId: channelId
});
}
async countByCondition(params) {
var sql = [];
sql.push("SELECT");
sql.push("count(1) as num");
sql.push("FROM saas_merchant t1");
sql.push("INNER JOIN saas_merchant_sign t2 ON t1.id = t2.id");
sql.push("WHERE 1 = 1 ");
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("t1.*,");
sql.push("t2.main_id, t2.begin_date, t2.end_date, t2.bm_reg_price, t2.invoice_service_rate, t2.trans_service_rate ");
sql.push("FROM saas_merchant t1");
sql.push("INNER JOIN saas_merchant_sign t2 ON t1.id = t2.id");
sql.push("WHERE 1 = 1 ");
this.setCondition(sql, params);
sql.push("ORDER BY t1.id DESC");
sql.push("LIMIT :startRow, :pageSize");
return await this.customQuery(sql.join(" "), params);
}
setCondition(sql, params) {
if (!params || !sql) {
return;
}
if (params.saas_id) {
sql.push("AND t1.saas_id = :saas_id");
}
if (params.channel_id) {
sql.push("AND t1.channel_id = :channel_id");
}
if (params.name) {
params.nameLike = `%${params.name}%`;
sql.push("AND t1.name LIKE :nameLike");
}
if (params.credit_code) {
sql.push("AND t1.credit_code LIKE :credit_code");
}
if(typeof params.is_sign != "undefined" && (params.is_sign === 1 || params.is_sign === 0)) {
sql.push("AND t1.is_sign LIKE :is_sign");
}
if (params.createBegin) {
sql.push("AND t1.created_at >= :createBegin");
}
if (params.createEnd) {
sql.push("AND t1.created_at <= :createEnd");
}
}
}
module.exports = SaasMerchantDao;
const system = require("../../../system");
const Dao = require("../../dao.base");
class SaasMerchantSignDao extends Dao {
constructor() {
super(Dao.getModelName(SaasMerchantSignDao));
}
async listByIds(ids, attrs) {
if (!ids || ids.length == 0) {
return [];
}
attrs = attrs || "*";
let sql = `SELECT ${attrs} FROM ${this.model.tableName} WHERE id IN (:ids) `;
return await this.customQuery(sql, {
ids: ids
});
}
async mapByIds(ids, attrs) {
let result = {};
let list = await this.listByIds(ids, attrs);
if (!list || list.length == 0) {
return result;
}
for (var item of list) {
result[item.id] = item;
}
return result;
}
async bySaasId(saasId, attrs) {
attrs = attrs || "*";
let sql = `SELECT ${attrs} FROM ${this.model.tableName} WHERE saas_id = :saasId `;
return await this.customQuery(sql, {
saasId: saasId
});
}
async byChannelId(channelId, attrs) {
attrs = attrs || "*";
let sql = `SELECT ${attrs} FROM ${this.model.tableName} WHERE channel_id = :channelId `;
return await this.customQuery(sql, {
channelId: channelId
});
}
}
module.exports = SaasMerchantSignDao;
const system = require("../../../system");
const settings = require("../../../../config/settings");
const uiconfig = system.getUiConfig2(settings.appKey);
module.exports = (db, DataTypes) => {
return db.define("saasmerchant", {
channel_id: DataTypes.STRING,
name: DataTypes.STRING,
short_name: DataTypes.STRING,
credit_code: DataTypes.STRING,
business_lincense_img: DataTypes.STRING,
residence: DataTypes.STRING,
tax_type: DataTypes.STRING,
business_scope: DataTypes.STRING,
term: DataTypes.INTEGER,
term_end: DataTypes.DATE,
idcard_front: DataTypes.STRING,
idcard_back: DataTypes.STRING,
legal_idno: DataTypes.STRING,
legal_name: DataTypes.STRING,
validity: DataTypes.INTEGER,
validity_end: DataTypes.DATE,
account_name: DataTypes.STRING,
account_bank_name: DataTypes.STRING,
account_bank_no: DataTypes.STRING,
account_mobile: DataTypes.STRING,
contact_man: DataTypes.STRING,
contact_mobile: DataTypes.STRING,
contact_email: DataTypes.STRING,
contact_addr: DataTypes.STRING,
is_sign: {
type: DataTypes.BOOLEAN,
defaultValue: false
},
saas_id: DataTypes.INTEGER,
}, {
paranoid: true, //假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'saas_merchant',
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}]
// }
]
});
}
\ No newline at end of file
const system=require("../../../system");
const settings=require("../../../../config/settings");
const uiconfig=system.getUiConfig2(settings.appKey);
module.exports = (db, DataTypes) => {
return db.define("saasmerchantsign", {
main_id: DataTypes.INTEGER,
begin_date: DataTypes.DATE,
end_date: DataTypes.DATE,
bm_reg_price: DataTypes.INTEGER,
invoice_service_rate: DataTypes.INTEGER,
trans_service_rate: DataTypes.INTEGER,
},{
paranoid: true,//假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'saas_merchant_sign',
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}]
// }
]
});
}
......@@ -23,7 +23,7 @@ class SaasChannelService extends ServiceBase {
let main = await this.dao.getById(params.id);
if (!main) {
return system.getResult(null, "签约主体不存在");
return system.getResult(null, "渠道不存在");
}
this.handleDate(main, ["created_at"], null, -8);
......@@ -41,7 +41,7 @@ class SaasChannelService extends ServiceBase {
let validity_end = this.trim(params.validity_end);
if (!saas_id) {
return getResult(null, "签约主体不存在");
return getResult(null, "saas不存在");
}
if (!this.trim(params.name)) {
......@@ -174,11 +174,12 @@ class SaasChannelService extends ServiceBase {
return system.getResultSuccess(page);
}
async mapByIds(params) {
if(!params.ids || params.ids.length == 0) {
return system.getResultSuccess({});
}
let rs = await this.dao.mapByIds(params.ids);
return system.getResultSuccess(rs);
}
}
module.exports = SaasChannelService;
// var task=new UserService();
// task.getUserStatisticGroupByApp().then(function(result){
// console.log((result));
// }).catch(function(e){
// console.log(e);
// });
\ No newline at end of file
......@@ -87,6 +87,13 @@ class SaasMainService extends ServiceBase {
return system.getResultSuccess(page);
}
async mapByIds(params) {
if(!params.ids || params.ids.length == 0) {
return system.getResultSuccess({});
}
let rs = await this.dao.mapByIds(params.ids);
return system.getResultSuccess(rs);
}
}
module.exports = SaasMainService;
// var task=new UserService();
......
const system = require("../../../system");
const ServiceBase = require("../../sve.base")
const settings = require("../../../../config/settings")
class SaasMerchantService extends ServiceBase {
constructor() {
super("merchant", ServiceBase.getDaoName(SaasMerchantService));
this.saasmerchantsignDao = system.getObject("db.merchant.saasmerchantsignDao");
}
// -----------------------以此间隔,上面为API,下面为service---------------------------------
async mapByIds(params) {
if(!params.ids || params.ids.length == 0) {
return system.getResultSuccess({});
}
let rs = this.dao.mapByIds(params.ids);
return system.getResultSuccess(rs);
}
async dics(params) {
let saas_id = Number(this.trim(params.saas_id) || 0);
if (!saas_id) {
return system.getResultSuccess([]);
}
let list = await this.dao.bySaasId(Number(params.saas_id), "id, name, short_name");
return system.getResultSuccess(list);
}
async info(params) {
if (!params.id) {
return system.getResult(null, "id不存在");
}
let merchant = await this.dao.getById(params.id);
if (!merchant) {
return system.getResult(null, "商户不存在");
}
this.handleDate(merchant, ["created_at"], null, -8);
let sign = await this.saasmerchantsignDao.getById(params.id);
this.handleDate(sign, ["created_at"], null, -8);
this.handleDate(sign, ["begin_date", "end_date"], "YYYY-MM-DD", -8);
merchant.sign = sign;
return system.getResultSuccess(merchant);
}
async signInfo(params) {
if (!params.id) {
return system.getResult(null, "id不存在");
}
let sign = await this.saasmerchantsignDao.getById(params.id);
if (!sign) {
return system.getResult(null, "商户不存在");
}
this.handleDate(sign, ["created_at"], null, -8);
this.handleDate(sign, ["begin_date", "end_date"], "YYYY-MM-DD", -8);
return system.getResultSuccess(sign);
}
async save(params) {
let id = Number(params.id || 0);
let saas_id = Number(params.saas_id || 0);
let term = Number(params.term || 1);
let term_end = this.trim(params.term_end);
let validity = Number(params.validity || 1);
let validity_end = this.trim(params.validity_end);
if (!saas_id) {
return getResult(null, "saas不存在");
}
if (!this.trim(params.name)) {
return system.getResult(null, "请填写渠道名称");
}
if (!this.trim(params.short_name)) {
return system.getResult(null, "请填写渠道简称");
}
if (!this.trim(params.credit_code)) {
return system.getResult(null, "请填写统一社会信用代码");
}
// if(!this.trim(params.business_lincense_img)) {return system.getResult(null, ""); } // 营业执照暂不验证
if (!this.trim(params.tax_type)) {
return system.getResult(null, "请选择纳税人类型");
}
if (!this.trim(params.residence)) {
return system.getResult(null, "请填写住所");
}
if (!this.trim(params.business_scope)) {
return system.getResult(null, "请填写经营范围");
}
if (term == 2 && !term_end) {
return system.getResult(null, "请填写营业期限固定日期");
}
// if(!this.trim(params.idcard_front)) {return system.getResult(null, "idcard_front为空"); }
// if(!this.trim(params.idcard_back)) {return system.getResult(null, "idcard_back为空"); }
if (!this.trim(params.legal_name)) {
return system.getResult(null, "请填写法人姓名");
}
if (!this.trim(params.legal_idno)) {
return system.getResult(null, "请填写法人身份证");
}
if (validity == 2 && !validity_end) {
return system.getResult(null, "请填写有效期限固定日期");
}
if (!this.trim(params.account_name)) {
return system.getResult(null, "请填写账户名称");
}
if (!this.trim(params.account_bank_name)) {
return system.getResult(null, "请填写开户行");
}
if (!this.trim(params.account_bank_no)) {
return system.getResult(null, "请填写开户账号");
}
if (!this.trim(params.account_mobile)) {
return system.getResult(null, "请填写联系电话");
}
if (!this.trim(params.contact_man)) {
return system.getResult(null, "请填写联系人姓名");
}
if (!this.trim(params.contact_mobile)) {
return system.getResult(null, "请填写联系人电话");
}
if (!this.trim(params.contact_email)) {
return system.getResult(null, "请填写联系人邮箱");
}
if (!this.trim(params.contact_addr)) {
return system.getResult(null, "请填写联系人地址");
}
let merchant;
if (id) {
merchant = await this.dao.findById(id);
} else {
merchant = {};
merchant.saas_id = saas_id;
merchant.channel_id = this.trim(params.channel_id);
}
merchant.name = this.trim(params.name);
merchant.short_name = this.trim(params.short_name);
merchant.credit_code = this.trim(params.credit_code);
merchant.business_lincense_img = this.trim(params.business_lincense_img);
merchant.residence = this.trim(params.residence);
merchant.tax_type = this.trim(params.tax_type);
merchant.business_scope = this.trim(params.business_scope);
merchant.idcard_front = this.trim(params.idcard_front);
merchant.idcard_back = this.trim(params.idcard_back);
merchant.legal_idno = this.trim(params.legal_idno);
merchant.legal_name = this.trim(params.legal_name);
merchant.account_name = this.trim(params.account_name);
merchant.account_bank_name = this.trim(params.account_bank_name);
merchant.account_bank_no = this.trim(params.account_bank_no);
merchant.account_mobile = this.trim(params.account_mobile);
merchant.contact_man = this.trim(params.contact_man);
merchant.contact_mobile = this.trim(params.contact_mobile);
merchant.contact_email = this.trim(params.contact_email);
merchant.contact_addr = this.trim(params.contact_addr);
merchant.term = term;
merchant.term_end = term_end;
merchant.validity = validity;
merchant.validity_end = validity_end;
let self = this;
if (merchant.id) {
await merchant.save();
} else {
merchant = await self.db.transaction(async function (t) {
// 创建商户
merchant = await self.dao.create(merchant, t);
await self.saasmerchantsignDao.create({
id: merchant.id
}, t);
return merchant;
});
}
return system.getResultSuccess(merchant);
}
async pageByCondition(params) {
let currentPage = Number(params.currentPage || 1);
params.pageSize = Number(params.pageSize || 10);
params.startRow = (currentPage - 1) * params.pageSize;
var page = { count: 0, rows: [] };
page.count = await this.dao.countByCondition(params);
if (page.count == 0) {
return page;
}
page.rows = await this.dao.listByCondition(params) || [];
if (page.rows) {
for (let item of page.rows) {
this.handleDate(item, ["created_at"], null, -8);
this.handleDate(item, ["begin_date", "end_date"], "YYYY-MM-DD", -8);
}
}
return system.getResultSuccess(page);
}
async sign(params) {
if (!params.id) {
return system.getResult(null, "id不存在");
}
if (!this.trim(params.main_id)) {
return system.getResult(null, "请选择签约主体");
}
if (!this.trim(params.begin_date)) {
return system.getResult(null, "请选择签约开始时间");
}
if (!this.trim(params.end_date)) {
return system.getResult(null, "请选择签约失效时间");
}
let merchant = await this.dao.findById(params.id);
let sign = await this.saasmerchantsignDao.findById(params.id);
sign.main_id = Number(this.trim(params.main_id) || 0);
sign.begin_date = this.trim(params.begin_date);
sign.end_date = this.trim(params.end_date);
sign.bm_reg_price = Number(params.bm_reg_price || 0);
sign.invoice_service_rate = Number(params.invoice_service_rate || 0);
sign.trans_service_rate = Number(params.trans_service_rate || 0);
await sign.save();
merchant.is_sign = true;
await merchant.save();
return system.getResultSuccess();
}
}
module.exports = SaasMerchantService;
// var task=new UserService();
// task.getUserStatisticGroupByApp().then(function(result){
// console.log((result));
// }).catch(function(e){
// console.log(e);
// });
\ 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