Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pay
Project
Project
Details
Activity
Releases
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
bp
pay
Commits
9ae25f92
Commit
9ae25f92
authored
Jul 10, 2021
by
wanjilong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add: 调整支付回调兼容 change \order
parent
07d8c438
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
132 additions
and
115 deletions
+132
-115
RefundException.php
application/exception/custom/RefundException.php
+4
-0
Callback.php
application/modules/Pay/controllers/Callback.php
+1
-16
Order.php
application/modules/Pay/controllers/Order.php
+53
-24
PayService.php
application/services/pay/PayService.php
+30
-22
RefundService.php
application/services/refund/RefundService.php
+42
-51
Wallet.php
daemon/Wallet.php
+2
-2
No files found.
application/exception/custom/RefundException.php
View file @
9ae25f92
...
...
@@ -19,5 +19,9 @@ class RefundException extends BaseException
5
=>
'该订单不允许退款,请核对'
,
6
=>
'该退款单核对ping++状态为未支付,请稍后重试!'
,
7
=>
'已核销计算订单不支持退款!'
,
8
=>
'退款消息类型匹配失败,请管理员关注!'
,
9
=>
'ping++退款消息格式错误,请管理员关注!'
,
10
=>
'ping++退单状态异常,请管理员关注!'
,
11
=>
'ping++退单缺少matadata!'
,
];
}
application/modules/Pay/controllers/Callback.php
View file @
9ae25f92
...
...
@@ -34,17 +34,11 @@ class CallbackController extends Base
}
//$str = gzuncompress(base64_decode($info['data']));
//先记录在验签
$signature
=
$_SERVER
[
'HTTP_X_PINGPLUSPLUS_SIGNATURE'
]
??
''
;
$sign
=
PingxxService
::
getInstance
()
->
verifySignature
(
$raw_data
,
$signature
);
if
(
$sign
!=
1
)
{
throw
new
\Exception
(
'验证签名失败,请管理员关注'
);
}
$ret
=
$paySrv
->
call_back
(
$data
);
$this
->
success
([
'result'
=>
$ret
]);
}
catch
(
Exception
$e
)
{
throw
$e
;
$this
->
failed
(
'500'
,
$e
->
getMessage
());
}
}
...
...
@@ -64,20 +58,11 @@ class CallbackController extends Base
]);
}
//先记录在验签
$signature
=
$_SERVER
[
'HTTP_X_PINGPLUSPLUS_SIGNATURE'
]
??
''
;
$sign
=
PingxxService
::
getInstance
()
->
verifySignature
(
$raw_data
,
$signature
);
if
(
$sign
!=
1
)
{
throw
new
\Exception
(
'验证签名失败,请管理员关注'
);
}
$refundSrv
=
new
RefundService
();
$ret
=
$refundSrv
->
call_back
(
$data
);
$this
->
success
([
'result'
=>
$ret
]);
}
catch
(
Exception
$e
)
{
http_response_code
(
500
);
$this
->
failed
(
'500'
,
$e
->
getMessage
());
}
}
...
...
application/modules/Pay/controllers/Order.php
View file @
9ae25f92
...
...
@@ -2,8 +2,11 @@
use
App\Base\Base
;
use
App\Exception\custom\PayException
;
use
App\Exception\custom\RefundException
;
use
App\Services\pay\PayService
;
use
App\Services\refund\RefundService
;
use
Api\PhpUtils\Log\FileLog
;
class
OrderController
extends
Base
...
...
@@ -13,39 +16,65 @@ class OrderController extends Base
*/
public
function
payAction
()
{
$params
=
$this
->
params
;
$user_id
=
$params
[
'user_id'
];
$order_id
=
$params
[
'order_id'
];
$pay_method_id
=
$params
[
'pay_method_id'
]
??
106
;
$paySrv
=
new
PayService
();
$ret
=
$paySrv
->
do_pay
(
$order_id
,
$user_id
,
$pay_method_id
);
//兼容C端客户端支付,调整返回结构,ping++ 返回 order,原生:微信、支付宝返回charge
$result
=
[];
$result
[]
=
[
'k'
=>
'order'
,
'v'
=>
$ret
];
$this
->
success
([
'result'
=>
$result
]);
try
{
$params
=
$this
->
params
;
$user_id
=
$params
[
'user_id'
];
$order_id
=
$params
[
'order_id'
];
$pay_method_id
=
$params
[
'pay_method_id'
]
??
106
;
$paySrv
=
new
PayService
();
$ret
=
$paySrv
->
do_pay
(
$order_id
,
$user_id
,
$pay_method_id
);
//兼容C端客户端支付,调整返回结构,ping++ 返回 order,原生:微信、支付宝返回charge
$result
=
[];
$result
[]
=
[
'k'
=>
'order'
,
'v'
=>
$ret
];
$this
->
success
([
'result'
=>
$result
]);
}
catch
(
PayException
$e
)
{
$this
->
failed
(
$e
->
getMessage
(),
$e
->
getCode
());
}
catch
(
\Exception
$e
)
{
FileLog
::
error
(
'pay-service:ping++支付报错'
,
json_encode
(
$params
,
JSON_UNESCAPED_UNICODE
),
$e
);
$this
->
failed
(
$e
->
getMessage
(),
$e
->
getCode
());
}
}
public
function
refundAction
()
{
$params
=
$this
->
params
;
$user_id
=
$params
[
'user_id'
];
$order_item_id
=
$params
[
'order_item_id'
];
$refundSrv
=
new
RefundService
();
$ret
=
$refundSrv
->
do_refund
(
$order_item_id
,
$user_id
);
try
{
$params
=
$this
->
params
;
$user_id
=
$params
[
'user_id'
];
$order_item_id
=
$params
[
'order_item_id'
];
$refundSrv
=
new
RefundService
();
$ret
=
$refundSrv
->
do_refund
(
$order_item_id
,
$user_id
);
$this
->
success
([
'result'
=>
$ret
]);
$this
->
success
([
'result'
=>
$ret
]);
}
catch
(
RefundException
$e
)
{
$this
->
failed
(
$e
->
getMessage
(),
$e
->
getCode
());
}
catch
(
\Exception
$e
)
{
FileLog
::
error
(
'pay-service:ping++退款报错'
,
json_encode
(
$params
,
JSON_UNESCAPED_UNICODE
),
$e
);
$this
->
failed
(
$e
->
getMessage
(),
$e
->
getCode
());
}
}
public
function
write_offAction
()
{
$params
=
$this
->
params
;
$life_account_id
=
$params
[
'life_account_id'
];
$order_item_id
=
$params
[
'order_item_id'
];
$refundSrv
=
new
PayService
();
$ret
=
$refundSrv
->
write_off
(
$order_item_id
,
$life_account_id
);
try
{
$params
=
$this
->
params
;
$life_account_id
=
$params
[
'life_account_id'
];
$order_item_id
=
$params
[
'order_item_id'
];
$refundSrv
=
new
PayService
();
$ret
=
$refundSrv
->
write_off
(
$order_item_id
,
$life_account_id
);
$this
->
success
([
'result'
=>
$ret
]);
$this
->
success
([
'result'
=>
$ret
]);
}
catch
(
RefundException
$e
)
{
$this
->
failed
(
$e
->
getMessage
(),
$e
->
getCode
());
}
catch
(
\Exception
$e
)
{
FileLog
::
error
(
'pay-service:核销报错'
,
json_encode
(
$params
,
JSON_UNESCAPED_UNICODE
),
$e
);
$this
->
failed
(
$e
->
getMessage
(),
$e
->
getCode
());
}
}
}
application/services/pay/PayService.php
View file @
9ae25f92
...
...
@@ -142,7 +142,7 @@ class PayService
*/
public
function
call_back
(
$data
)
{
if
(
$data
[
'type'
]
!=
'order.succeeded'
)
{
if
(
!
in_array
(
$data
[
'type'
],
[
'order.succeeded'
,
'charge.succeeded'
])
)
{
throw
new
PayException
([
'cus'
=>
7
]);
}
...
...
@@ -151,37 +151,44 @@ class PayService
}
$object
=
$data
[
'data'
][
'object'
];
/*
$ping_data = PingxxService::getInstance()->getOrder($object['id']);
if($ping_data['status'] != 'paid') {
if
(
$data
[
'type'
]
==
'charge.succeeded'
)
{
$pay_order_id
=
$object
[
'order_no'
];
$paid
=
$object
[
'paid'
];
$amount
=
$object
[
'amount'
];
}
else
{
$pay_order_id
=
$object
[
'merchant_order_no'
];
$paid
=
$object
[
'paid'
];
$amount
=
$object
[
'actual_amount'
];
}
if
(
$paid
!=
true
)
{
throw
new
PayException
([
'cus'
=>
6
]);
}
$pay_order
=
PayOrder
::
get
(
'*'
,
[
'pay_order_id'
=>
$pay_order_id
]);
if
(
empty
(
$pay_order
))
{
throw
new
PayException
([
'cus'
=>
5
]);
} //actual_amount 金额核对
*/
}
if
(
$pay_order
[
'pay_amount'
]
!=
$amount
)
{
throw
new
PayException
([
'cus'
=>
15
]);
}
// 修改状态,锁定业务
$pay_order_id
=
$object
[
'merchant_order_no'
];
$edit
=
[
'pay_order_status'
=>
Dictionary
::
O_PAY_STATUS_PAYED
,
'pay_order_status'
=>
2
,
//已经支付
'pingxx_callback_success_time'
=>
date
(
'Y-m-d H:i:s'
),
];
$where
=
[
'pay_order_id'
=>
$pay_order_id
,
'pay_order_status'
=>
Dictionary
::
O_PAY_STATUS_WAIT
'pay_order_status'
=>
1
,
//待支付确认
];
$cnt
=
PayOrder
::
update
(
$edit
,
$where
);
$pay_order
=
PayOrder
::
getMaster
(
'*'
,
[
'pay_order_id'
=>
$pay_order_id
]);
if
(
empty
(
$pay_order
))
{
throw
new
PayException
([
'cus'
=>
5
]);
}
//保持幂等返回成功
if
(
$cnt
==
0
&&
$pay_order
[
'pay_order_status'
]
==
Dictionary
::
O_PAY_STATUS_PAYED
)
{
if
(
$cnt
==
0
)
{
return
[
'pay_order_id'
=>
$pay_order_id
];
}
if
(
$pay_order
[
'pay_amount'
]
!=
$object
[
'actual_amount'
])
{
throw
new
PayException
([
'cus'
=>
15
]);
}
//获取订单 + 子单 + 分销信息
$ret
=
OrderService
::
getFullOrderData
(
$pay_order
[
'order_id'
],
$pay_order
[
'user_id'
]);
if
(
empty
(
$ret
[
'result'
][
'order_info'
]))
{
...
...
@@ -289,7 +296,7 @@ class PayService
],
[
'order_item_id'
=>
$order_item_id
,
'can_notify_account'
=>
1
]);
}
catch
(
\Exception
$e
)
{
FileLog
::
error
(
'wallet: 钱包同步失败'
,
json_encode
(
$wallet_list
,
JSON_UNESCAPED_UNICODE
),
$e
);
FileLog
::
error
(
'
pay-service:
wallet: 钱包同步失败'
,
json_encode
(
$wallet_list
,
JSON_UNESCAPED_UNICODE
),
$e
);
//补偿处理
PayOrderItem
::
update
([
'notify_account_status'
=>
0
,
...
...
@@ -327,7 +334,7 @@ class PayService
//核对各项资金的合理性
if
(
$wx_tip
<
0
||
$distribution_tip
<
0
||
$platform_tip
<
0
||
$merchant_cash
<
0
)
{
FileLog
::
error
(
'pay: 支付预结算失败,结算资金为负'
,
FileLog
::
error
(
'pay
-service
: 支付预结算失败,结算资金为负'
,
json_encode
([
$this
->
order_info
[
'payment'
],
$wx_tip
,
$distribution_tip
,
$platform_tip
,
$merchant_cash
]));
throw
new
PayException
([
'cus'
=>
14
]);
}
...
...
@@ -505,7 +512,7 @@ class PayService
'ret'
=>
$ret
,
],
JSON_UNESCAPED_UNICODE
);
FileLog
::
error
(
'pay:'
,
'获取生活号管理员失败'
,
$log_string
);
FileLog
::
error
(
'pay
-service
:'
,
'获取生活号管理员失败'
,
$log_string
);
throw
new
PayException
([
'cus'
=>
13
]);
}
...
...
@@ -639,6 +646,7 @@ class PayService
108
=>
"wx_pub_qr"
,
//微信 Native 支付
109
=>
"wx_wap"
,
//微信 H5 支付
110
=>
"wx_lite"
,
//微信小程序支付
120
=>
"alipay"
,
//支付宝
];
if
(
$maps
[
$pay_method_id
])
{
...
...
application/services/refund/RefundService.php
View file @
9ae25f92
...
...
@@ -75,37 +75,64 @@ class RefundService
return
[
'order_item_id'
=>
$order_item_id
];
}
catch
(
\Exception
$e
)
{
$edit
=
[
'refund_order_status'
=>
Dictionary
::
REFUND_ORDER_STATUS_UNDO
,
];
$edit
=
[
'refund_order_status'
=>
0
];
RefundOrder
::
update
(
$edit
,
[
'refund_order_id'
=>
$data
[
'refund_order'
][
'refund_order_id'
]]);
throw
$e
;
}
}
/**
* @param $data
* @return array
* @throws RefundException
* 退款回调
*/
public
function
call_back
(
$data
)
{
if
(
empty
(
$data
[
'data'
][
'object'
]))
{
throw
new
RefundException
([
'cus'
=>
6
]);
if
(
!
in_array
(
$data
[
'type'
],
[
'refund.succeeded'
,
'order.refunded'
]))
{
throw
new
RefundException
([
'cus'
=>
8
]);
}
if
(
empty
(
$data
[
'data'
][
'object'
]))
{
throw
new
RefundException
([
'cus'
=>
9
]);
}
$object
=
$data
[
'data'
][
'object'
];
if
(
empty
(
$object
[
'metadata'
][
'refund_order_id'
]))
{
throw
new
RefundException
([
'cus'
=>
0
]);
if
(
$data
[
'type'
]
==
'charge.succeeded'
)
{
$refund_order_id
=
$object
[
'order_no'
];
$refunded
=
$object
[
'succeed'
];
//"succeed": true,
}
else
{
$refund_order_id
=
$object
[
'merchant_order_no'
];
$refunded
=
$object
[
'refunded'
];
}
if
(
$refunded
!=
true
)
{
throw
new
RefundException
([
'cus'
=>
10
]);
}
/*
// 获取退款回调信息,确认订单ID
$charge = $object['charges']['data'][0];
$ping_refund = PingxxService::getInstance()->getRefund($charge['id'], $object['id']);
if($ping_refund['status'] != 'succeeded') {
throw new RefundException(['cus' => 6]);
$object
=
$data
[
'data'
][
'object'
];
if
(
empty
(
$object
[
'metadata'
][
'refund_order_id'
]))
{
throw
new
RefundException
([
'cus'
=>
11
]);
}
*/
// 修改状态,锁定业务
$refund_order_id
=
$object
[
'metadata'
][
'refund_order_id'
];
$this
->
lock_refund_clear
(
$refund_order_id
);
$edit
=
[
'refund_order_status'
=>
2
,
//pingxx回调成功,
'pingxx_callback_success_time'
=>
date
(
'Y-m-d H:i:s'
),
//回调成功时间
'notify_account_status'
=>
1
,
//不需要通知钱包
];
$cnt
=
RefundOrder
::
update
(
$edit
,
[
'refund_order_id'
=>
$refund_order_id
,
'refund_order_status'
=>
1
]);
//保持幂等操作
if
(
$cnt
==
0
)
{
return
[
'refund_order_id'
=>
$refund_order_id
];
}
//不用搞清分核算,是否需要平台记账?
$this
->
make_refund_clear
(
$refund_order_id
);
return
[
'refund_order_id'
=>
$refund_order_id
];
//不用搞清分核算,是否需要平台记账
}
/**
...
...
@@ -202,42 +229,6 @@ class RefundService
return
$data
;
}
private
function
lock_refund_clear
(
$refund_order_id
)
{
try
{
RefundOrder
::
beginTransaction
();
$refund_order
=
RefundOrder
::
get
(
'*'
,
[
'refund_order_id'
=>
$refund_order_id
]);
if
(
empty
(
$refund_order
))
{
throw
new
RefundException
([
'cus'
=>
0
]);
}
$this
->
refund_order
=
$refund_order
;
if
(
$refund_order
[
'refund_order_status'
]
==
Dictionary
::
REFUND_ORDER_STATUS_OK
)
{
throw
new
RefundException
([
'cus'
=>
0
]);
}
$edit
=
[
'refund_order_status'
=>
Dictionary
::
REFUND_ORDER_STATUS_OK
,
'pingxx_callback_success_time'
=>
date
(
'Y-m-d H:i:s'
),
'notify_account_status'
=>
Dictionary
::
SEND_ACCOUNT_STATUS_DONE
,
];
RefundOrder
::
update
(
$edit
,
[
'refund_order_id'
=>
$refund_order_id
]);
RefundOrder
::
commit
();
}
catch
(
\PDOException
$e
)
{
RefundOrder
::
rollback
();
throw
$e
;
}
}
private
function
make_refund_clear
()
{
return
true
;
//仅处理WX手续费,平台补贴,商户补贴
}
private
function
gen_refund_order_id
(
$user_id
)
{
$number
=
substr
(
$user_id
,
-
2
);
...
...
daemon/Wallet.php
View file @
9ae25f92
...
...
@@ -16,7 +16,6 @@ class Wallet implements DaemonServiceInterface
*/
public
function
run
()
{
FileLog
::
info
(
'Daemon:'
,
'start'
);
if
(
!
empty
(
$data
[
'LIMIT'
]))
{
$where
[
'LIMIT'
]
=
$data
[
'LIMIT'
];
}
...
...
@@ -26,6 +25,7 @@ class Wallet implements DaemonServiceInterface
}
$where
[
'can_notify_account'
]
=
1
;
$where
[
'notify_account_times[<]'
]
=
5
;
$where
[
'ORDER'
]
=
'can_notify_account_time ASC'
;
$where
[
'LIMIT'
]
=
[
0
,
10
];
...
...
@@ -38,7 +38,7 @@ class Wallet implements DaemonServiceInterface
}
if
(
empty
(
$list
))
{
sleep
(
10
);
sleep
(
1
2
0
);
}
}
}
\ 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