基于javaweb+mysql的ssm水果蔬菜商城系统(java+ssm+jsp+mysql)

基于javaweb+mysql的ssm水果蔬菜商城系统(java+ssm+jsp+mysql)

私信源码获取及调试交流

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

基于javaweb+mysql的SSM水果蔬菜商城系统(java+ssm+jsp+mysql)

项目描述:这是一个基于SSM框架开发的水果蔬菜商城系统。首先,这个项目页面简洁清爽,易于理解和学习。其次,这个项目功能丰富,具有一个在线水果蔬菜商城该有的所有功能,并且还涉及到沙箱支付宝支付等等技术亮点。

项目功能:此项目分为三个角色:客户、卖家和管理员。客户有登录注册、浏览商品信息、添加购物车、支付订单、收藏商品、评论商品等等功能。卖家有管理自己的商品、管理自己的订单、管理自己个人信息等等功能。管理员具有管理所有用户信息、管理所有商品信息、管理所有评论信息、管理商品种类信息、管理所有订单信息等等功能。

应用技术:Jsp + SSM + MySQL + 沙箱支付宝

运行环境:Eclipse/IntelliJ IDEA + MySQL5.7(项目压缩包中自带) + Tomcat7.0(项目压缩包中自带) + JDK1.8

			ret.put("type", "error");
			ret.put("msg", "添加失败,请联系管理员!");
			return ret;
		}
		ret.put("type", "success");
		ret.put("msg", "添加成功!");
		return ret;
	}
	
	/**
	 * 编辑商品
	 * @param product
	 * @return
	 */
	@RequestMapping(value="/edit",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> edit(Product product, HttpServletRequest request){
		Map<String, Object> ret = new HashMap<String, Object>();
		if(product == null){
			ret.put("type", "error");
			ret.put("msg", "请填写正确的商品信息");
			return ret;
		}
		if(StringUtils.isEmpty(product.getName())){
			ret.put("type", "error");
			ret.put("msg", "请填写商品名称");
			return ret;
		}
		if(product.getProductCategoryId() == null){
			ret.put("type", "error");
			ret.put("msg", "请选择所属分类!");
			return ret;
		}
		if(product.getPrice() == null){
			ret.put("type", "error");
			ret.put("msg", "请填写商品价格!");
			return ret;
		}
		if(StringUtils.isEmpty(product.getImageUrl())){
			ret.put("type", "error");
			ret.put("msg", "请上传商品主图");
			}
		} catch (Exception e) {
			// TODO: handle exception
			ret.put("type", "error");
			ret.put("msg", "该商品下存在订单信息,不允许删除!");
			return ret;
		}
		
		ret.put("type", "success");
		ret.put("msg", "删除成功!");
		return ret;
	}
	
	/**
	 * 返回树形分类
	 * @return
	 */
	@RequestMapping(value="/tree_list",method=RequestMethod.POST)
	@ResponseBody
	public List<Map<String, Object>> treeList(){
		Map<String, Object> queryMap = new HashMap<String, Object>();
		return getTreeCategory(productCategoryService.findList(queryMap));
	}
	
	/**
	 * 根据列表生成三级树形关系分类
	 * @param productCategorieList
	 * @return
	 */
	private List<Map<String, Object>> getTreeCategory(List<ProductCategory> productCategorieList){
		List<Map<String, Object>> ret = new ArrayList<Map<String,Object>>();
		//所有的父分类整理
		for(ProductCategory productCategory : productCategorieList){
			if(productCategory.getParentId() == null){
				Map<String, Object> top = new HashMap<String, Object>();
				top.put("id", productCategory.getId());
				top.put("text", productCategory.getName());
				top.put("children", new ArrayList<Map<String,Object>>());
				ret.add(top);
			}
		}
		//添加二级
		for(ProductCategory productCategory : productCategorieList){
			if(productCategory.getParentId() != null){
				for(Map<String, Object> map : ret){
					if(productCategory.getParentId().longValue() == Long.valueOf(map.get("id")+"")){
						List children = (List)map.get("children");
						Map<String, Object> child = new HashMap<String, Object>();
						child.put("id", productCategory.getId());
						child.put("text", productCategory.getName());
						child.put("children", new ArrayList<Map<String,Object>>());
						children.add(child);
			return ret;
		}
		if(StringUtils.isEmpty(product.getImageUrl())){
			ret.put("type", "error");
			ret.put("msg", "请上传商品主图");
			return ret;
		}
		Role role = (Role) request.getSession().getAttribute("role");
		User user = (User) request.getSession().getAttribute("admin");
		if(role.getId().equals(Long.valueOf("2"))) {
			//如果是卖家角色 
			product.setUserId(Integer.valueOf(String.valueOf(user.getId())));
		} 
		ProductCategory productCategory = productCategoryService.findById(product.getProductCategoryId());
		product.setTags(productCategory.getTags() + "," + productCategory.getId());
		//状态设置为待审核
		product.setState(1);
		if(productService.edit(product) <= 0){
			ret.put("type", "error");
			ret.put("msg", "编辑失败,请联系管理员!");
			return ret;
		}
		ret.put("type", "success");
		ret.put("msg", "编辑成功!");
		return ret;
	}
	
	/**
	 * 删除商品
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/delete",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> delete(Long id){
		Map<String, Object> ret = new HashMap<String, Object>();
		if(id == null){
			ret.put("type", "error");
			ret.put("msg", "请选择要删除的");
			return ret;
		}
		}
		if(StringUtils.isEmpty(comment.getContent())){
			ret.put("msg", "请填写评价内容!");
			return ret;
		}
		comment.setCreateTime(new Date());
		comment.setUserId(onlineAccount.getId());
		if(commentService.add(comment) <= 0){
			ret.put("msg", "评论失败,请联系管理员!");
			return ret;
		}
		//更新商品评论数量
		Product product = productService.findById(comment.getProductId());
		product.setCommentNum(product.getCommentNum()+1);
		productService.updateNum(product);
		ret.put("type", "success");
		return ret;
	}
	
	/**
	 * 删除评论
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/delete",method = RequestMethod.POST)
	@ResponseBody
	public Map<String, String> delete(Long id){
		Map<String, String> ret = new HashMap<String, String>();
		ret.put("type", "error");
		if(id == null){
			ret.put("msg", "请选择要删除的评论");
			return ret;
		}
		Comment comment = commentService.findById(id);
		if(comment == null){
			ret.put("msg", "评论不存在!");
			return ret;
		}
		if(commentService.delete(id) <= 0){
			ret.put("msg", "删除出错,请联系管理员!");
			return ret;
		}
		//更新商品评论数量
		Product product = productService.findById(comment.getProductId());
		product.setCommentNum(product.getCommentNum()-1);
	 * @param model
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/list_2",method = RequestMethod.GET)
	public ModelAndView list2(ModelAndView model,HttpServletRequest request){
		model.addObject("productCategoryList", MenuUtil.getTreeCategory(productCategoryService.findList(new HashMap<String, Object>())));
		model.addObject("allCategoryId","shop_hd_menu_all_category");
		Account onlineAccount = (Account)request.getSession().getAttribute("account");
		List<Purse> purse = purseService.findById(onlineAccount.getId());
		if(purse.size()>0) {
			Purse purse2 = purse.get(0);
			request.getSession().setAttribute("purseT", purse2);
			model.addObject("purse",purse2);
		}
		Map<String, Object> queryMap = new HashMap<String, Object>();
		queryMap.put("userId", onlineAccount.getId());
		model.addObject("cartList", cartService.findList(queryMap));
		model.addObject("currentCart", "current_");
		model.addObject("addressList", addressService.findList(queryMap));
		
		model.setViewName("home/cart/list_2");
		return model;
	}
	
	
	/**
	 * 添加购物车
	 * @param account
	 * @return
	 */
	@RequestMapping(value = "/add",method = RequestMethod.POST)
	@ResponseBody
	public Map<String, String> add(Cart cart,HttpServletRequest request){
		Map<String, String> ret = new HashMap<String, String>();
		Account onlineAccount = (Account)request.getSession().getAttribute("account");
		ret.put("type", "error");
		if(cart == null){
			ret.put("msg", "请选择正确的商品信息");
			return ret;
		}
		if(cart.getProductId() == null){
			ret.put("msg", "请选择要添加的商品!");
			return ret;
		}
		if(cart.getNum() == 0){
			ret.put("msg", "请填写商品数量");
			return ret;
		if(purseList.size()>0) {
			Purse purse = purseList.get(0);
			model.addObject("purse", purse);
		}*/
		model.addObject("productCategoryList", MenuUtil.getTreeCategory(productCategoryService.findList(new HashMap<String, Object>())));
		model.addObject("allCategoryId","shop_hd_menu_all_category");
		model.addObject("currentUser", "current_");
		model.setViewName("home/purse/purse");
		return model;
	}
	/**
	 * 确认充值金额
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/recharge",method=RequestMethod.POST)
	public Map<String,String> recharge(@RequestParam("balance")double balance,HttpServletRequest request){
		HashMap<String, String> ret = new HashMap<String,String>();
		ret.put("type", "error");
		Purse purse = new Purse();
		if(balance<=0) {
			ret.put("msg", "金额为正整数");
			return ret;
		}
		Account onlineAccount = (Account)request.getSession().getAttribute("account");
		purse.setUserId(onlineAccount.getId().intValue());
		purse.setRecharge(balance);
		purse.setState(0);
		if(purseService.add(purse)<=0) {
			ret.put("msg", "充值失败请联系管理员");
			return ret;
		}
		ret.put("type", "success");
		ret.put("msg", "充值成功,等待管理员审核");
		return ret;
	}

	/**
	 * 充值记录页面
	 * @param model
	 * @param request
	 * @return
	private FavoriteService favoriteService;
	/**
	 * 收藏列表页面
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/list",method = RequestMethod.GET)
	public ModelAndView index(ModelAndView model,Integer page,HttpServletRequest request){
		model.addObject("productCategoryList", MenuUtil.getTreeCategory(productCategoryService.findList(new HashMap<String, Object>())));
		model.addObject("allCategoryId","shop_hd_menu_all_category");
		Account onlineAccount = (Account)request.getSession().getAttribute("account");
		Map<String, Object> queryMap = new HashMap<String, Object>();
		if(page == null || page.intValue() <= 0){
			page = 1;
		}
		queryMap.put("offset", (page -1) * 16);
		queryMap.put("pageSize", 16);
		queryMap.put("userId", onlineAccount.getId());
		queryMap.put("orderBy", "createTime");
		queryMap.put("sort", "desc");
		model.addObject("favoriteList", favoriteService.findList(queryMap));
		model.addObject("currentUser", "current_");
		model.addObject("page", page);
		model.setViewName("home/favorite/list");
		return model;
	}
	
	
	/**
	 * 添加收藏
	 * @param account
	 * @return
	 */
	@RequestMapping(value = "/add",method = RequestMethod.POST)
	@ResponseBody
	public Map<String, String> add(Favorite favorite,HttpServletRequest request){
		Map<String, String> ret = new HashMap<String, String>();
		Account onlineAccount = (Account)request.getSession().getAttribute("account");
		ret.put("type", "error");
		if(favorite == null){
		ret.put("rows", roleService.findList(queryMap));
		ret.put("total", roleService.getTotal(queryMap));
		return ret;
	}
	
	/**
	 * 角色添加
	 * @param role
	 * @return
	 */
	@RequestMapping(value="/add",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, String> add(Role role){
		Map<String, String> ret = new HashMap<String, String>();
		if(role == null){
			ret.put("type", "error");
			ret.put("msg", "请填写正确的角色信息!");
			return ret;
		}
		if(StringUtils.isEmpty(role.getName())){
			ret.put("type", "error");
			ret.put("msg", "请填写角色名称!");
			return ret;
		}
		if(roleService.add(role) <= 0){
			ret.put("type", "error");
			ret.put("msg", "角色添加失败,请联系管理员!");
			return ret;
		}
		ret.put("type", "success");
		ret.put("msg", "角色添加成功!");
		return ret;
	}
	
	/**
	 * 角色修改
	 * @param role
	 * @return
	 */
	@RequestMapping(value="/edit",method=RequestMethod.POST)
	@RequestMapping(value = "/detail",method = RequestMethod.GET)
	public ModelAndView index(ModelAndView model,Long id){
		model.addObject("productCategoryList", MenuUtil.getTreeCategory(productCategoryService.findList(new HashMap<String, Object>())));
		model.addObject("allCategoryId","shop_hd_menu_all_category");
		if(id == null){
			model.addObject("msg", "非法商品id");
			model.setViewName("home/common/error");
			return model;
		}
		Product product = productService.findById(id);
		if(product == null || product.getState() != 2){
			model.addObject("msg", "商品不存在或未审核通过!");
			model.setViewName("home/common/error");
			return model;
		}
		model.addObject("product", product);
		Map<String, Object> queryMap = new HashMap<String, Object>();
		queryMap.put("offset", 0);
		queryMap.put("pageSize", 10);
		queryMap.put("sort", "desc");
		queryMap.put("orderBy", "sellNum");
		queryMap.put("productId", id);
		model.addObject("sellProductList", productService.findList(queryMap));
		model.addObject("currentHome", "current_");
		model.addObject("commentList", commentService.findList(queryMap));
		model.setViewName("home/product/detail");
		product.setViewNum(product.getViewNum()+1);
		productService.updateNum(product);
		return model;
	}
	
	/**
	 * 商品分类列表页面
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/product_category_list",method = RequestMethod.GET)
	public ModelAndView productCategoryList(
			@RequestParam(name="cid",required=true)Long cid,
			@RequestParam(name="orderby",required=false)String orderby,
			@RequestParam(name="priceMin",required=false)Double priceMin,
			@RequestParam(name="priceMax",required=false)Double priceMax,
			@RequestParam(name="page",required=false)Integer page,
			ModelAndView model){
		model.addObject("allCategoryId","shop_hd_menu_all_category");
		model.addObject("currentHome", "current_");
		if(cid == null){
			model.addObject("msg", "分类不存在");
			model.setViewName("home/common/error");
			return model;
		}
		ProductCategory productCategory = productCategoryService.findById(cid);
		if(productCategory == null){
			model.addObject("msg", "分类不存在");
	 */
	@RequestMapping(value="/list",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> list(@RequestParam(name="name",defaultValue="")String name,
				Page page
			){
		Map<String, Object> ret = new HashMap<String, Object>();
		Map<String, Object> queryMap = new HashMap<String, Object>();
		queryMap.put("name", name);
		//queryMap.put("offset", page.getOffset());
		//queryMap.put("pageSize", page.getRows());
		ret.put("rows", productCategoryService.findList(queryMap));
		ret.put("total", productCategoryService.getTotal(queryMap));
		return ret;
	}
	
	/**
	 * 返回树形分类
	 * @return
	 */
	@RequestMapping(value="/tree_list",method=RequestMethod.POST)
	@ResponseBody
	public List<Map<String, Object>> treeList(){
		Map<String, Object> queryMap = new HashMap<String, Object>();
		return getTreeCategory(productCategoryService.findList(queryMap));
	}
	
	/**
	 * 添加商品分类
	 * @param productCategory
	 * @return
	 */
	@RequestMapping(value="/add",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> add(ProductCategory productCategory){
		Map<String, Object> ret = new HashMap<String, Object>();
		if(productCategory == null){
			ret.put("type", "error");
			ret.put("msg", "请填写正确的分类信息");
			return ret;
		}
		if(StringUtils.isEmpty(productCategory.getName())){
			ret.put("type", "error");
			ret.put("msg", "请填写分类名称");
			return ret;
		}
		if(productCategory.getParentId() != null){
			ProductCategory productCategoryParent = productCategoryService.findById(productCategory.getParentId());
			if(productCategoryParent != null){
				String tags = "";
				if(productCategoryParent.getTags() != null){
					tags += productCategoryParent.getTags() + ",";
				}
				productCategory.setTags(tags + productCategory.getParentId());
			}
		}
		if(productCategoryService.edit(productCategory) <= 0){
			ret.put("type", "error");
			ret.put("msg", "编辑失败,请联系管理员!");
			return ret;
		}
		ret.put("type", "success");
		ret.put("msg", "编辑成功!");
		return ret;
	}
	
	/**
	 * 删除商品分类
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/delete",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> delete(Long id){
		Map<String, Object> ret = new HashMap<String, Object>();
		if(id == null){
			ret.put("type", "error");
			ret.put("msg", "请选择要删除的分类");
			return ret;
		}
		
		try {
			if(productCategoryService.delete(id) <= 0){
				ret.put("type", "error");
				ret.put("msg", "删除失败,请联系管理员!");
				return ret;
			}
		} catch (Exception e) {
			// TODO: handle exception
			ret.put("type", "error");
			ret.put("msg", "该分类下存在商品信息,不允许删除!");
			return ret;
		}
		
		ret.put("type", "success");
		ret.put("msg", "删除成功!");
		return ret;
	}
	}
}

/**
 * 前台订单控制器
 *
 */
@RequestMapping("/order")
@Controller
public class HomeOrderController {
	
	@Autowired
	private AccountService accountService;
	@Autowired
	private ProductCategoryService productCategoryService;
		try {
			//将文件保存至指定目录
			photo.transferTo(new File(savePath+filename));
		}catch (Exception e) {
			// TODO Auto-generated catch block
			ret.put("type", "error");
			ret.put("msg", "保存文件异常!");
			e.printStackTrace();
			return ret;
		}
		ret.put("type", "success");
		ret.put("msg", "用户删除成功!");
		ret.put("filepath",request.getServletContext().getContextPath() + "/resources/upload/" + filename );
		return ret;
	}
	/**
	 * 判断该用户名是否存在
	 * @param username
	 * @param id
	 * @return
	 */
	private boolean isExist(String username,Long id){
		User user = userService.findByUsername(username);
		if(user == null)return false;
		if(user.getId().longValue() == id.longValue())return false;
		return true;
	}
}

/**
	 * 商品评论页面
	 * @param model
	 * @param pid
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/comment",method = RequestMethod.GET)
	public ModelAndView comment(ModelAndView model,Long pid,HttpServletRequest request){
		model.addObject("productCategoryList", MenuUtil.getTreeCategory(productCategoryService.findList(new HashMap<String, Object>())));
		model.addObject("allCategoryId","shop_hd_menu_all_category");
		model.addObject("currentUser", "current_");
		model.addObject("product", productService.findById(pid));
		model.setViewName("home/order/comment");
		return model;
	}
	
}

@Controller
public class AliPayController {

    //==========================这些信息未经作者允许,不允许分享使用!!!=================================
    private final String APP_ID = "2016110300790563";
    private final String APP_PRIVATE_KEY = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCCsWvZktzLxZhB8yFUp0f98s3uPegxu0p95sYwwSurm9FrCqn8jEJaR92git/i19QsODjE4KFY85O+AVrcZEDJoqubf8Pc5tCGcaCI1Ho+OD2LHW31cmDj29tlLHi2SlsL9EynSD/LL2DsG1Ufj12/TkuWPVAzjwsf/NJwiKV9mTIX/I88RvCJV2tqX8vT8V5LuHvI27vmGeKTgioExymrv6GQlhM1aHv3w2GMShp/n5wY1S0bhgMLL5zzO3FJSOKrOBPTYh0sCLAhvcD7vDXDH3ruBVq+jbtqXkQMdHww1nmaTz/t06uqNEoofGYCKfZWSQgXnPwEQBpqdSEs8Nl/AgMBAAECggEAbYbY9pbwuUkYR7TFKxeh6r3wPQfersbiL88WK0fIHGJSR93BBahZ9yUhJGkeJhJwerqHQN9r+IrxNxwVlHvkG9da789MSrWY7gMN4X4IEFq7oPmB7F/1uR/Ipup1I3f/A26ySsLuy44iMNzbIr7YdvnbuMYbj4oCbcVIawzpe+6ThkSERg+kaqZbg9DsAjLEkUFLRLE37R2F5BgdM4Gc5Dsw6e7ZuRc1fyBwI4bbdC11oxpLTOkFQFL9aAR1iyKvaPhbV7fswYbMBmJXDTplfDLXufcZPbm7MgfbV1sIhipjf6HpNOB3Qc0WI3iWwBNrb5EGD6PbqAtZyLDBPOVz+QKBgQC4s3Xnt18XoQXqHU5cgg+XCZSkP6z5z/NB3rmvCfThFz1mMEhscw3YruvL2ohXxB0cqoI0eiH2LFMG2tw3g4aDavOLx4H2o+VjcT3rFHoePmTTXv/H+R8roE0IMOKpVQ8Mc65EEBHaZtbLAD2vEZpdv8CjBSx9hCVVC3ISF25otQKBgQC1JMfvT5ofKGUqKoqgz3+0sqd8nfkx5Q3BmeS02nhEXgLW65KThfJnez9MB+0V3f4lxJnRTwYGwh7RFL3bViAkFcO1ETwM9rW73n9tkmuAjY0OPQGiPfxnMUgmGUyR7cov8j7t/cCRUREx/GUXxAOngheDxXsZ8pSX8bPhs2ed4wKBgBwAmU+YLYKXlx33c3ny/goYGcENJlx5epfx/JTdHZNCwrxLda97gg3n9zfg2er0gLVn5HWwTpXUAoJ3jAuelTY3cNUwWjPahVyePpT1dc5AB2lEbeMTkfY7R3KGdtbVXoK0xybqiMpj7Qy57KAuOwkbmUkd77DX6BEMuy6i/spBAoGBAKAI+sqmnRdh7N6v7wHb0IuoOuiR+JLoNpsQh0pwqUhddkzCmyDSejKKZIWbiw6CrgJYCz0sf7qAzhESLhoVoRfAUsMpktAxNqXgENyRO4C7jh9CLqtT8CaLF57xQwC6AKMTdh10ziiUYoiy3+17M29OM9ArLHLkKfuDgtSoV6bZAoGATIOCxQrqrZFVe4zLCnzcAFHFQvqxeNKdeLo7fMfQhU5MnDn9TVmzHhVtNg0SfdNA4WwbVX2Per019M/UcKSjJc5uYJ8G5BZaBZ7ZNJ1JAG1TtOi0m4zAFJJG3SznJVgKOFCDeMc7shMpE2FnTXBJx39LCweTnz8PsF4T4A2/GLY=";
			queryMap.put("priceMin", priceMin);
		}
		if(priceMax != null){
			queryMap.put("priceMax", priceMax);
		}
		Role role = (Role) request.getSession().getAttribute("role");
		User user = (User) request.getSession().getAttribute("admin");
		if(role.getId().equals(Long.valueOf("2"))) {
			//如果是卖家角色, 只能看到自己的商品
			queryMap.put("userId", user.getId());
		}
		queryMap.put("offset", page.getOffset());
		queryMap.put("pageSize", page.getRows());
		ret.put("rows", productService.findList(queryMap));
		ret.put("total", productService.getTotal(queryMap));
		return ret;
	}
	
	/**
	 * 修改商品状态
	 * @param product
	 * @return
	 */
	@RequestMapping(value="/edit_state",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> editState(Product product){
		Map<String, Object> ret = new HashMap<String, Object>();
		if(product == null || product.getId() == null) {
			ret.put("type", "error");
			ret.put("msg", "非法数据!");
			return ret;
		}
		Product selectedProduct = productService.findById(product.getId());
		if(selectedProduct == null) {
			ret.put("type", "error");
			ret.put("msg", "此商品不存在!");
			return ret;
		}
		selectedProduct.setState(product.getState());
		productService.edit(selectedProduct);
		ret.put("type", "success");
		ret.put("msg", "成功修改商品状态!");
		return ret;
	}
	
	 * @param productCategorieList
	 * @return
	 */
	private List<Map<String, Object>> getTreeCategory(List<ProductCategory> productCategorieList){
		List<Map<String, Object>> ret = new ArrayList<Map<String,Object>>();
		//所有的父分类整理
		for(ProductCategory productCategory : productCategorieList){
			if(productCategory.getParentId() == null){
				Map<String, Object> top = new HashMap<String, Object>();
				top.put("id", productCategory.getId());
				top.put("text", productCategory.getName());
				top.put("children", new ArrayList<Map<String,Object>>());
				ret.add(top);
			}
		}
		for(ProductCategory productCategory : productCategorieList){
			if(productCategory.getParentId() != null){
				for(Map<String, Object> map : ret){
					if(productCategory.getParentId().longValue() == Long.valueOf(map.get("id")+"")){
						List children = (List)map.get("children");
						Map<String, Object> child = new HashMap<String, Object>();
						child.put("id", productCategory.getId());
						child.put("text", productCategory.getName());
						children.add(child);
					}
				}
			}
		}
		return ret;
	}
}

			return ret;
		}
		ret.put("type", "success");
		ret.put("msg", "添加成功!");
		return ret;
	}
	
	/**
	 * 编辑客户
	 * @param account
	 * @return
	 */
	@RequestMapping(value="/edit",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> edit(Account account){
		Map<String, Object> ret = new HashMap<String, Object>();
		if(account == null){
			ret.put("type", "error");
			ret.put("msg", "请填写正确的客户信息");
			return ret;
		}
		if(StringUtils.isEmpty(account.getName())){
			ret.put("type", "error");
			ret.put("msg", "请填写客户名称");
			return ret;
		}
		if(StringUtils.isEmpty(account.getPassword())){
			ret.put("type", "error");
			ret.put("msg", "请填写客户登录密码!");
			return ret;
		}
		if(isExist(account.getName(), account.getId())){
			ret.put("type", "error");
			ret.put("msg", "该用户名已存在!");
			return ret;
		}
		if(accountService.edit(account) <= 0){
			ret.put("type", "error");
			ret.put("msg", "添加失败,请联系管理员!");
			return ret;
		}
		ret.put("type", "success");
		ret.put("msg", "编辑成功!");
		return ret;
	}
	
	/**
	 * 删除客户
	 * @param id
	 * @return
		model.addObject("sellProductList", productService.findList(queryMap));
		model.addObject("currentHome", "current_");
		model.addObject("commentList", commentService.findList(queryMap));
		model.setViewName("home/product/detail");
		product.setViewNum(product.getViewNum()+1);
		productService.updateNum(product);
		return model;
	}
	
	/**
	 * 商品分类列表页面
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/product_category_list",method = RequestMethod.GET)
	public ModelAndView productCategoryList(
			@RequestParam(name="cid",required=true)Long cid,
			@RequestParam(name="orderby",required=false)String orderby,
			@RequestParam(name="priceMin",required=false)Double priceMin,
			@RequestParam(name="priceMax",required=false)Double priceMax,
			@RequestParam(name="page",required=false)Integer page,
			ModelAndView model){
		model.addObject("allCategoryId","shop_hd_menu_all_category");
		model.addObject("currentHome", "current_");
		if(cid == null){
			model.addObject("msg", "分类不存在");
			model.setViewName("home/common/error");
			return model;
		}
		ProductCategory productCategory = productCategoryService.findById(cid);
		if(productCategory == null){
			model.addObject("msg", "分类不存在");
			model.setViewName("home/common/error");
			return model;
		}
		model.addObject("title", "搜索【" + productCategory.getName() + "】分类下的商品");
		Map<String, Object> queryListMap = new HashMap<String, Object>();
		queryListMap.put("tags", cid);
		if(!StringUtils.isEmpty(orderby)){
			queryListMap.put("orderBy", orderby);
			queryListMap.put("sort", "desc");
		}
		if(priceMin != null){
			queryListMap.put("priceMin", priceMin);
		}
		if(priceMax != null){
			queryListMap.put("priceMax", priceMax);
		}
		if(page == null || page.intValue() <= 0){
			page = 1;

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值