Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Z
zhichan
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
蒋勇
zhichan
Commits
ee684618
Commit
ee684618
authored
Apr 21, 2020
by
孙亚楠
Browse files
Options
Browse Files
Download
Plain Diff
dd
parents
daedb63e
2f806950
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
181 additions
and
375 deletions
+181
-375
xgg-saas-merchant/app/base/controller/impl/saas/invoice2Ctl.js
+0
-332
xgg-saas-merchant/app/base/controller/impl/saas/invoiceCtl.js
+161
-30
xgg-saas-merchant/app/base/controller/impl/uc/userCtl.js
+3
-3
xgg-saas-merchant/app/base/service/impl/saas/invoiceSve.js
+5
-0
xgg-saas-merchant/app/base/system.js
+9
-2
xgg-saas-merchant/app/config/settings.js
+3
-8
No files found.
xgg-saas-merchant/app/base/controller/impl/saas/invoice2Ctl.js
deleted
100644 → 0
View file @
daedb63e
var
system
=
require
(
"../../../system"
)
const
CtlBase
=
require
(
"../../ctlms.base"
);
const
validation
=
system
.
getObject
(
"util.validation"
);
class
Invoice2Ctl
extends
CtlBase
{
constructor
()
{
super
();
this
.
orderSve
=
system
.
getObject
(
"service.saas.orderSve"
);
this
.
tradeSve
=
system
.
getObject
(
"service.trade.tradeSve"
);
this
.
invoiceSve
=
system
.
getObject
(
"service.saas.invoiceSve"
);
this
.
merchantSve
=
system
.
getObject
(
"service.saas.merchantSve"
);
this
.
redisClient
=
system
.
getObject
(
"util.redisClient"
);
}
// 注册订单列表
async
orderPage
(
params
,
pobj2
,
req
)
{
try
{
params
.
unInvoice
=
1
;
params
.
handle_statuses
=
[
'20'
,
'30'
];
this
.
doTimeCondition
(
params
,
[
"createBegin"
,
"createEnd"
]);
return
await
this
.
orderSve
.
page
(
params
);
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
// 交易信息列表页
async
tradePage
(
params
,
pobj2
,
req
)
{
try
{
params
.
unInvoice
=
1
;
params
.
order_type
=
params
.
fee_type
;
params
.
trade_status
=
"00"
;
this
.
doTimeCondition
(
params
,
[
"createBegin"
,
"createEnd"
]);
return
await
this
.
tradeSve
.
itemPage
(
params
);
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
// 交易列表
async
platformPage
(
params
,
pobj2
,
req
)
{
try
{
if
([
"00"
,
"10"
,
"20"
].
indexOf
(
params
.
fee_type
)
==
-
1
)
{
return
system
.
getResultSuccess
({
count
:
0
,
rows
:[],
fee_type
:
params
.
fee_type
});
}
if
(
params
.
fee_type
==
"00"
)
{
return
this
.
orderPage
(
params
,
pobj2
,
req
);
}
else
{
return
this
.
tradePage
(
params
,
pobj2
,
req
);
}
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
//发票列表
async
invoicePage
(
params
,
pobj2
,
req
)
{
try
{
let
rs
=
await
this
.
invoiceSve
.
merchantinvoicePage
(
params
);
return
rs
;
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
// 发票申请
async
apply
(
params
,
pobj2
,
req
)
{
try
{
let
fee_type
=
this
.
trim
(
params
.
fee_type
);
if
(
fee_type
==
"00"
)
{
}
else
if
(
fee_type
==
"10"
)
{
return
await
this
.
apply10
(
params
,
pobj2
,
req
);
}
else
if
(
fee_type
==
"20"
)
{
}
else
{
return
system
.
getResult
(
null
,
"费用类型错误"
);
}
return
await
this
.
orderSve
.
page
(
params
);
}
catch
(
error
)
{
let
msg
=
error
.
message
;
if
(
msg
.
startsWith
(
"bpo-validation-error:"
))
{
return
system
.
getResult
(
null
,
msg
.
replace
(
"bpo-validation-error:"
,
""
));
}
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
// 功能2开票
async
apply10
(
params
,
pobj2
,
req
)
{
validation
.
check
(
params
,
'data_ids'
,
{
name
:
"交易信息"
,
arr_require
:
true
});
let
title
=
await
this
.
merchantSve
.
title
(
params
)
||
{};
title
=
title
.
data
||
{};
if
(
!
title
.
merchant_name
||
!
title
.
merchant_credit_code
||
!
title
.
merchant_addr
||
!
title
.
merchant_mobile
||
!
title
.
merchant_bank
||
!
title
.
merchant_account
)
{
return
system
.
getResult
(
null
,
"开票抬头不完整,请联系平台"
);
}
let
addr
=
await
this
.
merchantSve
.
addr
(
params
)
||
{};
addr
=
addr
.
data
||
{};
if
(
!
addr
||
!
addr
.
mail_to
||
!
addr
.
mail_addr
||
!
addr
.
mail_mobile
)
{
return
system
.
getResult
(
null
,
"开票邮寄不完整"
);
}
let
trades
=
await
this
.
tradeSve
.
byIds
({
ids
:
params
.
data_ids
,
saas_merchant_id
:
params
.
saas_merchant_id
,
attrs
:
"id"
,
trade_statuses
:
[
'00'
],
unInvoice
:
true
,
})
||
[];
if
(
trades
.
data
.
length
!=
params
.
data_ids
.
length
)
{
return
system
.
getResult
(
null
,
"交易数据选择有误,请重新搜索后选择"
);
}
let
info
=
await
this
.
merchantSve
.
signInfo
({
id
:
params
.
saas_merchant_id
})
||
{};
info
=
info
.
data
||
{};
if
(
!
info
.
main_trade
||
!
info
.
main_trade
.
id
)
{
return
system
.
getResult
(
null
,
"商户未设置转账交易主体,请联系平台进行设置、"
);
}
let
main
=
info
.
main_trade
||
{};
let
batch_no
=
await
this
.
redisClient
.
genrateId
(
"invoice_batch_no"
);
let
apply_no
=
await
this
.
redisClient
.
genrateId
(
"invoice_apply_no"
);
let
data
=
{
saas_id
:
params
.
saas_id
,
saas_merchant_id
:
params
.
saas_merchant_id
,
parent_id
:
""
,
owner_type
:
"00"
,
status
:
"1000"
,
batch_no
:
batch_no
,
apply_no
:
apply_no
,
fee_type
:
this
.
trim
(
params
.
fee_type
),
invoice_type
:
this
.
trim
(
params
.
invoice_type
),
from_name
:
main
.
name
,
from_credit_code
:
main
.
credit_code
,
from_mobile
:
main
.
mobile
,
from_addr
:
main
.
addr
,
from_bank
:
main
.
bank_name
,
from_account
:
main
.
bank_account
,
to_name
:
this
.
trim
(
title
.
merchant_name
),
to_credit_code
:
this
.
trim
(
title
.
merchant_credit_code
),
to_addr
:
this
.
trim
(
title
.
merchant_addr
),
to_mobile
:
this
.
trim
(
title
.
merchant_mobile
),
to_bank
:
this
.
trim
(
title
.
merchant_bank
),
to_account
:
this
.
trim
(
title
.
merchant_account
),
mail_addr
:
this
.
trim
(
addr
.
mail_addr
),
mail_mobile
:
this
.
trim
(
addr
.
mail_mobile
),
mail_to
:
this
.
trim
(
addr
.
mail_to
),
};
data
=
await
this
.
invoiceSve
.
applySave
(
data
);
console
.
log
(
data
);
data
=
data
.
data
;
if
(
!
data
||
!
data
.
id
)
{
return
system
.
getResult
(
null
,
"网络异常,发票申请失败"
);
}
let
rs
=
await
this
.
tradeSve
.
updateInvoice
({
ids
:
params
.
data_ids
,
saas_invoice_id
:
data
.
id
});
console
.
log
(
rs
);
console
.
log
(
data
);
return
system
.
getResultSuccess
(
data
);
}
//发票申请列表
async
merchantinvoiceapplyPage
(
params
,
pobj2
,
req
)
{
try
{
params
.
currentPage
=
Number
(
params
.
currentPage
||
1
);
params
.
pageSize
=
Number
(
params
.
pageSize
||
1
);
let
rs
=
await
this
.
invoiceSve
.
merchantinvoiceapplyPage
(
params
);
return
rs
;
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
/**
* 发票账单列表
* @param {*} params
* @param {*} pobj2
* @param {*} req
*/
async
invoiceOrder
(
params
,
pobj2
,
req
){
if
(
!
params
.
id
){
return
system
.
getResult
(
null
,
`发票ID 不能为空`
);
}
try
{
return
await
this
.
invoiceSve
.
invoiceOrder
(
params
);
}
catch
(
error
)
{
console
.
log
(
error
);
return
system
.
getResult
(
null
,
`系统错误`
);
}
}
// 功能1 确定个体户开票
async
confirmInvoice
(
params
,
pobj2
,
req
)
{
let
invoice_type
=
params
.
invoice_type
;
let
msg
=
error
.
message
;
if
(
msg
.
startsWith
(
"bpo-validation-error:"
))
{
return
system
.
getResult
(
null
,
msg
.
replace
(
"bpo-validation-error:"
,
""
));
}
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
try
{
return
await
this
.
invoiceSve
.
invoiceOrder
(
params
);
}
catch
(
error
)
{
console
.
log
(
error
);
return
system
.
getResult
(
null
,
`系统错误`
);
}
}
async
buildTradeInvoice
(
params
)
{
let
invoiceId
=
params
.
id
;
let
invoice_type
=
params
.
invoice_type
;
// 查交易
let
items
=
await
this
.
tradeSve
.
itemByInvoiceId
({
saas_invoice_id
:
invoiceId
});
items
=
items
.
data
;
if
(
!
items
||
items
.
length
==
0
)
{
return
system
.
getResult
(
null
,
"该发票缺少交易信息,请联系平台查看原因"
);
}
let
bmMap
=
{};
let
creditCodes
=
[];
for
(
let
item
of
items
)
{
let
creditCode
=
item
.
credit_code
;
let
list
=
bmMap
[
creditCode
]
||
[];
list
.
push
(
item
);
bmMap
[
creditCode
]
=
list
;
creditCodes
.
push
(
creditCode
);
}
let
businessmenMap
=
await
this
.
orderSve
.
mapByCreditCodes
({
creditCodes
:
creditCodes
});
businessmenMap
=
businessmenMap
.
data
;
let
invoiceList
=
[];
let
calcParams
=
[];
for
(
let
creditCode
in
bmMap
)
{
let
businessmen
=
businessmenMap
[
creditCode
];
let
itemList
=
bmMap
[
creditCode
];
let
amount
=
0
;
for
(
let
item
of
itemList
)
{
amount
=
amount
+
Number
(
item
.
amt
||
0
);
}
calcParams
.
push
({
"credit_code"
:
creditCode
,
"invoiced_time"
:
moment
().
format
(
"YYYY-MM-DD hh:mm:ss"
),
"invoice_type"
:
invoice_type
,
"invoice_amount"
:
amount
});
// TODO 总统计算 end
invoiceList
.
push
({
"name"
:
businessmen
.
name
,
"credit_code"
:
creditCode
,
"is_bank"
:
businessmen
.
isBank
,
"is_bank_name"
:
businessmen
.
isBank
?
"已开户"
:
"未开户"
,
"invoice_amount"
:
system
.
y2f
(
amount
),
"personal_invoice_tax"
:
0
,
"additional_tax"
:
0
,
"service_tax"
:
0
,
"value_added_tax"
:
0
,
"unit"
:
""
,
"quantity"
:
""
,
"price"
:
""
,
"remark"
:
""
});
}
let
additional_tax_total
=
0
;
let
personal_invoice_tax_total
=
0
;
let
value_added_tax_total
=
0
;
let
service_tax_total
=
0
;
// TODO 总统计算 begin
// 计算税金
try
{
let
url
=
settings
.
deliverSysApi
().
calcInvoice
;
let
res
=
await
axios
({
method
:
'post'
,
url
:
url
,
data
:
calcParams
});
if
(
!
res
||
!
res
.
data
||
res
.
data
.
status
!=
0
||
res
.
data
.
data
.
length
==
0
){
return
system
.
getResult
(
null
,
`试算错误`
);
}
let
calcList
=
res
.
data
.
data
;
let
calcMap
=
{};
let
errors
=
[];
for
(
let
c
of
calcList
)
{
calcMap
[
c
.
credit_code
]
=
c
;
if
(
c
.
error
)
{
errors
.
push
(
`
${
c
.
msg
}
【
${
c
.
credit_code
}
】`
);
}
}
if
(
errors
.
length
>
0
)
{
return
system
.
getResult
(
null
,
errors
.
join
(
"、"
));
}
for
(
let
invoice
of
invoiceList
)
{
let
invoiceCalc
=
calcMap
[
invoice
.
credit_code
];
additional_tax_total
=
additional_tax_total
+
Number
(
invoiceCalc
.
additional_tax
);
personal_invoice_tax_total
=
personal_invoice_tax_total
+
Number
(
invoiceCalc
.
personal_invoice_tax
);
value_added_tax_total
=
value_added_tax_total
+
Number
(
invoiceCalc
.
value_added_tax
);
service_tax_total
=
service_tax_total
+
Number
(
invoiceCalc
.
service_amount
);
invoice
.
personal_invoice_tax
=
system
.
toFloat
(
Number
(
invoiceCalc
.
personal_invoice_tax
));
invoice
.
additional_tax
=
system
.
toFloat
(
Number
(
invoiceCalc
.
additional_tax
));
invoice
.
service_tax
=
system
.
toFloat
(
Number
(
invoiceCalc
.
service_amount
));
invoice
.
value_added_tax
=
system
.
toFloat
(
Number
(
invoiceCalc
.
value_added_tax
));
}
return
system
.
getResultSuccess
({
tax
:
{
additional_tax_total
:
system
.
toFloat
(
additional_tax_total
),
personal_invoice_tax_total
:
system
.
toFloat
(
personal_invoice_tax_total
),
value_added_tax_total
:
system
.
toFloat
(
value_added_tax_total
),
service_tax_total
:
system
.
toFloat
(
service_tax_total
),
},
invoiceList
:
invoiceList
});
}
catch
(
error
)
{
console
.
log
(
error
);
return
system
.
getResult
(
null
,
`系统错误`
);
}
}
}
module
.
exports
=
Invoice2Ctl
;
xgg-saas-merchant/app/base/controller/impl/saas/invoiceCtl.js
View file @
ee684618
var
system
=
require
(
"../../../system"
)
const
system
=
require
(
"../../../system"
)
const
settings
=
require
(
"../../../../config/settings"
)
const
CtlBase
=
require
(
"../../ctlms.base"
);
const
validation
=
system
.
getObject
(
"util.validation"
);
const
moment
=
require
(
"moment"
);
const
axios
=
require
(
"axios"
);
class
InvoiceCtl
extends
CtlBase
{
constructor
()
{
...
...
@@ -24,6 +27,7 @@ class InvoiceCtl extends CtlBase {
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
// 交易信息列表页
async
tradePage
(
params
,
pobj2
,
req
)
{
try
{
...
...
@@ -36,13 +40,14 @@ class InvoiceCtl extends CtlBase {
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
// 交易列表
async
platformPage
(
params
,
pobj2
,
req
)
{
try
{
if
([
"00"
,
"10"
,
"20"
].
indexOf
(
params
.
fee_type
)
==
-
1
)
{
return
system
.
getResultSuccess
({
count
:
0
,
rows
:
[],
fee_type
:
params
.
fee_type
});
return
system
.
getResultSuccess
({
count
:
0
,
rows
:
[],
fee_type
:
params
.
fee_type
});
}
if
(
params
.
fee_type
==
"00"
)
{
if
(
params
.
fee_type
==
"00"
)
{
return
this
.
orderPage
(
params
,
pobj2
,
req
);
}
else
{
return
this
.
tradePage
(
params
,
pobj2
,
req
);
...
...
@@ -71,10 +76,10 @@ class InvoiceCtl extends CtlBase {
}
else
if
(
fee_type
==
"10"
)
{
return
await
this
.
apply10
(
params
,
pobj2
,
req
);
}
else
if
(
fee_type
==
"20"
)
{
return
await
this
.
apply20
(
params
,
pobj2
,
req
);
}
else
{
return
system
.
getResult
(
null
,
"费用类型错误"
);
}
return
await
this
.
orderSve
.
page
(
params
);
}
catch
(
error
)
{
let
msg
=
error
.
message
;
if
(
msg
.
startsWith
(
"bpo-validation-error:"
))
{
...
...
@@ -164,7 +169,116 @@ class InvoiceCtl extends CtlBase {
return
system
.
getResultSuccess
(
data
);
}
// 功能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
});
let
title
=
await
this
.
merchantSve
.
title
(
params
)
||
{};
title
=
title
.
data
||
{};
if
(
!
title
.
merchant_name
||
!
title
.
merchant_credit_code
||
!
title
.
merchant_addr
||
!
title
.
merchant_mobile
||
!
title
.
merchant_bank
||
!
title
.
merchant_account
)
{
return
system
.
getResult
(
null
,
"开票抬头不完整,请联系平台"
);
}
let
addr
=
await
this
.
merchantSve
.
addr
(
params
)
||
{};
addr
=
addr
.
data
||
{};
if
(
!
addr
||
!
addr
.
mail_to
||
!
addr
.
mail_addr
||
!
addr
.
mail_mobile
)
{
return
system
.
getResult
(
null
,
"开票邮寄不完整"
);
}
let
info
=
await
this
.
merchantSve
.
signInfo
({
id
:
params
.
saas_merchant_id
})
||
{};
info
=
info
.
data
||
{};
// TODO WK
if
(
!
info
.
main_trade
)
{
return
system
.
getResult
(
null
,
"商户未设置转账交易主体,请联系平台进行设置、"
);
}
let
main
=
info
.
main_trade
;
let
invoiceList
=
params
.
invoiceList
;
let
creditCodes
=
[];
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
});
for
(
let
invoice
of
invoiceList
)
{
validation
.
check
(
businessmenMap
,
invoice
.
credit_code
,
{
name
:
`个体户[
${
invoice
.
credit_code
}
]`
,
is_require
:
true
});
}
let
applyList
=
[];
let
batch_no
=
await
this
.
redisClient
.
genrateId
(
"invoice_batch_no"
);
for
(
let
invoice
of
invoiceList
)
{
let
bussinessmen
=
businessmenMap
[
invoice
.
credit_code
];
let
apply_no
=
await
this
.
redisClient
.
genrateId
(
"invoice_apply_no"
);
let
data
=
{
saas_id
:
params
.
saas_id
,
saas_merchant_id
:
params
.
saas_merchant_id
,
parent_id
:
""
,
owner_type
:
"00"
,
status
:
"1000"
,
batch_no
:
batch_no
,
apply_no
:
apply_no
,
fee_type
:
params
.
fee_type
,
invoice_amount
:
system
.
y2f
(
invoice
.
invoice_amount
),
invoice_type
:
this
.
trim
(
params
.
invoice_type
),
from_name
:
bussinessmen
.
name
,
from_credit_code
:
bussinessmen
.
credit_code
,
from_mobile
:
bussinessmen
.
legal_mobile
,
from_addr
:
bussinessmen
.
business_place
,
from_bank
:
bussinessmen
.
bank_name
,
from_account
:
bussinessmen
.
bank_no
,
to_name
:
this
.
trim
(
main
.
from_name
),
to_credit_code
:
this
.
trim
(
main
.
from_credit_code
),
to_mobile
:
this
.
trim
(
main
.
from_mobile
),
to_addr
:
this
.
trim
(
main
.
from_addr
),
to_bank
:
this
.
trim
(
main
.
from_bank
),
to_account
:
this
.
trim
(
main
.
from_account
),
mail_addr
:
this
.
trim
(
addr
.
mail_addr
),
mail_mobile
:
this
.
trim
(
addr
.
mail_mobile
),
mail_to
:
this
.
trim
(
addr
.
mail_to
),
personal_invoice_tax
:
system
.
y2f
(
invoice
.
personal_invoice_tax
),
additional_tax
:
system
.
y2f
(
invoice
.
additional_tax
),
service_tax
:
system
.
y2f
(
invoice
.
service_tax
),
value_added_tax
:
system
.
y2f
(
invoice
.
value_added_tax
),
unit
:
this
.
trim
(
invoice
.
unit
),
quantity
:
this
.
trim
(
invoice
.
quantity
),
price
:
this
.
trim
(
invoice
.
price
),
remark
:
this
.
trim
(
invoice
.
remark
),
};
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"
,
}
});
return
system
.
getResultSuccess
(
rs
);
}
catch
(
error
)
{
let
msg
=
error
.
message
;
if
(
msg
.
startsWith
(
"bpo-validation-error:"
))
{
return
system
.
getResult
(
null
,
msg
.
replace
(
"bpo-validation-error:"
,
""
));
}
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
// 功能1开票
>>>>>>>
2
f8069504619be0803f13e594a5d3ed88d6cf516
async
apply00
(
params
,
pobj2
,
req
)
{
validation
.
check
(
params
,
'data_ids'
,
{
name
:
"提示信息"
,
arr_require
:
true
});
...
...
@@ -267,49 +381,65 @@ class InvoiceCtl extends CtlBase {
/**
* 发票账单列表
* @param {*} params
* @param {*} pobj2
* @param {*} req
* @param {*} params
* @param {*} pobj2
* @param {*} req
*/
async
invoiceOrder
(
params
,
pobj2
,
req
){
if
(
!
params
.
id
)
{
return
system
.
getResult
(
null
,
`发票ID 不能为空`
);
async
invoiceOrder
(
params
,
pobj2
,
req
)
{
if
(
!
params
.
id
)
{
return
system
.
getResult
(
null
,
`发票ID 不能为空`
);
}
try
{
return
await
this
.
invoiceSve
.
invoiceOrder
(
params
);
}
catch
(
error
)
{
console
.
log
(
error
);
return
system
.
getResult
(
null
,
`系统错误`
);
return
system
.
getResult
(
null
,
`系统错误`
);
}
}
// 功能1 确定个体户开票
async
confirmInvoice
(
params
,
pobj2
,
req
)
{
let
invoice_type
=
params
.
invoice_type
;
let
msg
=
error
.
message
;
if
(
msg
.
startsWith
(
"bpo-validation-error:"
))
{
return
system
.
getResult
(
null
,
msg
.
replace
(
"bpo-validation-error:"
,
""
));
}
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
try
{
return
await
this
.
invoiceSve
.
invoiceOrder
(
params
);
let
invoiceData
=
await
this
.
buildTradeInvoice
(
params
);
return
invoiceData
;
}
catch
(
error
)
{
console
.
log
(
error
);
return
system
.
getResult
(
null
,
`系统错误`
);
let
msg
=
error
.
message
;
if
(
msg
.
startsWith
(
"bpo-validation-error:"
))
{
return
system
.
getResult
(
null
,
msg
.
replace
(
"bpo-validation-error:"
,
""
));
}
return
system
.
getResult
(
null
,
`系统错误`
);
}
}
async
buildTradeInvoice
(
params
)
{
let
invoiceId
=
params
.
id
;
validation
.
check
(
params
,
'data_ids'
,
{
name
:
"交易信息"
,
arr_require
:
true
})
;
let
invoice_type
=
params
.
invoice_type
;
// 查交易
let
items
=
await
this
.
tradeSve
.
itemByInvoiceId
({
saas_invoice_id
:
invoiceId
});
let
items
=
await
this
.
tradeSve
.
byIds
({
ids
:
params
.
data_ids
,
saas_merchant_id
:
params
.
saas_merchant_id
,
order_type
:
params
.
fee_type
,
trade_statuses
:
[
'00'
],
unInvoice
:
true
,
})
||
[];
items
=
items
.
data
;
if
(
!
items
||
items
.
length
==
0
)
{
return
system
.
getResult
(
null
,
"
该发票缺少交易信息,请联系平台查看原因
"
);
return
system
.
getResult
(
null
,
"
注册订单信息有误,请刷新重新选择
"
);
}
let
signInfo
=
await
this
.
merchantSve
.
signInfo
({
id
:
params
.
saas_merchant_id
});
if
(
!
signInfo
||
!
signInfo
.
data
)
{
return
system
.
getResult
(
null
,
"商户签约信息不存在,请先做签约配置"
);
}
// TODO WK 改成开票签约主体
let
main
=
signInfo
.
data
.
main_trade
;
if
(
!
main
)
{
return
system
.
getResult
(
null
,
"开票签约主体未设置,请联系平台配置"
);
}
let
invoice_service_rate
=
signInfo
.
data
.
invoice_service_rate
||
0
;
let
bmMap
=
{};
let
creditCodes
=
[];
for
(
let
item
of
items
)
{
...
...
@@ -319,8 +449,7 @@ class InvoiceCtl extends CtlBase {
bmMap
[
creditCode
]
=
list
;
creditCodes
.
push
(
creditCode
);
}
let
businessmenMap
=
await
this
.
orderSve
.
mapByCreditCodes
({
creditCodes
:
creditCodes
});
businessmenMap
=
businessmenMap
.
data
;
let
businessmenMap
=
await
this
.
orderSve
.
mapByCreditCodes
({
creditCodes
:
creditCodes
,
saas_merchant_id
:
params
.
saas_merchant_id
});
let
invoiceList
=
[];
let
calcParams
=
[];
...
...
@@ -332,6 +461,7 @@ class InvoiceCtl extends CtlBase {
for
(
let
item
of
itemList
)
{
amount
=
amount
+
Number
(
item
.
amt
||
0
);
}
let
service_tax
=
parseFloat
((
Number
(
amount
)
*
Number
(
invoice_service_rate
)
/
100
).
toFixed
(
2
));
calcParams
.
push
({
"credit_code"
:
creditCode
,
"invoiced_time"
:
moment
().
format
(
"YYYY-MM-DD hh:mm:ss"
),
...
...
@@ -345,10 +475,10 @@ class InvoiceCtl extends CtlBase {
"credit_code"
:
creditCode
,
"is_bank"
:
businessmen
.
isBank
,
"is_bank_name"
:
businessmen
.
isBank
?
"已开户"
:
"未开户"
,
"invoice_amount"
:
system
.
y2f
(
amount
),
"invoice_amount"
:
system
.
f2y
(
amount
),
"personal_invoice_tax"
:
0
,
"additional_tax"
:
0
,
"service_tax"
:
0
,
"service_tax"
:
system
.
f2y
(
service_tax
)
,
"value_added_tax"
:
0
,
"unit"
:
""
,
"quantity"
:
""
,
...
...
@@ -394,11 +524,11 @@ class InvoiceCtl extends CtlBase {
additional_tax_total
=
additional_tax_total
+
Number
(
invoiceCalc
.
additional_tax
);
personal_invoice_tax_total
=
personal_invoice_tax_total
+
Number
(
invoiceCalc
.
personal_invoice_tax
);
value_added_tax_total
=
value_added_tax_total
+
Number
(
invoiceCalc
.
value_added_tax
);
service_tax_total
=
service_tax_total
+
Number
(
invoiceCalc
.
service_amount
);
service_tax_total
=
service_tax_total
+
Number
(
invoice
.
service_tax
);
invoice
.
personal_invoice_tax
=
system
.
toFloat
(
Number
(
invoiceCalc
.
personal_invoice_tax
));
invoice
.
additional_tax
=
system
.
toFloat
(
Number
(
invoiceCalc
.
additional_tax
));
invoice
.
service_tax
=
system
.
toFloat
(
Number
(
invoiceCalc
.
service_amount
));
invoice
.
value_added_tax
=
system
.
toFloat
(
Number
(
invoiceCalc
.
value_added_tax
));
}
...
...
@@ -409,6 +539,7 @@ class InvoiceCtl extends CtlBase {
value_added_tax_total
:
system
.
toFloat
(
value_added_tax_total
),
service_tax_total
:
system
.
toFloat
(
service_tax_total
),
},
main
:
main
,
invoiceList
:
invoiceList
});
}
catch
(
error
)
{
...
...
xgg-saas-merchant/app/base/controller/impl/uc/userCtl.js
View file @
ee684618
...
...
@@ -43,9 +43,9 @@ class UserCtl extends CtlBase {
async
setLogin
(
user
)
{
let
loginsid
=
"saasmcth_"
+
uuidv4
();
if
(
settings
.
env
=
"dev"
)
{
loginsid
=
"saasmcth_"
+
"2cb49932-fa02-44f0-90db-9f06fe02e5c7"
;
}
//
if (settings.env = "dev") {
//
loginsid = "saasmcth_" + "2cb49932-fa02-44f0-90db-9f06fe02e5c7";
//
}
await
this
.
redisClient
.
setWithEx
(
loginsid
,
JSON
.
stringify
(
user
),
60
*
60
*
5
);
return
loginsid
;
}
...
...
xgg-saas-merchant/app/base/service/impl/saas/invoiceSve.js
View file @
ee684618
...
...
@@ -31,6 +31,11 @@ class InvoiceService extends ServiceBase {
return
rs
;
}
async
applyBulkSave
(
params
)
{
let
rs
=
await
this
.
callms
(
"invoice"
,
"invoiceapplyBulkSave"
,
params
);
return
rs
;
}
transOrderField
(
rows
)
{
if
(
!
rows
||
rows
.
length
==
0
)
{
return
;
...
...
xgg-saas-merchant/app/base/system.js
View file @
ee684618
...
...
@@ -121,6 +121,13 @@ class System {
}
return
(
Number
(
y
)
*
100
).
toFixed
(
0
);
}
static
toFloat
(
f
,
digits
)
{
digits
=
digits
||
2
;
if
(
!
f
)
{
return
0
;
}
return
parseFloat
((
Number
(
f
)).
toFixed
(
digits
));
}
static
f2y
(
f
)
{
if
(
!
f
)
{
...
...
@@ -187,10 +194,10 @@ class System {
merchant
:
dev
+
":3101"
+
path
,
// 订单服务
order
:
local
+
":3103"
+
path
,
order
:
dev
+
":3103"
+
path
,
// 发票服务
invoice
:
local
+
":3105"
+
path
,
invoice
:
dev
+
":3105"
+
path
,
// 用户服务
uc
:
dev
+
":3106"
+
path
,
...
...
xgg-saas-merchant/app/config/settings.js
View file @
ee684618
...
...
@@ -128,18 +128,13 @@ var settings = {
deliverSysApi
:
function
()
{
let
domain
=
""
;
if
(
this
.
env
==
"dev"
)
{
// domain = "http://39.107.234.14:3002";
domain
=
"http://127.0.0.1:3002"
;
domain
=
"http://39.107.234.14:3002"
;
}
else
{
domain
=
"https://xggadmin.gongsibao.com"
;
}
return
{
// 推送订单s
orderPushApi
:
domain
+
"/web/order/orderCtl/addSourceOrder"
,
// 获取个体工商户信息
info
:
domain
+
"/web/business/businessmenCtl/info"
,
//获取工商户列表
businessmenPage
:
"/web/business/businessmenCtl/businessmenPage"
,
//发票是试算
calcInvoice
:
domain
+
"/web/invoice/invoiceCtl/calcInvoice"
,
}
},
redis
:
function
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment