|
|
@@ -24,11 +24,16 @@ import com.fs.erp.constant.AfterSalesOrderStatusEnum;
|
|
|
import com.fs.erp.domain.FsJstAftersalePush;
|
|
|
import com.fs.erp.dto.BaseResponse;
|
|
|
import com.fs.erp.dto.ErpRefundUpdateRequest;
|
|
|
+import com.fs.erp.dto.OrderQueryRequestDTO;
|
|
|
+import com.fs.erp.dto.OrderQueryResponseDTO;
|
|
|
+import com.fs.erp.dto.RefundItemDTO;
|
|
|
+import com.fs.erp.http.JstErpHttpService;
|
|
|
import com.fs.erp.mapper.FsJstAftersalePushMapper;
|
|
|
import com.fs.erp.mapper.FsJstAftersalePushScrmMapper;
|
|
|
import com.fs.erp.service.IErpOrderService;
|
|
|
import com.fs.his.config.FsSysConfig;
|
|
|
import com.fs.his.domain.*;
|
|
|
+import com.fs.his.dto.FsStoreCartDTO;
|
|
|
import com.fs.his.enums.FsStoreAfterSalesStatusEnum;
|
|
|
import com.fs.his.enums.FsStoreOrderLogEnum;
|
|
|
import com.fs.his.enums.FsStoreOrderStatusEnum;
|
|
|
@@ -60,6 +65,7 @@ import com.fs.tzBankPay.doman.RefundParam;
|
|
|
import com.fs.tzBankPay.doman.RefundResult;
|
|
|
import com.fs.tzBankPay.doman.TzBankResult;
|
|
|
import com.fs.ybPay.dto.RefundDTO;
|
|
|
+import com.fs.ybPay.dto.RefundOrderDTO;
|
|
|
import com.fs.ybPay.dto.YopRefundRequestDTO;
|
|
|
import com.fs.ybPay.dto.YopRefundResponseDTO;
|
|
|
import com.fs.ybPay.service.IYopPayService;
|
|
|
@@ -77,6 +83,7 @@ import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
@@ -145,6 +152,14 @@ public class FsStoreAfterSalesScrmServiceImpl implements IFsStoreAfterSalesScrmS
|
|
|
@Qualifier("k9OrderScrmServiceImpl")
|
|
|
private IErpOrderService k9OrderService;
|
|
|
|
|
|
+ /** 聚水潭 HTTP 客户端:用于调用 /open/orders/single/query 订单查询接口 */
|
|
|
+ @Autowired
|
|
|
+ private JstErpHttpService jstErpHttpService;
|
|
|
+
|
|
|
+ /** 聚水潭店铺编号,用于订单查询时填充 shop_id */
|
|
|
+ @Value("${jst.shop_code:0}")
|
|
|
+ private String jstShopCode;
|
|
|
+
|
|
|
@Autowired
|
|
|
private ISysConfigService configService;
|
|
|
|
|
|
@@ -377,6 +392,15 @@ public class FsStoreAfterSalesScrmServiceImpl implements IFsStoreAfterSalesScrmS
|
|
|
//
|
|
|
// }
|
|
|
// }
|
|
|
+ //清理原始售后信息
|
|
|
+ List<FsStoreAfterSalesVO> afterSalesVOList = fsStoreAfterSalesMapper.selectFsStoreAfterSalesVOByOrderCode(order.getOrderCode());
|
|
|
+ if(!afterSalesVOList.isEmpty()){
|
|
|
+ afterSalesVOList.forEach(v -> {
|
|
|
+ fsStoreAfterSalesMapper.deleteFsStoreAfterSalesById(v.getId());
|
|
|
+ //详情删除
|
|
|
+ afterSalesItemService.deleteFsStoreAfterSalesItemById(v.getId());
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
//生成售后订单
|
|
|
FsStoreAfterSalesScrm storeAfterSales = new FsStoreAfterSalesScrm();
|
|
|
@@ -396,6 +420,29 @@ public class FsStoreAfterSalesScrmServiceImpl implements IFsStoreAfterSalesScrmS
|
|
|
storeAfterSales.setCompanyUserId(order.getCompanyUserId());
|
|
|
storeAfterSales.setPackageJson(order.getPackageJson());
|
|
|
storeAfterSales.setIsPackage(order.getIsPackage());
|
|
|
+ // 兼容“一步提交”:若同时传了商家收货信息+物流信息,一并写入售后单
|
|
|
+ // 有寄回物流单号即视为退货退款,service_type 强制为 3
|
|
|
+ if (StringUtils.isNotBlank(storeAfterSalesParam.getDeliverySn())) {
|
|
|
+ storeAfterSales.setServiceType(3);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(storeAfterSalesParam.getConsignee())) {
|
|
|
+ storeAfterSales.setConsignee(storeAfterSalesParam.getConsignee());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(storeAfterSalesParam.getPhoneNumber())) {
|
|
|
+ storeAfterSales.setPhoneNumber(storeAfterSalesParam.getPhoneNumber());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(storeAfterSalesParam.getAddress())) {
|
|
|
+ storeAfterSales.setAddress(storeAfterSalesParam.getAddress());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(storeAfterSalesParam.getShipperCode())) {
|
|
|
+ storeAfterSales.setShipperCode(storeAfterSalesParam.getShipperCode());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(storeAfterSalesParam.getDeliverySn())) {
|
|
|
+ storeAfterSales.setDeliverySn(storeAfterSalesParam.getDeliverySn());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(storeAfterSalesParam.getDeliveryName())) {
|
|
|
+ storeAfterSales.setDeliveryName(storeAfterSalesParam.getDeliveryName());
|
|
|
+ }
|
|
|
fsStoreAfterSalesMapper.insertFsStoreAfterSales(storeAfterSales);
|
|
|
//售后商品详情
|
|
|
for (FsStoreAfterSalesProductParam productParam : storeAfterSalesParam.getProductList()) {
|
|
|
@@ -418,23 +465,23 @@ public class FsStoreAfterSalesScrmServiceImpl implements IFsStoreAfterSalesScrmS
|
|
|
storeAfterSalesStatus.setOperator(user.getNickname());
|
|
|
afterSalesStatusService.insertFsStoreAfterSalesStatus(storeAfterSalesStatus);
|
|
|
|
|
|
-// //更新OMS
|
|
|
- IErpOrderService erpOrderService = getErpService();
|
|
|
- ErpRefundUpdateRequest request=new ErpRefundUpdateRequest();
|
|
|
- request.setTid(order.getOrderCode());
|
|
|
- request.setOid(order.getOrderCode());
|
|
|
- request.setRefund_state(1);
|
|
|
- request.setStoreAfterSalesId(storeAfterSales.getId());
|
|
|
- if (StringUtils.isNotBlank(order.getExtendOrderId())){
|
|
|
- BaseResponse response=erpOrderService.refundUpdateScrm(request);
|
|
|
- if(response.getSuccess()){
|
|
|
- return R.ok();
|
|
|
- }
|
|
|
- else{
|
|
|
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
- return R.error(response.getErrorDesc());
|
|
|
- }
|
|
|
- }
|
|
|
+// //更新OMS-延迟取消,到退款的时候取消
|
|
|
+// IErpOrderService erpOrderService = getErpService();
|
|
|
+// ErpRefundUpdateRequest request=new ErpRefundUpdateRequest();
|
|
|
+// request.setTid(order.getOrderCode());
|
|
|
+// request.setOid(order.getOrderCode());
|
|
|
+// request.setRefund_state(1);
|
|
|
+// request.setStoreAfterSalesId(storeAfterSales.getId());
|
|
|
+// if (StringUtils.isNotBlank(order.getExtendOrderId())){
|
|
|
+// BaseResponse response=erpOrderService.refundUpdateScrm(request);
|
|
|
+// if(response.getSuccess()){
|
|
|
+// return R.ok();
|
|
|
+// }
|
|
|
+// else{
|
|
|
+// TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+// return R.error(response.getErrorDesc());
|
|
|
+// }
|
|
|
+// }
|
|
|
return R.ok();
|
|
|
}
|
|
|
|
|
|
@@ -974,16 +1021,16 @@ public class FsStoreAfterSalesScrmServiceImpl implements IFsStoreAfterSalesScrmS
|
|
|
//创建新的OMS订单
|
|
|
if (storeAfterSales.getOrderStatus().equals(OrderInfoEnum.STATUS_1.getValue()) ) {
|
|
|
if(StringUtils.isNotEmpty(order.getExtendOrderId())){
|
|
|
- //更新订单code
|
|
|
- String orderSn = IdUtil.getSnowflake(0, 0).nextIdStr();
|
|
|
- FsStoreOrderScrm orderMap=new FsStoreOrderScrm();
|
|
|
- orderMap.setId(order.getId());
|
|
|
- orderMap.setOrderCode(orderSn);
|
|
|
- orderService.updateFsStoreOrder(orderMap);
|
|
|
- storeAfterSales.setOrderCode(orderSn);
|
|
|
- orderItemService.updateFsStoreOrderCode(order.getId(),orderSn);
|
|
|
- //生成新的订单
|
|
|
- orderService.createOmsOrder(order.getId());
|
|
|
+// //更新订单code
|
|
|
+// String orderSn = IdUtil.getSnowflake(0, 0).nextIdStr();
|
|
|
+// FsStoreOrderScrm orderMap=new FsStoreOrderScrm();
|
|
|
+// orderMap.setId(order.getId());
|
|
|
+// orderMap.setOrderCode(orderSn);
|
|
|
+// orderService.updateFsStoreOrder(orderMap);
|
|
|
+// storeAfterSales.setOrderCode(orderSn);
|
|
|
+// orderItemService.updateFsStoreOrderCode(order.getId(),orderSn);
|
|
|
+// //生成新的订单
|
|
|
+// orderService.createOmsOrder(order.getId());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1011,8 +1058,10 @@ public class FsStoreAfterSalesScrmServiceImpl implements IFsStoreAfterSalesScrmS
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public R audit1(FsStoreAfterSalesAudit1Param param) {
|
|
|
FsStoreAfterSalesScrm storeAfterSales = fsStoreAfterSalesMapper.selectFsStoreAfterSalesById(param.getSalesId());
|
|
|
+ FsStoreOrderScrm order=orderService.selectFsStoreOrderByOrderCode(storeAfterSales.getOrderCode());
|
|
|
if (storeAfterSales == null) {
|
|
|
throw new CustomException("未查询到售后订单信息");
|
|
|
}
|
|
|
@@ -1042,10 +1091,9 @@ public class FsStoreAfterSalesScrmServiceImpl implements IFsStoreAfterSalesScrmS
|
|
|
afterSalesStatusService.insertFsStoreAfterSalesStatus(storeAfterSalesStatus);
|
|
|
}
|
|
|
//退款退货
|
|
|
- else if(storeAfterSales.getServiceType().equals(1)){
|
|
|
+ else if(storeAfterSales.getServiceType().equals(1) || storeAfterSales.getServiceType().equals(3)){
|
|
|
String json=configService.selectConfigByKey("store.config");
|
|
|
StoreConfig config=JSONUtil.toBean(json,StoreConfig.class);
|
|
|
- FsStoreOrderScrm order=orderService.selectFsStoreOrderByOrderCode(storeAfterSales.getOrderCode());
|
|
|
if(order.getStoreHouseCode()!=null){
|
|
|
if(order.getStoreHouseCode().equals("CK01")){
|
|
|
storeAfterSales.setConsignee(config.getRefundConsignee());
|
|
|
@@ -1065,7 +1113,7 @@ public class FsStoreAfterSalesScrmServiceImpl implements IFsStoreAfterSalesScrmS
|
|
|
storeAfterSales.setAddress(config.getRefundAddress());
|
|
|
}
|
|
|
//退款退货
|
|
|
- storeAfterSales.setStatus(1);
|
|
|
+ storeAfterSales.setStatus(2);
|
|
|
fsStoreAfterSalesMapper.updateFsStoreAfterSales(storeAfterSales);
|
|
|
FsStoreAfterSalesStatusScrm storeAfterSalesStatus = new FsStoreAfterSalesStatusScrm();
|
|
|
storeAfterSalesStatus.setStoreAfterSalesId(storeAfterSales.getId());
|
|
|
@@ -1076,9 +1124,129 @@ public class FsStoreAfterSalesScrmServiceImpl implements IFsStoreAfterSalesScrmS
|
|
|
afterSalesStatusService.insertFsStoreAfterSalesStatus(storeAfterSalesStatus);
|
|
|
}
|
|
|
|
|
|
+ //更新OMS-取消订单放到退款接口来
|
|
|
+ IErpOrderService erpOrderService = getErpService();
|
|
|
+ String jstOrderStatus = queryJstOrderStatus(order.getOrderCode());
|
|
|
+ boolean alreadySent = jstOrderStatus != null
|
|
|
+ ? "Sent".equalsIgnoreCase(jstOrderStatus)
|
|
|
+ : order.getStatus().equals(OrderInfoEnum.STATUS_2.getValue());
|
|
|
+ if(alreadySent){
|
|
|
+ //订单已发货:同步调用聚水潭 /open/aftersale/upload 上传售后单
|
|
|
+ // • 有寄回物流单号 = 退货退款: type=“普通退货”, shop_status=WAIT_SELLER_CONFIRM_GOODS,携带物流字段
|
|
|
+ // • 无寄回物流单号 = 仅退款: type=“仅退款”, shop_status=WAIT_SELLER_AGREE
|
|
|
+ // items[].type 仅接受 退货/换货/其它/补发,此处统一传“退货”
|
|
|
+ try {
|
|
|
+ boolean isReturnRefund = StringUtils.isNotBlank(storeAfterSales.getDeliverySn());
|
|
|
+ RefundOrderDTO refundOrderDTO = new RefundOrderDTO();
|
|
|
+ if (isReturnRefund) {
|
|
|
+ refundOrderDTO.setShopStatus(AfterSalesOrderStatusEnum.WAIT_SELLER_CONFIRM_GOODS.getCode());
|
|
|
+ refundOrderDTO.setType("普通退货");
|
|
|
+ refundOrderDTO.setLogisticsCompany(storeAfterSales.getDeliveryName());
|
|
|
+ refundOrderDTO.setLId(storeAfterSales.getDeliverySn());
|
|
|
+ } else {
|
|
|
+ refundOrderDTO.setShopStatus(AfterSalesOrderStatusEnum.WAIT_SELLER_AGREE.getCode());
|
|
|
+ refundOrderDTO.setType("仅退款");
|
|
|
+ }
|
|
|
+ refundOrderDTO.setQuestionType("可更新");
|
|
|
+ refundOrderDTO.setOuterAsId(String.valueOf(storeAfterSales.getId()));
|
|
|
+ refundOrderDTO.setRemark("用户退款");
|
|
|
+ refundOrderDTO.setSoId(storeAfterSales.getOrderCode());
|
|
|
+ refundOrderDTO.setTotalAmount(order.getTotalPrice());
|
|
|
+ refundOrderDTO.setRefund(order.getPayMoney());
|
|
|
+ refundOrderDTO.setPayment(BigDecimal.ZERO);
|
|
|
+ if (StringUtils.isNotBlank(jstShopCode) && !"0".equals(jstShopCode)) {
|
|
|
+ try {
|
|
|
+ refundOrderDTO.setShopId(Long.valueOf(jstShopCode));
|
|
|
+ } catch (NumberFormatException ignore) {
|
|
|
+ // shop_code 配置非数字时不传 shop_id,由聚水潭内部匹配
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 查订单商品明细构造 items 节点
|
|
|
+ FsStoreOrderItemScrm itemQuery = new FsStoreOrderItemScrm();
|
|
|
+ itemQuery.setOrderId(order.getId());
|
|
|
+ List<FsStoreOrderItemScrm> orderItems = orderItemService.selectFsStoreOrderItemList(itemQuery);
|
|
|
+ List<RefundItemDTO> refundItems = new ArrayList<>();
|
|
|
+ if (orderItems != null) {
|
|
|
+ for (FsStoreOrderItemScrm oi : orderItems) {
|
|
|
+ FsStoreCartDTO cartDTO = JSONUtil.toBean(oi.getJsonInfo(), FsStoreCartDTO.class);
|
|
|
+ RefundItemDTO ri = new RefundItemDTO();
|
|
|
+ ri.setSkuId(cartDTO.getBarCode());
|
|
|
+ ri.setQty(cartDTO.getNum());
|
|
|
+ ri.setAmount(cartDTO.getPrice());
|
|
|
+ // 文档映射:items[].type 只能是 退货/换货/其它/补发
|
|
|
+ ri.setType("退货");
|
|
|
+ refundItems.add(ri);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ refundOrderDTO.setItems(refundItems);
|
|
|
+ Object uploadResp = jstErpHttpService.aftersaleUpload(refundOrderDTO);
|
|
|
+ logger.info("[聚水潭售后上传] outerAsId={}, soId={}, response={}",
|
|
|
+ storeAfterSales.getId(), storeAfterSales.getOrderCode(),
|
|
|
+ JSON.toJSONString(uploadResp));
|
|
|
+ } catch (Exception ex) {
|
|
|
+ // ERP 调用异常不阻断本地审核流程,失败打印错误日志供排查
|
|
|
+ logger.error("[聚水潭售后上传] 异常 outerAsId={}, soId={}, 错误:{}",
|
|
|
+ storeAfterSales.getId(), storeAfterSales.getOrderCode(), ex.getMessage(), ex);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ ErpRefundUpdateRequest request=new ErpRefundUpdateRequest();
|
|
|
+ request.setTid(storeAfterSales.getOrderCode());
|
|
|
+ request.setOid(storeAfterSales.getOrderCode());
|
|
|
+ request.setRefund_state(1);
|
|
|
+ request.setStoreAfterSalesId(storeAfterSales.getId());
|
|
|
+ if (StringUtils.isNotBlank(order.getExtendOrderId())){
|
|
|
+ BaseResponse response=erpOrderService.refundUpdateScrm(request);
|
|
|
+ if(response.getSuccess()){
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return R.error(response.getErrorDesc());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
return R.ok("操作成功");
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 调用聚水潭 /open/orders/single/query 查询订单状态
|
|
|
+ * <p>
|
|
|
+ * 返回值为聚水潭订单状态枚举值字符串(Sent/Delivering/WaitConfirm/Cancelled 等),
|
|
|
+ * 查不到或调用异常时返回 null,由调用方自行降级。
|
|
|
+ *
|
|
|
+ * @param orderCode 线上订单号,即本地 FsStoreOrderScrm.orderCode,对应聚水潭 so_id
|
|
|
+ * @return 聚水潭订单状态值;若未查到或异常返回 null
|
|
|
+ */
|
|
|
+ private String queryJstOrderStatus(String orderCode) {
|
|
|
+ if (StringUtils.isBlank(orderCode)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ OrderQueryRequestDTO requestDTO = OrderQueryRequestDTO.builder()
|
|
|
+ .soIds(java.util.Collections.singletonList(orderCode))
|
|
|
+ .pageIndex(1)
|
|
|
+ .pageSize(1)
|
|
|
+ .isGetTotal(false)
|
|
|
+ .build();
|
|
|
+ // 配置了店铺编号时一并传入,提升查询命中率
|
|
|
+ if (StringUtils.isNotBlank(jstShopCode) && !"0".equals(jstShopCode)) {
|
|
|
+ try {
|
|
|
+ requestDTO.setShopId(Integer.valueOf(jstShopCode));
|
|
|
+ } catch (NumberFormatException ignore) {
|
|
|
+ // shop_code 配置非数字时忽略该参数
|
|
|
+ }
|
|
|
+ }
|
|
|
+ OrderQueryResponseDTO responseDTO = jstErpHttpService.query(requestDTO);
|
|
|
+ if (responseDTO == null || responseDTO.getOrders() == null || responseDTO.getOrders().isEmpty()) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return responseDTO.getOrders().get(0).getStatus();
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("查询聚水潭订单状态异常,orderCode={}, 错误:{}", orderCode, e.getMessage(), e);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public R audit2(FsStoreAfterSalesAudit2Param param) {
|
|
|
FsStoreAfterSalesScrm storeAfterSales = fsStoreAfterSalesMapper.selectFsStoreAfterSalesById(param.getSalesId());
|
|
|
@@ -1686,4 +1854,9 @@ public class FsStoreAfterSalesScrmServiceImpl implements IFsStoreAfterSalesScrmS
|
|
|
|
|
|
return i;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Integer getAfterSalesType(String orderCode) {
|
|
|
+ return fsStoreAfterSalesMapper.getAfterSalesType(orderCode);
|
|
|
+ }
|
|
|
}
|