|
@@ -1,34 +1,24 @@
|
|
|
package com.caimei.modules.order.util;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
import com.caimei.modules.order.constant.Constant;
|
|
|
import com.caimei.modules.order.dao.*;
|
|
|
import com.caimei.modules.order.entity.*;
|
|
|
import com.caimei.modules.order.service.CmReturnedPurchaseService;
|
|
|
-import com.caimei.modules.order.service.impl.CmReturnedPurchaseServiceImpl;
|
|
|
-import com.caimei.utils.AppUtils;
|
|
|
-import com.caimei.utils.Disguiser;
|
|
|
-import com.caimei.utils.MathUtil;
|
|
|
-import com.caimei.utils.RedisService;
|
|
|
+import com.caimei.utils.*;
|
|
|
import com.caimei.utils.payUtil.MyBeanUtils;
|
|
|
import com.caimei.utils.payUtil.RSA;
|
|
|
import com.caimei.utils.payUtil.SettlePostFormUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import okhttp3.*;
|
|
|
-import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.io.IOException;
|
|
|
-import java.lang.reflect.Field;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -351,4 +341,55 @@ public class OrderUtils {
|
|
|
public List<OrderPayShopRecord> getPayRecords(NewOrder newOrder) {
|
|
|
return payShopDao.findPayShopRecordsByOrder(newOrder.getOrderId());
|
|
|
}
|
|
|
+
|
|
|
+ public Boolean setDeliverStatus(List<NewOrderProduct> orderProducts) {
|
|
|
+ AtomicReference<Boolean> flag = new AtomicReference<>(true);
|
|
|
+ String orderStatus = newOrderDao.findStatus(orderProducts.get(0).getOrderProductId());
|
|
|
+ if (orderStatus.length() < 2) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ Map<Integer, Integer> shops = new HashMap<>();
|
|
|
+ orderProducts.forEach(o -> {
|
|
|
+ boolean b = shops.containsKey(o.getShopOrderId());
|
|
|
+ if (b) {
|
|
|
+ Integer num = shops.get(o.getShopOrderId());
|
|
|
+ shops.put(o.getShopOrderId(), o.getDeliveryNum() + num);
|
|
|
+ } else {
|
|
|
+ shops.put(o.getShopOrderId(), o.getDeliveryNum());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (!flag.get()) {
|
|
|
+ return flag.get();
|
|
|
+ }
|
|
|
+ AtomicReference<Integer> orderId = new AtomicReference<>();
|
|
|
+ List<Integer> statusList = new ArrayList<>();
|
|
|
+ shops.forEach((key, value) -> {
|
|
|
+ NewShopOrder shopOrder = shopOrderDao.get(key);
|
|
|
+ Integer outStoreNum = shopOrder.getOutStoreNum();
|
|
|
+ int deliver = outStoreNum + value;
|
|
|
+ int total = shopOrder.getItemCount() + shopOrder.getPresentNum();
|
|
|
+ // 已发货+本次发货 > 子订单商品总数 + 赠品数
|
|
|
+ if (deliver > total) {
|
|
|
+ flag.set(false);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 2 部分发货 3全部发货
|
|
|
+ int status = deliver < total ? 2 : 3;
|
|
|
+ statusList.add(status);
|
|
|
+ shopOrder.setOutStoreNum(outStoreNum + value);
|
|
|
+ shopOrder.setSendOutStatus(Integer.toString(status));
|
|
|
+ shopOrder.setOutStoreTimes(shopOrder.getOutStoreTimes() + 1);
|
|
|
+ shopOrder.setPaying(0);
|
|
|
+ shopOrderDao.update(shopOrder);
|
|
|
+ orderId.set(shopOrder.getOrderId());
|
|
|
+ });
|
|
|
+ Integer orderDeliverStatus = 3;
|
|
|
+ if (statusList.contains(2)) {
|
|
|
+ orderDeliverStatus = 2;
|
|
|
+ }
|
|
|
+ orderStatus = orderStatus.substring(0, 1) + orderDeliverStatus.toString();
|
|
|
+ //同步更新主订单的发货状态
|
|
|
+ newOrderDao.updateOrderStatus(orderDeliverStatus, orderStatus,orderId.get());
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|