Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
projecttwo
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
wangtao
projecttwo
Commits
a56e3c25
Commit
a56e3c25
authored
May 28, 2025
by
wangzhengwen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wechatpay
parent
ae578b53
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
78 additions
and
19 deletions
+78
-19
PayController.php
app/api/controller/PayController.php
+13
-15
User.php
app/api/controller/User.php
+2
-1
User.php
app/api/controller/mine/User.php
+52
-0
PayService.php
app/api/service/PayService.php
+9
-2
WeChatPayService.php
app/api/service/WeChatPayService.php
+1
-1
UserValidate.php
app/api/validate/UserValidate.php
+1
-0
No files found.
app/api/controller/PayController.php
View file @
a56e3c25
...
...
@@ -33,7 +33,6 @@ class PayController
// if (!$validate->scene('create')->check($params)) {
// return json(['code' => 400, 'msg' => $validate->getError()]);
// }
// 创建支付订单
$result
=
PayService
::
createPayment
(
$params
[
'user_id'
],
...
...
@@ -180,25 +179,24 @@ class PayController
$orderNo
=
request
()
->
param
(
'order_no'
);
try
{
$payment
=
Db
::
name
(
'fj_payment'
)
->
where
(
'order_no'
,
$orderNo
)
->
find
();
$wechatPayService
=
new
WeChatPayService
();
$order
=
$wechatPayService
->
queryOrderByOutTradeNo
(
$orderNo
);
if
(
!
$
payment
)
{
if
(
!
$
order
)
{
throw
new
\Exception
(
"支付订单不存在"
);
}
return
json
([
'code'
=>
200
,
'data'
=>
[
'order_no'
=>
$payment
[
'order_no'
],
'pay_status'
=>
$payment
[
'pay_status'
],
'pay_time'
=>
$payment
[
'pay_time'
],
'pay_amount'
=>
$payment
[
'pay_amount'
]
]
]);
$res
=
json_decode
(
$order
,
true
);
if
(
$res
[
'trade_state'
]
==
'SUCCESS'
)
{
// 处理业务逻辑
$res
=
PayService
::
handlePaymentNotify
(
$order
[
'out_trade_no'
],
$order
);
return
json
([
'code'
=>
1
,
'msg'
=>
'success'
,
'data'
=>
$res
]);
}
else
{
throw
new
\Exception
(
"订单处理失败"
);
}
}
catch
(
\Exception
$e
)
{
return
json
([
'code'
=>
50
0
,
'msg'
=>
$e
->
getMessage
()]);
return
json
([
'code'
=>
0
,
'msg'
=>
$e
->
getMessage
()]);
}
}
}
\ No newline at end of file
app/api/controller/User.php
View file @
a56e3c25
...
...
@@ -53,7 +53,7 @@ class User extends BaseController
public
function
register
(
Request
$request
)
{
$vo
=
(
new
UserValidate
())
->
goCheck
([
'name'
,
'mobile'
,
'password'
,
'code'
]);
$vo
=
(
new
UserValidate
())
->
goCheck
([
'name'
,
'mobile'
,
'password'
,
'code'
,
'role'
]);
if
(
$vo
!==
true
)
{
return
$vo
;
}
...
...
@@ -76,6 +76,7 @@ class User extends BaseController
$user
[
'salt'
]
=
random
(
4
);
$user
[
'password'
]
=
md5
(
$data
[
'password'
]
.
$user
[
'salt'
]);
$user
[
'reg_time'
]
=
time
();
$user
[
'role'
]
=
$data
[
'role'
]
??
1
;
$res
=
userModel
::
insert
(
$user
);
if
(
!
$res
)
{
...
...
app/api/controller/mine/User.php
View file @
a56e3c25
...
...
@@ -6,9 +6,11 @@ use app\api\controller\PayController;
use
app\api\middleware\Auth
;
use
app\api\service\UserService
;
use
app\api\service\UtilService
;
use
app\api\validate\CertValidate
;
use
app\api\validate\CourseValidate
;
use
app\api\validate\UserValidate
;
use
app\BaseController
;
use
app\model\CertOrder
;
use
app\model\Course
as
CourseModel
;
use
app\model\project\Mail
;
use
app\model\project\UserAccount
;
...
...
@@ -229,6 +231,56 @@ class User extends BaseController
}
//证书购买
public
function
buyCert
(
\think\Request
$request
)
{
$vo
=
(
new
CertValidate
())
->
goCheck
([
'cert_id'
]);
if
(
$vo
!==
true
)
{
return
$vo
;
}
$data
=
$request
->
param
();
$userId
=
$request
->
userId
;
$course
=
\app\model\Cert
::
where
([
'id'
=>
$data
[
'cert_id'
],
'is_sell'
=>
1
,
'is_del'
=>
0
])
->
find
();
if
(
!
$course
)
{
return
$this
->
returnMsg
(
'证书不存在'
);
}
if
(
$course
[
'price'
]
<=
0
)
{
return
$this
->
returnMsg
(
'免费证书无需购买'
);
}
$courseOrder
=
CertOrder
::
where
([
'status'
=>
0
,
'user_id'
=>
$userId
,
'cert_id'
=>
$course
[
'id'
]])
->
count
();
if
(
!
$courseOrder
)
{
return
$this
->
returnMsg
(
'请先报名'
);
}
// 验证购买状态(2表示证书类型)
if
(
UtilService
::
checkPurchase
(
$userId
,
$data
[
'cert_id'
],
2
))
{
return
$this
->
returnMsg
(
'请勿重复购买'
);
}
$params
=
[
'order_id'
=>
$data
[
'cert_id'
],
'order_type'
=>
2
,
'pay_method'
=>
$data
[
'pay_method'
],
'amount'
=>
$course
[
'price'
],
'user_id'
=>
$userId
,
];
$payController
=
new
PayController
();
return
$payController
->
create
(
$params
);
}
public
function
editPassword
(
Request
$request
)
{
$vo
=
(
new
UserValidate
())
->
goCheck
([
'confirm_password'
,
'password'
,
'old_password'
]);
...
...
app/api/service/PayService.php
View file @
a56e3c25
...
...
@@ -32,8 +32,13 @@ class PayService
public
static
function
createPayment
(
$userId
,
$orderId
,
$amount
,
$payMethod
,
$orderType
,
$reqInfo
=
[])
{
try
{
$orderNoType
=
match
(
$orderType
)
{
1
=>
'kc'
,
2
=>
'zs'
,
default
=>
null
,
};
// 生成支付订单号
$orderNo
=
UtilService
::
generateCompactOrderNo
(
$userId
,
'kc'
);
$orderNo
=
UtilService
::
generateCompactOrderNo
(
$userId
,
$orderNoType
);
// 支付订单数据
$paymentData
=
[
...
...
@@ -156,7 +161,9 @@ class PayService
// Db::name('fj_course_order')->where('id', $payment['order_id'])->update(['status' => 1]);
}
elseif
(
$payment
[
'order_type'
]
==
self
::
ORDER_TYPE_CERT
)
{
// 处理证书购买逻辑
// Db::name('fj_cert_order')->where('id', $payment['order_id'])->update(['status' => 1]);
$res
=
Db
::
name
(
'cert_order'
)
->
where
(
'cert_id'
,
$payment
[
'order_id'
])
->
update
([
'status'
=>
1
]);
}
// 可以添加其他业务逻辑,如发送通知等
...
...
app/api/service/WeChatPayService.php
View file @
a56e3c25
...
...
@@ -181,7 +181,7 @@ class WeChatPayService
$platformPublicKeyInstance
);
if
(
!
$verifiedStatus
)
{
//
throw new \Exception("签名验证失败:");
throw
new
\Exception
(
"签名验证失败:"
);
}
// 转换通知的JSON文本消息为PHP Array数组
...
...
app/api/validate/UserValidate.php
View file @
a56e3c25
...
...
@@ -24,6 +24,7 @@ class UserValidate extends BaseValidate
'amount'
=>
'require|chenckAmount'
,
'txType'
=>
'require'
,
'reset_token'
=>
'require'
,
'role'
=>
'require'
,
];
protected
$message
=
[
...
...
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