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
839a2016
Commit
839a2016
authored
Jul 13, 2021
by
wanjilong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add: 支持wx_pub 支付
parent
32fd971a
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
29 additions
and
18 deletions
+29
-18
PayException.php
application/exception/custom/PayException.php
+3
-0
Sdk.php
application/library/Helpers/Sdk.php
+2
-2
Order.php
application/modules/Pay/controllers/Order.php
+8
-1
OrderService.php
application/services/order/OrderService.php
+4
-4
PayService.php
application/services/pay/PayService.php
+9
-9
RefundService.php
application/services/refund/RefundService.php
+3
-2
No files found.
application/exception/custom/PayException.php
View file @
839a2016
...
@@ -12,6 +12,8 @@ class PayException extends BaseException
...
@@ -12,6 +12,8 @@ class PayException extends BaseException
protected
$cus
=
[
protected
$cus
=
[
0
=>
'系统错误,请稍收重试'
,
0
=>
'系统错误,请稍收重试'
,
1
=>
'订单服务获取订单信息失败。'
,
2
=>
'请确认订单信息及用户是否一致。'
,
3
=>
'该订单已经支付,请刷新确认'
,
3
=>
'该订单已经支付,请刷新确认'
,
4
=>
'费率计算错误,费率分母为0'
,
4
=>
'费率计算错误,费率分母为0'
,
5
=>
'支付回调失败,请核对订单'
,
5
=>
'支付回调失败,请核对订单'
,
...
@@ -25,5 +27,6 @@ class PayException extends BaseException
...
@@ -25,5 +27,6 @@ class PayException extends BaseException
13
=>
'生活号获取管理员ID失败,请联系管理员'
,
13
=>
'生活号获取管理员ID失败,请联系管理员'
,
14
=>
'支付订单预结算失败,结算资金不能负数,请核对配置'
,
14
=>
'支付订单预结算失败,结算资金不能负数,请核对配置'
,
15
=>
'支付订单金额与实际支付金额不等,请管理员关注'
,
15
=>
'支付订单金额与实际支付金额不等,请管理员关注'
,
16
=>
'支付订单创建失败,请管理员关注'
,
];
];
}
}
application/library/Helpers/Sdk.php
View file @
839a2016
...
@@ -3,6 +3,7 @@ namespace Helpers;
...
@@ -3,6 +3,7 @@ namespace Helpers;
use
Api\PhpUtils\Log\FileLog
;
use
Api\PhpUtils\Log\FileLog
;
use
Api\PhpUtils\Http\Request
;
use
Api\PhpUtils\Http\Request
;
use
App\Exception\BaseException
;
/**
/**
* Sdk 获取接口
* Sdk 获取接口
...
@@ -27,7 +28,6 @@ class Sdk {
...
@@ -27,7 +28,6 @@ class Sdk {
$headers = array_merge($headers, $header);
$headers = array_merge($headers, $header);
*/
*/
$data
=
(
new
Request
())
->
post
(
$url
,
$params
,
2000
,
'json'
);
$data
=
(
new
Request
())
->
post
(
$url
,
$params
,
2000
,
'json'
);
/*
/*
[
[
"http_code"=> 200,
"http_code"=> 200,
...
@@ -41,7 +41,7 @@ class Sdk {
...
@@ -41,7 +41,7 @@ class Sdk {
*/
*/
if
(
!
empty
(
$data
[
'response'
][
'code'
]))
{
if
(
!
empty
(
$data
[
'response'
][
'code'
]))
{
throw
new
\Exception
(
$data
[
'response'
][
'reason'
],
$data
[
'response'
][
'code'
]);
throw
new
BaseException
([
'msg'
=>
$data
[
'response'
][
'reason'
],
'code'
=>
$data
[
'response'
][
'code'
]
]);
}
}
return
$data
[
'response'
];
return
$data
[
'response'
];
...
...
application/modules/Pay/controllers/Order.php
View file @
839a2016
...
@@ -21,8 +21,15 @@ class OrderController extends Base
...
@@ -21,8 +21,15 @@ class OrderController extends Base
$order_id
=
$params
[
'order_id'
];
$order_id
=
$params
[
'order_id'
];
$pay_method_id
=
$params
[
'pay_method_id'
]
??
106
;
$pay_method_id
=
$params
[
'pay_method_id'
]
??
106
;
$extra
=
[];
if
(
!
empty
(
$params
[
'extra'
]))
{
if
(
is_string
(
$params
[
'extra'
]))
{
$extra
=
json_decode
(
$params
[
'extra'
],
true
);
}
}
$paySrv
=
new
PayService
();
$paySrv
=
new
PayService
();
$ret
=
$paySrv
->
do_pay
(
$order_id
,
$user_id
,
$pay_method_id
);
$ret
=
$paySrv
->
do_pay
(
$order_id
,
$user_id
,
$pay_method_id
,
$extra
);
//兼容C端客户端支付,调整返回结构,ping++ 返回 order,原生:微信、支付宝返回charge
//兼容C端客户端支付,调整返回结构,ping++ 返回 order,原生:微信、支付宝返回charge
$result
=
[];
$result
=
[];
...
...
application/services/order/OrderService.php
View file @
839a2016
...
@@ -13,14 +13,14 @@ class OrderService
...
@@ -13,14 +13,14 @@ class OrderService
* @param $userId
* @param $userId
* 调用内部服务获取用户订单、子单、分润信息
* 调用内部服务获取用户订单、子单、分润信息
*/
*/
public
static
function
getFullOrderData
(
$order_id
,
$user_id
)
{
public
static
function
getFullOrderData
(
$order_id
)
{
$url
=
config
(
'interface'
,
'order.order.pay_order'
);
$url
=
config
(
'interface'
,
'order.order.pay_order'
);
if
(
!
$url
)
{
if
(
!
$url
)
{
throw
new
CodeSpecialException
(
"failed"
.
__METHOD__
);
throw
new
CodeSpecialException
(
"failed"
.
__METHOD__
);
}
}
$params
=
[
'
user_id'
=>
$user_id
,
'
order_id'
=>
$order_id
];
$params
=
[
'order_id'
=>
$order_id
];
return
Sdk
::
call
(
$url
,
$params
);
return
Sdk
::
call
(
$url
,
$params
);
}
}
...
@@ -42,14 +42,14 @@ class OrderService
...
@@ -42,14 +42,14 @@ class OrderService
* @throws CodeSpecialException
* @throws CodeSpecialException
* 获取订单子单信息
* 获取订单子单信息
*/
*/
public
static
function
getOrderItemData
(
$order_item_id
,
$user_id
)
{
public
static
function
getOrderItemData
(
$order_item_id
)
{
//merchant.account.get_role_list
//merchant.account.get_role_list
$url
=
config
(
'interface'
,
'order.order.pay_order_item'
);
$url
=
config
(
'interface'
,
'order.order.pay_order_item'
);
if
(
!
$url
)
{
if
(
!
$url
)
{
throw
new
CodeSpecialException
(
"failed"
.
__METHOD__
);
throw
new
CodeSpecialException
(
"failed"
.
__METHOD__
);
}
}
$params
=
[
'
user_id'
=>
$user_id
,
'
order_item_id'
=>
$order_item_id
];
$params
=
[
'order_item_id'
=>
$order_item_id
];
return
Sdk
::
call
(
$url
,
$params
);
return
Sdk
::
call
(
$url
,
$params
);
}
}
}
}
\ No newline at end of file
application/services/pay/PayService.php
View file @
839a2016
...
@@ -20,6 +20,7 @@ use Helpers\Sdk;
...
@@ -20,6 +20,7 @@ use Helpers\Sdk;
use
Yaf\Application
;
use
Yaf\Application
;
use
App\Exception\custom\PayException
;
use
App\Exception\custom\PayException
;
use
App\Exception\BaseException
;
class
PayService
class
PayService
{
{
...
@@ -32,17 +33,17 @@ class PayService
...
@@ -32,17 +33,17 @@ class PayService
private
$clear_list
=
[];
private
$clear_list
=
[];
private
$clear_items_list
=
[];
private
$clear_items_list
=
[];
public
function
do_pay
(
$order_id
,
$user_id
,
$pay_method_id
=
10
6
)
public
function
do_pay
(
$order_id
,
$user_id
,
$pay_method_id
=
10
5
,
$extra
=
[]
)
{
{
// 获取订单信息
// 获取订单信息
$data
=
OrderService
::
getFullOrderData
(
$order_id
,
$user_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'
=>
1
]);
}
}
$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'
=>
1
]);
throw
new
PayException
([
'cus'
=>
2
]);
}
}
$metadata
=
[
$metadata
=
[
...
@@ -80,7 +81,7 @@ class PayService
...
@@ -80,7 +81,7 @@ 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'
=>
1
0
]);
throw
new
PayException
([
'cus'
=>
1
6
]);
}
}
if
(
$pay_order
[
'pay_order_status'
]
==
Dictionary
::
O_PAY_STATUS_PAYED
)
{
if
(
$pay_order
[
'pay_order_status'
]
==
Dictionary
::
O_PAY_STATUS_PAYED
)
{
...
@@ -95,7 +96,7 @@ class PayService
...
@@ -95,7 +96,7 @@ class PayService
}
}
if
(
!
empty
(
$ret
[
'error'
]))
{
if
(
!
empty
(
$ret
[
'error'
]))
{
throw
new
\Exception
(
$ret
[
'error'
][
'message'
],
'2301'
);
throw
new
BaseException
([
'msg'
=>
$ret
[
'error'
][
'message'
],
'code'
=>
'2301'
]
);
}
}
if
(
$ret
[
"status"
]
==
'paid'
||
$ret
[
'status'
]
==
'refunded'
)
{
if
(
$ret
[
"status"
]
==
'paid'
||
$ret
[
'status'
]
==
'refunded'
)
{
...
@@ -136,11 +137,12 @@ class PayService
...
@@ -136,11 +137,12 @@ class PayService
'charge_order_no'
=>
$pay_order
[
'pay_order_id'
],
'charge_order_no'
=>
$pay_order
[
'pay_order_id'
],
'charge_amount'
=>
$pay_order
[
'pay_amount'
],
'charge_amount'
=>
$pay_order
[
'pay_amount'
],
'channel'
=>
$this
->
getChannel
(
$pay_method_id
),
'channel'
=>
$this
->
getChannel
(
$pay_method_id
),
'extra'
=>
$extra
,
];
];
$pay
=
PingxxService
::
getInstance
()
->
pay
(
$ret
[
'id'
],
$payment
);
$pay
=
PingxxService
::
getInstance
()
->
pay
(
$ret
[
'id'
],
$payment
);
if
(
!
empty
(
$pay
[
'error'
]))
{
if
(
!
empty
(
$pay
[
'error'
]))
{
throw
new
\Exception
(
$pay
[
'error'
][
'message'
],
'2002'
);
throw
new
BaseException
([
'msg'
=>
$pay
[
'error'
][
'message'
],
'code'
=>
'2002'
]
);
}
}
return
$pay
;
return
$pay
;
...
@@ -148,8 +150,6 @@ class PayService
...
@@ -148,8 +150,6 @@ class PayService
}
else
{
}
else
{
return
$ret
;
return
$ret
;
}
}
}
}
/**
/**
...
@@ -429,7 +429,7 @@ class PayService
...
@@ -429,7 +429,7 @@ class PayService
$account
=
[
$account
=
[
'account_id'
=>
'100020003201'
,
'account_id'
=>
'100020003201'
,
'amount'
=>
0
,
'amount'
=>
0
,
'rate'
=>
300
0
,
'rate'
=>
0
,
'title'
=>
'平台收益'
,
'title'
=>
'平台收益'
,
];
];
...
...
application/services/refund/RefundService.php
View file @
839a2016
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
namespace
App\Services\refund
;
namespace
App\Services\refund
;
use
Api\PhpServices\Idgen\Idgen
;
use
Api\PhpServices\Idgen\Idgen
;
use
App\Exception\BaseException
;
use
App\Models\Dictionary
;
use
App\Models\Dictionary
;
use
App\Models\order\mysql\PayOrder
;
use
App\Models\order\mysql\PayOrder
;
use
App\Models\order\mysql\PayOrderClearing
;
use
App\Models\order\mysql\PayOrderClearing
;
...
@@ -33,7 +34,7 @@ class RefundService
...
@@ -33,7 +34,7 @@ class RefundService
public
function
do_refund
(
$order_item_id
,
$user_id
)
{
public
function
do_refund
(
$order_item_id
,
$user_id
)
{
// 获取子单信息
// 获取子单信息
$ret
=
OrderService
::
getOrderItemData
(
$order_item_id
,
$user_id
);
$ret
=
OrderService
::
getOrderItemData
(
$order_item_id
);
if
(
empty
(
$ret
[
'result'
]))
{
if
(
empty
(
$ret
[
'result'
]))
{
throw
new
RefundException
([
'cus'
=>
1
]);
throw
new
RefundException
([
'cus'
=>
1
]);
}
}
...
@@ -72,7 +73,7 @@ class RefundService
...
@@ -72,7 +73,7 @@ class RefundService
$edit
=
[
'request_pingxx_success_time'
=>
date
(
'Y-m-d H:i:s'
)];
$edit
=
[
'request_pingxx_success_time'
=>
date
(
'Y-m-d H:i:s'
)];
RefundOrder
::
update
(
$edit
,
[
'refund_order_id'
=>
$data
[
'refund_order'
][
'refund_order_id'
]]);
RefundOrder
::
update
(
$edit
,
[
'refund_order_id'
=>
$data
[
'refund_order'
][
'refund_order_id'
]]);
}
else
{
}
else
{
throw
new
\Exception
(
$ret
[
'error'
][
'message'
],
'2011'
);
throw
new
BaseException
([
'msg'
=>
$ret
[
'error'
][
'message'
],
'code'
=>
'2011'
]
);
}
}
return
[
'order_item_id'
=>
$order_item_id
];
return
[
'order_item_id'
=>
$order_item_id
];
...
...
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