// 收货地址删除 @RequestMapping("/delete/{id}") public String delete(ModelMap map, @PathVariable String id, HttpServletRequest request) { Receiver receiver = receiverService.load(id); Members loginMember = getLoginMember(request); if (receiver.getMember() != loginMember) { map.put("errorMessage", "参数错误!"); return ERROR; } receiverService.delete(receiver); map.put("loginMember", loginMember); map.put("redirectUrl", OPERRATE_RETURN_URL); return SUCCESS; }
// 收货地址编辑 @RequestMapping("/{id}/edit") @NeedNavigation public String edit(ModelMap map, HttpServletRequest request, @PathVariable String id) { addSystemConfig(map); Receiver receiver = receiverService.load(id); Members loginMember = getLoginMember(request); if (receiver.getMember() != loginMember) { map.put("errorMessage", "参数错误!"); return ERROR; } map.put("loginMember", loginMember); map.put("receiver", receiver); return "shop/receiver_input"; }
// 收货地址保存 @RequestMapping(value = "/save", method = RequestMethod.POST) public String save(ModelMap map, HttpServletRequest request, Receiver receiver) { if (StringUtils.isEmpty(receiver.getPhone()) && StringUtils.isEmpty(receiver.getMobile())) { map.put("errorMessage", "联系电话、联系手机必须填写其中一项!"); return ERROR; } if (!areaService.isAreaPath(receiver.getAreaPath())) { map.put("errorMessage", "地区错误!"); return ERROR; } Area localArea = (Area) areaService.get( receiver.getAreaPath().substring(receiver.getAreaPath().lastIndexOf(",") + 1)); if (localArea == null) { map.put("errorMessage", "请选择收货地址!"); return ERROR; } receiver.setArea(localArea); Members loginMember = getLoginMember(request); Set<Receiver> receiverSet = loginMember.getReceiverSet(); if (receiverSet != null && Receiver.MAX_RECEIVER_COUNT != null && receiverSet.size() >= Receiver.MAX_RECEIVER_COUNT) { map.put("errorMessage", "只允许添加最多" + Receiver.MAX_RECEIVER_COUNT + "项收货地址!"); return ERROR; } receiver.setMember(loginMember); receiverService.save(receiver); map.put("redirectUrl", OPERRATE_RETURN_URL); return SUCCESS; }
// 收货地址更新 @RequestMapping(value = "/update", method = RequestMethod.POST) public String update( ModelMap map, HttpServletRequest request, Receiver receiver, @RequestParam("id") String id) { if (StringUtils.isEmpty(receiver.getMobile()) && StringUtils.isEmpty(receiver.getPhone())) { map.put("errorMessage", "联系手机、联系电话必须填写其中一项!"); return ERROR; } if (!areaService.isAreaPath(receiver.getAreaPath())) { map.put("errorMessage", "地区错误!"); return ERROR; } Receiver persistent = receiverService.load(id); if (persistent.getMember() != getLoginMember(request)) { map.put("errorMessage", "参数错误!"); return ERROR; } BeanUtils.copyProperties( receiver, persistent, new String[] {"id", "createDate", "modifyDate", "member"}); receiverService.update(persistent); map.put("redirectUrl", OPERRATE_RETURN_URL); return SUCCESS; }