Showing
4 changed files
with
205 additions
and
1 deletions
framework @ e9d066dd
@@ -105,4 +105,67 @@ class CartData | @@ -105,4 +105,67 @@ class CartData | ||
105 | return Yohobuy::get(Yohobuy::API_URL, $param); | 105 | return Yohobuy::get(Yohobuy::API_URL, $param); |
106 | } | 106 | } |
107 | 107 | ||
108 | + /** | ||
109 | + * 购物车结算 | ||
110 | + * | ||
111 | + * @param int $uid 用户ID | ||
112 | + * @param string $cartType 购物车类型,ordinary表示普通购物车 | ||
113 | + * @return array 接口返回的数据 | ||
114 | + */ | ||
115 | + public static function cartPay($uid, $cartType) | ||
116 | + { | ||
117 | + $param = Yohobuy::param(); | ||
118 | + $param['method'] = 'app.Shopping.payment'; | ||
119 | + $param['cart_type'] = $cartType; | ||
120 | + $param['uid'] = $uid; | ||
121 | + $param['client_secret'] = Sign::getSign($param); | ||
122 | + | ||
123 | + return Yohobuy::get(Yohobuy::API_URL, $param); | ||
124 | + } | ||
125 | + | ||
126 | + /** | ||
127 | + * 购物车结算--支付方式和配送方式选择 | ||
128 | + * | ||
129 | + * @param int $uid 用户ID | ||
130 | + * @param string $cartType 购物车类型,ordinary表示普通购物车 | ||
131 | + * @param string $deliveryWay 配送方式,1表示普通快递,2表示顺丰速运 | ||
132 | + * @param string $paymentType 支付方式,1表示在线支付,2表示货到付款 | ||
133 | + * @param string $yohoCoin 使用的YOHO币数量,默认为null表示不适用 | ||
134 | + * @return array 接口返回的数据 | ||
135 | + */ | ||
136 | + public static function paymentTypeAndDelivery($uid, $cartType, $deliveryWay, $paymentType, $yohoCoin = null) | ||
137 | + { | ||
138 | + $param = Yohobuy::param(); | ||
139 | + $param['method'] = 'app.Shopping.compute'; | ||
140 | + $param['cart_type'] = $cartType; | ||
141 | + $param['delivery_way'] = $deliveryWay; | ||
142 | + $param['payment_type'] = $paymentType; | ||
143 | + if ($yohoCoin !== null) { | ||
144 | + $param['use_yoho_coin'] = $yohoCoin; | ||
145 | + } | ||
146 | + | ||
147 | + $param['uid'] = $uid; | ||
148 | + $param['client_secret'] = Sign::getSign($param); | ||
149 | + | ||
150 | + return Yohobuy::get(Yohobuy::API_URL, $param); | ||
151 | + } | ||
152 | + | ||
153 | + /** | ||
154 | + * 购物车结算--使用优惠券 | ||
155 | + * | ||
156 | + * @param int $uid 用户ID | ||
157 | + * @param string $couponCode 优惠券代码 | ||
158 | + * @return array 接口返回的数据 | ||
159 | + */ | ||
160 | + public static function getCoupon($uid, $couponCode) | ||
161 | + { | ||
162 | + $param = Yohobuy::param(); | ||
163 | + $param['method'] = 'app.Shopping.useCoupon'; | ||
164 | + $param['coupon_code'] = $couponCode; | ||
165 | + $param['uid'] = $uid; | ||
166 | + $param['client_secret'] = Sign::getSign($param); | ||
167 | + | ||
168 | + return Yohobuy::get(Yohobuy::API_URL, $param); | ||
169 | + } | ||
170 | + | ||
108 | } | 171 | } |
@@ -104,6 +104,87 @@ class ShoppingCartController extends AbstractAction | @@ -104,6 +104,87 @@ class ShoppingCartController extends AbstractAction | ||
104 | } | 104 | } |
105 | } | 105 | } |
106 | 106 | ||
107 | + /** | ||
108 | + * 购物车结算请求 | ||
109 | + */ | ||
110 | + public function payAction() | ||
111 | + { | ||
112 | + $result = array(); | ||
113 | + | ||
114 | + if ($this->isAjax()) { | ||
115 | + $cartType = $this->post('cartType', 'ordinary'); | ||
116 | + $result = CartModel::cartPay($this->_uid, $cartType); | ||
117 | + } | ||
118 | + | ||
119 | + if (empty($result)) { | ||
120 | + echo ' '; | ||
121 | + } else { | ||
122 | + $this->echoJson($result); | ||
123 | + } | ||
124 | + } | ||
125 | + | ||
126 | + /** | ||
127 | + * 购物车选择支付方式和配送方式接口 | ||
128 | + */ | ||
129 | + public function payAndDeliveryAction() | ||
130 | + { | ||
131 | + $result = array(); | ||
132 | + | ||
133 | + if ($this->isAjax()) { | ||
134 | + $cartType = $this->post('cartType', 'ordinary'); | ||
135 | + $deliveryWay = $this->post('deliveryWay', 1); | ||
136 | + $paymentType = $this->post('paymentType', 1); | ||
137 | + $result = CartModel::paymentTypeAndDelivery($this->_uid, $cartType, $deliveryWay, $paymentType); | ||
138 | + } | ||
139 | + | ||
140 | + if (empty($result)) { | ||
141 | + echo ' '; | ||
142 | + } else { | ||
143 | + $this->echoJson($result); | ||
144 | + } | ||
145 | + } | ||
146 | + | ||
147 | + /** | ||
148 | + * 购物车输入优惠券码使用优惠券 | ||
149 | + */ | ||
150 | + public function couponAction() | ||
151 | + { | ||
152 | + $result = array(); | ||
153 | + | ||
154 | + if ($this->isAjax()) { | ||
155 | + $couponCode = $this->post('couponCode', ''); | ||
156 | + $result = CartModel::getCoupon($this->_uid, $couponCode); | ||
157 | + } | ||
158 | + | ||
159 | + if (empty($result)) { | ||
160 | + echo ' '; | ||
161 | + } else { | ||
162 | + $this->echoJson($result); | ||
163 | + } | ||
164 | + } | ||
165 | + | ||
166 | + /** | ||
167 | + * 购物车使用YOHO币 | ||
168 | + */ | ||
169 | + public function yohoCoinAction() | ||
170 | + { | ||
171 | + $result = array(); | ||
172 | + | ||
173 | + if ($this->isAjax()) { | ||
174 | + $cartType = $this->post('cartType', 'ordinary'); | ||
175 | + $deliveryWay = $this->post('deliveryWay', 1); | ||
176 | + $paymentType = $this->post('paymentType', 1); | ||
177 | + $yohoCoin = $this->post('yohoCoin', 1); | ||
178 | + $result = CartModel::paymentTypeAndDelivery($this->_uid, $cartType, $deliveryWay, $paymentType, $yohoCoin); | ||
179 | + } | ||
180 | + | ||
181 | + if (empty($result)) { | ||
182 | + echo ' '; | ||
183 | + } else { | ||
184 | + $this->echoJson($result); | ||
185 | + } | ||
186 | + } | ||
187 | + | ||
107 | public function giftAdvanceAction() | 188 | public function giftAdvanceAction() |
108 | { | 189 | { |
109 | $data = array( | 190 | $data = array( |
@@ -185,6 +185,66 @@ class CartModel | @@ -185,6 +185,66 @@ class CartModel | ||
185 | return $result; | 185 | return $result; |
186 | } | 186 | } |
187 | 187 | ||
188 | + /** | ||
189 | + * 调用购物车结算接口返回的数据处理 | ||
190 | + * | ||
191 | + * @param int $uid 用户ID | ||
192 | + * @param string $cartType 购物车类型,ordinary表示普通购物车 | ||
193 | + * @return array 接口返回的数据 | ||
194 | + */ | ||
195 | + public static function cartPay($uid, $cartType) | ||
196 | + { | ||
197 | + $result = array(); | ||
198 | + | ||
199 | + $pay = CartData::cartPay($uid, $cartType); | ||
200 | + if ($pay && isset($pay['code']) && $pay['code'] === 200) { | ||
201 | + $result = $pay['data']; | ||
202 | + } | ||
203 | + | ||
204 | + return $result; | ||
205 | + } | ||
206 | + | ||
207 | + /** | ||
208 | + * 购物车结算--支付方式和配送方式选择以及是否使用YOHO币接口返回的数据处理 | ||
209 | + * | ||
210 | + * @param int $uid 用户ID | ||
211 | + * @param string $cartType 购物车类型,ordinary表示普通购物车 | ||
212 | + * @param string $deliveryWay 配送方式,1表示普通快递,2表示顺丰速运 | ||
213 | + * @param string $paymentType 支付方式,1表示在线支付,2表示货到付款 | ||
214 | + * @return array 接口返回的数据 | ||
215 | + */ | ||
216 | + public static function paymentTypeAndDelivery($uid, $cartType, $deliveryWay, $paymentType) | ||
217 | + { | ||
218 | + $result = array(); | ||
219 | + | ||
220 | + $pay = CartData::paymentTypeAndDelivery($uid, $cartType, $deliveryWay, $paymentType); | ||
221 | + if ($pay && isset($pay['code']) && $pay['code'] === 200) { | ||
222 | + $result = $pay['data']; | ||
223 | + } | ||
224 | + | ||
225 | + return $result; | ||
226 | + } | ||
227 | + | ||
228 | + /** | ||
229 | + * 购物车结算--输入优惠券代码返回的结果处理 | ||
230 | + * | ||
231 | + * @param int $uid 用户ID | ||
232 | + * @param string $couponCode 优惠券代码 | ||
233 | + * @return array 接口返回的数据 | ||
234 | + */ | ||
235 | + public static function getCoupon($uid, $couponCode) | ||
236 | + { | ||
237 | + $result = array('code' => 400, 'message' => '出错啦~'); | ||
238 | + | ||
239 | + $coupon = CartData::getCoupon($uid, $couponCode); | ||
240 | + if ($coupon && isset($coupon['code']) && $coupon['code'] === 200) { | ||
241 | + $result['code'] = $coupon['code']; | ||
242 | + $result['message'] = $coupon['message']; | ||
243 | + } | ||
244 | + | ||
245 | + return $result; | ||
246 | + } | ||
247 | + | ||
188 | 248 | ||
189 | /** | 249 | /** |
190 | * 处理不同类型的购物车数据 | 250 | * 处理不同类型的购物车数据 |
-
Please register or login to post a comment