use of com.wayn.common.core.domain.shop.OrderGoods in project waynboot-mall by wayn111.
the class AdminOrderServiceImpl method detail.
@Override
public R detail(Long orderId) {
Order order = getById(orderId);
if (order == null) {
return R.error();
}
List<OrderGoods> orderGoodsList = iOrderGoodsService.list(new QueryWrapper<OrderGoods>().eq("order_id", orderId));
Member member = iMemberService.getById(order.getUserId());
Map<String, Object> data = new HashMap<>();
data.put("order", order);
data.put("orderGoods", orderGoodsList);
data.put("user", member);
return R.success().add("data", data);
}
use of com.wayn.common.core.domain.shop.OrderGoods in project waynboot-mall by wayn111.
the class AdminOrderServiceImpl method refund.
@Override
@Transactional(rollbackFor = Exception.class)
public R refund(Long orderId) {
Order order = getById(orderId);
if (order == null) {
return R.error();
}
// 如果订单不是退款状态,则不能退款
if (!order.getOrderStatus().equals(OrderUtil.STATUS_REFUND)) {
return R.error(ReturnCodeEnum.ORDER_CANNOT_REFUND_ERROR);
}
// 微信退款
// WxPayRefundRequest wxPayRefundRequest = new WxPayRefundRequest();
// wxPayRefundRequest.setOutTradeNo(order.getOrderSn());
// wxPayRefundRequest.setOutRefundNo("refund_" + order.getOrderSn());
// // 元转成分
// Integer totalFee = order.getActualPrice().multiply(new BigDecimal(100)).intValue();
// wxPayRefundRequest.setTotalFee(totalFee);
// wxPayRefundRequest.setRefundFee(totalFee);
//
// WxPayRefundResult wxPayRefundResult;
// try {
// wxPayRefundResult = wxPayService.refund(wxPayRefundRequest);
// } catch (WxPayException e) {
// log.error(e.getMessage(), e);
// return R.error("订单退款失败");
// }
// if (!wxPayRefundResult.getReturnCode().equals("SUCCESS")) {
// log.warn("refund fail: " + wxPayRefundResult.getReturnMsg());
// return R.error("订单退款失败");
// }
// if (!wxPayRefundResult.getResultCode().equals("SUCCESS")) {
// log.warn("refund fail: " + wxPayRefundResult.getReturnMsg());
// return R.error("订单退款失败");
// }
LocalDateTime now = LocalDateTime.now();
// 设置订单取消状态
order.setOrderStatus(OrderUtil.STATUS_REFUND_CONFIRM);
order.setOrderEndTime(now);
// 记录订单退款相关信息
order.setRefundAmount(order.getActualPrice());
order.setRefundType("微信退款接口");
// order.setRefundContent(wxPayRefundResult.getRefundId());
order.setRefundContent("已退款");
order.setRefundTime(now);
order.setUpdateTime(new Date());
updateById(order);
// 商品货品数量增加
List<OrderGoods> orderGoodsList = iOrderGoodsService.list(new QueryWrapper<OrderGoods>().eq("order_id", orderId));
for (OrderGoods orderGoods : orderGoodsList) {
Long productId = orderGoods.getProductId();
Integer number = orderGoods.getNumber();
if (!iGoodsProductService.addStock(productId, number)) {
throw new RuntimeException("商品货品库存增加失败");
}
}
// 返还优惠券
// List<LitemallCouponUser> couponUsers = couponUserService.findByOid(orderId);
// for (LitemallCouponUser couponUser: couponUsers) {
// // 优惠券状态设置为可使用
// couponUser.setStatus(CouponUserConstant.STATUS_USABLE);
// couponUser.setUpdateTime(LocalDateTime.now());
// couponUserService.update(couponUser);
// }
// 退款成功通知用户, 例如“您申请的订单退款 [ 单号:{1} ] 已成功,请耐心等待到账。”
// 注意订单号只发后6位
String email = iMemberService.getById(order.getUserId()).getEmail();
if (StringUtils.isNotEmpty(email)) {
iMailService.sendEmail("订单已经退款", order.getOrderSn().substring(8, 14), email, WaynConfig.getAdminUrl() + "/message/email");
}
// logHelper.logOrderSucceed("退款", "订单编号 " + order.getOrderSn());
return R.success();
}
use of com.wayn.common.core.domain.shop.OrderGoods in project waynboot-mall by wayn111.
the class OrderUnpaidTask method run.
@Override
public void run() {
log.info("系统开始处理延时任务---订单超时未付款---{}", this.orderId);
IOrderService orderService = SpringContextUtil.getBean(IOrderService.class);
IOrderGoodsService orderGoodsService = SpringContextUtil.getBean(IOrderGoodsService.class);
IGoodsProductService productService = SpringContextUtil.getBean(IGoodsProductService.class);
RedisCache redisCache = SpringContextUtil.getBean(RedisCache.class);
Set<Long> zSet = redisCache.getCacheZset("order_zset", 0, System.currentTimeMillis());
if (CollectionUtils.isEmpty(zSet) || !zSet.contains(this.orderId)) {
return;
}
for (Long orderId : zSet) {
log.info("redis内未付款订单, 编号:{} begin", orderId);
final Long num = redisCache.deleteZsetObject("order_zset", orderId);
if (num == null || num <= 0) {
break;
}
Order order = orderService.getOne(Wrappers.lambdaQuery(Order.class).eq(Order::getOrderStatus, OrderUtil.STATUS_CREATE).eq(Order::getId, orderId));
if (Objects.isNull(order) || !OrderUtil.isCreateStatus(order)) {
break;
}
// 设置订单为已取消状态
order.setOrderStatus(OrderUtil.STATUS_AUTO_CANCEL);
order.setOrderEndTime(LocalDateTime.now());
if (!orderService.updateById(order)) {
log.info("redis内未付款订单, 编号:{} 更新订单状态失败", orderId);
throw new RuntimeException("更新订单状态失败");
}
// 商品货品数量增加
List<OrderGoods> orderGoodsList = orderGoodsService.list(Wrappers.lambdaQuery(OrderGoods.class).eq(OrderGoods::getOrderId, orderId));
for (OrderGoods orderGoods : orderGoodsList) {
Long productId = orderGoods.getProductId();
Integer number = orderGoods.getNumber();
if (!productService.addStock(productId, number)) {
log.info("redis内未付款订单, 编号:{} 商品货品库存增加失败", orderId);
throw new RuntimeException("商品货品库存增加失败");
}
}
log.info("redis内未付款订单, 编号:{} end", orderId);
}
log.info("系统结束处理延时任务---订单超时未付款---{}", this.orderId);
}
Aggregations