Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
yii2_fecshop
提交
1aa2ae33
Y
yii2_fecshop
项目概览
OpenDocCN
/
yii2_fecshop
通知
17
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
yii2_fecshop
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
1aa2ae33
编写于
1月 16, 2017
作者:
R
root
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
支付部分完善
上级
789039b2
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
64 addition
and
30 deletion
+64
-30
app/appfront/modules/Payment/PaymentController.php
app/appfront/modules/Payment/PaymentController.php
+19
-3
app/appfront/modules/Payment/controllers/CheckmoneyController.php
...ront/modules/Payment/controllers/CheckmoneyController.php
+29
-23
services/Order.php
services/Order.php
+6
-0
services/cart/Quote.php
services/cart/Quote.php
+8
-3
services/cart/QuoteItem.php
services/cart/QuoteItem.php
+2
-1
未找到文件。
app/appfront/modules/Payment/PaymentController.php
浏览文件 @
1aa2ae33
...
...
@@ -17,9 +17,25 @@ use fecshop\app\appfront\modules\AppfrontController;
*/
class
PaymentController
extends
AppfrontController
{
protected
$_increment_id
;
protected
$_order_model
;
public
function
init
(){
$homeUrl
=
Yii
::
$service
->
url
->
homeUrl
();
$this
->
_increment_id
=
Yii
::
$service
->
order
->
getSessionIncrementId
();
if
(
!
$this
->
_increment_id
){
Yii
::
$service
->
url
->
redirect
(
$homeUrl
);
exit
;
}
$this
->
_order_model
=
Yii
::
$service
->
order
->
GetByIncrementId
(
$this
->
_increment_id
);
if
(
!
isset
(
$this
->
_order_model
[
'increment_id'
])){
Yii
::
$service
->
url
->
redirect
(
$homeUrl
);
exit
;
}
parent
::
init
();
}
...
...
app/appfront/modules/Payment/controllers/CheckmoneyController.php
浏览文件 @
1aa2ae33
...
...
@@ -11,49 +11,55 @@ use Yii;
use
fec\helpers\CModule
;
use
fec\helpers\CRequest
;
use
fecshop\app\appfront\modules\AppfrontController
;
use
fecshop\app\appfront\modules\Payment\PaymentController
;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class
CheckmoneyController
extends
Appfro
ntController
class
CheckmoneyController
extends
Payme
ntController
{
public
$enableCsrfValidation
=
true
;
/**
* 支付开始页面
*/
public
function
actionStart
(){
$increment_id
=
Yii
::
$service
->
order
->
getSessionIncrementId
();
if
(
$increment_id
){
$orderModel
=
Yii
::
$service
->
order
->
GetByIncrementId
(
$increment_id
);
$payment_method
=
isset
(
$orderModel
[
'payment_method'
])
?
$orderModel
[
'payment_method'
]
:
''
;
if
(
$payment_method
){
$complateUrl
=
Yii
::
$service
->
payment
->
getStandardSuccessRedirectUrl
(
$payment_method
);
if
(
$complateUrl
){
Yii
::
$service
->
url
->
redirect
(
$complateUrl
);
exit
;
$payment_method
=
isset
(
$this
->
_order_model
[
'payment_method'
])
?
$this
->
_order_model
[
'payment_method'
]
:
''
;
if
(
$payment_method
){
$complateUrl
=
Yii
::
$service
->
payment
->
getStandardSuccessRedirectUrl
(
$payment_method
);
if
(
$complateUrl
){
# 登录用户,在支付前清空购物车。
if
(
!
Yii
::
$app
->
user
->
isGuest
){
Yii
::
$service
->
cart
->
clearCart
();
}
Yii
::
$service
->
url
->
redirect
(
$complateUrl
);
exit
;
}
}
$homeUrl
=
Yii
::
$service
->
url
->
homeUrl
();
Yii
::
$service
->
url
->
redirect
(
$homeUrl
);
}
/**
*
*
* 成功支付页面
*/
public
function
actionSuccess
(){
$increment_id
=
Yii
::
$service
->
order
->
getSessionIncrementId
();
if
(
$increment_id
){
$data
=
[
'increment_id'
=>
$increment_id
,
];
# 清理购物车中的产品。
$data
=
[
'increment_id'
=>
$this
->
_increment_id
,
];
# 清理购物车中的产品。(游客用户的购物车在成功页面清空)
if
(
Yii
::
$app
->
user
->
isGuest
){
Yii
::
$service
->
cart
->
clearCart
();
return
$this
->
render
(
'../../payment/checkmoney/success'
,
$data
);
}
else
{
$homeUrl
=
Yii
::
$service
->
url
->
homeUrl
();
Yii
::
$service
->
url
->
redirect
(
$homeUrl
);
}
# 清理session中的当前的increment_id
Yii
::
$service
->
order
->
removeSessionIncrementId
();
return
$this
->
render
(
'../../payment/checkmoney/success'
,
$data
);
}
/**
* IPN消息推送地址
* IPN过来后,不清除session中的 increment_id ,也不清除购物车
* 仅仅是更改订单支付状态。
*/
public
function
actionIpn
(){
}
...
...
services/Order.php
浏览文件 @
1aa2ae33
...
...
@@ -282,6 +282,12 @@ class Order extends Service
protected
function
actionGetSessionIncrementId
(){
return
Yii
::
$app
->
session
->
get
(
self
::
CURRENT_ORDER_CREAMENT_ID
);
}
/**
* 从session中销毁订单号
*/
protected
function
actionRemoveSessionIncrementId
(){
return
Yii
::
$app
->
session
->
remove
(
self
::
CURRENT_ORDER_CREAMENT_ID
);
}
/**
* @property $items | Array , example:
* $itmes = [
...
...
services/cart/Quote.php
浏览文件 @
1aa2ae33
...
...
@@ -146,11 +146,16 @@ class Quote extends Service
return
$items_count
;
}
/**
* @property $item_qty | Int ,当$item_qty 不等于null时,代表
* 已经知道购物车中产品的个数,不需要去cart_item表中查询。
* 譬如清空购物车操作,直接就知道产品个数肯定为零。
* 当购物车的产品变动后,更新cart表的产品总数
*/
public
function
computeCartInfo
(){
$item_qty
=
Yii
::
$service
->
cart
->
quoteItem
->
getItemQty
();
$cart
=
$this
->
getCart
();
public
function
computeCartInfo
(
$item_qty
=
null
){
if
(
$item_qty
===
null
){
$item_qty
=
Yii
::
$service
->
cart
->
quoteItem
->
getItemQty
();
}
$cart
=
$this
->
getCart
();
$cart
->
items_count
=
$item_qty
;
$cart
->
save
();
return
true
;
...
...
services/cart/QuoteItem.php
浏览文件 @
1aa2ae33
...
...
@@ -286,6 +286,7 @@ class QuoteItem extends Service
/**
* @property $cart_id | int 购物车id
* 删除购物车中的所有产品。
* 注意:清空购物车并不是清空所有信息,仅仅是清空用户购物车中的产品。
*/
public
function
removeItemByCartId
(
$cart_id
=
''
){
if
(
!
$cart_id
){
...
...
@@ -297,7 +298,7 @@ class QuoteItem extends Service
//'item_id' => $item_id,
]);
# 重新计算购物车的数量
Yii
::
$service
->
cart
->
quote
->
computeCartInfo
();
Yii
::
$service
->
cart
->
quote
->
computeCartInfo
(
0
);
}
return
true
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录