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
92ac74f2
Commit
92ac74f2
authored
Aug 30, 2021
by
wanjilong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add: 支付订单调整优化
parent
9fe7b281
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
90 additions
and
3 deletions
+90
-3
PayException.php
application/exception/custom/PayException.php
+1
-0
PayOrder.php
application/models/order/mysql/PayOrder.php
+2
-1
Order.php
application/modules/Pay/controllers/Order.php
+10
-0
PayService.php
application/services/pay/PayService.php
+77
-2
No files found.
application/exception/custom/PayException.php
View file @
92ac74f2
...
@@ -30,6 +30,7 @@ class PayException extends BaseException
...
@@ -30,6 +30,7 @@ class PayException extends BaseException
15
=>
'订单存在过期商品,不能支付'
,
15
=>
'订单存在过期商品,不能支付'
,
16
=>
'订单过期,不允许支付'
,
16
=>
'订单过期,不允许支付'
,
17
=>
'订单缺少过期时间,请联系管理员'
,
17
=>
'订单缺少过期时间,请联系管理员'
,
18
=>
'订单不存在,请重试'
,
];
];
}
}
application/models/order/mysql/PayOrder.php
View file @
92ac74f2
...
@@ -18,13 +18,14 @@ class PayOrder extends MysqlBase
...
@@ -18,13 +18,14 @@ class PayOrder extends MysqlBase
self
::
beginTransaction
();
self
::
beginTransaction
();
try
{
try
{
$order
=
self
::
getMaster
(
'*'
,
[
'order_id'
=>
$order_id
,
'pay_channel'
=>
$pay_order
[
'pay_channel'
]
]);
$order
=
self
::
getMaster
(
'*'
,
[
'order_id'
=>
$order_id
]);
if
(
empty
(
$order
))
{
if
(
empty
(
$order
))
{
$cnt
=
self
::
insert
(
$pay_order
,
[
'rowCount'
=>
true
]);
$cnt
=
self
::
insert
(
$pay_order
,
[
'rowCount'
=>
true
]);
if
(
$cnt
)
{
if
(
$cnt
)
{
$order
=
$pay_order
;
$order
=
$pay_order
;
}
}
}
}
self
::
commit
();
self
::
commit
();
}
catch
(
\PDOException
$e
)
{
}
catch
(
\PDOException
$e
)
{
...
...
application/modules/Pay/controllers/Order.php
View file @
92ac74f2
...
@@ -50,6 +50,16 @@ class OrderController extends Base
...
@@ -50,6 +50,16 @@ class OrderController extends Base
}
}
public
function
chargesAction
()
{
$params
=
$this
->
getRequest
()
->
getPost
();
$order_id
=
$params
[
'order_id'
]
??
''
;
$paySrv
=
new
PayService
();
$ret
=
$paySrv
->
pay_charges
(
$order_id
);
$this
->
success
([
'result'
=>
$ret
]);
}
public
function
write_offAction
()
{
public
function
write_offAction
()
{
$params
=
$this
->
params
;
$params
=
$this
->
params
;
...
...
application/services/pay/PayService.php
View file @
92ac74f2
...
@@ -122,6 +122,11 @@ class PayService
...
@@ -122,6 +122,11 @@ class PayService
throw
new
PayException
([
'cus'
=>
4
]);
throw
new
PayException
([
'cus'
=>
4
]);
}
}
//不支持修改订单过期时间,再次调用支付服务
if
(
strtotime
(
$pay_order
[
'expire_time'
])
<
time
())
{
throw
new
PayException
([
'cus'
=>
16
]);
}
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'
=>
5
]);
throw
new
PayException
([
'cus'
=>
5
]);
}
}
...
@@ -170,13 +175,25 @@ class PayService
...
@@ -170,13 +175,25 @@ class PayService
$ret
[
'exist'
]
=
true
;
$ret
[
'exist'
]
=
true
;
}
}
$channel_exist
=
false
;
$channel
=
$this
->
getChannel
(
$pay_method_id
);
if
(
!
empty
(
$ret
[
'charges'
][
'data'
]))
{
//是否存在
foreach
(
$ret
[
'charges'
][
'data'
]
as
$ch
)
{
if
(
$ch
[
'channel'
]
==
$channel
)
{
$channel_exist
=
true
;
}
}
}
//判断是否做过pay操作 charge
//判断是否做过pay操作 charge
if
(
empty
(
$ret
[
'charge'
])
)
{
if
(
$channel_exist
==
false
)
{
// 创建支付单
// 创建支付单
$payment
=
[
$payment
=
[
'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'
=>
$
channel
,
'extra'
=>
$extra
,
'extra'
=>
$extra
,
];
];
...
@@ -290,6 +307,64 @@ class PayService
...
@@ -290,6 +307,64 @@ class PayService
return
[
'pay_order_id'
=>
$pay_order_id
];
return
[
'pay_order_id'
=>
$pay_order_id
];
}
}
/**
* @param $order_id
* @return array
* @throws BaseException
* @throws PayException
* 返回订单状态及订单渠道列表
*/
public
function
pay_charges
(
$order_id
)
{
$pay_order
=
PayOrder
::
get
(
'*'
,
[
'order_id'
=>
$order_id
]);
if
(
empty
(
$pay_order
))
{
throw
new
PayException
([
'cus'
=>
18
]);
}
$data
=
[
'status'
=>
'created'
,
'max_expire_time'
=>
$pay_order
[
'expire_time'
],
'list'
=>
[]
];
$max_expire_time
=
strtotime
(
$pay_order
[
'expire_time'
]);
if
(
$max_expire_time
<
time
())
{
$data
[
"status"
]
=
'canceled'
;
}
if
(
empty
(
$pay_order
[
'third_order_id'
]))
{
return
$data
;
}
//paid、refunded、canceled、created
$ret
=
PingxxService
::
getInstance
()
->
getOrder
(
$pay_order
[
'third_order_id'
]);
if
(
!
empty
(
$ret
[
'error'
]))
{
throw
new
BaseException
([
'msg'
=>
$ret
[
'error'
][
'message'
],
'code'
=>
'2301'
]);
}
$data
[
"status"
]
=
$ret
[
"status"
];
if
(
!
empty
(
$ret
[
'charges'
][
'data'
]))
{
//是否存在
foreach
(
$ret
[
'charges'
][
'data'
]
as
$ch
)
{
$data
[
"list"
][]
=
[
'paid'
=>
$ch
[
'paid'
],
'refunded'
=>
$ch
[
'refunded'
],
'channel'
=>
$ch
[
'channel'
],
'time_expire'
=>
$ch
[
'time_expire'
],
];
if
(
$max_expire_time
<
$ch
[
'time_expire'
])
{
$max_expire_time
=
$ch
[
'time_expire'
];
}
}
}
$data
[
'max_expire_time'
]
=
date
(
'Y-m-d H:i:s'
,
$max_expire_time
);
return
$data
;
}
/**
/**
* @param $order_item_id
* @param $order_item_id
* @param $life_account_id
* @param $life_account_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