|
@@ -12,7 +12,9 @@ import com.fs.erp.domain.*;
|
|
|
import com.fs.erp.dto.*;
|
|
|
import com.fs.erp.http.JstErpHttpService;
|
|
|
import com.fs.erp.mapper.FsJstAftersalePushMapper;
|
|
|
+import com.fs.erp.mapper.FsJstAftersalePushScrmMapper;
|
|
|
import com.fs.erp.mapper.FsJstCodPushMapper;
|
|
|
+import com.fs.erp.mapper.FsJstCodPushScrmMapper;
|
|
|
import com.fs.erp.service.IErpOrderService;
|
|
|
import com.fs.his.domain.FsStoreOrder;
|
|
|
import com.fs.his.domain.FsStoreOrderItem;
|
|
@@ -27,6 +29,7 @@ import com.fs.hisStore.domain.FsStoreProductScrm;
|
|
|
import com.fs.hisStore.service.IFsStoreOrderItemScrmService;
|
|
|
import com.fs.hisStore.service.IFsStoreOrderScrmService;
|
|
|
import com.fs.hisStore.service.IFsStoreProductScrmService;
|
|
|
+import com.fs.hisStore.service.impl.FsStoreProductScrmServiceImpl;
|
|
|
import com.fs.hisStore.vo.FsStoreOrderItemVO;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang.ObjectUtils;
|
|
@@ -35,6 +38,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
@@ -58,15 +62,20 @@ public class JSTErpOrderServiceImpl implements IErpOrderService {
|
|
|
private IFsStoreOrderItemService fsStoreOrderItemService;
|
|
|
@Autowired
|
|
|
private IFsStoreOrderItemScrmService fsStoreOrderItemScrmService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private IFsStoreProductService fsStoreProductService;
|
|
|
- @Autowired
|
|
|
- private IFsStoreProductScrmService fsStoreProductScrmService;
|
|
|
|
|
|
@Autowired
|
|
|
private FsJstCodPushMapper fsJstCodPushMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private FsJstAftersalePushScrmMapper fsJstAftersalePushScrmMapper;
|
|
|
+ @Autowired
|
|
|
+ private FsJstCodPushScrmMapper fsJstCodPushScrmMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IFsStoreProductScrmService fsStoreProductScrmService;
|
|
|
+
|
|
|
@Override
|
|
|
public ErpOrderResponse addOrder(ErpOrder order) {
|
|
|
FsStoreOrder fsStoreOrder = fsStoreOrderService.selectFsStoreOrderByOrderCode(order.getPlatform_code());
|
|
@@ -129,8 +138,9 @@ public class JSTErpOrderServiceImpl implements IErpOrderService {
|
|
|
|
|
|
FsStoreProduct fsStoreProduct = fsStoreProductService.selectFsStoreProductById(item.getProductId());
|
|
|
|
|
|
- orderItemDTO.setAmount(fsStoreProduct.getPrice());
|
|
|
-
|
|
|
+ orderItemDTO.setAmount(fsStoreProduct.getPrice().multiply(new BigDecimal(item.getNum())));
|
|
|
+ orderItemDTO.setPic(fsStoreProduct.getImgUrl());
|
|
|
+ orderItemDTO.setPrice(fsStoreProduct.getPrice());
|
|
|
orderItemDTO.setQty(item.getNum().intValue());
|
|
|
orderItemDTO.setOuterOiId(String.format("%s%s",fsStoreOrder.getOrderCode(),item.getItemId()));
|
|
|
itemDTOList.add(orderItemDTO);
|
|
@@ -253,8 +263,9 @@ public class JSTErpOrderServiceImpl implements IErpOrderService {
|
|
|
|
|
|
FsStoreProductScrm fsStoreProduct = fsStoreProductScrmService.selectFsStoreProductById(item.getProductId());
|
|
|
|
|
|
- orderItemDTO.setAmount(fsStoreProduct.getPrice());
|
|
|
-
|
|
|
+ orderItemDTO.setAmount(fsStoreProduct.getPrice().multiply(new BigDecimal(item.getNum())));
|
|
|
+ orderItemDTO.setPic(fsStoreProduct.getImage());
|
|
|
+ orderItemDTO.setPrice(fsStoreProduct.getPrice());
|
|
|
orderItemDTO.setQty(item.getNum().intValue());
|
|
|
orderItemDTO.setOuterOiId(String.format("%s%s",fsStoreOrder.getOrderCode(),item.getItemId()));
|
|
|
itemDTOList.add(orderItemDTO);
|
|
@@ -275,13 +286,15 @@ public class JSTErpOrderServiceImpl implements IErpOrderService {
|
|
|
if("2".equals(fsStoreOrder.getPayType()) || "3".equals(fsStoreOrder.getPayType())){
|
|
|
shopOrderDTO.setIsCod(true);
|
|
|
// 货到付款金额 = 物流代收金额-优惠金额
|
|
|
- shopOrderDTO.setBuyerPaidAmount(fsStoreOrder.getPayDelivery());
|
|
|
- shopOrderDTO.setPayAmount(fsStoreOrder.getPayPrice().doubleValue());
|
|
|
+ //注释掉总买家实付
|
|
|
+ //shopOrderDTO.setBuyerPaidAmount(fsStoreOrder.getPayDelivery());
|
|
|
+ //应付金额(货到付款= 订单总金额 - 已付金额)
|
|
|
+ shopOrderDTO.setPayAmount(fsStoreOrder.getTotalPrice().subtract(fsStoreOrder.getPayPrice()).doubleValue());
|
|
|
|
|
|
// 货到付款要推两次
|
|
|
PaymentDTO paymentDTO2 = new PaymentDTO();
|
|
|
// 物流代收金额
|
|
|
- paymentDTO2.setAmount(fsStoreOrder.getPayDelivery().doubleValue());
|
|
|
+ paymentDTO2.setAmount(fsStoreOrder.getTotalPrice().subtract(fsStoreOrder.getPayPrice()).doubleValue());
|
|
|
paymentDTO2.setOuterPayId(String.format("%s%d",order.getPlatform_code(),1));
|
|
|
paymentDTO2.setPayDate(order.getDeal_datetime());
|
|
|
paymentDTO2.setPayment("货到付款");
|
|
@@ -295,7 +308,7 @@ public class JSTErpOrderServiceImpl implements IErpOrderService {
|
|
|
fsJstCodPush.setParams(JSON.toJSONString(shopOrderDTO));
|
|
|
fsJstCodPush.setRetryCount(0);
|
|
|
fsJstCodPush.setTaskStatus(TaskStatusEnum.PENDING.getCode());
|
|
|
- fsJstCodPushMapper.insert(fsJstCodPush);
|
|
|
+ fsJstCodPushScrmMapper.insert(fsJstCodPush);
|
|
|
|
|
|
//shopOrderDTO.setPay(paymentDTO);
|
|
|
}
|
|
@@ -355,6 +368,35 @@ public class JSTErpOrderServiceImpl implements IErpOrderService {
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ErpOrderQueryResponse getScrmOrder(ErpOrderQueryRequert param) {
|
|
|
+ // 1. 构建查询请求DTO
|
|
|
+ OrderQueryRequestDTO requestDTO = new OrderQueryRequestDTO();
|
|
|
+ requestDTO.setOIds(Collections.singletonList(Long.valueOf(param.getCode())));
|
|
|
+
|
|
|
+
|
|
|
+ // 2. 调用ERP服务查询订单
|
|
|
+ OrderQueryResponseDTO query = jstErpHttpService.query(requestDTO);
|
|
|
+
|
|
|
+ // 3. 构建响应对象
|
|
|
+ ErpOrderQueryResponse response = new ErpOrderQueryResponse();
|
|
|
+
|
|
|
+ // 4. 设置基本响应信息
|
|
|
+
|
|
|
+ // 5. 转换订单数据
|
|
|
+ if (query.getOrders() != null && !query.getOrders().isEmpty()) {
|
|
|
+ List<ErpOrderQuery> erpOrders = query.getOrders().stream()
|
|
|
+ .map(this::convertToErpOrderQueryScrm)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ response.setOrders(erpOrders);
|
|
|
+ } else {
|
|
|
+ response.setOrders(Collections.emptyList());
|
|
|
+ }
|
|
|
+
|
|
|
+ return response;
|
|
|
+ }
|
|
|
/**
|
|
|
* 将OrderQueryResponseDTO.Order转换为ErpOrderQuery
|
|
|
*
|
|
@@ -438,17 +480,99 @@ public class JSTErpOrderServiceImpl implements IErpOrderService {
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+ private ErpOrderQuery convertToErpOrderQueryScrm(OrderQueryResponseDTO.Order order) {
|
|
|
+ ErpOrderQuery erpOrder = new ErpOrderQuery();
|
|
|
+
|
|
|
+ FsStoreOrderScrm fsStoreOrder = fsStoreOrderService.selectFsStoreOrderScrmByOrderCode(order.getSoId());
|
|
|
+ Asserts.notNull(fsStoreOrder,"该订单号没有找到!");
|
|
|
+
|
|
|
+ // 设置基本订单信息
|
|
|
+ erpOrder.setCode(order.getSoId());
|
|
|
+
|
|
|
+ // 计算订单总数量
|
|
|
+ if (order.getItems() != null && !order.getItems().isEmpty()) {
|
|
|
+ int totalQty = order.getItems().stream()
|
|
|
+ .mapToInt(OrderQueryResponseDTO.OrderItem::getQty)
|
|
|
+ .sum();
|
|
|
+ erpOrder.setQty(totalQty);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置金额相关信息
|
|
|
+ erpOrder.setAmount(order.getAmount() != null ? order.getAmount().doubleValue() : null);
|
|
|
+ erpOrder.setPayment(order.getPaidAmount() != null ? order.getPaidAmount().doubleValue() : null);
|
|
|
+
|
|
|
+ // 设置其他订单属性
|
|
|
+ erpOrder.setCod(order.getIsCod());
|
|
|
+ erpOrder.setPlatform_code(order.getOrderFrom());
|
|
|
+
|
|
|
+ // 尝试解析创建时间
|
|
|
+ try {
|
|
|
+ if (order.getCreated() != null) {
|
|
|
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ erpOrder.setCreatetime(formatter.parse(order.getCreated()));
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 日期解析异常处理
|
|
|
+ // 可以记录日志或保持为null
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置店铺信息
|
|
|
+ erpOrder.setShop_name(order.getShopName());
|
|
|
+ erpOrder.setShop_code(String.valueOf(order.getShopId()));
|
|
|
+
|
|
|
+ // 设置物流信息
|
|
|
+ erpOrder.setExpress_name(order.getLogisticsCompany());
|
|
|
+ erpOrder.setExpress_code(order.getLId());
|
|
|
+
|
|
|
+ // 设置收件人信息
|
|
|
+// erpOrder.setReceiver_name(fsStoreOrder.getRealName());
|
|
|
+ erpOrder.setReceiver_name(fsStoreOrder.getRealName());
|
|
|
+ erpOrder.setReceiver_phone(fsStoreOrder.getUserPhone());
|
|
|
+ erpOrder.setReceiver_mobile(fsStoreOrder.getUserPhone());
|
|
|
+
|
|
|
+ // 构建完整地址
|
|
|
+ erpOrder.setReceiver_address(fsStoreOrder.getUserAddress());
|
|
|
+
|
|
|
+ // 如果是已发货
|
|
|
+ if(ObjectUtil.equal(order.getStatus(), ErpQueryOrderStatusEnum.SENT.getCode())){
|
|
|
+ List<ErpDeliverys> deliverysList = new ArrayList<>();
|
|
|
+
|
|
|
+ ErpDeliverys delivery = new ErpDeliverys();
|
|
|
+ delivery.setMail_no(order.getLId());
|
|
|
+ delivery.setExpress_code(order.getLcId());
|
|
|
+ delivery.setExpress_name(order.getLogisticsCompany());
|
|
|
+ delivery.setDelivery(true);
|
|
|
+ delivery.setCode(order.getSoId());
|
|
|
+
|
|
|
+ deliverysList.add(delivery);
|
|
|
+ erpOrder.setDeliverys(deliverysList);
|
|
|
+
|
|
|
+ // 设置发货状态,假设有物流单号就是已发货状态
|
|
|
+ erpOrder.setDelivery_state(1);
|
|
|
+ } else {
|
|
|
+ erpOrder.setDelivery_state(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ return erpOrder;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public BaseResponse refundUpdate(ErpRefundUpdateRequest param) {
|
|
|
|
|
|
FsStoreOrder fsStoreOrder = fsStoreOrderService.selectFsStoreOrderByOrderCode(param.getTid());
|
|
|
- //todo 待合并
|
|
|
-// FsStoreDelivers byOrderCode = fsStoreDeliversMapper.findByOrderCode(fsStoreOrder.getOrderCode());
|
|
|
- //todo
|
|
|
// 发货后退款
|
|
|
-// if(ObjectUtil.isNotNull(byOrderCode)){
|
|
|
+ if(ObjectUtils.equals(param.getOrderStatus(),2)){
|
|
|
+ FsJstAftersalePush fsJstAftersalePush = new FsJstAftersalePush();
|
|
|
+ fsJstAftersalePush.setOrderId(fsStoreOrder.getOrderCode());
|
|
|
+ fsJstAftersalePush.setTaskStatus(com.fs.hisStore.enums.TaskStatusEnum.PENDING.getCode());
|
|
|
+ fsJstAftersalePush.setType(String.valueOf(AfterSalesOrderStatusEnum.WAIT_SELLER_AGREE.getIndex()));
|
|
|
+ fsJstAftersalePush.setRetryCount(0);
|
|
|
+ fsJstAftersalePush.setAfterSaleId(String.valueOf(param.getStoreAfterSalesId()));
|
|
|
+ fsJstAftersalePushMapper.insert(fsJstAftersalePush);
|
|
|
|
|
|
-// } else {
|
|
|
+ } else {
|
|
|
// 如果是发货前退款,直接走取消订单流程
|
|
|
// 如果是发货后退款,走售后流程
|
|
|
OrderCancelRequestDTO requestDTO = new OrderCancelRequestDTO();
|
|
@@ -457,7 +581,7 @@ public class JSTErpOrderServiceImpl implements IErpOrderService {
|
|
|
requestDTO.setRemark("用户退款");
|
|
|
|
|
|
jstErpHttpService.cancel(requestDTO);
|
|
|
-// }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
BaseResponse baseResponse = new BaseResponse();
|
|
@@ -467,7 +591,7 @@ public class JSTErpOrderServiceImpl implements IErpOrderService {
|
|
|
}
|
|
|
|
|
|
@Autowired
|
|
|
- private FsJstAftersalePushMapper fsJstAftersalePushMapper;
|
|
|
+ private FsJstAftersalePushScrmMapper fsJstAftersalePushMapper;
|
|
|
|
|
|
@Override
|
|
|
public BaseResponse refundUpdateScrm(ErpRefundUpdateRequest param) {
|
|
@@ -475,7 +599,7 @@ public class JSTErpOrderServiceImpl implements IErpOrderService {
|
|
|
log.info("订单号: {},发货状态: {},是否发货后: {}",fsStoreOrder.getOrderCode(),fsStoreOrder.getStatus(),ObjectUtils.equals(fsStoreOrder.getStatus(),2));
|
|
|
|
|
|
// 发货后退款
|
|
|
- if(ObjectUtils.equals(fsStoreOrder.getStatus(),2)){
|
|
|
+ if(ObjectUtils.equals(param.getOrderStatus(),2)){
|
|
|
|
|
|
FsJstAftersalePush fsJstAftersalePush = new FsJstAftersalePush();
|
|
|
fsJstAftersalePush.setOrderId(fsStoreOrder.getOrderCode());
|
|
@@ -483,7 +607,7 @@ public class JSTErpOrderServiceImpl implements IErpOrderService {
|
|
|
fsJstAftersalePush.setType(String.valueOf(AfterSalesOrderStatusEnum.WAIT_SELLER_AGREE.getIndex()));
|
|
|
fsJstAftersalePush.setRetryCount(0);
|
|
|
fsJstAftersalePush.setAfterSaleId(String.valueOf(param.getStoreAfterSalesId()));
|
|
|
- fsJstAftersalePushMapper.insert(fsJstAftersalePush);
|
|
|
+ fsJstAftersalePushScrmMapper.insert(fsJstAftersalePush);
|
|
|
|
|
|
} else {
|
|
|
// 如果是发货前退款,直接走取消订单流程
|