Commit e02e387c by 赵庆

薪比果接口

parent 7f5b74a2
......@@ -9,5 +9,36 @@ class ApiBase{
return system.getResult2(null,null,"ok","请检查您的授权KEY");
}
}
doTimeCondition(params, fields) {
if (!params || !fields || fields.length == 0) {
return;
}
for (var f of fields) {
if (params[f]) {
var suffix = this.endWith(f, 'Begin') ? " 00:00:00" : " 23:59:59";
params[f] = params[f] + suffix;
}
}
}
trim(o) {
if(!o) {
return "";
}
return o.toString().trim();
}
getSettleParams(search) {
var params = search || {};
if (this.trim(params.createBegin)) {
params.createBegin = this.trim(params.createBegin) + " 00:00:00";
}
if (this.trim(params.createEnd)) {
params.createEnd = this.trim(params.createEnd) + " 23:59:59";
}
return params;
}
}
module.exports=ApiBase;
var system = require("../../system");
const apiBase = require("../api.base");
class XbgApi extends apiBase{
constructor() {
super();
this.utilesignbaoSve = system.getObject("service.utilesignbaoSve");
this.etemplateSve = system.getObject("service.etemplateSve");
this.ecompanySve = system.getObject("service.ecompanySve");
this.econtractSve = system.getObject("service.econtractSve");
this.esettleSve = system.getObject("service.esettleSve")
}
//合同模板
async etemplateList(qobj) {
try {
var params = qobj || {};
var ecompanyId = params.ecompany_id;
if (ecompanyId.length > 1) {
params.ecompanyIds = ecompanyId;
delete params.ecompany_id;
} else {
params.ecompanyIds = [ecompanyId];
delete params.ecompany_id;
}
var page = await this.etemplateSve.signPage(params);
return system.getResult2(page);
} catch (e) {
console.log(e);
return system.getErrResult2("接口异常");
}
}
//已签合同
async acontractList(qobj) {
try {
var params = qobj || {};
var ecompanyId = params.ecompany_id;
if (ecompanyId.length > 1) {
params.ecompanyIds = [ecompanyId];
delete params.ecompany_id;
} else {
params.ecompanyIds = ecompanyId;
delete params.ecompany_id;
}
params.eflowstatusList = ['2'];
this.doTimeCondition(params, ["signBegin", "signEnd"]);
var page = await this.econtractSve.pageByCondition(params);
return system.getResult2(page);
} catch (e) {
console.log(e);
return system.getErrResult2("接口异常");
}
}
//纳税人人员
async ratepayingListToPe(qobj) {
try {
var params = qobj || {};
var params = this.getSettleParams(params);
var page = await this.esettleSve.ratepayingToPe(params);
return system.getResult2(page);
} catch (e) {
console.log(e);
return system.getErrResult2("接口异常");
}
}
//纳税人按月
async ratepayingListToMonth(qobj) {
try {
var params = qobj || {};
var params = this.getSettleParams(params);
var page = await this.esettleSve.ratepayingToMonth(params);
return system.getResult2(page);
} catch (e) {
console.log(e);
return system.getErrResult2("接口异常");
}
}
//纳税人个人详情
async ratepayingListToOne(qobj) {
try {
var params = qobj || {};
var params = this.getSettleParams(params);
var page = await this.esettleSve.ratepayingToOne(params);
return system.getResult2(page);
} catch (e) {
console.log(e);
return system.getErrResult2("接口异常");
}
}
//数据概览
async dataOverview(qobj){
try {
var params = qobj || {};
var ecompanyId = params.ecompany_id;
if (ecompanyId.length > 1) {
params.ecompanyIds = [ecompanyId];
delete params.ecompany_id;
} else {
params.ecompanyIds = ecompanyId;
delete params.ecompany_id;
}
var result = {};
result.contractCount = await this.econtractSve.getCount(params);
var list = await this.esettleSve.getPays(params);
result.actual_amt = list.actual_amt;
result.income_tax = list.income_tax;
return system.getResult2(result);
}catch (e) {
console.log(e);
return system.getErrResult2("接口异常");
}
}
}
module.exports = XbgApi;
\ No newline at end of file
......@@ -220,7 +220,7 @@ class EsettleCtl extends CtlBase {
}
var params = this.getSettleParams(params);
var page = await this.service.settlePage(params);
var page = await this.service.ratepayingList(params);
return system.getResult2(page);
} catch (e) {
console.log(e);
......
......@@ -286,6 +286,17 @@ class EcontractService extends ServiceBase {
return resultAll;
}
async getCount(params){
var where = {};
if (params.ecompanyIds) {
where.ecompany_id = {
[this.db.Op.in]: params.ecompanyIds
};
}
let contractCount = await this.findCount(where);
return contractCount
}
async pageByCondition(params) {
var currentPage = Number(params.currentPage || 0);
var pageSize = Number(params.pageSize || 10);
......@@ -708,7 +719,6 @@ class EcontractService extends ServiceBase {
"contractName": item.name,
"companyName": company.name,
"statusName": item.eflowstatusname,
"mobile": item.mobile,
"userName": item.userName,
"mobile": item.mobile,
"idCard": item.personsSign.toUpperCase(),
......
......@@ -6,7 +6,7 @@ class EsettleService extends ServiceBase {
constructor() {
super(ServiceBase.getDaoName(EsettleService));
//this.appDao=system.getObject("db.appDao");
this.settledb=system.getObject("db.connection").getSettleDBCon();
this.settledb = system.getObject("db.connection").getSettleDBCon();
this.ecompanyDao = system.getObject("db.ecompanyDao");
this.epartnerDao = system.getObject("db.epartnerDao");
......@@ -23,21 +23,22 @@ class EsettleService extends ServiceBase {
async countAmtByCard(idno, begin, end) {
var sql = "SELECT sum(actual_amt) as num FROM `tbl_order_item` t1 " +
"WHERE t1.trade_status = '00' AND t1.id_no = '" + idno + "' ";
if(begin) {
if (begin) {
sql = sql + " AND t1.pay_complete_time >= '" + begin + "' ";
}
if(end) {
if (end) {
sql = sql + " AND t1.pay_complete_time <= '" + end + "' ";
}
var count = 0;
var countrs = await this.settledb.query(sql);
if(countrs && countrs[0,0]) {
count = countrs[0,0][0].num;
if (countrs && countrs[0, 0]) {
count = countrs[0, 0][0].num;
}
return parseFloat((Number(count || 0) / 100).toFixed(2));
}
async findOrderItemsByCard(idno, currentPage, pageSize) {
currentPage = Number(currentPage || 1);
pageSize = Number(pageSize || 10);
......@@ -49,12 +50,12 @@ class EsettleService extends ServiceBase {
"ORDER BY t1.`pay_complete_time` DESC ";
var countrs = await this.settledb.query(countSql);
var total = 0;
if(countrs && countrs[0,0]) {
total = countrs[0,0][0].num;
if (countrs && countrs[0, 0]) {
total = countrs[0, 0][0].num;
}
if(total == 0) {
return {count:0, rows:[]}
if (total == 0) {
return {count: 0, rows: []}
}
var sql = "SELECT t1.id, t1.`id_name`, t1.`id_no`, t1.`actual_amt`, t1.`pay_complete_time`, t1.`busi_id`, t3.`company_name` FROM `tbl_order_item` t1 " +
......@@ -64,18 +65,18 @@ class EsettleService extends ServiceBase {
"LIMIT " + Number(startRow) + ", " + Number(pageSize);
var list = await this.settledb.query(sql);
if(list && list.length > 0) {
list = list[0,0];
for(var item of list) {
if (list && list.length > 0) {
list = list[0, 0];
for (var item of list) {
item.actual_amt = parseFloat((Number(item.actual_amt || 0) / 100).toFixed(2));
if(item.pay_complete_time) {
if (item.pay_complete_time) {
item.pay_complete_time = moment(item.pay_complete_time).format("YYYY-MM-DD HH:mm");
}
}
} else{
} else {
list = []
}
return {count: total, rows:list};
return {count: total, rows: list};
}
async statSettle(params) {
......@@ -84,24 +85,115 @@ class EsettleService extends ServiceBase {
sql = sql + "INNER JOIN `tbl_busi` t2 ON t1.`busi_id` = t2.id ";
sql = sql + "WHERE t1.`trade_status` = '00' ";
if(params.company_name) {
if (params.company_name) {
sql = sql + " AND t2.company_name = :company_name ";
}
if(params.begin) {
if (params.begin) {
sql = sql + " AND pay_complete_time >= :begin ";
}
if(params.end) {
if (params.end) {
sql = sql + " AND pay_complete_time <= :end ";
}
var list = await this.settledb.query(sql);
if(list && list.length > 0) {
list = list[0,0];
if (list && list.length > 0) {
list = list[0, 0];
return list[0].num || 0;
}
return 0;
}
async ratepayingToPe(condition) {
var currentPage = Number(condition.currentPage || 1);
var pageSize = Number(condition.pageSize || 20);
var startRow = (currentPage - 1) * pageSize;
var listSql = "SELECT COUNT(*) count,id_name,mobile,id_no,pay_complete_time FROM tbl_order_item WHERE trade_status = '00'";
if(condition.ecompany_id){
listSql = listSql + " AND busi_id = '" + condition.ecompany_id + "'";
}
if (condition.id_name) {
listSql = listSql + " AND id_name = '" + condition.id_name + "'";
}
if (condition.id_no) {
listSql = listSql + " AND id_no = '" + condition.id_no + "'";
}
if (condition.mobile) {
listSql = listSql + " AND mobile = '" + condition.mobile + "'";
}
listSql = listSql + " GROUP BY id_no";
var countSql = "SELECT COUNT(ta.id_no) count FROM (" + listSql + ") ta";
listSql = listSql + " ORDER BY create_time DESC LIMIT " + Number(startRow) + ", " + Number(pageSize);
var countrs = await this.settledb.query(countSql);
var total = countrs[0][0].count;
if (total == 0) {
return {count: 0, list: []}
}
var list = await this.settledb.query(listSql);
if (list[0].length > 0) {
for (let i = 0;i < list[0].length; i++){
list[0][i].create_time = moment( list[0][i].create_time).format("YYYY-MM-DD HH:mm:ss");
}
}
return {count: total, list: list[0]}
}
async ratepayingToMonth(condition) {
var currentPage = Number(condition.currentPage || 1);
var pageSize = Number(condition.pageSize || 20);
var startRow = (currentPage - 1) * pageSize;
this.addmonth(condition);
var listSql = "SELECT SUM(actual_amt) actual_amt,SUM(income_tax) income_tax,id_name,mobile,id_no,create_time FROM tbl_order_item WHERE trade_status = '00'";
if(condition.ecompany_id){
listSql = listSql + " AND busi_id = '" + condition.ecompany_id + "'";
}
if (condition.createBegin) {
listSql = listSql + " AND `create_time` >= '" + condition.createBegin + "' ";
}
if (condition.createEnd) {
listSql = listSql + " AND `create_time` <= '" + condition.createEnd + "' ";
}
listSql = listSql + " GROUP BY id_no";
var countSql = "SELECT COUNT(ta.id_no) count FROM (" + listSql + ") ta";
listSql = listSql + " ORDER BY create_time DESC LIMIT " + Number(startRow) + ", " + Number(pageSize);
var countrs = await this.settledb.query(countSql);
var total = countrs[0][0].count;
if (total == 0) {
return {count: 0, list: []}
}
var list = await this.settledb.query(listSql);
if (list[0].length > 0) {
for (let i = 0;i < list[0].length; i++){
list[0][i].create_time = moment( list[0][i].create_time).format("YYYY-MM-DD");
}
}
return {count: total, list: list[0]}
}
async ratepayingToOne(condition){
var listSql = "SELECT actual_amt,income_tax,create_time FROM tbl_order_item WHERE trade_status = '00'";
if(condition.ecompany_id){
listSql = listSql + " AND busi_id = '" + condition.ecompany_id + "'";
}
if(condition.id_no){
listSql = listSql + " AND id_no = '" + condition.id_no + "'";
}
var list = await this.settledb.query(listSql);
if (list[0].length > 0) {
for (let i = 0;i < list[0].length; i++){
list[0][i].actual_amt = parseFloat((Number(list[0][i].actual_amt || 0) / 100).toFixed(2));
list[0][i].income_tax = parseFloat((Number(list[0][i].income_tax || 0) / 100).toFixed(2));
list[0][i].create_time = moment( list[0][i].create_time).format("YYYY-MM-DD");
}
}
return {list: list[0]};
}
async getPays(condition){
var countSql = "SELECT SUM(actual_amt) actual_amt,SUM(income_tax) income_tax FROM tbl_order_item WHERE trade_status = '00' AND busi_id IN (" + "'" + condition.ecompanyIds.join("','") + "'" + ") ";
var list = await this.settledb.query(countSql);
return {actual_amt:list[0][0].actual_amt,income_tax:list[0][0].income_tax}
}
async settlePage(condition) {
var currentPage = Number(condition.currentPage || 1);
var pageSize = Number(condition.pageSize || 20);
......@@ -120,47 +212,47 @@ class EsettleService extends ServiceBase {
"INNER JOIN `tbl_busi` t2 ON t1.`busi_id` = t2.`id` " +
"WHERE 1 = 1 ";
if(condition.busi_id) {
if (condition.busi_id) {
countSql = countSql + " AND t2.`id` = " + condition.busi_id + " ";
listSql = listSql + " AND t2.`id` = " + condition.busi_id + " ";
}
if(condition.companyNames && condition.companyNames.length > 0) {
if (condition.companyNames && condition.companyNames.length > 0) {
countSql = countSql + " AND t2.`company_name` IN (" + "'" + condition.companyNames.join("','") + "'" + ") ";
listSql = listSql + " AND t2.`company_name` IN (" + "'" + condition.companyNames.join("','") + "'" + ") ";
}
if(condition.companyName) {
if (condition.companyName) {
countSql = countSql + " AND t2.`company_name` = '" + condition.companyName + "' ";
listSql = listSql + " AND t2.`company_name` = '" + condition.companyName + "' ";
}
if(condition.companyNameLike) {
if (condition.companyNameLike) {
countSql = countSql + " AND t2.`company_name` LIKE :companyNameLike ";
listSql = listSql + " AND t2.`company_name` LIKE :companyNameLike ";
}
if(condition.createBegin) {
if (condition.createBegin) {
countSql = countSql + " AND t1.`create_time` >= '" + condition.createBegin + "' ";
listSql = listSql + " AND t1.`create_time` >= '" + condition.createBegin + "' ";
}
if(condition.createEnd) {
if (condition.createEnd) {
countSql = countSql + " AND t1.`create_time` <= '" + condition.createEnd + "' ";
listSql = listSql + " AND t1.`create_time` <= '" + condition.createEnd + "' ";
}
if(condition.out_trade_no) {
if (condition.out_trade_no) {
countSql = countSql + " AND t1.`out_trade_no` = '" + condition.out_trade_no + "' ";
listSql = listSql + " AND t1.`out_trade_no` = '" + condition.out_trade_no + "' ";
}
if(condition.amtBegin) {
if (condition.amtBegin) {
countSql = countSql + " AND t1.`amt` >= " + condition.amtBegin;
listSql = listSql + " AND t1.`amt` >= " + condition.amtBegin;
}
if(condition.amtEnd) {
if (condition.amtEnd) {
countSql = countSql + " AND t1.`amt` <= " + condition.amtEnd;
listSql = listSql + " AND t1.`amt` <= " + condition.amtEnd;
}
......@@ -168,37 +260,37 @@ class EsettleService extends ServiceBase {
listSql = listSql + " GROUP BY t1.id ORDER BY t1.`pay_complete_time` DESC ";
listSql = listSql + " LIMIT " + Number(startRow) + ", " + Number(pageSize);
var countrs = await this.settledb.query(countSql, { replacements: { companyNameLike : "%" + condition.companyNameLike + "%" } });
var countrs = await this.settledb.query(countSql, {replacements: {companyNameLike: "%" + condition.companyNameLike + "%"}});
var total = 0;
if(countrs && countrs[0,0]) {
total = countrs[0,0][0].num;
if (countrs && countrs[0, 0]) {
total = countrs[0, 0][0].num;
}
if(total == 0) {
return {count:0, rows:[]}
if (total == 0) {
return {count: 0, rows: []}
}
var list = await this.settledb.query(listSql, { replacements: { companyNameLike : "%" + condition.companyNameLike + "%" } });
if(list && list.length > 0) {
list = list[0,0] || [];
var list = await this.settledb.query(listSql, {replacements: {companyNameLike: "%" + condition.companyNameLike + "%"}});
if (list && list.length > 0) {
list = list[0, 0] || [];
var orderIds = [];
for(var item of list) {
for (var item of list) {
orderIds.push(item.order_id);
}
var itmap = [];
if(orderIds.length > 0) {
if (orderIds.length > 0) {
var itemSql = "SELECT order_id, COUNT(1) AS num FROM `tbl_order_item` WHERE order_id IN (" + orderIds.join(",") + ") GROUP BY order_id ";
var itlist = await this.settledb.query(itemSql);
if(itlist && itlist.length > 0) {
if (itlist && itlist.length > 0) {
itlist = itlist[0, 0] || [];
for(var itc of itlist) {
for (var itc of itlist) {
itmap['order_id_' + itc.order_id] = itc.num || 0;
}
}
}
for(var item of list) {
for (var item of list) {
item.amt = parseFloat((Number(item.amt || 0) / 100).toFixed(2));
item.actual_amt = parseFloat((Number(item.actual_amt || 0) / 100).toFixed(2));
item.deduct_amt = parseFloat((Number(item.deduct_amt || 0) / 100).toFixed(2));
......@@ -221,18 +313,18 @@ class EsettleService extends ServiceBase {
item.trade_type_name = "";
}
if(item.create_time) {
if (item.create_time) {
item.create_time = moment(item.create_time).subtract(8, "hours").format("YYYY-MM-DD HH:mm");
}
if(item.pay_complete_time) {
if (item.pay_complete_time) {
item.pay_complete_time = moment(item.pay_complete_time).subtract(8, "hours").format("YYYY-MM-DD HH:mm");
}
item.itemCount = itmap["order_id_" + item.order_id] || 0;
}
} else{
} else {
list = []
}
return {count: total, rows:list};
return {count: total, rows: list};
}
async statSettleAmt(condition) {
......@@ -242,44 +334,44 @@ class EsettleService extends ServiceBase {
"INNER JOIN `tbl_busi` t2 ON t1.`busi_id` = t2.`id` " +
"WHERE 1 = 1 ";
if(condition.companyNames && condition.companyNames.length > 0) {
if (condition.companyNames && condition.companyNames.length > 0) {
sql = sql + " AND t2.`company_name` IN (" + "'" + condition.companyNames.join("','") + "'" + ") ";
}
if(condition.companyName) {
if (condition.companyName) {
sql = sql + " AND t2.`company_name` = '" + condition.companyName + "' ";
}
if(condition.companyNameLike) {
if (condition.companyNameLike) {
sql = sql + " AND t2.`company_name` LIKE :companyNameLike ";
}
if(condition.createBegin) {
if (condition.createBegin) {
sql = sql + " AND t1.`create_time` >= '" + condition.createBegin + "' ";
}
if(condition.createEnd) {
if (condition.createEnd) {
sql = sql + " AND t1.`create_time` >= '" + condition.createBegin + "' ";
}
if(condition.out_trade_no) {
if (condition.out_trade_no) {
sql = sql + " AND t1.`out_trade_no` = '" + condition.out_trade_no + "' ";
}
if(condition.amtBegin) {
if (condition.amtBegin) {
sql = sql + " AND t1.`amt` >= " + condition.amtBegin;
}
if(condition.amtEnd) {
if (condition.amtEnd) {
sql = sql + " AND t1.`amt` <= " + condition.amtEnd;
}
sql = sql + " GROUP BY t1.id ";
var amt = 0;
var list = await this.settledb.query(sql, { replacements: { companyNameLike : "%" + condition.companyNameLike + "%" } });
if(list && list.length > 0) {
list = list[0,0] || [];
for(var item of list) {
var list = await this.settledb.query(sql, {replacements: {companyNameLike: "%" + condition.companyNameLike + "%"}});
if (list && list.length > 0) {
list = list[0, 0] || [];
for (var item of list) {
amt = amt + Number(item.amt);
}
}
......@@ -295,7 +387,7 @@ class EsettleService extends ServiceBase {
var listSql = "SELECT * FROM tbl_order_item WHERE 1 = 1 ";
var where = {};
if(condition.orderId) {
if (condition.orderId) {
countSql = countSql + " AND order_id = :orderId ";
listSql = listSql + " AND order_id = :orderId ";
where.orderId = condition.orderId;
......@@ -306,18 +398,18 @@ class EsettleService extends ServiceBase {
var countrs = await this.settledb.query(countSql, {replacements: where});
var total = 0;
if(countrs && countrs[0,0]) {
total = countrs[0,0][0].num;
if (countrs && countrs[0, 0]) {
total = countrs[0, 0][0].num;
}
if(total == 0) {
return {count:0, rows:[]}
if (total == 0) {
return {count: 0, rows: []}
}
var list = await this.settledb.query(listSql, { replacements: where});
if(list && list.length > 0) {
list = list[0,0] || [];
for(var item of list) {
var list = await this.settledb.query(listSql, {replacements: where});
if (list && list.length > 0) {
list = list[0, 0] || [];
for (var item of list) {
item.amt = parseFloat((Number(item.amt || 0) / 100).toFixed(2));
item.actual_amt = parseFloat((Number(item.actual_amt || 0) / 100).toFixed(2));
item.deduct_amt = parseFloat((Number(item.deduct_amt || 0) / 100).toFixed(2));
......@@ -340,34 +432,34 @@ class EsettleService extends ServiceBase {
item.trade_type_name = "";
}
if(item.create_time) {
if (item.create_time) {
item.create_time = moment(item.create_time).subtract(8, "hours").format("YYYY-MM-DD HH:mm");
}
if(item.pay_complete_time) {
if (item.pay_complete_time) {
item.pay_complete_time = moment(item.pay_complete_time).subtract(8, "hours").format("YYYY-MM-DD HH:mm");
}
}
} else{
} else {
list = []
}
return {count: total, rows:list};
return {count: total, rows: list};
}
async doCommission(orderId) {
var tblorder = await this.findTBLOrderById(orderId);
if(!tblorder || !tblorder.company_name) {
if (!tblorder || !tblorder.company_name) {
return;
}
var ecompany = await this.ecompanyDao.findOne({name:tblorder.company_name});
var ecompany = await this.ecompanyDao.findOne({name: tblorder.company_name});
var ecompanyId = 0;
var epartnerId = 0;
var epartnerUserId = 0;
var epartner = null;
if(ecompany) {
if (ecompany) {
ecompanyId = ecompany.id;
epartner = await this.epartnerDao.findById(ecompany.epartner_id);
if(epartner) {
if (epartner) {
epartnerId = epartner.id;
epartnerUserId = epartner.user_id;
}
......@@ -380,7 +472,7 @@ class EsettleService extends ServiceBase {
var payTime = moment(tblorder.create_time).subtract(8, "hours");
var payCompleteTime = moment(tblorder.create_time).subtract(8, "hours");
var month = Number(moment(payCompleteTime).format("YYYYMM"));
if(!settle) {
if (!settle) {
settle = {
ecompany_id: ecompanyId,
ecompanyName: tblorder.company_name,
......@@ -420,7 +512,7 @@ class EsettleService extends ServiceBase {
await settle.save();
}
if(ecompany && epartner) {
if (ecompany && epartner) {
await this.addCommission(settle, epartner, ecompany);
}
}
......@@ -449,7 +541,7 @@ class EsettleService extends ServiceBase {
var lastMonth = Number(moment(esettle.pay_complete_time).subtract(1, 'months').format("YYYYMM"));
var sql = "SELECT COUNT(1) as num FROM `c_esettle_commission` WHERE ecompany_id = :ecompanyId AND `month` = :month ";
var countrs = await this.customQuery(sql, {ecompanyId: ecompany.id, month: lastMonth});
if(countrs && countrs.length > 0 && countrs[0].num) {
if (countrs && countrs.length > 0 && countrs[0].num) {
ecompany.isBenefit = false;
await ecompany.save();
return;
......@@ -461,9 +553,12 @@ class EsettleService extends ServiceBase {
commissionType = '0';
}
var esettleCommssion = await this.esettlecommissionDao.findOne({esettle_id: esettle.id, epartner_id: epartner.id});
var esettleCommssion = await this.esettlecommissionDao.findOne({
esettle_id: esettle.id,
epartner_id: epartner.id
});
var isExist = esettleCommssion ? true : false;
if(!isExist) {
if (!isExist) {
esettleCommssion = {};
}
esettleCommssion.month = esettle.month;
......@@ -485,7 +580,7 @@ class EsettleService extends ServiceBase {
esettleCommssion.epartnerSourceName = "";
esettleCommssion.pay_complete_time = esettle.pay_complete_time;
if(isExist) {
if (isExist) {
await esettleCommssion.save();
} else {
await this.esettlecommissionDao.create(esettleCommssion);
......@@ -496,9 +591,12 @@ class EsettleService extends ServiceBase {
var pcommission = Math.floor(commission * 0.1);
pcommission = pcommission < 0 ? 0 : pcommission;
var pesettleCommssion = await this.esettlecommissionDao.findOne({esettle_id: esettle.id, epartner_id: pepartner.id});
var pesettleCommssion = await this.esettlecommissionDao.findOne({
esettle_id: esettle.id,
epartner_id: pepartner.id
});
var pIsExist = pesettleCommssion ? true : false;
if(!pIsExist) {
if (!pIsExist) {
pesettleCommssion = {};
}
pesettleCommssion.month = esettle.month;
......@@ -521,7 +619,7 @@ class EsettleService extends ServiceBase {
pesettleCommssion.epartnerSourceName = epartner.nickName;
pesettleCommssion.pay_complete_time = esettle.pay_complete_time;
if(pIsExist) {
if (pIsExist) {
await pesettleCommssion.save();
} else {
await this.esettlecommissionDao.create(pesettleCommssion);
......@@ -531,11 +629,11 @@ class EsettleService extends ServiceBase {
async settleCommission(begin, end) {
var orderIds = await this.findTBLOrderIds(begin, end);
if(!orderIds || orderIds.length == 0) {
if (!orderIds || orderIds.length == 0) {
return;
}
for(var order of orderIds) {
for (var order of orderIds) {
try {
await this.doCommission(order.id);
} catch (error) {
......@@ -559,19 +657,19 @@ class EsettleService extends ServiceBase {
var where = {id: id};
var list = await this.settledb.query(sql.join(" "), {replacements: where});
if(list && list.length > 0) {
list = list[0,0] || [];
if (list && list.length > 0) {
list = list[0, 0] || [];
}
return list && list.length > 0 ? list[0] : null;
}
async findTBLOrderIds(begin, end) {
if(!begin) {
if (!begin) {
begin = moment().subtract(3, "days").format("YYYY-MM-DD");
}
begin = begin + " 00:00:00";
if(!end) {
if (!end) {
end = moment().format("YYYY-MM-DD");
}
end = end + " 23:59:59";
......@@ -587,8 +685,8 @@ class EsettleService extends ServiceBase {
sql.push("ORDER BY pay_complete_time ASC");
var where = {begin: begin, end: end};
var list = await this.settledb.query(sql.join(" "), {replacements: where});
if(list && list.length > 0) {
list = list[0,0] || [];
if (list && list.length > 0) {
list = list[0, 0] || [];
}
return list;
}
......@@ -611,13 +709,13 @@ class EsettleService extends ServiceBase {
listSql.push("WHERE 1 = 1 ");
var where = {};
if(condition.companyNames) {
if (condition.companyNames) {
countSql.push(" AND t2.company_name IN (:companyNames)");
listSql.push(" AND t2.company_name IN (:companyNames)");
where.companyNames = condition.companyNames;
}
if(condition.ecompanyName) {
if (condition.ecompanyName) {
countSql.push(" AND t2.`company_name` LIKE :companyNameLike ");
listSql.push(" AND t2.`company_name` LIKE :companyNameLike ");
where.companyNameLike = "%" + condition.ecompanyName + "%";
......@@ -628,25 +726,25 @@ class EsettleService extends ServiceBase {
var countrs = await this.settledb.query(countSql.join(" "), {replacements: where});
var total = 0;
if(countrs && countrs[0,0]) {
total = countrs[0,0][0].num;
if (countrs && countrs[0, 0]) {
total = countrs[0, 0][0].num;
}
if(total == 0) {
return {count:0, rows:[]}
if (total == 0) {
return {count: 0, rows: []}
}
var list = await this.settledb.query(listSql.join(" "), { replacements: where});
if(list && list.length > 0) {
list = list[0,0] || [];
for(var item of list) {
var list = await this.settledb.query(listSql.join(" "), {replacements: where});
if (list && list.length > 0) {
list = list[0, 0] || [];
for (var item of list) {
item.available_amt = parseFloat((Number(item.available_amt || 0) / 100).toFixed(2));
item.frozen_amt = parseFloat((Number(item.frozen_amt || 0) / 100).toFixed(2));
}
} else{
} else {
list = []
}
return {count: total, rows:list};
return {count: total, rows: list};
}
async statOnlineSettle(params) {
......@@ -662,20 +760,20 @@ class EsettleService extends ServiceBase {
sql.push("tbl_order_item");
sql.push("WHERE pay_complete_time IS NOT NULL AND trade_status = '00'");
var where = {};
if(params.payTimeBegin) {
if (params.payTimeBegin) {
sql.push("AND pay_complete_time >= :payTimeBegin");
where.payTimeBegin = params.payTimeBegin;
}
if(params.payTimeEnd) {
if (params.payTimeEnd) {
sql.push("AND pay_complete_time <= :payTimeEnd");
where.payTimeEnd = params.payTimeEnd;
}
var stat = {};
var list = await this.settledb.query(sql.join(" "), {replacements: where});
if(list && list.length > 0) {
list = list[0,0] || [];
if(list && list.length > 0) {
if (list && list.length > 0) {
list = list[0, 0] || [];
if (list && list.length > 0) {
stat = list[0] || {};
stat.amtCount = system.f2y(stat.amtCount);
stat.actualAmtCount = system.f2y(stat.actualAmtCount);
......@@ -688,7 +786,7 @@ class EsettleService extends ServiceBase {
async findIncomeTaxById(orderItemId) {
var getTax = {};
if(!orderItemId) {
if (!orderItemId) {
return getTax;
}
var sql = [];
......@@ -698,15 +796,15 @@ class EsettleService extends ServiceBase {
sql.push("tbl_order_item ");
sql.push("WHERE pay_complete_time IS NOT NULL AND trade_status = '00'");
var where = {};
if(orderItemId) {
if (orderItemId) {
sql.push("AND id = :id");
where.id = orderItemId;
}
var list = await this.settledb.query(sql.join(" "), {replacements: where});
if(list && list.length > 0) {
list = list[0,0] || [];
if(list && list.length > 0) {
if (list && list.length > 0) {
list = list[0, 0] || [];
if (list && list.length > 0) {
getTax = list[0] || {};
getTax.incomeTax = getTax.incomeTax;
}
......@@ -715,7 +813,7 @@ class EsettleService extends ServiceBase {
}
async findOrderItemById(orderItemId) {
if(!orderItemId) {
if (!orderItemId) {
return null;
}
var sql = [];
......@@ -725,15 +823,15 @@ class EsettleService extends ServiceBase {
sql.push("tbl_order_item ");
sql.push("WHERE pay_complete_time IS NOT NULL AND trade_status = '00'");
var where = {};
if(orderItemId) {
if (orderItemId) {
sql.push("AND id = :id");
where.id = orderItemId;
}
var getTax;
var list = await this.settledb.query(sql.join(" "), {replacements: where});
if(list && list.length > 0) {
list = list[0,0] || [];
if(list && list.length > 0) {
if (list && list.length > 0) {
list = list[0, 0] || [];
if (list && list.length > 0) {
getTax = list[0];
}
}
......@@ -741,4 +839,5 @@ class EsettleService extends ServiceBase {
}
}
module.exports = EsettleService;
\ No newline at end of file
......@@ -131,5 +131,12 @@ class ServiceBase{
}
return o.toString().trim();
}
addmonth(params) {
if (this.trim(params.month)) {
params.createBegin = moment(params.month).format("YYYY-MM-DD") + " 00:00:00";
params.createEnd = moment(params.month).add(1, "months").subtract(1, 'days').format("YYYY-MM-DD") + " 23:59:59";
}
}
}
module.exports=ServiceBase;
......@@ -3,15 +3,15 @@ var settings = {
host: "43.247.184.32",
port: 8967,
password: "Gongsibao2018",
db:10,
db:11,
},
database: {
dbname: "bpo",
user: "root",
password: "123456",
user: "write",
password: "write",
config: {
host: '43.247.184.35',
port: 8899,
host: '192.168.18.237',
port: 3306,
dialect: 'mysql',
operatorsAliases: false,
pool: {
......
This source diff could not be displayed because it is too large. You can view the blob instead.
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