Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
5
51business
Project
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
方斌
51business
Commits
493d83c6
Commit
493d83c6
authored
Sep 12, 2019
by
李尚科
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
7acedd53
Pipeline
#13750
passed with stage
in 6 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
21 deletions
+13
-21
order.js
app/controller/credit/order.js
+1
-1
common.js
app/service/credit/common.js
+7
-18
order.js
app/service/credit/order.js
+5
-2
No files found.
app/controller/credit/order.js
View file @
493d83c6
...
...
@@ -57,7 +57,7 @@ class OrderController extends Controller {
ctx
.
logger
.
info
({
notice_params
:
ret_obj
});
const
ret
=
await
ctx
.
service
.
credit
.
common
.
WexinNotify
(
ret_obj
);
if
(
ret
)
{
ctx
.
success
(
"<xml><return_code>
SUCCESS</return_code><return_msg>OK
</return_msg></xml>"
);
ctx
.
success
(
"<xml><return_code>
<![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]>
</return_msg></xml>"
);
return
;
}
ctx
.
success
(
"<xml><return_code>FAIL</return_code><return_msg>UNKONW</return_msg></xml>"
);
...
...
app/service/credit/common.js
View file @
493d83c6
...
...
@@ -141,27 +141,21 @@ class CommonService extends Service {
if
(
!
transaction_id
&&
!
trade_no
)
{
return
false
;
}
const
pay_info
=
await
ctx
.
prometheusModel
.
CreditPay
.
one
({
where
:
{
trade_no
}
});
if
(
!
pay_info
||
!
pay_info
.
order_id
)
{
ctx
.
failed
(
'pay info error'
);
}
const
order_info
=
await
ctx
.
service
.
credit
.
order
.
getOrderInfo
(
pay_info
.
order_id
);
// const order_info = await ctx.service.credit.order.getOrderInfo(pay_info.order_id);
const
nonce_str
=
ctx
.
helper
.
createNoncestr
();
const
url
=
'https://api.mch.weixin.qq.com/pay/orderquery'
;
let
data_obj
=
{
appid
:
this
.
config
.
MCH_APPID
,
mch_id
:
this
.
config
.
MCH_ID
,
transaction_id
,
out_trade_no
:
trade_no
,
nonce_str
,
}
if
(
transaction_id
)
data_obj
.
transaction_id
=
transaction_id
;
if
(
trade_no
)
data_obj
.
out_trade_no
=
trade_no
;
const
sign
=
this
.
getWexinSign
(
data_obj
);
data_obj
.
sign
=
sign
;
const
xml_data
=
ctx
.
helper
.
jsonToxml
(
data_obj
);
const
result_wexin
=
await
ctx
.
curl
(
url
,
{
timeout
:
3000
,
method
:
'POST'
,
data
:
xml_data
,
headers
:
{
'content-type'
:
'text/html'
,
},
streaming
:
false
,
dataType
:
'text'
,
});
ctx
.
logger
.
info
(
JSON
.
stringify
({
query_wexinpay_param
:
data_obj
,
query_wexinpay_result
:
result_wexin
.
data
}));
if
(
result_wexin
.
status
!==
200
)
{
ctx
.
failed
(
'wexin orderquery error1'
);
}
...
...
@@ -170,23 +164,18 @@ class CommonService extends Service {
for
(
let
key
in
ret
)
{
ret_data
[
key
]
=
ret
[
key
][
0
];
}
ctx
.
logger
.
info
(
JSON
.
stringify
({
query_wexinpay_param
:
params
,
query_wexinpay_result
:
ret_data
}));
//
ctx.logger.info(JSON.stringify({ query_wexinpay_param: params, query_wexinpay_result: ret_data }));
let
error_msg
=
'wexin orderquery error2'
;
if
(
ret_data
.
return_code
!==
'SUCCESS'
&&
ret_data
.
result_code
!==
'SUCCESS'
)
{
error_msg
=
ret_data
.
return_msg
?
ret_data
.
return_msg
:
error_msg
;
ctx
.
failed
(
error_msg
);
}
if
(
ret_data
.
trade_state
===
'SUCCESS'
)
{
return
false
;
}
const
price
=
order_info
.
price
*
100
-
order_info
.
preferential_price
*
100
;
if
(
price
!=
ret_data
.
cash_fee
)
{
if
(
ret_data
.
trade_state
!==
'SUCCESS'
)
{
return
false
;
}
await
ctx
.
prometheusModel
.
CreditPay
.
edit
({
where
:
{
id
:
pay_info
.
id
},
params
:
{
pay_result
:
JSON
.
stringify
(
ret_data
),
status
:
1
}
});
return
true
;
return
{
total_fee
:
ret_data
.
cash_fee
,
ret_data
}
;
}
...
...
app/service/credit/order.js
View file @
493d83c6
...
...
@@ -240,13 +240,16 @@ class OrderService extends Service {
if
(
order
&&
order
.
pay_status
===
1
)
{
return
true
;
}
const
credit_pay
=
await
ctx
.
prometheusModel
.
CreditPay
.
o
ne
({
where
:
{
order_id
},
order
:
[[
'id'
,
'desc'
]]
});
const
credit_pay
=
await
ctx
.
prometheusModel
.
CreditPay
.
findO
ne
({
where
:
{
order_id
},
order
:
[[
'id'
,
'desc'
]]
});
if
(
!
credit_pay
||
!
credit_pay
.
id
)
{
ctx
.
failed
(
'error credit pay'
);
}
const
{
transaction_id
,
trade_no
}
=
credit_pay
;
const
wexin_check_pay_ret
=
await
ctx
.
service
.
credit
.
common
.
WexinCheckPay
({
transaction_id
,
trade_no
});
if
(
wexin_check_pay_ret
)
{
const
price
=
((
order
.
price
-
order
.
preferential_price
)
*
100
).
toFixed
();
if
(
price
===
wexin_check_pay_ret
.
total_fee
)
{
await
ctx
.
prometheusModel
.
CreditPay
.
edit
({
where
:
{
id
:
credit_pay
.
id
},
params
:
{
pay_result
:
JSON
.
stringify
(
wexin_check_pay_ret
),
status
:
1
}
});
const
state_time
=
moment
().
format
(
'YYYY-MM-DD HH:mm:ss'
);
await
ctx
.
prometheusModel
.
CreditOrder
.
update
({
state
:
'已支付'
,
state_time
,
pay_status
:
1
},
{
where
:
{
id
:
order
.
id
,
pay_status
:
0
}
})
return
true
;
...
...
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