大家好!我是岛上程序猿,感谢您阅读本文,欢迎一键三连哦。
💞当前专栏:微信小程序毕业设计
精彩专栏推荐👇🏻👇🏻👇🏻
开发运行环境
①前端:微信小程序开发工具
② 后端:Java
- 框架:ssm
- JDK版本:JDK1.8
- 服务器:tomcat7
- 数据库:mysql 5.7
- 数据库工具:Navicat12
- 开发软件:eclipse/myeclipse/idea
- Maven包:Maven3.3.9
- 浏览器:谷歌浏览器
源码下载地址:
https://download.csdn.net/download/m0_46388260/89223502
论文目录
【如需全文请按文末获取联系】
一、项目简介
基于微信小程序的跳蚤市场按照操作主体分为管理员后台与用户小程序前台。管理员的功能包括对用户信息的管理,对商品,商品订单,商品留言,论坛,新闻,收货地址等信息的管理。用户的功能包括购买商品,发布商品,发帖,评论帖子,在线充值,查看订单等。该系统采用了SSM框架,Mysql数据库,Java语言等技术实现管理员后台,采用微信开发者工具来对用户小程序端进行了开发。
二、系统设计
2.1软件功能模块设计
图4.1即为设计的管理员功能结构,管理员权限操作的功能包括对用户信息的管理,对商品,商品订单,商品留言,论坛,新闻,收货地址等信息的管理。
图4.2即为设计的用户功能结构,用户权限操作的功能包括购买商品,发布商品,发帖,评论帖子,在线充值,查看订单等。
2.2数据库设计
(1)图4.4即为用户这个实体所拥有的属性值。
(2)图4.5即为商品这个实体所拥有的属性值。
(3)图4.6即为商品订单这个实体所拥有的属性值。
三、系统项目部分截图
3.1管理员功能实现
商品信息管理
图5.1 即为编码实现的商品信息管理界面,管理员在该界面中对商品下架,新增商品,修改商品等操作。
商品订单管理
图5.2 即为编码实现的商品订单管理界面,管理员在该界面中具备查询商品订单,删除商品订单,查看商品订单详情等操作。
用户管理
图5.4 即为编码实现的用户管理界面,管理员在该界面中具备更改,删除,查询小程序端已经注册的用户资料的权限。
3.2用户功能实现
商品信息
图5.6 即为编码实现的商品信息界面,用户在该界面中对商品介绍进行了解,可以点击购买按钮购买商品。
订单确认
图5.7 即为编码实现的订单确认界面,用户在该界面中需要对收货地址进行选择,然后对购买清单进行查看,最后才提交订单并支付。
我的订单
图5.8 即为编码实现的我的订单界面,用户在该界面中能够查看已支付订单,已完成订单等信息,可以对各个订单进行相应操作,包括订单退款等操作。
四、部分核心代码
package com.controller;
import java.io.File;
import java.math.BigDecimal;
import java.net.URL;
import java.text.SimpleDateFormat;
import com.alibaba.fastjson.JSONObject;
import java.util.*;
import org.springframework.beans.BeanUtils;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.context.ContextLoader;
import javax.servlet.ServletContext;
import com.service.TokenService;
import com.utils.*;
import java.lang.reflect.InvocationTargetException;
import com.service.DictionaryService;
import org.apache.commons.lang3.StringUtils;
import com.annotation.IgnoreAuth;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.entity.*;
import com.entity.view.*;
import com.service.*;
import com.utils.PageUtils;
import com.utils.R;
import com.alibaba.fastjson.*;
/**
* 商品订单
* 后端接口
* @author
* @email
*/
@RestController
@Controller
@RequestMapping("/goodsOrder")
public class GoodsOrderController {
private static final Logger logger = LoggerFactory.getLogger(GoodsOrderController.class);
@Autowired
private GoodsOrderService goodsOrderService;
@Autowired
private TokenService tokenService;
@Autowired
private DictionaryService dictionaryService;
//级联表service
@Autowired
private AddressService addressService;
@Autowired
private GoodsService goodsService;
@Autowired
private YonghuService yonghuService;
/**
* 后端列表
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){
logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
String role = String.valueOf(request.getSession().getAttribute("role"));
if(StringUtil.isEmpty(role))
return R.error(511,"权限为空");
else if("用户".equals(role))
params.put("yonghuId",request.getSession().getAttribute("userId"));
if(params.get("orderBy")==null || params.get("orderBy")==""){
params.put("orderBy","id");
}
PageUtils page = goodsOrderService.queryPage(params);
//字典表数据转换
List<GoodsOrderView> list =(List<GoodsOrderView>)page.getList();
for(GoodsOrderView c:list){
//修改对应字典表字段
dictionaryService.dictionaryConvert(c, request);
}
return R.ok().put("data", page);
}
/**
* 后端详情
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id, HttpServletRequest request){
logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
GoodsOrderEntity goodsOrder = goodsOrderService.selectById(id);
if(goodsOrder !=null){
//entity转view
GoodsOrderView view = new GoodsOrderView();
BeanUtils.copyProperties( goodsOrder , view );//把实体数据重构到view中
//级联表
AddressEntity address = addressService.selectById(goodsOrder.getAddressId());
if(address != null){
BeanUtils.copyProperties( address , view ,new String[]{ "id", "createDate"});//把级联的数据添加到view中,并排除id和创建时间字段
view.setAddressId(address.getId());
}
//级联表
GoodsEntity goods = goodsService.selectById(goodsOrder.getGoodsId());
if(goods != null){
BeanUtils.copyProperties( goods , view ,new String[]{ "id", "createDate"});//把级联的数据添加到view中,并排除id和创建时间字段
view.setGoodsId(goods.getId());
}
//级联表
YonghuEntity yonghu = yonghuService.selectById(goodsOrder.getYonghuId());
if(yonghu != null){
BeanUtils.copyProperties( yonghu , view ,new String[]{ "id", "createDate"});//把级联的数据添加到view中,并排除id和创建时间字段
view.setYonghuId(yonghu.getId());
}
//修改对应字典表字段
dictionaryService.dictionaryConvert(view, request);
return R.ok().put("data", view);
}else {
return R.error(511,"查不到数据");
}
}
/**
* 后端保存
*/
@RequestMapping("/save")
public R save(@RequestBody GoodsOrderEntity goodsOrder, HttpServletRequest request){
logger.debug("save方法:,,Controller:{},,goodsOrder:{}",this.getClass().getName(),goodsOrder.toString());
String role = String.valueOf(request.getSession().getAttribute("role"));
if(StringUtil.isEmpty(role))
return R.error(511,"权限为空");
else if("用户".equals(role))
goodsOrder.setYonghuId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));
goodsOrder.setInsertTime(new Date());
goodsOrder.setCreateTime(new Date());
goodsOrderService.insert(goodsOrder);
return R.ok();
}
/**
* 后端修改
*/
@RequestMapping("/update")
public R update(@RequestBody GoodsOrderEntity goodsOrder, HttpServletRequest request){
logger.debug("update方法:,,Controller:{},,goodsOrder:{}",this.getClass().getName(),goodsOrder.toString());
goodsOrderService.updateById(goodsOrder);//根据id更新
return R.ok();
}
/**
* 删除
*/
@RequestMapping("/delete")
public R delete(@RequestBody Integer[] ids){
logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
goodsOrderService.deleteBatchIds(Arrays.asList(ids));
return R.ok();
}
/**
* 批量上传
*/
@RequestMapping("/batchInsert")
public R save( String fileName){
logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);
try {
List<GoodsOrderEntity> goodsOrderList = new ArrayList<>();//上传的东西
Map<String, List<String>> seachFields= new HashMap<>();//要查询的字段
Date date = new Date();
int lastIndexOf = fileName.lastIndexOf(".");
if(lastIndexOf == -1){
return R.error(511,"该文件没有后缀");
}else{
String suffix = fileName.substring(lastIndexOf);
if(!".xls".equals(suffix)){
return R.error(511,"只支持后缀为xls的excel文件");
}else{
URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);//获取文件路径
File file = new File(resource.getFile());
if(!file.exists()){
return R.error(511,"找不到上传文件,请联系管理员");
}else{
List<List<String>> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件
dataList.remove(0);//删除第一行,因为第一行是提示
for(List<String> data:dataList){
//循环
GoodsOrderEntity goodsOrderEntity = new GoodsOrderEntity();
// goodsOrderEntity.setGoodsOrderUuidNumber(data.get(0)); //订单号 要改的
// goodsOrderEntity.setGoodsId(Integer.valueOf(data.get(0))); //商品 要改的
// goodsOrderEntity.setYonghuId(Integer.valueOf(data.get(0))); //用户 要改的
// goodsOrderEntity.setAddressId(Integer.valueOf(data.get(0))); //收货地址 要改的
// goodsOrderEntity.setBuyNumber(Integer.valueOf(data.get(0))); //购买数量 要改的
// goodsOrderEntity.setGoodsOrderTruePrice(data.get(0)); //实付价格 要改的
// goodsOrderEntity.setGoodsOrderTypes(Integer.valueOf(data.get(0))); //订单类型 要改的
// goodsOrderEntity.setGoodsOrderPaymentTypes(Integer.valueOf(data.get(0))); //支付类型 要改的
// goodsOrderEntity.setInsertTime(date);//时间
// goodsOrderEntity.setCreateTime(date);//时间
goodsOrderList.add(goodsOrderEntity);
//把要查询是否重复的字段放入map中
//订单号
if(seachFields.containsKey("goodsOrderUuidNumber")){
List<String> goodsOrderUuidNumber = seachFields.get("goodsOrderUuidNumber");
goodsOrderUuidNumber.add(data.get(0));//要改的
}else{
List<String> goodsOrderUuidNumber = new ArrayList<>();
goodsOrderUuidNumber.add(data.get(0));//要改的
seachFields.put("goodsOrderUuidNumber",goodsOrderUuidNumber);
}
}
//查询是否重复
//订单号
List<GoodsOrderEntity> goodsOrderEntities_goodsOrderUuidNumber = goodsOrderService.selectList(new EntityWrapper<GoodsOrderEntity>().in("goods_order_uuid_number", seachFields.get("goodsOrderUuidNumber")));
if(goodsOrderEntities_goodsOrderUuidNumber.size() >0 ){
ArrayList<String> repeatFields = new ArrayList<>();
for(GoodsOrderEntity s:goodsOrderEntities_goodsOrderUuidNumber){
repeatFields.add(s.getGoodsOrderUuidNumber());
}
return R.error(511,"数据库的该表中的 [订单号] 字段已经存在 存在数据为:"+repeatFields.toString());
}
goodsOrderService.insertBatch(goodsOrderList);
return R.ok();
}
}
}
}catch (Exception e){
return R.error(511,"批量插入数据异常,请联系管理员");
}
}
/**
* 前端列表
*/
@IgnoreAuth
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params, HttpServletRequest request){
logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
// 没有指定排序字段就默认id倒序
if(StringUtil.isEmpty(String.valueOf(params.get("orderBy")))){
params.put("orderBy","id");
}
PageUtils page = goodsOrderService.queryPage(params);
//字典表数据转换
List<GoodsOrderView> list =(List<GoodsOrderView>)page.getList();
for(GoodsOrderView c:list)
dictionaryService.dictionaryConvert(c, request); //修改对应字典表字段
return R.ok().put("data", page);
}
/**
* 前端详情
*/
@RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id, HttpServletRequest request){
logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
GoodsOrderEntity goodsOrder = goodsOrderService.selectById(id);
if(goodsOrder !=null){
//entity转view
GoodsOrderView view = new GoodsOrderView();
BeanUtils.copyProperties( goodsOrder , view );//把实体数据重构到view中
//级联表
AddressEntity address = addressService.selectById(goodsOrder.getAddressId());
if(address != null){
BeanUtils.copyProperties( address , view ,new String[]{ "id", "createDate"});//把级联的数据添加到view中,并排除id和创建时间字段
view.setAddressId(address.getId());
}
//级联表
GoodsEntity goods = goodsService.selectById(goodsOrder.getGoodsId());
if(goods != null){
BeanUtils.copyProperties( goods , view ,new String[]{ "id", "createDate"});//把级联的数据添加到view中,并排除id和创建时间字段
view.setGoodsId(goods.getId());
}
//级联表
YonghuEntity yonghu = yonghuService.selectById(goodsOrder.getYonghuId());
if(yonghu != null){
BeanUtils.copyProperties( yonghu , view ,new String[]{ "id", "createDate"});//把级联的数据添加到view中,并排除id和创建时间字段
view.setYonghuId(yonghu.getId());
}
//修改对应字典表字段
dictionaryService.dictionaryConvert(view, request);
return R.ok().put("data", view);
}else {
return R.error(511,"查不到数据");
}
}
/**
* 前端保存
*/
@RequestMapping("/add")
public R add(@RequestBody GoodsOrderEntity goodsOrder, HttpServletRequest request){
logger.debug("add方法:,,Controller:{},,goodsOrder:{}",this.getClass().getName(),goodsOrder.toString());
String role = String.valueOf(request.getSession().getAttribute("role"));
if("用户".equals(role)){
GoodsEntity goodsEntity = goodsService.selectById(goodsOrder.getGoodsId());
//商品发布用户信息
YonghuEntity user = yonghuService.selectById(goodsEntity.getYonghuId());
Integer userId = (Integer) request.getSession().getAttribute("userId");
//购买用户信息
YonghuEntity yonghuEntity = yonghuService.selectById(userId);
if(goodsEntity == null){
return R.error(511,"查不到该物品");
}
if(false){
}
else if((goodsEntity.getGoodsKucunNumber() - goodsOrder.getBuyNumber())<0){
return R.error(511,"购买数量不能大于库存数量");
}
else if(goodsEntity.getGoodsNewMoney() == null){
return R.error(511,"物品价格不能为空");
}
//判断商品的库存是否足够
if(goodsEntity.getGoodsKucunNumber() < goodsOrder.getBuyNumber()){
//商品库存不足直接返回
return R.error(goodsEntity.getGoodsName()+"的库存不足");
}else{
//商品库存充足就减库存
goodsEntity.setGoodsKucunNumber(goodsEntity.getGoodsKucunNumber() - goodsOrder.getBuyNumber());
}
//计算所获得积分
Double buyJifen =0.0;
if(yonghuEntity == null)
return R.error(511,"用户不能为空");
if(yonghuEntity.getNewMoney() == null)
return R.error(511,"用户金额不能为空");
//减少购买用户余额
double balance = yonghuEntity.getNewMoney() - goodsEntity.getGoodsNewMoney()*goodsOrder.getBuyNumber();//余额
//增加发布用户的余额
user.setNewMoney(user.getNewMoney()+goodsEntity.getGoodsNewMoney()*goodsOrder.getBuyNumber());
if(balance<0)
return R.error(511,"余额不够支付");
goodsOrder.setGoodsOrderTypes(3); //设置订单状态为已支付
goodsOrder.setGoodsOrderTruePrice(goodsEntity.getGoodsNewMoney()*goodsOrder.getBuyNumber()); //设置实付价格
goodsOrder.setGoodsOrderPaymentTypes(1);
goodsOrder.setInsertTime(new Date());
goodsOrder.setCreateTime(new Date());
goodsOrder.setYonghuId(userId);
goodsOrderService.insert(goodsOrder);//新增订单
yonghuEntity.setNewMoney(balance);//设置金额
yonghuService.updateById(yonghuEntity);
yonghuService.updateById(user);
goodsService.updateById(goodsEntity);
return R.ok();
}else{
return R.error(511,"您没有权限支付订单");
}
}
/**
* 添加订单
*/
@RequestMapping("/order")
public R add(@RequestParam Map<String, Object> params, HttpServletRequest request){
logger.debug("order方法:,,Controller:{},,params:{}",this.getClass().getName(),params.toString());
String goodsOrderUuidNumber = String.valueOf(new Date().getTime());
//获取当前登录用户的id
Integer userId = (Integer) request.getSession().getAttribute("userId");
Integer addressId = Integer.valueOf(String.valueOf(params.get("addressId")));
Integer goodsOrderPaymentTypes = Integer.valueOf(String.valueOf(params.get("goodsOrderPaymentTypes")));//支付类型
String data = String.valueOf(params.get("goodss"));
JSONArray jsonArray = JSON.parseArray(data);
List<Map> goodss = JSON.parseObject(jsonArray.toString(), List.class);
//获取当前登录用户的个人信息
YonghuEntity yonghuEntity = yonghuService.selectById(userId);
//当前订单表
List<GoodsOrderEntity> goodsOrderList = new ArrayList<>();
//商品表
List<GoodsEntity> goodsList = new ArrayList<>();
//购物车ids
List<Integer> cartIds = new ArrayList<>();
BigDecimal zhekou = new BigDecimal(1.0);
//循环取出需要的数据
for (Map<String, Object> map : goodss) {
//取值
Integer goodsId = Integer.valueOf(String.valueOf(map.get("goodsId")));//商品id
Integer buyNumber = Integer.valueOf(String.valueOf(map.get("buyNumber")));//购买数量
GoodsEntity goodsEntity = goodsService.selectById(goodsId);//购买的商品
String id = String.valueOf(map.get("id"));
if(StringUtil.isNotEmpty(id))
cartIds.add(Integer.valueOf(id));
//订单信息表增加数据
GoodsOrderEntity goodsOrderEntity = new GoodsOrderEntity<>();
//赋值订单信息
goodsOrderEntity.setGoodsOrderUuidNumber(goodsOrderUuidNumber);//订单号
goodsOrderEntity.setGoodsId(goodsId);//商品
goodsOrderEntity.setYonghuId(userId);//用户
goodsOrderEntity.setAddressId(addressId);//收货地址
goodsOrderEntity.setBuyNumber(buyNumber);//购买数量 ??????
goodsOrderEntity.setGoodsOrderTypes(3);//订单类型
goodsOrderEntity.setGoodsOrderPaymentTypes(goodsOrderPaymentTypes);//支付类型
goodsOrderEntity.setInsertTime(new Date());//订单创建时间
goodsOrderEntity.setCreateTime(new Date());//创建时间
//判断是什么支付方式 1代表余额 2代表积分
if(goodsOrderPaymentTypes == 1){//余额支付
//计算金额
Double money = new BigDecimal(goodsEntity.getGoodsNewMoney()).multiply(new BigDecimal(buyNumber)).multiply(zhekou).doubleValue();
if(yonghuEntity.getNewMoney() - money <0 ){
return R.error("余额不足,请充值!!!");
}else{
//计算所获得积分
Double buyJifen =0.0;
yonghuEntity.setNewMoney(yonghuEntity.getNewMoney() - money); //设置金额
goodsOrderEntity.setGoodsOrderTruePrice(money);
}
}
goodsOrderList.add(goodsOrderEntity);
goodsList.add(goodsEntity);
}
goodsOrderService.insertBatch(goodsOrderList);
goodsService.updateBatchById(goodsList);
yonghuService.updateById(yonghuEntity);
return R.ok();
}
/**
* 退款
*/
@RequestMapping("/refund")
public R refund(Integer id, HttpServletRequest request){
logger.debug("refund方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
String role = String.valueOf(request.getSession().getAttribute("role"));
if("用户".equals(role)){
GoodsOrderEntity goodsOrder = goodsOrderService.selectById(id);
Integer goodsId = goodsOrder.getGoodsId();
GoodsEntity goodsEntity = goodsService.selectById(goodsId);
YonghuEntity user = yonghuService.selectById(goodsEntity.getYonghuId());
Integer userId = (Integer) request.getSession().getAttribute("userId");
//购买用户信息
YonghuEntity yonghuEntity = yonghuService.selectById(userId);
Integer buyNumber = goodsOrder.getBuyNumber();
Integer goodsOrderPaymentTypes = goodsOrder.getGoodsOrderPaymentTypes();
if(goodsId == null)
return R.error(511,"查不到该物品");
if(goodsEntity == null)
return R.error(511,"查不到该物品");
Double goodsNewMoney = goodsEntity.getGoodsNewMoney();
if(goodsNewMoney == null)
return R.error(511,"物品价格不能为空");
if(yonghuEntity == null)
return R.error(511,"用户不能为空");
if(yonghuEntity.getNewMoney() == null)
return R.error(511,"用户金额不能为空");
Double zhekou = 1.0;
//判断是什么支付方式 1代表余额 2代表积分
if(goodsOrderPaymentTypes == 1){//余额支付
//计算金额
Double money = goodsEntity.getGoodsNewMoney() * buyNumber * zhekou;
//计算所获得积分
Double buyJifen = 0.0;
yonghuEntity.setNewMoney(yonghuEntity.getNewMoney() + money); //设置金额
user.setNewMoney(user.getNewMoney()-money);
}
goodsEntity.setGoodsKucunNumber(goodsEntity.getGoodsKucunNumber() + buyNumber);
goodsOrder.setGoodsOrderTypes(2);//设置订单状态为退款
goodsOrderService.updateById(goodsOrder);//根据id更新
yonghuService.updateById(yonghuEntity);//更新用户信息
yonghuService.updateById(user);//更新发布商品用户信息
goodsService.updateById(goodsEntity);//更新订单中物品的信息
return R.ok();
}else{
return R.error(511,"您没有权限退款");
}
}
/**
* 发货
*/
@RequestMapping("/deliver")
public R deliver(Integer id){
logger.debug("refund:,,Controller:{},,ids:{}",this.getClass().getName(),id.toString());
GoodsOrderEntity goodsOrderEntity = new GoodsOrderEntity();;
goodsOrderEntity.setId(id);
goodsOrderEntity.setGoodsOrderTypes(4);
boolean b = goodsOrderService.updateById( goodsOrderEntity);
if(!b){
return R.error("发货出错");
}
return R.ok();
}
/**
* 收货
*/
@RequestMapping("/receiving")
public R receiving(Integer id){
logger.debug("refund:,,Controller:{},,ids:{}",this.getClass().getName(),id.toString());
GoodsOrderEntity goodsOrderEntity = new GoodsOrderEntity();
goodsOrderEntity.setId(id);
goodsOrderEntity.setGoodsOrderTypes(5);
boolean b = goodsOrderService.updateById( goodsOrderEntity);
if(!b){
return R.error("收货出错");
}
return R.ok();
}
/**
* 评价
*/
@RequestMapping("/commentback")
public R commentback(Integer id, String commentbackText,HttpServletRequest request){
logger.debug("commentback方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
String role = String.valueOf(request.getSession().getAttribute("role"));
if("用户".equals(role)){
GoodsOrderEntity goodsOrder = goodsOrderService.selectById(id);
if(goodsOrder == null)
return R.error(511,"查不到该订单");
if(goodsOrder.getGoodsOrderTypes() != 5)
return R.error(511,"您不能评价");
Integer goodsId = goodsOrder.getGoodsId();
if(goodsId == null)
return R.error(511,"查不到该物品");
goodsOrder.setGoodsOrderTypes(1);//设置订单状态为已评价
goodsOrderService.updateById(goodsOrder);//根据id更新
return R.ok();
}else{
return R.error(511,"您没有权限评价");
}
}
}
获取源码或论文
如需对应的论文或源码,以及其他定制需求,也可以下方微信联系我。