|
@@ -1750,43 +1750,59 @@ public class OrderServiceImpl implements OrderService {
|
|
|
|
|
|
// 检查库存和更新库存
|
|
|
for (LinkedHashMap goodsDto : goodsList) {
|
|
|
- //
|
|
|
- GoodsEntity goodsEntity = goodsDao.queryObjectByProdBarcodeAndStore((String) goodsDto.get("prodBarcode"),storeId);
|
|
|
- if (goodsEntity == null) {
|
|
|
- resultObj.put("errno", 400);
|
|
|
- resultObj.put("errmsg", "订单提交失败:商品不存在");
|
|
|
- return resultObj;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ // 要购买的数量
|
|
|
Integer sellVolume = (Integer)goodsDto.get("sellVolume");
|
|
|
|
|
|
- goodsDto.put("goodsId",goodsEntity.getId());
|
|
|
- goodsDto.put("goodsSn",goodsEntity.getGoodsSn());
|
|
|
- goodsDto.put("productId",goodsEntity.getProductId());
|
|
|
- goodsDto.put("storeMarketPrice",goodsEntity.getStoreMarketPrice());
|
|
|
-
|
|
|
- if(goodsDto.get("actualPaymentAmount") instanceof Double){
|
|
|
- goodsDto.put("storeRetailPrice",new BigDecimal((Double)goodsDto.get("actualPaymentAmount")));
|
|
|
- }else if(goodsDto.get("actualPaymentAmount") instanceof Integer){
|
|
|
- goodsDto.put("storeRetailPrice",new BigDecimal((Integer)goodsDto.get("actualPaymentAmount")));
|
|
|
- }else if(goodsDto.get("actualPaymentAmount") instanceof Float){
|
|
|
- goodsDto.put("storeRetailPrice",new BigDecimal((Float)goodsDto.get("actualPaymentAmount")));
|
|
|
+ Integer goodsSellNumber = (Integer)goodsDto.get("sellVolume");
|
|
|
+
|
|
|
+ String prodBarcode = (String) goodsDto.get("prodBarcode");
|
|
|
+
|
|
|
+ Map<GoodsEntity,Integer> numberMap = new HashMap<>();
|
|
|
+ List<GoodsEntity> queryGoodsList = goodsDao.queryListByBarcode(prodBarcode,storeId);
|
|
|
+ if(queryGoodsList != null && queryGoodsList.size() != 0) {
|
|
|
+ for (GoodsEntity goodsEntity : queryGoodsList) {
|
|
|
+ // 如果当前还有需要购买的
|
|
|
+ if (sellVolume > 0) {
|
|
|
+ // 当前商品剩余的数量
|
|
|
+ Integer remainAmount = goodsEntity.getGoodsNumber();
|
|
|
+ if (sellVolume >= remainAmount) {
|
|
|
+ // 证明该sku库存不足,需要继续向下个sku消费
|
|
|
+ sellVolume -= remainAmount;
|
|
|
+ // 记录该商品用了多少个数量
|
|
|
+ numberMap.put(goodsEntity, remainAmount);
|
|
|
+ } else {
|
|
|
+ // 记录该商品用了多少个数量
|
|
|
+ numberMap.put(goodsEntity, sellVolume);
|
|
|
+ sellVolume = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ if(sellVolume > 0){
|
|
|
+ resultObj.put("errno", 400);
|
|
|
+ resultObj.put("errmsg", "订单提交失败:条形码:"+prodBarcode+",电商门店库存不足");
|
|
|
+ return resultObj;
|
|
|
+ }
|
|
|
|
|
|
- //取得规格的信息,判断规格库存
|
|
|
- ProductStoreRelaEntity productInfo = productStoreRelaDao
|
|
|
- .queryByGoodsIdAndStoreId(Long.valueOf(storeId), Long.valueOf(goodsEntity.getId()));
|
|
|
- synchronized (productInfo) {
|
|
|
- if (null == productInfo || null == productInfo.getStockNum() ||
|
|
|
- productInfo.getStockNum() < (sellVolume)) {
|
|
|
- resultObj.put("errno", 400);
|
|
|
- resultObj.put("errmsg", "库存不足,仅剩余" + productInfo.getStockNum());
|
|
|
- return resultObj;
|
|
|
- } else {
|
|
|
- // 判断销售价是否低于底线价
|
|
|
+ Iterator<GoodsEntity> goodsIterator = numberMap.keySet().iterator();
|
|
|
+ // 循环购买的商品map,重新计算数量跟价格
|
|
|
+ while(goodsIterator.hasNext()){
|
|
|
+ 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(productInfo.getBottomLinePrice() != null){
|
|
|
// BigDecimal bottomLinePrice = new BigDecimal(productInfo.getBottomLinePrice());
|
|
|
// if (goodsEntity.getStoreRetailPrice().compareTo(bottomLinePrice) <= -1) {
|
|
@@ -1807,77 +1823,94 @@ public class OrderServiceImpl implements OrderService {
|
|
|
// return resultObj;
|
|
|
// }
|
|
|
// }
|
|
|
+ productInfo.setStockNum(productInfo.getStockNum() - num);
|
|
|
+ productInfo.setStoreId(Long.valueOf(storeId));
|
|
|
+ productInfo.setSellVolume(productInfo.getSellVolume() + num);
|
|
|
+// productInfo.addSellVolume();
|
|
|
+ productInfo.setLastSaleTime(new Date());
|
|
|
+ productStoreRelaDao.updateStockNum(productInfo);//修改普通商品库存
|
|
|
+
|
|
|
+ if(goodsEntity != null) {
|
|
|
+ goodsEntity.setGoodsNumber(goodsEntity.getGoodsNumber() - num);
|
|
|
+ goodsEntity.setLastSaleTime(new Date());
|
|
|
+ goodsDao.update(goodsEntity);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- productInfo.setStockNum(productInfo.getStockNum() - sellVolume);
|
|
|
- productInfo.setStoreId(Long.valueOf(storeId));
|
|
|
- productInfo.addSellVolume();
|
|
|
- productInfo.setLastSaleTime(new Date());
|
|
|
- productStoreRelaDao.updateStockNum(productInfo);//修改普通商品库存
|
|
|
+ BigDecimal retailPrice = new BigDecimal(0);
|
|
|
+ BigDecimal storeRetailPrice = new BigDecimal(0);
|
|
|
+ if(goodsDto.get("retailPrice") instanceof Double){
|
|
|
|
|
|
- if(goodsEntity != null) {
|
|
|
- goodsEntity.setGoodsNumber(goodsEntity.getGoodsNumber() - sellVolume);
|
|
|
- goodsEntity.setLastSaleTime(new Date());
|
|
|
- goodsDao.update(goodsEntity);
|
|
|
+ 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);
|
|
|
|
|
|
|
|
|
- if(goodsDto.get("retailPrice") instanceof Double){
|
|
|
- goodsEntity.setRetailPrice(new BigDecimal((Double)goodsDto.get("retailPrice"))); // 单价
|
|
|
- }else if(goodsDto.get("retailPrice") instanceof Integer){
|
|
|
- goodsEntity.setRetailPrice(new BigDecimal((Integer)goodsDto.get("retailPrice")));
|
|
|
- }else if(goodsDto.get("retailPrice") instanceof Float){
|
|
|
- goodsEntity.setRetailPrice(new BigDecimal((Float)goodsDto.get("retailPrice")));
|
|
|
- }
|
|
|
- if(goodsDto.get("discountedPrice") instanceof Double){
|
|
|
- goodsEntity.setDiscountedPrice(new BigDecimal((Double)goodsDto.get("discountedPrice"))); // 优惠金额
|
|
|
- }else if(goodsDto.get("discountedPrice") instanceof Integer){
|
|
|
- goodsEntity.setDiscountedPrice(new BigDecimal((Integer)goodsDto.get("discountedPrice")));
|
|
|
- }else if(goodsDto.get("discountedPrice") instanceof Float){
|
|
|
- goodsEntity.setDiscountedPrice(new BigDecimal((Float)goodsDto.get("discountedPrice")));
|
|
|
- }
|
|
|
- if(goodsDto.get("actualPaymentAmount") instanceof Double){
|
|
|
- goodsEntity.setActualPaymentAmount(new BigDecimal((Double)goodsDto.get("actualPaymentAmount"))); // 实际支付价格
|
|
|
- }else if(goodsDto.get("actualPaymentAmount") instanceof Integer){
|
|
|
- goodsEntity.setActualPaymentAmount(new BigDecimal((Integer)goodsDto.get("actualPaymentAmount")));
|
|
|
- }else if(goodsDto.get("actualPaymentAmount") instanceof Float){
|
|
|
- goodsEntity.setActualPaymentAmount(new BigDecimal((Float)goodsDto.get("actualPaymentAmount")));
|
|
|
- }
|
|
|
+ goodsEntity.setRetailPrice(retailPrice);
|
|
|
+ goodsEntity.setStoreRetailPrice(storeRetailPrice);
|
|
|
+ goodsEntity.setDiscountedPrice(disCountedPrice);
|
|
|
+ goodsEntity.setActualPaymentAmount(actualPaymentAmount);
|
|
|
|
|
|
|
|
|
- Object taxObject = goodsDto.get("goodstaxes");
|
|
|
- BigDecimal tax = new BigDecimal(0);
|
|
|
- if(taxObject instanceof Double){
|
|
|
- tax = new BigDecimal((Double) taxObject);
|
|
|
- }else if(taxObject instanceof Integer){
|
|
|
- tax = new BigDecimal((Integer) taxObject);
|
|
|
- }else if(taxObject instanceof Float){
|
|
|
- tax = new BigDecimal((Float) taxObject);
|
|
|
- }else if(taxObject instanceof String){
|
|
|
- tax = new BigDecimal((String) taxObject) ;
|
|
|
- }
|
|
|
- totalTax = totalTax.add(tax).setScale(2,BigDecimal.ROUND_HALF_DOWN); // 计算总的税额
|
|
|
-
|
|
|
- if(goodsDto.get("retailPrice") instanceof Double){
|
|
|
- goodsEntity.setStoreRetailPrice(new BigDecimal((Double)goodsDto.get("retailPrice"))); // 单价
|
|
|
- }else if(goodsDto.get("retailPrice") instanceof Integer){
|
|
|
- goodsEntity.setStoreRetailPrice(new BigDecimal((Integer)goodsDto.get("retailPrice")));
|
|
|
- }else if(goodsDto.get("retailPrice") instanceof Float){
|
|
|
- goodsEntity.setStoreRetailPrice(new BigDecimal((Float)goodsDto.get("retailPrice")));
|
|
|
- }
|
|
|
|
|
|
+ // 借用这个字段来存储购买数
|
|
|
+ goodsEntity.setGoodsNumber(num);
|
|
|
+ goodsEntity.setActivity((String) goodsDto.get("activity"));
|
|
|
+ goodsEntities.add(goodsEntity);
|
|
|
+ }
|
|
|
|
|
|
-// goodsEntity.setStoreRetailPrice(productInfo.getRetailPrice());
|
|
|
- // 借用这个字段来存储购买数
|
|
|
- goodsEntity.setGoodsNumber(sellVolume);
|
|
|
|
|
|
- goodsEntity.setActivity((String) goodsDto.get("activity"));
|
|
|
+ }
|
|
|
|
|
|
- goodsEntities.add(goodsEntity);
|
|
|
+ // 计算该购物车所需要的所有税费
|
|
|
+ Object taxObject = goodsDto.get("goodstaxes");
|
|
|
+ BigDecimal tax = new BigDecimal(0);
|
|
|
+ if(taxObject instanceof Double){
|
|
|
+ tax = new BigDecimal((Double) taxObject);
|
|
|
+ }else if(taxObject instanceof Integer){
|
|
|
+ tax = new BigDecimal((Integer) taxObject);
|
|
|
+ }else if(taxObject instanceof Float){
|
|
|
+ tax = new BigDecimal((Float) taxObject);
|
|
|
+ }else if(taxObject instanceof String){
|
|
|
+ tax = new BigDecimal((String) taxObject) ;
|
|
|
}
|
|
|
+ totalTax = totalTax.add(tax).setScale(2,BigDecimal.ROUND_HALF_DOWN); // 计算总的税额
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|