添加购物车商品选择与取消接口
Code Review By Rock Zhang
Showing
4 changed files
with
72 additions
and
1 deletions
framework @ e9d066dd
@@ -48,6 +48,32 @@ class CartData | @@ -48,6 +48,32 @@ class CartData | ||
48 | } | 48 | } |
49 | 49 | ||
50 | /** | 50 | /** |
51 | + * 购物车商品选择与取消接口 | ||
52 | + * | ||
53 | + * @param int $uid 用户ID | ||
54 | + * @param string $sku 商品sku列表 | ||
55 | + * @param string $shoppingKey 未登录用户唯一识别码 | ||
56 | + * @return array 购物车接口返回的数据 | ||
57 | + */ | ||
58 | + public static function selectGoods($uid, $sku, $shoppingKey) | ||
59 | + { | ||
60 | + $param = Yohobuy::param(); | ||
61 | + $param['method'] = 'app.Shopping.selected'; | ||
62 | + $param['product_sku_list'] = $sku; | ||
63 | + | ||
64 | + if (!empty($uid)) { | ||
65 | + $param['uid'] = $uid; | ||
66 | + } | ||
67 | + if (!empty($shoppingKey)) { | ||
68 | + $param['shopping_key'] = $shoppingKey; | ||
69 | + } | ||
70 | + | ||
71 | + $param['client_secret'] = Sign::getSign($param); | ||
72 | + | ||
73 | + return Yohobuy::get(Yohobuy::API_URL, $param); | ||
74 | + } | ||
75 | + | ||
76 | + /** | ||
51 | * 购物车数据 | 77 | * 购物车数据 |
52 | * | 78 | * |
53 | * @param int $uid 用户ID | 79 | * @param int $uid 用户ID |
@@ -32,6 +32,27 @@ class ShoppingCartController extends AbstractAction | @@ -32,6 +32,27 @@ class ShoppingCartController extends AbstractAction | ||
32 | } | 32 | } |
33 | 33 | ||
34 | /** | 34 | /** |
35 | + * 购物车商品选择与取消 | ||
36 | + */ | ||
37 | + public function selectAction() | ||
38 | + { | ||
39 | + $result = array(); | ||
40 | + | ||
41 | + if ($this->isAjax()) { | ||
42 | + $productId = $this->post('id', 0); | ||
43 | + $uid = $this->getUid(true); | ||
44 | + $shoppingKey = $this->getSession('shoppingKey'); | ||
45 | + $result = CartModel::selectGoods($uid, $productId, $shoppingKey); | ||
46 | + } | ||
47 | + | ||
48 | + if (empty($result)) { | ||
49 | + echo ' '; | ||
50 | + } else { | ||
51 | + $this->echoJson($result); | ||
52 | + } | ||
53 | + } | ||
54 | + | ||
55 | + /** | ||
35 | * 移出购物车 | 56 | * 移出购物车 |
36 | */ | 57 | */ |
37 | public function delAction() | 58 | public function delAction() |
@@ -79,6 +79,30 @@ class CartModel | @@ -79,6 +79,30 @@ class CartModel | ||
79 | } | 79 | } |
80 | 80 | ||
81 | /** | 81 | /** |
82 | + * 购物车商品选择与取消接口返回的数据处理 | ||
83 | + * | ||
84 | + * @param int $uid 用户ID | ||
85 | + * @param string $sku 商品sku列表 | ||
86 | + * @param string $shoppingKey 未登录用户唯一识别码 | ||
87 | + * @return array 处理之后的数据的数据 | ||
88 | + */ | ||
89 | + public static function selectGoods($uid, $sku, $shoppingKey) | ||
90 | + { | ||
91 | + $result = array('code' => 400, 'message' => '出错啦~'); | ||
92 | + | ||
93 | + // 处理sku | ||
94 | + $sku_list = json_encode(array($sku => 1)); | ||
95 | + | ||
96 | + $select = CartData::selectGoods($uid, $sku_list, $shoppingKey); | ||
97 | + if ($select && isset($select['code'])) { | ||
98 | + $result['code'] = $select['code']; | ||
99 | + $result['message'] = $select['message']; | ||
100 | + } | ||
101 | + | ||
102 | + return $result; | ||
103 | + } | ||
104 | + | ||
105 | + /** | ||
82 | * 移出购物车 | 106 | * 移出购物车 |
83 | * | 107 | * |
84 | * @param int $uid 用户ID | 108 | * @param int $uid 用户ID |
-
Please register or login to post a comment