作者:计算机源码社
个人简介:本人七年开发经验,擅长Java、微信小程序、Python、Android等,大家有这一块的问题可以一起交流!
学习资料、程序开发、技术解答、代码讲解、文档报告
JavaWeb项目
微信小程序项目
Python项目
Android项目
随着科技的发展,电子商务的崛起,带动了全民网上购物的浪潮。随着计算机技术和智能电脑和手机设备普遍,商品交易模式发生了质的改变,通过网络平台,手机App下单自己想要的商品,通过物流公司运送到家门口。这种便捷的购物方式逐渐是大众趋势。随着人们生活水平的提高,网购在人们日常生活中必不可少,需求量很大。今年疫情影响无法外出购买商品,通常会选择在网上购买送到家中,实现足不出户享受购物的愉悦。
通过研究调查发现,网购不再是年轻人的市场,有许多中老年人也加入到了网购大军队伍,网购人数不断递增,计算机应用对于购物网站,有实体店无法比拟的优点,快速检索、强大存储、维护成本低、使用期限长等。所以开发一个网上购物商城保证用户便捷、安全、顺利完成商品交易。网上购物商城是以vue框架集成开发,使用Java开发语言,前端使用HTML、JS、CSS,后台使用MySQL数据库等技术去实现。主要功能模块有商品管理、用户管理、订单管理、系统管理等,更安全、更保密地保存客户信息,也提高了管理水平。
基于springboot+vue商品推荐系统采用B/S的结构,Java语言进行设计,后台上采用Mysql数据库。
基于springboot+vue商品推荐系统的主要使用者分为管理员和用户,实现功能包括:
①用户:注册、登录、查看商品信息、查看商品详情、分类搜索、查看推荐商品、添加购物车、提交订单、确认收货、申请退货、评价、收藏、个人信息管理、查看新闻资讯等功能。
②管理员:登录、个人信息管理、用户管理、商品分类管理、商品管理、轮播图管理、新闻资讯管理、订单管理等功能。
/**
* 商品信息
* 后端接口
*/
@RestController
@RequestMapping("/shangpinxinxi")
public class ShangpinxinxiController {
@Autowired
private ShangpinxinxiService shangpinxinxiService;
@Autowired
private StoreupService storeupService;
@Autowired
private OrdersService ordersService;
/**
* 后端商品信息列表
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params,ShangpinxinxiEntity shangpinxinxi,
HttpServletRequest request){
EntityWrapper<ShangpinxinxiEntity> ew = new EntityWrapper<ShangpinxinxiEntity>();
PageUtils page = shangpinxinxiService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, shangpinxinxi), params), params));
return R.ok().put("data", page);
}
/**
* 前端商品信息列表
*/
@IgnoreAuth
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params,ShangpinxinxiEntity shangpinxinxi,
HttpServletRequest request){
EntityWrapper<ShangpinxinxiEntity> ew = new EntityWrapper<ShangpinxinxiEntity>();
PageUtils page = shangpinxinxiService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, shangpinxinxi), params), params));
return R.ok().put("data", page);
}
/**
* 商品信息列表
*/
@RequestMapping("/lists")
public R list( ShangpinxinxiEntity shangpinxinxi){
EntityWrapper<ShangpinxinxiEntity> ew = new EntityWrapper<ShangpinxinxiEntity>();
ew.allEq(MPUtil.allEQMapPre( shangpinxinxi, "shangpinxinxi"));
return R.ok().put("data", shangpinxinxiService.selectListView(ew));
}
/**
* 查询商品信息
*/
@RequestMapping("/query")
public R query(ShangpinxinxiEntity shangpinxinxi){
EntityWrapper< ShangpinxinxiEntity> ew = new EntityWrapper< ShangpinxinxiEntity>();
ew.allEq(MPUtil.allEQMapPre( shangpinxinxi, "shangpinxinxi"));
ShangpinxinxiView shangpinxinxiView = shangpinxinxiService.selectView(ew);
return R.ok("查询商品信息成功").put("data", shangpinxinxiView);
}
/**
* 后端商品信息详情
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id){
ShangpinxinxiEntity shangpinxinxi = shangpinxinxiService.selectById(id);
shangpinxinxi.setClicktime(new Date());
shangpinxinxiService.updateById(shangpinxinxi);
return R.ok().put("data", shangpinxinxi);
}
/**
* 前端商品信息详情
*/
@IgnoreAuth
@RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id){
ShangpinxinxiEntity shangpinxinxi = shangpinxinxiService.selectById(id);
shangpinxinxi.setClicktime(new Date());
shangpinxinxiService.updateById(shangpinxinxi);
return R.ok().put("data", shangpinxinxi);
}
/**
* 后端保存商品信息
*/
@RequestMapping("/save")
public R save(@RequestBody ShangpinxinxiEntity shangpinxinxi, HttpServletRequest request){
shangpinxinxi.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(shangpinxinxi);
shangpinxinxiService.insert(shangpinxinxi);
return R.ok();
}
/**
* 前端保存商品信息
*/
@RequestMapping("/add")
public R add(@RequestBody ShangpinxinxiEntity shangpinxinxi, HttpServletRequest request){
shangpinxinxi.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(shangpinxinxi);
shangpinxinxiService.insert(shangpinxinxi);
return R.ok();
}
/**
* 修改商品信息
*/
@RequestMapping("/update")
public R update(@RequestBody ShangpinxinxiEntity shangpinxinxi, HttpServletRequest request){
//ValidatorUtils.validateEntity(shangpinxinxi);
shangpinxinxiService.updateById(shangpinxinxi);//全部更新
return R.ok();
}
/**
* 删除商品信息
*/
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids){
shangpinxinxiService.deleteBatchIds(Arrays.asList(ids));
return R.ok();
}
/**
* 商品信息提醒接口
*/
@RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type,@RequestParam Map<String, Object> map) {
map.put("column", columnName);
map.put("type", type);
if(type.equals("2")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
Date remindStartDate = null;
Date remindEndDate = null;
if(map.get("remindstart")!=null) {
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindStart);
remindStartDate = c.getTime();
map.put("remindstart", sdf.format(remindStartDate));
}
if(map.get("remindend")!=null) {
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindEnd);
remindEndDate = c.getTime();
map.put("remindend", sdf.format(remindEndDate));
}
}
Wrapper<ShangpinxinxiEntity> wrapper = new EntityWrapper<ShangpinxinxiEntity>();
if(map.get("remindstart")!=null) {
wrapper.ge(columnName, map.get("remindstart"));
}
if(map.get("remindend")!=null) {
wrapper.le(columnName, map.get("remindend"));
}
int count = shangpinxinxiService.selectCount(wrapper);
return R.ok().put("count", count);
}
/**
* 前端商品信息智能排序
*/
@IgnoreAuth
@RequestMapping("/autoSort")
public R autoSort(@RequestParam Map<String, Object> params,ShangpinxinxiEntity shangpinxinxi, HttpServletRequest request,String pre){
EntityWrapper<ShangpinxinxiEntity> ew = new EntityWrapper<ShangpinxinxiEntity>();
Map<String, Object> newMap = new HashMap<String, Object>();
Map<String, Object> param = new HashMap<String, Object>();
Iterator<Map.Entry<String, Object>> it = param.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, Object> entry = it.next();
String key = entry.getKey();
String newKey = entry.getKey();
if (pre.endsWith(".")) {
newMap.put(pre + newKey, entry.getValue());
} else if (StringUtils.isEmpty(pre)) {
newMap.put(newKey, entry.getValue());
} else {
newMap.put(pre + "." + newKey, entry.getValue());
}
}
params.put("sort", "clicktime");
params.put("order", "desc");
PageUtils page = shangpinxinxiService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, shangpinxinxi), params), params));
return R.ok().put("data", page);
}
/**
* (按用户购买推荐)
*/
@RequestMapping("/autoSort2")
public R autoSort2(@RequestParam Map<String, Object> params,ShangpinxinxiEntity shangpinxinxi, HttpServletRequest request){
String userId = request.getSession().getAttribute("userId").toString();
String goodtypeColumn = "shangpinleixing";
List<OrdersEntity> orders = ordersService.selectList(new EntityWrapper<OrdersEntity>().eq("userid", userId).eq("tablename", "shangpinxinxi").orderBy("addtime", false));
List<String> goodtypes = new ArrayList<String>();
Integer limit = params.get("limit")==null?10:Integer.parseInt(params.get("limit").toString());
List<ShangpinxinxiEntity> shangpinxinxiList = new ArrayList<ShangpinxinxiEntity>();
//去重
List<OrdersEntity> ordersDist = new ArrayList<OrdersEntity>();
for(OrdersEntity o1 : orders) {
boolean addFlag = true;
for(OrdersEntity o2 : ordersDist) {
if(o1.getGoodid()==o2.getGoodid() || o1.getGoodtype().equals(o2.getGoodtype())) {
addFlag = false;
break;
}
}
if(addFlag) ordersDist.add(o1);
}
if(ordersDist!=null && ordersDist.size()>0) {
for(OrdersEntity o : ordersDist) {
shangpinxinxiList.addAll(shangpinxinxiService.selectList(new EntityWrapper<ShangpinxinxiEntity>().eq(goodtypeColumn, o.getGoodtype())));
}
}
EntityWrapper<ShangpinxinxiEntity> ew = new EntityWrapper<ShangpinxinxiEntity>();
params.put("sort", "id");
params.put("order", "desc");
PageUtils page = shangpinxinxiService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, shangpinxinxi), params), params));
List<ShangpinxinxiEntity> pageList = (List<ShangpinxinxiEntity>)page.getList();
if(shangpinxinxiList.size()<limit) {
int toAddNum = (limit-shangpinxinxiList.size())<=pageList.size()?(limit-shangpinxinxiList.size()):pageList.size();
for(ShangpinxinxiEntity o1 : pageList) {
boolean addFlag = true;
for(ShangpinxinxiEntity o2 : shangpinxinxiList) {
if(o1.getId().intValue()==o2.getId().intValue()) {
addFlag = false;
break;
}
}
if(addFlag) {
shangpinxinxiList.add(o1);
if(--toAddNum==0) break;
}
}
} else if(shangpinxinxiList.size()>limit) {
shangpinxinxiList = shangpinxinxiList.subList(0, limit);
}
page.setList(shangpinxinxiList);
return R.ok().put("data", page);
}
/**
* 购物车表
* 后端接口
*/
@RestController
@RequestMapping("/cart")
public class CartController {
@Autowired
private CartService cartService;
/**
* 后端购物车列表
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params,CartEntity cart,
HttpServletRequest request){
if(!request.getSession().getAttribute("role").toString().equals("管理员")) {
cart.setUserid((Long)request.getSession().getAttribute("userId"));
}
EntityWrapper<CartEntity> ew = new EntityWrapper<CartEntity>();
PageUtils page = cartService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, cart), params), params));
return R.ok().put("data", page);
}
/**
* 前端购物车列表
*/
@IgnoreAuth
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params,CartEntity cart,
HttpServletRequest request){
EntityWrapper<CartEntity> ew = new EntityWrapper<CartEntity>();
PageUtils page = cartService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, cart), params), params));
return R.ok().put("data", page);
}
/**
* 购物车列表
*/
@RequestMapping("/lists")
public R list( CartEntity cart){
EntityWrapper<CartEntity> ew = new EntityWrapper<CartEntity>();
ew.allEq(MPUtil.allEQMapPre( cart, "cart"));
return R.ok().put("data", cartService.selectListView(ew));
}
/**
* 查询购物车
*/
@RequestMapping("/query")
public R query(CartEntity cart){
EntityWrapper< CartEntity> ew = new EntityWrapper< CartEntity>();
ew.allEq(MPUtil.allEQMapPre( cart, "cart"));
CartView cartView = cartService.selectView(ew);
return R.ok("查询购物车表成功").put("data", cartView);
}
/**
* 后端购物车详情
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id){
CartEntity cart = cartService.selectById(id);
return R.ok().put("data", cart);
}
/**
* 前端购物车详情
*/
@IgnoreAuth
@RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id){
CartEntity cart = cartService.selectById(id);
return R.ok().put("data", cart);
}
/**
* 后端保存购物车
*/
@RequestMapping("/save")
public R save(@RequestBody CartEntity cart, HttpServletRequest request){
cart.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(cart);
cart.setUserid((Long)request.getSession().getAttribute("userId"));
cartService.insert(cart);
return R.ok();
}
/**
* 前端保存购物车
*/
@RequestMapping("/add")
public R add(@RequestBody CartEntity cart, HttpServletRequest request){
cart.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(cart);
cartService.insert(cart);
return R.ok();
}
/**
* 修改购物车
*/
@RequestMapping("/update")
public R update(@RequestBody CartEntity cart, HttpServletRequest request){
//ValidatorUtils.validateEntity(cart);
cartService.updateById(cart);//全部更新
return R.ok();
}
/**
* 删除购物车
*/
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids){
cartService.deleteBatchIds(Arrays.asList(ids));
return R.ok();
}
/**
* 购物车提醒接口
*/
@RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type,@RequestParam Map<String, Object> map) {
map.put("column", columnName);
map.put("type", type);
if(type.equals("2")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
Date remindStartDate = null;
Date remindEndDate = null;
if(map.get("remindstart")!=null) {
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindStart);
remindStartDate = c.getTime();
map.put("remindstart", sdf.format(remindStartDate));
}
if(map.get("remindend")!=null) {
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindEnd);
remindEndDate = c.getTime();
map.put("remindend", sdf.format(remindEndDate));
}
}
Wrapper<CartEntity> wrapper = new EntityWrapper<CartEntity>();
if(map.get("remindstart")!=null) {
wrapper.ge(columnName, map.get("remindstart"));
}
if(map.get("remindend")!=null) {
wrapper.le(columnName, map.get("remindend"));
}
if(!request.getSession().getAttribute("role").toString().equals("管理员")) {
wrapper.eq("userid", (Long)request.getSession().getAttribute("userId"));
}
int count = cartService.selectCount(wrapper);
return R.ok().put("count", count);
}
/**
* 收藏表
* 后端接口
*/
@RestController
@RequestMapping("/storeup")
public class StoreupController {
@Autowired
private StoreupService storeupService;
/**
* 后端收藏商品列表
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params,StoreupEntity storeup,
HttpServletRequest request){
if(!request.getSession().getAttribute("role").toString().equals("管理员")) {
storeup.setUserid((Long)request.getSession().getAttribute("userId"));
}
EntityWrapper<StoreupEntity> ew = new EntityWrapper<StoreupEntity>();
PageUtils page = storeupService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, storeup), params), params));
return R.ok().put("data", page);
}
/**
* 前端收藏商品列表
*/
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params,StoreupEntity storeup,
HttpServletRequest request){
if(!request.getSession().getAttribute("role").toString().equals("管理员")) {
storeup.setUserid((Long)request.getSession().getAttribute("userId"));
}
EntityWrapper<StoreupEntity> ew = new EntityWrapper<StoreupEntity>();
PageUtils page = storeupService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, storeup), params), params));
return R.ok().put("data", page);
}
/**
* 收藏商品列表
*/
@RequestMapping("/lists")
public R list( StoreupEntity storeup){
EntityWrapper<StoreupEntity> ew = new EntityWrapper<StoreupEntity>();
ew.allEq(MPUtil.allEQMapPre( storeup, "storeup"));
return R.ok().put("data", storeupService.selectListView(ew));
}
/**
* 查询收藏商品
*/
@RequestMapping("/query")
public R query(StoreupEntity storeup){
EntityWrapper< StoreupEntity> ew = new EntityWrapper< StoreupEntity>();
ew.allEq(MPUtil.allEQMapPre( storeup, "storeup"));
StoreupView storeupView = storeupService.selectView(ew);
return R.ok("查询收藏表成功").put("data", storeupView);
}
/**
* 后端收藏商品详情
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id){
StoreupEntity storeup = storeupService.selectById(id);
return R.ok().put("data", storeup);
}
/**
* 前端收藏商品详情
*/
@IgnoreAuth
@RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id){
StoreupEntity storeup = storeupService.selectById(id);
return R.ok().put("data", storeup);
}
/**
* 后端保存收藏商品
*/
@RequestMapping("/save")
public R save(@RequestBody StoreupEntity storeup, HttpServletRequest request){
storeup.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(storeup);
storeup.setUserid((Long)request.getSession().getAttribute("userId"));
storeupService.insert(storeup);
return R.ok();
}
/**
* 前端保存收藏商品
*/
@RequestMapping("/add")
public R add(@RequestBody StoreupEntity storeup, HttpServletRequest request){
storeup.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(storeup);
storeup.setUserid((Long)request.getSession().getAttribute("userId"));
storeupService.insert(storeup);
return R.ok();
}
/**
* 修改收藏商品
*/
@RequestMapping("/update")
public R update(@RequestBody StoreupEntity storeup, HttpServletRequest request){
//ValidatorUtils.validateEntity(storeup);
storeupService.updateById(storeup);//全部更新
return R.ok();
}
/**
* 删除收藏商品
*/
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids){
storeupService.deleteBatchIds(Arrays.asList(ids));
return R.ok();
}
/**
* 收藏商品提醒接口
*/
@RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type,@RequestParam Map<String, Object> map) {
map.put("column", columnName);
map.put("type", type);
if(type.equals("2")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
Date remindStartDate = null;
Date remindEndDate = null;
if(map.get("remindstart")!=null) {
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindStart);
remindStartDate = c.getTime();
map.put("remindstart", sdf.format(remindStartDate));
}
if(map.get("remindend")!=null) {
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindEnd);
remindEndDate = c.getTime();
map.put("remindend", sdf.format(remindEndDate));
}
}
Wrapper<StoreupEntity> wrapper = new EntityWrapper<StoreupEntity>();
if(map.get("remindstart")!=null) {
wrapper.ge(columnName, map.get("remindstart"));
}
if(map.get("remindend")!=null) {
wrapper.le(columnName, map.get("remindend"));
}
if(!request.getSession().getAttribute("role").toString().equals("管理员")) {
wrapper.eq("userid", (Long)request.getSession().getAttribute("userId"));
}
int count = storeupService.selectCount(wrapper);
return R.ok().put("count", count);
}