基于javaweb+mysql的springboot生鲜水果商城(java+springboot+html+thymeleaf+bootstrap+mysql+redis)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot生鲜水果商城(java+springboot+html+thymeleaf+bootstrap+mysql+redis)
项目介绍
后台功能:
- 后台商品信息的添加 2. 后台商品信息的维护 要求:商品图片的修改。先显示现有的图片,当鼠标移动到图片上时,图片右上角显示一把X,即允许删除当前图片,然后提供添加新图片的按钮。类似于QQ空间相册中图片的修改一样。 上传的所有商品图片必须在右下角自动加上水印,即前台显示时,显示已经加好水印的图片。 3. 后台统计报表 要求:使用Echarts显示统计日营业额、月营业额、季度营业额以及年度营业额 以及 根据商品统计月营业额
前台功能:
-
首页商品显示 要求:显示每种类型的最新四种商品信息(一次性查出,即只能发送一次请求和一条sql语句) 2. 点击首页 查看更多后,根据类型跳到goods.html页面分页显示当前类型的商品信息,排序规则:先根据销售数量降序,再根据商品编号降序 3. 点击加入购物车按钮时 要求: 先判断有没有登录,如果没有登录先提醒用户"请先登录…",然后跳到登录界面,登录成功后再跳回到原来界面 如果已经登录,加入购物车前,先判断该商品购物车中是否已经存在,如果存在则直接加数量,如果不存在则添加次商品信息到购物车 当前页面 “我的购物车” 商品信息的数量相应的改变 4. 当点击头部或其它地方的 “我的购物车” 时,跳到购物车页面 要求:需要做登录校验 完善全选全不选效果 完善增或减商品的数量,合计、商品数量总计等信息需要联动 5. 在我的购物车页面勾选需要结账的商品后,点击去结账 要求:如果没有勾选任何商品,则给出提示信息 点击编辑收货地址,弹出收货地址编辑框,让用户选择当前订单的收货地址,省市区采用js解析xml三级级联实现 完善收货地址编辑列表,添加设为默认收货地址按钮和当前为默认收货地址的标签,效果可参考京东、淘宝的收货地址效果 修改默认收货地址时,只允许发送一条sql语句 6. 点击提交订单时(需要做登录校验) 要求:删除当前用户购物车中,已下单的商品信息 修改用户已经购买的商品的相应的库存量 在订单表中添加一条订单记录 在订单详细表中添加购买商品的详细信息 要求以上操作必须添加事务管理,所有操作要么同时成功要么都回滚,并且对每个表的操作只能发送一条sql一句,即总共下单功能只能发送4条sql语句 7. 在首页或商品信息页面,当用户点击某个商品时,跳到 details.html 显示该商品的详细信息 扩展功能: 1. 添加前台会员信息的修改,允许前台会员拍照上传或选择图片上传的方式修改个人的图像
-
购物车数据使用redis缓存
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.是否Maven项目: 是;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目
6.数据库:MySql 5.7版本;
技术栈
-
后端:SpringBoot
-
前端:HTML+Thymeleaf+jQuery+easyUI+bootstrap
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,配置tomcat,然后运行; 3. 将项目中application.yml配置文件中的数据库配置改为自己的配置; 4.运行项目,前台地址:http://localhost:8080 用户名 wang11 密码123456 后台地址: http://localhost:8080/toAdminLogin
用户名 supperman 密码 123456
@RequestMapping("/readMoreSecond")
public String readMoreSecond(String groupid, Model model){
if (gdsList!=null){
List<Goods> goodsPart = new ArrayList<Goods>();
if (gdsList.size()>=2){
goodsPart.add(gdsList.get(gdsList.size() - 2));
goodsPart.add(gdsList.get(gdsList.size() - 1));
}else if((gdsList.size()==1)){
goodsPart.add(gdsList.get(gdsList.size() - 1));
}
model.addAttribute("groupid", groupid);
model.addAttribute("goodsPart", goodsPart);
model.addAttribute("goodslist", gdsList);
return "readmoreShop";
}
return null;
}
/**
* 用户查看商品详情
*/
@RequestMapping("/shopMessage")
public String shopMessage(String id, Model model, HttpServletRequest request) {
HttpSession session = request.getSession();
Goods goods = goodsService.shopMessage(id);
if (goods == null) {
return "redirect:toIndex";
} else {
if (goodsBrowse.size() >= 1) {
for (int i = 0; i < goodsBrowse.size(); i++) {
if (goods.getName().equals(goodsBrowse.get(i).getName())) {
goodsBrowse.remove(i);
}
}
}
goodsBrowse.add(goods);
if (goodsBrowse.size() > 4) {
goodsBrowse.remove(0);
}
session.setAttribute("goodsBrowse", goodsBrowse);
String groupid = goods.getGroupid();
List<Goods> goodslist = goodsService.readMore(groupid);
List<Goods> goodsNews = new ArrayList<Goods>();
if (goodslist.size()>=2){
goodsNews.add(goodslist.get(goodslist.size() - 2));
goodsNews.add(goodslist.get(goodslist.size() - 1));
}else if(goodslist.size()==1){
goodsNews.add(goodslist.get(goodslist.size() - 1));
@Controller
public class OrdergoodsController {
@Resource(name = "orderService")
OrderService orderService;
@Resource(name = "userService")
UserService userService;
@Resource(name = "goodsCarService")
GoodsCarService goodsCarService;
@Resource(name = "goodsService")
GoodsService goodsService;
/**
* 取消订单
*/
@RequestMapping("/cancelOrder")
@ResponseBody
public synchronized Map<String, Object> cancelOrder(String id,String username, HttpServletRequest request) {
Map<String, Object> map = new HashMap<String, Object>();
User us = userService.findUserByUsername(username);
Ordergoods ordergoods = orderService.selectGoodsId(id);
if (us.getDr() == 1){
//管理员确定订单
if (ordergoods != null && ordergoods.getDr() != 1){
int result = orderService.orderEnsure(id);
Ordergoods og = orderService.selectOrderById(id);
Map<String, Object> map2 = new HashMap<String, Object>();
double count = (og.getGoods().getCount()-og.getGoodscar().getCount());
map2.put("id",og.getGoods().getId());
map2.put("count",count);
int result1 = goodsService.updateGoodsCount(map2);
if (result==1 && result1==1){
HttpSession session = request.getSession();
List<Ordergoods> ordersWaitList = orderService.ordersWaitList();
session.setAttribute("ordersWaitList",ordersWaitList);
map.put("status", 0);
map.put("message", "发货成功");
}else {
map.put("status", 1);
map.put("message", "发货失败");
}
model.addAttribute("goodsPart", goodsPart);
model.addAttribute("goodslist", goodslist);
return "readmoreShop";
}
@RequestMapping("/readMoreSecond")
public String readMoreSecond(String groupid, Model model){
if (gdsList!=null){
List<Goods> goodsPart = new ArrayList<Goods>();
if (gdsList.size()>=2){
goodsPart.add(gdsList.get(gdsList.size() - 2));
goodsPart.add(gdsList.get(gdsList.size() - 1));
}else if((gdsList.size()==1)){
goodsPart.add(gdsList.get(gdsList.size() - 1));
}
model.addAttribute("groupid", groupid);
model.addAttribute("goodsPart", goodsPart);
model.addAttribute("goodslist", gdsList);
return "readmoreShop";
}
return null;
}
/**
* 用户查看商品详情
*/
@RequestMapping("/shopMessage")
public String shopMessage(String id, Model model, HttpServletRequest request) {
HttpSession session = request.getSession();
Goods goods = goodsService.shopMessage(id);
if (goods == null) {
return "redirect:toIndex";
} else {
if (goodsBrowse.size() >= 1) {
for (int i = 0; i < goodsBrowse.size(); i++) {
if (goods.getName().equals(goodsBrowse.get(i).getName())) {
goodsBrowse.remove(i);
}
}
}
goodsBrowse.add(goods);
if (goodsBrowse.size() > 4) {
goodsBrowse.remove(0);
}
session.setAttribute("goodsBrowse", goodsBrowse);
String groupid = goods.getGroupid();
List<Goods> goodslist = goodsService.readMore(groupid);
map.put("message", "登录成功");
} else {
map.put("status", 1);
map.put("message", "登录失败,请检查信息是否正确");
}
}
return map;
}
/**
* 管理员修改密码
*/
@RequestMapping("/userAdminForgetPwd")
@ResponseBody
public Map<String, Object> adminForgetPwd(String username, String password, String email, String checkcode, HttpServletRequest request) {
Map<String, Object> map = new HashMap<String, Object>();
HttpSession session = request.getSession();
String checkcode_server = (String) session.getAttribute("CHECKCODE");
session.removeAttribute("CHECKCODE");//为了保证验证码只能使用一次
User u = userService.findUserByUsername(username);
if (u != null && checkcode.equalsIgnoreCase(checkcode_server) && email.equals(u.getEmail()) && u.getDr() == 1) {
User user = new User(username, password);
int result = userService.updatePassword(user);
if (result == 1) {
map.put("status", 0);
map.put("message", "修改成功");
} else {
map.put("status", 1);
map.put("message", "修改失败,请检查信息是否正确");
}
} else {
map.put("status", 1);
map.put("message", "修改失败,请检查信息是否正确");
}
return map;
}
/**
* 用户修改密码
*/
@RequestMapping("/userForgetPwd")
@ResponseBody
public Map<String, Object> forgetPwd(String username, String password, String email, String checkcode, HttpServletRequest request) {
Map<String, Object> map = new HashMap<String, Object>();
HttpSession session = request.getSession();
String checkcode_server = (String) session.getAttribute("CHECKCODE");
session.removeAttribute("CHECKCODE");//为了保证验证码只能使用一次
User u = userService.findUserByUsername(username);
if (u != null && checkcode.equalsIgnoreCase(checkcode_server) && email.equals(u.getEmail()) && u.getDr() == 0) {
User user = new User(username, password);
} else {
map.put("status", 1);
map.put("message", "删除失败");
}
return map;
}
/**
* 商品批量删除
*/
@RequestMapping("/deleteAll")
@ResponseBody
public Map<String, Object> deleteAll(String ids) {
Map<String, Object> map = new HashMap<String, Object>();
String[] id_s = ids.split(",");
int result = goodsService.deleteAll(id_s);
if (result >= 1) {
map.put("status", 0);
map.put("message", "删除成功");
} else {
map.put("status", 1);
map.put("message", "删除失败");
}
return map;
}
/**
* 管理员查看商品详情
*/
@RequestMapping("/goodsDetail")
@ResponseBody
public Map<String, Object> goodsDetail(String photo) {
Map<String, Object> map = new HashMap<String, Object>();
Goods goods = goodsService.goodsDetail(photo);
if (goods != null) {
map.put("status", 0);
map.put("message", "加载成功");
map.put("result", goods);
} else {
map.put("status", 1);
map.put("message", "加载失败");
map.put("result", null);
}
return map;
}
if (goodsBrowse.size() > 4) {
goodsBrowse.remove(0);
}
session.setAttribute("goodsBrowse", goodsBrowse);
String groupid = goods.getGroupid();
List<Goods> goodslist = goodsService.readMore(groupid);
List<Goods> goodsNews = new ArrayList<Goods>();
if (goodslist.size()>=2){
goodsNews.add(goodslist.get(goodslist.size() - 2));
goodsNews.add(goodslist.get(goodslist.size() - 1));
}else if(goodslist.size()==1){
goodsNews.add(goodslist.get(goodslist.size() - 1));
}
model.addAttribute("goodsNews", goodsNews);
model.addAttribute("goods", goods);
}
return "shop_message";
}
/**
* 商品主页搜索
*/
@RequestMapping("/goodsSearch")
public String goodsSearch(String search, Model model) {
if (search == "" || search == null) {
return "redirect:toNoPage";
}
List<Goods> goodslist = goodsService.goodsSearch(search);
if (goodslist.size() <= 0) {
return "redirect:toNoPage";
} else {
model.addAttribute("goodslist", goodslist);
}
return "searchmoreShop";
}
}
/**
* 加入购物车
*/
@RequestMapping("/addGoodsCar")
@ResponseBody
public Map<String, Object> addGoodsCar(String goodsid, String shuliang, HttpServletRequest request) {
Map<String, Object> map = new HashMap<String, Object>();
HttpSession session = request.getSession();
String username = (String) session.getAttribute("username");
User u = userService.findUserByUsername(username);
String userid = u.getId();
List<Goodscar> goodscars = goodsCarService.findGoodscarByUserId(userid);
for (Goodscar gs : goodscars) {
if (gs.getGoodsid().equals(goodsid)){
double count = Double.parseDouble(shuliang);
count += gs.getCount();
Map<String, Object> map1 = new HashMap<String, Object>();
int reserved1 = (int) count;
map1.put("count",count);
map1.put("goodsid",goodsid);
map1.put("reserved1",String.valueOf(reserved1));
int result = goodsCarService.updateGoodsCarByCount(map1);
if (result == 1){
List<Goodscar> gds = goodsCarService.findGoodscarByUserId(userid);
App.goodscarList = gds;
session.setAttribute("goodscarList", App.goodscarList);
session.setAttribute("count", App.goodscarList.size());
map.put("status", 0);
map.put("message", "加入购物车成功");
}else {
map.put("status", 1);
map.put("message", "加入购物车失败");
}
return map;
}
}
String id = App.getUid();
int dr = 1;
double count = Double.parseDouble(shuliang);
Map<String, Object> map1 = new HashMap<String, Object>();
map1.put("id",id);
map1.put("goodsid",goodsid);
map1.put("userid",userid);
map1.put("dr",dr);
map1.put("count",count);
map1.put("reserved1",shuliang);
int result = goodsCarService.addGoodsCar(map1);
if (result == 1) {
List<Goodscar> gods = goodsCarService.findGoodscarByUserId(userid);
/**
* 待发货的订单
*/
@RequestMapping("/ordersWaitList")
@ResponseBody
public Map<String, Object> ordersWaitList(HttpServletRequest request){
Map<String, Object> map = new HashMap<String, Object>();
HttpSession session = request.getSession();
List<Ordergoods> ordersWaitList = orderService.ordersWaitList();
if (ordersWaitList.size()<=0){
session.setAttribute("ordersWaitList",ordersWaitList);
map.put("status", 1);
map.put("message", "暂无订单");
}else {
session.setAttribute("ordersWaitList",ordersWaitList);
map.put("status", 0);
map.put("message", "订单查询成功");
}
return map;
}
/**
* 已发货的订单
*/
@RequestMapping("/ordersEndList")
@ResponseBody
public Map<String, Object> ordersEndList(HttpServletRequest request){
Map<String, Object> map = new HashMap<String, Object>();
HttpSession session = request.getSession();
List<Ordergoods> ordersEndList = orderService.ordersEndList();
if (ordersEndList.size()<=0){
map.put("status", 1);
map.put("message", "暂无订单");
}else {
session.setAttribute("ordersEndList",ordersEndList);
map.put("status", 0);
map.put("message", "订单查询成功");
}
return map;
}
// /**
// * 进行发货
// */
// @RequestMapping("/orderEnsure")
// @ResponseBody
// public Map<String, Object> orderEnsure(String id,String reserved1,HttpServletRequest request){
// Map<String, Object> map = new HashMap<String, Object>();
// HttpSession session = request.getSession();
// int result = orderService.orderEnsure(id);
session.setAttribute("ordersList", ordersList);
}
return "ordersList";
}
//代发货订单页面
@RequestMapping("/toOrdersWait")
public String ordersWait(HttpServletRequest request){
HttpSession session = request.getSession();
List<Ordergoods> ordersWaitList = orderService.ordersWaitList();
// if (ordersWaitList.size()>0){
// session.setAttribute("ordersWaitList",ordersWaitList);
// }
session.setAttribute("ordersWaitList",ordersWaitList);
return "ordersWait";
}
//已发货订单页面
@RequestMapping("/toOrdersEnd")
public String ordersEnd(HttpServletRequest request){
HttpSession session = request.getSession();
List<Ordergoods> ordersEndList = orderService.ordersEndList();
if (ordersEndList.size()>0){
session.setAttribute("ordersEndList",ordersEndList);
}
return "ordersEnd";
}
//商品类别列表页面
@RequestMapping("/toGoodsTypeList")
public String goodsTypeList() {
return "goodsTypeList";
}
//增加商品类别列表页面
@RequestMapping("/toAddGoodsType")
public String addGoodsType() {
return "addGoodsType";
}
//日历页面
public Map<String, Object> doLogin(String username, String pwd, String checkcode, int checked, HttpServletRequest request) {
Map<String, Object> map = new HashMap<String, Object>();
HttpSession session = request.getSession();
String checkcode_server = (String) session.getAttribute("CHECKCODE");
session.removeAttribute("CHECKCODE");//为了保证验证码只能使用一次
User u = userService.findUserByUsername(username);
if (u == null || u.getDr() == 1) {
map.put("status", 1);
map.put("message", "登录失败,请检查信息是否正确");
} else {
if (u.getPassword().equals(pwd) && checkcode.equalsIgnoreCase(checkcode_server)) {
String userid = u.getId();
List<Goodscar> goodscars = goodsCarService.findGoodscarByUserId(userid);
App.goodscarList = goodscars;
session.setAttribute("goodscarList", App.goodscarList);
session.setAttribute("count", App.goodscarList.size());
session.setAttribute("username", username);
session.setAttribute("email", u.getEmail());
List<Ordergoods> orders = new ArrayList<Ordergoods>();
List<Ordergoods> ordersEndList = orderService.ordersEndListById(userid);
if (ordersEndList.size()>0){
session.setAttribute("ordersEndListById",ordersEndList);
}
List<Ordergoods> gcs = orderService.selectOrderByuserId(u.getId());
for (Ordergoods gs : gcs) {
orders.add(gs);
}
if (orders.size() > 0) {
session.setAttribute("orders", orders);
}
if (checked == 1) {
App.USERNAME = username;
} else if (checked == 0) {
App.USERNAME = null;
}
map.put("status", 0);
map.put("message", "登录成功");
} else {
map.put("status", 1);
map.put("message", "登录失败,请检查信息是否正确");
}
}
return map;
}
/**
* 管理员登录
* checked 为 1 代表记住用户名和密码,为0 反之
@Value("${web.upload-path}")
private String GoodsPhotoPath;
public GoodsController() {
goodsBrowse = new ArrayList<Goods>();
}
/**
* 分页查询商品列表信息
*/
@RequestMapping("/goodsList")
@ResponseBody
public Map<String, Object> goodsList(int currentPage, String search) {
Map<String, Object> resultMap = new HashMap<String, Object>();
PageBean<Goods> pageBean = new PageBean<Goods>();
int pageSize = 5;
int start = (currentPage - 1) * pageSize;
int size = pageSize;
if (search == "" || search == null) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("start",start);
map.put("size",size);
List<Goods> lists = goodsService.findByPage(map);
// List<Goods> list = goodsService.selectCount();
int count = goodsService.selectCount();
if (count <= 0) {
resultMap.put("status", 1);
resultMap.put("message", "没有数据");
resultMap.put("result", null);
} else {
int totalCount = count;
double tc = totalCount;
int totalPage = (int) Math.ceil(tc / pageSize);
pageBean.setCurrentage(currentPage);
pageBean.setPageSize(pageSize);
pageBean.setTotalCount(totalCount);
pageBean.setTotalPage(totalPage);
pageBean.setLists(lists);
resultMap.put("status", 0);
resultMap.put("message", "有数据");
resultMap.put("result", pageBean);
}
} else {
// String search1 = "";
// search1 += ("%" + search + "%");
// System.out.println(search1);
Map<String, Object> map = new HashMap<String, Object>();
map.put("start",start);
map.put("size",size);
map.put("search",search);
List<Goods> lists = goodsService.findByPageSearch(map);
// List<Goods> list = goodsService.selectSearchCount(search1);
@RequestMapping("/goodsDown")
@ResponseBody
public Map<String, Object> goodsDown(String id) {
Map<String, Object> map = new HashMap<String, Object>();
int result = goodsService.goodsDown(id);
if (result == 1) {
map.put("status", 0);
map.put("message", "下架成功");
} else {
map.put("status", 1);
map.put("message", "下架失败");
}
return map;
}
/**
* 商品删除
*/
@RequestMapping("/goodsDelete")
@ResponseBody
public Map<String, Object> goodsDelete(String id) {
Map<String, Object> map = new HashMap<String, Object>();
int result = goodsService.goodsDelete(id);
if (result == 1) {
map.put("status", 0);
map.put("message", "删除成功");
} else {
map.put("status", 1);
map.put("message", "删除失败");
}
return map;
}
/**
* 商品批量删除
*/
@RequestMapping("/deleteAll")
@ResponseBody
public Map<String, Object> deleteAll(String ids) {
Map<String, Object> map = new HashMap<String, Object>();
String[] id_s = ids.split(",");
resultMap.put("message", "没有数据");
resultMap.put("result", null);
} else {
int totalCount = count;
double tc = totalCount;
int totalPage = (int) Math.ceil(tc / pageSize);
pageBean.setCurrentage(currentPage);
pageBean.setPageSize(pageSize);
pageBean.setTotalCount(totalCount);
pageBean.setTotalPage(totalPage);
pageBean.setLists(lists);
resultMap.put("status", 0);
resultMap.put("message", "有数据");
resultMap.put("result", pageBean);
}
}
return resultMap;
}
/**
* 添加商品
*/
@RequestMapping("/addGoods")
@ResponseBody
public Map<String, Object> addGoods(MultipartFile file, Goods goods) {
Map<String, Object> map = new HashMap<String, Object>();
try {
//获取文件名
String pname = file.getOriginalFilename();
//获取文件格式
String type = pname.substring(pname.lastIndexOf("."));
//重命名
String photo_name = App.getUid() + type;
//将图片存到指定的位置
//windows系统配置图片路径
file.transferTo(new File(GoodsPhotoPath, photo_name));
//mac系统配置图片路径
//file.transferTo(new File("/Users/hanmeng/Desktop/java源码/Springboot生鲜水果商城/源码/GoodsPhoto", photo_name));
//将图片信息存入商品对象
goods.setPhoto(photo_name);
//商品id
goods.setId(App.getUid());
//商品状态
goods.setDr(1);
resultMap.put("status", 1);
resultMap.put("message", "没有数据");
resultMap.put("result", null);
} else {
int totalCount = count;
double tc = totalCount;
int totalPage = (int) Math.ceil(tc / pageSize);
pageBean.setCurrentage(currentPage);
pageBean.setPageSize(pageSize);
pageBean.setTotalCount(totalCount);
pageBean.setTotalPage(totalPage);
pageBean.setLists(lists);
resultMap.put("status", 0);
resultMap.put("message", "有数据");
resultMap.put("result", pageBean);
}
}
return resultMap;
}
/**
* 添加商品
*/
@RequestMapping("/addGoods")
@ResponseBody
public Map<String, Object> addGoods(MultipartFile file, Goods goods) {
Map<String, Object> map = new HashMap<String, Object>();
try {
//获取文件名
String pname = file.getOriginalFilename();
//获取文件格式
String type = pname.substring(pname.lastIndexOf("."));
//重命名
String photo_name = App.getUid() + type;
//将图片存到指定的位置
//windows系统配置图片路径
file.transferTo(new File(GoodsPhotoPath, photo_name));
//mac系统配置图片路径
//file.transferTo(new File("/Users/hanmeng/Desktop/java源码/Springboot生鲜水果商城/源码/GoodsPhoto", photo_name));
//将图片信息存入商品对象
goods.setPhoto(photo_name);
//商品id
goods.setId(App.getUid());
//商品状态
goods.setDr(1);
int i = goodsService.addGoods(goods);
if (i == 1) {
map.put("status", 0);
map.put("message", "添加成功");
} else {
map.put("status", 0);
map.put("message", "交易成功");
}
}
return map;
}
/**
* 立即购买
*/
@RequestMapping("/buyGoodsImmediately")
@ResponseBody
public Map<String, Object> buyGoodsImmediately(String goodsid, String shuliang,HttpServletRequest request){
Map<String, Object> map = new HashMap<String, Object>();
HttpSession session = request.getSession();
String username = (String) session.getAttribute("username");
User u = userService.findUserByUsername(username);
String userid = u.getId();
String id = App.getUid();
int dr = 0;
double count = Double.parseDouble(shuliang);
Map<String, Object> map1 = new HashMap<String, Object>();
map1.put("id",id);
map1.put("goodsid",goodsid);
map1.put("userid",userid);
map1.put("dr",dr);
map1.put("count",count);
map1.put("reserved1",shuliang);
int result = goodsCarService.addGoodsCar(map1);
Map<String, Object> map2 = new HashMap<String, Object>();
map2.put("id",App.getUid());
map2.put("userid",userid);
map2.put("goodsid",goodsid);
map2.put("goodscarid",id);
map2.put("dr",dr);
int result2 = orderService.addOrdergoods(map2);
if (result == 1 && result2 == 1){
List<Ordergoods> orders = new ArrayList<Ordergoods>();
List<Ordergoods> gcs = orderService.selectOrderByuserId(u.getId());
for (Ordergoods gs : gcs) {
orders.add(gs);
map.put("typeDr",typeDr);
List<Goods> lists = goodsService.findByPageDr(map);
// List<Goods> list = goodsService.selectCountDr(typeDr);
int count = goodsService.selectCountDr(typeDr);
if (count <= 0) {
resultMap.put("status", 1);
resultMap.put("message", "没有数据");
resultMap.put("result", null);
} else {
int totalCount = count;
double tc = totalCount;
int totalPage = (int) Math.ceil(tc / pageSize);
pageBean.setCurrentage(currentPage);
pageBean.setPageSize(pageSize);
pageBean.setTotalCount(totalCount);
pageBean.setTotalPage(totalPage);
pageBean.setLists(lists);
resultMap.put("status", 0);
resultMap.put("message", "有数据");
resultMap.put("result", pageBean);
}
} else {
// String search1 = "";
// search1 += ("%" + search + "%");
Map<String, Object> map = new HashMap<String, Object>();
map.put("start",start);
map.put("size",size);
map.put("typeDr",typeDr);
map.put("search",search);
List<Goods> lists = goodsService.findByPageSearchDr(map);
Map<String, Object> map1 = new HashMap<String, Object>();
map1.put("typeDr",typeDr);
map1.put("search",search);
// List<Goods> list = goodsService.selectSearchCountDr(map1);
int count = goodsService.selectSearchCountDr(map1);
if (count <= 0) {
resultMap.put("status", 1);
resultMap.put("message", "没有数据");
resultMap.put("result", null);
} else {
int totalCount = count;
double tc = totalCount;
int totalPage = (int) Math.ceil(tc / pageSize);
pageBean.setCurrentage(currentPage);
pageBean.setPageSize(pageSize);
pageBean.setTotalCount(totalCount);
HttpSession session = request.getSession();
Map<String, Object> map = new HashMap<String, Object>();
User u = userService.findUserByUsername(username);
if (u == null || u.getDr() == 0) {
map.put("status", 1);
map.put("message", "登录失败,请检查信息是否正确");
} else {
if (u.getPassword().equals(password)) {
session.setAttribute("adminUsername", username);
session.setAttribute("adminEmail", u.getEmail());
if (checked == 1) {
App.ADMIN_USERNAME = username;
App.ADMIN_PASSWORD = password;
} else if (checked == 0) {
App.ADMIN_USERNAME = null;
App.ADMIN_PASSWORD = null;
}
map.put("status", 0);
map.put("message", "登录成功");
} else {
map.put("status", 1);
map.put("message", "登录失败,请检查信息是否正确");
}
}
return map;
}
/**
* 管理员修改密码
*/
@RequestMapping("/userAdminForgetPwd")
@ResponseBody
public Map<String, Object> adminForgetPwd(String username, String password, String email, String checkcode, HttpServletRequest request) {
Map<String, Object> map = new HashMap<String, Object>();
HttpSession session = request.getSession();
String checkcode_server = (String) session.getAttribute("CHECKCODE");
session.removeAttribute("CHECKCODE");//为了保证验证码只能使用一次
User u = userService.findUserByUsername(username);
if (u != null && checkcode.equalsIgnoreCase(checkcode_server) && email.equals(u.getEmail()) && u.getDr() == 1) {
User user = new User(username, password);
int result = userService.updatePassword(user);
if (result == 1) {
map.put("status", 0);
map.put("message", "修改成功");
} else {
map.put("status", 1);
map.put("message", "修改失败,请检查信息是否正确");
* 用户登录
* checked 为1 代表记住用户名,为0 代表忘记用户名
*/
@RequestMapping("/userLogin")
@ResponseBody
public Map<String, Object> doLogin(String username, String pwd, String checkcode, int checked, HttpServletRequest request) {
Map<String, Object> map = new HashMap<String, Object>();
HttpSession session = request.getSession();
String checkcode_server = (String) session.getAttribute("CHECKCODE");
session.removeAttribute("CHECKCODE");//为了保证验证码只能使用一次
User u = userService.findUserByUsername(username);
if (u == null || u.getDr() == 1) {
map.put("status", 1);
map.put("message", "登录失败,请检查信息是否正确");
} else {
if (u.getPassword().equals(pwd) && checkcode.equalsIgnoreCase(checkcode_server)) {
String userid = u.getId();
List<Goodscar> goodscars = goodsCarService.findGoodscarByUserId(userid);
App.goodscarList = goodscars;
session.setAttribute("goodscarList", App.goodscarList);
session.setAttribute("count", App.goodscarList.size());
session.setAttribute("username", username);
session.setAttribute("email", u.getEmail());
List<Ordergoods> orders = new ArrayList<Ordergoods>();
List<Ordergoods> ordersEndList = orderService.ordersEndListById(userid);
if (ordersEndList.size()>0){
session.setAttribute("ordersEndListById",ordersEndList);
}
List<Ordergoods> gcs = orderService.selectOrderByuserId(u.getId());
for (Ordergoods gs : gcs) {
orders.add(gs);
}
if (orders.size() > 0) {
session.setAttribute("orders", orders);
}
if (checked == 1) {
App.USERNAME = username;
} else if (checked == 0) {
App.USERNAME = null;
}
map.put("status", 0);
map.put("message", "登录成功");
} else {
map.put("status", 1);
map.put("message", "登录失败,请检查信息是否正确");
}
}
return map;
}
/**