Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
yii2_fecshop
提交
6d700f69
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 搜索 >>
提交
6d700f69
编写于
10月 15, 2017
作者:
T
Terry
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
appserver checkout onepage部分
上级
e33a12ee
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
165 addition
and
108 deletion
+165
-108
app/appserver/modules/Checkout/block/onepage/Index.php
app/appserver/modules/Checkout/block/onepage/Index.php
+5
-2
app/appserver/modules/Checkout/block/onepage/Placeorder.php
app/appserver/modules/Checkout/block/onepage/Placeorder.php
+131
-80
app/appserver/modules/Checkout/controllers/OnepageController.php
...server/modules/Checkout/controllers/OnepageController.php
+3
-13
services/Payment.php
services/Payment.php
+26
-13
未找到文件。
app/appserver/modules/Checkout/block/onepage/Index.php
浏览文件 @
6d700f69
...
...
@@ -29,7 +29,7 @@ class Index
protected
$_cartAddress
;
protected
$_cart_address
;
protected
$_cart_info
;
protected
$is_empty_cart
=
false
;
public
function
getLastData
()
{
$cartInfo
=
Yii
::
$service
->
cart
->
getCartInfo
();
...
...
@@ -54,11 +54,12 @@ class Index
'code'
=>
200
,
'payments'
=>
$this
->
getPayment
(),
'shippings'
=>
$shippings
,
'current_shipping_method'
=>
$this
->
_shipping_method
,
'current_payment_method'
=>
$this
->
_payment_method
,
'cart_info'
=>
$last_cart_info
,
'currency_info'
=>
$currency_info
,
//'address_view_file' => $this->_address_view_file,
//'is_empty_cart' => $this->is_empty_cart,
'isGuest'
=>
$isGuest
,
'address_list'
=>
$this
->
_address_list
,
...
...
@@ -316,6 +317,8 @@ class Index
$cart_info
[
'products'
][
$k
][
'image'
]
=
$custom_option_image
;
}
}
}
else
{
$this
->
is_empty_cart
=
true
;
}
$this
->
_cart_info
=
$cart_info
;
}
...
...
app/appserver/modules/Checkout/block/onepage/Placeorder.php
浏览文件 @
6d700f69
...
...
@@ -45,48 +45,67 @@ class Placeorder
if
(
$post
[
'payment_method'
]
==
$alipay_payment_key
){
Yii
::
$service
->
page
->
currency
->
setCurrentCurrency2CNY
();
}
// 检查前台传递的数据的完整
if
(
$this
->
checkOrderInfoAndInit
(
$post
))
{
// 如果游客用户勾选了注册账号,则注册,登录,并把地址写入到用户的address中
$gus_status
=
$this
->
guestCreateAndLoginAccount
(
$post
);
$save_address_status
=
$this
->
updateAddress
(
$post
);
if
(
$gus_status
&&
$save_address_status
)
{
// 更新Cart信息
//$this->updateCart();
// 设置checkout type
$serviceOrder
=
Yii
::
$service
->
order
;
$checkout_type
=
$serviceOrder
::
CHECKOUT_TYPE_STANDARD
;
$serviceOrder
->
setCheckoutType
(
$checkout_type
);
// 将购物车数据,生成订单。
$innerTransaction
=
Yii
::
$app
->
db
->
beginTransaction
();
try
{
# 生成订单,扣除库存,但是,不清空购物车。
$genarateStatus
=
Yii
::
$service
->
order
->
generateOrderByCart
(
$this
->
_billing
,
$this
->
_shipping_method
,
$this
->
_payment_method
,
false
);
if
(
$genarateStatus
)
{
// 得到当前的订单信息
//$orderInfo = Yii::$service->order->getCurrentOrderInfo();
// 发送新订单邮件
//Yii::$service->email->order->sendCreateEmail($orderInfo);
// 得到支付跳转前的准备页面。
$startUrl
=
Yii
::
$service
->
payment
->
getStandardStartUrl
();
$innerTransaction
->
commit
();
Yii
::
$service
->
url
->
redirect
(
$startUrl
);
// 检查前台传递的数据的完整
$checkInfo
=
$this
->
checkOrderInfoAndInit
(
$post
);
if
(
$checkInfo
!==
true
)
{
return
$checkInfo
;
}
// 如果游客用户勾选了注册账号,则注册,登录,并把地址写入到用户的address中
$gus_status
=
$this
->
guestCreateAndLoginAccount
(
$post
);
if
(
$gus_status
!==
true
)
{
return
$gus_status
;
}
$save_address
=
$this
->
updateAddress
(
$post
);
if
(
$save_address
!==
true
)
{
return
$save_address
;
}
// 更新Cart信息
//$this->updateCart();
// 设置checkout type
$serviceOrder
=
Yii
::
$service
->
order
;
$checkout_type
=
$serviceOrder
::
CHECKOUT_TYPE_STANDARD
;
$serviceOrder
->
setCheckoutType
(
$checkout_type
);
// 将购物车数据,生成订单。
$innerTransaction
=
Yii
::
$app
->
db
->
beginTransaction
();
try
{
# 生成订单,扣除库存,但是,不清空购物车。
$genarateStatus
=
Yii
::
$service
->
order
->
generateOrderByCart
(
$this
->
_billing
,
$this
->
_shipping_method
,
$this
->
_payment_method
,
false
);
if
(
$genarateStatus
)
{
// 得到当前的订单信息
//$orderInfo = Yii::$service->order->getCurrentOrderInfo();
// 发送新订单邮件
//Yii::$service->email->order->sendCreateEmail($orderInfo);
// 得到支付跳转前的准备页面。
$startUrl
=
Yii
::
$service
->
payment
->
getStandardStartUrl
(
''
,
'appserver'
);
$innerTransaction
->
commit
();
//Yii::$service->url->redirect($startUrl);
return
[
'code'
=>
200
,
'redirect'
=>
$startUrl
,
'content'
=>
'success'
,
];
return
true
;
}
else
{
$innerTransaction
->
rollBack
();
}
}
catch
(
Exception
$e
)
{
$innerTransaction
->
rollBack
();
}
return
true
;
}
else
{
$innerTransaction
->
rollBack
();
}
}
else
{
}
catch
(
Exception
$e
)
{
$innerTransaction
->
rollBack
();
}
}
return
[
'code'
=>
401
,
'content'
=>
'generate order fail'
,
];
//echo 333;exit;
Yii
::
$service
->
page
->
message
->
addByHelperErrors
();
//
Yii::$service->page->message->addByHelperErrors();
return
false
;
//
return false;
}
/**
...
...
@@ -98,37 +117,45 @@ class Placeorder
{
$create_account
=
$post
[
'create_account'
];
$billing
=
$post
[
'billing'
];
if
(
!
is_array
(
$billing
)
||
empty
(
$billing
))
{
Yii
::
$service
->
helper
->
errors
->
add
(
'billing must be array and can not empty'
);
return
false
;
}
//var_dump($create_account);
if
(
$create_account
)
{
//echo 22;
//echo $create_account;exit;
$customer_password
=
$billing
[
'customer_password'
];
$confirm_password
=
$billing
[
'confirm_password'
];
if
(
$customer_password
!=
$confirm_password
)
{
Yii
::
$service
->
helper
->
errors
->
add
(
'the passwords are inconsistent'
);
return
false
;
return
[
'code'
=>
401
,
'content'
=>
'the passwords are inconsistent'
,
];
}
$passMin
=
Yii
::
$service
->
customer
->
getRegisterPassMinLength
();
$passMax
=
Yii
::
$service
->
customer
->
getRegisterPassMaxLength
();
if
(
strlen
(
$customer_password
)
<
$passMin
)
{
Yii
::
$service
->
helper
->
errors
->
add
(
'password must Greater than '
.
$passMin
);
return
false
;
return
[
'code'
=>
401
,
'content'
=>
'password must Greater than '
.
$passMin
,
];
}
if
(
strlen
(
$customer_password
)
>
$passMax
)
{
Yii
::
$service
->
helper
->
errors
->
add
(
'password must less than '
.
$passMax
);
return
false
;
return
[
'code'
=>
401
,
'content'
=>
'password must less than '
.
$passMax
,
];
}
$param
[
'email'
]
=
$billing
[
'email'
];
$param
[
'password'
]
=
$billing
[
'customer_password'
];
$param
[
'firstname'
]
=
$billing
[
'first_name'
];
$param
[
'lastname'
]
=
$billing
[
'last_name'
];
if
(
!
Yii
::
$service
->
customer
->
register
(
$param
))
{
return
false
;
return
[
'code'
=>
401
,
'content'
=>
'customer register account fail'
,
];
}
else
{
Yii
::
$service
->
customer
->
Login
([
'email'
=>
$billing
[
'email'
],
...
...
@@ -174,19 +201,21 @@ class Placeorder
$address_id
=
Yii
::
$service
->
customer
->
address
->
save
(
$one
);
$this
->
_address_id
=
$address_id
;
if
(
!
$address_id
)
{
Yii
::
$service
->
helper
->
errors
->
add
(
'new customer address save fail'
);
return
false
;
return
[
'code'
=>
401
,
'content'
=>
'new customer address save fail'
,
];
}
//echo "$address_id,$this->_shipping_method,$this->_payment_method";
}
return
Yii
::
$service
->
cart
->
updateLoginCart
(
$this
->
_address_id
,
$this
->
_shipping_method
,
$this
->
_payment_method
);
Yii
::
$service
->
cart
->
updateLoginCart
(
$this
->
_address_id
,
$this
->
_shipping_method
,
$this
->
_payment_method
);
}
else
{
return
Yii
::
$service
->
cart
->
updateGuestCart
(
$this
->
_billing
,
$this
->
_shipping_method
,
$this
->
_payment_method
);
Yii
::
$service
->
cart
->
updateGuestCart
(
$this
->
_billing
,
$this
->
_shipping_method
,
$this
->
_payment_method
);
}
return
true
;
}
/**
...
...
@@ -215,25 +244,36 @@ class Placeorder
if
(
$address_id
)
{
$this
->
_address_id
=
$address_id
;
if
(
Yii
::
$app
->
user
->
isGuest
)
{
Yii
::
$service
->
helper
->
errors
->
add
(
'address id can not use for guest'
);
return
false
;
// address_id 这种情况,必须是登录用户。
return
[
'code'
=>
401
,
'content'
=>
'address id can not use for guest'
,
];
//return false; // address_id 这种情况,必须是登录用户。
}
else
{
$customer_id
=
Yii
::
$app
->
user
->
identity
->
id
;
if
(
!
$customer_id
)
{
Yii
::
$service
->
helper
->
errors
->
add
(
'customer id is empty'
);
return
false
;
return
[
'code'
=>
401
,
'content'
=>
'customer id is empty'
,
];
}
else
{
$address_one
=
Yii
::
$service
->
customer
->
address
->
getAddressByIdAndCustomerId
(
$address_id
,
$customer_id
);
if
(
!
$address_one
)
{
Yii
::
$service
->
helper
->
errors
->
add
(
'current address id is not belong to current user'
);
return
false
;
return
[
'code'
=>
401
,
'content'
=>
'current address id is not belong to current user'
,
];
}
else
{
// 从address_id中取出来的字段,查看是否满足必写的要求。
if
(
!
Yii
::
$service
->
order
->
checkRequiredAddressAttr
(
$address_one
))
{
return
false
;
return
[
'code'
=>
401
,
'content'
=>
'address id can not use for guest'
,
];
}
$arr
[
'customer_id'
]
=
$customer_id
;
foreach
(
$address_one
as
$k
=>
$v
)
{
...
...
@@ -247,7 +287,11 @@ class Placeorder
// 检查address的必写字段是否都存在
//var_dump($billing);exit;
if
(
!
Yii
::
$service
->
order
->
checkRequiredAddressAttr
(
$billing
))
{
return
false
;
return
[
'code'
=>
401
,
'content'
=>
'address require attr is empty'
,
];
}
$this
->
_billing
=
$billing
;
}
...
...
@@ -255,26 +299,33 @@ class Placeorder
$payment_method
=
isset
(
$post
[
'payment_method'
])
?
$post
[
'payment_method'
]
:
''
;
// 验证货运方式
if
(
!
$shipping_method
)
{
Yii
::
$service
->
helper
->
errors
->
add
(
'shipping method can not empty'
);
return
false
;
return
[
'code'
=>
401
,
'content'
=>
'shipping method can not empty'
,
];
}
else
{
if
(
!
Yii
::
$service
->
shipping
->
ifIsCorrect
(
$shipping_method
))
{
Yii
::
$service
->
helper
->
errors
->
add
(
'shipping method is not correct'
);
return
false
;
return
[
'code'
=>
401
,
'content'
=>
'shipping method is not correct'
,
];
}
}
// 验证支付方式
if
(
!
$payment_method
)
{
Yii
::
$service
->
helper
->
errors
->
add
(
'payment method can not empty'
);
return
false
;
return
[
'code'
=>
401
,
'content'
=>
'payment method can not empty'
,
];
}
else
{
if
(
!
Yii
::
$service
->
payment
->
ifIsCorrectStandard
(
$payment_method
))
{
Yii
::
$service
->
helper
->
errors
->
add
(
'payment method is not correct'
);
return
false
;
return
[
'code'
=>
401
,
'content'
=>
'payment method is not correct'
,
];
}
}
$this
->
_shipping_method
=
$shipping_method
;
...
...
app/appserver/modules/Checkout/controllers/OnepageController.php
浏览文件 @
6d700f69
...
...
@@ -46,19 +46,9 @@ class OnepageController extends AppserverController
'content'
=>
'you must login your account'
];
}
$submitOrder
=
Yii
::
$app
->
request
->
post
(
'submitOrder'
);
$status
=
$this
->
getBlock
(
'placeorder'
)
->
getLastData
();
if
(
!
$status
)
{
return
[
'code'
=>
'401'
,
'content'
=>
'generate order fail'
];
}
else
{
return
[
'code'
=>
'200'
,
'content'
=>
'generate order success'
];
}
return
$this
->
getBlock
(
'placeorder'
)
->
getLastData
();
}
...
...
services/Payment.php
浏览文件 @
6d700f69
...
...
@@ -50,7 +50,7 @@ class Payment extends Service
* @return 返回提交订单信息跳转到的第三方支付url,也就是第三方支付的url。
* #从配置信息中获取
*/
public
function
getStandardStartUrl
(
$payment_method
=
''
)
public
function
getStandardStartUrl
(
$payment_method
=
''
,
$type
=
''
)
{
if
(
!
$payment_method
)
{
$payment_method
=
$this
->
getPaymentMethod
();
...
...
@@ -59,11 +59,34 @@ class Payment extends Service
$paymentConfig
=
$this
->
paymentConfig
;
if
(
isset
(
$paymentConfig
[
'standard'
][
$payment_method
][
'start_url'
]))
{
if
(
!
empty
(
$paymentConfig
[
'standard'
][
$payment_method
][
'start_url'
]))
{
return
$this
->
getUrl
(
$paymentConfig
[
'standard'
][
$payment_method
][
'start_url'
]);
if
(
$type
==
'appserver'
){
return
$this
->
getAppServerUrl
(
$paymentConfig
[
'standard'
][
$payment_method
][
'start_url'
]);
}
else
{
return
$this
->
getUrl
(
$paymentConfig
[
'standard'
][
$payment_method
][
'start_url'
]);
}
}
}
}
}
public
function
getAppServerUrl
(
$url
){
$url
=
str_replace
(
'@homeUrl'
,
''
,
$url
);
return
trim
(
$url
);
}
/**
* @property $url | String url的字符串
* @return string 根据传递的字符串格式,得到相应的url
*/
protected
function
getUrl
(
$url
)
{
$homeUrl
=
Yii
::
$service
->
url
->
homeUrl
();
$url
=
str_replace
(
'@homeUrl'
,
$homeUrl
,
$url
);
return
trim
(
$url
);
}
/**
* @property $payment_method | String 支付方式。
...
...
@@ -224,17 +247,7 @@ class Payment extends Service
}
}
/**
* @property $url | String url的字符串
* @return string 根据传递的字符串格式,得到相应的url
*/
protected
function
getUrl
(
$url
)
{
$homeUrl
=
Yii
::
$service
->
url
->
homeUrl
();
$url
=
str_replace
(
'@homeUrl'
,
$homeUrl
,
$url
);
return
trim
(
$url
);
}
/**
* @return array 得到所有支付的数组,数组含有三个字段。
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录