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
9b9c9981
Commit
9b9c9981
authored
Jul 01, 2021
by
wanjilong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add: 调整订单支付逻辑,增加退款发送,增加退款回调
parent
11e8f98f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
109 additions
and
16 deletions
+109
-16
PayService.php
application/services/pay/PayService.php
+5
-5
RefundService.php
application/services/refund/RefundService.php
+104
-11
No files found.
application/services/pay/PayService.php
View file @
9b9c9981
...
@@ -318,13 +318,13 @@ class PayService
...
@@ -318,13 +318,13 @@ class PayService
'need_recorded'
=>
$account
[
'need_recorded'
],
'need_recorded'
=>
$account
[
'need_recorded'
],
];
];
if
(
$is_wx
)
{
//微信不计算手续费拆弹
return
true
;
}
foreach
(
$this
->
order_items
as
$r
)
{
foreach
(
$this
->
order_items
as
$r
)
{
if
(
$is_wx
)
{
$current_tip
=
Strategy
::
getTip
(
$r
[
'payment'
],
$total_amount
,
$cleared_amount
,
$total_tip
,
$cleared_tip
);
$current_tip
=
Strategy
::
getWxTip
(
$r
[
'payment'
],
$total_amount
,
$cleared_amount
,
$total_tip
,
$cleared_tip
);
}
else
{
$current_tip
=
Strategy
::
getTip
(
$r
[
'payment'
],
$total_amount
,
$cleared_amount
,
$total_tip
,
$cleared_tip
);
}
$this
->
clear_items_list
[]
=
[
$this
->
clear_items_list
[]
=
[
'pay_order_clearing_item_id'
=>
$this
->
gen_pay_order_clearing_item_id
(),
'pay_order_clearing_item_id'
=>
$this
->
gen_pay_order_clearing_item_id
(),
...
...
application/services/refund/RefundService.php
View file @
9b9c9981
...
@@ -19,7 +19,12 @@ use App\Exception\custom\RefundException;
...
@@ -19,7 +19,12 @@ use App\Exception\custom\RefundException;
class
RefundService
class
RefundService
{
{
/**
* @param $order_item_id
* @param $user_id
* @throws RefundException
* 发起退款请求
*/
public
function
do_refund
(
$order_item_id
,
$user_id
)
{
public
function
do_refund
(
$order_item_id
,
$user_id
)
{
// 获取子单信息
// 获取子单信息
...
@@ -27,26 +32,84 @@ class RefundService
...
@@ -27,26 +32,84 @@ class RefundService
if
(
empty
(
$order_item
))
{
if
(
empty
(
$order_item
))
{
throw
new
RefundException
([
'cus'
=>
1
]);
throw
new
RefundException
([
'cus'
=>
1
]);
}
}
$where
=
[
$where
=
[
'order_item_id'
=>
$order_item_id
,
'order_item_id'
=>
$order_item_id
,
'user_id'
=>
$user_id
,
'user_id'
=>
$user_id
,
'order_id'
=>
$order_item
[
'order_id'
],
'order_id'
=>
$order_item
[
'order_id'
],
'refund_amount'
=>
$order_item
[
'payment'
],
'refund_order_id'
=>
$this
->
gen_refund_order_id
(),
'refund_order_id'
=>
$this
->
gen_refund_order_id
(),
];
];
$refund_order
=
$this
->
can_refund
(
$where
);
$refund_order
=
$this
->
can_refund
(
$where
,
$order_item
);
// 重新计算手续费
// 发起ping++ 创建退款
try
{
// 通过发起一次退款请求创建一个新的 refund 对象,只能对已经发生交易并且没有全额退款的 charge 对象发起退款
$re
=
\Pingpp\Refund
::
create
(
$refund_order
[
'third_order_id'
],
[
'amount'
=>
$refund_order
[
'refund_amount'
],
'description'
=>
'订单申请退款'
,
'metadata'
=>
[
'refund_order_id'
=>
$refund_order
[
'refund_order_id'
]]
]
);
$ret
=
json_decode
(
$re
,
true
);
if
(
!
empty
(
$ret
[
"data"
]))
{
$edit
=
[
'request_pingxx_success_time'
=>
date
(
'Y-m-d H:i:s'
),
];
}
else
{
$edit
=
[
'refund_order_status'
=>
Dictionary
::
REFUND_ORDER_STATUS_UNDO
,
];
}
}
catch
(
\Pingpp\Error\Base
$e
)
{
$edit
=
[
'refund_order_status'
=>
Dictionary
::
REFUND_ORDER_STATUS_UNDO
,
];
Logger
::
error
(
$e
->
getHttpBody
());
}
RefundOrder
::
update
(
$edit
,
[
'refund_order_id'
=>
$refund_order
[
'refund_order_id'
]]);
}
public
function
call_back
(
$data
)
{
if
(
empty
(
$data
[
'data'
][
'object'
]))
{
Logger
::
error
(
'回调参数错误:'
,
$data
);
}
$object
=
$data
[
'data'
][
'object'
];
if
(
empty
(
$object
[
'metadata'
][
'refund_order_id'
]))
{
throw
new
RefundException
([
'cus'
=>
0
]);
}
$refund_order_id
=
$object
[
'metadata'
][
'refund_order_id'
];
try
{
// 查询 refund 对象列表
$re_list
=
\Pingpp\Refund
::
all
(
'ch_L8qn10mLmr1GS8e5OODmHaL4'
,
[
'limit'
=>
10
,
]);
echo
$re_list
;
// 输出 Ping++ 返回的 refund 对象列表
}
catch
(
\Pingpp\Error\Base
$e
)
{
if
(
$e
->
getHttpStatus
()
!=
null
)
{
header
(
'Status: '
.
$e
->
getHttpStatus
());
echo
$e
->
getHttpBody
();
}
else
{
echo
$e
->
getMessage
();
}
}
// 创建退款订单,计算微信退款手续费
// 修改订单支付状态,
// 发起ping++ 创建退款
$this
->
send_pingxx
(
$order_item
);
}
}
/**
/**
...
@@ -55,7 +118,7 @@ class RefundService
...
@@ -55,7 +118,7 @@ class RefundService
* @throws RefundException
* @throws RefundException
* 判断订单是否可退,判断是否存在退款申请
* 判断订单是否可退,判断是否存在退款申请
*/
*/
private
function
can_refund
(
$where
)
{
private
function
can_refund
(
$where
,
$order_item
)
{
/**
/**
* 业务方自行解决,订单关闭、订单超过时长不允许退款等逻辑
* 业务方自行解决,订单关闭、订单超过时长不允许退款等逻辑
...
@@ -86,16 +149,46 @@ class RefundService
...
@@ -86,16 +149,46 @@ class RefundService
}
else
{
}
else
{
$refund_order
=
$where
;
$refund_order
=
$where
;
$refund_order
[
'refund_order_status'
]
=
Dictionary
::
REFUND_ORDER_STATUS_
SEND
;
$refund_order
[
'refund_order_status'
]
=
Dictionary
::
REFUND_ORDER_STATUS_
UNDO
;
$refund_order
[
'refund_amount'
]
=
0
;
$refund_order
[
'refund_amount'
]
=
0
;
$cnt
=
RefundOrder
::
insert
(
$refund_order
,
[
'rowCount'
=>
true
]);
$cnt
=
RefundOrder
::
insert
(
$refund_order
,
[
'rowCount'
=>
true
]);
if
(
$cnt
==
0
)
{
if
(
$cnt
==
0
)
{
throw
new
RefundException
([
'cus'
=>
0
]);
throw
new
RefundException
([
'cus'
=>
0
]);
}
}
}
}
//重新计算微信手续费
$cleared_amount
=
$cleared_tip
=
0
;
// 总共手续费
$wx_tip
=
PayOrderClearing
::
getMaster
(
'*'
,
[
'order_id'
=>
$pay_order
[
'order_id'
],
'pay_order_id'
=>
$pay_order
[
'pay_order_id'
],
'pay_type'
=>
Dictionary
::
PAY_TYPE_IN
]
);
// 计算已退金额、已退手续费
$list
=
RefundOrder
::
selectMaster
(
'*'
,
[
'order_id'
=>
$where
[
'order_id'
]]);
foreach
(
$list
as
$r
)
{
if
(
$r
[
'refund_order_status'
]
==
Dictionary
::
REFUND_ORDER_STATUS_UNDO
)
{
continue
;
}
$cleared_amount
+=
$r
[
'refund_amount'
];
$cleared_tip
+=
$r
[
'refund_wx_tip'
];
}
$wx_tip
=
Strategy
::
getWxTip
(
$order_item
[
'payment'
],
$pay_order
[
'payment'
],
$cleared_amount
,
$wx_tip
[
'pay_amount'
],
$cleared_tip
);
$edit
=
[
'refund_order_status'
=>
Dictionary
::
REFUND_ORDER_STATUS_SEND
,
'refund_amount'
=>
$order_item
[
'payment'
],
'refund_wx_tip'
=>
$wx_tip
,
];
RefundOrder
::
update
(
$edit
,
[
'refund_order_id'
=>
$refund_order
[
'refund_order_id'
]]);
$refund_order
[
'third_order_id'
]
=
$pay_order
[
'third_order_id'
];
RefundOrder
::
commit
();
RefundOrder
::
commit
();
}
catch
(
\PDOException
$e
)
{
}
catch
(
\PDOException
$e
)
{
...
...
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