package com.yuu.ymall.web.api.service.impl;
import com.alipay.api.response.AlipayTradePrecreateResponse;
import com.alipay.demo.trade.config.Configs;
import com.alipay.demo.trade.model.TradeStatus;
import com.alipay.demo.trade.model.builder.AlipayTradePrecreateRequestBuilder;
import com.alipay.demo.trade.model.builder.AlipayTradeQueryRequestBuilder;
import com.alipay.demo.trade.model.result.AlipayF2FPrecreateResult;
import com.alipay.demo.trade.model.result.AlipayF2FQueryResult;
import com.alipay.demo.trade.service.AlipayTradeService;
import com.alipay.demo.trade.service.impl.AlipayTradeServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yuu.ymall.commons.consts.Consts;
import com.yuu.ymall.commons.dto.BaseResult;
import com.yuu.ymall.commons.redis.RedisCacheManager;
import com.yuu.ymall.commons.utils.IDUtil;
import com.yuu.ymall.commons.utils.MapperUtil;
import com.yuu.ymall.domain.*;
import com.yuu.ymall.web.api.common.config.AlipayConfig;
import com.yuu.ymall.web.api.common.utils.IPInfoUtil;
import com.yuu.ymall.web.api.dto.*;
import com.yuu.ymall.web.api.mapper.*;
import com.yuu.ymall.web.api.service.OrderService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
/**
* @author by Yuu
* @classname OrderServiceImpl
* @date 2019/7/6 2:14
*/
@Service
@Transactional(readOnly = false)
public class OrderServiceImpl implements OrderService {
@Value("${ADD_ORDER}")
private String ADD_ORDER;
@Value("${CART_PRE}")
private String CART_PRE;
@Value("${ORDER_PAY}")
private String ORDER_PAY;
@Autowired
private RedisCacheManager redisCacheManager;
@Autowired
private TbMemberMapper tbMemberMapper;
@Autowired
private TbOrderMapper tbOrderMapper;
@Autowired
private TbOrderItemMapper tbOrderItemMapper;
@Autowired
private TbOrderShippingMapper tbOrderShippingMapper;
@Autowired
private TbItemMapper tbItemMapper;
@Value("${PRODUCT_ITEM}")
private String PRODUCT_ITEM;
@Transactional
@Override
public BaseResult addOrder(OrderInfo orderInfo, HttpServletRequest request) {
// 用户 id
Long userId = orderInfo.getUserId();
// 地址收货人
String username = orderInfo.getUserName();
// 订单商品
List<CartProduct> goods = orderInfo.getGoodsList();
if (userId == null || StringUtils.isBlank(username) || goods == null || goods.size() == 0) {
return BaseResult.fail("请求信息异常");
}
// 请求 ip 地址
String ip = IPInfoUtil.getIpAddr(request);
if("0:0:0:0:0:0:0:1".equals(ip)){
ip="127.0.0.1";
}
// Redis key,防止恶意请求
String redisKey = ADD_ORDER + ":" + ip;
String temp = (String) redisCacheManager.get(redisKey);
if (StringUtils.isNotBlank(temp)) {
return BaseResult.fail("您提交的太频繁了,请您稍后再试");
}
TbMember tbMember = tbMemberMapper.selectByPrimaryKey(userId);
if (tbMember == null) {
return BaseResult.fail("获取下单用户失败");
}
// 生成订单
TbOrder tbOrder = new TbOrder();
tbOrder.setId(String.valueOf(IDUtil.getRandomId()));
tbOrder.setUserId(userId);
if (StringUtils.isBlank(tbMember.getUsername())) {
tbOrder.setBuyerNick(tbMember.getPhone());
} else {
tbOrder.setBuyerNick(tbMember.getUsername());
}
tbOrder.setPayment(orderInfo.getOrderTotal());
tbOrder.setCreated(new Date());
tbOrder.setUpdated(new Date());
// 0: 未付款 1: 已付款 2: 未发货 3: 已发货 4: 交易成功 5: 交易关闭
tbOrder.setStatus(0);
// 添加订单
tbOrderMapper.insert(tbOrder);
// 生成订单信息
List<CartProduct> goodsList = orderInfo.getGoodsList();
for (CartProduct cartProduct : goodsList) {
TbOrderItem tbOrderItem = new TbOrderItem();
Long orderItemId = IDUtil.getRandomId();
tbOrderItem.setId(orderItemId.toString());
tbOrderItem.setItemId(cartProduct.getProductId().toString());
tbOrderItem.setOrderId(tbOrder.getId());
tbOrderItem.setNum(cartProduct.getProductNum());
tbOrderItem.setTitle(cartProduct.getProductName());
tbOrderItem.setPrice(cartProduct.getSalePrice());
tbOrderItem.setTotalFee(cartProduct.getSalePrice().multiply(BigDecimal.valueOf(cartProduct.getProductNum())));
tbOrderItem.setPicPath(cartProduct.getProductImg());
tbOrderItemMapper.insert(tbOrderItem);
// 删除会员购物车中的该商品
// Redis key
String cartProductKey = CART_PRE + ":" + orderInfo.getUserId();
// Hash Key
String hashKey = cartProduct.getProductId().toString();
// 删除记录
redisCacheManager.deleteHash(cartProductKey, hashKey);
}
// 生成物流信息
TbOrderShipping tbOrderShipping = new TbOrderShipping();
tbOrderShipping.setOrderId(tbOrder.getId());
tbOrderShipping.setReceiverName(orderInfo.getUserName());
tbOrderShipping.setReceiverAddress(orderInfo.getStreetName());
tbOrderShipping.setReceiverPhone(orderInfo.getTel());
tbOrderShipping.setCreated(new Date());
tbOrderShipping.setUpdated(new Date());
tbOrderShippingMapper.insert(tbOrderShipping);
// 修改商品库存信息
for (CartProduct good : goods) {
Long productId = good.getProductId();
// 商品库存
tbItemMapper.reduceItemNum(productId, good.getProductNum());
// 删除 Redis 商品缓存信息
String redisItemKey = PRODUCT_ITEM + ":" + productId;
redisCacheManager.del(redisItemKey);
}
// 设置 Redis ip 缓存
redisCacheManager.set(redisKey, "ADD_ORDER");
redisCacheManager.expire(redisKey, 60);
return BaseResult.success((Object)tbOrder.getId());
}
@Override
public BaseResult getOrderDet(String orderId) {
Order order = new Order();
// 获取订单信息
TbOrder tbOrder = tbOrderMapper.selectByPrimaryKey(orderId);
if (tbOrder == null) {
return BaseResult.fail("通过id获取订单详情失败");
}
// 订单 id
order.setOrderId(tbOrder.getId());
// 会员 id
order.setUserId(tbOrder.getUserId().toString());
// 订单状态
order.setOrderStatus(tbOrder.getStatus());
// 未支付,最晚支付时间
if (order.getOrderStatus() == 0) {
Date createDate = tbOrder.getCreated();
Calendar calendar = Calendar.getInstance();
calendar.setTime(createDate);
calendar.add(Calendar.HOUR, 2);
String countTime = calendar.getTime().getTime() + "";
order.setCountTime(countTime);
}
// 订单创建时间
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String createDate = simpleDateFormat.format(tbOrder.getCreated());
order.setCreateDate(createDate);
// 订单支付时间
if (tbOrder.getPaymentTime() != null) {
String payDate = simpleDateFormat.format(tbOrder.getPaymentTime());
order.setPayDate(payDate);
}
没有合适的资源?快使用搜索试试~ 我知道了~
基于 SSM + VUE +mysql的 B2C 在线电商项目.zip
共1647个文件
html:345个
png:302个
gif:299个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 118 浏览量
2023-08-09
22:13:41
上传
评论
收藏 17.66MB ZIP 举报
温馨提示
用Java写的项目,项目真实可靠,可用作本科毕业设计,欢迎大家下载学习。用Java写的项目,项目真实可靠,可用作本科毕业设计,欢迎大家下载学习。用Java写的项目,项目真实可靠,可用作本科毕业设计,欢迎大家下载学习。用Java写的项目,项目真实可靠,可用作本科毕业设计,欢迎大家下载学习。用Java写的项目,项目真实可靠,可用作本科毕业设计,欢迎大家下载学习。
资源推荐
资源详情
资源评论
收起资源包目录
基于 SSM + VUE +mysql的 B2C 在线电商项目.zip (1647个子文件)
.babelrc 445B
.rebel.xml.bak 763B
jquery.easy-pie-chart.coffee 5KB
H-ui.css 203KB
H-ui.min.css 149KB
bootstrap.css 123KB
bootstrap.min.css 101KB
style.css 80KB
screen.css 43KB
print.css 41KB
font-awesome-ie7.css 40KB
font-awesome-ie7.min.css 37KB
font-awesome.css 27KB
font-awesome.css 22KB
font-awesome.min.css 22KB
_all.css 21KB
default.css 20KB
bootstrap-theme.min.css 17KB
iconfont.css 16KB
wangEditor.css 16KB
_all.css 15KB
iconfont.min.css 14KB
wangEditor.min.css 14KB
_all.css 14KB
layer.css 14KB
_all.css 13KB
common.css 13KB
dropzone.css 12KB
webuploader.css 11KB
dropzone.min.css 9KB
style-responsive.css 9KB
style.css 8KB
H-ui.admin.css 7KB
metroStyle.css 6KB
bootstrap-reset.css 6KB
zTreeStyle.css 6KB
iconfont.css 5KB
datepicker-dev.css 4KB
style.css 4KB
datepicker.css 4KB
datepicker.css 3KB
style.css 3KB
datepicker.css 3KB
H-ui.reset.css 3KB
lightbox.css 3KB
qq.css 3KB
H-ui.ie.css 3KB
zTreeStyleForApi.css 3KB
purple.css 2KB
yellow.css 2KB
orange.css 2KB
green.css 2KB
pink.css 2KB
blue.css 2KB
grey.css 2KB
aero.css 2KB
red.css 2KB
simple.css 2KB
line.css 2KB
H-ui.login.css 2KB
demo.css 2KB
orange.css 2KB
purple.css 2KB
yellow.css 2KB
purple.css 2KB
orange.css 2KB
yellow.css 2KB
green.css 2KB
green.css 2KB
pink.css 2KB
blue.css 2KB
grey.css 2KB
aero.css 2KB
blue.css 2KB
pink.css 2KB
grey.css 2KB
aero.css 2KB
red.css 2KB
red.css 2KB
all.css 2KB
minimal.css 2KB
polaris.css 2KB
square.css 2KB
nprogress.css 1KB
purple.css 1KB
orange.css 1KB
yellow.css 1KB
green.css 1KB
grey.css 1KB
pink.css 1KB
blue.css 1KB
aero.css 1KB
futurico.css 1KB
red.css 1KB
owl.carousel.css 1KB
flat.css 1KB
skin.css 1KB
skin.css 1KB
skin.css 1KB
skin.css 1KB
共 1647 条
- 1
- 2
- 3
- 4
- 5
- 6
- 17
资源评论
c++服务器开发
- 粉丝: 3183
- 资源: 4461
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 第6节-指针.pdf
- 第5节-操作符详解.pdf
- 第9节-windows版本git的用法.pdf
- 第8节-实用调试技巧.pdf
- JDK17的下载与安装 .pdf
- idm641.exe
- flatpak-libs-1.0.9-13.el7-9.x64-86.rpm.tar.gz
- 不知道minGW64是那个的看点这个.txt
- flex-2.5.37-6.el7.x64-86.rpm.tar.gz
- 3--线性表之-链表.pdf
- 2--线性表之-顺序表.pdf
- 5--树和二叉树.pdf
- 4--线性表之-栈和队列.pdf
- 7--实践练习-迷宫问题.pdf
- Java Access Bridge测试例子,全网唯一的
- flex-devel-2.5.37-6.el7.x64-86.rpm.tar.gz
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功