Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
YOHO-ACTIVITY-PHP
·
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
Rock Zhang
9 years ago
Commit
b3050ee4536c2a6ecc234d68d516b4af1f6fe9a1
1 parent
e18d7250
添加购物车中商品删除,加入收藏夹,修改接口”
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
208 additions
and
3 deletions
library/LibModels/Wap/Home/CartData.php
yohobuy/m.yohobuy.com/application/controllers/ShoppingCart.php
yohobuy/m.yohobuy.com/application/models/Index/Cart.php
library/LibModels/Wap/Home/CartData.php
View file @
b3050ee
...
...
@@ -32,4 +32,58 @@ class CartData
return
Yohobuy
::
get
(
Yohobuy
::
API_URL
,
$param
);
}
/**
* 移出购物车
*
* @param int $uid 用户ID
* @param string $sku 商品sku列表
* @return array 接口返回的数据
*/
public
static
function
removeFromCart
(
$uid
,
$sku
)
{
$param
=
Yohobuy
::
param
();
$param
[
'method'
]
=
'app.Shopping.remove'
;
$param
[
'product_sku_list'
]
=
$sku
;
$param
[
'uid'
]
=
$uid
;
$param
[
'client_secret'
]
=
Sign
::
getSign
(
$param
);
return
Yohobuy
::
get
(
Yohobuy
::
API_URL
,
$param
);
}
/**
* 修改购物车商品数据
*
* @param int $uid 用户ID
* @param string $swapData 商品数据
* @return array 接口返回的数据
*/
public
static
function
modifyCartProduct
(
$uid
,
$swapData
)
{
$param
=
Yohobuy
::
param
();
$param
[
'method'
]
=
'app.Shopping.swap'
;
$param
[
'swap_data'
]
=
$swapData
;
$param
[
'uid'
]
=
$uid
;
$param
[
'client_secret'
]
=
Sign
::
getSign
(
$param
);
return
Yohobuy
::
get
(
Yohobuy
::
API_URL
,
$param
);
}
/**
* 移入收藏夹
*
* @param int $uid 用户ID
* @param string $sku 商品sku列表
* @return array 接口返回的数据
*/
public
static
function
addToFav
(
$uid
,
$sku
)
{
$param
=
Yohobuy
::
param
();
$param
[
'method'
]
=
'app.Shopping.addfavorite'
;
$param
[
'product_sku_list'
]
=
$sku
;
$param
[
'uid'
]
=
$uid
;
$param
[
'client_secret'
]
=
Sign
::
getSign
(
$param
);
return
Yohobuy
::
get
(
Yohobuy
::
API_URL
,
$param
);
}
}
...
...
yohobuy/m.yohobuy.com/application/controllers/ShoppingCart.php
View file @
b3050ee
<?php
use
Action\AbstractAction
;
use
Index\CartModel
;
use
Plugin\Helpers
;
/**
* 购物车
*/
class
ShoppingCartController
extends
AbstractAction
{
protected
$_uid
;
/**
* 初始化
*/
public
function
init
()
{
// 检查用户是否登录, 未登录则跳转到登录页
$this
->
_uid
=
$this
->
getUid
();
if
(
!
$this
->
_uid
)
{
$this
->
go
(
Helpers
::
url
(
'/signin.html'
));
}
parent
::
init
();
}
/*
* 首页
*/
public
function
indexAction
()
{
$this
->
setTitle
(
'购物车'
);
$this
->
setNavHeader
(
'购物车'
);
$uid
=
$this
->
getUid
();
$data
=
array
(
'shoppingCartPage'
=>
true
,
'shoppingCart'
=>
\Index\CartModel
::
getCartData
(
$
uid
)
'shoppingCart'
=>
CartModel
::
getCartData
(
$this
->
_
uid
)
);
// 渲染模板
$this
->
_view
->
display
(
'index'
,
$data
);
}
/**
* 移出购物车
*/
public
function
delAction
()
{
$result
=
array
();
if
(
$this
->
isAjax
())
{
$productId
=
$this
->
post
(
'id'
,
0
);
$result
=
CartModel
::
removeFromCart
(
$this
->
_uid
,
$productId
);
}
if
(
empty
(
$result
))
{
echo
' '
;
}
else
{
$this
->
echoJson
(
$result
);
}
}
/**
* 移入收藏夹
*/
public
function
colAction
()
{
$result
=
array
();
if
(
$this
->
isAjax
())
{
$productId
=
$this
->
post
(
'id'
,
0
);
$result
=
CartModel
::
addToFav
(
$this
->
_uid
,
$productId
);
}
if
(
empty
(
$result
))
{
echo
' '
;
}
else
{
$this
->
echoJson
(
$result
);
}
}
/**
* 修改购物车商品数据
*/
public
function
modifyAction
()
{
$result
=
array
();
if
(
$this
->
isAjax
())
{
$params
=
array
();
$params
[
'old_product_sku'
]
=
$this
->
post
(
'old_product_sku'
,
0
);
$params
[
'new_product_sku'
]
=
$this
->
post
(
'new_product_sku'
,
0
);
$params
[
'buy_number'
]
=
$this
->
post
(
'buy_number'
,
0
);
$params
[
'selected'
]
=
$this
->
post
(
'selected'
,
null
);
$result
=
CartModel
::
modifyCartProduct
(
$this
->
_uid
,
$params
);
}
if
(
empty
(
$result
))
{
echo
' '
;
}
else
{
$this
->
echoJson
(
$result
);
}
}
public
function
giftAdvanceAction
()
{
$data
=
array
(
...
...
yohobuy/m.yohobuy.com/application/models/Index/Cart.php
View file @
b3050ee
...
...
@@ -51,6 +51,75 @@ class CartModel
return
$result
;
}
/**
* 移出购物车
*
* @param int $uid 用户ID
* @param string $sku 商品sku列表
* @return array 接口返回的数据
*/
public
static
function
removeFromCart
(
$uid
,
$sku
)
{
$result
=
array
(
'code'
=>
400
,
'message'
=>
'出错啦~'
);
// 处理sku
$sku_list
=
json_encode
(
array
(
$sku
=>
1
));
$remove
=
CartData
::
removeFromCart
(
$uid
,
$sku_list
);
if
(
$remove
&&
isset
(
$remove
[
'code'
]))
{
$result
[
'code'
]
=
$remove
[
'code'
];
$result
[
'message'
]
=
$remove
[
'message'
];
}
return
$result
;
}
/**
* 移入收藏夹
*
* @param int $uid 用户ID
* @param string $sku 商品sku列表
* @return array 接口返回的数据
*/
public
static
function
addToFav
(
$uid
,
$sku
)
{
$result
=
array
(
'code'
=>
400
,
'message'
=>
'出错啦~'
);
// 处理sku
$sku_list
=
json_encode
(
array
(
$sku
=>
1
));
$add
=
CartData
::
addToFav
(
$uid
,
$sku_list
);
if
(
$add
&&
isset
(
$add
[
'code'
]))
{
$result
[
'code'
]
=
$add
[
'code'
];
$result
[
'message'
]
=
$add
[
'message'
];
}
return
$result
;
}
/**
* 修改购物车商品数据
*
* @param int $uid 用户ID
* @param string $param 要更改的数据
* @return array 接口返回的数据
*/
public
static
function
modifyCartProduct
(
$uid
,
$param
)
{
$result
=
array
(
'code'
=>
400
,
'message'
=>
'出错啦~'
);
// 处理要更改的数据
$swapData
=
json_encode
(
array
(
$param
));
$modify
=
CartData
::
addToFav
(
$uid
,
$swapData
);
if
(
$modify
&&
isset
(
$modify
[
'code'
]))
{
$result
[
'code'
]
=
$modify
[
'code'
];
$result
[
'message'
]
=
$modify
[
'message'
];
}
return
$result
;
}
/**
* 处理不同类型的购物车数据
...
...
@@ -65,7 +134,7 @@ class CartModel
$oneGoods
=
array
();
// 购买的商品列表
foreach
(
$data
[
'goods_list'
]
as
$value
)
{
$oneGoods
[
'id'
]
=
$value
[
'product_
id
'
];
$oneGoods
[
'id'
]
=
$value
[
'product_
sku
'
];
$oneGoods
[
'name'
]
=
$value
[
'product_name'
];
$oneGoods
[
'thumb'
]
=
Images
::
getImageUrl
(
$value
[
'goods_images'
],
120
,
120
);
$oneGoods
[
'color'
]
=
$value
[
'color_name'
];
...
...
Please
register
or
login
to post a comment