Showing
3 changed files
with
210 additions
and
19 deletions
@@ -188,6 +188,76 @@ class UserData | @@ -188,6 +188,76 @@ class UserData | ||
188 | } | 188 | } |
189 | 189 | ||
190 | /** | 190 | /** |
191 | + * 获取三级地址列表数据 | ||
192 | + * | ||
193 | + * @param int $uid 用户ID | ||
194 | + * @return array 地址接口返回的数据 | ||
195 | + */ | ||
196 | + public static function addressListData($uid) | ||
197 | + { | ||
198 | + $param = Yohobuy::param(); | ||
199 | + $param['method'] = 'app.address.getlist'; | ||
200 | + $param['uid'] = $uid; | ||
201 | + $param['client_secret'] = Sign::getSign($param); | ||
202 | + | ||
203 | + return Yohobuy::get(Yohobuy::API_URL, $param); | ||
204 | + } | ||
205 | + | ||
206 | + /** | ||
207 | + * 保存地址数据 | ||
208 | + * | ||
209 | + * @param int $uid 用户ID | ||
210 | + * @param string $address 地址信息 | ||
211 | + * @param int $area_code 城市码 | ||
212 | + * @param string $consignee 收货人 | ||
213 | + * @param string $email 邮箱地址 | ||
214 | + * @param int $id 地址唯一标识符id | ||
215 | + * @param string $mobile 手机号码 | ||
216 | + * @param string $zip_code 邮编 | ||
217 | + * @return array 地址接口返回的数据 | ||
218 | + */ | ||
219 | + public static function saveAddressData($uid, $address, $area_code, $consignee, $email, $id, $mobile, $zip_code) | ||
220 | + { | ||
221 | + $param = Yohobuy::param(); | ||
222 | + $param['address'] = $address; | ||
223 | + $param['area_code'] = $area_code; | ||
224 | + $param['consignee'] = $consignee; | ||
225 | + $param['email'] = $email; | ||
226 | + | ||
227 | + if ($id !== null) { // 修改 | ||
228 | + $param['id'] = $id; | ||
229 | + $param['method'] = 'app.address.update'; | ||
230 | + } else { // 添加 | ||
231 | + $param['method'] = 'app.address.add'; | ||
232 | + } | ||
233 | + | ||
234 | + $param['mobile'] = $mobile; | ||
235 | + $param['zip_code'] = $zip_code; | ||
236 | + $param['uid'] = $uid; | ||
237 | + $param['client_secret'] = Sign::getSign($param); | ||
238 | + | ||
239 | + return Yohobuy::get(Yohobuy::API_URL, $param); | ||
240 | + } | ||
241 | + | ||
242 | + /** | ||
243 | + * 设置默认地址 | ||
244 | + * | ||
245 | + * @param int $uid 用户ID | ||
246 | + * @param int $id 地址唯一标识符id | ||
247 | + * @return array 接口返回的数据 | ||
248 | + */ | ||
249 | + public static function setDefaultAddress($uid, $id) | ||
250 | + { | ||
251 | + $param = Yohobuy::param(); | ||
252 | + $param['id'] = $id; | ||
253 | + $param['method'] = 'app.address.setdefault'; | ||
254 | + $param['uid'] = $uid; | ||
255 | + $param['client_secret'] = Sign::getSign($param); | ||
256 | + | ||
257 | + return Yohobuy::get(Yohobuy::API_URL, $param); | ||
258 | + } | ||
259 | + | ||
260 | + /** | ||
191 | * 意见反馈数据 | 261 | * 意见反馈数据 |
192 | * | 262 | * |
193 | * @param string $udid 客户端唯一标识 | 263 | * @param string $udid 客户端唯一标识 |
@@ -208,38 +208,69 @@ class HomeController extends AbstractAction | @@ -208,38 +208,69 @@ class HomeController extends AbstractAction | ||
208 | $uid = 967016; | 208 | $uid = 967016; |
209 | 209 | ||
210 | $address = \Index\UserModel::getAddressData($uid); | 210 | $address = \Index\UserModel::getAddressData($uid); |
211 | + $addressList = \Index\UserModel::getAddressListData($uid); | ||
211 | 212 | ||
212 | // print_r($address); | 213 | // print_r($address); |
213 | 214 | ||
214 | $this->_view->display('address', array( | 215 | $this->_view->display('address', array( |
215 | 'addressPage' => true, | 216 | 'addressPage' => true, |
216 | 'pageFooter' => true, | 217 | 'pageFooter' => true, |
217 | - 'address' => $address | 218 | + 'address' => $address, |
219 | + 'addressList' => $addressList | ||
218 | )); | 220 | )); |
219 | } | 221 | } |
220 | 222 | ||
221 | - /** | ||
222 | - * 修改地址 | ||
223 | - */ | ||
224 | - public function editAddressAction() | ||
225 | - { | ||
226 | - // 设置网站标题 | ||
227 | - $this->setTitle('修改地址'); | ||
228 | - $this->setNavHeader('修改地址', true, SITE_MAIN); | 223 | + /** |
224 | + * 修改地址或者添加新地址 | ||
225 | + */ | ||
226 | + public function saveAddressAction() | ||
227 | + { | ||
228 | + $result = array(); | ||
229 | + | ||
230 | + if ($this->isAjax()) { | ||
231 | + // $uid = $this->getUid(); | ||
232 | + $uid = 967016; | ||
233 | + $address = $this->post('address', ''); | ||
234 | + $area_code = $this->post('area_code', ''); | ||
235 | + $consignee = $this->post('consignee', ''); | ||
236 | + $email = $this->post('email', ''); | ||
237 | + $id = $this->post('id', null); | ||
238 | + $mobile = $this->post('mobile', ''); | ||
239 | + $zip_code = $this->post('zip_code', ''); | ||
240 | + | ||
241 | + $result = \Index\UserModel::saveAddressData($uid, $address, $area_code, $consignee, $email, $id, $mobile, $zip_code); | ||
242 | + } | ||
229 | 243 | ||
230 | - // $uid = $this->getUid(); | ||
231 | - $uid = 967016; | 244 | + if (empty($result)) { |
245 | + echo ' '; | ||
246 | + } else { | ||
247 | + $this->echoJson($result); | ||
248 | + } | ||
232 | 249 | ||
233 | - $address = \Index\UserModel::getAddressData($uid); | 250 | + } |
234 | 251 | ||
235 | - // print_r($address); | 252 | + /** |
253 | + * 设置默认地址 | ||
254 | + */ | ||
255 | + public function defaultAddressAction() | ||
256 | + { | ||
257 | + $result = array(); | ||
236 | 258 | ||
237 | - $this->_view->display('edit_address', array( | ||
238 | - 'editAddressPage' => true, | ||
239 | - 'pageFooter' => true, | ||
240 | - 'address' => $address | ||
241 | - )); | ||
242 | - } | 259 | + if ($this->isAjax()) { |
260 | + // $uid = $this->getUid(); | ||
261 | + $uid = 967016; | ||
262 | + $id = $this->post('id', ''); | ||
263 | + | ||
264 | + $result = \Index\UserModel::setDefaultAddress($uid, $id); | ||
265 | + } | ||
266 | + | ||
267 | + if (empty($result)) { | ||
268 | + echo ' '; | ||
269 | + } else { | ||
270 | + $this->echoJson($result); | ||
271 | + } | ||
272 | + | ||
273 | + } | ||
243 | 274 | ||
244 | //在线客服 | 275 | //在线客服 |
245 | public function onlineServiceAction() | 276 | public function onlineServiceAction() |
@@ -246,6 +246,96 @@ class UserModel | @@ -246,6 +246,96 @@ class UserModel | ||
246 | } | 246 | } |
247 | 247 | ||
248 | /** | 248 | /** |
249 | + * 处理地址列表数据 | ||
250 | + * | ||
251 | + * @param int $uid 用户ID | ||
252 | + * @return array|mixed 处理之后的地址列表数据 | ||
253 | + */ | ||
254 | + public static function getAddressListData($uid) | ||
255 | + { | ||
256 | + $result = array(); | ||
257 | + | ||
258 | + // 调用接口获取地址列表数据 | ||
259 | + $address = UserData::addressListData($uid); | ||
260 | + | ||
261 | + // 处理地址数据 | ||
262 | + if (isset($address['data']) && !empty($address['data'])) { | ||
263 | + $result = $address['data']; | ||
264 | + } | ||
265 | + | ||
266 | + return $result; | ||
267 | + } | ||
268 | + | ||
269 | + /** | ||
270 | + * 保存地址数据 | ||
271 | + * | ||
272 | + * @param int $uid 用户ID | ||
273 | + * @param string $address 地址信息 | ||
274 | + * @param int $area_code 城市码 | ||
275 | + * @param string $consignee 收货人 | ||
276 | + * @param string $email 邮箱地址 | ||
277 | + * @param int $id 地址唯一标识符id | ||
278 | + * @param string $mobile 手机号码 | ||
279 | + * @param string $zip_code 邮编 | ||
280 | + * @return array|mixed 处理之后的地址列表数据 | ||
281 | + */ | ||
282 | + public static function saveAddressData($uid, $address, $area_code, $consignee, $email, $id, $mobile, $zip_code) | ||
283 | + { | ||
284 | + $result = array(); | ||
285 | + | ||
286 | + // 参数验证 | ||
287 | + if (empty($uid)) { | ||
288 | + $result['code'] = 400; | ||
289 | + $result['message'] = '用户不可用'; | ||
290 | + } else if (empty($address)) { | ||
291 | + $result['code'] = 401; | ||
292 | + $result['message'] = '请输入可用的地址信息'; | ||
293 | + } else if (empty($area_code)) { | ||
294 | + $result['code'] = 402; | ||
295 | + $result['message'] = '地区码不可用'; | ||
296 | + } else if (empty($consignee)) { | ||
297 | + $result['code'] = 403; | ||
298 | + $result['message'] = '请输入收件人姓名'; | ||
299 | + } else if (!empty($email) && Helpers::verifyEmail($email)) { | ||
300 | + $result['code'] = 404; | ||
301 | + $result['message'] = '输入的邮箱地址格式不正确'; | ||
302 | + } else if (!empty($mobile) && Helpers::verifyMobile($mobile)) { | ||
303 | + $result['code'] = 404; | ||
304 | + $result['message'] = '输入的手机号码格式不正确'; | ||
305 | + } else { | ||
306 | + // 调用接口保存地址数据 | ||
307 | + $address = UserData::saveAddressData($uid, $address, $area_code, $consignee, $email, $id, $mobile, $zip_code); | ||
308 | + // 处理返回结果 | ||
309 | + if (isset($address['code']) && $address['code'] == 200) { | ||
310 | + $result = $address['data']; | ||
311 | + } | ||
312 | + } | ||
313 | + | ||
314 | + return $result; | ||
315 | + } | ||
316 | + | ||
317 | + /** | ||
318 | + * 设置默认地址 | ||
319 | + * | ||
320 | + * @param int $uid 用户ID | ||
321 | + * @param int $id 地址唯一标识符id | ||
322 | + * @return array|mixed 处理之后的返回数据 | ||
323 | + */ | ||
324 | + public static function setDefaultAddress($uid, $id) | ||
325 | + { | ||
326 | + $result = array('code' => 400, 'message' => '错误'); | ||
327 | + | ||
328 | + // 调用接口设置默认地址 | ||
329 | + $address = UserData::setDefaultAddress($uid, $id); | ||
330 | + // 处理返回结果 | ||
331 | + if ($address && isset($address['code'])) { | ||
332 | + $result = $address; | ||
333 | + } | ||
334 | + | ||
335 | + return $result; | ||
336 | + } | ||
337 | + | ||
338 | + /** | ||
249 | * 处理意见反馈数据 | 339 | * 处理意见反馈数据 |
250 | * | 340 | * |
251 | * @param string $udid 客户端唯一标识 | 341 | * @param string $udid 客户端唯一标识 |
-
Please register or login to post a comment