package com.ppmall.service.impl;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.DataType;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.alipay.api.AlipayApiException;
import com.alipay.api.response.AlipayTradePrecreateResponse;
import com.alipay.config.Configs;
import com.alipay.model.ExtendParams;
import com.alipay.model.GoodsDetail;
import com.alipay.model.builder.AlipayTradePrecreateRequestBuilder;
import com.alipay.model.result.AlipayF2FPrecreateResult;
import com.alipay.service.AlipayTradeService;
import com.alipay.service.impl.AlipayTradeServiceImpl;
import com.alipay.util.ZxingUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ppmall.common.Const;
import com.ppmall.common.ServerResponse;
import com.ppmall.dao.CartMapper;
import com.ppmall.dao.OrderItemMapper;
import com.ppmall.dao.OrderMapper;
import com.ppmall.dao.PayInfoMapper;
import com.ppmall.dao.ProductMapper;
import com.ppmall.dao.ShippingMapper;
import com.ppmall.pojo.Order;
import com.ppmall.pojo.OrderItem;
import com.ppmall.pojo.PayInfo;
import com.ppmall.pojo.Product;
import com.ppmall.pojo.Shipping;
import com.ppmall.service.IOrderService;
import com.ppmall.util.DateUtil;
import com.ppmall.util.FtpUtil;
import com.ppmall.util.PropertiesUtil;
import com.ppmall.vo.CartProductVo;
import com.ppmall.vo.OrderInfoVo;
import com.ppmall.vo.OrderItemVo;
@Service("iOrderService")
public class OrderServiceImpl implements IOrderService {
@Autowired
private OrderMapper orderMapper;
@Autowired
private ShippingMapper shippingMapper;
@Autowired
private OrderItemMapper orderItemMapper;
@Autowired
private CartMapper cartMapper;
@Autowired
private ProductMapper productMapper;
@Autowired
private PayInfoMapper payInfoMapper;
@Override
public ServerResponse getOrderList(Long orderNum, int pageNum, int pageSize) {
PageHelper.startPage(pageNum, pageSize);
Map paramMap = new HashMap();
paramMap.put("orderNum", orderNum);
List<Order> orderList = orderMapper.selectAll(paramMap);
PageInfo<Order> pageResult = new PageInfo<>(orderList);
return ServerResponse.createSuccess("获取成功", pageResult);
}
@Override
public ServerResponse getOrderDetail(Long orderNo) {
Order order = orderMapper.selectByOrderNo(orderNo);
if (order == null)
return ServerResponse.createErrorMessage("找不到该订单");
int shippingId = order.getShippingId();
Shipping shipping = shippingMapper.selectByPrimaryKey(shippingId);
List<OrderItem> orderItems = orderItemMapper.selectByOrderNo(orderNo);
String imageHost = PropertiesUtil.getProperty("ftp.server.http.prefix");
OrderInfoVo orderInfoVo = new OrderInfoVo();
if (order.getCreateTime() != null)
orderInfoVo.setCreateTime(DateUtil.getDateString(order.getCreateTime()));
if (order.getPaymentTime() != null)
orderInfoVo.setPaymentTime(DateUtil.getDateString(order.getPaymentTime()));
if (order.getSendTime() != null)
orderInfoVo.setSendTime(DateUtil.getDateString(order.getSendTime()));
if (order.getCloseTime() != null)
orderInfoVo.setCloseTime(DateUtil.getDateString(order.getCloseTime()));
if (order.getEndTime() != null)
orderInfoVo.setEndTime(DateUtil.getDateString(order.getEndTime()));
if (order.getPaymentType() != null)
orderInfoVo.setPaymentTypeDesc(Const.PayType.codeOf(order.getPaymentType()).getDesc());
orderInfoVo.setStatus(order.getStatus());
orderInfoVo.setStatusDesc(Const.OrderStatus.codeOf(order.getStatus()).getDesc());
orderInfoVo.setImageHost(PropertiesUtil.getProperty("ftp.server.http.prefix"));
orderInfoVo.setOrderItemVoList(orderItems);
orderInfoVo.setOrderNo(order.getOrderNo());
orderInfoVo.setPayment(order.getPayment());
orderInfoVo.setShippingVo(shipping);
return ServerResponse.createSuccess("获取成功", orderInfoVo);
}
@Override
public ServerResponse getOrderCart(int userId) {
List<OrderItemVo> list = orderItemMapper.selectCart(userId, 1);
double cartTotalPrice = 0;
for (OrderItemVo vo : list) {
double totalPrice = vo.getTotalPrice();
cartTotalPrice += totalPrice;
}
Map returnMap = new HashMap<>();
returnMap.put("imageHost", PropertiesUtil.getProperty("ftp.server.http.prefix"));
returnMap.put("productTotalPrice", cartTotalPrice);
returnMap.put("orderItemVoList", list);
return ServerResponse.createSuccess("获取成功", returnMap);
}
@Override
@Transactional
public ServerResponse createOrder(int userId, int shippingId) {
List<CartProductVo> cartCheckedList = cartMapper.selectCartProductListByUserIdAndChecked(userId, 1);// 1是选中
long orderNo = generateOrderNo();
Date date = DateUtil.getDate();
double paymentTotal = 0;
List batchInsertList = new ArrayList();
List deleteCartList = new ArrayList<>();
List updateProductList = new ArrayList<>();
if (cartCheckedList == null || cartCheckedList.size() == 0) {
return ServerResponse.createErrorMessage("购物车为空~");
}
for (CartProductVo vo : cartCheckedList) {
OrderItem item = new OrderItem();
item.setOrderNo(orderNo);
item.setUserId(userId);
item.setCurrentUnitPrice(new BigDecimal(vo.getProductPrice()));
item.setProductId(vo.getProductId());
item.setProductImage(vo.getProductMainImage());
item.setProductName(vo.getProductName());
item.setQuantity(vo.getQuantity());
item.setTotalPrice(new BigDecimal(vo.getProductTotalPrice()));
item.setCreateTime(date);
item.setUpdateTime(date);
paymentTotal += vo.getProductTotalPrice();
batchInsertList.add(item);
deleteCartList.add(vo.getProductId());
Product product = new Product();
product.setId(vo.getProductId());
product.setStock(vo.getProductStock() - vo.getQuantity());
updateProductList.add(product);
}
BigDecimal payment = new BigDecimal(paymentTotal);
Order order = new Order();
order.setCreateTime(date);
order.setOrderNo(orderNo);
order.setPayment(payment);
order.setPostage(0);
order.setShippingId(shippingId);
order.setStatus(Const.OrderStatus.UNPAY.getCode());
order.setUpdateTime(date);
order.setUserId(userId);
order.setOrderNo(orderNo);
orderMapper.insertSelective(order);
orderItemMapper.insertBatchSelective(batchInsertList);
productMapper.updateBatchSelective(updateProductList);
cleanCart(userId, deleteCartList);
ServerResponse response = getOrderDetail(orderNo);
return ServerResponse.createSuccess("创建成功", response.getData());
}
private int cleanCart(int userId, List deleteCartList) {
Map paramMap = new HashMap<>();
paramMap.put("productIds", deleteCartList.toArray());
paramMap.put("userId", userId);
return cartMapper.deleteByProductIds(paramMap);
}
private long generateOrderNo() {
long currentTime = System.currentTimeMillis();
return currentTime + new Random().nextInt(100);
}
@Override
public ServerResponse getOrderList(int userId, int pageNum, int pageSize) {
// TODO Auto-generated method stub
PageHelper.startPage(pageNum, pageSize);
Map paramMap = new HashMap();
paramMap.put("userId", userId);
List returnList = new ArrayList<>();
List<Order> orderList = orderMapper.selectAll(paramMap);
for (Order order : orderList) {
List<OrderItem> orderItems = orderItemMapper.selectByOrderNo(order.getOrderNo());
Shipping shippingVo = shippingMapper.selectByPrimaryKey(order.getShippingId());
OrderInfoVo orderInfoVo = new OrderInfoVo();
if (order.getCreateTime() != null)
orderInfoVo.setCreateTime(DateUtil.getDateString(order.getCreateTime()));
if (order.getPaymentTime() != null)
orderInfoVo.setPaymentTime(DateUtil.getDateString(order.getPaymentTime()));
没有合适的资源?快使用搜索试试~ 我知道了~
一个基于Spring,SpringMVC,Mybatis 构建的电商平台
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共333个文件
java:137个
xml:88个
jpg:30个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 39 浏览量
2023-05-09
14:25:35
上传
评论
收藏 5.81MB ZIP 举报
温馨提示
ppmall-服务端项目(Java)一个基于Spring,SpringMVC,Mybatis 构建的电商平台,涵盖后台系统和门户页面,是SSM实战的很好实践。运用到了常用的互联网技术,比如redis,jwt,等等
资源推荐
资源详情
资源评论
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JAR.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JAR.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 333 条
- 1
- 2
- 3
- 4
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/de50ac10e30e41b89db28203f97239be_qq_41701956.jpg!1)
Java程序员-张凯
- 粉丝: 1w+
- 资源: 6825
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)