Commit 9bd9ef2b by 王昆

gsb

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