Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
YOHOBUYWAP
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
hf
9 years ago
Commit
93c59e1e165cf2b07daac5db5e206a964cb2f42b
1 parent
9a1c313e
code review by fei.hong: do modify cache config to aliyun vpc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
587 additions
and
0 deletions
yohobuy/www.yohobuy.com/application/modules/Cart/controllers/Index.php
yohobuy/www.yohobuy.com/application/modules/Cart/controllers/Index.php
0 → 100644
View file @
93c59e1
<?php
use
Action\WebAction
;
use
WebPlugin\Helpers
;
use
Shopping\CartModel
;
use
Product\ItemModel
;
/**
* 购物车相关的控制器
*
* @name IndexController
* @package Cart
* @copyright yoho.inc
* @version 1.0 (2016-2-17 15:43:19)
* @author fei.hong <fei.hong@yoho.cn>
*/
class
IndexController
extends
WebAction
{
/**
* 通过当前用户审判是否跳到登录
*
* @param boolean $useSession (true:从服务端session中检查, false:从客户端cookie中检查)
* @pram string $refer 指定的来源地址
* @return void
*/
protected
function
auditJumpLogin
(
$useSession
=
true
,
$refer
=
''
)
{
$uid
=
$this
->
getUid
(
$useSession
);
if
(
!
$uid
)
{
if
(
empty
(
$refer
))
{
$refer
=
$this
->
server
(
'HTTP_REFERER'
,
SITE_MAIN
);
}
$this
->
go
(
Helpers
::
url
(
'/signin.html'
,
array
(
'refer'
=>
$refer
)));
}
}
/**
* 我的购物车
*/
public
function
indexAction
()
{
$uid
=
$this
->
getUid
(
true
);
$shoppingKey
=
Helpers
::
getShoppingKeyByCookie
();
// 显示一次并清除已删除的COOKIE记录
$cartDelList
=
$this
->
getCookie
(
'cart-del-list'
);
if
(
!
empty
(
$cartDelList
))
{
$this
->
setCookie
(
'cart-del-list'
,
''
);
}
$this
->
setTitle
(
'购物车'
,
true
,
' | '
);
$this
->
setSimpleHeader
();
$this
->
_view
->
display
(
'cart'
,
array
(
'cartEnsurePage'
=>
true
,
'cartEnsure'
=>
CartModel
::
myCartData
(
$uid
,
$shoppingKey
,
$cartDelList
),
));
}
/**
* 购物车商品选择与取消
*
* @param string skuList 商品sku列表,json格式,如{"744403":1,"777777":3}
* @return json
*/
public
function
selectAction
()
{
$result
=
array
();
if
(
$this
->
isAjax
())
{
$productId
=
$this
->
post
(
'skuList'
,
0
);
$uid
=
$this
->
getUid
(
true
);
$shoppingKey
=
Helpers
::
getShoppingKeyByCookie
();
$result
=
CartModel
::
selectGoods
(
$uid
,
$productId
,
$shoppingKey
);
}
$this
->
echoJson
(
$result
);
}
/**
* 修改购物车商品数量
*
* @param int sku
* @param int increaseNum
* @param int decreaseNum
* @return json
*/
public
function
modifyAction
()
{
$result
=
array
();
if
(
$this
->
isAjax
())
{
$shoppingKey
=
Helpers
::
getShoppingKeyByCookie
();
$uid
=
$this
->
getUid
(
true
);
$sku
=
$this
->
post
(
'sku'
,
0
);
$increaseNum
=
$this
->
post
(
'increaseNum'
,
null
);
$decreaseNum
=
$this
->
post
(
'decreaseNum'
,
null
);
$result
=
CartModel
::
modifyProductNum
(
$uid
,
$sku
,
$increaseNum
,
$decreaseNum
,
$shoppingKey
);
if
(
!
empty
(
$result
[
'code'
])
&&
$result
[
'code'
]
==
200
)
{
$this
->
setShoppingCookie
(
$uid
);
}
}
$this
->
echoJson
(
$result
);
}
/**
* 移出购物车
*
* @param string skuList 商品sku列表,json格式,如{"744403":1,"777777":3}
* @return json
*/
public
function
removeAction
()
{
$result
=
array
();
if
(
$this
->
isAjax
())
{
$skuList
=
$this
->
post
(
'skuList'
,
0
);
$uid
=
$this
->
getUid
(
true
);
$shoppingKey
=
Helpers
::
getShoppingKeyByCookie
();
$result
=
CartModel
::
removeFromCart
(
$uid
,
$skuList
,
$shoppingKey
);
if
(
!
empty
(
$result
[
'code'
])
&&
$result
[
'code'
]
==
200
)
{
$this
->
setShoppingCookie
(
$uid
);
}
}
$this
->
echoJson
(
$result
);
}
/**
* 移入收藏夹
*
* 支持批量移入收藏夹
*
* @param string 商品sku列表,json格式,如{"744403":1,"777777":3}
* @return json
*/
public
function
favAction
()
{
$result
=
array
();
if
(
$this
->
isAjax
())
{
$skuList
=
$this
->
post
(
'skuList'
);
$uid
=
$this
->
getUid
(
true
);
$result
=
CartModel
::
addToFav
(
$uid
,
$skuList
);
if
(
!
empty
(
$result
[
'code'
])
&&
$result
[
'code'
]
==
200
)
{
$this
->
setShoppingCookie
(
$uid
);
}
}
$this
->
echoJson
(
$result
);
}
/**
* 检查是否收藏
*
* @param string sknList 商品productId列表,如["123123","123412"]
*/
public
function
checkFavAction
()
{
$result
=
array
(
'code'
=>
200
,
'message'
=>
'是否收藏'
,
'data'
=>
array
());
if
(
$this
->
isAjax
())
{
$uid
=
$this
->
getUid
(
false
);
$pidList
=
$this
->
post
(
'pidList'
,
''
);
$result
[
'data'
]
=
CartModel
::
checkUserIsFav
(
$uid
,
$pidList
);
}
$this
->
echoJson
(
$result
);
}
/**
* 凑单商品异步请求
*/
public
function
getTogetherProductAction
()
{
$result
=
array
(
'code'
=>
200
,
'data'
=>
array
(),
'message'
=>
'凑单商品'
);
if
(
$this
->
isAjax
())
{
$page
=
$this
->
get
(
'page'
,
1
);
$result
=
CartModel
::
getTogetherProduct
(
$page
);
}
$this
->
echoJson
(
$result
);
}
/**
* 最近浏览的商品异步请求
*/
public
function
getHistroyProductAction
()
{
$result
=
array
(
'code'
=>
200
,
'data'
=>
array
(),
'message'
=>
'浏览记录'
);
do
{
if
(
!
$this
->
isAjax
())
{
break
;
}
$page
=
$this
->
get
(
'page'
,
1
);
// $uid = $this->getUid(false);
// if ($uid) {
// $udid = $this->getUdid();
// $result = CartModel::getBrowseProduct($uid, $udid, $page);
// break;
// }
$sknList
=
$this
->
getCookie
(
'_browseskn'
);
if
(
empty
(
$sknList
))
{
break
;
}
$sknList
=
explode
(
','
,
rawurldecode
(
$sknList
));
$result
=
CartModel
::
getNamedBrowseProduct
(
$page
,
6
,
$sknList
);
}
while
(
false
);
$this
->
echoJson
(
$result
);
}
/**
* 确认订单
*/
public
function
orderEnsureAction
()
{
$type
=
$this
->
get
(
'type'
,
1
);
$refer
=
Helpers
::
url
(
'/cart/index/orderEnsure'
,
array
(
'type'
=>
$type
));
// 审判用户是否已登录
$this
->
auditJumpLogin
(
true
,
$refer
);
$this
->
setTitle
(
'填写订单'
,
true
,
' | '
);
$this
->
setSimpleHeader
();
$cartType
=
(
$type
==
2
)
?
'advance'
:
'ordinary'
;
$isAdvanceCart
=
(
$type
==
2
)
?
true
:
false
;
$uid
=
$this
->
getUid
(
true
);
$orderEnsure
=
CartModel
::
cartPay
(
$uid
,
$cartType
,
$isAdvanceCart
);
if
(
empty
(
$orderEnsure
))
{
$this
->
go
(
Helpers
::
url
(
'/shopping/cart'
));
}
$this
->
_view
->
display
(
'order-ensure'
,
array
(
'orderEnsurePage'
=>
true
,
'orderEnsure'
=>
$orderEnsure
,
));
}
/**
* 异步获取地址信息
*
* @return json
*/
public
function
getAddressAction
()
{
$result
=
array
(
'code'
=>
200
,
'data'
=>
array
(),
'message'
=>
'地址信息'
);
if
(
$this
->
isAjax
())
{
$uid
=
$this
->
getUid
(
true
);
$result
[
'data'
]
=
CartModel
::
userAddressList
(
$uid
);
}
$this
->
echoJson
(
$result
);
}
/**
* 设置为默认的地址
*
* @param int id 地址ID
* @return json
*/
public
function
setDefaultAddressAction
()
{
$result
=
array
();
if
(
$this
->
isAjax
())
{
$uid
=
$this
->
getUid
(
true
);
$addressId
=
$this
->
post
(
'id'
);
$result
=
CartModel
::
setDefaultAddress
(
$uid
,
$addressId
);
}
$this
->
echoJson
(
$result
);
}
/**
* 保存地址信息
*
* @param int $id 地址ID ,当修改操作的时候需要传,添加时候不需要传
* @param string $address 地址信息
* @param int $areaCode 城市码
* @param string $consignee 收货人
* @param string $email 邮箱地址
* @param string $mobile 手机号码
* @param string $zipCode 邮编
* @return json
*/
public
function
saveAddressAction
()
{
$result
=
array
();
if
(
$this
->
isAjax
())
{
$uid
=
$this
->
getUid
(
true
);
$id
=
$this
->
post
(
'id'
,
null
);
$address
=
$this
->
post
(
'address'
,
''
);
$areaCode
=
$this
->
post
(
'areaCode'
,
''
);
$consignee
=
$this
->
post
(
'consignee'
,
''
);
$email
=
$this
->
post
(
'email'
,
''
);
$mobile
=
$this
->
post
(
'mobile'
,
''
);
$zipCode
=
$this
->
post
(
'zipCode'
,
''
);
$result
=
CartModel
::
saveAddressData
(
$uid
,
$address
,
$areaCode
,
$consignee
,
$email
,
$id
,
$mobile
,
$zipCode
);
}
$this
->
echoJson
(
$result
);
}
/**
* 删除地址
*
* @param int id 地址ID
*/
public
function
delAddressAction
()
{
$result
=
array
();
if
(
$this
->
isAjax
())
{
$uid
=
$this
->
getUid
(
true
);
$addressId
=
$this
->
post
(
'id'
);
$result
=
CartModel
::
delAddress
(
$uid
,
$addressId
);
}
$this
->
echoJson
(
$result
);
}
/**
* 获取省市区县信息列表
*
* @param int id
* @return json
*/
public
function
getAreaListAction
()
{
$result
=
array
(
'code'
=>
200
,
'message'
=>
'地区信息'
,
'data'
=>
array
());
if
(
$this
->
isAjax
())
{
$id
=
$this
->
get
(
'id'
,
0
);
$result
[
'data'
]
=
CartModel
::
getAreaList
(
$id
);
}
$this
->
echoJson
(
$result
);
}
/**
* 获取优惠券列表
*
* @return json
*/
public
function
getCouponListAction
()
{
$result
=
array
(
'code'
=>
200
,
'message'
=>
'优惠券信息'
,
'data'
=>
array
());
if
(
$this
->
isAjax
())
{
$uid
=
$this
->
getUid
(
true
);
$result
[
'data'
]
=
CartModel
::
getCouponList
(
$uid
);
}
$this
->
echoJson
(
$result
);
}
/**
* 购物车选择改变字段,重新运算订单数据
*
* @param string $cartType 购物车类型,ordinary表示普通, advance表示预售
* @param int $deliveryWay 配送方式,1表示普通快递,2表示顺丰速运
* @param int $paymentType 支付方式,1表示在线支付,2表示货到付款
* @param string $couponCode 优惠券码
* @param mixed $yohoCoin 使用的YOHO币数量
* @param int $redEnvelopes 红包
* @return json
*/
public
function
orderComputeAction
()
{
$result
=
array
();
if
(
$this
->
isAjax
())
{
$cartType
=
$this
->
post
(
'cartType'
,
'ordinary'
);
$deliveryWay
=
$this
->
post
(
'deliveryWay'
,
1
);
$paymentType
=
$this
->
post
(
'paymentType'
,
1
);
$couponCode
=
$this
->
post
(
'couponCode'
,
null
);
$yohoCoin
=
$this
->
post
(
'yohoCoin'
,
null
);
$redEnvelopes
=
$this
->
post
(
'redEnvelopes'
,
null
);
$uid
=
$this
->
getUid
(
true
);
$result
=
CartModel
::
orderCompute
(
$uid
,
$cartType
,
$deliveryWay
,
$paymentType
,
$couponCode
,
$yohoCoin
,
$redEnvelopes
);
}
$this
->
echoJson
(
$result
);
}
/**
* 确认结算订单
*
* @param int $addressId 地址ID
* @param int $cartType 购物车类型ID
* @param int $deliveryTimeId 寄送时间ID
* @param int $deliveryWayId 寄送方式ID
* @param string $invoiceTitle 发票抬头
* @param int $invoiceId 发票类型ID
* @param int $paymentId 支付方式ID
* @param int $paymentType 支付类型ID
* @param string $remark 留言
* @param string $couponCode 优惠券码
* @param mixed $yohoCoin 使用的YOHO币数量或为空
* @param int $isPreContact 送货前是否联系 true:是, false:否
* @param int $isPrintPrice 是否打印价格 true:是, false:否
* @param int $redEnvelopes 红包
* @return json
*/
public
function
orderSubAction
()
{
$result
=
array
(
'code'
=>
400
,
'data'
=>
array
(),
'message'
=>
CartModel
::
ERROR_400_MESSAGE
);
do
{
// 判断是否是AJAX请求
if
(
!
$this
->
isAjax
())
{
break
;
}
// 判断用户是否登录
$uid
=
$this
->
getUid
(
true
);
if
(
!
$uid
)
{
$result
[
'message'
]
=
'请先登录'
;
break
;
}
$addressId
=
$this
->
post
(
'addressId'
,
null
);
$cartType
=
$this
->
post
(
'cartType'
,
'ordinary'
);
// 默认普通购物车
$deliveryTimeId
=
$this
->
post
(
'deliveryTimeId'
,
1
);
// 默认只工作日配送
$deliveryWayId
=
$this
->
post
(
'deliveryWayId'
,
1
);
// 默认普通快递
$invoiceTitle
=
$this
->
post
(
'invoiceTitle'
,
null
);
// 发票抬头
$invoiceId
=
$this
->
post
(
'invoiceId'
,
null
);
// 发票类型
$paymentId
=
$this
->
post
(
'paymentId'
,
15
);
// 支付ID
$paymentType
=
$this
->
post
(
'paymentType'
,
1
);
// 默认在线支付
$remark
=
$this
->
post
(
'remark'
,
''
);
// 备注信息
$couponCode
=
$this
->
post
(
'couponCode'
,
null
);
// 优惠码
$yohoCoin
=
$this
->
post
(
'yohoCoin'
,
1
);
// YOHO币
$isPreContact
=
$this
->
post
(
'isPreContact'
,
false
);
// 送货前是否联系
$isPrintPrice
=
$this
->
post
(
'isPrintPrice'
,
true
);
// 是否打印价格
$redEnvelopes
=
$this
->
post
(
'redEnvelopes'
,
null
);
// 调用下单接口
$result
=
CartModel
::
orderSub
(
$uid
,
$addressId
,
$cartType
,
$deliveryTimeId
,
$deliveryWayId
,
$invoiceTitle
,
$invoiceId
,
$paymentId
,
$paymentType
,
$remark
,
$couponCode
,
$yohoCoin
,
$isPreContact
,
$isPrintPrice
,
$redEnvelopes
);
// 判断是否下单成功
if
(
empty
(
$result
[
'data'
][
'order_code'
]))
{
break
;
}
// 跳转到支付的URL链接
$result
[
'data'
][
'payUrl'
]
=
Helpers
::
url
(
'/shopping/pay'
,
array
(
'ordercode'
=>
$result
[
'data'
][
'order_code'
]));
}
while
(
false
);
// $result = CartModel::orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $couponCode, $yohoCoin);
//
// // 记录下单异常的数据
// if (empty($result)) {
// $message = 'uid:' . $uid . ',addressId:' . $addressId . ',cartType:' . $cartType . ',deliveryTime:' . $deliveryTime
// . ',deliveryWay:' . $deliveryWay . 'invoiceTitle:' . $invoiceTitle . ',invoiceId:' . $invoiceId . ',yohoCoin:' . $yohoCoin
// . ',paymentId:' . $paymentId . ',paymentType:' . $paymentType . ',remark:' . $remark . ',couponCode:' . $couponCode . "\n";
// error_log($message, 3, '/Data/logs/php/pc_error/order.' . date('Ym') . '.log');
// }
// // 返回数据
// else {
// // 提交成功清除Cookie
// $this->setCookie('order-info', null);
//
// $this->echoJson($result);
// }
//
// if ($uid && !empty($result['data'])) {
// try {
// UnionTrans::set($uid, $result['data']['order_code'], $result['data']['order_amount']);
// } catch (Exception $e) {
// // do nothing
// }
// }
$this
->
echoJson
(
$result
);
}
/**
* 加入购物车
*
* @param string productSku 商品的SKU
* @param int buyNumber 购买数量
* @param int promotionId 促销ID, 加价购有关
* @param int goodsType 商品类型,0表示普通商品,1表示加价购商品
* @param int isEdit 是否是编辑商品SKU,0表示不是编辑
* @return json
*/
public
function
addAction
()
{
$result
=
array
();
if
(
$this
->
isAjax
())
{
$shoppingKey
=
Helpers
::
getShoppingKeyByCookie
();
$productSku
=
$this
->
post
(
'productSku'
);
$buyNumber
=
$this
->
post
(
'buyNumber'
,
1
);
$goodsType
=
$this
->
post
(
'goodsType'
,
0
);
$promotionId
=
$this
->
post
(
'promotionId'
,
0
);
$isEdit
=
$this
->
post
(
'isEdit'
,
0
);
$uid
=
$this
->
getUid
(
true
);
// 执行加入购物车操作
$result
=
CartModel
::
addToCart
(
$productSku
,
$buyNumber
,
$goodsType
,
$isEdit
,
$promotionId
,
$uid
,
$shoppingKey
);
// 设置加入购物车凭证到客户端浏览器
if
(
empty
(
$shoppingKey
)
&&
isset
(
$result
[
'data'
][
'shopping_key'
]))
{
$this
->
setCookie
(
'_SPK'
,
$result
[
'data'
][
'shopping_key'
],
time
()
+
86400
*
360
);
}
// 老站购物车需要的COOKIE
if
(
isset
(
$result
[
'data'
][
'shopping_key'
]))
{
$this
->
setCookie
(
'_g'
,
json_encode
(
array
(
'_k'
=>
$result
[
'data'
][
'shopping_key'
],
'_nac'
=>
$result
[
'data'
][
'goods_count'
],
'_ac'
=>
0
,
'_r'
=>
1
)));
}
}
$this
->
echoJson
(
$result
);
}
/**
* 获取商品信息
*/
public
function
getProductInfoAction
()
{
$productId
=
$this
->
get
(
'productId'
);
$uid
=
$this
->
getUid
();
$vipLevel
=
-
1
;
$data
=
array
();
if
(
!
empty
(
$this
->
_vip
))
{
$vipLevel
=
Helpers
::
getVipLevel
(
$this
->
_vip
);
}
if
(
!
empty
(
$productId
))
{
$data
=
ItemModel
::
getCartProductInfo
(
$productId
,
$uid
,
$vipLevel
);
}
$this
->
_view
->
display
(
'goods-detail'
,
$data
);
}
/**
* 获取购物车商品总数
*
* @return jsonp
*/
public
function
countAction
()
{
$callback
=
$this
->
get
(
'callback'
,
'callback'
);
$uid
=
$this
->
getUid
(
false
);
$shoppingKey
=
Helpers
::
getShoppingKeyByCookie
();
$result
=
CartModel
::
getCartCount
(
$uid
,
$shoppingKey
);
$this
->
helpJsonCallbackResult
(
$callback
,
200
,
'总数'
,
$result
);
}
/**
* 设置购物车COOKIE信息
*/
private
function
setShoppingCookie
(
$uid
=
null
)
{
(
$uid
===
null
)
?
$uid
=
$this
->
getUid
(
false
)
:
true
;
$shoppingKey
=
Helpers
::
getShoppingKeyByCookie
();
$cartCount
=
CartModel
::
getCartCount
(
$uid
,
$shoppingKey
);
if
(
!
empty
(
$cartCount
[
'data'
][
'cart_goods_count'
]))
{
$this
->
setCookie
(
'_g'
,
json_encode
(
array
(
'_k'
=>
$shoppingKey
,
'_nac'
=>
$cartCount
[
'data'
][
'cart_goods_count'
],
'_ac'
=>
0
,
'_r'
=>
1
)));
}
}
}
\ No newline at end of file
...
...
Please
register
or
login
to post a comment