|
@@ -1751,8 +1751,8 @@ public class GoodsServiceImpl implements GoodsService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public GoodsDetailsDto queryGoodsDetailsByProdBarcode(String prodBarcode, String storeId) {
|
|
|
|
- return goodsDao.queryGoodsDetailsByProdBarcode(prodBarcode,storeId);
|
|
|
|
|
|
+ public GoodsDetailsDto queryGoodsDetailsByProdBarcode(String prodBarcode, String storeId,String sku) {
|
|
|
|
+ return goodsDao.queryGoodsDetailsByProdBarcode(prodBarcode,storeId,sku);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1789,11 +1789,11 @@ public class GoodsServiceImpl implements GoodsService {
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
@Transactional
|
|
@Transactional
|
|
- public Map<String,Object> calculateGoodsDetail(String prodBarcode, String storeId) {
|
|
|
|
|
|
+ public Map<String,Object> calculateGoodsDetail(String prodBarcode, String storeId,String sku) {
|
|
/**
|
|
/**
|
|
* 1.首先根据商品条码跟门店id查询是否有库存,没库存直接返回
|
|
* 1.首先根据商品条码跟门店id查询是否有库存,没库存直接返回
|
|
*/
|
|
*/
|
|
- GoodsDetailsDto goods = queryGoodsDetailsByProdBarcode(prodBarcode,storeId);
|
|
|
|
|
|
+ GoodsDetailsDto goods = queryGoodsDetailsByProdBarcode(prodBarcode,storeId,sku);
|
|
if(goods == null) {
|
|
if(goods == null) {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
@@ -2060,6 +2060,293 @@ public class GoodsServiceImpl implements GoodsService {
|
|
return skuActivitiesMap;
|
|
return skuActivitiesMap;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public List<Map<String,Object>> selectSkuDetails(String prodBarcode, String storeId) {
|
|
|
|
+ /**
|
|
|
|
+ * 1.首先根据商品条码跟门店id查询是否有库存,没库存直接返回
|
|
|
|
+ */
|
|
|
|
+ List<GoodsDetailsDto> goodsList = goodsDao.queryGoodsSkuList(prodBarcode,storeId);
|
|
|
|
+ List<Map<String,Object>> mapList = new ArrayList<>();
|
|
|
|
+ if (goodsList == null) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ for(GoodsDetailsDto goods : goodsList){
|
|
|
|
+ mapList.add(selectGetSkuDetails(goods,prodBarcode,storeId));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return mapList;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Map<String,Object> selectGetSkuDetails(GoodsDetailsDto goods,String prodBarcode, String storeId) {
|
|
|
|
+ /**
|
|
|
|
+ * 1.首先根据商品条码跟门店id查询是否有库存,没库存直接返回
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+ goods.setDiscountedPrice(new BigDecimal(0));
|
|
|
|
+ BigDecimal retailPrice = goods.getRetailPrice();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ goods.setActualPaymentAmount(retailPrice.setScale(2,RoundingMode.HALF_UP));
|
|
|
|
+
|
|
|
|
+ Map<String,Object> skuActivitiesMap = new HashMap<>();
|
|
|
|
+
|
|
|
|
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 2.查询当前时间,该门店是否有活动,如果有活动,查询开启了哪些营销方式
|
|
|
|
+ * 参数: 当前时间 门店id
|
|
|
|
+ */
|
|
|
|
+ List<MkActivitiesEntity> mkActivitiesEntityList = mkActivitiesService.queryByNow(storeId,format.format(new Date()));
|
|
|
|
+
|
|
|
|
+ if(mkActivitiesEntityList == null || mkActivitiesEntityList.size() == 0){
|
|
|
|
+ // 计算税费
|
|
|
|
+ GoodsEntity goodsEntity = goodsDao.queryByBarcodeAndSku(prodBarcode, goods.getGoodsSn());
|
|
|
|
+ BigDecimal tax = CalculateTax.calculateFinalTax(goodsEntity,goods.getActualPaymentAmount(),this).setScale(3,RoundingMode.HALF_UP);
|
|
|
|
+ goods.setGoodstaxes(tax.toString());
|
|
|
|
+ skuActivitiesMap.put("goods",goods);
|
|
|
|
+ return skuActivitiesMap;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 遍历活动集合,查询有哪些活动是开启的
|
|
|
|
+ boolean daily = false,coupon = false,combinationPrice = false
|
|
|
|
+ ,discount = false,fullGift = false,fullReduction = false
|
|
|
|
+ ,getOneFree = false,promotion = false,halfPrice = false;
|
|
|
|
+
|
|
|
|
+ List<String> topicList = new ArrayList<>(); // 记录有哪些营销活动的topic
|
|
|
|
+ Map<String,String> mkaIdMap = new HashMap<>(); // 记录topic跟mkaId的关系
|
|
|
|
+ // 将所有的营销活动新增到list中
|
|
|
|
+ for(MkActivitiesEntity mkActivitiesEntity : mkActivitiesEntityList){
|
|
|
|
+ topicList.add(mkActivitiesEntity.getMkaTopic());
|
|
|
|
+ String mkaId = mkaIdMap.putIfAbsent(mkActivitiesEntity.getMkaTopic(), mkActivitiesEntity.getMkaId()+"");
|
|
|
|
+ if(StringUtils.isNotEmpty(mkaId)){
|
|
|
|
+// mkaId = "'"+mkaId + "','" + mkActivitiesEntity.getMkaId()+"'";
|
|
|
|
+ mkaId += String.format(",%s",mkActivitiesEntity.getMkaId());
|
|
|
|
+ mkaIdMap.put(mkActivitiesEntity.getMkaTopic(),mkaId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 判断有哪些营销活动
|
|
|
|
+ if(topicList.contains("zhjsp")) // 组合价
|
|
|
|
+ combinationPrice = true;
|
|
|
|
+ if(topicList.contains("dz")) // 打折
|
|
|
|
+ discount = true;
|
|
|
|
+ if(topicList.contains("mz")) //满赠
|
|
|
|
+ fullGift = true;
|
|
|
|
+ if(topicList.contains("mj")) // 满减
|
|
|
|
+ fullReduction = true;
|
|
|
|
+ if(topicList.contains("mysy")) // 买一送一
|
|
|
|
+ getOneFree = true;
|
|
|
|
+ if(topicList.contains("rchd")) // 日常活动
|
|
|
|
+ daily = true;
|
|
|
|
+ if(topicList.contains("yhq")) // 优惠券
|
|
|
|
+ coupon = true;
|
|
|
|
+ if(topicList.contains("lscx")) // 临时促销
|
|
|
|
+ promotion = true;
|
|
|
|
+ if(topicList.contains("drjbj"))
|
|
|
|
+ halfPrice = true;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 获取未优惠前的商品价格
|
|
|
|
+ retailPrice = goods.getRetailPrice();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 根据条码查询商品品牌名称 mall_brand mall_product_store_rela mall_goods
|
|
|
|
+ String brandName = goods.getBrand();
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 优先级:临时促销 》买一送一=满赠 》 组合价=日常活动 》 打折=满减 》 优惠券
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 组合价的做法就是将参与组合的条码带到收银端
|
|
|
|
+ * 现根据营销活动id跟条形码,查询有哪些参与该条码组合的商品
|
|
|
|
+ *
|
|
|
|
+ *
|
|
|
|
+ * TODO
|
|
|
|
+ */
|
|
|
|
+ if(combinationPrice){
|
|
|
|
+ String mkaId = mkaIdMap.get("zhjsp");
|
|
|
|
+ Map<String,Object> param = new HashMap<>();
|
|
|
|
+ param.put("mkaId",mkaId);
|
|
|
|
+ param.put("prodBarcode",prodBarcode);
|
|
|
|
+ List<MkActivitiesCombinationPriceEntity> combinationPriceList = combinationPriceService.queryList(param);
|
|
|
|
+ if(combinationPriceList != null && combinationPriceList.size() > 0) {
|
|
|
|
+ Map<String, List<MkActivitiesCombinationPriceEntity>> collect =
|
|
|
|
+ combinationPriceList.stream().collect(Collectors.groupingBy(MkActivitiesCombinationPriceEntity::getCombinationType));
|
|
|
|
+
|
|
|
|
+ skuActivitiesMap.put("zhjsp",collect);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ format = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
+ String nowTime = format.format(new Date());
|
|
|
|
+ /**
|
|
|
|
+ * 满减可能是跟着条码,也可能跟着品牌
|
|
|
|
+ * 根据商品品牌跟商品条码去查询是否有优惠金额
|
|
|
|
+ *
|
|
|
|
+ * 满足金额 购买商品条码 赠品条码
|
|
|
|
+ *
|
|
|
|
+ */
|
|
|
|
+ Map<String,Object> fullReductionMap = new HashMap<>();
|
|
|
|
+ if(fullReduction){
|
|
|
|
+ String mkaId = mkaIdMap.get("mj");
|
|
|
|
+ MkActivitiesFullReductionEntity fullReductionEntity = fullReductionService.queryByCodeOrBrand(mkaId,prodBarcode,brandName,nowTime);
|
|
|
|
+ if(fullReductionEntity != null) {
|
|
|
|
+ if(!StringUtils.isNullOrEmpty(fullReductionEntity.getProductBrand())){
|
|
|
|
+ // 跟着品牌走
|
|
|
|
+ fullReductionMap.put(brandName,fullReductionEntity);
|
|
|
|
+ }else{
|
|
|
|
+ // 跟着条码走
|
|
|
|
+ fullReductionMap.put(fullReductionEntity.getBarcode(), fullReductionEntity);
|
|
|
|
+ }
|
|
|
|
+ skuActivitiesMap.put("mj",fullReductionMap);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 满赠可能是跟着条码,也可能跟着品牌
|
|
|
|
+ * 根据商品品牌跟商品条码去查询是否有满赠
|
|
|
|
+ * 1.先扫买的商品,然后查询出赠送的商品条码
|
|
|
|
+ * 2.先扫赠的商品,然后查询出符合条件的商品条码或者品牌
|
|
|
|
+ * 满足的金额 购买的商品条码或者品牌 赠送的商品条码
|
|
|
|
+ * TODO
|
|
|
|
+ */
|
|
|
|
+ Map<String,Object> fullGiftMap = new HashMap<>();
|
|
|
|
+ if(fullGift){
|
|
|
|
+ String mkaId = mkaIdMap.get("mz");
|
|
|
|
+ MkActivitiesFullGiftEntity giftEntity = fullGiftService.queryByCodeOrBrand(mkaId,prodBarcode,brandName,nowTime);
|
|
|
|
+ if(giftEntity != null) {
|
|
|
|
+ if(giftEntity.getProductBrand() != null){
|
|
|
|
+ // 跟着品牌走
|
|
|
|
+ fullGiftMap.put(brandName,giftEntity);
|
|
|
|
+ }else{
|
|
|
|
+ // 跟着条码走
|
|
|
|
+ fullGiftMap.put(giftEntity.getBarcode(), giftEntity);
|
|
|
|
+ }
|
|
|
|
+ skuActivitiesMap.put("mz",fullGiftMap);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 买一送一可能是跟着条码,也可能跟着品牌
|
|
|
|
+ * 根据商品品牌跟商品条码去查询是否有送的商品
|
|
|
|
+ * 有两个场景
|
|
|
|
+ * 1.先扫买的商品,然后查询出赠送的商品条码
|
|
|
|
+ * 2.先扫赠的商品,然后查询出符合条件的商品条码或者品牌
|
|
|
|
+ * 所以就需要一个map
|
|
|
|
+ * key为购买的商品条码或者商品品牌 value为赠送的商品条码
|
|
|
|
+ * 但是品牌是根据条码查询的,所以最终map里面的结构是
|
|
|
|
+ * key 商品条码 value 赠品条码
|
|
|
|
+ */
|
|
|
|
+ if(getOneFree){
|
|
|
|
+ String mkaId = mkaIdMap.get("mysy");
|
|
|
|
+ MkActivitiesGetOneFreeGoodsEntity getOneFreeGoodsEntity = getOneFreeGoodsService.queryByCodeOrBrand(mkaId,prodBarcode,brandName);
|
|
|
|
+ if(getOneFreeGoodsEntity != null){
|
|
|
|
+ if("无".equals(getOneFreeGoodsEntity.getProductBrand())){
|
|
|
|
+ getOneFreeGoodsEntity.setBrand(false);
|
|
|
|
+ skuActivitiesMap.put("mysy",getOneFreeGoodsEntity);
|
|
|
|
+ }else{
|
|
|
|
+ getOneFreeGoodsEntity.setBrand(true);
|
|
|
|
+ skuActivitiesMap.put("mysy",getOneFreeGoodsEntity);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 第二份半价
|
|
|
|
+ if(halfPrice){
|
|
|
|
+ String mkaId = mkaIdMap.get("drjbj");
|
|
|
|
+ MkActivitiesHalfPriceEntity activitiesHalfPriceEntity = halfPriceService.queryByCodeOrBrand(mkaId,prodBarcode);
|
|
|
|
+ if(activitiesHalfPriceEntity != null){
|
|
|
|
+ skuActivitiesMap.put("drjbj",activitiesHalfPriceEntity);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // --------------------------------------------------------------------------------------
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 优惠券跟着条形码走,一般是设置一个标识,然后最后输入优惠券码后,减扣对应的标识,所以返回一个map数组
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+ if(coupon){
|
|
|
|
+ String mkaId = mkaIdMap.get("yhq");
|
|
|
|
+ MkActivitiesCouponEntity couponEntity = couponService.queryByBarCode(mkaId,prodBarcode,nowTime);
|
|
|
|
+ if(couponEntity != null){ // 优惠券码,优惠金额
|
|
|
|
+ Map<String,Object> returnMap = new HashMap<>();
|
|
|
|
+ returnMap.put(couponEntity.getCouponSn() , couponEntity.getCouponPrice());
|
|
|
|
+ skuActivitiesMap.put("yhq",returnMap);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 打折的价格是与条形码对应的,所以需要根据条形码和营销方式id去查询活动价格
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+ if(discount){
|
|
|
|
+ String mkaId = mkaIdMap.get("dz");
|
|
|
|
+ MkActivitiesDiscountEntity discountEntity = discountService.queryByBarCode(mkaId,prodBarcode);
|
|
|
|
+ // TODO 可能会直接替代产品价格
|
|
|
|
+ if (discountEntity != null) {
|
|
|
|
+ goods.setActualPaymentAmount(discountEntity.getActivityPrice());
|
|
|
|
+ goods.setRetailPrice(discountEntity.getActivityPrice());
|
|
|
|
+
|
|
|
|
+ goods.setActivity("打折");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 日常活动跟着条形码走,优先级比临时促销低,但是高于正常价格
|
|
|
|
+ */
|
|
|
|
+ if(daily){
|
|
|
|
+ String mkaId = mkaIdMap.get("rchd");
|
|
|
|
+ MkDailyActivitiesEntity dailyActivitiesEntity = dailyActivitiesService.queryByBarCode(mkaId,prodBarcode);
|
|
|
|
+ if(dailyActivitiesEntity != null){
|
|
|
|
+ goods.setActualPaymentAmount(dailyActivitiesEntity.getActivityPrice());
|
|
|
|
+ goods.setRetailPrice(dailyActivitiesEntity.getActivityPrice());
|
|
|
|
+
|
|
|
|
+ goods.setActivity("日常活动");
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 临时促销跟着条形码走,优先级应该最高,所以排到了最下面
|
|
|
|
+ */
|
|
|
|
+ if(promotion){
|
|
|
|
+ String mkaId = mkaIdMap.get("lscx");
|
|
|
|
+ MkActivitiesPromotionEntity promotionEntity = promotionService.queryByBarCode(mkaId,prodBarcode);
|
|
|
|
+ // 如果该商品存在临时促销,直接替换活动价格
|
|
|
|
+ if(promotionEntity != null){
|
|
|
|
+ goods.setActualPaymentAmount(promotionEntity.getActivityPrice());
|
|
|
|
+ goods.setRetailPrice(promotionEntity.getActivityPrice());
|
|
|
|
+
|
|
|
|
+ goods.setActivity("临时促销");
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 计算税费
|
|
|
|
+ GoodsEntity goodsEntity = goodsDao.queryByBarcodeAndSku(prodBarcode, goods.getGoodsSn());
|
|
|
|
+ BigDecimal tax = CalculateTax.calculateFinalTax(goodsEntity,goods.getActualPaymentAmount(),this).setScale(3,RoundingMode.HALF_UP);
|
|
|
|
+ goods.setGoodstaxes(tax.toString());
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ skuActivitiesMap.put("goods",goods);
|
|
|
|
+ return skuActivitiesMap;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 根据条形码查询商品
|
|
* 根据条形码查询商品
|
|
*
|
|
*
|