|
|
@@ -20,6 +20,7 @@ import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.poi.excel.ExcelUtil;
|
|
|
import cn.hutool.poi.excel.ExcelWriter;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
@@ -30,6 +31,7 @@ import com.google.common.collect.Maps;
|
|
|
import com.google.gson.internal.LinkedTreeMap;
|
|
|
import com.yami.shop.bean.app.dto.OrderCountData;
|
|
|
import com.yami.shop.bean.app.dto.ShopCartOrderMergerDto;
|
|
|
+import com.yami.shop.bean.dto.hb.HBBaseReq;
|
|
|
import com.yami.shop.bean.enums.*;
|
|
|
import com.yami.shop.bean.event.CancelOrderEvent;
|
|
|
import com.yami.shop.bean.event.ReceiptOrderEvent;
|
|
|
@@ -48,6 +50,7 @@ import com.yami.shop.service.OrderItemService;
|
|
|
import com.yami.shop.service.OrderService;
|
|
|
import com.yami.shop.service.OrderSettlementService;
|
|
|
import com.yami.shop.utils.CullenUtils;
|
|
|
+import com.yami.shop.utils.HBSignUtil;
|
|
|
import com.yami.shop.wx.po.RefundInfoPo;
|
|
|
import com.yami.shop.wx.service.WxProviderService;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
@@ -73,6 +76,8 @@ import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import static com.yami.shop.common.util.HttpUtil.post;
|
|
|
+
|
|
|
/**
|
|
|
* @author lgh on 2018/09/15.
|
|
|
*/
|
|
|
@@ -95,6 +100,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
private final OrderSettlementMapper orderSettlementMapper;
|
|
|
private Snowflake snowflake;
|
|
|
private final OrderRefundSkuMapper orderRefundSkuMapper;
|
|
|
+ private final HBSignUtil hbSignUtil;
|
|
|
|
|
|
|
|
|
@Override
|
|
|
@@ -959,12 +965,16 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
.eq(OrderRefund::getReturnMoneySts, 70)
|
|
|
.eq(OrderRefund::getHandler, Boolean.FALSE)
|
|
|
);
|
|
|
- //生成待商家审核记录
|
|
|
- addOrderRefundRecord(orderRefund.getRefundId(), 25, 6, "平台已退款到微信账户中");
|
|
|
- addOrderRefundRecord(orderRefund.getRefundId(), 30, 10, "商家已同意收货,正在为你处理退款。");
|
|
|
+ if (ObjectUtils.isNotEmpty(orderRefund)) {
|
|
|
+ Order order = orderMapper.selectById(orderRefund.getOrderId());
|
|
|
+
|
|
|
+ //生成待商家审核记录
|
|
|
+ addOrderRefundRecord(orderRefund.getRefundId(), 25, 6, "平台已退款到微信账户中");
|
|
|
+ addOrderRefundRecord(orderRefund.getRefundId(), 30, 10, "商家已同意收货,正在为你处理退款。");
|
|
|
+ //如果是分次退款最后一个商品需要改变订单状态
|
|
|
+ updateOrderStatus(order);
|
|
|
|
|
|
|
|
|
- if (ObjectUtils.isNotEmpty(orderRefund)) {
|
|
|
//退款的金额
|
|
|
BigDecimal refundActual = BigDecimal.ZERO;
|
|
|
//退款的积分
|
|
|
@@ -973,7 +983,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
long refundExpiredScore = 0L;
|
|
|
//退款总积分
|
|
|
Long refundOffsetPoints=0L;
|
|
|
- Order order = orderMapper.selectById(orderRefund.getOrderId());
|
|
|
+
|
|
|
if (null == order) throw new GlobalException("该订单不支持退款");
|
|
|
//判定已完成的时间
|
|
|
if (Objects.equals(order.getHbOrderStatus(), OrderStatus.SUCCESS.value()) && isPaymentOver7Days(order.getPayTime())) {
|
|
|
@@ -1236,6 +1246,53 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 退款成功后,修改订单状态
|
|
|
+ * @param order 订单
|
|
|
+ * 退款单
|
|
|
+ */
|
|
|
+ private void updateOrderStatus(Order order) {
|
|
|
+ //定义变量是否需要通知海博改变订单状态
|
|
|
+ boolean status = true;
|
|
|
+ for (OrderItem orderItem : orderItemMapper.getListByOrderNumber(order.getOrderNumber())) {
|
|
|
+ List<OrderRefundSku> orderRefundSkus = orderRefundSkuMapper.selectByOrderItemList(orderItem.getOrderItemId());
|
|
|
+ if (ObjectUtils.isEmpty(orderRefundSkus)){
|
|
|
+ status = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ //统计orderRefundSkus里面商品数量
|
|
|
+ int refundCount = orderRefundSkus.stream().mapToInt(OrderRefundSku::getProductCount).sum();
|
|
|
+ if (!orderItem.getProdCount().equals(refundCount)) {
|
|
|
+ status = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (status){
|
|
|
+ order.setHbOrderStatus(OrderStatus.CLOSE.value());
|
|
|
+ orderMapper.updateById(order);
|
|
|
+ //通知海博改变订单状态
|
|
|
+ HBBaseReq<Object> build = HBBaseReq.create();
|
|
|
+ build.setAppId(hbSignUtil.getAppId());
|
|
|
+
|
|
|
+ // 3. 构建外层请求体
|
|
|
+ JSONObject requestBody = new JSONObject();
|
|
|
+ requestBody.put("channelOrderId", order.getOrderNumber());
|
|
|
+ requestBody.put("operator", "admin");
|
|
|
+ // 订单操作时间戳毫秒数
|
|
|
+ requestBody.put("operatorTime", System.currentTimeMillis());
|
|
|
+ //操作类型 (20:订单已接单 30:订单待配送 60:订单已取消 80:订单已完成)
|
|
|
+ requestBody.put("operatorType", OrderStatus.CLOSE.value());
|
|
|
+ // 4. 将整个JSON对象序列化为字符串并设置
|
|
|
+ build.setBody(JSON.toJSONString(requestBody));
|
|
|
+
|
|
|
+ build.setSign(hbSignUtil.signMd5(build));
|
|
|
+ log.info("post 订单推送单号参数:{}", JSON.toJSONString(build));
|
|
|
+ String post = post(hbSignUtil.getHBHost() + "/api/order/changeOrderStatus", build);
|
|
|
+ log.info("post 订单推送结果:{}", post);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void addOrderRefundRecord(Long refundId, Integer auditStatus, Integer sort, String instructions) {
|
|
|
OrderRefundRecord orderRefundRecord = new OrderRefundRecord();
|
|
|
orderRefundRecord.setOrderRefundId(refundId);
|