Authored by yangyang

购物车添加相同sku商品bug

@@ -59,10 +59,10 @@ class CartData @@ -59,10 +59,10 @@ class CartData
59 * @param string $shoppingKey 未登录用户唯一识别码 59 * @param string $shoppingKey 未登录用户唯一识别码
60 * @return array 购物车接口返回的数据 60 * @return array 购物车接口返回的数据
61 */ 61 */
62 - public static function selectGoods($uid, $sku, $shoppingKey) 62 + public static function selectGoods($uid, $sku, $shoppingKey, $hasPromotion = false)
63 { 63 {
64 $param = Yohobuy::param(); 64 $param = Yohobuy::param();
65 - $param['method'] = 'app.Shopping.selected'; 65 + $param['method'] = $hasPromotion ? 'app.Shopping.selectedAndCart' : 'app.Shopping.selected';
66 $param['product_sku_list'] = $sku; 66 $param['product_sku_list'] = $sku;
67 if (!empty($uid)) { 67 if (!empty($uid)) {
68 $param['uid'] = $uid; 68 $param['uid'] = $uid;
@@ -108,10 +108,10 @@ class CartData @@ -108,10 +108,10 @@ class CartData
108 * @param string $shoppingKey 未登录用户唯一识别码 108 * @param string $shoppingKey 未登录用户唯一识别码
109 * @return array 接口返回的数据 109 * @return array 接口返回的数据
110 */ 110 */
111 - public static function removeFromCart($uid, $sku, $shoppingKey) 111 + public static function removeFromCart($uid, $sku, $shoppingKey, $hasPromotion = false)
112 { 112 {
113 $param = Yohobuy::param(); 113 $param = Yohobuy::param();
114 - $param['method'] = 'app.Shopping.remove'; 114 + $param['method'] = $hasPromotion ? 'app.Shopping.removeAndCart' : 'app.Shopping.remove';;
115 $param['product_sku_list'] = $sku; 115 $param['product_sku_list'] = $sku;
116 116
117 if (!empty($uid)) { 117 if (!empty($uid)) {
@@ -133,10 +133,10 @@ class CartData @@ -133,10 +133,10 @@ class CartData
133 * @param string $sku 商品sku列表 133 * @param string $sku 商品sku列表
134 * @return array 接口返回的数据 134 * @return array 接口返回的数据
135 */ 135 */
136 - public static function addToFav($uid, $sku) 136 + public static function addToFav($uid, $sku, $hasPromotion = false)
137 { 137 {
138 $param = Yohobuy::param(); 138 $param = Yohobuy::param();
139 - $param['method'] = 'app.Shopping.addfavorite'; 139 + $param['method'] = $hasPromotion ? 'app.Shopping.addfavoriteAndCart' : 'app.Shopping.addfavorite';
140 $param['product_sku_list'] = $sku; 140 $param['product_sku_list'] = $sku;
141 $param['uid'] = $uid; 141 $param['uid'] = $uid;
142 $param['client_secret'] = Sign::getSign($param); 142 $param['client_secret'] = Sign::getSign($param);
@@ -135,7 +135,7 @@ class CartModel @@ -135,7 +135,7 @@ class CartModel
135 * @param string $shoppingKey 未登录用户唯一识别码 135 * @param string $shoppingKey 未登录用户唯一识别码
136 * @return array 处理之后的数据的数据 136 * @return array 处理之后的数据的数据
137 */ 137 */
138 - public static function selectGoods($uid, $skuList, $shoppingKey) 138 + public static function selectGoods($uid, $skuList, $shoppingKey, $hasPromotion = false)
139 { 139 {
140 $result = array('code' => 400, 'message' => '出错啦~'); 140 $result = array('code' => 400, 'message' => '出错啦~');
141 141
@@ -144,7 +144,7 @@ class CartModel @@ -144,7 +144,7 @@ class CartModel
144 break; 144 break;
145 } 145 }
146 146
147 - $select = CartData::selectGoods($uid, $skuList, $shoppingKey); 147 + $select = CartData::selectGoods($uid, $skuList, $shoppingKey,$hasPromotion);
148 if ($select && isset($select['code'])) { 148 if ($select && isset($select['code'])) {
149 $result['code'] = $select['code']; 149 $result['code'] = $select['code'];
150 $result['message'] = $select['message']; 150 $result['message'] = $select['message'];
@@ -163,14 +163,14 @@ class CartModel @@ -163,14 +163,14 @@ class CartModel
163 * @param string $shoppingKey 未登录用户唯一识别码 163 * @param string $shoppingKey 未登录用户唯一识别码
164 * @return array 接口返回的数据 164 * @return array 接口返回的数据
165 */ 165 */
166 - public static function removeFromCart($uid, $sku, $count, $shoppingKey) 166 + public static function removeFromCart($uid, $sku, $count, $shoppingKey, $hasPromotion = false)
167 { 167 {
168 $result = array('code' => 400, 'message' => '出错啦~'); 168 $result = array('code' => 400, 'message' => '出错啦~');
169 169
170 // 处理sku 170 // 处理sku
171 $sku_list = json_encode(array($sku => intval($count) )); 171 $sku_list = json_encode(array($sku => intval($count) ));
172 172
173 - $remove = CartData::removeFromCart($uid, $sku_list, $shoppingKey); 173 + $remove = CartData::removeFromCart($uid, $sku_list, $shoppingKey, $hasPromotion);
174 if ($remove && isset($remove['code'])) { 174 if ($remove && isset($remove['code'])) {
175 $result['code'] = $remove['code']; 175 $result['code'] = $remove['code'];
176 $result['message'] = $remove['message']; 176 $result['message'] = $remove['message'];
@@ -186,7 +186,7 @@ class CartModel @@ -186,7 +186,7 @@ class CartModel
186 * @param string $sku 商品sku列表 186 * @param string $sku 商品sku列表
187 * @return array 接口返回的数据 187 * @return array 接口返回的数据
188 */ 188 */
189 - public static function addToFav($uid, $sku) 189 + public static function addToFav($uid, $sku, $hasPromotion = false)
190 { 190 {
191 $result = array('code' => 400, 'message' => '出错啦~'); 191 $result = array('code' => 400, 'message' => '出错啦~');
192 192
@@ -201,7 +201,7 @@ class CartModel @@ -201,7 +201,7 @@ class CartModel
201 // 处理sku 201 // 处理sku
202 $sku_list = json_encode(array($sku => 1)); 202 $sku_list = json_encode(array($sku => 1));
203 203
204 - $add = CartData::addToFav($uid, $sku_list); 204 + $add = CartData::addToFav($uid, $sku_list, $hasPromotion);
205 if ($add && isset($add['code'])) { 205 if ($add && isset($add['code'])) {
206 $result['code'] = $add['code']; 206 $result['code'] = $add['code'];
207 $result['message'] = $add['message']; 207 $result['message'] = $add['message'];
@@ -103,7 +103,8 @@ class IndexController extends AbstractAction @@ -103,7 +103,8 @@ class IndexController extends AbstractAction
103 $productId = $this->post('skuList', 0); 103 $productId = $this->post('skuList', 0);
104 $uid = $this->getUid(true); 104 $uid = $this->getUid(true);
105 $shoppingKey = Helpers::getShoppingKeyByCookie(); 105 $shoppingKey = Helpers::getShoppingKeyByCookie();
106 - $result = CartModel::selectGoods($uid, $productId, $shoppingKey); 106 + $hasPromotion = $this->post('hasPromotion', false);
  107 + $result = CartModel::selectGoods($uid, $productId, $shoppingKey, $hasPromotion);
107 } 108 }
108 109
109 $this->echoJson($result); 110 $this->echoJson($result);
@@ -121,6 +122,7 @@ class IndexController extends AbstractAction @@ -121,6 +122,7 @@ class IndexController extends AbstractAction
121 $count = $this->post('count', 0); 122 $count = $this->post('count', 0);
122 $uid = $this->getUid(true); 123 $uid = $this->getUid(true);
123 $shoppingKey = Helpers::getShoppingKeyByCookie(); 124 $shoppingKey = Helpers::getShoppingKeyByCookie();
  125 + $hasPromotion = $this->post('hasPromotion', false);
124 $result = CartModel::removeFromCart($uid, $sku, $count, $shoppingKey); 126 $result = CartModel::removeFromCart($uid, $sku, $count, $shoppingKey);
125 } 127 }
126 128
@@ -137,7 +139,8 @@ class IndexController extends AbstractAction @@ -137,7 +139,8 @@ class IndexController extends AbstractAction
137 if ($this->isAjax()) { 139 if ($this->isAjax()) {
138 $productId = $this->post('id', 0); 140 $productId = $this->post('id', 0);
139 $uid = $this->getUid(true); 141 $uid = $this->getUid(true);
140 - $result = CartModel::addToFav($uid, $productId); 142 + $hasPromotion = $this->post('hasPromotion', false);
  143 + $result = CartModel::addToFav($uid, $productId, $hasPromotion);
141 } 144 }
142 145
143 $this->echoJson($result); 146 $this->echoJson($result);