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
607e3516
Commit
607e3516
authored
Mar 10, 2020
by
孙亚楠
Browse files
Options
Browse Files
Download
Plain Diff
dd
parents
416996d9
f460c0de
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
2205 additions
and
2176 deletions
+2205
-2176
xggsve-invoice/app/base/api/impl/op/action.js
+1
-1
xggsve-invoice/app/base/db/impl/invoice/iinvoiceDao.js
+7
-3
xggsve-invoice/app/base/db/impl/product/iproductprocessDao.js
+2
-3
xggsve-invoice/app/base/db/models/invoice/iinvoiceprocess.js
+2
-1
xggsve-invoice/app/base/service/impl/invoice/applySve.js
+1
-1028
xggsve-invoice/app/base/service/impl/invoice/applySvebak.js
+1036
-0
xggsve-invoice/app/base/service/impl/invoice/iinvoiceSve.js
+49
-45
xggsve-invoice/app/base/service/impl/invoice/iinvoiceSvebak.js
+256
-256
xggsve-invoice/app/base/service/impl/invoice/iinvoicedeliverSve.js
+0
-839
xggsve-invoice/app/base/service/impl/invoice/iinvoicedeliverSvebak.js
+851
-0
No files found.
xggsve-invoice/app/base/api/impl/op/action.js
View file @
607e3516
...
...
@@ -128,7 +128,7 @@ class ActionAPI extends APIBase {
// break;
case
"test"
:
// 查询业务进度
opResult
=
await
this
.
iinvoiceSve
.
allName
s
(
action_body
);
opResult
=
await
this
.
iinvoiceSve
.
buildProces
s
(
action_body
);
break
;
default
:
...
...
xggsve-invoice/app/base/db/impl/invoice/iinvoiceDao.js
View file @
607e3516
const
system
=
require
(
"../../../system"
);
const
Dao
=
require
(
"../../dao.base"
);
const
moment
=
require
(
"moment"
);
class
InvoiceDao
extends
Dao
{
class
I
I
nvoiceDao
extends
Dao
{
constructor
()
{
<<<<<<<
HEAD
super
(
Dao
.
getModelName
(
InvoiceDao
));
// this.tableName = this.model.tableName;
=======
super
(
Dao
.
getModelName
(
IInvoiceDao
));
>>>>>>>
f460c0de7754b2fe93251b14723661f33e7fb373
}
async
findByChannelAndApplyNo
(
channel_id
,
apply_no
){
...
...
@@ -161,4 +165,4 @@ class InvoiceDao extends Dao {
// return await this.customQuery(sql.join(" "), params);
// }
}
module
.
exports
=
InvoiceDao
;
\ No newline at end of file
module
.
exports
=
IInvoiceDao
;
\ No newline at end of file
xggsve-invoice/app/base/db/impl/product/iproductprocessDao.js
View file @
607e3516
...
...
@@ -27,7 +27,6 @@ class IproductprocessDao extends Dao {
}
async
byProductPid
(
productPid
)
{
let
result
=
{};
let
sql
=
[];
sql
.
push
(
"SELECT"
);
sql
.
push
(
"*"
);
...
...
@@ -38,9 +37,9 @@ class IproductprocessDao extends Dao {
let
list
=
await
this
.
customQuery
(
sql
.
join
(
" "
),
{
productPid
:
productPid
});
if
(
!
list
||
list
.
length
==
0
)
{
return
result
;
return
[]
;
}
return
resul
t
;
return
lis
t
;
}
}
...
...
xggsve-invoice/app/base/db/models/invoice/iinvoiceprocess.js
View file @
607e3516
...
...
@@ -24,7 +24,7 @@ module.exports = function (db, DataTypes) {
underscore
:
true
,
paranoid
:
true
,
version
:
true
,
tableName
:
'i_
product
_process'
,
tableName
:
'i_
invoice
_process'
,
comment
:
'发票产品流程表'
,
});
}
\ No newline at end of file
xggsve-invoice/app/base/service/impl/invoice/applySve.js
View file @
607e3516
const
system
=
require
(
"../../../system"
);
const
ServiceBase
=
require
(
"../../sve.base"
)
const
moment
=
require
(
'moment'
);
var
rule
=
require
(
"../../../utils/invoiceRule/rule"
);
const
Decimal
=
require
(
'decimal.js'
);
class
ApplyService
extends
ServiceBase
{
class
ApplyService
{
constructor
()
{
super
(
"invoice"
,
ServiceBase
.
getDaoName
(
ApplyService
));
let
is
=
system
.
getObject
(
"util.invoiceStatus"
);
this
.
invoiceStatus
=
is
.
status
;
this
.
delivererDao
=
system
.
getObject
(
"db.invoice.delivererDao"
);
this
.
invoiceDao
=
system
.
getObject
(
"db.invoice.invoiceDao"
);
//最大的发票总额度
this
.
MAX_TOTAL_AMOUNT
=
500000000
;
//警告发票额度
this
.
WARNING_AMOUNT
=
400000000
;
this
.
PER_TAX
=
1
;
//个税
this
.
VAL_TAX
=
2
;
//增值税
this
.
INVOICE_MAX
=
10
;
//一次性插入最大值
}
/**
* 保存发票信息
*/
async
apiSaveInvoice
(
params
)
{
try
{
let
res
=
await
this
.
saveInvoice
(
params
);
return
res
;
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息:
${
error
}
`
);
}
}
/**
* 查询申请列表(平台)
* @param {*} params
*/
async
apiQueryApplyInvoices
(
params
)
{
try
{
return
await
this
.
queryApplyInvoices
(
params
);
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
/**
* 查询发票明细(平台)
* @param {*} params
*/
async
apiQueryInvoice
(
params
)
{
try
{
var
merchantId
=
params
.
merchantId
||
params
.
merchant_id
;
if
((
params
.
merchantId
&&
params
.
applyNo
)
||
params
.
id
)
{
let
res
=
await
this
.
queryInvoice
(
params
.
applyNo
,
merchantId
,
params
.
id
);
return
res
;
}
else
{
return
system
.
getResultSuccess
();
}
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息:
${
error
}
`
);
}
}
/**
* 发票撤回
* @param params
* {
* applyNo:"", //发票申请编号
* merchantId:"", //商户id
* }
*/
async
apiCancelInvoice
(
params
)
{
try
{
var
merchantId
=
params
.
merchantId
||
params
.
merchant_id
;
if
(
!
params
.
applyNo
||
!
merchantId
)
{
return
system
.
getResult
(
null
,
"发票申请编号不合法。"
);
}
return
await
this
.
cancelInvoice
(
params
.
applyNo
,
merchantId
);
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误:错误信息
${
error
}
`
);
}
}
/**
* 平台业务分配
* @param {*} params
* {
* id:"xxx" //发票id
* nextStatus:"xxx", //发票状态
*
* }
*/
async
apiAssignment
(
params
)
{
try
{
if
(
!
params
.
id
)
{
return
system
.
getResult
(
null
,
`参数错误`
);
}
return
await
this
.
assignment
(
params
);
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
/**
* 平台业务分配
* @param {*} params
* {
* id:"xxx" //发票id
* nextStatus:"xxx", //发票状态
*
* }
*/
async
apiVerificationByBusinessmenCreditCode
(
params
)
{
try
{
if
(
!
params
.
businessmenCreditCode
)
{
return
system
.
getResult
(
null
,
`参数错误`
);
}
return
await
this
.
verificationByBusinessmenCreditCode
(
this
.
trim
(
params
.
businessmenCreditCode
));
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
/**
* 发票红冲
* @param {*} params
*/
async
apiRedRushInvoice
(
params
)
{
if
(
!
params
.
id
)
{
return
system
.
getResult
(
null
,
`参数错误 发票ID不合法`
);
}
try
{
let
res
=
await
this
.
redRushInvoice
(
params
);
return
res
;
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`参数错误 错误信息
${
error
}
`
);
}
}
/**
* 交易数据(平台)
* @param {*} params
*/
async
apiStatTransData
(
params
)
{
try
{
return
await
this
.
statTransData
(
params
);
}
catch
(
error
)
{
return
system
.
getResult
(
-
1
,
`系统错误 错误信息
${
error
}
`
);
}
}
/**
* 发票办理(平台)
* @param {*} params
*/
async
apiStatBusinessData
(
params
)
{
try
{
return
await
this
.
statBusinessData
(
params
);
}
catch
(
error
)
{
console
.
log
(
error
);
return
system
.
getResult
(
null
,
"接口异常"
);
}
}
//===========================================================================================
/**
* 插入发票
* @param {*} params
*/
async
saveInvoice
(
params
)
{
try
{
//试算
let
val
=
await
rule
.
dispatcher
(
params
);
if
(
val
.
data
==-
1
){
return
system
.
getResult
(
-
1
,
`系统错误
${
val
.
msg
}
`
);
}
params
.
personalIncomeTax
=
this
.
trim
(
val
.
personalIncomeTax
);
params
.
additionalTax
=
this
.
trim
(
val
.
additionalTax
);
params
.
valueAddedTax
=
this
.
trim
(
val
.
valueAddedTax
);
params
.
serviceCharge
=
this
.
trim
(
val
.
serviceCharge
);
params
.
isPay
=
(
params
.
isPay
)
?
1
:
0
;
params
.
status
=
"1000"
;
params
.
customerStatus
=
"1000"
;
params
.
ruleCode
=
this
.
trim
(
params
.
ruleCode
);
params
.
ruleParams
=
JSON
.
stringify
(
params
);
await
this
.
db
.
transaction
(
async
(
t
)
=>
{
//插入发票申请单
let
_apply
=
await
this
.
dao
.
create
(
params
,
t
);
//插入一条发票信息
await
this
.
invoiceDao
.
model
.
create
({
id
:
_apply
.
id
,
applyNo
:
_apply
.
applyNo
,
merchantId
:
_apply
.
merchantId
,
businessmenId
:
params
.
businessmenId
,
businessmenType
:
params
.
businessmenType
,
ruleCode
:
params
.
ruleCode
,
ruleParams
:
params
.
ruleParams
},
t
);
});
return
system
.
getResultSuccess
();
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
/**
* 发票办理(平台)
* @param {*} params
*/
async
statBusinessData
(
params
)
{
var
result
=
{};
var
type
=
Number
(
params
.
type
||
1
);
// 查 已完成订单,待分配订单,待审核订单,办理中订单
var
begin
,
end
;
// 取开始时间
if
(
type
==
1
)
{
begin
=
moment
().
format
(
"YYYY-MM"
)
+
"-01 00:00:00"
;
end
=
moment
(
begin
).
add
(
1
,
"months"
).
subtract
(
1
,
'days'
).
format
(
"YYYY-MM-DD"
)
+
" 23:59:59"
;
}
else
if
(
type
==
2
)
{
begin
=
moment
().
subtract
(
1
,
"months"
).
format
(
"YYYY-MM"
)
+
"-01 00:00:00"
;
end
=
moment
(
begin
).
add
(
1
,
"months"
).
subtract
(
1
,
'days'
).
format
(
"YYYY-MM-DD"
)
+
" 23:59:59"
;
}
// 先按照订单状态查
var
statMap
=
await
this
.
dao
.
statByStatus
(
begin
,
end
);
// 已开具 1050
result
.
completeCount
=
this
.
addStatCount
(
statMap
,
[
'1050'
]);
// 待申请审核 1000
result
.
toApplyCount
=
this
.
addStatCount
(
statMap
,
[
'1000'
]);
// 待交付审核 1130 1140
result
.
toAuditCount
=
this
.
addStatCount
(
statMap
,
[
'1060'
]);
// 办理中 "1030", "1050", "1060", "1080", "1300"
result
.
handlingCount
=
this
.
addStatCount
(
statMap
,
[
"1030"
,
"1050"
,
"1060"
,
"1080"
,
"1300"
]);
return
system
.
getResultSuccess
(
result
);
}
/**
* 交易数据(平台)
* @param {*} params
*/
async
statTransData
(
params
)
{
try
{
var
result
=
{
invoiceCount
:
0
,
serviceChange
:
0
,
};
var
type
=
Number
(
params
.
type
||
1
);
var
begin
,
end
;
// 取开始时间
if
(
type
==
1
)
{
begin
=
moment
().
format
(
"YYYY-MM"
)
+
"-01 00:00:00"
;
}
else
if
(
type
==
2
)
{
begin
=
moment
().
subtract
(
1
,
"months"
).
format
(
"YYYY-MM"
)
+
"-01 00:00:00"
;
}
// echart数据
var
days
=
[];
var
dayCounts
=
[];
var
priceCounts
=
[];
// 处理查询业务
if
(
type
==
1
||
type
==
2
)
{
// 取结束时间
end
=
moment
(
begin
).
add
(
1
,
"months"
).
subtract
(
1
,
'days'
).
format
(
"YYYY-MM-DD"
)
+
" 23:59:59"
;
days
=
this
.
getDays
(
end
);
// 按天统计
var
dayMap
=
await
this
.
dao
.
statDayByTime
(
begin
,
end
);
for
(
var
day
of
days
)
{
var
ditem
=
dayMap
[
day
]
||
{};
dayCounts
.
push
(
ditem
.
invoiceCount
||
0
);
priceCounts
.
push
(
system
.
f2y
(
ditem
.
serviceChange
||
0
));
}
}
else
{
var
monthMap
=
await
this
.
dao
.
statMonthByTime
(
begin
,
end
);
var
bm
=
monthMap
.
begin
||
""
;
var
em
=
monthMap
.
end
||
""
;
if
(
bm
&&
em
)
{
// 开始月份-结束月份所有月份
var
curMonth
=
bm
;
while
(
true
)
{
days
.
push
(
curMonth
);
if
(
curMonth
==
em
)
{
break
;
}
curMonth
=
moment
(
curMonth
+
"-01"
).
add
(
1
,
"month"
).
format
(
"YYYY-MM"
);
}
}
for
(
var
day
of
days
)
{
var
ditem
=
monthMap
[
day
]
||
{};
dayCounts
.
push
(
ditem
.
invoiceCount
||
0
);
priceCounts
.
push
(
system
.
f2y
(
ditem
.
serviceChange
||
0
));
}
}
var
invoiceApplyData
=
await
this
.
dao
.
statInvoiceByTime
(
begin
,
end
)
||
{};
result
.
invoiceCount
=
invoiceApplyData
.
invoiceCount
;
result
.
serviceChange
=
system
.
f2y
(
invoiceApplyData
.
serviceChange
);
result
.
days
=
days
;
result
.
dayCounts
=
dayCounts
;
result
.
priceCounts
=
priceCounts
;
return
system
.
getResultSuccess
(
result
);
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
/**
* 红冲
* @param {*} params
*/
async
redRushInvoice
(
params
)
{
try
{
let
_apply
=
await
this
.
dao
.
findById
(
params
.
id
)
||
{};
let
invoice
=
await
this
.
invoiceDao
.
findById
(
params
.
id
)
||
{};
//判断红冲状态
if
(
invoice
.
redStatus
==
2
)
{
return
system
.
getResult
(
null
,
`发票红冲中`
);
}
else
if
(
invoice
.
redStatus
==
4
)
{
return
system
.
getResult
(
null
,
`红冲已红冲`
);
}
let
nowObj
=
{};
nowObj
.
merchantId
=
this
.
trim
(
_apply
.
merchantId
);
nowObj
.
merchantName
=
this
.
trim
(
_apply
.
merchantName
);
nowObj
.
merchantCreditCode
=
this
.
trim
(
_apply
.
merchantCreditCode
);
nowObj
.
merchantAddr
=
this
.
trim
(
_apply
.
merchantAddr
);
nowObj
.
merchantMobile
=
this
.
trim
(
_apply
.
merchantMobile
);
nowObj
.
merchantBank
=
this
.
trim
(
_apply
.
merchantBank
);
nowObj
.
merchantAccount
=
this
.
trim
(
_apply
.
merchantAccount
);
nowObj
.
businessmenCreditCode
=
this
.
trim
(
_apply
.
businessmenCreditCode
);
nowObj
.
businessmenId
=
this
.
trim
(
_apply
.
businessmenId
);
nowObj
.
businessmenName
=
this
.
trim
(
_apply
.
businessmenName
);
nowObj
.
businessmenAddr
=
this
.
trim
(
_apply
.
businessmenAddr
);
nowObj
.
businessmenMobile
=
this
.
trim
(
_apply
.
businessmenMobile
);
nowObj
.
businessmenBank
=
this
.
trim
(
_apply
.
businessmenBank
);
nowObj
.
businessmenAccount
=
this
.
trim
(
_apply
.
businessmenAccount
);
nowObj
.
isBank
=
_apply
.
isBank
?
1
:
0
;
nowObj
.
taxAuthorities
=
this
.
trim
(
_apply
.
taxAuthorities
);
nowObj
.
type
=
this
.
trim
(
_apply
.
type
);
nowObj
.
invoiceAmount
=
this
.
trim
(
_apply
.
invoiceAmount
);
nowObj
.
statements
=
this
.
trim
(
_apply
.
statements
);
nowObj
.
contract
=
this
.
trim
(
_apply
.
contract
);
nowObj
.
invoiceTime
=
this
.
trim
(
_apply
.
invoiceTime
);
nowObj
.
settleImg
=
this
.
trim
(
_apply
.
settleImg
);
nowObj
.
applyNo
=
this
.
trim
(
_apply
.
applyNo
);
nowObj
.
invoiceConten
=
this
.
trim
(
_apply
.
invoiceConten
);
nowObj
.
personalIncomeTax
=
this
.
trim
(
_apply
.
personalIncomeTax
);
nowObj
.
additionalTax
=
this
.
trim
(
_apply
.
additionalTax
);
nowObj
.
valueAddedTax
=
this
.
trim
(
_apply
.
valueAddedTax
);
nowObj
.
serviceCharge
=
this
.
trim
(
_apply
.
serviceCharge
);
nowObj
.
applyMobile
=
this
.
trim
(
_apply
.
applyMobile
);
nowObj
.
parentId
=
this
.
trim
(
_apply
.
id
);
nowObj
.
status
=
this
.
trim
(
"1000"
);
nowObj
.
customerStatus
=
this
.
trim
(
"1000"
);
nowObj
.
payWay
=
this
.
trim
(
_apply
.
payWay
);
nowObj
.
payAccount
=
this
.
trim
(
_apply
.
payAccount
);
nowObj
.
mailAddr
=
this
.
trim
(
_apply
.
mailAddr
);
nowObj
.
mailMobile
=
this
.
trim
(
_apply
.
mailMobile
);
nowObj
.
mailTo
=
this
.
trim
(
_apply
.
mailTo
);
nowObj
.
remark
=
this
.
trim
(
""
);
nowObj
.
delivererId
=
this
.
trim
(
""
);
nowObj
.
isPay
=
0
;
nowObj
.
businessmenType
=
this
.
trim
(
_apply
.
businessmenType
);
nowObj
.
ruleCode
=
this
.
trim
(
_apply
.
ruleCode
);
nowObj
.
ruleParams
=
this
.
trim
(
_apply
.
ruleParams
);
let
res
=
await
this
.
db
.
transaction
(
async
(
t
)
=>
{
// 插入发票申请单
let
_nowObj
=
await
this
.
dao
.
create
(
nowObj
,
t
);
// 插入一条发票信息
await
this
.
invoiceDao
.
create
({
id
:
_nowObj
.
id
,
applyNo
:
_nowObj
.
applyNo
,
merchantId
:
_nowObj
.
merchantId
,
red_status
:
'1'
,
businessmenType
:
nowObj
.
businessmenType
,
ruleCode
:
nowObj
.
ruleCode
,
ruleParams
:
nowObj
.
ruleParams
},
t
);
// 源发票改为红冲办理中
var
updfields
=
{
redStatus
:
'2'
,
id
:
_apply
.
id
,
}
await
this
.
invoiceDao
.
update
(
updfields
,
t
);
});
return
system
.
getResultSuccess
();
}
catch
(
error
)
{
console
.
log
(
error
);
return
system
.
getResult
(
null
,
`参数错误 错误信息
${
error
}
`
);
}
}
async
getByApplyNo
(
params
)
{
var
merchantId
=
params
.
merchantId
||
params
.
merchant_id
;
var
applyNo
=
params
.
applyNo
;
var
item
=
await
this
.
dao
.
getByApplyNo
(
merchantId
,
applyNo
);
if
(
item
)
{
this
.
handleDate
(
item
,
[
"created_at"
,
"updated_at"
],
null
,
-
8
);
}
return
system
.
getResultSuccess
(
item
);
}
/**
* 查询发票明细
* @param {*} applyNo
* @param {*} merchantId
*/
async
queryInvoice
(
applyNo
,
merchantId
,
id
)
{
try
{
let
_apply
;
if
(
merchantId
&&
applyNo
)
{
_apply
=
await
this
.
dao
.
model
.
findOne
({
where
:
{
merchantId
:
merchantId
,
applyNo
:
applyNo
},
raw
:
true
});
}
else
if
(
id
)
{
_apply
=
await
this
.
dao
.
model
.
findOne
({
where
:
{
id
:
this
.
trim
(
id
)
},
raw
:
true
});
}
else
{
_apply
=
null
;
}
if
(
!
_apply
)
{
return
system
.
getResult
(
null
)
}
this
.
dao
.
setRowCodeName
(
_apply
,
"status"
);
this
.
dao
.
setRowCodeName
(
_apply
,
"customerStatus"
);
//查询平台审批内容
let
deliverer
=
await
this
.
delivererDao
.
model
.
findOne
({
where
:
{
id
:
_apply
.
delivererId
},
raw
:
true
});
_apply
.
deliverer
=
deliverer
;
//查询发票信息
let
invoice
=
await
this
.
invoiceDao
.
model
.
findOne
({
where
:
{
id
:
_apply
.
id
},
raw
:
true
});
this
.
dao
.
setRowCodeName
(
invoice
,
"status"
);
//红冲关联
let
parentInvoice
=
await
this
.
dao
.
model
.
findOne
({
where
:
{
id
:
_apply
.
parentId
},
raw
:
true
});
this
.
dao
.
setRowCodeName
(
parentInvoice
,
"status"
);
this
.
dao
.
setRowCodeName
(
parentInvoice
,
"customerStatus"
);
_apply
.
invoice
=
invoice
;
_apply
.
deliverer
=
deliverer
||
{};
_apply
.
parentInvoice
=
parentInvoice
;
this
.
handleDate
(
_apply
.
invoice
,
[
"taxTime"
,
"invoiceTime"
],
"YYYY-MM-DD"
);
return
system
.
getResult
(
_apply
);
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息:
${
error
}
`
);
}
}
/**
* 发票撤回
* @param {*} applyNo
* @param {*} merchantId
* @param
*/
async
cancelInvoice
(
applyNo
,
merchantId
)
{
let
_invoice
=
await
this
.
dao
.
model
.
findOne
({
where
:
{
applyNo
:
applyNo
,
merchantId
:
merchantId
},
attributes
:
[
'id'
,
'status'
]
});
if
(
_invoice
.
status
!=
this
.
invoiceStatus
.
unpay
)
{
return
system
.
getResult
(
null
,
`当前发票正在处理,不能撤回`
);
}
else
{
_invoice
.
status
=
this
.
invoiceStatus
.
recall
;
try
{
let
res
=
await
_invoice
.
save
();
return
system
.
getResult
(
res
);
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误:
${
error
}
`
);
}
}
}
/**
* 发票业务分配
* @param {*} params
* {
* id:"" //发票id
* nextStatus:"" //发票状态
* }
*/
async
assignment
(
params
)
{
let
_apply
=
await
this
.
verification
(
params
);
try
{
let
res
;
switch
(
params
.
nextStatus
)
{
case
"1010"
:
//审核不通过
res
=
await
this
.
examine1000
(
params
,
_apply
);
break
;
case
"1020"
:
//待分配
res
=
await
this
.
examine1000
(
params
,
_apply
);
break
;
case
"1030"
:
//待处理
res
=
await
this
.
examine1030
(
params
,
_apply
);
break
;
case
"1070"
:
//审核通过
res
=
await
this
.
examine1070
(
params
,
_apply
);
break
;
case
"1300"
:
//审核失败
res
=
await
this
.
examine1300
(
params
,
_apply
);
break
;
case
"1090"
:
//已完成
res
=
await
this
.
examine1090
(
params
,
_apply
);
break
;
default
:
res
=
system
.
getResult
(
null
,
"action_type参数错误"
);
break
;
}
return
res
;
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
/**
* 第一次审核
* @param {*} params
* {
* id: xxx, //发票id
* isPay:1, //时候付款
* nextStatus:1020,//发票状态
* remark:""//发票标注
* }
*/
async
examine1000
(
params
,
_apply
)
{
if
(
Number
(
params
.
isPay
)
!=
1
)
{
return
system
.
getResult
(
null
,
`参数错误 请核对付款信息`
);
}
params
.
nextStatus
=
this
.
trim
(
params
.
nextStatus
);
params
.
remark
=
this
.
trim
(
params
.
remark
);
_apply
.
status
=
params
.
nextStatus
;
_apply
.
remark
=
params
.
remark
;
_apply
.
isPay
=
Number
(
params
.
isPay
);
if
(
params
.
nextStatus
==
"1010"
)
{
_apply
.
customerStatus
=
"1010"
;
}
try
{
let
res
=
await
_apply
.
save
();
if
(
_apply
.
parentId
&&
params
.
nextStatus
==
"1010"
)
{
await
this
.
invoiceDao
.
update
({
id
:
_apply
.
parentId
,
redStatus
:
'3'
});
}
return
system
.
getResultSuccess
();
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
/**
* 待处理 (当前状态待分配或者是审核为通过)
* @param {*} params
* {
* id: xxx, //发票id
* delivererId:1, //交付商
* nextStatus:examine1020,//发票状态
* delivererName:""//交付商名称
* delivererAmount:"" //分成
* }
*/
async
examine1030
(
params
,
_apply
)
{
if
(
!
params
.
id
||
!
params
.
delivererName
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
await
this
.
db
.
transaction
(
async
(
t
)
=>
{
let
_deliverer
=
await
this
.
delivererDao
.
create
({
invoiceId
:
_apply
.
id
,
applyNo
:
_apply
.
applyNo
,
merchantId
:
_apply
.
merchantId
,
delivererId
:
this
.
trim
(
params
.
delivererId
),
delivererName
:
this
.
trim
(
params
.
delivererName
),
delivererAmount
:
Number
(
this
.
trim
(
params
.
delivererAmount
))
},
t
);
let
applyData
=
{};
applyData
.
status
=
this
.
trim
(
params
.
nextStatus
);
applyData
.
customerStatus
=
this
.
trim
(
params
.
nextStatus
);
applyData
.
delivererId
=
this
.
trim
(
_deliverer
.
id
);
applyData
.
id
=
this
.
trim
(
params
.
id
);
//更新申请发票内容
await
this
.
dao
.
update
(
applyData
,
t
);
//更改发票状态
let
invoiceData
=
{};
invoiceData
.
status
=
this
.
trim
(
params
.
nextStatus
);
invoiceData
.
id
=
this
.
trim
(
params
.
id
);
await
this
.
invoiceDao
.
update
(
invoiceData
,
t
);
}).
catch
(
error
=>
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
});
return
system
.
getResultSuccess
();
}
/**
* 第二次审核
* @param {*} params
* {
* id: xxx, //发票id
* auditContent:1, //审核备注
* nextStatus:1070,//发票状态
* delivererContent:""//发票内容
* mailAddr:"", //邮寄地址
* mailMobile:"", //邮寄电话
* mailTo:"", //邮寄人
* }
*/
async
examine1070
(
params
,
_apply
)
{
let
delivererData
=
{},
applyData
=
{},
invoiceData
=
{};
let
_deliverer
=
await
this
.
delivererDao
.
findOne
({
id
:
_apply
.
delivererId
});
delivererData
.
auditContent
=
this
.
trim
(
params
.
auditContent
);
delivererData
.
delivererContent
=
this
.
trim
(
params
.
delivererContent
);
delivererData
.
mailAddr
=
this
.
trim
(
params
.
mailAddr
);
delivererData
.
mailMobile
=
this
.
trim
(
params
.
mailMobile
);
delivererData
.
mailTo
=
this
.
trim
(
params
.
mailTo
);
delivererData
.
mailEmail
=
this
.
trim
(
params
.
mailEmail
);
delivererData
.
id
=
this
.
trim
(
_deliverer
.
id
);
applyData
.
status
=
this
.
trim
(
params
.
nextStatus
);
applyData
.
id
=
this
.
trim
(
params
.
id
);
invoiceData
.
status
=
this
.
trim
(
params
.
nextStatus
);
invoiceData
.
id
=
this
.
trim
(
params
.
id
);
await
this
.
db
.
transaction
(
async
(
t
)
=>
{
//更新deliverer信息
await
this
.
delivererDao
.
update
(
delivererData
,
t
);
//更新 申请单和发票单
await
this
.
dao
.
update
(
applyData
,
t
);
await
this
.
invoiceDao
.
update
(
invoiceData
,
t
);
if
(
_apply
.
parentId
)
{
await
this
.
invoiceDao
.
update
({
id
:
_apply
.
parentId
,
redStatus
:
'4'
},
t
);
}
}).
catch
(
error
=>
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
});
return
system
.
getResultSuccess
();
}
/**
* 第二次审核失败
* @param {*} params
*/
async
examine1300
(
params
)
{
let
_apply
=
await
this
.
dao
.
findOne
({
id
:
this
.
trim
(
params
.
id
)
});
if
(
!
_apply
)
{
return
system
.
getResult
(
null
,
`发票不存在,请核对发票ID`
);
}
let
_deliverer
=
await
this
.
delivererDao
.
model
.
findOne
({
where
:
{
id
:
_apply
.
delivererId
}
});
if
(
!
_deliverer
)
{
return
system
.
getResult
(
null
,
`交付商不存在,请联系管理员`
);
}
await
this
.
db
.
transaction
(
async
(
t
)
=>
{
//更新 申请单和发票单
await
this
.
dao
.
update
({
status
:
"1300"
,
id
:
_apply
.
id
},
t
);
await
this
.
invoiceDao
.
update
({
status
:
"1300"
,
id
:
_apply
.
id
},
t
);
if
(
_deliverer
.
id
)
{
//提交审核信息
await
this
.
delivererDao
.
update
({
auditContent
:
this
.
trim
(
auditContent
),
id
:
_deliverer
.
id
});
}
}).
catch
(
error
=>
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
});
return
system
.
getResultSuccess
();
}
/**
* 平台更新 已完成状态
* @param {*} params
* @param {*} _apply
*/
async
examine1090
(
params
,
_apply
)
{
let
applyData
=
{};
applyData
.
status
=
this
.
trim
(
params
.
nextStatus
);
applyData
.
customerStatus
=
this
.
trim
(
params
.
nextStatus
);
applyData
.
id
=
this
.
trim
(
params
.
id
);
// invoiceData.status = this.trim(params.nextStatus);
// invoiceData.id=this.trim(params.id);
await
this
.
db
.
transaction
(
async
(
t
)
=>
{
//更新 申请单和发票单
await
this
.
dao
.
update
(
applyData
,
t
);
// await this.invoiceDao.update(invoiceData,t);
}).
catch
(
error
=>
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
});
return
system
.
getResultSuccess
();
}
/**
* 检查状态是否正确
* @param {*} params
* {
* id:xxx //发票id
* nextStatus:xxx //发票状态
* }
*/
async
verification
(
params
)
{
let
_apply
=
await
this
.
dao
.
findOne
({
id
:
this
.
trim
(
params
.
id
)
});
if
(
!
_apply
)
{
return
system
.
getResult
(
null
,
`此发票不存在`
);
}
//获取当前状态 的对象
let
_status
=
this
.
invoiceStatus
[
_apply
.
status
];
//如果不符合状态则退出
if
(
params
.
nextStatus
==
"1300"
||
params
.
nextStatus
==
"1040"
||
params
.
nextStatus
==
"1010"
)
{
return
_apply
;
}
if
(
!
_status
&&
_status
.
next
!=
params
.
nextStatus
)
{
let
name
=
this
.
invoiceStatus
[
this
.
invoiceStatus
[
_apply
.
status
].
next
].
name
;
return
system
.
getResult
(
null
,
`更新状态错误,提示:当前状态的下一个状态是
${
name
}
`
);
}
return
_apply
;
}
/**
* 发票申请列表查询(平台)
* @param {*} params
* @param applyNo 发票的申请编号
* @param invoiceTime 发票的申请时间
* @param type 发票的类型
* @param status 业务进度
*/
async
queryApplyInvoices
(
params
)
{
let
where
=
{};
if
(
this
.
trim
(
params
.
applyNo
))
{
where
.
applyNo
=
this
.
trim
(
params
.
applyNo
);
}
if
(
this
.
trim
(
params
.
businessmenCreditCode
))
{
where
.
businessmenCreditCode
=
this
.
trim
(
params
.
businessmenCreditCode
);
}
if
(
this
.
trim
(
params
.
invoiceTime
))
{
where
.
invoiceTime
=
{
[
this
.
db
.
Op
.
gte
]:
this
.
trim
(
params
.
invoiceTime
)
}
}
if
(
this
.
trim
(
params
.
type
))
{
where
.
type
=
this
.
trim
(
params
.
type
);
}
if
(
this
.
trim
(
params
.
status
))
{
where
.
status
=
this
.
trim
(
params
.
status
);
}
let
pageIndex
=
params
.
pageIndex
||
1
;
let
pageSize
=
params
.
pageSize
||
10
;
let
orderObj
=
[
// ['updatedAt', 'desc'],
[
'id'
,
'desc'
]
];
try
{
let
_apply
=
await
this
.
dao
.
getPageList
(
pageIndex
,
pageSize
,
where
,
orderObj
,
null
,
null
);
for
(
let
item
of
_apply
.
rows
)
{
let
_deliverer
=
await
this
.
delivererDao
.
model
.
findOne
({
// where: {
// delivererId: item.delivererId
// },
attributes
:
[
'delivererName'
]
});
if
(
_deliverer
)
{
item
.
delivererName
=
_deliverer
.
delivererName
;
}
else
{
item
.
delivererName
=
""
;
}
if
(
item
.
type
==
"10"
)
{
item
.
type
=
"普通发票"
;
}
else
if
(
item
.
type
==
"20"
)
{
item
.
type
=
"增值税专用发票"
;
}
else
if
(
item
.
type
==
"30"
)
{
item
.
type
=
"电子发票"
;
}
else
{
item
.
type
=
""
;
}
let
_invoice
=
await
this
.
invoiceDao
.
model
.
findOne
({
where
:
{
id
:
item
.
id
},
attributes
:
[
'status'
,
'invoiceImg'
]
});
if
(
_invoice
.
status
)
{
this
.
dao
.
setRowCodeName
(
_invoice
,
"status"
);
}
else
{
_invoice
.
status
=
""
;
}
item
.
invoiceImg
=
this
.
trim
(
_invoice
.
invoiceImg
);
item
.
delivererStatus
=
_invoice
.
statusName
;
//处理时间
this
.
handleDate
(
item
,
[
"invoiceTime"
],
null
,
-
8
);
this
.
dao
.
setRowCodeName
(
item
,
"status"
);
item
.
isPay
=
item
.
isPay
==
1
?
'已付款'
:
'未付款'
;
}
return
system
.
getResult
(
_apply
);
}
catch
(
error
)
{
return
system
.
getResult
(
`系统错误 错误信息
${
error
}
`
);
}
}
/**
* 列举所有日期
* @param {*} end
*/
getDays
(
end
)
{
var
days
=
[];
var
month
=
moment
(
end
).
format
(
"YYYY-MM"
);
var
endDay
=
Number
(
moment
(
end
).
format
(
"DD"
));
for
(
var
i
=
1
;
i
<=
endDay
;
i
++
)
{
if
(
i
<
10
)
{
days
.
push
(
month
+
"-0"
+
i
);
}
else
{
days
.
push
(
month
+
"-"
+
i
);
}
}
return
days
;
}
addStatCount
(
statusMap
,
statuses
)
{
var
count
=
0
;
if
(
!
statuses
)
{
return
count
;
}
for
(
var
status
of
statuses
)
{
count
=
count
+
Number
(
statusMap
[
status
]
||
0
);
}
return
count
;
}
//查询发票状态 只有在状态为 '1000','0090' 或者信息不存在的情况下 验证成功 参考 applySve.verificationByBusinessmenCreditCode接口
async
verificationInvoiceStatus
(
businessmenType
,
businessmenId
,
businessmenCreditCode
)
{
try
{
let
condition
=
{
businessmenType
:
businessmenType
,
businessmenId
:
businessmenId
,
status
:
{
[
this
.
db
.
Op
.
in
]:
[
'1000'
,
'0090'
]
}
};
if
(
businessmenCreditCode
)
{
condition
.
businessmenCreditCode
=
businessmenCreditCode
;
}
let
invoices
=
await
this
.
dao
.
model
.
findAll
({
where
:
condition
,
attributes
:
[
"id"
,
"status"
]
});
if
(
!
invoices
)
{
return
false
;
}
for
(
let
item
of
invoices
)
{
if
(
!
item
)
{
continue
;
}
if
(
item
[
'status'
]
!=
"1000"
||
item
[
'status'
]
!=
"0090"
)
{
return
false
;
}
}
return
true
;
}
catch
(
error
)
{
return
false
;
}
}
/**
* 累计不含税价
* @param {*} businessmenId 商户id
* @param {*} taxIncPriRat 不含税价百分比
* @param {*} invoiceAmount 发票总额
* @param {*} type 计算类型 1:个税 2:增值税
* @param {*} valCalWay 增值税计算类型 1:月 2:季度 3:年
* @param {*} perCalWay 增值税计算类型 1:月 2:季度 3:年
* @param {*} invoiceTime 格式 YYYY-MM-DD hh:mm:ss
*/
async
calAccumulatedPriceExcludingTax
(
businessmenId
,
businessmenType
,
businessmenCreditCode
,
taxIncPriRat
,
invoiceAmount
,
type
,
valCalWay
,
perCalWay
,
invoiceTime
)
{
try
{
let
now
=
moment
(
invoiceTime
),
startTime
,
attribute
;
if
(
type
===
1
)
{
//个税
attribute
=
`invoiceAmount`
;
if
(
perCalWay
===
3
)
{
//按照年
startTime
=
`
${
now
.
get
(
'year'
)}
-01-01 00:00:00`
;
}
else
if
(
perCalWay
===
2
)
{
//按照季度
let
quarter
=
now
.
quarter
();
if
(
1
==
quarter
)
{
//第一季度
startTime
=
`
${
now
.
get
(
'year'
)}
-01-01 00:00:00`
;
}
else
if
(
2
==
quarter
)
{
startTime
=
`
${
now
.
get
(
'year'
)}
-04-01 00:00:00`
;
}
else
if
(
3
==
quarter
)
{
startTime
=
`
${
now
.
get
(
'year'
)}
-07-01 00:00:00`
;
}
else
{
startTime
=
`
${
now
.
get
(
'year'
)}
-10-01 00:00:00`
;
}
}
else
{
//按照月
let
_month
=
now
.
month
()
<
10
?
"0"
+
now
.
month
()
:
now
.
month
();
startTime
=
`
${
now
.
get
(
'year'
)}
-
${
_month
}
-01 00:00:00`
;
}
}
else
{
attribute
=
`valueAddedTax`
;
if
(
valCalWay
===
1
)
{
//月
startTime
=
`
${
now
.
get
(
'year'
)}
-
${
now
.
month
()}
-01 00:00:00`
;
}
else
if
(
valCalWay
===
2
)
{
//季度
let
quarter
=
now
.
quarter
();
if
(
1
==
quarter
)
{
//第一季度
startTime
=
`
${
now
.
get
(
'year'
)}
-01-01 00:00:00`
;
}
else
if
(
2
==
quarter
)
{
startTime
=
`
${
now
.
get
(
'year'
)}
-04-01 00:00:00`
;
}
else
if
(
3
==
quarter
)
{
startTime
=
`
${
now
.
get
(
'year'
)}
-07-01 00:00:00`
;
}
else
{
startTime
=
`
${
now
.
get
(
'year'
)}
-10-01 00:00:00`
;
}
}
else
{
//年
startTime
=
`
${
now
.
get
(
'year'
)}
-01-01 00:00:00`
;
}
}
console
.
log
(
"本年度开始的时间:"
+
startTime
+
" 至今:"
+
now
.
format
(
"YYYY-MM-DD hh:mm:ss"
));
let
condition
=
{
businessmenId
:
businessmenId
,
businessmenType
:
businessmenType
,
status
:
{
[
this
.
db
.
Op
.
in
]:
[
'1020'
,
'1030'
,
'1040'
,
'1050'
,
'1060'
,
'1070'
,
'1080'
,
'1090'
,
'1100'
,
'1200'
,
'1300'
]
},
invoiceTime
:
{
[
this
.
db
.
Op
.
between
]:
[
startTime
,
now
.
format
(
"YYYY-MM-DD hh:mm:ss"
)],
}
};
if
(
businessmenCreditCode
){
condition
.
businessmenCreditCode
=
businessmenCreditCode
;
}
let
beforeAmount
=
await
this
.
dao
.
model
.
sum
(
attribute
,
{
where
:
condition
});
beforeAmount
=
isNaN
(
beforeAmount
)
?
0
:
beforeAmount
;
let
res
=
new
Decimal
(
invoiceAmount
).
plus
(
beforeAmount
).
div
(
Decimal
.
add
(
1
,
taxIncPriRat
)).
toFixed
(
2
);
console
.
log
(
"当前累计金额 :"
+
res
);
return
res
;
}
catch
(
error
)
{
console
.
log
(
error
);
return
system
.
getResult
(
-
1
,
`系统错误 错误信息
${
error
}
`
);
}
}
/**
* 计算累计税值
* @param {*} businessmenId
* @param {*} type 计算类型 1:个税 2:增值税
* @param {*} valCalWay 增值税计算类型 1:月 2:季度
*
*/
async
calCumulativeProfit
(
businessmenId
,
businessmenType
,
type
,
valCalWay
)
{
let
now
=
moment
(),
startTime
,
attribute
;
if
(
type
==
1
)
{
attribute
=
`personalIncomeTax`
;
startTime
=
`
${
now
.
get
(
'year'
)}
-01-01 00:00:00`
;
}
else
{
attribute
=
`valueAddedTax`
;
if
(
valCalWay
===
1
)
{
//月
startTime
=
`
${
now
.
get
(
'year'
)}
-
${
now
.
month
()}
-01 00:00:00`
;
}
else
{
//季度
let
quarter
=
now
.
quarter
();
if
(
1
==
quarter
)
{
//第一季度
startTime
=
`
${
now
.
get
(
'year'
)}
-01-01 00:00:00`
;
}
else
if
(
2
==
quarter
)
{
startTime
=
`
${
now
.
get
(
'year'
)}
-04-01 00:00:00`
;
}
else
if
(
3
==
quarter
)
{
startTime
=
`
${
now
.
get
(
'year'
)}
-07-01 00:00:00`
;
}
else
{
startTime
=
`
${
now
.
get
(
'year'
)}
-10-01 00:00:00`
;
}
}
}
console
.
log
(
"本年度开始的时间:"
+
startTime
+
" 至今:"
+
now
.
format
(
"YYYY-MM-DD hh:mm:ss"
));
let
cumulativeProfit
=
await
this
.
dao
.
model
.
sum
(
attribute
,
{
where
:
{
businessmenId
:
businessmenId
,
businessmenType
:
businessmenType
,
status
:
this
.
invoiceStatus
.
auditPass
,
invoiceTime
:
{
[
this
.
db
.
Op
.
between
]:
[
startTime
,
now
.
format
(
"YYYY-MM-DD hh:mm:ss"
)],
}
}
});
return
cumulativeProfit
||
0
;
}
}
module
.
exports
=
ApplyService
;
\ No newline at end of file
xggsve-invoice/app/base/service/impl/invoice/applySvebak.js
0 → 100644
View file @
607e3516
// const system = require("../../../system");
// const ServiceBase = require("../../sve.base")
// const moment = require('moment');
// var rule =require("../../../utils/invoiceRule/rule");
// const Decimal = require('decimal.js');
// class ApplyService extends ServiceBase {
// constructor() {
// super("invoice", ServiceBase.getDaoName(ApplyService));
// let is = system.getObject("util.invoiceStatus");
// this.invoiceStatus = is.status;
// this.delivererDao = system.getObject("db.invoice.delivererDao");
// this.invoiceDao = system.getObject("db.invoice.invoiceDao");
// //最大的发票总额度
// this.MAX_TOTAL_AMOUNT = 500000000;
// //警告发票额度
// this.WARNING_AMOUNT = 400000000;
// this.PER_TAX = 1; //个税
// this.VAL_TAX = 2; //增值税
// this.INVOICE_MAX = 10; //一次性插入最大值
// }
// /**
// * 保存发票信息
// */
// async apiSaveInvoice(params) {
// try {
// let res = await this.saveInvoice(params);
// return res;
// } catch (error) {
// return system.getResult(null, `系统错误 错误信息:${error}`);
// }
// }
// /**
// * 查询申请列表(平台)
// * @param {*} params
// */
// async apiQueryApplyInvoices(params) {
// try {
// return await this.queryApplyInvoices(params);
// } catch (error) {
// return system.getResult(null, `系统错误 错误信息 ${error}`);
// }
// }
// /**
// * 查询发票明细(平台)
// * @param {*} params
// */
// async apiQueryInvoice(params) {
// try {
// var merchantId = params.merchantId || params.merchant_id;
// if ((params.merchantId && params.applyNo) || params.id) {
// let res = await this.queryInvoice(params.applyNo, merchantId, params.id);
// return res;
// } else {
// return system.getResultSuccess();
// }
// } catch (error) {
// return system.getResult(null, `系统错误 错误信息:${error}`);
// }
// }
// /**
// * 发票撤回
// * @param params
// * {
// * applyNo:"", //发票申请编号
// * merchantId:"", //商户id
// * }
// */
// async apiCancelInvoice(params) {
// try {
// var merchantId = params.merchantId || params.merchant_id;
// if (!params.applyNo || !merchantId) {
// return system.getResult(null, "发票申请编号不合法。");
// }
// return await this.cancelInvoice(params.applyNo, merchantId);
// } catch (error) {
// return system.getResult(null, `系统错误:错误信息 ${error}`);
// }
// }
// /**
// * 平台业务分配
// * @param {*} params
// * {
// * id:"xxx" //发票id
// * nextStatus:"xxx", //发票状态
// *
// * }
// */
// async apiAssignment(params) {
// try {
// if (!params.id) {
// return system.getResult(null, `参数错误`);
// }
// return await this.assignment(params);
// } catch (error) {
// return system.getResult(null, `系统错误 错误信息 ${error}`);
// }
// }
// /**
// * 平台业务分配
// * @param {*} params
// * {
// * id:"xxx" //发票id
// * nextStatus:"xxx", //发票状态
// *
// * }
// */
// async apiVerificationByBusinessmenCreditCode(params) {
// try {
// if (!params.businessmenCreditCode) {
// return system.getResult(null, `参数错误`);
// }
// return await this.verificationByBusinessmenCreditCode(this.trim(params.businessmenCreditCode));
// } catch (error) {
// return system.getResult(null, `系统错误 错误信息 ${error}`);
// }
// }
// /**
// * 发票红冲
// * @param {*} params
// */
// async apiRedRushInvoice(params) {
// if (!params.id) {
// return system.getResult(null, `参数错误 发票ID不合法`);
// }
// try {
// let res = await this.redRushInvoice(params);
// return res;
// } catch (error) {
// return system.getResult(null, `参数错误 错误信息 ${error}`);
// }
// }
// /**
// * 交易数据(平台)
// * @param {*} params
// */
// async apiStatTransData(params) {
// try {
// return await this.statTransData(params);
// } catch (error) {
// return system.getResult(-1, `系统错误 错误信息 ${error}`);
// }
// }
// /**
// * 发票办理(平台)
// * @param {*} params
// */
// async apiStatBusinessData(params) {
// try {
// return await this.statBusinessData(params);
// } catch (error) {
// console.log(error);
// return system.getResult(null, "接口异常");
// }
// }
// //===========================================================================================
// /**
// * 插入发票
// * @param {*} params
// */
// async saveInvoice(params) {
// try {
// //试算
// let val = await rule.dispatcher(params);
// if(val.data==-1){
// return system.getResult(-1,`系统错误 ${val.msg}`);
// }
// params.personalIncomeTax = this.trim(val.personalIncomeTax);
// params.additionalTax = this.trim(val.additionalTax);
// params.valueAddedTax = this.trim(val.valueAddedTax);
// params.serviceCharge = this.trim(val.serviceCharge);
// params.isPay = (params.isPay) ? 1 : 0;
// params.status = "1000";
// params.customerStatus = "1000";
// params.ruleCode = this.trim(params.ruleCode);
// params.ruleParams = JSON.stringify(params);
// await this.db.transaction(async (t) => {
// //插入发票申请单
// let _apply = await this.dao.create(params, t);
// //插入一条发票信息
// await this.invoiceDao.model.create({
// id: _apply.id,
// applyNo: _apply.applyNo,
// merchantId: _apply.merchantId,
// businessmenId: params.businessmenId,
// businessmenType: params.businessmenType,
// ruleCode: params.ruleCode,
// ruleParams: params.ruleParams
// }, t);
// });
// return system.getResultSuccess();
// } catch (error) {
// return system.getResult(null, `系统错误 错误信息 ${error}`);
// }
// }
// /**
// * 发票办理(平台)
// * @param {*} params
// */
// async statBusinessData(params) {
// var result = {};
// var type = Number(params.type || 1);
// // 查 已完成订单,待分配订单,待审核订单,办理中订单
// var begin, end;
// // 取开始时间
// if (type == 1) {
// begin = moment().format("YYYY-MM") + "-01 00:00:00";
// end = moment(begin).add(1, "months").subtract(1, 'days').format("YYYY-MM-DD") + " 23:59:59";
// } else if (type == 2) {
// begin = moment().subtract(1, "months").format("YYYY-MM") + "-01 00:00:00";
// end = moment(begin).add(1, "months").subtract(1, 'days').format("YYYY-MM-DD") + " 23:59:59";
// }
// // 先按照订单状态查
// var statMap = await this.dao.statByStatus(begin, end);
// // 已开具 1050
// result.completeCount = this.addStatCount(statMap, ['1050']);
// // 待申请审核 1000
// result.toApplyCount = this.addStatCount(statMap, ['1000']);
// // 待交付审核 1130 1140
// result.toAuditCount = this.addStatCount(statMap, ['1060']);
// // 办理中 "1030", "1050", "1060", "1080", "1300"
// result.handlingCount = this.addStatCount(statMap, ["1030", "1050", "1060", "1080", "1300"]);
// return system.getResultSuccess(result);
// }
// /**
// * 交易数据(平台)
// * @param {*} params
// */
// async statTransData(params) {
// try {
// var result = {
// invoiceCount: 0,
// serviceChange: 0,
// };
// var type = Number(params.type || 1);
// var begin, end;
// // 取开始时间
// if (type == 1) {
// begin = moment().format("YYYY-MM") + "-01 00:00:00";
// } else if (type == 2) {
// begin = moment().subtract(1, "months").format("YYYY-MM") + "-01 00:00:00";
// }
// // echart数据
// var days = [];
// var dayCounts = [];
// var priceCounts = [];
// // 处理查询业务
// if (type == 1 || type == 2) { // 取结束时间
// end = moment(begin).add(1, "months").subtract(1, 'days').format("YYYY-MM-DD") + " 23:59:59";
// days = this.getDays(end);
// // 按天统计
// var dayMap = await this.dao.statDayByTime(begin, end);
// for (var day of days) {
// var ditem = dayMap[day] || {};
// dayCounts.push(ditem.invoiceCount || 0);
// priceCounts.push(system.f2y(ditem.serviceChange || 0));
// }
// } else {
// var monthMap = await this.dao.statMonthByTime(begin, end);
// var bm = monthMap.begin || "";
// var em = monthMap.end || "";
// if (bm && em) {
// // 开始月份-结束月份所有月份
// var curMonth = bm;
// while (true) {
// days.push(curMonth);
// if (curMonth == em) {
// break;
// }
// curMonth = moment(curMonth + "-01").add(1, "month").format("YYYY-MM");
// }
// }
// for (var day of days) {
// var ditem = monthMap[day] || {};
// dayCounts.push(ditem.invoiceCount || 0);
// priceCounts.push(system.f2y(ditem.serviceChange || 0));
// }
// }
// var invoiceApplyData = await this.dao.statInvoiceByTime(begin, end) || {};
// result.invoiceCount = invoiceApplyData.invoiceCount;
// result.serviceChange = system.f2y(invoiceApplyData.serviceChange);
// result.days = days;
// result.dayCounts = dayCounts;
// result.priceCounts = priceCounts;
// return system.getResultSuccess(result);
// } catch (error) {
// return system.getResult(null, `系统错误 错误信息 ${error}`);
// }
// }
// /**
// * 红冲
// * @param {*} params
// */
// async redRushInvoice(params) {
// try {
// let _apply = await this.dao.findById(params.id) || {};
// let invoice = await this.invoiceDao.findById(params.id) || {};
// //判断红冲状态
// if (invoice.redStatus == 2) {
// return system.getResult(null, `发票红冲中`);
// } else if (invoice.redStatus == 4) {
// return system.getResult(null, `红冲已红冲`);
// }
// let nowObj = {};
// nowObj.merchantId = this.trim(_apply.merchantId);
// nowObj.merchantName = this.trim(_apply.merchantName);
// nowObj.merchantCreditCode = this.trim(_apply.merchantCreditCode);
// nowObj.merchantAddr = this.trim(_apply.merchantAddr);
// nowObj.merchantMobile = this.trim(_apply.merchantMobile);
// nowObj.merchantBank = this.trim(_apply.merchantBank);
// nowObj.merchantAccount = this.trim(_apply.merchantAccount);
// nowObj.businessmenCreditCode = this.trim(_apply.businessmenCreditCode);
// nowObj.businessmenId = this.trim(_apply.businessmenId);
// nowObj.businessmenName = this.trim(_apply.businessmenName);
// nowObj.businessmenAddr = this.trim(_apply.businessmenAddr);
// nowObj.businessmenMobile = this.trim(_apply.businessmenMobile);
// nowObj.businessmenBank = this.trim(_apply.businessmenBank);
// nowObj.businessmenAccount = this.trim(_apply.businessmenAccount);
// nowObj.isBank = _apply.isBank ? 1 : 0;
// nowObj.taxAuthorities = this.trim(_apply.taxAuthorities);
// nowObj.type = this.trim(_apply.type);
// nowObj.invoiceAmount = this.trim(_apply.invoiceAmount);
// nowObj.statements = this.trim(_apply.statements);
// nowObj.contract = this.trim(_apply.contract);
// nowObj.invoiceTime = this.trim(_apply.invoiceTime);
// nowObj.settleImg = this.trim(_apply.settleImg);
// nowObj.applyNo = this.trim(_apply.applyNo);
// nowObj.invoiceConten = this.trim(_apply.invoiceConten);
// nowObj.personalIncomeTax = this.trim(_apply.personalIncomeTax);
// nowObj.additionalTax = this.trim(_apply.additionalTax);
// nowObj.valueAddedTax = this.trim(_apply.valueAddedTax);
// nowObj.serviceCharge = this.trim(_apply.serviceCharge);
// nowObj.applyMobile = this.trim(_apply.applyMobile);
// nowObj.parentId = this.trim(_apply.id);
// nowObj.status = this.trim("1000");
// nowObj.customerStatus = this.trim("1000");
// nowObj.payWay = this.trim(_apply.payWay);
// nowObj.payAccount = this.trim(_apply.payAccount);
// nowObj.mailAddr = this.trim(_apply.mailAddr);
// nowObj.mailMobile = this.trim(_apply.mailMobile);
// nowObj.mailTo = this.trim(_apply.mailTo);
// nowObj.remark = this.trim("");
// nowObj.delivererId = this.trim("");
// nowObj.isPay = 0;
// nowObj.businessmenType = this.trim(_apply.businessmenType);
// nowObj.ruleCode = this.trim(_apply.ruleCode);
// nowObj.ruleParams = this.trim(_apply.ruleParams);
// let res = await this.db.transaction(async (t) => {
// // 插入发票申请单
// let _nowObj = await this.dao.create(nowObj, t);
// // 插入一条发票信息
// await this.invoiceDao.create({
// id: _nowObj.id,
// applyNo: _nowObj.applyNo,
// merchantId: _nowObj.merchantId,
// red_status: '1',
// businessmenType : nowObj.businessmenType,
// ruleCode : nowObj.ruleCode,
// ruleParams : nowObj.ruleParams
// }, t);
// // 源发票改为红冲办理中
// var updfields = {
// redStatus: '2',
// id: _apply.id,
// }
// await this.invoiceDao.update(updfields, t);
// });
// return system.getResultSuccess();
// } catch (error) {
// console.log(error);
// return system.getResult(null, `参数错误 错误信息 ${error}`);
// }
// }
// async getByApplyNo(params) {
// var merchantId = params.merchantId || params.merchant_id;
// var applyNo = params.applyNo;
// var item = await this.dao.getByApplyNo(merchantId, applyNo);
// if (item) {
// this.handleDate(item, ["created_at", "updated_at"], null, -8);
// }
// return system.getResultSuccess(item);
// }
// /**
// * 查询发票明细
// * @param {*} applyNo
// * @param {*} merchantId
// */
// async queryInvoice(applyNo, merchantId, id) {
// try {
// let _apply;
// if (merchantId && applyNo) {
// _apply = await this.dao.model.findOne({
// where: {
// merchantId: merchantId,
// applyNo: applyNo
// },
// raw: true
// });
// } else if (id) {
// _apply = await this.dao.model.findOne({
// where: {
// id: this.trim(id)
// },
// raw: true
// });
// } else {
// _apply = null;
// }
// if (!_apply) {
// return system.getResult(null)
// }
// this.dao.setRowCodeName(_apply, "status");
// this.dao.setRowCodeName(_apply, "customerStatus");
// //查询平台审批内容
// let deliverer = await this.delivererDao.model.findOne({
// where: {
// id: _apply.delivererId
// },
// raw: true
// });
// _apply.deliverer = deliverer;
// //查询发票信息
// let invoice = await this.invoiceDao.model.findOne({
// where: {
// id: _apply.id
// },
// raw: true
// });
// this.dao.setRowCodeName(invoice, "status");
// //红冲关联
// let parentInvoice = await this.dao.model.findOne({
// where: {
// id: _apply.parentId
// },
// raw: true
// });
// this.dao.setRowCodeName(parentInvoice, "status");
// this.dao.setRowCodeName(parentInvoice, "customerStatus");
// _apply.invoice = invoice;
// _apply.deliverer = deliverer || {};
// _apply.parentInvoice = parentInvoice;
// this.handleDate(_apply.invoice, ["taxTime", "invoiceTime"], "YYYY-MM-DD");
// return system.getResult(_apply);
// } catch (error) {
// return system.getResult(null, `系统错误 错误信息:${error}`);
// }
// }
// /**
// * 发票撤回
// * @param {*} applyNo
// * @param {*} merchantId
// * @param
// */
// async cancelInvoice(applyNo, merchantId) {
// let _invoice = await this.dao.model.findOne({
// where: {
// applyNo: applyNo,
// merchantId: merchantId
// },
// attributes: ['id', 'status']
// });
// if (_invoice.status != this.invoiceStatus.unpay) {
// return system.getResult(null, `当前发票正在处理,不能撤回`);
// } else {
// _invoice.status = this.invoiceStatus.recall;
// try {
// let res = await _invoice.save();
// return system.getResult(res);
// } catch (error) {
// return system.getResult(null, `系统错误: ${error}`);
// }
// }
// }
// /**
// * 发票业务分配
// * @param {*} params
// * {
// * id:"" //发票id
// * nextStatus:"" //发票状态
// * }
// */
// async assignment(params) {
// let _apply = await this.verification(params);
// try {
// let res;
// switch (params.nextStatus) {
// case "1010": //审核不通过
// res = await this.examine1000(params, _apply);
// break;
// case "1020": //待分配
// res = await this.examine1000(params, _apply);
// break;
// case "1030": //待处理
// res = await this.examine1030(params, _apply);
// break;
// case "1070": //审核通过
// res = await this.examine1070(params, _apply);
// break;
// case "1300": //审核失败
// res = await this.examine1300(params, _apply);
// break;
// case "1090": //已完成
// res = await this.examine1090(params, _apply);
// break;
// default:
// res = system.getResult(null, "action_type参数错误");
// break;
// }
// return res;
// } catch (error) {
// return system.getResult(null, `系统错误 错误信息 ${error}`);
// }
// }
// /**
// * 第一次审核
// * @param {*} params
// * {
// * id: xxx, //发票id
// * isPay:1, //时候付款
// * nextStatus:1020,//发票状态
// * remark:""//发票标注
// * }
// */
// async examine1000(params, _apply) {
// if (Number(params.isPay) != 1) {
// return system.getResult(null, `参数错误 请核对付款信息`);
// }
// params.nextStatus = this.trim(params.nextStatus);
// params.remark = this.trim(params.remark);
// _apply.status = params.nextStatus;
// _apply.remark = params.remark;
// _apply.isPay = Number(params.isPay);
// if (params.nextStatus == "1010") {
// _apply.customerStatus = "1010";
// }
// try {
// let res = await _apply.save();
// if (_apply.parentId && params.nextStatus == "1010") {
// await this.invoiceDao.update({ id: _apply.parentId, redStatus: '3' });
// }
// return system.getResultSuccess();
// } catch (error) {
// return system.getResult(null, `系统错误 错误信息 ${error}`);
// }
// }
// /**
// * 待处理 (当前状态待分配或者是审核为通过)
// * @param {*} params
// * {
// * id: xxx, //发票id
// * delivererId:1, //交付商
// * nextStatus:examine1020,//发票状态
// * delivererName:""//交付商名称
// * delivererAmount:"" //分成
// * }
// */
// async examine1030(params, _apply) {
// if (!params.id || !params.delivererName) {
// return system.getResult(null, `系统错误 错误信息 ${error}`);
// }
// await this.db.transaction(async (t) => {
// let _deliverer = await this.delivererDao.create({
// invoiceId: _apply.id,
// applyNo: _apply.applyNo,
// merchantId: _apply.merchantId,
// delivererId: this.trim(params.delivererId),
// delivererName: this.trim(params.delivererName),
// delivererAmount: Number(this.trim(params.delivererAmount))
// }, t);
// let applyData = {};
// applyData.status = this.trim(params.nextStatus);
// applyData.customerStatus = this.trim(params.nextStatus);
// applyData.delivererId = this.trim(_deliverer.id);
// applyData.id = this.trim(params.id);
// //更新申请发票内容
// await this.dao.update(applyData, t);
// //更改发票状态
// let invoiceData = {};
// invoiceData.status = this.trim(params.nextStatus);
// invoiceData.id = this.trim(params.id);
// await this.invoiceDao.update(invoiceData, t);
// }).catch(error => {
// return system.getResult(null, `系统错误 错误信息 ${error}`);
// });
// return system.getResultSuccess();
// }
// /**
// * 第二次审核
// * @param {*} params
// * {
// * id: xxx, //发票id
// * auditContent:1, //审核备注
// * nextStatus:1070,//发票状态
// * delivererContent:""//发票内容
// * mailAddr:"", //邮寄地址
// * mailMobile:"", //邮寄电话
// * mailTo:"", //邮寄人
// * }
// */
// async examine1070(params, _apply) {
// let delivererData = {},
// applyData = {},
// invoiceData = {};
// let _deliverer = await this.delivererDao.findOne({
// id: _apply.delivererId
// });
// delivererData.auditContent = this.trim(params.auditContent);
// delivererData.delivererContent = this.trim(params.delivererContent);
// delivererData.mailAddr = this.trim(params.mailAddr);
// delivererData.mailMobile = this.trim(params.mailMobile);
// delivererData.mailTo = this.trim(params.mailTo);
// delivererData.mailEmail = this.trim(params.mailEmail);
// delivererData.id = this.trim(_deliverer.id);
// applyData.status = this.trim(params.nextStatus);
// applyData.id = this.trim(params.id);
// invoiceData.status = this.trim(params.nextStatus);
// invoiceData.id = this.trim(params.id);
// await this.db.transaction(async (t) => {
// //更新deliverer信息
// await this.delivererDao.update(delivererData, t);
// //更新 申请单和发票单
// await this.dao.update(applyData, t);
// await this.invoiceDao.update(invoiceData, t);
// if (_apply.parentId) {
// await this.invoiceDao.update({ id: _apply.parentId, redStatus: '4' }, t);
// }
// }).catch(error => {
// return system.getResult(null, `系统错误 错误信息 ${error}`);
// });
// return system.getResultSuccess();
// }
// /**
// * 第二次审核失败
// * @param {*} params
// */
// async examine1300(params) {
// let _apply = await this.dao.findOne({
// id: this.trim(params.id)
// });
// if (!_apply) {
// return system.getResult(null, `发票不存在,请核对发票ID`);
// }
// let _deliverer = await this.delivererDao.model.findOne({
// where: {
// id: _apply.delivererId
// }
// });
// if (!_deliverer) {
// return system.getResult(null, `交付商不存在,请联系管理员`);
// }
// await this.db.transaction(async (t) => {
// //更新 申请单和发票单
// await this.dao.update({
// status: "1300",
// id: _apply.id
// }, t);
// await this.invoiceDao.update({
// status: "1300",
// id: _apply.id
// }, t);
// if (_deliverer.id) {
// //提交审核信息
// await this.delivererDao.update({
// auditContent: this.trim(auditContent),
// id: _deliverer.id
// });
// }
// }).catch(error => {
// return system.getResult(null, `系统错误 错误信息 ${error}`);
// });
// return system.getResultSuccess();
// }
// /**
// * 平台更新 已完成状态
// * @param {*} params
// * @param {*} _apply
// */
// async examine1090(params, _apply) {
// let applyData = {};
// applyData.status = this.trim(params.nextStatus);
// applyData.customerStatus = this.trim(params.nextStatus);
// applyData.id = this.trim(params.id);
// // invoiceData.status = this.trim(params.nextStatus);
// // invoiceData.id=this.trim(params.id);
// await this.db.transaction(async (t) => {
// //更新 申请单和发票单
// await this.dao.update(applyData, t);
// // await this.invoiceDao.update(invoiceData,t);
// }).catch(error => {
// return system.getResult(null, `系统错误 错误信息 ${error}`);
// });
// return system.getResultSuccess();
// }
// /**
// * 检查状态是否正确
// * @param {*} params
// * {
// * id:xxx //发票id
// * nextStatus:xxx //发票状态
// * }
// */
// async verification(params) {
// let _apply = await this.dao.findOne({
// id: this.trim(params.id)
// });
// if (!_apply) {
// return system.getResult(null, `此发票不存在`);
// }
// //获取当前状态 的对象
// let _status = this.invoiceStatus[_apply.status];
// //如果不符合状态则退出
// if (params.nextStatus == "1300" || params.nextStatus == "1040" || params.nextStatus == "1010") {
// return _apply;
// }
// if (!_status && _status.next != params.nextStatus) {
// let name = this.invoiceStatus[this.invoiceStatus[_apply.status].next].name;
// return system.getResult(null, `更新状态错误,提示:当前状态的下一个状态是 ${name}`);
// }
// return _apply;
// }
// /**
// * 发票申请列表查询(平台)
// * @param {*} params
// * @param applyNo 发票的申请编号
// * @param invoiceTime 发票的申请时间
// * @param type 发票的类型
// * @param status 业务进度
// */
// async queryApplyInvoices(params) {
// let where = {};
// if (this.trim(params.applyNo)) {
// where.applyNo = this.trim(params.applyNo);
// }
// if (this.trim(params.businessmenCreditCode)) {
// where.businessmenCreditCode = this.trim(params.businessmenCreditCode);
// }
// if (this.trim(params.invoiceTime)) {
// where.invoiceTime = {
// [this.db.Op.gte]: this.trim(params.invoiceTime)
// }
// }
// if (this.trim(params.type)) {
// where.type = this.trim(params.type);
// }
// if (this.trim(params.status)) {
// where.status = this.trim(params.status);
// }
// let pageIndex = params.pageIndex || 1;
// let pageSize = params.pageSize || 10;
// let orderObj = [
// // ['updatedAt', 'desc'],
// ['id', 'desc']
// ];
// try {
// let _apply = await this.dao.getPageList(pageIndex, pageSize, where, orderObj, null, null);
// for (let item of _apply.rows) {
// let _deliverer = await this.delivererDao.model.findOne({
// // where: {
// // delivererId: item.delivererId
// // },
// attributes: ['delivererName']
// });
// if (_deliverer) {
// item.delivererName = _deliverer.delivererName;
// } else {
// item.delivererName = "";
// }
// if (item.type == "10") {
// item.type = "普通发票";
// } else if (item.type == "20") {
// item.type = "增值税专用发票";
// } else if (item.type == "30") {
// item.type = "电子发票";
// } else {
// item.type = "";
// }
// let _invoice = await this.invoiceDao.model.findOne({
// where: {
// id: item.id
// },
// attributes: ['status', 'invoiceImg']
// });
// if (_invoice.status) {
// this.dao.setRowCodeName(_invoice, "status");
// } else {
// _invoice.status = "";
// }
// item.invoiceImg = this.trim(_invoice.invoiceImg);
// item.delivererStatus = _invoice.statusName;
// //处理时间
// this.handleDate(item, ["invoiceTime"], null, -8);
// this.dao.setRowCodeName(item, "status");
// item.isPay = item.isPay == 1 ? '已付款' : '未付款';
// }
// return system.getResult(_apply);
// } catch (error) {
// return system.getResult(`系统错误 错误信息 ${error}`);
// }
// }
// /**
// * 列举所有日期
// * @param {*} end
// */
// getDays(end) {
// var days = [];
// var month = moment(end).format("YYYY-MM");
// var endDay = Number(moment(end).format("DD"));
// for (var i = 1; i <= endDay; i++) {
// if (i < 10) {
// days.push(month + "-0" + i);
// } else {
// days.push(month + "-" + i);
// }
// }
// return days;
// }
// addStatCount(statusMap, statuses) {
// var count = 0;
// if (!statuses) {
// return count;
// }
// for (var status of statuses) {
// count = count + Number(statusMap[status] || 0);
// }
// return count;
// }
// //查询发票状态 只有在状态为 '1000','0090' 或者信息不存在的情况下 验证成功 参考 applySve.verificationByBusinessmenCreditCode接口
// async verificationInvoiceStatus(businessmenType, businessmenId, businessmenCreditCode) {
// try {
// let condition = {
// businessmenType: businessmenType,
// businessmenId: businessmenId,
// status: {
// [this.db.Op.in]: ['1000', '0090']
// }
// };
// if (businessmenCreditCode) {
// condition.businessmenCreditCode = businessmenCreditCode;
// }
// let invoices = await this.dao.model.findAll({
// where: condition,
// attributes: ["id", "status"]
// });
// if (!invoices) { return false; }
// for (let item of invoices) {
// if (!item) { continue; }
// if (item['status'] != "1000" || item['status'] != "0090") {
// return false;
// }
// }
// return true;
// } catch (error) {
// return false;
// }
// }
// /**
// * 累计不含税价
// * @param {*} businessmenId 商户id
// * @param {*} taxIncPriRat 不含税价百分比
// * @param {*} invoiceAmount 发票总额
// * @param {*} type 计算类型 1:个税 2:增值税
// * @param {*} valCalWay 增值税计算类型 1:月 2:季度 3:年
// * @param {*} perCalWay 增值税计算类型 1:月 2:季度 3:年
// * @param {*} invoiceTime 格式 YYYY-MM-DD hh:mm:ss
// */
// async calAccumulatedPriceExcludingTax(businessmenId,businessmenType, businessmenCreditCode, taxIncPriRat, invoiceAmount, type, valCalWay, perCalWay, invoiceTime) {
// try {
// let now = moment(invoiceTime),startTime, attribute;
// if (type === 1) { //个税
// attribute = `invoiceAmount`;
// if (perCalWay === 3) { //按照年
// startTime = `${now.get('year')}-01-01 00:00:00`;
// } else if (perCalWay === 2) { //按照季度
// let quarter = now.quarter();
// if (1 == quarter) { //第一季度
// startTime = `${now.get('year')}-01-01 00:00:00`;
// } else if (2 == quarter) {
// startTime = `${now.get('year')}-04-01 00:00:00`;
// } else if (3 == quarter) {
// startTime = `${now.get('year')}-07-01 00:00:00`;
// } else {
// startTime = `${now.get('year')}-10-01 00:00:00`;
// }
// } else { //按照月
// let _month = now.month() < 10 ? "0" + now.month() : now.month();
// startTime = `${now.get('year')}-${_month}-01 00:00:00`;
// }
// } else {
// attribute = `valueAddedTax`;
// if (valCalWay === 1) { //月
// startTime = `${now.get('year')}-${now.month()}-01 00:00:00`;
// } else if (valCalWay === 2) { //季度
// let quarter = now.quarter();
// if (1 == quarter) { //第一季度
// startTime = `${now.get('year')}-01-01 00:00:00`;
// } else if (2 == quarter) {
// startTime = `${now.get('year')}-04-01 00:00:00`;
// } else if (3 == quarter) {
// startTime = `${now.get('year')}-07-01 00:00:00`;
// } else {
// startTime = `${now.get('year')}-10-01 00:00:00`;
// }
// } else { //年
// startTime = `${now.get('year')}-01-01 00:00:00`;
// }
// }
// console.log("本年度开始的时间:" + startTime + " 至今:" + now.format("YYYY-MM-DD hh:mm:ss"));
// let condition = {
// businessmenId: businessmenId,
// businessmenType:businessmenType,
// status: {
// [this.db.Op.in]: ['1020', '1030', '1040', '1050', '1060', '1070', '1080', '1090', '1100', '1200', '1300']
// },
// invoiceTime: {
// [this.db.Op.between]: [startTime, now.format("YYYY-MM-DD hh:mm:ss")],
// }
// };
// if(businessmenCreditCode){
// condition.businessmenCreditCode=businessmenCreditCode;
// }
// let beforeAmount = await this.dao.model.sum(attribute, {
// where: condition
// });
// beforeAmount = isNaN(beforeAmount) ? 0 : beforeAmount;
// let res = new Decimal(invoiceAmount).plus(beforeAmount).div(Decimal.add(1, taxIncPriRat)).toFixed(2);
// console.log("当前累计金额 :" + res);
// return res;
// } catch (error) {
// console.log(error);
// return system.getResult(-1,`系统错误 错误信息 ${error}`);
// }
// }
// /**
// * 计算累计税值
// * @param {*} businessmenId
// * @param {*} type 计算类型 1:个税 2:增值税
// * @param {*} valCalWay 增值税计算类型 1:月 2:季度
// *
// */
// async calCumulativeProfit(businessmenId,businessmenType, type, valCalWay) {
// let now = moment(),
// startTime, attribute;
// if (type == 1) {
// attribute = `personalIncomeTax`;
// startTime = `${now.get('year')}-01-01 00:00:00`;
// } else {
// attribute = `valueAddedTax`;
// if (valCalWay === 1) { //月
// startTime = `${now.get('year')}-${now.month()}-01 00:00:00`;
// } else { //季度
// let quarter = now.quarter();
// if (1 == quarter) { //第一季度
// startTime = `${now.get('year')}-01-01 00:00:00`;
// } else if (2 == quarter) {
// startTime = `${now.get('year')}-04-01 00:00:00`;
// } else if (3 == quarter) {
// startTime = `${now.get('year')}-07-01 00:00:00`;
// } else {
// startTime = `${now.get('year')}-10-01 00:00:00`;
// }
// }
// }
// console.log("本年度开始的时间:" + startTime + " 至今:" + now.format("YYYY-MM-DD hh:mm:ss"));
// let cumulativeProfit = await this.dao.model.sum(attribute, {
// where: {
// businessmenId: businessmenId,
// businessmenType: businessmenType,
// status: this.invoiceStatus.auditPass,
// invoiceTime: {
// [this.db.Op.between]: [startTime, now.format("YYYY-MM-DD hh:mm:ss")],
// }
// }
// });
// return cumulativeProfit || 0;
// }
// }
// module.exports = ApplyService;
\ No newline at end of file
xggsve-invoice/app/base/service/impl/invoice/iinvoiceSve.js
View file @
607e3516
...
...
@@ -4,15 +4,21 @@ const moment = require('moment')
/**
* 交付商 提交的信息
*/
class
I
i
nvoiceService
extends
ServiceBase
{
class
I
I
nvoiceService
extends
ServiceBase
{
constructor
()
{
super
(
"invoice"
,
ServiceBase
.
getDaoName
(
IinvoiceService
));
super
(
"invoice"
,
ServiceBase
.
getDaoName
(
IInvoiceService
));
let
is
=
system
.
getObject
(
"util.invoiceStatus"
);
this
.
invoiceStatus
=
is
.
status
;
this
.
iinvoicesummaryinfoDao
=
system
.
getObject
(
"db.invoice.iinvoicesummaryinfoDao"
);
this
.
iinvoiceprocessDao
=
system
.
getObject
(
"db.invoice.iinvoiceprocessDao"
);
this
.
iinvoiceinforegDao
=
system
.
getObject
(
"db.invoice.iinvoiceinforegDao"
);
this
.
iinvoicedeliverDao
=
system
.
getObject
(
"db.invoice.iinvoicedeliverDao"
);
this
.
RULE_INVOICE_TYPE
=
[
"10"
,
'20'
,
'30'
];
//发票类型
this
.
RULE_BUSINESSMEN_TYPE
=
[
'10'
,
'20'
];
//销售方类型
this
.
iproductDao
=
system
.
getObject
(
"db.product.iproductDao"
);
this
.
iprocessDao
=
system
.
getObject
(
"db.product.iprocessDao"
);
this
.
iproductprocessDao
=
system
.
getObject
(
"db.product.iproductprocessDao"
);
}
/**
...
...
@@ -129,57 +135,56 @@ class IinvoiceService extends ServiceBase {
}
}
/**********************************************以下是旧版本************************************************************
/*
* 构建产品流程对象
* @param productPid
* @param chooseProductIds
* @returns {Promise<void>}
*/
// async buildOrderProcess(productPid
) {
// let productPid =
productPid || 50010000;
//
// 查询产品流程
// let productProcessList = await this.o
productprocessDao.byProductPid(productPid);
//
if (!productProcessList || productProcessList.length == 0) {
// continue
;
//
}
async
buildProcess
(
params
)
{
let
productPid
=
params
.
productPid
||
50010000
;
// 查询产品流程
let
productProcessList
=
await
this
.
i
productprocessDao
.
byProductPid
(
productPid
);
if
(
!
productProcessList
||
productProcessList
.
length
==
0
)
{
return
[]
;
}
//
let invoiceProcessList = [];
//
// 批量查流程
// let processMap = await this.o
processDao.mapAll();
let
invoiceProcessList
=
[];
// 批量查流程
let
processMap
=
await
this
.
i
processDao
.
mapAll
();
//
for (let productProcess of productProcessList) {
//
// 风还钻该处理每一个子项流程 变为 订单流程对象
//
let process = processMap[productProcess.process_id];
//
let nextArr = this.trim(productProcess.next_status).split(",");
//
let nextStatus = [];
// for (var
nextId of nextArr) {
//
nextId = Number(nextId || 0);
//
let nextObj = processMap[nextId];
//
if (!nextObj) {
//
continue;
//
}
//
nextStatus.push({ next_status: nextObj.status, next_name: nextObj.name });
//
}
for
(
let
productProcess
of
productProcessList
)
{
// 风还钻该处理每一个子项流程 变为 订单流程对象
let
process
=
processMap
[
productProcess
.
process_id
];
let
nextArr
=
this
.
trim
(
productProcess
.
next_status
).
split
(
","
);
let
nextStatus
=
[];
for
(
let
nextId
of
nextArr
)
{
nextId
=
Number
(
nextId
||
0
);
let
nextObj
=
processMap
[
nextId
];
if
(
!
nextObj
)
{
continue
;
}
nextStatus
.
push
({
next_status
:
nextObj
.
status
,
next_name
:
nextObj
.
name
});
}
//
let orderProcess = {
//
product_id: productPid,
//
name: process.name,
//
status: process.status,
//
func: productProcess.func,
//
next_status: JSON.stringify(nextStatus),
//
name1: productProcess.name1,
//
name2: productProcess.name2,
//
name3: productProcess.name3,
//
name4: productProcess.name4,
//
sort: productProcess.sort,
//
autoIncrement: true
//
};
//
invoiceProcessList.push(orderProcess);
//
}
let
orderProcess
=
{
product_id
:
productPid
,
name
:
process
.
name
,
status
:
process
.
status
,
func
:
productProcess
.
func
,
next_status
:
JSON
.
stringify
(
nextStatus
),
name1
:
productProcess
.
name1
,
name2
:
productProcess
.
name2
,
name3
:
productProcess
.
name3
,
name4
:
productProcess
.
name4
,
sort
:
productProcess
.
sort
,
autoIncrement
:
true
};
invoiceProcessList
.
push
(
orderProcess
);
}
//
return invoiceProcessList;
//
}
return
invoiceProcessList
;
}
}
module
.
exports
=
IinvoiceService
;
\ No newline at end of file
module
.
exports
=
IInvoiceService
;
xggsve-invoice/app/base/service/impl/invoice/iinvoiceSvebak.js
View file @
607e3516
const
ServiceBase
=
require
(
"../../sve.base"
);
const
system
=
require
(
"../../../system"
);
const
moment
=
require
(
'moment'
)
/**
* 交付商 提交的信息
*/
class
InvoiceService
extends
ServiceBase
{
constructor
()
{
super
(
"invoice"
,
ServiceBase
.
getDaoName
(
InvoiceService
));
let
is
=
system
.
getObject
(
"util.invoiceStatus"
);
this
.
invoiceStatus
=
is
.
status
;
//
const ServiceBase = require("../../sve.base");
//
const system = require("../../../system");
//
const moment = require('moment')
/
/ /
**
//
* 交付商 提交的信息
//
*/
//
class InvoiceService extends ServiceBase {
//
constructor() {
//
super("invoice", ServiceBase.getDaoName(InvoiceService));
//
let is = system.getObject("util.invoiceStatus");
//
this.invoiceStatus = is.status;
this
.
applyDao
=
system
.
getObject
(
"db.invoice.applyDao"
);
this
.
delivererDao
=
system
.
getObject
(
"db.invoice.delivererDao"
);
}
//
this.applyDao = system.getObject("db.invoice.applyDao");
//
this.delivererDao = system.getObject("db.invoice.delivererDao");
//
}
/**
* 完税证明
* @param {*} params
*/
async
apiTxPayment
(
params
)
{
if
(
!
params
.
id
)
{
return
system
.
getResult
(
null
,
`参数错误 发票ID不合法`
);
}
try
{
let
res
=
await
this
.
txPayment
(
params
);
return
res
;
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`参数错误 错误信息
${
error
}
`
);
}
}
//
/**
//
* 完税证明
//
* @param {*} params
//
*/
//
async apiTxPayment(params) {
//
if (!params.id) {
//
return system.getResult(null, `参数错误 发票ID不合法`);
//
}
//
try {
//
let res = await this.txPayment(params);
//
return res;
//
} catch (error) {
//
return system.getResult(null, `参数错误 错误信息 ${error}`);
//
}
//
}
/**
* 查看完税证明
* @param {*} params
*/
async
apiQueryTxPayment
(
params
)
{
if
(
!
params
.
id
)
{
return
system
.
getResult
(
null
,
`参数错误 发票ID不合法`
);
}
try
{
return
await
this
.
queryTxPayment
(
params
);
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`参数错误 错误信息
${
error
}
`
);
}
}
//
/**
//
* 查看完税证明
//
* @param {*} params
//
*/
//
async apiQueryTxPayment(params) {
//
if (!params.id) {
//
return system.getResult(null, `参数错误 发票ID不合法`);
//
}
//
try {
//
return await this.queryTxPayment(params);
//
} catch (error) {
//
return system.getResult(null, `参数错误 错误信息 ${error}`);
//
}
//
}
/**
* 发票列表(平台)
* @param {*} params
*/
async
apiQueryInvoices
(
params
)
{
try
{
if
(
params
.
applyNo
){
params
.
applyNo
=
this
.
trim
(
params
.
applyNo
)}
if
(
params
.
type
){
params
.
type
=
this
.
trim
(
params
.
type
);}
if
(
params
.
invoiceTime
){
params
.
invoiceTime
=
this
.
trim
(
params
.
invoiceTime
);}
return
await
this
.
queryInvoices
(
params
);
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
//
/**
//
* 发票列表(平台)
//
* @param {*} params
//
*/
//
async apiQueryInvoices(params) {
//
try {
//
if(params.applyNo){params.applyNo=this.trim(params.applyNo)}
//
if(params.type){params.type=this.trim(params.type);}
//
if(params.invoiceTime){params.invoiceTime=this.trim(params.invoiceTime);}
//
return await this.queryInvoices(params);
//
} catch (error) {
//
return system.getResult(null, `系统错误 错误信息 ${error}`);
//
}
//
}
/**
* 发票红冲列表
* @param {*} params
*/
async
apiRedRushList
(
params
)
{
try
{
if
(
params
){}
let
res
=
await
this
.
redRushList
(
params
);
return
res
;
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`参数错误 错误信息
${
error
}
`
);
}
}
//
/**
//
* 发票红冲列表
//
* @param {*} params
//
*/
//
async apiRedRushList(params) {
//
try {
//
if(params){}
//
let res = await this.redRushList(params);
//
return res;
//
} catch (error) {
//
return system.getResult(null, `参数错误 错误信息 ${error}`);
//
}
//
}
//==============================================================
//
//==============================================================
/**
* 红冲列表
* @param {*} params
*/
async
redRushList
(
params
){
try
{
if
(
params
.
delivererId
)
{
params
.
delivererId
=
this
.
trim
(
params
.
delivererId
);
}
if
(
this
.
trim
(
params
.
applyNo
))
{
params
.
applyNo
=
this
.
trim
(
params
.
applyNo
);
}
if
(
this
.
trim
(
params
.
invoiceNo
))
{
params
.
invoiceNo
=
this
.
trim
(
params
.
invoiceNo
);
}
if
(
this
.
trim
(
params
.
invoiceTime
))
{
params
.
invoiceTime
=
this
.
trim
(
params
.
invoiceTime
);
}
if
(
this
.
trim
(
params
.
startTime
))
{
params
.
startTime
=
this
.
trim
(
params
.
startTime
);
}
if
(
this
.
trim
(
params
.
endTime
))
{
params
.
endTime
=
this
.
trim
(
params
.
endTime
);
}
if
(
this
.
trim
(
params
.
type
))
{
params
.
type
=
this
.
trim
(
params
.
type
);
}
if
(
this
.
trim
(
params
.
status
))
{
params
.
status
=
this
.
trim
(
params
.
status
);
}
if
(
this
.
trim
(
params
.
redStatus
))
{
params
.
redStatus
=
this
.
trim
(
params
.
redStatus
);
}
//
/**
//
* 红冲列表
//
* @param {*} params
//
*/
//
async redRushList(params){
//
try {
//
if (params.delivererId) {
//
params.delivererId=this.trim(params.delivererId);
//
}
//
if (this.trim(params.applyNo)) {
//
params.applyNo=this.trim(params.applyNo);
//
}
//
if (this.trim(params.invoiceNo)) {
//
params.invoiceNo=this.trim(params.invoiceNo);
//
}
//
if (this.trim(params.invoiceTime)) {
//
params.invoiceTime=this.trim(params.invoiceTime);
//
}
//
if (this.trim(params.startTime)) {
//
params.startTime=this.trim(params.startTime);
//
}
//
if (this.trim(params.endTime)) {
//
params.endTime=this.trim(params.endTime);
//
}
//
if (this.trim(params.type)) {
//
params.type=this.trim(params.type);
//
}
//
if (this.trim(params.status)) {
//
params.status=this.trim(params.status);
//
}
//
if (this.trim(params.redStatus)) {
//
params.redStatus=this.trim(params.redStatus);
//
}
params
.
statRow
=
(
Number
(
this
.
trim
(
params
.
pageIndex
))
-
1
)
*
Number
(
this
.
trim
(
params
.
pageSize
));
if
(
params
.
statRow
<=
0
)
{
params
.
statRow
=
0
;
}
params
.
pageSize
=
Number
(
this
.
trim
(
params
.
pageSize
))
<=
0
?
10
:
Number
(
this
.
trim
(
params
.
pageSize
));
//
params.statRow = (Number(this.trim(params.pageIndex)) - 1) * Number(this.trim(params.pageSize));
//
if (params.statRow <= 0) { params.statRow = 0; }
//
params.pageSize = Number(this.trim(params.pageSize)) <= 0 ? 10 : Number(this.trim(params.pageSize));
let
total
=
await
this
.
dao
.
countRedRushListByParams
(
params
);
if
(
total
==
0
||
total
[
0
].
count
==
0
)
{
let
res
=
{
rows
:
[],
count
:
0
};
return
system
.
getResult
(
res
);
}
//
let total = await this.dao.countRedRushListByParams(params);
//
if (total == 0 || total[0].count == 0) {
//
let res = { rows: [], count: 0 };
//
return system.getResult(res);
//
}
let
rows
=
await
this
.
dao
.
redRushListByParams
(
params
);
for
(
let
item
of
rows
)
{
if
(
item
.
type
==
"10"
)
{
item
.
type
=
"普通发票"
;
}
else
if
(
item
.
type
==
"20"
)
{
item
.
type
=
"增值税专用发票"
;
}
else
if
(
item
.
type
==
"30"
)
{
item
.
type
=
"电子发票"
;
}
else
{
item
.
type
=
""
;
}
this
.
handleDate
(
item
,
[
"invoice_time"
],
"YYYY-MM-DD HH:mm:ss"
,
-
8
);
this
.
dao
.
setRowCodeName
(
item
,
"status"
);
}
//
let rows = await this.dao.redRushListByParams(params);
//
for (let item of rows) {
//
if (item.type == "10") {
//
item.type = "普通发票";
//
} else if (item.type == "20") {
//
item.type = "增值税专用发票";
//
} else if (item.type == "30") {
//
item.type = "电子发票";
//
} else {
//
item.type = "";
//
}
//
this.handleDate(item, ["invoice_time"], "YYYY-MM-DD HH:mm:ss", -8);
//
this.dao.setRowCodeName(item, "status");
//
}
let
res
=
{
count
:
total
[
0
].
count
,
rows
:
rows
};
return
system
.
getResult
(
res
);
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
//
let res = { count: total[0].count, rows: rows };
//
return system.getResult(res);
//
} catch (error) {
//
return system.getResult(null, `系统错误 错误信息 ${error}`);
//
}
//
}
/**
* 完税证明
* @param {*} params
* {
* id:xxx //完税证明
* }
*/
async
txPayment
(
params
)
{
try
{
let
_invoice
=
await
this
.
dao
.
findOne
({
id
:
this
.
trim
(
params
.
id
)
});
if
(
!
_invoice
)
{
return
system
.
getResult
(
null
,
`发票不存在`
);
}
let
res
=
await
this
.
dao
.
update
({
id
:
this
.
trim
(
params
.
id
),
taxNo
:
this
.
trim
(
params
.
taxNo
),
complateTax
:
1
,
taxTime
:
this
.
trim
(
params
.
taxTime
),
taxVoucher
:
this
.
trim
(
params
.
taxVoucher
)
});
return
system
.
getResult
(
res
);
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`参数错误 错误信息
${
error
}
`
);
}
}
//
/**
//
* 完税证明
//
* @param {*} params
//
* {
//
* id:xxx //完税证明
//
* }
//
*/
//
async txPayment(params) {
//
try {
//
let _invoice = await this.dao.findOne({
//
id: this.trim(params.id)
//
});
//
if (!_invoice) {
//
return system.getResult(null, `发票不存在`);
//
}
//
let res = await this.dao.update({
//
id: this.trim(params.id),
//
taxNo: this.trim(params.taxNo),
//
complateTax: 1,
//
taxTime: this.trim(params.taxTime),
//
taxVoucher: this.trim(params.taxVoucher)
//
});
//
return system.getResult(res);
//
} catch (error) {
//
return system.getResult(null, `参数错误 错误信息 ${error}`);
//
}
//
}
/**
* 查看完税证明
* @param {*} params
* {
* id:xxx //完税证明
* }
*/
async
queryTxPayment
(
params
)
{
try
{
let
_invoice
=
await
this
.
dao
.
model
.
findOne
({
where
:
{
id
:
this
.
trim
(
params
.
id
),
complateTax
:
1
},
attributes
:
[
'id'
,
'taxNo'
,
'complateTax'
,
'taxTime'
,
'taxVoucher'
]
});
if
(
!
_invoice
)
{
return
system
.
getResult
(
null
,
`完税证明不存在`
);
}
return
system
.
getResult
(
_invoice
);
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`参数错误 错误信息
${
error
}
`
);
}
}
//
/**
//
* 查看完税证明
//
* @param {*} params
//
* {
//
* id:xxx //完税证明
//
* }
//
*/
//
async queryTxPayment(params) {
//
try {
//
let _invoice = await this.dao.model.findOne({
//
where: {
//
id: this.trim(params.id),
//
complateTax: 1
//
},
//
attributes: ['id', 'taxNo', 'complateTax', 'taxTime', 'taxVoucher']
//
});
//
if (!_invoice) {
//
return system.getResult(null, `完税证明不存在`);
//
}
//
return system.getResult(_invoice);
//
} catch (error) {
//
return system.getResult(null, `参数错误 错误信息 ${error}`);
//
}
//
}
/**
* 发票列表查询(平台)
* @param {*} params
* @param applyNo 发票的申请编号
* @param invoiceTime 发票的申请时间
* @param type 发票的类型
* @param status 业务进度
*/
async
queryInvoices
(
params
)
{
try
{
//
/**
//
* 发票列表查询(平台)
//
* @param {*} params
//
* @param applyNo 发票的申请编号
//
* @param invoiceTime 发票的申请时间
//
* @param type 发票的类型
//
* @param status 业务进度
//
*/
//
async queryInvoices(params) {
//
try {
var
pageIndex
=
Number
(
params
.
pageIndex
||
1
);
var
pageSize
=
Number
(
params
.
pageSize
||
10
);
//
var pageIndex = Number(params.pageIndex || 1);
//
var pageSize = Number(params.pageSize || 10);
var
total
=
await
this
.
dao
.
countByParams
(
params
);
if
(
total
==
0
)
{
return
system
.
getResultSuccess
({
count
:
0
,
rows
:
[]
});
}
//
var total = await this.dao.countByParams(params);
//
if (total == 0) {
//
return system.getResultSuccess({
//
count: 0,
//
rows: []
//
});
//
}
var
startRow
=
(
pageIndex
-
1
)
*
pageSize
;
//
var startRow = (pageIndex - 1) * pageSize;
var
list
=
await
this
.
dao
.
pageByParams
(
params
,
startRow
,
pageSize
);
//
var list = await this.dao.pageByParams(params, startRow, pageSize);
await
this
.
setApply
(
list
);
for
(
var
item
of
list
)
{
// item.redStatusName = this.dao.getRowCodeName(item, "red_status");
//
await this.setApply(list);
//
for (var item of list) {
//
// item.redStatusName = this.dao.getRowCodeName(item, "red_status");
if
(
item
.
red_status
==
1
)
{
item
.
red_status
=
'未红冲'
;
}
else
if
(
item
.
red_status
==
2
)
{
item
.
red_status
=
'红冲中'
;
}
else
if
(
item
.
red_status
==
3
)
{
item
.
red_status
=
'红冲失败'
}
else
if
(
item
.
red_status
==
4
)
{
item
.
red_status
=
'红冲成功'
;
}
else
{
item
.
red_status
=
''
;
}
this
.
dao
.
getRowCodeName
(
item
.
apply
,
"status"
);
item
.
complate_tax
=
item
.
complate_tax
==
1
?
'已完税'
:
'未完税'
;
item
.
month
=
moment
(
item
.
invoice_time
).
month
()
+
1
;
this
.
handleDate
(
item
,[
'invoice_time'
],
null
,
-
8
);
if
(
item
.
apply
[
'type'
]
==
'10'
)
{
item
.
apply
[
'type'
]
=
"普通发票"
;
}
else
if
(
item
.
apply
[
'type'
]
==
'20'
)
{
item
.
apply
[
'type'
]
=
"增值税专用发票"
;
}
else
{
item
.
apply
[
'type'
]
=
"电子发票"
;
}
}
var
page
=
{
count
:
total
,
rows
:
list
};
return
system
.
getResultSuccess
(
page
);
}
catch
(
error
)
{
console
.
log
(
error
);
return
system
.
getResult
(
`系统错误 错误信息
${
error
}
`
);
}
}
//
if (item.red_status == 1) {
//
item.red_status = '未红冲';
//
} else if (item.red_status == 2) {
//
item.red_status = '红冲中';
//
} else if (item.red_status == 3) {
//
item.red_status = '红冲失败'
//
} else if (item.red_status == 4) {
//
item.red_status = '红冲成功';
//
} else {
//
item.red_status = '';
//
}
//
this.dao.getRowCodeName(item.apply,"status");
//
item.complate_tax = item.complate_tax == 1 ? '已完税' : '未完税';
//
item.month = moment(item.invoice_time).month() + 1;
//
this.handleDate(item,['invoice_time'],null,-8);
//
if (item.apply['type'] == '10') {
//
item.apply['type'] = "普通发票";
//
} else if (item.apply['type'] == '20') {
//
item.apply['type'] = "增值税专用发票";
//
} else {
//
item.apply['type'] = "电子发票";
//
}
//
}
//
var page = {
//
count: total,
//
rows: list
//
};
//
return system.getResultSuccess(page);
//
} catch (error) {
//
console.log(error);
//
return system.getResult(`系统错误 错误信息 ${error}`);
//
}
//
}
async
setApply
(
list
)
{
if
(
!
list
||
list
.
length
==
0
)
{
return
;
}
//
async setApply(list) {
//
if (!list || list.length == 0) {
//
return;
//
}
var
ids
=
[];
for
(
var
item
of
list
)
{
ids
.
push
(
item
.
id
);
}
//
var ids = [];
//
for (var item of list) {
//
ids.push(item.id);
//
}
var
applyMap
=
await
this
.
applyDao
.
findMapByIds
(
ids
)
||
{};
for
(
var
item
of
list
)
{
item
.
apply
=
applyMap
[
item
.
id
]
||
{};
}
}
//
var applyMap = await this.applyDao.findMapByIds(ids) || {};
//
for (var item of list) {
//
item.apply = applyMap[item.id] || {};
//
}
//
}
}
module
.
exports
=
InvoiceService
;
\ No newline at end of file
// }
// module.exports = InvoiceService;
\ No newline at end of file
xggsve-invoice/app/base/service/impl/invoice/iinvoicedeliverSve.js
View file @
607e3516
...
...
@@ -7,844 +7,6 @@ const moment = require('moment');
class
IinvoicedelivererService
extends
ServiceBase
{
constructor
()
{
super
(
"invoice"
,
ServiceBase
.
getDaoName
(
DelivererService
));
this
.
invoiceDao
=
system
.
getObject
(
"db.invoice.invoiceDao"
);
let
is
=
system
.
getObject
(
"util.invoiceStatus"
);
this
.
invoiceStatus
=
is
.
status
;
}
/**
* 平台业务分配
* @param {*} params
*/
async
apiAssignment
(
params
)
{
try
{
return
await
this
.
assignment
(
params
);
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
/**
* 产看业务办理
* @param {*} params
* {
* id:xxx 发票id
* }
*/
async
apiQueryProcess
(
params
)
{
try
{
return
await
this
.
queryProcess
(
params
);
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
/**
* 平台更新地址
* @param {*} params
*/
async
apiUpEmNo
(
params
)
{
try
{
if
(
!
params
.
id
)
{
return
system
.
getResult
(
null
,
`参数错误 ID不能为空`
);
}
if
(
!
params
.
platformMailNo
)
{
return
system
.
getResult
(
null
,
`参数错误 邮寄单号不能为空`
);
}
return
await
this
.
updateEmailNo
(
params
);
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
/**
* 申请列表(交付商)
* 注意:当前只有一个交付商,如果有多个交付商,则需要传入id 并且修改当前接口sql
* @param {*} params
*/
async
apiDelivererApplyInvoices
(
params
)
{
try
{
if
(
!
params
.
delivererId
)
{
return
system
.
getResult
(
null
,
`参数错误 ID不能为空`
);
}
return
await
this
.
delivererApplyInvoices
(
params
);
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
/**
* 发票明细(交付商)
* @param {*} params
*/
async
apiQueryInvoiceDeliverer
(
params
)
{
try
{
var
merchantId
=
params
.
merchantId
||
params
.
merchant_id
;
if
((
params
.
merchantId
&&
params
.
applyNo
)
||
params
.
id
)
{
let
res
=
await
this
.
queryInvoiceDeliverer
(
params
.
applyNo
,
merchantId
,
params
.
id
);
return
res
;
}
else
{
return
system
.
getResultSuccess
();
}
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息:
${
error
}
`
);
}
}
/**
* 交付商审批列表
* @param {*} params
*/
async
apiDelInvs
(
params
)
{
try
{
return
await
this
.
delInvs
(
params
);
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
/**
* 交付商业务概览
* @param {*} params
*/
async
apiStatDeliverData
(
params
)
{
try
{
return
await
this
.
statDeliverData
(
params
);
}
catch
(
error
)
{
console
.
log
(
error
);
return
system
.
getResult
(
null
,
"接口异常"
);
}
}
/**
* 交易数据(交付商)
* @param {*} params
*/
async
apiDelStatTransData
(
params
)
{
try
{
if
(
!
params
.
delivererId
){
return
system
.
getResult
(
-
1
,
`交付商ID不能为空`
);
}
return
await
this
.
delStatTransData
(
params
);
}
catch
(
error
)
{
return
system
.
getResult
(
-
1
,
`系统错误 错误信息
${
error
}
`
);
}
}
/**
* 发票办理(交付商)
* @param {*} params
*/
async
apiDelStatBusinessData
(
params
)
{
try
{
if
(
!
params
.
delivererId
){
return
system
.
getResult
(
-
1
,
`交付商ID不能为空`
);
}
return
await
this
.
delStatBusinessData
(
params
);
}
catch
(
error
)
{
console
.
log
(
error
);
return
system
.
getResult
(
null
,
"接口异常"
);
}
}
//=========================================================================================//
/**
* 发票办理(交付商)
* @param {*} params
*/
async
delStatBusinessData
(
params
)
{
try
{
var
result
=
{};
var
type
=
Number
(
params
.
type
||
1
);
// 查 已完成订单,待分配订单,待审核订单,办理中订单
var
begin
,
end
,
delivererId
=
params
.
delivererId
;
// 取开始时间
if
(
type
==
1
)
{
//本月
begin
=
moment
().
format
(
"YYYY-MM"
)
+
"-01 00:00:00"
;
end
=
moment
(
begin
).
add
(
1
,
"months"
).
subtract
(
1
,
'days'
).
format
(
"YYYY-MM-DD"
)
+
" 23:59:59"
;
}
else
if
(
type
==
2
)
{
//上个月
begin
=
moment
().
subtract
(
1
,
"months"
).
format
(
"YYYY-MM"
)
+
"-01 00:00:00"
;
end
=
moment
(
begin
).
add
(
1
,
"months"
).
subtract
(
1
,
'days'
).
format
(
"YYYY-MM-DD"
)
+
" 23:59:59"
;
}
// 先按照订单状态查
let
list
=
await
this
.
dao
.
model
.
findAll
({
include
:[
{
association
:
this
.
dao
.
model
.
belongsTo
(
this
.
applyDao
.
model
,{
foreignKey
:
"invoiceId"
,
targetKey
:
"id"
}),
required
:
true
,
attributes
:[
'status'
],
where
:{
status
:{
[
this
.
db
.
Op
.
in
]:[
'1030'
,
'1040'
,
'1050'
,
'1060'
,
'1300'
]
}
}
}
],
where
:{
delivererId
:
delivererId
,
createdAt
:{
[
this
.
db
.
Op
.
between
]:[
begin
,
end
]
}
},
attributes
:[
'id'
,
'delivererName'
,
'delivererId'
]
});
// 已开具 1050
let
count
=
0
;
for
(
let
item
of
list
){
if
(
item
.
apply
.
status
==
"1050"
){
count
+=
1
;
}
}
result
.
completeCount
=
count
||
0
;
result
.
handlingCount
=
list
.
length
-
count
<=
0
?
0
:
list
.
length
-
count
;
return
system
.
getResultSuccess
(
result
);
}
catch
(
error
)
{
return
system
.
getResult
(
-
1
,
`系统错误 错误信息
${
error
}
`
);
}
}
/**
* 交易数据(交付商)
* @param {*} params
*/
async
delStatTransData
(
params
)
{
try
{
var
result
=
{
invoiceCount
:
0
,
delivererAmount
:
0
,
};
var
type
=
Number
(
params
.
type
||
1
);
var
begin
,
end
,
delivererId
=
params
.
delivererId
;
// 取开始时间
if
(
type
==
1
)
{
begin
=
moment
().
format
(
"YYYY-MM"
)
+
"-01 00:00:00"
;
}
else
if
(
type
==
2
)
{
begin
=
moment
().
subtract
(
1
,
"months"
).
format
(
"YYYY-MM"
)
+
"-01 00:00:00"
;
}
// echart数据
var
days
=
[];
var
dayCounts
=
[];
var
priceCounts
=
[];
// 处理查询业务
if
(
type
==
1
||
type
==
2
)
{
// 取结束时间
end
=
moment
(
begin
).
add
(
1
,
"months"
).
subtract
(
1
,
'days'
).
format
(
"YYYY-MM-DD"
)
+
" 23:59:59"
;
days
=
this
.
getDays
(
end
);
// 按天统计
var
dayMap
=
await
this
.
dao
.
delStatDayByTime
(
begin
,
end
,
delivererId
);
for
(
var
day
of
days
)
{
var
ditem
=
dayMap
[
day
]
||
{};
dayCounts
.
push
(
ditem
.
invoiceCount
||
0
);
priceCounts
.
push
(
system
.
f2y
(
ditem
.
delivererAmount
||
0
));
}
}
else
{
var
monthMap
=
await
this
.
dao
.
delStatMonthByTime
(
begin
,
end
,
delivererId
);
var
bm
=
monthMap
.
begin
||
""
;
var
em
=
monthMap
.
end
||
""
;
if
(
bm
&&
em
)
{
// 开始月份-结束月份所有月份
var
curMonth
=
bm
;
while
(
true
)
{
days
.
push
(
curMonth
);
if
(
curMonth
==
em
)
{
break
;
}
curMonth
=
moment
(
curMonth
+
"-01"
).
add
(
1
,
"month"
).
format
(
"YYYY-MM"
);
}
}
for
(
var
day
of
days
)
{
var
ditem
=
monthMap
[
day
]
||
{};
dayCounts
.
push
(
ditem
.
invoiceCount
||
0
);
priceCounts
.
push
(
system
.
f2y
(
ditem
.
delivererAmount
||
0
));
}
}
var
invoiceApplyData
=
await
this
.
dao
.
delStatInvoiceByTime
(
begin
,
end
,
delivererId
)
||
{};
result
.
invoiceCount
=
invoiceApplyData
.
invoiceCount
;
result
.
delivererAmount
=
system
.
f2y
(
invoiceApplyData
.
delivererAmount
);
result
.
days
=
days
;
result
.
dayCounts
=
dayCounts
;
result
.
priceCounts
=
priceCounts
;
return
system
.
getResultSuccess
(
result
);
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
/**
* 交付商业务概览
* @param {*} params
*/
async
statDeliverData
(
params
)
{
try
{
var
currentPage
=
Number
(
params
.
currentPage
||
1
);
var
pageSize
=
Number
(
params
.
pageSize
||
10
);
// 处理时间
var
type
=
Number
(
params
.
type
||
1
);
var
begin
,
end
;
// 取开始时间
if
(
type
==
1
)
{
begin
=
moment
().
format
(
"YYYY-MM"
)
+
"-01 00:00:00"
;
end
=
moment
(
begin
).
add
(
1
,
"months"
).
subtract
(
1
,
'days'
).
format
(
"YYYY-MM-DD"
)
+
" 23:59:59"
;
}
else
if
(
type
==
2
)
{
begin
=
moment
().
subtract
(
1
,
"months"
).
format
(
"YYYY-MM"
)
+
"-01 00:00:00"
;
end
=
moment
(
begin
).
add
(
1
,
"months"
).
subtract
(
1
,
'days'
).
format
(
"YYYY-MM-DD"
)
+
" 23:59:59"
;
}
var
condition
=
{
begin
:
begin
,
end
:
end
,
}
// 查总数
var
_res
=
await
this
.
dao
.
countStat
(
condition
);
if
(
_res
.
total
==
0
)
{
return
system
.
getResultSuccess
({
count
:
0
,
rows
:
[]
});
}
else
{
let
_str
=
[];
//这个id是交付商的id
for
(
let
item
of
_res
.
list
)
{
_str
.
push
(
`'
${
item
.
deliverer_id
}
'`
);
}
condition
.
list
=
_str
.
join
(
","
);
}
// 查条数
var
startRow
=
(
currentPage
-
1
)
*
pageSize
;
var
list
=
await
this
.
dao
.
queryStat
(
condition
,
startRow
,
pageSize
);
for
(
let
item
of
list
)
{
item
.
totalAmount
=
system
.
f2y
(
item
.
totalAmount
||
0
)
}
//计算每个
// 设置已完成数量、办理中数量
var
delivererIds
=
[];
for
(
var
item
of
list
)
{
//这个是交付商表的主键
delivererIds
.
push
(
item
.
id
);
}
var
dstatusMap
=
await
this
.
dao
.
statDeliverByStatus
({
begin
:
begin
,
end
:
end
,
delivererIds
:
delivererIds
});
for
(
var
item
of
list
)
{
item
.
completeCount
=
this
.
addStatCount
(
dstatusMap
,
item
.
id
,
[
'1080'
,
"1090"
]);
item
.
handlingCount
=
this
.
addStatCount
(
dstatusMap
,
item
.
id
,
[
'1030'
,
'1040'
,
'1050'
,
'1060'
,
'1300'
]);
}
return
system
.
getResultSuccess
({
count
:
_res
.
total
,
rows
:
list
});
}
catch
(
error
)
{
system
.
getResult
(
-
1
,
`系统错误 错误信息
${
error
}
`
);
}
}
addStatCount
(
statusMap
,
deliverer_id
,
statuses
)
{
var
count
=
0
;
if
(
!
statuses
||
statuses
.
length
==
0
)
{
return
count
;
}
for
(
var
status
of
statuses
)
{
count
=
count
+
Number
(
statusMap
[
deliverer_id
+
"_"
+
status
]
||
0
);
}
return
count
;
}
/**
* 发票业务分配
* @param {*} params
* {
* applyNo:"" //发票编号
* nextStatus:"" //发票状态
* }
*/
async
assignment
(
params
)
{
let
obj
=
await
this
.
verification
(
params
);
let
_apply
=
obj
.
_apply
;
let
_invoice
=
obj
.
_invoice
;
try
{
let
res
;
switch
(
params
.
nextStatus
)
{
case
"1040"
:
//交付商以关闭
res
=
await
this
.
examine1040
(
params
,
_apply
,
_invoice
);
break
;
case
"1050"
:
//已开具
res
=
await
this
.
examine1050
(
params
,
_apply
,
_invoice
);
break
;
case
"1060"
:
//待审核
res
=
await
this
.
examine1060
(
params
,
_apply
,
_invoice
);
break
;
case
"1080"
:
//邮寄
res
=
await
this
.
examine1080
(
params
,
_apply
,
_invoice
);
break
;
case
"1090"
:
//已邮寄
res
=
await
this
.
examine1090
(
params
,
_apply
,
_invoice
);
break
;
default
:
res
=
system
.
getResult
(
null
,
"action_type参数错误"
);
break
;
}
return
res
;
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
/**
* 交付商拒绝
* @param {*} params
* {
* "id":"xxx",
* "nextStatus":"1040",
* ""
* }
* @param {*} _apply
* //将申请表中的delivererId 变成null,
* //将invoice和apply 中的状态待分配 1020
* //添加拒绝原因
*/
async
examine1040
(
params
,
_apply
,
_invoice
)
{
//更改发票表信息
_invoice
.
status
=
this
.
trim
(
params
.
nextStatus
);
//添加拒绝原因
let
delivererData
=
{
breakReason
:
this
.
trim
(
params
.
breakReason
),
id
:
_apply
.
delivererId
};
//更改申请表信息
_apply
.
status
=
"1020"
;
_apply
.
delivererId
=
null
;
let
applyData
=
{};
applyData
.
id
=
_apply
.
id
;
applyData
.
status
=
"1020"
;
applyData
.
delivererId
=
''
;
let
invoiceData
=
{};
invoiceData
.
status
=
"1020"
;
await
this
.
db
.
transaction
(
async
(
t
)
=>
{
//更新申请表状态
await
this
.
applyDao
.
update
(
applyData
,
t
);
//更新发票表状态
await
this
.
invoiceDao
.
update
(
invoiceData
,
t
);
//更新拒绝原因
await
this
.
dao
.
update
(
delivererData
,
t
);
}).
catch
(
error
=>
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
});
return
system
.
getResultSuccess
();
}
/**
* 交付商开具
* @param {*} params
* @param {*} _apply
*/
async
examine1050
(
params
,
_apply
,
_invoice
)
{
//更改发票表信息
let
invoiceData
=
{};
invoiceData
.
id
=
params
.
id
;
invoiceData
.
invoiceNo
=
this
.
trim
(
params
.
invoiceNo
);
invoiceData
.
invoiceTime
=
this
.
trim
(
params
.
invoiceTime
);
invoiceData
.
invoiceImg
=
this
.
trim
(
params
.
invoiceImg
);
invoiceData
.
status
=
this
.
trim
(
params
.
nextStatus
);
//更改申请表信息
let
applyData
=
{};
applyData
.
id
=
params
.
id
;
applyData
.
status
=
this
.
trim
(
params
.
nextStatus
);
applyData
.
customerStatus
=
this
.
trim
(
params
.
nextStatus
);
await
this
.
db
.
transaction
(
async
(
t
)
=>
{
//更新申请表状态
await
this
.
applyDao
.
update
(
applyData
,
t
);
//更新发票表状态
await
this
.
invoiceDao
.
update
(
invoiceData
,
t
);
}).
catch
(
error
=>
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
});
return
system
.
getResultSuccess
();
}
/**
* 交付商提交审核
* @param {*} params
* {
* nextStatus:xxx, //发票状态
* id:xxx //发票id
* }
* @param {*} _apply
*/
async
examine1060
(
params
,
_apply
,
_invoice
)
{
let
invoiceData
=
{},
applyData
=
{};
invoiceData
.
status
=
params
.
nextStatus
;
invoiceData
.
id
=
params
.
id
;
if
(
params
.
invoiceNo
)
{
invoiceData
.
invoiceNo
=
this
.
trim
(
params
.
invoiceNo
);
}
if
(
params
.
invoiceTime
)
{
invoiceData
.
invoiceTime
=
this
.
trim
(
params
.
invoiceTime
);
}
if
(
params
.
invoiceImg
)
{
invoiceData
.
invoiceImg
=
this
.
trim
(
params
.
invoiceImg
);
}
applyData
.
status
=
params
.
nextStatus
;
applyData
.
id
=
params
.
id
;
await
this
.
db
.
transaction
(
async
(
t
)
=>
{
//更新申请表状态
await
this
.
applyDao
.
update
(
applyData
,
t
);
//更新发票表状态
await
this
.
invoiceDao
.
update
(
invoiceData
,
t
);
}).
catch
(
error
=>
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
});
return
system
.
getResultSuccess
();
}
/**
* 交付商已邮寄
* @param {*} params
* {
* nextStatus:xxx, //发票状态
* id:xxx //发票id
* }
* @param {*} _apply
*/
async
examine1080
(
params
,
_apply
,
_invoice
)
{
let
invoiceData
=
{},
applyData
=
{},
delivererData
=
{};
//更改发票表信息
invoiceData
.
status
=
this
.
trim
(
params
.
nextStatus
);
invoiceData
.
mailNo
=
this
.
trim
(
params
.
mailNo
);
invoiceData
.
id
=
this
.
trim
(
params
.
id
);
//更改申请表信息
applyData
.
status
=
this
.
trim
(
params
.
nextStatus
);
applyData
.
id
=
this
.
trim
(
params
.
id
);
//交付商
let
_deliverer
=
await
this
.
dao
.
findOne
({
id
:
_apply
.
delivererId
});
delivererData
.
delivererMailNo
=
params
.
mailNo
;
delivererData
.
id
=
_deliverer
.
id
;
await
this
.
db
.
transaction
(
async
(
t
)
=>
{
//更新申请表状态
await
this
.
applyDao
.
update
(
applyData
,
t
);
//更新发票表状态
await
this
.
invoiceDao
.
update
(
invoiceData
,
t
);
//更新交付商信息
await
this
.
dao
.
update
(
delivererData
,
t
);
}).
catch
(
error
=>
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
});
return
system
.
getResultSuccess
();
}
/**
* 检查状态是否正确
* @param {*} params
* {
* id:xxx //发票id
* nextStatus:xxx //发票状态
* }
*/
async
verification
(
params
)
{
let
_apply
=
await
this
.
applyDao
.
findOne
({
id
:
params
.
id
});
let
_invoice
=
await
this
.
invoiceDao
.
findOne
({
id
:
params
.
id
});
if
(
!
_invoice
)
{
return
system
.
getResult
(
null
,
`此发票不存在`
);
}
//获取当前状态 的对象
let
_status
=
this
.
invoiceStatus
[
_invoice
.
status
];
//如果不符合状态则退出
if
(
params
.
nextStatus
==
"1300"
||
params
.
nextStatus
==
"1040"
||
params
.
nextStatus
==
"1010"
)
{
let
obj
=
{
_apply
:
_apply
,
_invoice
:
_invoice
};
return
obj
;
}
else
if
(
!
_status
&&
_status
.
dstatus
!=
params
.
nextStatus
)
{
let
name
=
this
.
invoiceStatus
[
this
.
invoiceStatus
[
_invoice
.
status
].
dstatus
].
name
;
return
system
.
getResult
(
null
,
`更新状态错误,提示:当前状态的下一个状态是
${
name
}
`
);
}
let
obj
=
{
_apply
:
_apply
,
_invoice
:
_invoice
};
return
obj
;
}
/**
* 查看业务办理
*/
async
queryProcess
(
params
)
{
let
_apply
=
await
this
.
applyDao
.
model
.
findOne
({
where
:
{
id
:
this
.
trim
(
params
.
id
)
},
attributes
:
[
'delivererId'
]
});
if
(
!
_apply
)
{
return
system
.
getResult
(
null
,
`发票不存在`
);
}
let
_deliverer
=
await
this
.
dao
.
findOne
({
id
:
_apply
.
delivererId
});
return
system
.
getResult
(
_deliverer
);
}
/**
* 平台更新邮寄地址
* @param {*} params
*/
async
updateEmailNo
(
params
)
{
try
{
let
_apply
=
await
this
.
applyDao
.
model
.
findOne
({
where
:
{
id
:
this
.
trim
(
params
.
id
)
},
attributes
:
[
'delivererId'
]
});
if
(
!
_apply
)
{
return
system
.
getResult
(
null
,
`发票不存在,请确认发票ID`
);
}
let
_deliverer
=
await
this
.
dao
.
model
.
findOne
({
where
:
{
id
:
_apply
.
delivererId
}
});
if
(
!
_deliverer
)
{
return
system
.
getResult
(
null
,
`交付商办理信息不存在,请联系管理员`
);
}
_deliverer
.
platformMailNo
=
this
.
trim
(
params
.
platformMailNo
);
let
res
=
await
_deliverer
.
save
();
return
system
.
getResult
(
res
);
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
/**
* 交付商申请列表
* @param {*} params
*/
async
delivererApplyInvoices
(
params
)
{
try
{
if
(
params
.
delivererId
)
{
params
.
delivererId
=
this
.
trim
(
params
.
delivererId
);
}
if
(
this
.
trim
(
params
.
applyNo
))
{
params
.
applyNo
=
this
.
trim
(
params
.
applyNo
);
}
if
(
this
.
trim
(
params
.
invoiceTime
))
{
params
.
invoiceTime
=
this
.
trim
(
params
.
invoiceTime
);
}
if
(
this
.
trim
(
params
.
startTime
))
{
params
.
startTime
=
this
.
trim
(
params
.
startTime
);
}
if
(
this
.
trim
(
params
.
endTime
))
{
params
.
endTime
=
this
.
trim
(
params
.
endTime
);
}
if
(
this
.
trim
(
params
.
type
))
{
params
.
type
=
this
.
trim
(
params
.
type
);
}
if
(
this
.
trim
(
params
.
status
))
{
params
.
status
=
this
.
trim
(
params
.
status
);
}
params
.
statRow
=
(
Number
(
this
.
trim
(
params
.
pageIndex
))
-
1
)
*
Number
(
this
.
trim
(
params
.
pageSize
));
if
(
params
.
statRow
<=
0
)
{
params
.
statRow
=
0
;
}
params
.
pageSize
=
Number
(
this
.
trim
(
params
.
pageSize
))
<=
0
?
10
:
Number
(
this
.
trim
(
params
.
pageSize
));
let
total
=
await
this
.
dao
.
countApplyByParams
(
params
);
if
(
total
[
0
].
count
==
0
)
{
let
res
=
{
rows
:
[],
count
:
0
};
return
system
.
getResult
(
res
);
}
let
rows
=
await
this
.
dao
.
delivererApplyInvoices
(
params
);
for
(
let
item
of
rows
)
{
if
(
item
.
type
==
"10"
)
{
item
.
type
=
"普通发票"
;
}
else
if
(
item
.
type
==
"20"
)
{
item
.
type
=
"增值税专用发票"
;
}
else
if
(
item
.
type
==
"30"
)
{
item
.
type
=
"电子发票"
;
}
else
{
item
.
type
=
""
;
}
this
.
handleDate
(
item
,
[
"invoice_time"
],
"YYYY-MM-DD HH:mm:ss"
,
-
8
);
this
.
dao
.
setRowCodeName
(
item
,
"status"
);
}
let
res
=
{
count
:
total
[
0
].
count
,
rows
:
rows
};
return
system
.
getResult
(
res
);
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
/**
* 查询发票明细(交付商)
* @param {*} applyNo
* @param {*} merchantId
*/
async
queryInvoiceDeliverer
(
applyNo
,
merchantId
,
id
)
{
try
{
let
_apply
;
if
(
merchantId
&&
applyNo
)
{
_apply
=
await
this
.
applyDao
.
model
.
findOne
({
where
:
{
merchantId
:
this
.
trim
(
merchantId
),
applyNo
:
this
.
trim
(
applyNo
)
},
attributes
:
this
.
_applyAttribute
,
raw
:
true
});
}
else
if
(
id
)
{
_apply
=
await
this
.
applyDao
.
model
.
findOne
({
where
:
{
id
:
this
.
trim
(
id
)
},
attributes
:
this
.
_applyAttribute
,
raw
:
true
});
}
else
{
_apply
=
null
;
}
if
(
!
_apply
)
{
return
system
.
getResult
(
null
)
}
//格式化字典
_apply
.
isBank
=
this
.
isBank
==
1
?
'开户'
:
'未开户'
;
if
(
_apply
.
type
==
10
)
{
_apply
.
type
=
"普通发票"
;
}
else
if
(
_apply
.
type
==
20
)
{
_apply
.
type
=
"增值税专用发票"
;
}
else
{
_apply
.
type
=
"电子发票"
}
//格式化日期
this
.
handleDate
(
_apply
,
[
"invoiceTime"
],
"YYYY-MM-DD HH:mm:ss"
,
-
8
);
this
.
handleDate
(
_apply
,
[
"createdAt"
],
"YYYY-MM-DD HH:mm:ss"
,
-
8
);
//查询平台审批内容
let
deliverer
=
await
this
.
dao
.
model
.
findOne
({
where
:
{
id
:
_apply
.
delivererId
},
raw
:
true
,
attributes
:
this
.
_delivererAttribute
});
//查询发票信息
let
invoice
=
await
this
.
invoiceDao
.
model
.
findOne
({
where
:
{
id
:
_apply
.
id
},
attributes
:
this
.
_invoiceAttribute
,
raw
:
true
});
this
.
handleDate
(
invoice
,
[
"invoiceTime"
],
"YYYY-MM-DD HH:mm:ss"
,
-
8
);
this
.
handleDate
(
invoice
,
[
"taxTime"
],
"YYYY-MM-DD HH:mm:ss"
,
-
8
);
invoice
.
complateTax
=
invoice
.
complateTax
==
1
?
'已完税'
:
'未完税'
;
deliverer
.
status
=
invoice
.
status
;
//格式化状态
this
.
dao
.
setRowCodeName
(
deliverer
,
"status"
);
_apply
.
deliverer
=
deliverer
;
delete
invoice
[
"status"
];
_apply
.
invoice
=
invoice
;
_apply
.
deliverer
=
deliverer
||
null
;
return
system
.
getResult
(
_apply
);
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息:
${
error
}
`
);
}
}
/**
* 发票列表(交付商)
* @param {*} params
*/
async
delInvs
(
params
)
{
if
(
params
.
delivererId
)
{
params
.
delivererId
=
this
.
trim
(
params
.
delivererId
);
}
if
(
this
.
trim
(
params
.
applyNo
))
{
params
.
applyNo
=
this
.
trim
(
params
.
applyNo
);
}
if
(
this
.
trim
(
params
.
invoiceNo
))
{
params
.
invoiceNo
=
this
.
trim
(
params
.
invoiceNo
);
}
if
(
this
.
trim
(
params
.
invoiceTime
))
{
params
.
invoiceTime
=
this
.
trim
(
params
.
invoiceTime
);
}
if
(
this
.
trim
(
params
.
startTime
))
{
params
.
startTime
=
this
.
trim
(
params
.
startTime
);
}
if
(
this
.
trim
(
params
.
endTime
))
{
params
.
endTime
=
this
.
trim
(
params
.
endTime
);
}
if
(
this
.
trim
(
params
.
type
))
{
params
.
type
=
this
.
trim
(
params
.
type
);
}
if
(
this
.
trim
(
params
.
status
))
{
params
.
status
=
this
.
trim
(
params
.
status
);
}
if
(
this
.
trim
(
params
.
complateTax
)
==
"1"
||
this
.
trim
(
params
.
complateTax
)
==
"0"
)
{
params
.
complateTax
=
this
.
trim
(
params
.
complateTax
);
}
if
(
this
.
trim
(
params
.
redStatus
))
{
params
.
red_status
=
this
.
trim
(
params
.
red_status
);
}
params
.
statRow
=
(
Number
(
this
.
trim
(
params
.
pageIndex
))
-
1
)
*
Number
(
this
.
trim
(
params
.
pageSize
));
if
(
params
.
statRow
<=
0
)
{
params
.
statRow
=
0
;
}
params
.
pageSize
=
Number
(
this
.
trim
(
params
.
pageSize
))
<=
0
?
10
:
Number
(
this
.
trim
(
params
.
pageSize
));
try
{
//查总数
let
total
=
await
this
.
dao
.
countInvoiceByParams
(
params
);
//查列表信息
let
rows
=
await
this
.
dao
.
delivererInvoices
(
params
);
for
(
let
item
of
rows
)
{
if
(
item
.
type
==
10
)
{
item
.
type
=
'普通发票'
;
}
else
if
(
item
.
type
==
20
)
{
item
.
type
=
'增值税专用发票'
;
}
else
if
(
item
.
type
==
30
)
{
item
.
type
=
'电子发票'
;
}
else
{
}
if
(
item
.
red_status
==
1
)
{
item
.
red_status
=
'未红冲'
;
}
else
if
(
item
.
red_status
==
2
)
{
item
.
red_status
=
'红冲中'
;
}
else
if
(
item
.
red_status
==
3
)
{
item
.
red_status
=
'红冲失败'
;
}
else
if
(
item
.
red_status
==
4
)
{
item
.
red_status
=
'红冲成功'
;
}
else
{
item
.
red_status
=
''
;
}
item
.
month
=
moment
(
item
.
invoice_time
).
month
()
+
1
;
item
.
complate_tax
=
item
.
complate_tax
==
1
?
'已完成'
:
'未完成'
;
this
.
handleDate
(
item
,
[
"invoice_time"
],
"YYYY-MM-DD HH:mm:ss"
,
-
8
);
this
.
dao
.
setRowCodeName
(
item
,
"status"
);
}
let
res
=
{
count
:
total
[
0
].
count
,
rows
:
rows
};
return
system
.
getResult
(
res
);
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
/**
* 列举所有日期
* @param {*} end
*/
getDays
(
end
)
{
var
days
=
[];
var
month
=
moment
(
end
).
format
(
"YYYY-MM"
);
var
endDay
=
Number
(
moment
(
end
).
format
(
"DD"
));
for
(
var
i
=
1
;
i
<=
endDay
;
i
++
)
{
if
(
i
<
10
)
{
days
.
push
(
month
+
"-0"
+
i
);
}
else
{
days
.
push
(
month
+
"-"
+
i
);
}
}
return
days
;
}
// addStatCount(statusMap, statuses) {
// var count = 0;
// if(!statuses) {
// return count;
// }
// for(var status of statuses) {
// count = count + Number(statusMap[status] || 0);
// }
// return count;
// }
}
module
.
exports
=
IinvoicedelivererService
;
\ No newline at end of file
xggsve-invoice/app/base/service/impl/invoice/iinvoicedeliverSvebak.js
0 → 100644
View file @
607e3516
// const ServiceBase = require("../../sve.base");
// const system = require("../../../system");
// const moment = require('moment');
// /**
// * 平台提交的信息
// */
// class IinvoicedelivererService extends ServiceBase {
// constructor() {
// super("invoice", ServiceBase.getDaoName(DelivererService));
// this.invoiceDao = system.getObject("db.invoice.invoiceDao");
// let is = system.getObject("util.invoiceStatus");
// this.invoiceStatus = is.status;
// }
// /**
// * 平台业务分配
// * @param {*} params
// */
// async apiAssignment(params) {
// try {
// return await this.assignment(params);
// } catch (error) {
// return system.getResult(null, `系统错误 错误信息 ${error}`);
// }
// }
// /**
// * 产看业务办理
// * @param {*} params
// * {
// * id:xxx 发票id
// * }
// */
// async apiQueryProcess(params) {
// try {
// return await this.queryProcess(params);
// } catch (error) {
// return system.getResult(null, `系统错误 错误信息 ${error}`);
// }
// }
// /**
// * 平台更新地址
// * @param {*} params
// */
// async apiUpEmNo(params) {
// try {
// if (!params.id) { return system.getResult(null, `参数错误 ID不能为空`); }
// if (!params.platformMailNo) { return system.getResult(null, `参数错误 邮寄单号不能为空`); }
// return await this.updateEmailNo(params);
// } catch (error) {
// return system.getResult(null, `系统错误 错误信息 ${error}`);
// }
// }
// /**
// * 申请列表(交付商)
// * 注意:当前只有一个交付商,如果有多个交付商,则需要传入id 并且修改当前接口sql
// * @param {*} params
// */
// async apiDelivererApplyInvoices(params) {
// try {
// if (!params.delivererId) { return system.getResult(null, `参数错误 ID不能为空`); }
// return await this.delivererApplyInvoices(params);
// } catch (error) {
// return system.getResult(null, `系统错误 错误信息 ${error}`);
// }
// }
// /**
// * 发票明细(交付商)
// * @param {*} params
// */
// async apiQueryInvoiceDeliverer(params) {
// try {
// var merchantId = params.merchantId || params.merchant_id;
// if ((params.merchantId && params.applyNo) || params.id) {
// let res = await this.queryInvoiceDeliverer(params.applyNo, merchantId, params.id);
// return res;
// } else {
// return system.getResultSuccess();
// }
// } catch (error) {
// return system.getResult(null, `系统错误 错误信息:${error}`);
// }
// }
// /**
// * 交付商审批列表
// * @param {*} params
// */
// async apiDelInvs(params) {
// try {
// return await this.delInvs(params);
// } catch (error) {
// return system.getResult(null, `系统错误 错误信息 ${error}`);
// }
// }
// /**
// * 交付商业务概览
// * @param {*} params
// */
// async apiStatDeliverData(params) {
// try {
// return await this.statDeliverData(params);
// } catch (error) {
// console.log(error);
// return system.getResult(null, "接口异常");
// }
// }
// /**
// * 交易数据(交付商)
// * @param {*} params
// */
// async apiDelStatTransData(params) {
// try {
// if(!params.delivererId){
// return system.getResult(-1,`交付商ID不能为空`);
// }
// return await this.delStatTransData(params);
// } catch (error) {
// return system.getResult(-1,`系统错误 错误信息 ${error}`);
// }
// }
// /**
// * 发票办理(交付商)
// * @param {*} params
// */
// async apiDelStatBusinessData(params) {
// try {
// if(!params.delivererId){
// return system.getResult(-1,`交付商ID不能为空`);
// }
// return await this.delStatBusinessData(params);
// } catch (error) {
// console.log(error);
// return system.getResult(null, "接口异常");
// }
// }
// //=========================================================================================//
// /**
// * 发票办理(交付商)
// * @param {*} params
// */
// async delStatBusinessData(params) {
// try {
// var result = {};
// var type = Number(params.type || 1);
// // 查 已完成订单,待分配订单,待审核订单,办理中订单
// var begin, end,delivererId=params.delivererId;
// // 取开始时间
// if (type == 1) {//本月
// begin = moment().format("YYYY-MM") + "-01 00:00:00";
// end = moment(begin).add(1, "months").subtract(1, 'days').format("YYYY-MM-DD") + " 23:59:59";
// } else if (type == 2) {//上个月
// begin = moment().subtract(1, "months").format("YYYY-MM") + "-01 00:00:00";
// end = moment(begin).add(1, "months").subtract(1, 'days').format("YYYY-MM-DD") + " 23:59:59";
// }
// // 先按照订单状态查
// let list = await this.dao.model.findAll({
// include:[
// {
// association:this.dao.model.belongsTo(this.applyDao.model,{
// foreignKey:"invoiceId",targetKey:"id"
// }),
// required:true,
// attributes:['status'],
// where:{
// status:{
// [this.db.Op.in]:['1030','1040','1050','1060','1300']
// }
// }
// }
// ],
// where:{
// delivererId:delivererId,
// createdAt:{
// [this.db.Op.between]:[begin,end]
// }
// },
// attributes:['id','delivererName','delivererId']
// });
// // 已开具 1050
// let count = 0;
// for(let item of list){
// if(item.apply.status=="1050"){
// count+=1;
// }
// }
// result.completeCount = count || 0;
// result.handlingCount = list.length-count<=0?0:list.length-count;
// return system.getResultSuccess(result);
// } catch (error) {
// return system.getResult(-1,`系统错误 错误信息 ${error}`);
// }
// }
// /**
// * 交易数据(交付商)
// * @param {*} params
// */
// async delStatTransData(params) {
// try {
// var result = {
// invoiceCount: 0,
// delivererAmount: 0,
// };
// var type = Number(params.type || 1);
// var begin, end,delivererId=params.delivererId;
// // 取开始时间
// if (type == 1) {
// begin = moment().format("YYYY-MM") + "-01 00:00:00";
// } else if (type == 2) {
// begin = moment().subtract(1, "months").format("YYYY-MM") + "-01 00:00:00";
// }
// // echart数据
// var days = [];
// var dayCounts = [];
// var priceCounts = [];
// // 处理查询业务
// if (type == 1 || type == 2) { // 取结束时间
// end = moment(begin).add(1, "months").subtract(1, 'days').format("YYYY-MM-DD") + " 23:59:59";
// days = this.getDays(end);
// // 按天统计
// var dayMap = await this.dao.delStatDayByTime(begin, end,delivererId);
// for (var day of days) {
// var ditem = dayMap[day] || {};
// dayCounts.push(ditem.invoiceCount || 0);
// priceCounts.push(system.f2y(ditem.delivererAmount || 0));
// }
// } else {
// var monthMap = await this.dao.delStatMonthByTime(begin, end, delivererId);
// var bm = monthMap.begin || "";
// var em = monthMap.end || "";
// if (bm && em) {
// // 开始月份-结束月份所有月份
// var curMonth = bm;
// while (true) {
// days.push(curMonth);
// if (curMonth == em) {
// break;
// }
// curMonth = moment(curMonth + "-01").add(1, "month").format("YYYY-MM");
// }
// }
// for (var day of days) {
// var ditem = monthMap[day] || {};
// dayCounts.push(ditem.invoiceCount || 0);
// priceCounts.push(system.f2y(ditem.delivererAmount || 0));
// }
// }
// var invoiceApplyData = await this.dao.delStatInvoiceByTime(begin, end ,delivererId) || {};
// result.invoiceCount = invoiceApplyData.invoiceCount;
// result.delivererAmount = system.f2y(invoiceApplyData.delivererAmount);
// result.days = days;
// result.dayCounts = dayCounts;
// result.priceCounts = priceCounts;
// return system.getResultSuccess(result);
// } catch (error) {
// return system.getResult(null,`系统错误 错误信息 ${error}`);
// }
// }
// /**
// * 交付商业务概览
// * @param {*} params
// */
// async statDeliverData(params) {
// try {
// var currentPage = Number(params.currentPage || 1);
// var pageSize = Number(params.pageSize || 10);
// // 处理时间
// var type = Number(params.type || 1);
// var begin, end;
// // 取开始时间
// if (type == 1) {
// begin = moment().format("YYYY-MM") + "-01 00:00:00";
// end = moment(begin).add(1, "months").subtract(1, 'days').format("YYYY-MM-DD") + " 23:59:59";
// } else if (type == 2) {
// begin = moment().subtract(1, "months").format("YYYY-MM") + "-01 00:00:00";
// end = moment(begin).add(1, "months").subtract(1, 'days').format("YYYY-MM-DD") + " 23:59:59";
// }
// var condition = {
// begin: begin,
// end: end,
// }
// // 查总数
// var _res = await this.dao.countStat(condition);
// if (_res.total == 0) {
// return system.getResultSuccess({
// count: 0,
// rows: []
// });
// }else{
// let _str=[];
// //这个id是交付商的id
// for (let item of _res.list) {
// _str.push(`'${item.deliverer_id}'`);
// }
// condition.list=_str.join(",");
// }
// // 查条数
// var startRow = (currentPage - 1) * pageSize;
// var list = await this.dao.queryStat(condition, startRow, pageSize);
// for (let item of list) {
// item.totalAmount=system.f2y(item.totalAmount || 0)
// }
// //计算每个
// // 设置已完成数量、办理中数量
// var delivererIds = [];
// for (var item of list) {
// //这个是交付商表的主键
// delivererIds.push(item.id);
// }
// var dstatusMap = await this.dao.statDeliverByStatus({
// begin: begin,
// end: end,
// delivererIds: delivererIds
// });
// for (var item of list) {
// item.completeCount = this.addStatCount(dstatusMap, item.id, ['1080',"1090"]);
// item.handlingCount = this.addStatCount(dstatusMap, item.id, ['1030','1040','1050','1060','1300']);
// }
// return system.getResultSuccess({
// count: _res.total,
// rows: list
// });
// } catch (error) {
// system.getResult(-1,`系统错误 错误信息 ${error}`);
// }
// }
// addStatCount(statusMap, deliverer_id, statuses) {
// var count = 0;
// if (!statuses || statuses.length == 0) {
// return count;
// }
// for (var status of statuses) {
// count = count + Number(statusMap[deliverer_id + "_" + status] || 0);
// }
// return count;
// }
// /**
// * 发票业务分配
// * @param {*} params
// * {
// * applyNo:"" //发票编号
// * nextStatus:"" //发票状态
// * }
// */
// async assignment(params) {
// let obj = await this.verification(params);
// let _apply = obj._apply;
// let _invoice = obj._invoice;
// try {
// let res;
// switch (params.nextStatus) {
// case "1040": //交付商以关闭
// res = await this.examine1040(params, _apply, _invoice);
// break;
// case "1050": //已开具
// res = await this.examine1050(params, _apply, _invoice);
// break;
// case "1060": //待审核
// res = await this.examine1060(params, _apply, _invoice);
// break;
// case "1080": //邮寄
// res = await this.examine1080(params, _apply, _invoice);
// break;
// case "1090": //已邮寄
// res = await this.examine1090(params, _apply, _invoice);
// break;
// default:
// res = system.getResult(null, "action_type参数错误");
// break;
// }
// return res;
// } catch (error) {
// return system.getResult(null, `系统错误 错误信息 ${error}`);
// }
// }
// /**
// * 交付商拒绝
// * @param {*} params
// * {
// * "id":"xxx",
// * "nextStatus":"1040",
// * ""
// * }
// * @param {*} _apply
// * //将申请表中的delivererId 变成null,
// * //将invoice和apply 中的状态待分配 1020
// * //添加拒绝原因
// */
// async examine1040(params, _apply, _invoice) {
// //更改发票表信息
// _invoice.status = this.trim(params.nextStatus);
// //添加拒绝原因
// let delivererData = {
// breakReason: this.trim(params.breakReason),
// id: _apply.delivererId
// };
// //更改申请表信息
// _apply.status = "1020";
// _apply.delivererId = null;
// let applyData = {};
// applyData.id = _apply.id;
// applyData.status = "1020";
// applyData.delivererId = '';
// let invoiceData = {};
// invoiceData.status = "1020";
// await this.db.transaction(async (t) => {
// //更新申请表状态
// await this.applyDao.update(applyData, t);
// //更新发票表状态
// await this.invoiceDao.update(invoiceData, t);
// //更新拒绝原因
// await this.dao.update(delivererData, t);
// }).catch(error => {
// return system.getResult(null, `系统错误 错误信息 ${error}`);
// });
// return system.getResultSuccess();
// }
// /**
// * 交付商开具
// * @param {*} params
// * @param {*} _apply
// */
// async examine1050(params, _apply, _invoice) {
// //更改发票表信息
// let invoiceData = {};
// invoiceData.id = params.id;
// invoiceData.invoiceNo = this.trim(params.invoiceNo);
// invoiceData.invoiceTime = this.trim(params.invoiceTime);
// invoiceData.invoiceImg = this.trim(params.invoiceImg);
// invoiceData.status = this.trim(params.nextStatus);
// //更改申请表信息
// let applyData = {};
// applyData.id = params.id;
// applyData.status = this.trim(params.nextStatus);
// applyData.customerStatus = this.trim(params.nextStatus);
// await this.db.transaction(async (t) => {
// //更新申请表状态
// await this.applyDao.update(applyData, t);
// //更新发票表状态
// await this.invoiceDao.update(invoiceData, t);
// }).catch(error => {
// return system.getResult(null, `系统错误 错误信息 ${error}`);
// });
// return system.getResultSuccess();
// }
// /**
// * 交付商提交审核
// * @param {*} params
// * {
// * nextStatus:xxx, //发票状态
// * id:xxx //发票id
// * }
// * @param {*} _apply
// */
// async examine1060(params, _apply, _invoice) {
// let invoiceData = {}, applyData = {};
// invoiceData.status = params.nextStatus;
// invoiceData.id = params.id;
// if (params.invoiceNo) {
// invoiceData.invoiceNo = this.trim(params.invoiceNo);
// }
// if (params.invoiceTime) {
// invoiceData.invoiceTime = this.trim(params.invoiceTime);
// }
// if (params.invoiceImg) {
// invoiceData.invoiceImg = this.trim(params.invoiceImg);
// }
// applyData.status = params.nextStatus;
// applyData.id = params.id;
// await this.db.transaction(async (t) => {
// //更新申请表状态
// await this.applyDao.update(applyData, t);
// //更新发票表状态
// await this.invoiceDao.update(invoiceData, t);
// }).catch(error => {
// return system.getResult(null, `系统错误 错误信息 ${error}`);
// });
// return system.getResultSuccess();
// }
// /**
// * 交付商已邮寄
// * @param {*} params
// * {
// * nextStatus:xxx, //发票状态
// * id:xxx //发票id
// * }
// * @param {*} _apply
// */
// async examine1080(params, _apply, _invoice) {
// let invoiceData = {}, applyData = {}, delivererData = {};
// //更改发票表信息
// invoiceData.status = this.trim(params.nextStatus);
// invoiceData.mailNo = this.trim(params.mailNo);
// invoiceData.id = this.trim(params.id);
// //更改申请表信息
// applyData.status = this.trim(params.nextStatus);
// applyData.id = this.trim(params.id);
// //交付商
// let _deliverer = await this.dao.findOne({ id: _apply.delivererId });
// delivererData.delivererMailNo = params.mailNo;
// delivererData.id = _deliverer.id;
// await this.db.transaction(async (t) => {
// //更新申请表状态
// await this.applyDao.update(applyData, t);
// //更新发票表状态
// await this.invoiceDao.update(invoiceData, t);
// //更新交付商信息
// await this.dao.update(delivererData, t);
// }).catch(error => {
// return system.getResult(null, `系统错误 错误信息 ${error}`);
// });
// return system.getResultSuccess();
// }
// /**
// * 检查状态是否正确
// * @param {*} params
// * {
// * id:xxx //发票id
// * nextStatus:xxx //发票状态
// * }
// */
// async verification(params) {
// let _apply = await this.applyDao.findOne({ id: params.id });
// let _invoice = await this.invoiceDao.findOne({ id: params.id });
// if (!_invoice) { return system.getResult(null, `此发票不存在`); }
// //获取当前状态 的对象
// let _status = this.invoiceStatus[_invoice.status];
// //如果不符合状态则退出
// if (params.nextStatus == "1300" || params.nextStatus == "1040" || params.nextStatus == "1010") {
// let obj = {
// _apply: _apply,
// _invoice: _invoice
// };
// return obj;
// } else if (!_status && _status.dstatus != params.nextStatus) {
// let name = this.invoiceStatus[this.invoiceStatus[_invoice.status].dstatus].name;
// return system.getResult(null, `更新状态错误,提示:当前状态的下一个状态是 ${name}`);
// }
// let obj = {
// _apply: _apply,
// _invoice: _invoice
// };
// return obj;
// }
// /**
// * 查看业务办理
// */
// async queryProcess(params) {
// let _apply = await this.applyDao.model.findOne({ where: { id: this.trim(params.id) }, attributes: ['delivererId'] });
// if (!_apply) {
// return system.getResult(null, `发票不存在`);
// }
// let _deliverer = await this.dao.findOne({ id: _apply.delivererId });
// return system.getResult(_deliverer);
// }
// /**
// * 平台更新邮寄地址
// * @param {*} params
// */
// async updateEmailNo(params) {
// try {
// let _apply = await this.applyDao.model.findOne({ where: { id: this.trim(params.id) }, attributes: ['delivererId'] });
// if (!_apply) { return system.getResult(null, `发票不存在,请确认发票ID`); }
// let _deliverer = await this.dao.model.findOne({ where: { id: _apply.delivererId } });
// if (!_deliverer) { return system.getResult(null, `交付商办理信息不存在,请联系管理员`); }
// _deliverer.platformMailNo = this.trim(params.platformMailNo);
// let res = await _deliverer.save();
// return system.getResult(res);
// } catch (error) {
// return system.getResult(null, `系统错误 错误信息 ${error}`);
// }
// }
// /**
// * 交付商申请列表
// * @param {*} params
// */
// async delivererApplyInvoices(params) {
// try {
// if (params.delivererId) {
// params.delivererId=this.trim(params.delivererId);
// }
// if (this.trim(params.applyNo)) {
// params.applyNo=this.trim(params.applyNo);
// }
// if (this.trim(params.invoiceTime)) {
// params.invoiceTime=this.trim(params.invoiceTime);
// }
// if (this.trim(params.startTime)) {
// params.startTime=this.trim(params.startTime);
// }
// if (this.trim(params.endTime)) {
// params.endTime=this.trim(params.endTime);
// }
// if (this.trim(params.type)) {
// params.type=this.trim(params.type);
// }
// if (this.trim(params.status)) {
// params.status=this.trim(params.status);
// }
// params.statRow = (Number(this.trim(params.pageIndex)) - 1) * Number(this.trim(params.pageSize));
// if (params.statRow <= 0) { params.statRow = 0; }
// params.pageSize = Number(this.trim(params.pageSize)) <= 0 ? 10 : Number(this.trim(params.pageSize));
// let total = await this.dao.countApplyByParams(params);
// if (total[0].count == 0) {
// let res = { rows: [], count: 0 };
// return system.getResult(res);
// }
// let rows = await this.dao.delivererApplyInvoices(params);
// for (let item of rows) {
// if (item.type == "10") {
// item.type = "普通发票";
// } else if (item.type == "20") {
// item.type = "增值税专用发票";
// } else if (item.type == "30") {
// item.type = "电子发票";
// } else {
// item.type = "";
// }
// this.handleDate(item, ["invoice_time"], "YYYY-MM-DD HH:mm:ss", -8);
// this.dao.setRowCodeName(item, "status");
// }
// let res = { count: total[0].count, rows: rows };
// return system.getResult(res);
// } catch (error) {
// return system.getResult(null, `系统错误 错误信息 ${error}`);
// }
// }
// /**
// * 查询发票明细(交付商)
// * @param {*} applyNo
// * @param {*} merchantId
// */
// async queryInvoiceDeliverer(applyNo, merchantId, id) {
// try {
// let _apply;
// if (merchantId && applyNo) {
// _apply = await this.applyDao.model.findOne({
// where: {
// merchantId: this.trim(merchantId),
// applyNo: this.trim(applyNo)
// },
// attributes: this._applyAttribute,
// raw: true
// });
// } else if (id) {
// _apply = await this.applyDao.model.findOne({
// where: { id: this.trim(id) },
// attributes: this._applyAttribute,
// raw: true
// });
// } else {
// _apply = null;
// }
// if (!_apply) { return system.getResult(null) }
// //格式化字典
// _apply.isBank = this.isBank == 1 ? '开户' : '未开户';
// if (_apply.type == 10) {
// _apply.type = "普通发票";
// } else if (_apply.type == 20) {
// _apply.type = "增值税专用发票";
// } else {
// _apply.type = "电子发票"
// }
// //格式化日期
// this.handleDate(_apply, ["invoiceTime"], "YYYY-MM-DD HH:mm:ss", -8);
// this.handleDate(_apply, ["createdAt"], "YYYY-MM-DD HH:mm:ss", -8);
// //查询平台审批内容
// let deliverer = await this.dao.model.findOne({
// where: { id: _apply.delivererId },
// raw: true,
// attributes: this._delivererAttribute
// });
// //查询发票信息
// let invoice = await this.invoiceDao.model.findOne({
// where: { id: _apply.id },
// attributes: this._invoiceAttribute,
// raw: true
// });
// this.handleDate(invoice, ["invoiceTime"], "YYYY-MM-DD HH:mm:ss", -8);
// this.handleDate(invoice, ["taxTime"], "YYYY-MM-DD HH:mm:ss", -8);
// invoice.complateTax = invoice.complateTax == 1 ? '已完税' : '未完税';
// deliverer.status = invoice.status;
// //格式化状态
// this.dao.setRowCodeName(deliverer, "status");
// _apply.deliverer = deliverer;
// delete invoice["status"];
// _apply.invoice = invoice;
// _apply.deliverer = deliverer || null;
// return system.getResult(_apply);
// } catch (error) {
// return system.getResult(null, `系统错误 错误信息:${error}`);
// }
// }
// /**
// * 发票列表(交付商)
// * @param {*} params
// */
// async delInvs(params) {
// if (params.delivererId) {
// params.delivererId=this.trim(params.delivererId);
// }
// if (this.trim(params.applyNo)) {
// params.applyNo=this.trim(params.applyNo);
// }
// if (this.trim(params.invoiceNo)) {
// params.invoiceNo=this.trim(params.invoiceNo);
// }
// if (this.trim(params.invoiceTime)) {
// params.invoiceTime=this.trim(params.invoiceTime);
// }
// if (this.trim(params.startTime)) {
// params.startTime=this.trim(params.startTime);
// }
// if (this.trim(params.endTime)) {
// params.endTime=this.trim(params.endTime);
// }
// if (this.trim(params.type)) {
// params.type=this.trim(params.type);
// }
// if (this.trim(params.status)) {
// params.status=this.trim(params.status);
// }
// if (this.trim(params.complateTax) == "1" || this.trim(params.complateTax) == "0") {
// params.complateTax=this.trim(params.complateTax);
// }
// if (this.trim(params.redStatus)) {
// params.red_status=this.trim(params.red_status);
// }
// params.statRow = (Number(this.trim(params.pageIndex)) - 1) * Number(this.trim(params.pageSize));
// if (params.statRow <= 0) { params.statRow = 0; }
// params.pageSize = Number(this.trim(params.pageSize)) <= 0 ? 10 : Number(this.trim(params.pageSize));
// try {
// //查总数
// let total = await this.dao.countInvoiceByParams(params);
// //查列表信息
// let rows = await this.dao.delivererInvoices(params);
// for (let item of rows) {
// if (item.type == 10) {
// item.type = '普通发票';
// } else if (item.type == 20) {
// item.type = '增值税专用发票';
// } else if (item.type == 30) {
// item.type = '电子发票';
// } else { }
// if (item.red_status == 1) {
// item.red_status = '未红冲';
// } else if (item.red_status == 2) {
// item.red_status = '红冲中';
// } else if (item.red_status == 3) {
// item.red_status = '红冲失败';
// } else if (item.red_status == 4) {
// item.red_status = '红冲成功';
// } else {
// item.red_status = '';
// }
// item.month = moment(item.invoice_time).month() + 1;
// item.complate_tax = item.complate_tax == 1 ? '已完成' : '未完成';
// this.handleDate(item, ["invoice_time"], "YYYY-MM-DD HH:mm:ss", -8);
// this.dao.setRowCodeName(item, "status");
// }
// let res = { count: total[0].count, rows: rows };
// return system.getResult(res);
// } catch (error) {
// return system.getResult(null, `系统错误 错误信息 ${error}`);
// }
// }
// /**
// * 列举所有日期
// * @param {*} end
// */
// getDays(end) {
// var days = [];
// var month = moment(end).format("YYYY-MM");
// var endDay = Number(moment(end).format("DD"));
// for (var i = 1; i <= endDay; i++) {
// if (i < 10) {
// days.push(month + "-0" + i);
// } else {
// days.push(month + "-" + i);
// }
// }
// return days;
// }
// // addStatCount(statusMap, statuses) {
// // var count = 0;
// // if(!statuses) {
// // return count;
// // }
// // for(var status of statuses) {
// // count = count + Number(statusMap[status] || 0);
// // }
// // return count;
// // }
// }
// module.exports = IinvoicedelivererService;
\ No newline at end of file
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