基于javaweb+mysql的springboot网上电商项目(前后端分离+java+vue+springboot+ssm+mysql+maven+redis)
运行环境
Java≥8、MySQL≥5.7、Node.js≥10
开发工具
后端:eclipse/idea/myeclipse/sts等均可配置运行
前端:WebStorm/VSCode/HBuilderX等均可
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot网上电商项目(前后端分离+java+vue+springboot+ssm+mysql+maven+redis)
一、项目简述
本系统功能包括: 一款基于Springboot+Vue的电商项目,前后端分离项目,前台后台都有,前台商品展示购买,购物车分类,订 单查询等等,后台商品管理,订单管理,信息维护,用户管理等等。
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + Mysql + HBuilderX (Webstorm也 行)+ Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts都支 持)。
项目技术: Springboot + Maven + Mybatis + Vue + Redis, B/S 模式+ Maven等等,附带支付宝沙箱环境以及支付环节代码。
}
@RequestMapping(value = "/product/findAllSale")
private CommonResult findAllSale() {
List<Product> products = productService.selectAllSale();
if(products!=null){
return CommonResult.success("全部商品信息查询成功",products);
}else{
return CommonResult.error("全部商品信息查询失败");
}
}
@RequestMapping(value = "/product/findAllLikeName")
private CommonResult findAllLikeName(String keyWord) {
List<Product> products = productService.selectAllLikeName(keyWord);
if(products!=null){
return CommonResult.success("全部商品信息查询成功",products);
}else{
return CommonResult.error("全部商品信息查询失败");
}
}
@RequestMapping(value = "/product/findAllLikeType")
private CommonResult findAllLikeType(String keyWord) {
List<Product> products = productService.selectAllLikeType(keyWord);
if(products!=null){
return CommonResult.success("全部商品信息查询成功",products);
}else{
return CommonResult.error("全部商品信息查询失败");
}
}
@RequestMapping(value = "/product/findAllLikeBrand")
private CommonResult findAllLikeBrand(String keyWord) {
List<Product> products = productService.selectAllLikeBrand(keyWord);
if(products!=null){
return CommonResult.success("全部商品信息查询成功",products);
}else{
return CommonResult.error("全部商品信息查询失败");
}
}
@RequestMapping(value = "/product/findAllByType")
private CommonResult findAllByType() {
List<Map<String, Object>> maps = productService.selectAllByType();
if(maps!=null){
return CommonResult.success("商品分类信息查询成功",maps);
}else{
return CommonResult.error("商品分类信息查询失败");
}
}
/**
* @email qiudb.top@aliyun.com
* @description 用户相关业务
*/
@RestController
@CrossOrigin
public class UserController {
final RoleService roleService;
final UserService userService;
final UserRoleService userRoleService;
final VipService vipService;
public UserController(UserService userService, RoleService roleService,VipService vipService, UserRoleService userRoleService) {
this.userService = userService;
this.roleService = roleService;
this.userRoleService = userRoleService;
this.vipService = vipService;
}
/*根据id查询用户*/
@RequestMapping(value = "/user/findById")
private CommonResult findById(Integer id) {
User user = userService.selectById(id);
if(user!=null){
return CommonResult.success("查询成功",user);
}else{
return CommonResult.error("查询失败");
}
}
}
}
@RequestMapping(value = "/logistics/addInfo")
private CommonResult addInfo(Logistics logistics) {
if(logistics!=null){
if(logisticsService.insertData(logistics)){
return CommonResult.success("物流信息添加成功",logistics);
}else{
return CommonResult.error("物流信息添加失败");
}
}
return CommonResult.error("物流信息数据不存在");
}
@RequestMapping(value = "/logistics/deleteInfo")
private CommonResult deleteInfo(Integer logisticId) {
if(logisticId!=null){
if(logisticsService.deleteById(logisticId)){
return CommonResult.success("物流信息删除成功",logisticId);
}else{
return CommonResult.error("物流信息删除失败");
}
}
return CommonResult.error("物流信息数据不存在");
}
@RequestMapping(value = "/orderDetail/returnInfo")
private CommonResult returnInfo(String orderNo) {
ArrayList<Object> resultList = new ArrayList<>();
Map<String, Object> returnGoods = returnGoodsService.selectOrderNo(orderNo);
Logistics logistics = logisticsService.selectOrderNo(orderNo);
if(returnGoods!=null){
resultList.add(returnGoods);
}
if(logistics!=null){
resultList.add(logistics);
}
if(resultList.size()!=0){
return CommonResult.success("退货订单详情查询成功",resultList);
}else{
return CommonResult.error("退货订单详情查询失败");
* @description 购物车业务类
*/
@RestController
@CrossOrigin
public class ShoppingCartController {
final ShoppingCartService shoppingCartService;
public ShoppingCartController(ShoppingCartService shoppingCartService){
this.shoppingCartService = shoppingCartService;
}
/*商品类别*/
@RequestMapping(value = "/shoppingCart/add")
private CommonResult addShoppingCart(ShoppingCart shoppingCart) {
if(shoppingCartService.insertData(shoppingCart)){
return CommonResult.success("购物车添加成功",shoppingCart);
}else{
return CommonResult.error("购物车添加失败");
}
}
@RequestMapping(value = "/shoppingCart/update")
private CommonResult updateShoppingCart(ShoppingCart shoppingCart) {
if(shoppingCartService.updateById(shoppingCart)){
return CommonResult.success("购物车修改成功",shoppingCart);
}else{
return CommonResult.error("购物车修改失败");
}
}
@RequestMapping(value = "/shoppingCart/deleteById")
private CommonResult deleteShoppingCart(Integer cartId) {
if(shoppingCartService.deleteById(cartId)){
return CommonResult.success("购物车删除成功","cartId: "+cartId);
}else{
return CommonResult.error("购物车删除失败");
}
}
@RequestMapping(value = "/shoppingCart/deleteByUser")
private CommonResult deleteByUser(String accountNumber) {
if(shoppingCartService.deleteByUser(accountNumber)){
return CommonResult.success("购物车删除成功","accountNumber: "+accountNumber);
}else{
return CommonResult.error("购物车删除失败");
}
}
@RequestMapping(value = "/shoppingCart/findAll")
private CommonResult findAllShoppingCart(String accountNumber) {
}
if (codeK.equals(code)) {
redisTemplate.delete(key);
return CommonResult.success("验证码成功!", true);
} else {
return CommonResult.success("验证码错误!", false);
}
}
/**
* 用于绑定手机号操作,发送验证码
*
* @param phone 发送的手机号
*/
@RequestMapping(value = "/util/smsCode")
public CommonResult aliYunSmsCode(String phone) {
String code = redisTemplate.opsForValue().get(phone);
if (!StringUtils.isEmpty(code)) {
return CommonResult.error(phone + "的验证码还未过期!");
}
//生成验证码并存储到redis中
code = MyUtils.getCode(6);
boolean isSend = aliYunSmsService.sendSms(phone, code);
if (isSend) {
redisTemplate.opsForValue().set(phone, code, 10, TimeUnit.MINUTES);
return CommonResult.success("验证码已发送,网络有延迟请稍等~");
} else {
return CommonResult.error("验证码发送失败,请稍后重试~");
}
}
}
package com.qiu.controller;
return CommonResult.success("查询成功",roles);
}else{
return CommonResult.error("查询失败");
}
}
/*查询所有用户*/
@RequestMapping(value = "/role/findAllUsable")
private CommonResult findAllUsable() {
List<Role> roles = roleService.selectAllUsable();
if(roles!=null){
return CommonResult.success("查询成功",roles);
}else{
return CommonResult.error("查询失败");
}
}
@RequestMapping(value = "/role/count")
private CommonResult findCount() {
Integer count = roleService.selectCount();
if(count!=null){
return CommonResult.success("查询成功",count);
}else{
return CommonResult.error("查询失败");
}
}
@RequestMapping(value = "/role/findIdByKey")
private CommonResult findIdByKey(String key) {
Integer id = roleService.selectIdByKey(key);
if(id!=null){
return CommonResult.success("查询成功","id: "+id);
}else{
return CommonResult.error("查询失败");
}
}
@RequestMapping(value = "/role/add")
private CommonResult add(Role role) {
if(role!=null){
if(roleService.insertData(role)){
return CommonResult.success("添加成功",role);
}else{
return CommonResult.error("添加失败");
}
}
return CommonResult.error("用户数据不存在");
}
@RequestMapping(value = "/role/update")
private CommonResult update(Role role) {
}
}
@RequestMapping(value = "/order/findCount")
private CommonResult findCount() {
Integer count = orderService.selectCount();
if(count!=null){
return CommonResult.success("订单数量查询成功",count);
}else{
return CommonResult.error("订单数量查询失败");
}
}
@RequestMapping(value = "/order/add")
private CommonResult addOrder(Order order) {
if(order!=null){
if(order.getProductNo().contains("Vip")){
if(orderService.insertData(order)){
return CommonResult.success("创建订单成功",order);
}else{
return CommonResult.error("创建订单失败");
}
}else{
Product product = productService.selectByKey(order.getProductNo());
Integer productStock = product.getProductStock();
Integer payAmount = order.getPayAmount();
boolean isOk =productStock >= payAmount;
if(isOk){
Product newProduct = new Product();
newProduct.setProductId(product.getProductId());
int newStock = productStock - payAmount;
newProduct.setProductStock(newStock);
newProduct.setIsStockOut(newStock<product.getLowestStock());
// 如果库存小于等于0,自动下架
newProduct.setIsSale(newStock>0);
if(productService.updateById(newProduct)){
if(orderService.insertData(order)){
redisTemplate.opsForValue().set(order.getOrderNo(),order.getOrderNo(),24, TimeUnit.HOURS);
return CommonResult.success("创建订单成功",order);
}else{
return CommonResult.error("创建订单失败");
}
}else{
return CommonResult.error("创建订单失败");
}
}else{
return CommonResult.error("商品库存不足");
}
}
return CommonResult.error("商品分类信息查询失败");
}
}
@RequestMapping(value = "/product/add")
private CommonResult add(Product product) {
System.out.println(product);
if(productService.insertData(product)){
return CommonResult.success("添加商品成功",product);
}else{
return CommonResult.error("添加商品失败");
}
}
@RequestMapping(value = "/product/update")
private CommonResult update(Product product) {
if(product.getIsNew()!=null && product.getIsNew()){
product.setSaleTime(new Date());
}
if(productService.updateById(product)){
return CommonResult.success("修改商品成功",product);
}else{
return CommonResult.error("修改商品失败");
}
}
@RequestMapping(value = "/product/delete")
private CommonResult delete(Integer productId) {
if(productService.deleteById(productId)){
return CommonResult.success("商品删除成功","productId:" + productId);
}else{
return CommonResult.error("商品删除失败");
}
}
/*商品类别*/
@RequestMapping(value = "/productType/add")
private CommonResult addType(ProductType productType) {
if(productTypeService.insertData(productType)){
return CommonResult.success("商品分类添加成功",productType);
}else{
public OverViewController(OrderService orderService,ProductService productService,ReturnGoodsService returnGoodsService) {
this.orderService = orderService;
this.productService = productService;
this.returnGoodsService = returnGoodsService;
}
@RequestMapping(value = "/view/dataInfo")
private CommonResult dataInfo() {
Map<String, Object> resultMap = new HashMap<>();
Map<String, Object> productMap = productService.productOverview();
Map<String, Object> orderMap = orderService.orderOverview();
Map<String, Object> returnGoodsMap = returnGoodsService.returnGoodsOverview();
if(productMap!=null){
resultMap.putAll(productMap);
}
if(orderMap!=null){
resultMap.putAll(orderMap);
}
if(returnGoodsMap!=null){
resultMap.putAll(returnGoodsMap);
}
if(resultMap.size()!=0){
return CommonResult.success("查询成功",resultMap);
}else{
return CommonResult.error("查询失败");
}
}
@RequestMapping(value = "/view/orderChartDATE")
private CommonResult orderChartDATE(String startTime,String endTime) {
Map<String, Object> data = new HashMap<>();
List<Map<String, Object>> lineData = orderService.selectChartDATE(startTime,endTime);
List<Map<String, Object>> ringData = orderService.selectProductTypeChart(startTime, endTime);
Map<String, Object> countData = orderService.selectCountAndAmount(startTime,endTime);
if(lineData.size()!=0){
data.put("lineData",lineData);
}
if(ringData.size()!=0){
data.put("ringData",ringData);
}
if(countData.size()!=0){
data.put("countData",countData);
}
if(data.size()!=0){
return CommonResult.success("查询成功",data);
}else{
return CommonResult.error("查询失败");
}else{
return CommonResult.error("查询失败");
}
}
/*根据key查询用户*/
@RequestMapping(value = "/role/existRoleName")
private CommonResult existRoleName(Integer roleId,String roleName) {
Boolean isExist = roleService.existsRoleName(roleId,roleName);
if(isExist!=null){
return CommonResult.success("查询成功",isExist);
}else{
return CommonResult.error("查询失败");
}
}
/*查询所有角色信息*/
@RequestMapping(value = "/role/findAll")
private CommonResult findAll() {
List<Role> roles = roleService.selectAll();
if(roles!=null){
return CommonResult.success("查询成功",roles);
}else{
return CommonResult.error("查询失败");
}
}
/*查询所有用户*/
@RequestMapping(value = "/role/findAllUsable")
private CommonResult findAllUsable() {
List<Role> roles = roleService.selectAllUsable();
if(roles!=null){
return CommonResult.success("查询成功",roles);
}else{
return CommonResult.error("查询失败");
}
}
@RequestMapping(value = "/role/count")
private CommonResult findCount() {
Integer count = roleService.selectCount();
if(count!=null){
return CommonResult.success("查询成功",count);
}else{
return CommonResult.error("查询失败");
private CommonResult orderChartDATE(String startTime,String endTime) {
Map<String, Object> data = new HashMap<>();
List<Map<String, Object>> lineData = orderService.selectChartDATE(startTime,endTime);
List<Map<String, Object>> ringData = orderService.selectProductTypeChart(startTime, endTime);
Map<String, Object> countData = orderService.selectCountAndAmount(startTime,endTime);
if(lineData.size()!=0){
data.put("lineData",lineData);
}
if(ringData.size()!=0){
data.put("ringData",ringData);
}
if(countData.size()!=0){
data.put("countData",countData);
}
if(data.size()!=0){
return CommonResult.success("查询成功",data);
}else{
return CommonResult.error("查询失败");
}
}
}
package com.qiu.controller;
/**
* @email qiudb.top@aliyun.com
* @description 描述
*/
@RestController
@CrossOrigin
public class BannerController {
final BannerService bannerService;
public BannerController(BannerService bannerService){
this.bannerService = bannerService;
}
/*商品类别*/
@RequestMapping(value = "/banner/add")
private CommonResult addBanner(Banner banner) {
if(bannerService.insertData(banner)){
return CommonResult.success("商品轮播图添加成功",banner);
}else{
return CommonResult.error("商品轮播图添加失败");
}
if(returnReasonService.insertData(returnReason)){
return CommonResult.success("添加成功",returnReason);
}else{
return CommonResult.error("添加失败");
}
}
return CommonResult.error("退货原因数据不存在");
}
@RequestMapping(value = "/returnReason/updateReason")
private CommonResult updateReason(ReturnReason returnReason) {
if(returnReason!=null){
if(returnReasonService.updateById(returnReason)){
return CommonResult.success("更新成功",returnReason);
}else{
return CommonResult.error("更新失败");
}
}
return CommonResult.error("退货原因数据不存在");
}
@RequestMapping(value = "/returnReason/deleteReason")
private CommonResult updateReason(Integer reasonId) {
if(reasonId!=null){
if(returnReasonService.deleteById(reasonId)){
return CommonResult.success("删除成功",reasonId);
}else{
return CommonResult.error("删除失败");
}
}
return CommonResult.error("退货原因数据不存在");
}
/*查询商品退货信息*/
@RequestMapping(value = "/returnGoods/findReturnById")
private CommonResult findReturnById(Integer returnId) {
ReturnGoods returnGoods = returnGoodsService.selectById(returnId);
if(returnGoods!=null){
return CommonResult.success("退货商品查询成功",returnGoods);
}else{
return CommonResult.error("退货商品查询失败");
}
}
/*查询全部退货商品*/
@RequestMapping(value = "/returnGoods/findAllReturn")
private CommonResult findAllReturn() {
List<ReturnGoods> returnGoods = returnGoodsService.selectAll();
if(returnGoods!=null){
return CommonResult.success("退货商品查询成功",returnGoods);
}else{
return CommonResult.error("退货商品查询失败");
try{
//String tradeNo =map.get("out_trade_no");
String tradeNo =orderNo;
if(tradeNo.contains("Vip")){
Integer orderId = orderService.selectIdByKey(tradeNo);
Order order = new Order();
order.setOrderId(orderId);
order.setOrderState("开通成功");
String serialNumber = redisTemplate.opsForValue().get(tradeNo);
if(serialNumber !=null){
response.sendRedirect("http://"+hostAddress+"/?#/personalCenter?serialNumber="+serialNumber);
redisTemplate.delete(tradeNo);
}else{
response.sendRedirect("http://"+hostAddress+"/?#/personalCenter?serialNumber="+"ERROR");
}
orderService.updateById(order);
}else{
String Str = redisTemplate.opsForValue().get(tradeNo);
redisTemplate.delete(tradeNo);
assert Str != null;
String[] ordersNo = Str.split(",");
System.out.println(Arrays.toString(ordersNo));
for (String orderNo1 : ordersNo) {
Integer orderId = orderService.selectIdByKey(orderNo1);
Order order = new Order();
order.setOrderId(orderId);
order.setOrderState("待发货");
orderService.updateById(order);
}
response.sendRedirect("http://"+hostAddress+"/?#/myOrder");
}
}catch (IOException e) {
e.printStackTrace();
}
}
@ResponseBody
@PostMapping(value = "/vip", produces = "text/html;charset=utf-8")
public String create(@RequestParam("orderNo") String orderNo,
@RequestParam("orderName") String orderName,
/*用于注册新用户*/
@RequestMapping(value = "/allow/add")
private CommonResult add(User user) {
if(user.getPassword()!=null && user.getUserName()!=null){
// SimpleHash md5 = new SimpleHash("MD5", user.getPassword(), ByteSource.Util.bytes(user.getAccountNumber()), 2);
// user.setPassword(md5.toHex());
user.setUserState(true);
user.setCreatTime(Timestamp.valueOf(LocalDateTime.now()));
if(userService.insertData(user)){
logger.info("成功添加了一个新用户");
return CommonResult.success("注册成功",user);
}else{
return CommonResult.error("注册失败");
}
}
return CommonResult.error("用户数据不存在");
}
//更新用户信息
@RequestMapping(value = "/allow/update")
private CommonResult update(User user) {
System.out.println(user);
if(userService.updateById(user)){
return CommonResult.success("信息保存成功",user);
}else{
return CommonResult.error("信息保存失败");
}
}
}
package com.qiu.controller;
mailService.sendAttachmentsMail(sendTo, "文件操作", content, filePath);
return "发送成功!";
} catch (Exception e) {
e.printStackTrace();
return "发送邮件时发生异常,稍后请重新发送!";
}
}
/**
* 验证输入的验证码是否正确
*
* @param key 验证的依据
* @param code 验证码
*/
@RequestMapping(value = "/allow/checkCode")
public CommonResult checkCode(String key, String code) {
String codeK = redisTemplate.opsForValue().get(key);
if (codeK == null) {
return CommonResult.error("验证码不存在或已过期,请重新发送!");
}
if (codeK.equals(code)) {
redisTemplate.delete(key);
return CommonResult.success("验证码成功!", true);
} else {
return CommonResult.success("验证码错误!", false);
}
}
/**
* 用于绑定手机号操作,发送验证码
*
* @param phone 发送的手机号
*/
@RequestMapping(value = "/util/smsCode")
public CommonResult aliYunSmsCode(String phone) {
String code = redisTemplate.opsForValue().get(phone);
if (!StringUtils.isEmpty(code)) {
return CommonResult.error(phone + "的验证码还未过期!");
}
//生成验证码并存储到redis中
code = MyUtils.getCode(6);
boolean isSend = aliYunSmsService.sendSms(phone, code);
if (isSend) {
redisTemplate.opsForValue().set(phone, code, 10, TimeUnit.MINUTES);
return CommonResult.success("验证码已发送,网络有延迟请稍等~");
} else {
return CommonResult.error("验证码发送失败,请稍后重试~");
}
}
}
package com.qiu.controller;
if(supplier!=null){
if(supplierService.insertData(supplier)){
return CommonResult.success("添加成功",supplier);
}else{
return CommonResult.error("添加失败");
}
}
return CommonResult.error("供应商数据不存在");
}
/*修改供应商*/
@RequestMapping(value = "/supplier/updateSupplier")
private CommonResult updateSupplier(Supplier supplier) {
if(supplier!=null){
if(supplierService.updateById(supplier)){
return CommonResult.success("更新成功",supplier);
}else{
return CommonResult.error("更新失败");
}
}
return CommonResult.error("供应商数据不存在");
}
/*删除供应商*/
@RequestMapping(value = "/supplier/deleteSupplier")
private CommonResult deleteSupplier(Integer supplierId) {
if(supplierId!=null){
if(supplierService.deleteById(supplierId)){
return CommonResult.success("删除成功",supplierId);
}else{
return CommonResult.error("删除失败");
}
}
return CommonResult.error("供应商数据不存在");
}
/*查询采购信息*/
@RequestMapping(value = "/purchase/findPurchaseById")
private CommonResult findPurchaseById(Integer purchaseId) {
Purchase purchase = purchaseService.selectById(purchaseId);
if(purchase!=null){
return CommonResult.success("采购信息查询成功",purchase);
}else{
return CommonResult.error("采购信息查询失败");
}
}
/*查询全部采购信息*/
@RequestMapping(value = "/purchase/findPurchaseAll")
private CommonResult findPurchaseAll() {
List<Purchase> purchases = purchaseService.selectAll();
if(purchases!=null){
return CommonResult.success("采购信息查询成功",purchases);
return CommonResult.error("删除订单失败");
}
}
@RequestMapping(value = "/order/receipt")
private CommonResult updateOrder(Integer orderId) {
Order order = new Order();
order.setOrderId(orderId);
order.setOrderState("已收货");
if(orderService.updateById(order)){
return CommonResult.success("商品收货成功",order);
}else{
return CommonResult.error("商品收货失败");
}
}
@RequestMapping(value = "/orderDetail/orderInfo")
private CommonResult orderInfo(String orderNo) {
ArrayList<Object> resultList = new ArrayList<>();
Order order = orderService.selectByKey(orderNo);
Logistics logistics = logisticsService.selectOrderNo(orderNo);
if(order!=null){
resultList.add(order);
}
if(logistics!=null){
resultList.add(logistics);
}
if(resultList.size()!=0){
return CommonResult.success("订单详情查询成功",resultList);
}else{
return CommonResult.error("订单详情查询失败");
}
}
}
package com.qiu.controller;
return CommonResult.error("发送验证码时发生异常,请稍后重试!");
}
}
@RequestMapping(value = "/allow/sendHtmlRegister")
public CommonResult sendRegisterInfo(String sendTo, String pwd, String name) {
try {
Map<String, Object> data = new HashMap<>();
data.put("account", sendTo);
data.put("password", pwd);
data.put("name", name);
data.put("year", Calendar.getInstance().get(Calendar.YEAR));
mailService.sendTemplateMail(sendTo, "注册成功", "register", data);
return CommonResult.success("注册信息发送成功");
} catch (Exception e) {
return CommonResult.error("注册信息发送失败");
}
}
@RequestMapping(value = "/allow/sendHtmlRole")
public CommonResult sendRoleInfo(String sendTo, String userName, String roleInfo) {
try {
Map<String, Object> data = new HashMap<>();
data.put("userName", userName);
data.put("roleInfo", roleInfo);
data.put("year", Calendar.getInstance().get(Calendar.YEAR));
mailService.sendTemplateMail(sendTo, "权限管理", "role", data);
return CommonResult.success("授权信息发送成功");
} catch (Exception e) {
return CommonResult.error("授权信息发送失败");
}
}
@RequestMapping(value = "/allow/sendHtmlResetPwd")
public CommonResult sendResetPwd(String sendTo, String pwd) {
try {
Map<String, Object> data = new HashMap<>();
data.put("password", pwd);
data.put("year", Calendar.getInstance().get(Calendar.YEAR));
mailService.sendTemplateMail(sendTo, "重置密码", "resetpwd", data);
return CommonResult.success("新密码信息发送成功");
} catch (Exception e) {
return CommonResult.error("新密码信息发送失败");
}
}
order.setReturnState(true);
order.setOrderState("已退款");
Logistics logistics = logisticsService.selectOrderNo(orderNo);
if(logistics!=null){
logisticsService.deleteById(logistics.getLogisticId());
}
if(orderService.updateById(order)){
if(returnGoodsService.updateById(returnGoods)){
return CommonResult.success("更新成功",returnGoods);
}else{
return CommonResult.error("更新失败");
}
}else{
return CommonResult.error("更新失败");
}
}
return CommonResult.error("商品退款数据不存在");
}
/*拒绝买家退款申请*/
@RequestMapping(value = "/returnGoods/rejectRefund")
private CommonResult rejectRefund(Integer returnId,String operatorNumber,String operatorName) {
if(returnId!=null){
ReturnGoods returnGoods = returnGoodsService.selectById(returnId);
returnGoods.setReturnState("拒绝退款");
returnGoods.setDealTime(new Date());
returnGoods.setOperatorNumber(operatorNumber);
returnGoods.setOperatorName(operatorName);
String orderNo = returnGoods.getOrderNo();
Integer orderId = orderService.selectIdByKey(orderNo);
Order order = new Order();
order.setOrderId(orderId);
order.setOrderState("待发货");
if(orderService.updateById(order)){
if(returnGoodsService.updateById(returnGoods)){
return CommonResult.success("更新成功",returnGoods);
}else{
return CommonResult.error("更新失败");
}
}else {
return CommonResult.error("更新失败");
}
}
/*查询VIP用户信息根据id*/
@RequestMapping(value = "/vip/findVipById")
private CommonResult findVipById(Integer vipId) {
Vip vip = vipService.selectById(vipId);
if(vip!=null){
return CommonResult.success("查询成功",vip);
}else{
return CommonResult.error("查询失败");
}
}
/*查询VIP用户信息根据id*/
@RequestMapping(value = "/vip/findVipByKey")
private CommonResult findVipByKey(String accountNumber) {
Vip vip = vipService.selectByKey(accountNumber);
if(vip!=null){
return CommonResult.success("查询成功",vip);
}else{
return CommonResult.error("查询失败");
}
}
/*判断用户信息是否存在*/
@RequestMapping(value = "/vip/existsVip")
private CommonResult existsVip(String accountNumber) {
Boolean isExist = vipService.existsVip(accountNumber);
if(isExist!=null){
return CommonResult.success("查询成功",isExist);
}else{
return CommonResult.error("查询失败");
}
}
//创建vip信息
@RequestMapping(value = "/vip/addVip")
private CommonResult addVip(Vip vip) {
Date date = new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(date);//设置起时间
cal.add(Calendar.YEAR, 1);//增加一年
vip.setOverdueTime(cal.getTime());
if(vipService.insertData(vip)){
return CommonResult.success("物流信息添加成功",logistics);
}else{
return CommonResult.error("物流信息添加失败");
}
}
return CommonResult.error("物流信息数据不存在");
}
@RequestMapping(value = "/logistics/deleteInfo")
private CommonResult deleteInfo(Integer logisticId) {
if(logisticId!=null){
if(logisticsService.deleteById(logisticId)){
return CommonResult.success("物流信息删除成功",logisticId);
}else{
return CommonResult.error("物流信息删除失败");
}
}
return CommonResult.error("物流信息数据不存在");
}
@RequestMapping(value = "/orderDetail/returnInfo")
private CommonResult returnInfo(String orderNo) {
ArrayList<Object> resultList = new ArrayList<>();
Map<String, Object> returnGoods = returnGoodsService.selectOrderNo(orderNo);
Logistics logistics = logisticsService.selectOrderNo(orderNo);
if(returnGoods!=null){
resultList.add(returnGoods);
}
if(logistics!=null){
resultList.add(logistics);
}
if(resultList.size()!=0){
return CommonResult.success("退货订单详情查询成功",resultList);
}else{
return CommonResult.error("退货订单详情查询失败");
}
}
}
@RequestMapping(value = "/order/findCount")
private CommonResult findCount() {
Integer count = orderService.selectCount();
if(count!=null){
return CommonResult.success("订单数量查询成功",count);
}else{
return CommonResult.error("订单数量查询失败");
}
}
@RequestMapping(value = "/order/add")
private CommonResult addOrder(Order order) {
if(order!=null){
if(order.getProductNo().contains("Vip")){
if(orderService.insertData(order)){
return CommonResult.success("创建订单成功",order);
}else{
return CommonResult.error("创建订单失败");
}
}else{
Product product = productService.selectByKey(order.getProductNo());
Integer productStock = product.getProductStock();
Integer payAmount = order.getPayAmount();
boolean isOk =productStock >= payAmount;
if(isOk){
Product newProduct = new Product();
newProduct.setProductId(product.getProductId());
int newStock = productStock - payAmount;
newProduct.setProductStock(newStock);
newProduct.setIsStockOut(newStock<product.getLowestStock());
// 如果库存小于等于0,自动下架
newProduct.setIsSale(newStock>0);
if(productService.updateById(newProduct)){
if(orderService.insertData(order)){
redisTemplate.opsForValue().set(order.getOrderNo(),order.getOrderNo(),24, TimeUnit.HOURS);
return CommonResult.success("创建订单成功",order);
}else{
return CommonResult.error("创建订单失败");
}
}else{
@RequestMapping(value = "/productSpecs/findAllByProId")
private CommonResult findAllByProId(Integer productId) {
List<String> specsName = productSpecsService.selectAllByProId(productId);
if(specsName!=null){
return CommonResult.success("查询成功",specsName);
}else{
return CommonResult.error("查询失败");
}
}
@RequestMapping(value = "/productSpecs/add")
private CommonResult add(ProductSpecs productSpecs) {
if(productSpecs!=null){
if(productSpecsService.insertData(productSpecs)){
return CommonResult.success("添加成功",productSpecs);
}else{
return CommonResult.error("添加失败");
}
}
return CommonResult.error("数据不存在");
}
@RequestMapping(value = "/productSpecs/addBatch")
private CommonResult addBatch(Integer productId,Integer[] specsIds) {
System.out.println(productId);
System.out.println(Arrays.toString(specsIds));
if(specsIds!=null){
ProductSpecs productSpecs;
List<ProductSpecs> productSpecsList = new ArrayList<>();
for (Integer specsId : specsIds) {
productSpecs = new ProductSpecs();
productSpecs.setProductId(productId);
productSpecs.setSpecsId(specsId);
productSpecsList.add(productSpecs);
}
for (ProductSpecs specs : productSpecsList) {
System.out.println(specs);
}
if(productSpecsService.insertBatch(productSpecsList)){
return CommonResult.success("添加成功",productSpecsList);
}else{
return CommonResult.error("添加失败");
}
}
return CommonResult.error("数据不存在");
return CommonResult.error("重置密码失败");
}
}
return CommonResult.error("用户数据不存在");
}
/*用于注册新用户*/
@RequestMapping(value = "/allow/add")
private CommonResult add(User user) {
if(user.getPassword()!=null && user.getUserName()!=null){
// SimpleHash md5 = new SimpleHash("MD5", user.getPassword(), ByteSource.Util.bytes(user.getAccountNumber()), 2);
// user.setPassword(md5.toHex());
user.setUserState(true);
user.setCreatTime(Timestamp.valueOf(LocalDateTime.now()));
if(userService.insertData(user)){
logger.info("成功添加了一个新用户");
return CommonResult.success("注册成功",user);
}else{
return CommonResult.error("注册失败");
}
}
return CommonResult.error("用户数据不存在");
}
//更新用户信息
@RequestMapping(value = "/allow/update")
private CommonResult update(User user) {
System.out.println(user);
if(userService.updateById(user)){
return CommonResult.success("信息保存成功",user);
}else{
return CommonResult.error("信息保存失败");
}
}
}
package com.qiu.controller;
if(returnGoodsService.updateById(returnGoods)){
return CommonResult.success("更新成功",returnGoods);
}else{
return CommonResult.error("更新失败");
}
}
return CommonResult.error("商品退货数据不完整");
}
@RequestMapping(value = "/returnGoods/deleteReturn")
private CommonResult deleteReturn(Integer returnId) {
if(returnId!=null){
if(returnGoodsService.deleteById(returnId)){
return CommonResult.success("删除成功",returnId);
}else{
return CommonResult.error("删除失败");
}
}
return CommonResult.error("商品退货数据不存在");
}
/*查询物流信息*/
@RequestMapping(value = "/logistics/findInfoById")
private CommonResult findInfoById(Integer logisticId) {
Logistics logistics = logisticsService.selectById(logisticId);
if(logistics!=null){
return CommonResult.success("物流信息查询成功",logistics);
}else{
return CommonResult.error("物流信息查询失败");
}
}
/*查询全部物流信息*/
@RequestMapping(value = "/logistics/findAllInfo")
private CommonResult findAllInfo() {
List<Logistics> logistics = logisticsService.selectAll();
if(logistics!=null){
return CommonResult.success("物流信息查询成功",logistics);
}else{
return CommonResult.error("物流信息查询失败");
}
}
@RequestMapping(value = "/logistics/addInfo")
private CommonResult addInfo(Logistics logistics) {
if(logistics!=null){
return CommonResult.error("查询失败");
}
}
@RequestMapping(value = "/returnReason/addReason")
private CommonResult addReason(ReturnReason returnReason) {
if(returnReason!=null){
if(returnReasonService.insertData(returnReason)){
return CommonResult.success("添加成功",returnReason);
}else{
return CommonResult.error("添加失败");
}
}
return CommonResult.error("退货原因数据不存在");
}
@RequestMapping(value = "/returnReason/updateReason")
private CommonResult updateReason(ReturnReason returnReason) {
if(returnReason!=null){
if(returnReasonService.updateById(returnReason)){
return CommonResult.success("更新成功",returnReason);
}else{
return CommonResult.error("更新失败");
}
}
return CommonResult.error("退货原因数据不存在");
}
@RequestMapping(value = "/returnReason/deleteReason")
private CommonResult updateReason(Integer reasonId) {
if(reasonId!=null){
if(returnReasonService.deleteById(reasonId)){
return CommonResult.success("删除成功",reasonId);
}else{
return CommonResult.error("删除失败");
}
}
return CommonResult.error("退货原因数据不存在");
}
/*查询商品退货信息*/
@RequestMapping(value = "/returnGoods/findReturnById")
private CommonResult findReturnById(Integer returnId) {
ReturnGoods returnGoods = returnGoodsService.selectById(returnId);
if(returnGoods!=null){
return CommonResult.success("退货商品查询成功",returnGoods);
}else{
return CommonResult.error("退货商品查询失败");
}
}
/*查询全部退货商品*/
@RequestMapping(value = "/returnGoods/findAllReturn")
private CommonResult findAllReturn() {
List<ReturnGoods> returnGoods = returnGoodsService.selectAll();