Authored by Rock Zhang

修改单个选取购物车商品以及全选购物车商品的接口

Code Review By Rock Zhang
@@ -72,10 +72,11 @@ class ShoppingcartController extends AbstractAction @@ -72,10 +72,11 @@ class ShoppingcartController extends AbstractAction
72 $result = array(); 72 $result = array();
73 73
74 if ($this->isAjax()) { 74 if ($this->isAjax()) {
75 - $productId = $this->post('id', 0);  
76 $uid = $this->getUid(true); 75 $uid = $this->getUid(true);
77 $shoppingKey = $this->getSession('shoppingKey'); 76 $shoppingKey = $this->getSession('shoppingKey');
78 - $result = CartModel::selectGoods($uid, $productId, $shoppingKey); 77 +
  78 + $skuList = $this->post('skuList', null);
  79 + $result = CartModel::selectGoods($uid, $skuList, $shoppingKey);
79 } 80 }
80 81
81 if (empty($result)) { 82 if (empty($result)) {
@@ -96,22 +96,25 @@ class CartModel @@ -96,22 +96,25 @@ class CartModel
96 * 购物车商品选择与取消接口返回的数据处理 96 * 购物车商品选择与取消接口返回的数据处理
97 * 97 *
98 * @param int $uid 用户ID 98 * @param int $uid 用户ID
99 - * @param string $sku 商品sku列表 99 + * @param string $skuList 商品sku列表
100 * @param string $shoppingKey 未登录用户唯一识别码 100 * @param string $shoppingKey 未登录用户唯一识别码
101 * @return array 处理之后的数据的数据 101 * @return array 处理之后的数据的数据
102 */ 102 */
103 - public static function selectGoods($uid, $sku, $shoppingKey) 103 + public static function selectGoods($uid, $skuList, $shoppingKey)
104 { 104 {
105 $result = array('code' => 400, 'message' => '出错啦~'); 105 $result = array('code' => 400, 'message' => '出错啦~');
106 106
107 - // 处理sku  
108 - $sku_list = json_encode(array($sku => 1)); 107 + do {
  108 + if (empty($skuList)) {
  109 + break;
  110 + }
109 111
110 - $select = CartData::selectGoods($uid, $sku_list, $shoppingKey); 112 + $select = CartData::selectGoods($uid, $skuList, $shoppingKey);
111 if ($select && isset($select['code'])) { 113 if ($select && isset($select['code'])) {
112 $result['code'] = $select['code']; 114 $result['code'] = $select['code'];
113 $result['message'] = $select['message']; 115 $result['message'] = $select['message'];
114 } 116 }
  117 + }while(0);
115 118
116 return $result; 119 return $result;
117 } 120 }