Commit 9bd9ef2b by 王昆

gsb

parent 991b6dca
...@@ -70,6 +70,7 @@ class InvoiceCtl extends CtlBase { ...@@ -70,6 +70,7 @@ class InvoiceCtl extends CtlBase {
// 发票申请 // 发票申请
async apply(params, pobj2, req) { async apply(params, pobj2, req) {
try { try {
validation.check(params, "fee_type", {name: "费用记录类型", is_require: true, dics: ['00', "10", "20"]});
let fee_type = this.trim(params.fee_type); let fee_type = this.trim(params.fee_type);
if (fee_type == "00") { if (fee_type == "00") {
return await this.apply00(params, pobj2, req); return await this.apply00(params, pobj2, req);
...@@ -153,6 +154,7 @@ class InvoiceCtl extends CtlBase { ...@@ -153,6 +154,7 @@ class InvoiceCtl extends CtlBase {
mail_addr: this.trim(addr.mail_addr), mail_addr: this.trim(addr.mail_addr),
mail_mobile: this.trim(addr.mail_mobile), mail_mobile: this.trim(addr.mail_mobile),
mail_to: this.trim(addr.mail_to), mail_to: this.trim(addr.mail_to),
data_ids: params.data_ids.join(","),
}; };
data = await this.invoiceSve.applySave(data); data = await this.invoiceSve.applySave(data);
...@@ -171,11 +173,9 @@ class InvoiceCtl extends CtlBase { ...@@ -171,11 +173,9 @@ class InvoiceCtl extends CtlBase {
// 功能3开票 // 功能3开票
async apply20(params, pobj2, req) { async apply20(params, pobj2, req) {
try { try {
// TODO 方法未测试 // TODO 方法未测试
validation.check(params, "fee_type", {name: "费用记录类型", is_require: true, dics: ['00', "10", "20"]});
validation.check(params, "invoice_type", {name: "发票类型", is_require: true, dics: ['00', "10", "20"]}); validation.check(params, "invoice_type", {name: "发票类型", is_require: true, dics: ['00', "10", "20"]});
validation.check(params, "invoiceList", {name: "开票信息", arr_require: true}); validation.check(params, "invoiceList", {name: "开票信息", arr_require: true});
...@@ -205,7 +205,10 @@ class InvoiceCtl extends CtlBase { ...@@ -205,7 +205,10 @@ class InvoiceCtl extends CtlBase {
for (let invoice of invoiceList) { for (let invoice of invoiceList) {
creditCodes.push(invoice.credit_code); creditCodes.push(invoice.credit_code);
} }
let businessmenMap = await this.orderSve.mapByCreditCodes({creditCodes: creditCodes, saas_merchant_id: params.saas_merchant_id}); let businessmenMap = await this.orderSve.mapByCreditCodes({
creditCodes: creditCodes,
saas_merchant_id: params.saas_merchant_id
});
for (let invoice of invoiceList) { for (let invoice of invoiceList) {
validation.check(businessmenMap, invoice.credit_code, {name: `个体户[${invoice.credit_code}]`, is_require: true}); validation.check(businessmenMap, invoice.credit_code, {name: `个体户[${invoice.credit_code}]`, is_require: true});
...@@ -214,13 +217,17 @@ class InvoiceCtl extends CtlBase { ...@@ -214,13 +217,17 @@ class InvoiceCtl extends CtlBase {
let applyList = []; let applyList = [];
let batch_no = await this.redisClient.genrateId("invoice_batch_no"); let batch_no = await this.redisClient.genrateId("invoice_batch_no");
for (let invoice of invoiceList) { for (let invoice of invoiceList) {
if (!invoice.data_ids) {
return system.getResult(null, "数据错误,请刷新重试");
}
let bussinessmen = businessmenMap[invoice.credit_code]; let bussinessmen = businessmenMap[invoice.credit_code];
let apply_no = await this.redisClient.genrateId("invoice_apply_no"); let apply_no = await this.redisClient.genrateId("invoice_apply_no");
let data = { let data = {
saas_id: params.saas_id, saas_id: params.saas_id,
saas_merchant_id: params.saas_merchant_id, saas_merchant_id: params.saas_merchant_id,
parent_id: "", parent_id: "",
owner_type: "00", owner_type: "00",
status: "1000", status: "1000",
batch_no: batch_no, batch_no: batch_no,
apply_no: apply_no, apply_no: apply_no,
...@@ -254,19 +261,25 @@ class InvoiceCtl extends CtlBase { ...@@ -254,19 +261,25 @@ class InvoiceCtl extends CtlBase {
quantity: this.trim(invoice.quantity), quantity: this.trim(invoice.quantity),
price: this.trim(invoice.price), price: this.trim(invoice.price),
remark: this.trim(invoice.remark), remark: this.trim(invoice.remark),
data_ids: invoice.data_ids,
}; };
applyList.push(data); applyList.push(data);
} }
let rs = await this.invoiceSve.applyBulkSave({ let rs = await this.invoiceSve.applyBulkSave({
fee_type: params.fee_type, fee_type: params.fee_type,
dataList: applyList, dataList: applyList,
parent_id: "", parent_id: ""
updateStatus: {
id: apply.id,
preStatus: "1040",
status: "1060",
}
}); });
if (rs && rs.data && rs.data.length > 0) {
for (let d of rs.data) {
console.log(d.id, d.data_ids);
if (!d.data_ids) {
continue;
}
let tradeIds = d.data_ids.split(",");
await this.tradeSve.updateInvoice({ids: tradeIds, saas_invoice_id: d.id});
}
}
return system.getResultSuccess(rs); return system.getResultSuccess(rs);
} catch (error) { } catch (error) {
let msg = error.message; let msg = error.message;
...@@ -279,12 +292,12 @@ class InvoiceCtl extends CtlBase { ...@@ -279,12 +292,12 @@ class InvoiceCtl extends CtlBase {
// 功能1开票 // 功能1开票
async apply00(params, pobj2, req) { async apply00(params, pobj2, req) {
validation.check(params, 'data_ids', {name: "提示信息", arr_require: true}); validation.check(params, 'data_ids', {name: "订单信息", arr_require: true});
let title = await this.merchantSve.title(params) || {}; let title = await this.merchantSve.title(params) || {};
title = title.data || {}; title = title.data || {};
if (!title.merchant_name || !title.merchant_credit_code || !title.merchant_addr if (!title.merchant_name || !title.merchant_credit_code || !title.merchant_addr
|| !title.merchant_mobile || !title.merchant_bank || !title.merchant_account) { || !title.merchant_mobile || !title.merchant_bank || !title.merchant_account) {
return system.getResult(null, "开票抬头不完整,请联系平台"); return system.getResult(null, "开票抬头不完整,请联系平台");
} }
...@@ -295,17 +308,17 @@ class InvoiceCtl extends CtlBase { ...@@ -295,17 +308,17 @@ class InvoiceCtl extends CtlBase {
} }
let orders = await this.orderSve.byIds({ let orders = await this.orderSve.byIds({
ids: params.data_ids, ids: params.data_ids,
saas_merchant_id: params.saas_merchant_id, saas_merchant_id: params.saas_merchant_id,
attrs: "id,price", attrs: "id,price",
handle_status: ['20','30'], handle_status: ['20', '30'],
unInvoice: true, unInvoice: true,
}) || []; }) || [];
if (orders.data.length != params.data_ids.length) { if (orders.data.length != params.data_ids.length) {
return system.getResult(null, "订单数据选择有误,请重新搜索后选择"); return system.getResult(null, "订单数据选择有误,请重新搜索后选择");
} }
let invoice_amount = 0; let invoice_amount = 0;
for(let item of orders.data){ for (let item of orders.data) {
invoice_amount = invoice_amount + Number(item.price || 0); invoice_amount = invoice_amount + Number(item.price || 0);
} }
...@@ -348,9 +361,9 @@ class InvoiceCtl extends CtlBase { ...@@ -348,9 +361,9 @@ class InvoiceCtl extends CtlBase {
mail_mobile: this.trim(addr.mail_mobile), mail_mobile: this.trim(addr.mail_mobile),
mail_to: this.trim(addr.mail_to), mail_to: this.trim(addr.mail_to),
invoice_amount:invoice_amount, invoice_amount: invoice_amount,
service_tax:service_tax, service_tax: service_tax,
data_ids: params.data_ids.join(","),
}; };
data = await this.invoiceSve.applySave(data); data = await this.invoiceSve.applySave(data);
...@@ -366,6 +379,7 @@ class InvoiceCtl extends CtlBase { ...@@ -366,6 +379,7 @@ class InvoiceCtl extends CtlBase {
console.log(data); console.log(data);
return system.getResultSuccess(data); return system.getResultSuccess(data);
} }
//发票申请列表 //发票申请列表
async merchantinvoiceapplyPage(params, pobj2, req) { async merchantinvoiceapplyPage(params, pobj2, req) {
try { try {
...@@ -448,7 +462,10 @@ class InvoiceCtl extends CtlBase { ...@@ -448,7 +462,10 @@ class InvoiceCtl extends CtlBase {
bmMap[creditCode] = list; bmMap[creditCode] = list;
creditCodes.push(creditCode); creditCodes.push(creditCode);
} }
let businessmenMap = await this.orderSve.mapByCreditCodes({creditCodes: creditCodes, saas_merchant_id: params.saas_merchant_id}); let businessmenMap = await this.orderSve.mapByCreditCodes({
creditCodes: creditCodes,
saas_merchant_id: params.saas_merchant_id
});
let invoiceList = []; let invoiceList = [];
let calcParams = []; let calcParams = [];
...@@ -457,8 +474,10 @@ class InvoiceCtl extends CtlBase { ...@@ -457,8 +474,10 @@ class InvoiceCtl extends CtlBase {
let businessmen = businessmenMap[creditCode]; let businessmen = businessmenMap[creditCode];
let itemList = bmMap[creditCode]; let itemList = bmMap[creditCode];
let amount = 0; let amount = 0;
let data_ids = [];
for (let item of itemList) { for (let item of itemList) {
amount = amount + Number(item.amt || 0); amount = amount + Number(item.amt || 0);
data_ids.push(item.id);
} }
let service_tax = parseFloat((Number(amount) * Number(invoice_service_rate) / 100).toFixed(2)); let service_tax = parseFloat((Number(amount) * Number(invoice_service_rate) / 100).toFixed(2));
calcParams.push({ calcParams.push({
...@@ -482,7 +501,8 @@ class InvoiceCtl extends CtlBase { ...@@ -482,7 +501,8 @@ class InvoiceCtl extends CtlBase {
"unit": "", "unit": "",
"quantity": "", "quantity": "",
"price": "", "price": "",
"remark": "" "remark": "",
"data_ids": data_ids.join(","),
}); });
} }
...@@ -500,8 +520,8 @@ class InvoiceCtl extends CtlBase { ...@@ -500,8 +520,8 @@ class InvoiceCtl extends CtlBase {
url: url, url: url,
data: calcParams data: calcParams
}); });
if(!res || !res.data || res.data.status !=0 || res.data.data.length==0){ if (!res || !res.data || res.data.status != 0 || res.data.data.length == 0) {
return system.getResult(null,`试算错误`); return system.getResult(null, `试算错误`);
} }
let calcList = res.data.data; let calcList = res.data.data;
...@@ -543,7 +563,7 @@ class InvoiceCtl extends CtlBase { ...@@ -543,7 +563,7 @@ class InvoiceCtl extends CtlBase {
}); });
} catch (error) { } catch (error) {
console.log(error); console.log(error);
return system.getResult(null,`系统错误`); return system.getResult(null, `系统错误`);
} }
} }
} }
......
...@@ -197,7 +197,7 @@ class System { ...@@ -197,7 +197,7 @@ class System {
order: dev + ":3103" + path, order: dev + ":3103" + path,
// 发票服务 // 发票服务
invoice: dev + ":3105" + path, invoice: local + ":3105" + path,
// 用户服务 // 用户服务
uc: dev + ":3106" + path, uc: dev + ":3106" + path,
......
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