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
08e4f4c9
Commit
08e4f4c9
authored
Jul 13, 2021
by
万继龙
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into 'test'
add: 调整合并pay支付文案 See merge request bp/pay!11
parents
ef27ee52
03804e85
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
63 additions
and
50 deletions
+63
-50
PayException.php
application/exception/custom/PayException.php
+17
-15
RefundException.php
application/exception/custom/RefundException.php
+9
-5
Order.php
application/modules/Pay/controllers/Order.php
+2
-0
PayService.php
application/services/pay/PayService.php
+21
-18
RefundService.php
application/services/refund/RefundService.php
+14
-12
No files found.
application/exception/custom/PayException.php
View file @
08e4f4c9
...
@@ -12,21 +12,23 @@ class PayException extends BaseException
...
@@ -12,21 +12,23 @@ class PayException extends BaseException
protected
$cus
=
[
protected
$cus
=
[
0
=>
'系统错误,请稍收重试'
,
0
=>
'系统错误,请稍收重试'
,
1
=>
'订单服务获取订单信息失败。'
,
1
=>
'请输入订单ID'
,
2
=>
'请确认订单信息及用户是否一致。'
,
2
=>
'订单服务获取订单信息失败。'
,
3
=>
'该订单已经支付,请刷新确认'
,
3
=>
'请确认订单信息及用户是否一致。'
,
4
=>
'费率计算错误,费率分母为0'
,
4
=>
'支付订单创建失败,请管理员关注'
,
5
=>
'支付回调失败,请核对订单'
,
5
=>
'该订单已经支付,请稍后刷新'
,
6
=>
'回调参数错误,请管理员关注'
,
6
=>
'该订单已超时取消关闭,请重新下单购买'
,
7
=>
'订单回调类型错误,请管理员关注'
,
8
=>
'退款中订单不允许核销,请管理员关注'
,
7
=>
'支付回调订单不存在,请管理员关注'
,
9
=>
'未支付订单不允许核销,请管理员关注'
,
8
=>
'支付订单金额与实际支付金额不等,请管理员关注'
,
10
=>
'仅允许核销商家自己的订单,请管理员关注'
,
9
=>
'退款中订单不允许核销,请管理员关注'
,
11
=>
'该订单已超时关闭,请重新下单'
,
10
=>
'未支付订单不允许核销,请管理员关注'
,
12
=>
'订单不存在,请核对'
,
11
=>
'商家仅允许核销自己的订单,请管理员关注'
,
12
=>
'支付订单预结算失败,结算资金不能负数,请核对配置'
,
13
=>
'生活号获取管理员ID失败,请联系管理员'
,
13
=>
'生活号获取管理员ID失败,请联系管理员'
,
14
=>
'支付订单预结算失败,结算资金不能负数,请核对配置'
,
15
=>
'支付订单金额与实际支付金额不等,请管理员关注'
,
16
=>
'支付订单创建失败,请管理员关注'
,
];
];
}
}
application/exception/custom/RefundException.php
View file @
08e4f4c9
...
@@ -12,16 +12,20 @@ class RefundException extends BaseException
...
@@ -12,16 +12,20 @@ class RefundException extends BaseException
protected
$cus
=
[
protected
$cus
=
[
0
=>
'系统异常请联系管理员'
,
0
=>
'系统异常请联系管理员'
,
1
=>
'
获取订单信息不存在,请核对
'
,
1
=>
'
缺少退款订单ID!
'
,
2
=>
'
退款已经成功操作
,请核对'
,
2
=>
'
获取订单信息返回错误
,请核对'
,
3
=>
'
退款进行中,请稍等
'
,
3
=>
'
仅支持自己操作订单退款!
'
,
4
=>
'目前仅支持支付后的订单退款,请核对'
,
4
=>
'目前仅支持支付后的订单退款,请核对'
,
5
=>
'该订单不允许退款,请核对'
,
5
=>
'已核销计算订单不支持退款!'
,
6
=>
'退款处理完成,请勿重复申请'
,
7
=>
'退款处理中请稍等'
,
6
=>
'该退款单核对ping++状态为未支付,请稍后重试!'
,
6
=>
'该退款单核对ping++状态为未支付,请稍后重试!'
,
7
=>
'已核销计算订单不支持退款!'
,
8
=>
'退款消息类型匹配失败,请管理员关注!'
,
8
=>
'退款消息类型匹配失败,请管理员关注!'
,
9
=>
'ping++退款消息格式错误,请管理员关注!'
,
9
=>
'ping++退款消息格式错误,请管理员关注!'
,
10
=>
'ping++退单状态异常,请管理员关注!'
,
10
=>
'ping++退单状态异常,请管理员关注!'
,
11
=>
'ping++退单缺少matadata!'
,
11
=>
'ping++退单缺少matadata!'
,
13
=>
'仅支持自己操作订单退款!'
,
];
];
}
}
application/modules/Pay/controllers/Order.php
View file @
08e4f4c9
...
@@ -25,6 +25,8 @@ class OrderController extends Base
...
@@ -25,6 +25,8 @@ class OrderController extends Base
if
(
!
empty
(
$params
[
'extra'
]))
{
if
(
!
empty
(
$params
[
'extra'
]))
{
if
(
is_string
(
$params
[
'extra'
]))
{
if
(
is_string
(
$params
[
'extra'
]))
{
$extra
=
json_decode
(
$params
[
'extra'
],
true
);
$extra
=
json_decode
(
$params
[
'extra'
],
true
);
}
else
{
$extra
=
$params
[
'extra'
];
}
}
}
}
...
...
application/services/pay/PayService.php
View file @
08e4f4c9
...
@@ -35,15 +35,18 @@ class PayService
...
@@ -35,15 +35,18 @@ class PayService
public
function
do_pay
(
$order_id
,
$user_id
,
$pay_method_id
=
105
,
$extra
=
[])
public
function
do_pay
(
$order_id
,
$user_id
,
$pay_method_id
=
105
,
$extra
=
[])
{
{
if
(
empty
(
$order_id
))
{
throw
new
PayException
([
'cus'
=>
1
]);
}
// 获取订单信息
// 获取订单信息
$data
=
OrderService
::
getFullOrderData
(
$order_id
);
$data
=
OrderService
::
getFullOrderData
(
$order_id
);
if
(
empty
(
$data
[
'result'
][
'order_info'
]))
{
if
(
empty
(
$data
[
'result'
][
'order_info'
]))
{
throw
new
PayException
([
'cus'
=>
1
]);
throw
new
PayException
([
'cus'
=>
2
]);
}
}
$order_info
=
$data
[
'result'
][
'order_info'
];
$order_info
=
$data
[
'result'
][
'order_info'
];
if
(
$order_info
[
'user_id'
]
!=
$user_id
)
{
if
(
$order_info
[
'user_id'
]
!=
$user_id
)
{
throw
new
PayException
([
'cus'
=>
2
]);
throw
new
PayException
([
'cus'
=>
3
]);
}
}
$metadata
=
[
$metadata
=
[
...
@@ -81,11 +84,11 @@ class PayService
...
@@ -81,11 +84,11 @@ class PayService
//获取或创建支付订单
//获取或创建支付订单
$pay_order
=
PayOrder
::
get_valid_order
(
$order_id
,
$new_pay_order
);
$pay_order
=
PayOrder
::
get_valid_order
(
$order_id
,
$new_pay_order
);
if
(
empty
(
$pay_order
))
{
if
(
empty
(
$pay_order
))
{
throw
new
PayException
([
'cus'
=>
16
]);
throw
new
PayException
([
'cus'
=>
4
]);
}
}
if
(
$pay_order
[
'pay_order_status'
]
==
Dictionary
::
O_PAY_STATUS_PAYED
)
{
if
(
$pay_order
[
'pay_order_status'
]
==
Dictionary
::
O_PAY_STATUS_PAYED
)
{
throw
new
PayException
([
'cus'
=>
3
]);
throw
new
PayException
([
'cus'
=>
5
]);
}
}
// 已经创建,需要查询返回
// 已经创建,需要查询返回
...
@@ -104,15 +107,15 @@ class PayService
...
@@ -104,15 +107,15 @@ class PayService
'pay_order_status'
=>
Dictionary
::
O_PAY_STATUS_PAYED
,
'pay_order_status'
=>
Dictionary
::
O_PAY_STATUS_PAYED
,
'third_order_id'
=>
$ret
[
'id'
],
'third_order_id'
=>
$ret
[
'id'
],
];
];
PayOrder
::
update
(
$edit
,
[
'pay_order_id'
=>
$pay_order
[
'pay_order_id'
]]);
//
PayOrder::update($edit, ['pay_order_id' => $pay_order['pay_order_id']]);
throw
new
PayException
([
'cus'
=>
3
]);
throw
new
PayException
([
'cus'
=>
5
]);
}
elseif
(
$ret
[
"status"
]
==
'canceled'
)
{
}
elseif
(
$ret
[
"status"
]
==
'canceled'
)
{
$edit
=
[
$edit
=
[
'expire_time'
=>
date
(
'Y-m-d H:i:s'
),
'expire_time'
=>
date
(
'Y-m-d H:i:s'
),
];
];
PayOrder
::
update
(
$edit
,
[
'pay_order_id'
=>
$pay_order
[
'pay_order_id'
]]);
PayOrder
::
update
(
$edit
,
[
'pay_order_id'
=>
$pay_order
[
'pay_order_id'
]]);
throw
new
PayException
([
'cus'
=>
11
]);
throw
new
PayException
([
'cus'
=>
6
]);
}
elseif
(
$ret
[
"status"
]
==
'created'
)
{
}
elseif
(
$ret
[
"status"
]
==
'created'
)
{
$edit
=
[
$edit
=
[
...
@@ -159,17 +162,17 @@ class PayService
...
@@ -159,17 +162,17 @@ class PayService
public
function
call_back
(
$data
)
public
function
call_back
(
$data
)
{
{
if
(
!
in_array
(
$data
[
'type'
],
[
'order.succeeded'
,
'charge.succeeded'
]))
{
if
(
!
in_array
(
$data
[
'type'
],
[
'order.succeeded'
,
'charge.succeeded'
]))
{
throw
new
PayException
([
'cus'
=>
7
])
;
return
[
'error'
=>
'支付回调类型不正确'
]
;
}
}
if
(
empty
(
$data
[
'data'
][
'object'
]))
{
if
(
empty
(
$data
[
'data'
][
'object'
]))
{
throw
new
PayException
([
'cus'
=>
6
])
;
return
[
'error'
=>
'支付回调格式不正确'
]
;
}
}
$object
=
$data
[
'data'
][
'object'
];
$object
=
$data
[
'data'
][
'object'
];
if
(
empty
(
$object
[
'metadata'
][
'app_id'
])
||
$object
[
'metadata'
][
'app_id'
]
!=
"merchant-c"
)
{
if
(
empty
(
$object
[
'metadata'
][
'app_id'
])
||
$object
[
'metadata'
][
'app_id'
]
!=
"merchant-c"
)
{
//非支付中心发出的订单,需要忽略
//非支付中心发出的订单,需要忽略
return
[
'
id'
=>
$object
[
'id'
]
];
return
[
'
error'
=>
'非merchant渠道订单,不做处理。'
];
}
}
if
(
$data
[
'type'
]
==
'charge.succeeded'
)
{
if
(
$data
[
'type'
]
==
'charge.succeeded'
)
{
...
@@ -183,15 +186,15 @@ class PayService
...
@@ -183,15 +186,15 @@ class PayService
}
}
if
(
$paid
!=
true
)
{
if
(
$paid
!=
true
)
{
throw
new
PayException
([
'cus'
=>
6
])
;
return
[
'error'
=>
'支付状态不正确,不做处理。'
]
;
}
}
$pay_order
=
PayOrder
::
get
(
'*'
,
[
'pay_order_id'
=>
$pay_order_id
]);
$pay_order
=
PayOrder
::
get
(
'*'
,
[
'pay_order_id'
=>
$pay_order_id
]);
if
(
empty
(
$pay_order
))
{
if
(
empty
(
$pay_order
))
{
throw
new
PayException
([
'cus'
=>
5
]);
throw
new
PayException
([
'cus'
=>
7
]);
}
}
if
(
$pay_order
[
'pay_amount'
]
!=
$amount
)
{
if
(
$pay_order
[
'pay_amount'
]
!=
$amount
)
{
throw
new
PayException
([
'cus'
=>
15
]);
throw
new
PayException
([
'cus'
=>
8
]);
}
}
// 修改状态,锁定业务
// 修改状态,锁定业务
...
@@ -242,23 +245,23 @@ class PayService
...
@@ -242,23 +245,23 @@ class PayService
$refund
=
RefundOrder
::
getMaster
(
'*'
,
[
'order_item_id'
=>
$order_item_id
]);
$refund
=
RefundOrder
::
getMaster
(
'*'
,
[
'order_item_id'
=>
$order_item_id
]);
if
(
!
empty
(
$refund
))
{
if
(
!
empty
(
$refund
))
{
throw
new
PayException
([
'cus'
=>
8
]);
throw
new
PayException
([
'cus'
=>
9
]);
}
}
$item
=
PayOrderItem
::
getMaster
(
'*'
,
[
'order_item_id'
=>
$order_item_id
]);
$item
=
PayOrderItem
::
getMaster
(
'*'
,
[
'order_item_id'
=>
$order_item_id
]);
if
(
empty
(
$item
))
{
if
(
empty
(
$item
))
{
throw
new
PayException
([
'cus'
=>
9
]);
throw
new
PayException
([
'cus'
=>
10
]);
}
}
$pay_order
=
PayOrder
::
getMaster
(
'*'
,
[
'pay_order_id'
=>
$item
[
'pay_order_id'
]]);
$pay_order
=
PayOrder
::
getMaster
(
'*'
,
[
'pay_order_id'
=>
$item
[
'pay_order_id'
]]);
if
(
empty
(
$pay_order
)
||
$pay_order
[
'life_account_id'
]
!=
$life_account_id
)
{
if
(
empty
(
$pay_order
)
||
$pay_order
[
'life_account_id'
]
!=
$life_account_id
)
{
throw
new
PayException
([
'cus'
=>
1
0
]);
throw
new
PayException
([
'cus'
=>
1
1
]);
}
}
PayOrderItem
::
commit
();
PayOrderItem
::
commit
();
}
catch
(
\Exception
$e
)
{
}
catch
(
\Exception
$e
)
{
PayOrderItem
::
rollback
();
PayOrderItem
::
rollback
();
throw
$e
;
throw
new
BaseException
([
'msg'
=>
$e
->
getMessage
(),
'code'
=>
$e
->
getCode
()])
;
}
}
if
(
$cnt
==
0
)
{
//幂等直接返回
if
(
$cnt
==
0
)
{
//幂等直接返回
...
@@ -356,7 +359,7 @@ class PayService
...
@@ -356,7 +359,7 @@ class PayService
if
(
$wx_tip
<
0
||
$distribution_tip
<
0
||
$platform_tip
<
0
||
$merchant_cash
<
0
)
{
if
(
$wx_tip
<
0
||
$distribution_tip
<
0
||
$platform_tip
<
0
||
$merchant_cash
<
0
)
{
FileLog
::
error
(
'pay-service: 支付预结算失败,结算资金为负'
,
FileLog
::
error
(
'pay-service: 支付预结算失败,结算资金为负'
,
json_encode
([
$this
->
order_info
[
'payment'
],
$wx_tip
,
$distribution_tip
,
$platform_tip
,
$merchant_cash
]));
json_encode
([
$this
->
order_info
[
'payment'
],
$wx_tip
,
$distribution_tip
,
$platform_tip
,
$merchant_cash
]));
throw
new
PayException
([
'cus'
=>
1
4
]);
throw
new
PayException
([
'cus'
=>
1
2
]);
}
}
$this
->
make_merchant_clearing
(
$merchant_cash
);
//商户收益
$this
->
make_merchant_clearing
(
$merchant_cash
);
//商户收益
...
...
application/services/refund/RefundService.php
View file @
08e4f4c9
...
@@ -33,14 +33,17 @@ class RefundService
...
@@ -33,14 +33,17 @@ class RefundService
*/
*/
public
function
do_refund
(
$order_item_id
,
$user_id
)
{
public
function
do_refund
(
$order_item_id
,
$user_id
)
{
if
(
empty
(
$order_item_id
))
{
throw
new
RefundException
([
'cus'
=>
1
]);
}
// 获取子单信息
// 获取子单信息
$ret
=
OrderService
::
getOrderItemData
(
$order_item_id
);
$ret
=
OrderService
::
getOrderItemData
(
$order_item_id
);
if
(
empty
(
$ret
[
'result'
]))
{
if
(
empty
(
$ret
[
'result'
]))
{
throw
new
RefundException
([
'cus'
=>
1
]);
throw
new
RefundException
([
'cus'
=>
2
]);
}
}
if
(
empty
(
$ret
[
'result'
][
'user_id'
]
!=
$user_id
))
{
if
(
empty
(
$ret
[
'result'
][
'user_id'
]
!=
$user_id
))
{
throw
new
RefundException
([
'cus'
=>
1
]);
throw
new
RefundException
([
'cus'
=>
3
]);
}
}
$order_item
=
$ret
[
'result'
];
$order_item
=
$ret
[
'result'
];
...
@@ -94,17 +97,17 @@ class RefundService
...
@@ -94,17 +97,17 @@ class RefundService
public
function
call_back
(
$data
)
{
public
function
call_back
(
$data
)
{
if
(
!
in_array
(
$data
[
'type'
],
[
'refund.succeeded'
,
'order.refunded'
]))
{
if
(
!
in_array
(
$data
[
'type'
],
[
'refund.succeeded'
,
'order.refunded'
]))
{
throw
new
RefundException
([
'cus'
=>
8
])
;
return
[
'error'
=>
'退款回调类型不正确'
]
;
}
}
if
(
empty
(
$data
[
'data'
][
'object'
]))
{
if
(
empty
(
$data
[
'data'
][
'object'
]))
{
throw
new
RefundException
([
'cus'
=>
9
])
;
return
[
'error'
=>
'退款回调格式不正确'
]
;
}
}
$object
=
$data
[
'data'
][
'object'
];
$object
=
$data
[
'data'
][
'object'
];
if
(
empty
(
$object
[
'metadata'
][
'app_id'
])
||
$object
[
'metadata'
][
'app_id'
]
!=
"merchant-c"
)
{
if
(
empty
(
$object
[
'metadata'
][
'app_id'
])
||
$object
[
'metadata'
][
'app_id'
]
!=
"merchant-c"
)
{
//非支付中心发出的订单,需要忽略
//非支付中心发出的订单,需要忽略
return
[
'
id'
=>
$object
[
'id'
]
];
return
[
'
error'
=>
'非merchant渠道订单,不做处理。'
];
}
}
if
(
$data
[
'type'
]
==
'refund.succeeded'
)
{
if
(
$data
[
'type'
]
==
'refund.succeeded'
)
{
...
@@ -116,12 +119,11 @@ class RefundService
...
@@ -116,12 +119,11 @@ class RefundService
}
}
if
(
$refunded
!=
true
)
{
if
(
$refunded
!=
true
)
{
throw
new
RefundException
([
'cus'
=>
10
])
;
return
[
'error'
=>
'退款状态不正确,不做处理。'
]
;
}
}
$object
=
$data
[
'data'
][
'object'
];
if
(
empty
(
$object
[
'metadata'
][
'refund_order_id'
]))
{
if
(
empty
(
$object
[
'metadata'
][
'refund_order_id'
]))
{
throw
new
RefundException
([
'cus'
=>
11
])
;
return
[
'error'
=>
'退款订单缺少matadata,不做处理。'
]
;
}
}
// 修改状态,锁定业务
// 修改状态,锁定业务
...
@@ -163,17 +165,17 @@ class RefundService
...
@@ -163,17 +165,17 @@ class RefundService
throw
new
RefundException
([
'cus'
=>
4
]);
throw
new
RefundException
([
'cus'
=>
4
]);
}
}
if
(
$pay_order_item
[
'can_notify_account'
]
==
1
)
{
if
(
$pay_order_item
[
'can_notify_account'
]
==
1
)
{
throw
new
RefundException
([
'cus'
=>
7
]);
throw
new
RefundException
([
'cus'
=>
5
]);
}
}
$refund_order
=
RefundOrder
::
getMaster
(
'*'
,
[
'order_item_id'
=>
$where
[
'order_item_id'
]]);
$refund_order
=
RefundOrder
::
getMaster
(
'*'
,
[
'order_item_id'
=>
$where
[
'order_item_id'
]]);
if
(
!
empty
(
$refund_order
))
{
if
(
!
empty
(
$refund_order
))
{
if
(
$refund_order
[
'refund_order_status'
]
==
Dictionary
::
REFUND_ORDER_STATUS_OK
)
{
if
(
$refund_order
[
'refund_order_status'
]
==
Dictionary
::
REFUND_ORDER_STATUS_OK
)
{
throw
new
RefundException
([
'cus'
=>
2
]);
throw
new
RefundException
([
'cus'
=>
6
]);
}
}
if
(
$refund_order
[
'refund_order_status'
]
==
Dictionary
::
REFUND_ORDER_STATUS_SEND
)
{
if
(
$refund_order
[
'refund_order_status'
]
==
Dictionary
::
REFUND_ORDER_STATUS_SEND
)
{
throw
new
RefundException
([
'cus'
=>
3
]);
throw
new
RefundException
([
'cus'
=>
7
]);
}
}
}
else
{
}
else
{
...
@@ -231,7 +233,7 @@ class RefundService
...
@@ -231,7 +233,7 @@ class RefundService
}
catch
(
\PDOException
$e
)
{
}
catch
(
\PDOException
$e
)
{
RefundOrder
::
rollback
();
RefundOrder
::
rollback
();
throw
$e
;
throw
new
BaseException
([
'msg'
=>
$e
->
getMessage
(),
'code'
=>
$e
->
getCode
()])
;
}
}
return
$data
;
return
$data
;
...
...
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