Commit 4e322908 by 王昆

gsb

parent ed256dfd
...@@ -2,83 +2,125 @@ const system = require("../../../system"); ...@@ -2,83 +2,125 @@ const system = require("../../../system");
const Dao = require("../../dao.base"); const Dao = require("../../dao.base");
class TaxinfoDao extends Dao { class TaxinfoDao extends Dao {
constructor() { constructor() {
super(Dao.getModelName(TaxinfoDao)); super(Dao.getModelName(TaxinfoDao));
}
async statCount(companyNames) {
var result = {};
if (!companyNames || companyNames.length == 0) {
return result;
} }
async statCount(companyNames) { var sql = "SELECT company_name, COUNT(1) AS num FROM `tax_info` WHERE company_name IN (:companyNames) GROUP BY name";
var result = {};
if(!companyNames || companyNames.length == 0) {
return result;
}
var sql = "SELECT company_name, COUNT(1) AS num FROM `tax_info` WHERE company_name IN (:companyNames) GROUP BY name";
let list = await this.customQuery(sql, {companyNames: companyNames}); let list = await this.customQuery(sql, {companyNames: companyNames});
if(list || list.length == 0) { if (list || list.length == 0) {
return result; return result;
} }
for (var item of list) { for (var item of list) {
result[item.company_name] = item.num || 0; result[item.company_name] = item.num || 0;
}
return result;
} }
async statCounts(companyNames) { return result;
var result = {}; }
if(!companyNames || companyNames.length == 0) {
return result;
}
var sql = "SELECT company_name, SUM(actual_amount) AS num FROM `tax_info` WHERE company_name IN (:companyNames) GROUP BY name";
let list = await this.customQuery(sql, {companyNames: companyNames}); async statCounts(companyNames) {
var result = {};
if (!companyNames || companyNames.length == 0) {
return result;
}
var sql = "SELECT company_name, SUM(actual_amount) AS num FROM `tax_info` WHERE company_name IN (:companyNames) GROUP BY name";
if(list || list.length == 0) { let list = await this.customQuery(sql, {companyNames: companyNames});
return result;
}
for (var item of list) { if (list || list.length == 0) {
result[item.company_name] = item.num || 0; return result;
}
return result;
} }
async sCount(idno) { for (var item of list) {
var result = {}; result[item.company_name] = item.num || 0;
if(!idno || idno.length == 0) { }
return result; return result;
} }
var sql = "SELECT id_no, COUNT(1) AS num FROM `tax_info` WHERE id_no IN (:idno) GROUP BY name";
let list = await this.customQuery(sql, {idno: idno}); async sCount(idno) {
var result = {};
if (!idno || idno.length == 0) {
return result;
}
var sql = "SELECT id_no, COUNT(1) AS num FROM `tax_info` WHERE id_no IN (:idno) GROUP BY name";
let list = await this.customQuery(sql, {idno: idno});
if (list || list.length == 0) {
return result;
}
if(list || list.length == 0) { for (var item of list) {
return result; result[item.id_no] = item.num || 0;
} }
return result;
}
for (var item of list) { async sCountS(inno) {
result[item.id_no] = item.num || 0; var result = {};
} if (!inno || inno.length == 0) {
return result; return result;
} }
var sql = "SELECT id_no, SUM(actual_amount) AS num FROM `tax_info` WHERE company_name IN (:inno) GROUP BY name";
let list = await this.customQuery(sql, {inno: inno});
async sCountS(inno) { if (list || list.length == 0) {
var result = {}; return result;
if(!inno || inno.length == 0) { }
return result;
}
var sql = "SELECT id_no, SUM(actual_amount) AS num FROM `tax_info` WHERE company_name IN (:inno) GROUP BY name";
let list = await this.customQuery(sql, {inno: inno}); for (var item of list) {
result[item.id_no] = item.num || 0;
}
return result;
}
if(list || list.length == 0) { async countByUser(params) {
return result; var sql = [];
} sql.push("SELECT COUNT(DISTINCT(id_no)) AS num FROM `tax_info` WHERE status = 1");
this.setCondition(sql, params);
for (var item of list) { let rs = await this.customQuery(sql.join(" "), params);
result[item.id_no] = item.num || 0; if (!rs || rs.length == 0) {
} return 0;
return result; }
return rs[0].num || 0;
}
async pageByUser(params) {
var sql = [];
sql.push("SELECT");
sql.push("`id`, `company_name`, `usc_code`, `name`, `id_no`, `actual_amount`, `income_tax`,");
sql.push("`tax_time`, `sign_body`, `tax_url`, `created_at`, `updated_at`, `deleted_at`,");
sql.push("`version`, `redundance_1`, `redundance_2`, `redundance_3`, `redundance_4`,");
sql.push("count(1) AS times");
sql.push("FROM `tax_info`");
sql.push("WHERE 1 = 1");
this.setCondition(sql, params);
sql.push("GROUP BY id_no");
sql.push("LIMIT :startRow, :pageSize");
return await this.customQuery(sql.join(" "), params);
}
setCondition(sql, params) {
if (params.user_id) {
sql.push("AND user_id = :user_id");
}
if (params.idNo) {
sql.push("AND id_no = :idNo");
}
if (params.name) {
sql.push("AND name = :name");
} }
}
} }
module.exports = TaxinfoDao; module.exports = TaxinfoDao;
\ No newline at end of file
...@@ -13,7 +13,7 @@ class TaxinfoService extends ServiceBase { ...@@ -13,7 +13,7 @@ class TaxinfoService extends ServiceBase {
*/ */
async taxinfoListByMonth(params) { async taxinfoListByMonth(params) {
try { try {
var currentPage = Number(params.currentPage || 0); var currentPage = Number(params.currentPage || 1);
var pageSize = Number(params.pageSize || 10); var pageSize = Number(params.pageSize || 10);
if(!params.userId){ if(!params.userId){
return system.getResult(null,`参数错误 userId不能为空`); return system.getResult(null,`参数错误 userId不能为空`);
...@@ -51,36 +51,26 @@ class TaxinfoService extends ServiceBase { ...@@ -51,36 +51,26 @@ class TaxinfoService extends ServiceBase {
} }
/** /**
* 按查询按照人信息 * 按ren查询按照人信息
* @param {*} params * @param {*} params
*/ */
async taxinfoListByUser(params) { async taxinfoListByUser(params) {
try { try {
var currentPage = Number(params.currentPage || 0); params.currentPage = Number(params.currentPage || 1);
var pageSize = Number(params.pageSize || 10); params.pageSize = Number(params.pageSize || 10);
if(!params.userId){
return system.getResult(null,`参数错误 userId不能为空`); let total = await this.dao.countByUser(params);
} if (total === 0) {
var where = {}; return {count: 1, rows: []};
if(params.name){
where.name = this.trim(params.name);
}
// if(params.mobile){
// where.mobile = this.trim(params.mobile);
// }
if(params.idNo){
where.id_no = this.trim(params.idNo);
} }
where.user_id = this.trim(params.userId); params.startRow = (params.currentPage - 1) * params.pageSize;
var orderby = [ let list = await this.dao.pageByUser(params);
["id", 'desc'] if (list) {
]; for (var item of list) {
var page = await this.dao.taxinfoList(currentPage, pageSize, where, orderby);
if (page && page.rows) {
for (var row of page.rows) {
this.handleDate(row, ["tax_time"],null,-8); this.handleDate(row, ["tax_time"],null,-8);
} }
} }
return {count: total, rows: list};
return system.getResult(page); return system.getResult(page);
} catch (error) { } catch (error) {
console.log(error); console.log(error);
......
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