Commit 5ef789fc by 王昆

gsb

parent bcbb9cbf
...@@ -317,6 +317,16 @@ class EsettleCtl extends CtlBase { ...@@ -317,6 +317,16 @@ class EsettleCtl extends CtlBase {
params.companyNames = nameList; params.companyNames = nameList;
var page = await this.service.settlePage(params); var page = await this.service.settlePage(params);
if(page.rows) {
for(let row of page.rows) {
row.bankno = row.bank_no;
if(row.bank_no) {
if(row.bank_no > 4) {
row.bank_no = "************" + row.bank_no.substring(row.bank_no.length - 4);
}
}
}
}
return system.getResult2(page); return system.getResult2(page);
} catch (e) { } catch (e) {
console.log(e); console.log(e);
......
...@@ -6,7 +6,7 @@ class EsettleService extends ServiceBase { ...@@ -6,7 +6,7 @@ class EsettleService extends ServiceBase {
constructor() { constructor() {
super(ServiceBase.getDaoName(EsettleService)); super(ServiceBase.getDaoName(EsettleService));
//this.appDao=system.getObject("db.appDao"); //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.ecompanyDao = system.getObject("db.ecompanyDao");
this.epartnerDao = system.getObject("db.epartnerDao"); this.epartnerDao = system.getObject("db.epartnerDao");
...@@ -22,18 +22,18 @@ class EsettleService extends ServiceBase { ...@@ -22,18 +22,18 @@ class EsettleService extends ServiceBase {
async countAmtByCard(idno, begin, end) { async countAmtByCard(idno, begin, end) {
var sql = "SELECT sum(actual_amt) as num FROM `tbl_order_item` t1 " + var sql = "SELECT sum(actual_amt) as num FROM `tbl_order_item` t1 " +
"WHERE t1.trade_status = '00' AND t1.id_no = '" + idno + "' "; "WHERE t1.trade_status = '00' AND t1.id_no = '" + idno + "' ";
if(begin) { if (begin) {
sql = sql + " AND t1.pay_complete_time >= '" + begin + "' "; sql = sql + " AND t1.pay_complete_time >= '" + begin + "' ";
} }
if(end) { if (end) {
sql = sql + " AND t1.pay_complete_time <= '" + end + "' "; sql = sql + " AND t1.pay_complete_time <= '" + end + "' ";
} }
var count = 0; var count = 0;
var countrs = await this.settledb.query(sql); var countrs = await this.settledb.query(sql);
if(countrs && countrs[0,0]) { if (countrs && countrs[0, 0]) {
count = countrs[0,0][0].num; count = countrs[0, 0][0].num;
} }
return parseFloat((Number(count || 0) / 100).toFixed(2)); return parseFloat((Number(count || 0) / 100).toFixed(2));
} }
...@@ -44,38 +44,38 @@ class EsettleService extends ServiceBase { ...@@ -44,38 +44,38 @@ class EsettleService extends ServiceBase {
var startRow = (currentPage - 1) * pageSize; var startRow = (currentPage - 1) * pageSize;
var countSql = "SELECT COUNT(1) as num FROM `tbl_order_item` t1 " + var countSql = "SELECT COUNT(1) as num FROM `tbl_order_item` t1 " +
"INNER JOIN `tbl_busi` t3 ON t3.`id` = t1.`busi_id` " + "INNER JOIN `tbl_busi` t3 ON t3.`id` = t1.`busi_id` " +
"WHERE t1.trade_status = '00' AND t1.id_no = '" + idno + "' " + "WHERE t1.trade_status = '00' AND t1.id_no = '" + idno + "' " +
"ORDER BY t1.`pay_complete_time` DESC "; "ORDER BY t1.`pay_complete_time` DESC ";
var countrs = await this.settledb.query(countSql); var countrs = await this.settledb.query(countSql);
var total = 0; var total = 0;
if(countrs && countrs[0,0]) { if (countrs && countrs[0, 0]) {
total = countrs[0,0][0].num; total = countrs[0, 0][0].num;
} }
if(total == 0) { if (total == 0) {
return {count:0, rows:[]} 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 " + 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 " +
"INNER JOIN `tbl_busi` t3 ON t3.`id` = t1.`busi_id` " + "INNER JOIN `tbl_busi` t3 ON t3.`id` = t1.`busi_id` " +
"WHERE t1.trade_status = '00' AND t1.id_no = '" + idno + "' " + "WHERE t1.trade_status = '00' AND t1.id_no = '" + idno + "' " +
"ORDER BY t1.`pay_complete_time` DESC " + "ORDER BY t1.`pay_complete_time` DESC " +
"LIMIT " + Number(startRow) + ", " + Number(pageSize); "LIMIT " + Number(startRow) + ", " + Number(pageSize);
var list = await this.settledb.query(sql); var list = await this.settledb.query(sql);
if(list && list.length > 0) { if (list && list.length > 0) {
list = list[0,0]; list = list[0, 0];
for(var item of list) { for (var item of list) {
item.actual_amt = parseFloat((Number(item.actual_amt || 0) / 100).toFixed(2)); 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"); item.pay_complete_time = moment(item.pay_complete_time).format("YYYY-MM-DD HH:mm");
} }
} }
} else{ } else {
list = [] list = []
} }
return {count: total, rows:list}; return { count: total, rows: list };
} }
async statSettle(params) { async statSettle(params) {
...@@ -84,19 +84,19 @@ class EsettleService extends ServiceBase { ...@@ -84,19 +84,19 @@ class EsettleService extends ServiceBase {
sql = sql + "INNER JOIN `tbl_busi` t2 ON t1.`busi_id` = t2.id "; sql = sql + "INNER JOIN `tbl_busi` t2 ON t1.`busi_id` = t2.id ";
sql = sql + "WHERE t1.`trade_status` = '00' "; sql = sql + "WHERE t1.`trade_status` = '00' ";
if(params.company_name) { if (params.company_name) {
sql = sql + " AND t2.company_name = :company_name "; sql = sql + " AND t2.company_name = :company_name ";
} }
if(params.begin) { if (params.begin) {
sql = sql + " AND pay_complete_time >= :begin "; sql = sql + " AND pay_complete_time >= :begin ";
} }
if(params.end) { if (params.end) {
sql = sql + " AND pay_complete_time <= :end "; sql = sql + " AND pay_complete_time <= :end ";
} }
var list = await this.settledb.query(sql); var list = await this.settledb.query(sql);
if(list && list.length > 0) { if (list && list.length > 0) {
list = list[0,0]; list = list[0, 0];
return list[0].num || 0; return list[0].num || 0;
} }
return 0; return 0;
...@@ -113,92 +113,92 @@ class EsettleService extends ServiceBase { ...@@ -113,92 +113,92 @@ class EsettleService extends ServiceBase {
"WHERE 1 = 1 "; "WHERE 1 = 1 ";
var listSql = "SELECT " + var listSql = "SELECT " +
"t2.`company_name`, t2.`open_bank`, t2.`bank_no`, t2.`bank_account_name`, t1.busi_id, " + "t2.`company_name`, t2.`open_bank`, t2.`bank_no`, t2.`bank_account_name`, t1.busi_id, " +
"t1.id AS order_id, t1.out_trade_no, t1.`amt`, t1.`actual_amt`, t1.`deduct_amt`, t1.trade_status , t1.trade_type, " + "t1.id AS order_id, t1.out_trade_no, t1.`amt`, t1.`actual_amt`, t1.`deduct_amt`, t1.trade_status , t1.trade_type, " +
"t1.`create_time`, t1.pay_complete_time " + "t1.`create_time`, t1.pay_complete_time " +
"FROM tbl_order t1 " + "FROM tbl_order t1 " +
"INNER JOIN `tbl_busi` t2 ON t1.`busi_id` = t2.`id` " + "INNER JOIN `tbl_busi` t2 ON t1.`busi_id` = t2.`id` " +
"WHERE 1 = 1 "; "WHERE 1 = 1 ";
if(condition.busi_id) { if (condition.busi_id) {
countSql = countSql + " AND t2.`id` = '" + condition.busi_id + "' "; countSql = countSql + " AND t2.`id` = '" + condition.busi_id + "' ";
listSql = listSql + " 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("','") + "'" + ") "; countSql = countSql + " AND t2.`company_name` IN (" + "'" + condition.companyNames.join("','") + "'" + ") ";
listSql = listSql + " 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 + "' "; countSql = countSql + " AND t2.`company_name` = '" + condition.companyName + "' ";
listSql = listSql + " 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 "; countSql = countSql + " AND t2.`company_name` LIKE :companyNameLike ";
listSql = listSql + " 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 + "' "; countSql = countSql + " AND t1.`create_time` >= '" + condition.createBegin + "' ";
listSql = listSql + " 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 + "' "; countSql = countSql + " AND t1.`create_time` <= '" + condition.createEnd + "' ";
listSql = listSql + " 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 + "' "; countSql = countSql + " AND t1.`out_trade_no` = '" + condition.out_trade_no + "' ";
listSql = listSql + " 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; countSql = countSql + " AND t1.`amt` >= " + condition.amtBegin;
listSql = listSql + " 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; countSql = countSql + " AND t1.`amt` <= " + condition.amtEnd;
listSql = listSql + " AND t1.`amt` <= " + condition.amtEnd; listSql = listSql + " AND t1.`amt` <= " + condition.amtEnd;
} }
listSql = listSql + " GROUP BY t1.id ORDER BY t1.`pay_complete_time` DESC "; listSql = listSql + " GROUP BY t1.id ORDER BY t1.`pay_complete_time` DESC ";
listSql = listSql + " LIMIT " + Number(startRow) + ", " + Number(pageSize); 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; var total = 0;
if(countrs && countrs[0,0]) { if (countrs && countrs[0, 0]) {
total = countrs[0,0][0].num; total = countrs[0, 0][0].num;
} }
if(total == 0) { if (total == 0) {
return {count:0, rows:[]} return { count: 0, rows: [] }
} }
var list = await this.settledb.query(listSql, { replacements: { companyNameLike : "%" + condition.companyNameLike + "%" } }); var list = await this.settledb.query(listSql, { replacements: { companyNameLike: "%" + condition.companyNameLike + "%" } });
if(list && list.length > 0) { if (list && list.length > 0) {
list = list[0,0] || []; list = list[0, 0] || [];
var orderIds = []; var orderIds = [];
for(var item of list) { for (var item of list) {
orderIds.push(item.order_id); orderIds.push(item.order_id);
} }
var itmap = []; 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 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); var itlist = await this.settledb.query(itemSql);
if(itlist && itlist.length > 0) { if (itlist && itlist.length > 0) {
itlist = itlist[0, 0] || []; itlist = itlist[0, 0] || [];
for(var itc of itlist) { for (var itc of itlist) {
itmap['order_id_' + itc.order_id] = itc.num || 0; 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.amt = parseFloat((Number(item.amt || 0) / 100).toFixed(2));
item.actual_amt = parseFloat((Number(item.actual_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)); item.deduct_amt = parseFloat((Number(item.deduct_amt || 0) / 100).toFixed(2));
...@@ -221,69 +221,69 @@ class EsettleService extends ServiceBase { ...@@ -221,69 +221,69 @@ class EsettleService extends ServiceBase {
item.trade_type_name = ""; 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"); 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.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; item.itemCount = itmap["order_id_" + item.order_id] || 0;
} }
} else{ } else {
list = [] list = []
} }
return {count: total, rows:list}; return { count: total, rows: list };
} }
async statSettleAmt(condition) { async statSettleAmt(condition) {
var sql = "SELECT " + var sql = "SELECT " +
"t1.`amt` " + "t1.`amt` " +
"FROM tbl_order_item t1 " + "FROM tbl_order_item t1 " +
"INNER JOIN `tbl_busi` t2 ON t1.`busi_id` = t2.`id` " + "INNER JOIN `tbl_busi` t2 ON t1.`busi_id` = t2.`id` " +
"WHERE trade_status = '00' "; "WHERE trade_status = '00' ";
if(condition.busi_id) { if (condition.busi_id) {
sql = sql + " AND t2.`id` = '" + condition.busi_id + "' "; sql = sql + " AND t2.`id` = '" + condition.busi_id + "' ";
} }
if(condition.companyNames && condition.companyNames.length > 0) { if (condition.companyNames && condition.companyNames.length > 0) {
sql = sql + " AND t2.`company_name` IN (" + "'" + condition.companyNames.join("','") + "'" + ") "; sql = sql + " AND t2.`company_name` IN (" + "'" + condition.companyNames.join("','") + "'" + ") ";
} }
if(condition.companyName) { if (condition.companyName) {
sql = sql + " AND t2.`company_name` = '" + condition.companyName + "' "; sql = sql + " AND t2.`company_name` = '" + condition.companyName + "' ";
} }
if(condition.companyNameLike) { if (condition.companyNameLike) {
sql = sql + " AND t2.`company_name` LIKE :companyNameLike "; sql = sql + " AND t2.`company_name` LIKE :companyNameLike ";
} }
if(condition.createBegin) { if (condition.createBegin) {
sql = sql + " AND t1.`create_time` >= '" + condition.createBegin + "' "; sql = sql + " AND t1.`create_time` >= '" + condition.createBegin + "' ";
} }
if(condition.createEnd) { if (condition.createEnd) {
sql = sql + " AND t1.`create_time` >= '" + condition.createBegin + "' "; 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 + "' "; sql = sql + " AND t1.`out_trade_no` = '" + condition.out_trade_no + "' ";
} }
if(condition.amtBegin) { if (condition.amtBegin) {
sql = sql + " AND t1.`amt` >= " + condition.amtBegin; sql = sql + " AND t1.`amt` >= " + condition.amtBegin;
} }
if(condition.amtEnd) { if (condition.amtEnd) {
sql = sql + " AND t1.`amt` <= " + condition.amtEnd; sql = sql + " AND t1.`amt` <= " + condition.amtEnd;
} }
sql = sql + " GROUP BY t1.id "; sql = sql + " GROUP BY t1.id ";
var amt = 0; var amt = 0;
var list = await this.settledb.query(sql, { replacements: { companyNameLike : "%" + condition.companyNameLike + "%" } }); var list = await this.settledb.query(sql, { replacements: { companyNameLike: "%" + condition.companyNameLike + "%" } });
if(list && list.length > 0) { if (list && list.length > 0) {
list = list[0,0] || []; list = list[0, 0] || [];
for(var item of list) { for (var item of list) {
amt = amt + Number(item.amt); amt = amt + Number(item.amt);
} }
} }
...@@ -299,7 +299,7 @@ class EsettleService extends ServiceBase { ...@@ -299,7 +299,7 @@ class EsettleService extends ServiceBase {
var listSql = "SELECT * FROM tbl_order_item WHERE 1 = 1 "; var listSql = "SELECT * FROM tbl_order_item WHERE 1 = 1 ";
var where = {}; var where = {};
if(condition.orderId) { if (condition.orderId) {
countSql = countSql + " AND order_id = :orderId "; countSql = countSql + " AND order_id = :orderId ";
listSql = listSql + " AND order_id = :orderId "; listSql = listSql + " AND order_id = :orderId ";
where.orderId = condition.orderId; where.orderId = condition.orderId;
...@@ -308,20 +308,20 @@ class EsettleService extends ServiceBase { ...@@ -308,20 +308,20 @@ class EsettleService extends ServiceBase {
listSql = listSql + " ORDER BY pay_complete_time DESC, id ASC "; listSql = listSql + " ORDER BY pay_complete_time DESC, id ASC ";
listSql = listSql + " LIMIT " + Number(startRow) + ", " + Number(pageSize); listSql = listSql + " LIMIT " + Number(startRow) + ", " + Number(pageSize);
var countrs = await this.settledb.query(countSql, {replacements: where}); var countrs = await this.settledb.query(countSql, { replacements: where });
var total = 0; var total = 0;
if(countrs && countrs[0,0]) { if (countrs && countrs[0, 0]) {
total = countrs[0,0][0].num; total = countrs[0, 0][0].num;
} }
if(total == 0) { if (total == 0) {
return {count:0, rows:[]} return { count: 0, rows: [] }
} }
var list = await this.settledb.query(listSql, { replacements: where}); var list = await this.settledb.query(listSql, { replacements: where });
if(list && list.length > 0) { if (list && list.length > 0) {
list = list[0,0] || []; list = list[0, 0] || [];
for(var item of list) { for (var item of list) {
item.amt = parseFloat((Number(item.amt || 0) / 100).toFixed(2)); item.amt = parseFloat((Number(item.amt || 0) / 100).toFixed(2));
item.actual_amt = parseFloat((Number(item.actual_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)); item.deduct_amt = parseFloat((Number(item.deduct_amt || 0) / 100).toFixed(2));
...@@ -344,34 +344,40 @@ class EsettleService extends ServiceBase { ...@@ -344,34 +344,40 @@ class EsettleService extends ServiceBase {
item.trade_type_name = ""; 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"); 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.pay_complete_time = moment(item.pay_complete_time).subtract(8, "hours").format("YYYY-MM-DD HH:mm");
} }
item.idno = item.id_no;
if (item.id_no) {
let id_no_show = item.id_no.substring(item.id_no.length - 4);
item.id_no = "**************" + id_no_show;
}
} }
} else{ } else {
list = [] list = []
} }
return {count: total, rows:list}; return { count: total, rows: list };
} }
async doCommission(orderId) { async doCommission(orderId) {
var tblorder = await this.findTBLOrderById(orderId); var tblorder = await this.findTBLOrderById(orderId);
if(!tblorder || !tblorder.company_name) { if (!tblorder || !tblorder.company_name) {
return; 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 ecompanyId = 0;
var epartnerId = 0; var epartnerId = 0;
var epartnerUserId = 0; var epartnerUserId = 0;
var epartner = null; var epartner = null;
if(ecompany) { if (ecompany) {
ecompanyId = ecompany.id; ecompanyId = ecompany.id;
epartner = await this.epartnerDao.findById(ecompany.epartner_id); epartner = await this.epartnerDao.findById(ecompany.epartner_id);
if(epartner) { if (epartner) {
epartnerId = epartner.id; epartnerId = epartner.id;
epartnerUserId = epartner.user_id; epartnerUserId = epartner.user_id;
} }
...@@ -379,12 +385,12 @@ class EsettleService extends ServiceBase { ...@@ -379,12 +385,12 @@ class EsettleService extends ServiceBase {
// || !ecompany.epartner_id || !ecompany.isBenefit // || !ecompany.epartner_id || !ecompany.isBenefit
var settle = await this.findOne({tbl_order_id: orderId}); var settle = await this.findOne({ tbl_order_id: orderId });
var payTime = moment(tblorder.create_time).subtract(8, "hours"); var payTime = moment(tblorder.create_time).subtract(8, "hours");
var payCompleteTime = moment(tblorder.create_time).subtract(8, "hours"); var payCompleteTime = moment(tblorder.create_time).subtract(8, "hours");
var month = Number(moment(payCompleteTime).format("YYYYMM")); var month = Number(moment(payCompleteTime).format("YYYYMM"));
if(!settle) { if (!settle) {
settle = { settle = {
ecompany_id: ecompanyId, ecompany_id: ecompanyId,
ecompanyName: tblorder.company_name, ecompanyName: tblorder.company_name,
...@@ -399,7 +405,7 @@ class EsettleService extends ServiceBase { ...@@ -399,7 +405,7 @@ class EsettleService extends ServiceBase {
amt: tblorder.amt || 0, amt: tblorder.amt || 0,
actual_amt: tblorder.actual_amt || 0, actual_amt: tblorder.actual_amt || 0,
deduct_amt: tblorder.deduct_amt || 0, deduct_amt: tblorder.deduct_amt || 0,
service_tax: tblorder.service_tax || 0, service_tax: tblorder.service_tax || 0,
added_value_tax: tblorder.added_value_tax || 0, added_value_tax: tblorder.added_value_tax || 0,
service_rate: tblorder.service_rate || 0, service_rate: tblorder.service_rate || 0,
} }
...@@ -424,7 +430,7 @@ class EsettleService extends ServiceBase { ...@@ -424,7 +430,7 @@ class EsettleService extends ServiceBase {
await settle.save(); await settle.save();
} }
if(ecompany && epartner) { if (ecompany && epartner) {
await this.addCommission(settle, epartner, ecompany); await this.addCommission(settle, epartner, ecompany);
} }
} }
...@@ -442,7 +448,7 @@ class EsettleService extends ServiceBase { ...@@ -442,7 +448,7 @@ class EsettleService extends ServiceBase {
commission = Math.floor(esettle.service_tax * 0.1); commission = Math.floor(esettle.service_tax * 0.1);
} else if (ecompany.partnerType == '2') { } else if (ecompany.partnerType == '2') {
// 高级 // 高级
if (!serviceRate) { if (!serviceRate) {
commission = 0; commission = 0;
} else { } else {
commission = Math.floor((serviceRate - 1) * esettle.service_tax / serviceRate); commission = Math.floor((serviceRate - 1) * esettle.service_tax / serviceRate);
...@@ -452,8 +458,8 @@ class EsettleService extends ServiceBase { ...@@ -452,8 +458,8 @@ class EsettleService extends ServiceBase {
// 查询公司上个月分润 // 查询公司上个月分润
var lastMonth = Number(moment(esettle.pay_complete_time).subtract(1, 'months').format("YYYYMM")); 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 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}); 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; ecompany.isBenefit = false;
await ecompany.save(); await ecompany.save();
return; return;
...@@ -465,9 +471,9 @@ class EsettleService extends ServiceBase { ...@@ -465,9 +471,9 @@ class EsettleService extends ServiceBase {
commissionType = '0'; 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; var isExist = esettleCommssion ? true : false;
if(!isExist) { if (!isExist) {
esettleCommssion = {}; esettleCommssion = {};
} }
esettleCommssion.month = esettle.month; esettleCommssion.month = esettle.month;
...@@ -489,7 +495,7 @@ class EsettleService extends ServiceBase { ...@@ -489,7 +495,7 @@ class EsettleService extends ServiceBase {
esettleCommssion.epartnerSourceName = ""; esettleCommssion.epartnerSourceName = "";
esettleCommssion.pay_complete_time = esettle.pay_complete_time; esettleCommssion.pay_complete_time = esettle.pay_complete_time;
if(isExist) { if (isExist) {
await esettleCommssion.save(); await esettleCommssion.save();
} else { } else {
await this.esettlecommissionDao.create(esettleCommssion); await this.esettlecommissionDao.create(esettleCommssion);
...@@ -500,9 +506,9 @@ class EsettleService extends ServiceBase { ...@@ -500,9 +506,9 @@ class EsettleService extends ServiceBase {
var pcommission = Math.floor(commission * 0.1); var pcommission = Math.floor(commission * 0.1);
pcommission = pcommission < 0 ? 0 : pcommission; 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; var pIsExist = pesettleCommssion ? true : false;
if(!pIsExist) { if (!pIsExist) {
pesettleCommssion = {}; pesettleCommssion = {};
} }
pesettleCommssion.month = esettle.month; pesettleCommssion.month = esettle.month;
...@@ -514,7 +520,7 @@ class EsettleService extends ServiceBase { ...@@ -514,7 +520,7 @@ class EsettleService extends ServiceBase {
pesettleCommssion.service_tax = esettle.service_tax; pesettleCommssion.service_tax = esettle.service_tax;
pesettleCommssion.service_rate = esettle.service_rate; pesettleCommssion.service_rate = esettle.service_rate;
pesettleCommssion.out_trade_no = esettle.out_trade_no; pesettleCommssion.out_trade_no = esettle.out_trade_no;
pesettleCommssion.commission = commission; pesettleCommssion.commission = commission;
pesettleCommssion.commissionType = "2"; pesettleCommssion.commissionType = "2";
pesettleCommssion.commissionTypeName = "佣金提成"; pesettleCommssion.commissionTypeName = "佣金提成";
...@@ -525,7 +531,7 @@ class EsettleService extends ServiceBase { ...@@ -525,7 +531,7 @@ class EsettleService extends ServiceBase {
pesettleCommssion.epartnerSourceName = epartner.nickName; pesettleCommssion.epartnerSourceName = epartner.nickName;
pesettleCommssion.pay_complete_time = esettle.pay_complete_time; pesettleCommssion.pay_complete_time = esettle.pay_complete_time;
if(pIsExist) { if (pIsExist) {
await pesettleCommssion.save(); await pesettleCommssion.save();
} else { } else {
await this.esettlecommissionDao.create(pesettleCommssion); await this.esettlecommissionDao.create(pesettleCommssion);
...@@ -535,11 +541,11 @@ class EsettleService extends ServiceBase { ...@@ -535,11 +541,11 @@ class EsettleService extends ServiceBase {
async settleCommission(begin, end) { async settleCommission(begin, end) {
var orderIds = await this.findTBLOrderIds(begin, end); var orderIds = await this.findTBLOrderIds(begin, end);
if(!orderIds || orderIds.length == 0) { if (!orderIds || orderIds.length == 0) {
return; return;
} }
for(var order of orderIds) { for (var order of orderIds) {
try { try {
await this.doCommission(order.id); await this.doCommission(order.id);
} catch (error) { } catch (error) {
...@@ -560,22 +566,22 @@ class EsettleService extends ServiceBase { ...@@ -560,22 +566,22 @@ class EsettleService extends ServiceBase {
sql.push("INNER JOIN tbl_busi t2 ON t1.busi_id = t2.id"); sql.push("INNER JOIN tbl_busi t2 ON t1.busi_id = t2.id");
sql.push("INNER JOIN tbl_busi_signed t3 ON t1.busi_id = t3.busi_id"); sql.push("INNER JOIN tbl_busi_signed t3 ON t1.busi_id = t3.busi_id");
sql.push("WHERE t1.id = :id"); sql.push("WHERE t1.id = :id");
var where = {id: id}; var where = { id: id };
var list = await this.settledb.query(sql.join(" "), {replacements: where}); var list = await this.settledb.query(sql.join(" "), { replacements: where });
if(list && list.length > 0) { if (list && list.length > 0) {
list = list[0,0] || []; list = list[0, 0] || [];
} }
return list && list.length > 0 ? list[0] : null; return list && list.length > 0 ? list[0] : null;
} }
async findTBLOrderIds(begin, end) { async findTBLOrderIds(begin, end) {
if(!begin) { if (!begin) {
begin = moment().subtract(3, "days").format("YYYY-MM-DD"); begin = moment().subtract(3, "days").format("YYYY-MM-DD");
} }
begin = begin + " 00:00:00"; begin = begin + " 00:00:00";
if(!end) { if (!end) {
end = moment().format("YYYY-MM-DD"); end = moment().format("YYYY-MM-DD");
} }
end = end + " 23:59:59"; end = end + " 23:59:59";
...@@ -589,10 +595,10 @@ class EsettleService extends ServiceBase { ...@@ -589,10 +595,10 @@ class EsettleService extends ServiceBase {
sql.push("AND pay_complete_time >= :begin AND pay_complete_time <= :end"); sql.push("AND pay_complete_time >= :begin AND pay_complete_time <= :end");
sql.push("AND pay_complete_time IS NOT NULL"); sql.push("AND pay_complete_time IS NOT NULL");
sql.push("ORDER BY pay_complete_time ASC"); sql.push("ORDER BY pay_complete_time ASC");
var where = {begin: begin, end: end}; var where = { begin: begin, end: end };
var list = await this.settledb.query(sql.join(" "), {replacements: where}); var list = await this.settledb.query(sql.join(" "), { replacements: where });
if(list && list.length > 0) { if (list && list.length > 0) {
list = list[0,0] || []; list = list[0, 0] || [];
} }
return list; return list;
} }
...@@ -615,13 +621,13 @@ class EsettleService extends ServiceBase { ...@@ -615,13 +621,13 @@ class EsettleService extends ServiceBase {
listSql.push("WHERE 1 = 1 "); listSql.push("WHERE 1 = 1 ");
var where = {}; var where = {};
if(condition.companyNames) { if (condition.companyNames) {
countSql.push(" AND t2.company_name IN (:companyNames)"); countSql.push(" AND t2.company_name IN (:companyNames)");
listSql.push(" AND t2.company_name IN (:companyNames)"); listSql.push(" AND t2.company_name IN (:companyNames)");
where.companyNames = condition.companyNames; where.companyNames = condition.companyNames;
} }
if(condition.ecompanyName) { if (condition.ecompanyName) {
countSql.push(" AND t2.`company_name` LIKE :companyNameLike "); countSql.push(" AND t2.`company_name` LIKE :companyNameLike ");
listSql.push(" AND t2.`company_name` LIKE :companyNameLike "); listSql.push(" AND t2.`company_name` LIKE :companyNameLike ");
where.companyNameLike = "%" + condition.ecompanyName + "%"; where.companyNameLike = "%" + condition.ecompanyName + "%";
...@@ -630,27 +636,27 @@ class EsettleService extends ServiceBase { ...@@ -630,27 +636,27 @@ class EsettleService extends ServiceBase {
listSql.push(" ORDER BY t1.`available_amt` ASC, t1.`frozen_amt` ASC "); listSql.push(" ORDER BY t1.`available_amt` ASC, t1.`frozen_amt` ASC ");
listSql.push(" LIMIT " + Number(startRow) + ", " + Number(pageSize)); listSql.push(" LIMIT " + Number(startRow) + ", " + Number(pageSize));
var countrs = await this.settledb.query(countSql.join(" "), {replacements: where}); var countrs = await this.settledb.query(countSql.join(" "), { replacements: where });
var total = 0; var total = 0;
if(countrs && countrs[0,0]) { if (countrs && countrs[0, 0]) {
total = countrs[0,0][0].num; total = countrs[0, 0][0].num;
} }
if(total == 0) { if (total == 0) {
return {count:0, rows:[]} return { count: 0, rows: [] }
} }
var list = await this.settledb.query(listSql.join(" "), { replacements: where}); var list = await this.settledb.query(listSql.join(" "), { replacements: where });
if(list && list.length > 0) { if (list && list.length > 0) {
list = list[0,0] || []; list = list[0, 0] || [];
for(var item of list) { for (var item of list) {
item.available_amt = parseFloat((Number(item.available_amt || 0) / 100).toFixed(2)); item.available_amt = parseFloat((Number(item.available_amt || 0) / 100).toFixed(2));
item.frozen_amt = parseFloat((Number(item.frozen_amt || 0) / 100).toFixed(2)); item.frozen_amt = parseFloat((Number(item.frozen_amt || 0) / 100).toFixed(2));
} }
} else{ } else {
list = [] list = []
} }
return {count: total, rows:list}; return { count: total, rows: list };
} }
async statOnlineSettle(params) { async statOnlineSettle(params) {
...@@ -666,20 +672,20 @@ class EsettleService extends ServiceBase { ...@@ -666,20 +672,20 @@ class EsettleService extends ServiceBase {
sql.push("tbl_order_item"); sql.push("tbl_order_item");
sql.push("WHERE pay_complete_time IS NOT NULL AND trade_status = '00'"); sql.push("WHERE pay_complete_time IS NOT NULL AND trade_status = '00'");
var where = {}; var where = {};
if(params.payTimeBegin) { if (params.payTimeBegin) {
sql.push("AND pay_complete_time >= :payTimeBegin"); sql.push("AND pay_complete_time >= :payTimeBegin");
where.payTimeBegin = params.payTimeBegin; where.payTimeBegin = params.payTimeBegin;
} }
if(params.payTimeEnd) { if (params.payTimeEnd) {
sql.push("AND pay_complete_time <= :payTimeEnd"); sql.push("AND pay_complete_time <= :payTimeEnd");
where.payTimeEnd = params.payTimeEnd; where.payTimeEnd = params.payTimeEnd;
} }
var stat = {}; var stat = {};
var list = await this.settledb.query(sql.join(" "), {replacements: where}); var list = await this.settledb.query(sql.join(" "), { replacements: where });
if(list && list.length > 0) { if (list && list.length > 0) {
list = list[0,0] || []; list = list[0, 0] || [];
if(list && list.length > 0) { if (list && list.length > 0) {
stat = list[0] || {}; stat = list[0] || {};
stat.amtCount = system.f2y(stat.amtCount); stat.amtCount = system.f2y(stat.amtCount);
stat.actualAmtCount = system.f2y(stat.actualAmtCount); stat.actualAmtCount = system.f2y(stat.actualAmtCount);
...@@ -692,7 +698,7 @@ class EsettleService extends ServiceBase { ...@@ -692,7 +698,7 @@ class EsettleService extends ServiceBase {
async findIncomeTaxById(orderItemId) { async findIncomeTaxById(orderItemId) {
var getTax = {}; var getTax = {};
if(!orderItemId) { if (!orderItemId) {
return getTax; return getTax;
} }
var sql = []; var sql = [];
...@@ -702,24 +708,24 @@ class EsettleService extends ServiceBase { ...@@ -702,24 +708,24 @@ class EsettleService extends ServiceBase {
sql.push("tbl_order_item "); sql.push("tbl_order_item ");
sql.push("WHERE pay_complete_time IS NOT NULL AND trade_status = '00'"); sql.push("WHERE pay_complete_time IS NOT NULL AND trade_status = '00'");
var where = {}; var where = {};
if(orderItemId) { if (orderItemId) {
sql.push("AND id = :id"); sql.push("AND id = :id");
where.id = orderItemId; where.id = orderItemId;
} }
var list = await this.settledb.query(sql.join(" "), {replacements: where}); var list = await this.settledb.query(sql.join(" "), { replacements: where });
if(list && list.length > 0) { if (list && list.length > 0) {
list = list[0,0] || []; list = list[0, 0] || [];
if(list && list.length > 0) { if (list && list.length > 0) {
getTax = list[0] || {}; getTax = list[0] || {};
getTax.incomeTax = getTax.incomeTax; getTax.incomeTax = getTax.incomeTax;
} }
} }
return getTax; return getTax;
} }
async findOrderItemById(orderItemId) { async findOrderItemById(orderItemId) {
if(!orderItemId) { if (!orderItemId) {
return null; return null;
} }
var sql = []; var sql = [];
...@@ -729,15 +735,15 @@ class EsettleService extends ServiceBase { ...@@ -729,15 +735,15 @@ class EsettleService extends ServiceBase {
sql.push("tbl_order_item "); sql.push("tbl_order_item ");
sql.push("WHERE pay_complete_time IS NOT NULL AND trade_status = '00'"); sql.push("WHERE pay_complete_time IS NOT NULL AND trade_status = '00'");
var where = {}; var where = {};
if(orderItemId) { if (orderItemId) {
sql.push("AND id = :id"); sql.push("AND id = :id");
where.id = orderItemId; where.id = orderItemId;
} }
var getTax; var getTax;
var list = await this.settledb.query(sql.join(" "), {replacements: where}); var list = await this.settledb.query(sql.join(" "), { replacements: where });
if(list && list.length > 0) { if (list && list.length > 0) {
list = list[0,0] || []; list = list[0, 0] || [];
if(list && list.length > 0) { if (list && list.length > 0) {
getTax = list[0]; getTax = list[0];
} }
} }
...@@ -745,7 +751,7 @@ class EsettleService extends ServiceBase { ...@@ -745,7 +751,7 @@ class EsettleService extends ServiceBase {
} }
async findByMtchIds(mtchIds) { async findByMtchIds(mtchIds) {
if(!mtchIds || mtchIds.length == 0) { if (!mtchIds || mtchIds.length == 0) {
return {}; return {};
} }
var where = { var where = {
...@@ -760,38 +766,38 @@ class EsettleService extends ServiceBase { ...@@ -760,38 +766,38 @@ class EsettleService extends ServiceBase {
sql.push("WHERE t1.`id` IN (:ids)"); sql.push("WHERE t1.`id` IN (:ids)");
var rs = {}; var rs = {};
var list = await this.settledb.query(sql.join(" "), {replacements: where}); var list = await this.settledb.query(sql.join(" "), { replacements: where });
if(list && list.length > 0) { if (list && list.length > 0) {
list = list[0,0] || []; list = list[0, 0] || [];
for(var item of list) { for (var item of list) {
rs['id_' + item.mtchId] = item; rs['id_' + item.mtchId] = item;
} }
} }
return rs; return rs;
} }
async suggest(name){ async suggest(name) {
if(!name) { if (!name) {
return []; return [];
} }
var sql = "SELECT id, company_name FROM `tbl_busi` WHERE company_name LIKE :queryLike ORDER BY id ASC"; var sql = "SELECT id, company_name FROM `tbl_busi` WHERE company_name LIKE :queryLike ORDER BY id ASC";
var list = await this.settledb.query(sql, {replacements: {queryLike: "%" + name + "%"}}); var list = await this.settledb.query(sql, { replacements: { queryLike: "%" + name + "%" } });
if(list && list.length > 0) { if (list && list.length > 0) {
list = list[0,0] || []; list = list[0, 0] || [];
} }
return list; return list;
} }
async findcompanyid(id){ async findcompanyid(id) {
if(!id) { if (!id) {
return []; return [];
} }
var sql = "SELECT company_name FROM `tbl_busi` WHERE id = :queryId"; var sql = "SELECT company_name FROM `tbl_busi` WHERE id = :queryId";
var list = await this.settledb.query(sql, {replacements: {queryId: id}}); var list = await this.settledb.query(sql, { replacements: { queryId: id } });
if(list && list.length > 0) { if (list && list.length > 0) {
list = list[0,0] || []; list = list[0, 0] || [];
} }
return list; return list;
} }
......
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