|
@@ -54,6 +54,7 @@ import com.kmall.manager.manager.alipay.AliPayMicropayApiResult;
|
|
|
import com.kmall.manager.manager.alipay.AliPayRequestParams;
|
|
|
import com.kmall.manager.manager.alipay.AliPayUtil;
|
|
|
import com.kmall.manager.manager.express.kdn.KdniaoUtil;
|
|
|
+import com.kmall.manager.manager.express.sf.ServiceException;
|
|
|
import com.kmall.manager.manager.express.sf.entity.RouteEntity;
|
|
|
import com.kmall.manager.manager.express.sf.entity.RouteResponseEntity;
|
|
|
import com.kmall.manager.manager.express.sf.entity.SfRouteServiceResponseEntity;
|
|
@@ -73,6 +74,7 @@ import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
@@ -1645,6 +1647,7 @@ public class OrderServiceImpl implements OrderService {
|
|
|
public Boolean restore(String orderSns) {
|
|
|
|
|
|
if (org.springframework.util.StringUtils.isEmpty(orderSns)) {
|
|
|
+ LOGGER.error("还原查验单库存,订单编号为空!");
|
|
|
return false;
|
|
|
}
|
|
|
List<String> orderIdStrList = new ArrayList<>();
|
|
@@ -1657,6 +1660,14 @@ public class OrderServiceImpl implements OrderService {
|
|
|
List<Integer> orderIdList = orderIdStrList.parallelStream().map(Integer::valueOf).collect(Collectors.toList());
|
|
|
// 查询订单详细信息
|
|
|
List<OrderGoodsRestoreVo> orderGoodsRestoreVos = orderGoodsService.queryListByOrderIds(orderIdList);
|
|
|
+ List<String> orderSnList = orderGoodsRestoreVos.stream().map(OrderGoodsRestoreVo::getOrderSn).collect(Collectors.toList());
|
|
|
+ // 查询记录表, 不能还原多次
|
|
|
+ List<String> snList = newRetailOrderRestoreStockRecordService.queryListByOrderSnList(orderSnList);
|
|
|
+ // 不为空则说明有订单已经被还原过, 返回失败
|
|
|
+ if (!CollectionUtils.isEmpty(snList)) {
|
|
|
+ LOGGER.error(String.format("订单【%s】已经还原过库存,不可继续还原!", snList));
|
|
|
+ throw new RRException(String.format("订单【%s】已经还原过库存,不可继续还原!", snList));
|
|
|
+ }
|
|
|
|
|
|
// 需要更新门店商品库存(mall_product_store_rela)和园区库存(mall_goods)
|
|
|
// 园区库存, 无门店概念
|
|
@@ -1673,11 +1684,14 @@ public class OrderServiceImpl implements OrderService {
|
|
|
goodsService.restoreBatch(goodsEntities);
|
|
|
// 还原门店库存
|
|
|
productStoreRelaService.restoreBatch(productStoreRelaEntities);
|
|
|
-
|
|
|
+ LOGGER.info("还原【{}】查验订单库存成功!", orderSnList);
|
|
|
+ // 查验完成的单已经转成保税备货,800放行后不会通知到kmall,所以需要将状态修改为已发货
|
|
|
+ orderDao.updateOrderStatusByOrderSnList(orderSnList);
|
|
|
+ LOGGER.info("更新【{}】查验订单状态为已发货成功!", orderSnList);
|
|
|
// 添加还原记录
|
|
|
List<NewRetailOrderRestoreStockRecordEntity> stockRecordEntityList = orderGoodsRestoreVos.stream().map(this::wrapRestoreRecord).collect(Collectors.toList());
|
|
|
newRetailOrderRestoreStockRecordService.saveBatch(stockRecordEntityList);
|
|
|
-
|
|
|
+ LOGGER.info("新增【{}】查验订单还原记录成功!", orderSnList);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -2012,6 +2026,7 @@ public class OrderServiceImpl implements OrderService {
|
|
|
String prodBarcode = (String) goodsDto.get("prodBarcode");
|
|
|
|
|
|
Map<GoodsEntity, Integer> numberMap = new HashMap<>();
|
|
|
+ // 根据商品条码和门店id查找,
|
|
|
List<GoodsEntity> queryGoodsList = goodsDao.queryListByBarcode(prodBarcode, storeId);
|
|
|
if (queryGoodsList != null && queryGoodsList.size() != 0) {
|
|
|
for (GoodsEntity goodsEntity : queryGoodsList) {
|
|
@@ -2033,12 +2048,11 @@ public class OrderServiceImpl implements OrderService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 园区库存是有问题的, 这里去掉校验极端情况下可能会导致园区库存为负数
|
|
|
-// if (sellVolume > 0) {
|
|
|
-// resultObj.put("errno", 400);
|
|
|
-// resultObj.put("errmsg", "订单提交失败:条形码:" + prodBarcode + ",电商门店库存不足");
|
|
|
-// return resultObj;
|
|
|
-// }
|
|
|
+ if (sellVolume > 0) {
|
|
|
+ resultObj.put("errno", 400);
|
|
|
+ resultObj.put("errmsg", "订单提交失败:条形码:" + prodBarcode + ",电商门店库存不足");
|
|
|
+ return resultObj;
|
|
|
+ }
|
|
|
|
|
|
Iterator<GoodsEntity> goodsIterator = numberMap.keySet().iterator();
|
|
|
// 循环购买的商品map,重新计算数量跟价格
|
|
@@ -2046,16 +2060,17 @@ public class OrderServiceImpl implements OrderService {
|
|
|
GoodsEntity goodsEntity = goodsIterator.next();
|
|
|
// 该商品购买数量
|
|
|
Integer num = numberMap.get(goodsEntity);
|
|
|
- //取得规格的信息,判断规格库存
|
|
|
+ // 取得规格的信息,判断规格库存,门店库存
|
|
|
ProductStoreRelaEntity productInfo = productStoreRelaDao
|
|
|
.queryByGoodsIdAndStoreId(Long.valueOf(storeId), Long.valueOf(goodsEntity.getId()));
|
|
|
+ // 判断园区库存
|
|
|
synchronized (productInfo) {
|
|
|
- if (null == productInfo || null == productInfo.getStockNum() ||
|
|
|
- productInfo.getStockNum() < (num)) {
|
|
|
- resultObj.put("errno", 400);
|
|
|
- resultObj.put("errmsg", "条形码:" + prodBarcode + ",电商门店库存不足,仅剩余" + productInfo.getStockNum());
|
|
|
- return resultObj;
|
|
|
- } else {
|
|
|
+// if (null == productInfo || null == productInfo.getStockNum() ||
|
|
|
+// productInfo.getStockNum() < (num)) {
|
|
|
+// resultObj.put("errno", 400);
|
|
|
+// resultObj.put("errmsg", "条形码:" + prodBarcode + ",电商门店库存不足,仅剩余" + productInfo.getStockNum());
|
|
|
+// return resultObj;
|
|
|
+// } else {
|
|
|
// 判断销售价是否低于底线价
|
|
|
// if(productInfo.getBottomLinePrice() != null){
|
|
|
// BigDecimal bottomLinePrice = new BigDecimal(productInfo.getBottomLinePrice());
|
|
@@ -2077,108 +2092,105 @@ public class OrderServiceImpl implements OrderService {
|
|
|
// return resultObj;
|
|
|
// }
|
|
|
// }
|
|
|
- StoreMngChangeEntity storeMngChangeEntity = new StoreMngChangeEntity();
|
|
|
- storeMngChangeEntity.setChangeType(Dict.changeType.item_1.getItem());
|
|
|
- storeMngChangeEntity.setChangeReason("商品销售扣减");
|
|
|
- storeMngChangeEntity.setGoodsId(Integer.parseInt(String.valueOf(productInfo.getGoodsId())));
|
|
|
- storeMngChangeEntity.setStoreId(Integer.parseInt(String.valueOf(productInfo.getStoreId())));
|
|
|
- storeMngChangeEntity.setMerchSn(productInfo.getMerchSn());
|
|
|
- storeMngChangeEntity.setStoreChangeNum(num);
|
|
|
- storeMngChangeEntity.setStoreOriginalNum(productInfo.getStockNum());
|
|
|
- storeMngChangeEntity.setStoreValidNum(productInfo.getStockNum() - num);
|
|
|
- storeMngChangeEntity.setCreateTime(new Date());
|
|
|
- storeMngChangeEntity.setModTime(new Date());
|
|
|
- storeMngChangeEntity.setCreaterSn(user.getUsername());
|
|
|
- storeMngChangeEntity.setModerSn(user.getUsername());
|
|
|
- storeMngChangeEntity.setIsValid(0);
|
|
|
- storeMngChangeDao.save(storeMngChangeEntity);
|
|
|
-
|
|
|
-
|
|
|
- productInfo.setStockNum(productInfo.getStockNum() - num);
|
|
|
- productInfo.setStoreId(Long.valueOf(storeId));
|
|
|
- productInfo.setSellVolume(productInfo.getSellVolume() + num);
|
|
|
- productInfo.setLastSaleTime(new Date());
|
|
|
- productStoreRelaDao.updateStockNum(productInfo);//修改普通商品库存
|
|
|
-
|
|
|
- if (goodsEntity != null) {
|
|
|
- MngChangeEntity mngChangeEntity = new MngChangeEntity();
|
|
|
- mngChangeEntity.setThirdPartyMerchCode(goodsEntity.getThirdPartyMerchCode());
|
|
|
- mngChangeEntity.setChangeReason("商品销售扣减");
|
|
|
- mngChangeEntity.setCreateTime(new Date());
|
|
|
- mngChangeEntity.setModTime(new Date());
|
|
|
- mngChangeEntity.setCreaterSn(user.getUsername());
|
|
|
- mngChangeEntity.setModerSn(user.getUsername());
|
|
|
- mngChangeEntity.setIsValid(0);
|
|
|
- mngChangeEntity.setMerchSn(goodsEntity.getMerchSn());
|
|
|
- mngChangeEntity.setOriginalNum(goodsEntity.getGoodsNumber());//原库存数
|
|
|
- mngChangeEntity.setValidNum(goodsEntity.getGoodsNumber() - num);//可用数
|
|
|
- mngChangeEntity.setChangeNum(num);//变化数
|
|
|
- mngChangeEntity.setChangeType(Dict.changeType.item_1.getItem());
|
|
|
- mngChangeEntity.setGoodsId(Integer.parseInt(String.valueOf(goodsEntity.getId())));
|
|
|
-
|
|
|
- mngChangeDao.save(mngChangeEntity);
|
|
|
- goodsEntity.setGoodsNumber(goodsEntity.getGoodsNumber() - num);
|
|
|
+ StoreMngChangeEntity storeMngChangeEntity = new StoreMngChangeEntity();
|
|
|
+ storeMngChangeEntity.setChangeType(Dict.changeType.item_1.getItem());
|
|
|
+ storeMngChangeEntity.setChangeReason("商品销售扣减");
|
|
|
+ storeMngChangeEntity.setGoodsId(Integer.parseInt(String.valueOf(productInfo.getGoodsId())));
|
|
|
+ storeMngChangeEntity.setStoreId(Integer.parseInt(String.valueOf(productInfo.getStoreId())));
|
|
|
+ storeMngChangeEntity.setMerchSn(productInfo.getMerchSn());
|
|
|
+ storeMngChangeEntity.setStoreChangeNum(num);
|
|
|
+ storeMngChangeEntity.setStoreOriginalNum(productInfo.getStockNum());
|
|
|
+ storeMngChangeEntity.setStoreValidNum(productInfo.getStockNum() - num);
|
|
|
+ storeMngChangeEntity.setCreateTime(new Date());
|
|
|
+ storeMngChangeEntity.setModTime(new Date());
|
|
|
+ storeMngChangeEntity.setCreaterSn(user.getUsername());
|
|
|
+ storeMngChangeEntity.setModerSn(user.getUsername());
|
|
|
+ storeMngChangeEntity.setIsValid(0);
|
|
|
+ storeMngChangeDao.save(storeMngChangeEntity);
|
|
|
+
|
|
|
+ productInfo.setStockNum(productInfo.getStockNum() - num);
|
|
|
+ productInfo.setStoreId(Long.valueOf(storeId));
|
|
|
+ productInfo.setSellVolume(productInfo.getSellVolume() + num);
|
|
|
+ productInfo.setLastSaleTime(new Date());
|
|
|
+ productStoreRelaDao.updateStockNum(productInfo);//修改普通商品库存
|
|
|
+
|
|
|
+ if (goodsEntity != null) {
|
|
|
+ int diff = goodsEntity.getGoodsNumber() - num;
|
|
|
+ MngChangeEntity mngChangeEntity = new MngChangeEntity();
|
|
|
+ mngChangeEntity.setThirdPartyMerchCode(goodsEntity.getThirdPartyMerchCode());
|
|
|
+ mngChangeEntity.setChangeReason("商品销售扣减");
|
|
|
+ mngChangeEntity.setCreateTime(new Date());
|
|
|
+ mngChangeEntity.setModTime(new Date());
|
|
|
+ mngChangeEntity.setCreaterSn(user.getUsername());
|
|
|
+ mngChangeEntity.setModerSn(user.getUsername());
|
|
|
+ mngChangeEntity.setIsValid(0);
|
|
|
+ mngChangeEntity.setMerchSn(goodsEntity.getMerchSn());
|
|
|
+ mngChangeEntity.setOriginalNum(goodsEntity.getGoodsNumber());//原库存数
|
|
|
+ mngChangeEntity.setValidNum(diff);//可用数
|
|
|
+ mngChangeEntity.setChangeNum(num);//变化数
|
|
|
+ mngChangeEntity.setChangeType(Dict.changeType.item_1.getItem());
|
|
|
+ mngChangeEntity.setGoodsId(Integer.parseInt(String.valueOf(goodsEntity.getId())));
|
|
|
+
|
|
|
+ mngChangeDao.save(mngChangeEntity);
|
|
|
+ // 如果园区库存数量小于等于0, 则不更新园区库存, 园区库存只做参考
|
|
|
+ if (diff >= 0) {
|
|
|
+ goodsEntity.setGoodsNumber(diff);
|
|
|
goodsEntity.setLastSaleTime(new Date());
|
|
|
goodsDao.update(goodsEntity);
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
- BigDecimal retailPrice = new BigDecimal(0);
|
|
|
- BigDecimal storeRetailPrice = new BigDecimal(0);
|
|
|
- if (goodsDto.get("retailPrice") instanceof Double) {
|
|
|
-
|
|
|
- retailPrice = new BigDecimal((Double) goodsDto.get("retailPrice")); // 单价
|
|
|
- storeRetailPrice = new BigDecimal((Double) goodsDto.get("retailPrice")); // 单价
|
|
|
- } else if (goodsDto.get("retailPrice") instanceof Integer) {
|
|
|
- retailPrice = new BigDecimal((Integer) goodsDto.get("retailPrice"));
|
|
|
- storeRetailPrice = new BigDecimal((Integer) goodsDto.get("retailPrice"));
|
|
|
- } else if (goodsDto.get("retailPrice") instanceof Float) {
|
|
|
- retailPrice = new BigDecimal((Float) goodsDto.get("retailPrice"));
|
|
|
- storeRetailPrice = new BigDecimal((Float) goodsDto.get("retailPrice"));
|
|
|
- }
|
|
|
-
|
|
|
- BigDecimal disCountedPrice = new BigDecimal(0);
|
|
|
- BigDecimal actualPaymentAmount = new BigDecimal(0);
|
|
|
-
|
|
|
- if (goodsDto.get("discountedPrice") instanceof Double) {
|
|
|
- disCountedPrice = new BigDecimal((Double) goodsDto.get("discountedPrice")); // 优惠金额
|
|
|
- } else if (goodsDto.get("discountedPrice") instanceof Integer) {
|
|
|
- disCountedPrice = new BigDecimal((Integer) goodsDto.get("discountedPrice"));
|
|
|
- } else if (goodsDto.get("discountedPrice") instanceof Float) {
|
|
|
- disCountedPrice = new BigDecimal((Float) goodsDto.get("discountedPrice"));
|
|
|
- }
|
|
|
- if (goodsDto.get("actualPaymentAmount") instanceof Double) {
|
|
|
- actualPaymentAmount = new BigDecimal((Double) goodsDto.get("actualPaymentAmount")); // 实际支付价格
|
|
|
- } else if (goodsDto.get("actualPaymentAmount") instanceof Integer) {
|
|
|
- actualPaymentAmount = new BigDecimal((Integer) goodsDto.get("actualPaymentAmount"));
|
|
|
- } else if (goodsDto.get("actualPaymentAmount") instanceof Float) {
|
|
|
- actualPaymentAmount = new BigDecimal((Float) goodsDto.get("actualPaymentAmount"));
|
|
|
- }
|
|
|
- disCountedPrice = disCountedPrice
|
|
|
- .divide(new BigDecimal(goodsSellNumber), 3, RoundingMode.HALF_UP)
|
|
|
- .multiply(new BigDecimal(num))
|
|
|
- .setScale(2, RoundingMode.HALF_UP);
|
|
|
- actualPaymentAmount = actualPaymentAmount
|
|
|
- .divide(new BigDecimal(goodsSellNumber), 3, RoundingMode.HALF_UP)
|
|
|
- .multiply(new BigDecimal(num))
|
|
|
- .setScale(2, RoundingMode.HALF_UP);
|
|
|
-
|
|
|
-
|
|
|
- goodsEntity.setRetailPrice(retailPrice);
|
|
|
- goodsEntity.setStoreRetailPrice(storeRetailPrice);
|
|
|
- goodsEntity.setDiscountedPrice(disCountedPrice);
|
|
|
- goodsEntity.setActualPaymentAmount(actualPaymentAmount);
|
|
|
-
|
|
|
- // 借用这个字段来存储购买数
|
|
|
- goodsEntity.setGoodsNumber(num);
|
|
|
- goodsEntity.setActivity((String) goodsDto.get("activity"));
|
|
|
- goodsEntities.add(goodsEntity);
|
|
|
+ BigDecimal retailPrice = new BigDecimal(0);
|
|
|
+ BigDecimal storeRetailPrice = new BigDecimal(0);
|
|
|
+ if (goodsDto.get("retailPrice") instanceof Double) {
|
|
|
+
|
|
|
+ retailPrice = new BigDecimal((Double) goodsDto.get("retailPrice")); // 单价
|
|
|
+ storeRetailPrice = new BigDecimal((Double) goodsDto.get("retailPrice")); // 单价
|
|
|
+ } else if (goodsDto.get("retailPrice") instanceof Integer) {
|
|
|
+ retailPrice = new BigDecimal((Integer) goodsDto.get("retailPrice"));
|
|
|
+ storeRetailPrice = new BigDecimal((Integer) goodsDto.get("retailPrice"));
|
|
|
+ } else if (goodsDto.get("retailPrice") instanceof Float) {
|
|
|
+ retailPrice = new BigDecimal((Float) goodsDto.get("retailPrice"));
|
|
|
+ storeRetailPrice = new BigDecimal((Float) goodsDto.get("retailPrice"));
|
|
|
}
|
|
|
|
|
|
+ BigDecimal disCountedPrice = new BigDecimal(0);
|
|
|
+ BigDecimal actualPaymentAmount = new BigDecimal(0);
|
|
|
|
|
|
+ if (goodsDto.get("discountedPrice") instanceof Double) {
|
|
|
+ disCountedPrice = new BigDecimal((Double) goodsDto.get("discountedPrice")); // 优惠金额
|
|
|
+ } else if (goodsDto.get("discountedPrice") instanceof Integer) {
|
|
|
+ disCountedPrice = new BigDecimal((Integer) goodsDto.get("discountedPrice"));
|
|
|
+ } else if (goodsDto.get("discountedPrice") instanceof Float) {
|
|
|
+ disCountedPrice = new BigDecimal((Float) goodsDto.get("discountedPrice"));
|
|
|
+ }
|
|
|
+ if (goodsDto.get("actualPaymentAmount") instanceof Double) {
|
|
|
+ actualPaymentAmount = new BigDecimal((Double) goodsDto.get("actualPaymentAmount")); // 实际支付价格
|
|
|
+ } else if (goodsDto.get("actualPaymentAmount") instanceof Integer) {
|
|
|
+ actualPaymentAmount = new BigDecimal((Integer) goodsDto.get("actualPaymentAmount"));
|
|
|
+ } else if (goodsDto.get("actualPaymentAmount") instanceof Float) {
|
|
|
+ actualPaymentAmount = new BigDecimal((Float) goodsDto.get("actualPaymentAmount"));
|
|
|
+ }
|
|
|
+ disCountedPrice = disCountedPrice
|
|
|
+ .divide(new BigDecimal(goodsSellNumber), 3, RoundingMode.HALF_UP)
|
|
|
+ .multiply(new BigDecimal(num))
|
|
|
+ .setScale(2, RoundingMode.HALF_UP);
|
|
|
+ actualPaymentAmount = actualPaymentAmount
|
|
|
+ .divide(new BigDecimal(goodsSellNumber), 3, RoundingMode.HALF_UP)
|
|
|
+ .multiply(new BigDecimal(num))
|
|
|
+ .setScale(2, RoundingMode.HALF_UP);
|
|
|
+
|
|
|
+
|
|
|
+ goodsEntity.setRetailPrice(retailPrice);
|
|
|
+ goodsEntity.setStoreRetailPrice(storeRetailPrice);
|
|
|
+ goodsEntity.setDiscountedPrice(disCountedPrice);
|
|
|
+ goodsEntity.setActualPaymentAmount(actualPaymentAmount);
|
|
|
+
|
|
|
+ // 借用这个字段来存储购买数
|
|
|
+ goodsEntity.setGoodsNumber(num);
|
|
|
+ goodsEntity.setActivity((String) goodsDto.get("activity"));
|
|
|
+ goodsEntities.add(goodsEntity);
|
|
|
}
|
|
|
|
|
|
// 计算该购物车所需要的所有税费
|