Commit 372045a6 by 孙昱

Merge branch 'qa' of gitlab.freemud.com:order-group-application/order-group into qa

parents 79150162 f2e2fc71
package cn.freemud.entities.dto;
import lombok.Data;
/**
* All rights Reserved, Designed By www.freemud.cn
*
* @version V1.0
* @Title: OpenPlatformPartnerWxappConfig
* @Package cn.freemud.entities.dto
* @Description:
* @author: ping1.wu
* @date: 2020/9/15 15:59
* @Copyright: 2020 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
@Data
public class OpenPlatformPartnerWxappConfig {
private String wxAppid;
private String appKey;
private String appValue;
private Integer state;
}
......@@ -39,6 +39,7 @@ import cn.freemud.service.impl.calculate.CalculationSharingCartService;
import cn.freemud.service.impl.calculate.CalculationSharingDiscountService;
import cn.freemud.service.impl.calculate.CalculationSharingEquallyService;
import cn.freemud.service.thirdparty.*;
import cn.freemud.utils.BeanUtil;
import cn.freemud.utils.PromotionFactory;
import cn.freemud.utils.PropertyConvertUtil;
import cn.freemud.utils.ResponseUtil;
......@@ -75,8 +76,6 @@ import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.BoundHashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import java.awt.geom.Point2D;
......@@ -149,6 +148,11 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
private ProductService productService;
@Autowired
private ActivityService activityService;
@Autowired
private RedisCache redisCache;
private static final String limitCartKey = "ecology:kgd:wxappconfig:open_platform_partner_wxapp_config:appkey_";
@Autowired
private CalculationSharingDiscountService sharingDiscountService;
......@@ -247,6 +251,7 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
String menuType = addShoppingCartGoodsRequestVo.getMenuType();
Integer orderType = addShoppingCartGoodsRequestVo.getOrderType();
String receiveId = addShoppingCartGoodsRequestVo.getReceiveId();
String tableNumber = addShoppingCartGoodsRequestVo.getTableNumber();
CartGoods cartGoods = ShoppingCartConvertAdapter.convent2CartGoods(addShoppingCartGoodsRequestVo);
List<Long> productIds = new ArrayList<>();
......@@ -268,13 +273,14 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
if (CollectionUtils.isEmpty(allCartGoodsList)) {
allCartGoodsList = new ArrayList<>();
}
List<CartGoods> oldCartGoodsList = BeanUtil.convertBeans(allCartGoodsList, CartGoods::new);
/**
Integer checkQty = allCartGoodsList.indexOf(cartGoods) != -1 ?
allCartGoodsList.get(allCartGoodsList.indexOf(cartGoods)).getQty() + cartGoods.getQty() : cartGoods.getQty();
*/
Integer checkQty = this.checkSkuQty(allCartGoodsList, cartGoods);
//购物车添加数量限制
limitGoodsQty(checkQty,appId);
Integer productsCount = limitGoodsQty(allCartGoodsList,cartGoods,appId);
//查询多个商品库存信息
queryManyGoodsStocks(addShoppingCartGoodsRequestVo, productIds, productBeanListSpuClass, skuId, checkQty);
String productName = null;
......@@ -325,7 +331,7 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
// 获取优惠信息
ActivityCalculationDiscountResponseDto.CalculationDiscountResult calculationDiscountResult
=getCalculationDiscountResult(menuType,partnerId,storeId,userId,appId,userLoginInfoDto.getWxAppid(),orderType,assortmentCustomerInfoVo.isMemberPaid(), allCartGoodsList,new ArrayList(),new ArrayList<>(),null,deliveryAmount);
sendGoodsQtyCheck(productsCount,appId,partnerId, userId, storeId,tableNumber, oldCartGoodsList,shoppingCartBaseService,calculationDiscountResult.getSendGoods());
// 促销活动的优惠金额计算
updateShoppingCartGoodsDiscount(null, activityQueryDto, calculationDiscountResult, allCartGoodsList, shoppingCartGoodsResponseVo, null, userLoginInfoDto, addShoppingCartGoodsRequestVo.getMenuType(), deliveryAmount);
clearMsg(shoppingCartGoodsResponseVo, cartGoods.getCartGoodsUid());
......@@ -391,8 +397,6 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
if (cartGoods == null) {
throw new ServiceException(ResponseResult.SHOPPING_CART_UPDATE_ERROR);
}
//购物车添加数量限制
limitGoodsQty(qty,appId);
// 检查购物车商品库存数量
checkUpdateStock(updateShoppingCartGoodsQtyRequestVo, cartGoods);
......@@ -448,6 +452,7 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
shoppingCartGoodsResponseVo.setProducts(cartGoodsList);
//return shoppingCartGoodsResponseVo;
}
sendGoodsQtyCheckForUpdate(cartGoodsList,cartGoods.getQty(),appId,partnerId, userId, storeId,null, cartGoodsUid,shoppingCartBaseService,calculationDiscountResult.getSendGoods());
// 促销活动的优惠金额计算
updateShoppingCartGoodsDiscount(null, activityQueryDto, calculationDiscountResult, cartGoodsList, shoppingCartGoodsResponseVo, null, userLoginInfoDto, updateShoppingCartGoodsQtyRequestVo.getMenuType(), deliveryAmount);
clearMsg(shoppingCartGoodsResponseVo, cartGoodsUid);
......@@ -1810,20 +1815,110 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
}
@Autowired
private RedisTemplate redisTemplate;
/**
* 查询生态配置限制加购开关与限制数量
*/
public Integer limitGoodsQty(List<CartGoods> oldCartGoodsList, CartGoods cartGoods,String appid){
Integer qty = 0;
if(CollectionUtils.isNotEmpty(oldCartGoodsList)){
for (CartGoods goods : oldCartGoodsList) {
qty += goods.getQty();
}
}
qty += cartGoods.getQty();
String redisKey = limitCartKey + appid;
Object value = redisCache.hashGet(redisKey, "2");
if (value == null) {
return qty;
} else {
JSONArray jsonArray = (JSONArray)value;
int cartLimitFlag = 0;
int cartLimitCount = 0;
for (Object object : jsonArray){
JSONObject jsonObject = (JSONObject)object;
HashMap hashMap = JSONObject.parseObject(jsonObject.toJSONString(),HashMap.class);
if("cartLimitFlag".equals(hashMap.get("appKey"))){
if (StringUtils.isBlank((String)hashMap.get("appValue"))) {
return qty;
}
cartLimitFlag = Integer.parseInt((String)hashMap.get("appValue"));
}
if("cartLimitCount".equals(hashMap.get("appKey"))){
if (StringUtils.isBlank((String)hashMap.get("appValue"))) {
return qty;
}
cartLimitCount = Integer.parseInt((String)hashMap.get("appValue"));
}
}
if(cartLimitFlag == 1 && cartLimitCount != 0 && qty > cartLimitCount){
throw new ServiceException(ResponseResult.SHOPPING_CART_LIMIT_ADD);
}
}
return qty;
}
@Autowired
private RedisCache redisCache;
/**
* 查询生态配置限制加购开关与限制数量
* 购物车添加完成后促销返回赠送商品总数量校验
*/
public void sendGoodsQtyCheck(Integer checkQty,String appid,String partnerId, String userId, String storeId, String tableNumber,List<CartGoods> oldCartGoodsList, ShoppingCartBaseService shoppingCartService,List<ActivityCalculationDiscountResponseDto.CalculationDiscountResult.SendActivity> sendActivitys){
if(CollectionUtils.isEmpty(sendActivitys)){
return;
}
int sendQty = 0;
for (ActivityCalculationDiscountResponseDto.CalculationDiscountResult.SendActivity sendActivity : sendActivitys){
for (ActivityCalculationDiscountResponseDto.CalculationDiscountResult.SendActivity.SendGoods sendGoods : sendActivity.getSendGoods()){
sendQty += sendGoods.getSendNumber();
}
}
String redisKey = limitCartKey + appid;
Object value = redisCache.hashGet(redisKey, "2");
if (value == null) {
return ;
} else {
JSONArray jsonArray = (JSONArray)value;
int cartLimitFlag = 0;
int cartLimitCount = 0;
for (Object object : jsonArray){
JSONObject jsonObject = (JSONObject)object;
HashMap hashMap = JSONObject.parseObject(jsonObject.toJSONString(),HashMap.class);
if("cartLimitFlag".equals(hashMap.get("appKey"))){
if (StringUtils.isBlank((String)hashMap.get("appValue"))) {
return;
}
cartLimitFlag = Integer.parseInt((String)hashMap.get("appValue"));
}
if("cartLimitCount".equals(hashMap.get("appKey"))){
if (StringUtils.isBlank((String)hashMap.get("appValue"))) {
return;
}
cartLimitCount = Integer.parseInt((String)hashMap.get("appValue"));
}
}
if(cartLimitFlag == 1 && cartLimitCount != 0 && checkQty+sendQty > cartLimitCount){
assortmentSdkService.setShoppingCart( partnerId, storeId, userId, oldCartGoodsList, null, tableNumber, shoppingCartService);
throw new ServiceException(ResponseResult.SHOPPING_CART_LIMIT_ADD);
}
}
}
/**
* 购物车添加完成后促销返回赠送商品总数量校验
*/
public void limitGoodsQty(Integer qty,String appid){
String redisKey = "ecology:kgd:wxappconfig:open_platform_partner_wxapp_config:appkey_"+appid;
public void sendGoodsQtyCheckForUpdate(List<CartGoods> cartGoodsList,Integer goodsQty,String appid,String partnerId, String userId, String storeId, String cartGoodsUid,String tableNumber, ShoppingCartBaseService shoppingCartService,List<ActivityCalculationDiscountResponseDto.CalculationDiscountResult.SendActivity> sendActivitys){
Integer updateQty = 0;
if(CollectionUtils.isNotEmpty(cartGoodsList)){
for (CartGoods goods : cartGoodsList) {
updateQty += goods.getQty();
}
}
String redisKey = limitCartKey + appid;
Object value = redisCache.hashGet(redisKey, "2");
List<AssortmentOpenPlatformPartnerWxappConfig> configs = null;
if (value == null) {
return ;
} else {
......@@ -1846,10 +1941,21 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
cartLimitCount = Integer.parseInt((String)hashMap.get("appValue"));
}
}
if(cartLimitFlag == 1 && cartLimitCount != 0 && qty > cartLimitCount){
int sendQty = 0;
if(CollectionUtils.isNotEmpty(sendActivitys)){
for (ActivityCalculationDiscountResponseDto.CalculationDiscountResult.SendActivity sendActivity : sendActivitys){
for (ActivityCalculationDiscountResponseDto.CalculationDiscountResult.SendActivity.SendGoods sendGoods : sendActivity.getSendGoods()){
sendQty += sendGoods.getSendNumber();
}
}
}
if(cartLimitFlag == 1 && cartLimitCount != 0 && updateQty+sendQty > cartLimitCount){
assortmentSdkService.updateGoodsQtyBySdk(partnerId, userId, storeId, cartGoodsUid, goodsQty, "", shoppingCartBaseService);
throw new ServiceException(ResponseResult.SHOPPING_CART_LIMIT_ADD);
}
}
}
}
......@@ -21,10 +21,8 @@ import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import static cn.freemud.constant.ShoppingCartConstant.SHOPPING_CART_EMPTY_GOODS_LIST;
......@@ -66,12 +64,13 @@ public class CalculationCommonService {
originalAmount = 0L;
amount = 0L;
packageAmount = 0L;
CalculationSharingDiscountResponseDto.CalculationDiscountResult.Goods find = goods.stream().filter((k) -> k.getCartGoodsUid().equals(cartGoods.getCartGoodsUid())).findFirst().get();
if (find == null) continue;
//CalculationSharingDiscountResponseDto.CalculationDiscountResult.Goods find = goods.stream().filter((k) -> k.getCartGoodsUid().equals(cartGoods.getCartGoodsUid())).findFirst().get();
//if (find == null) continue;
this.rowRealAmount(goods, cartGoods);
//成交价行记录
//amount += find.getRealAmount() * cartGoods.getQty();
amount += find.getRealAmount();
cartGoods.setAmount(amount);
amount = cartGoods.getAmount();
//cartGoods.setAmount(amount);
totalAmount += amount;
//原价行记录
originalAmount = cartGoods.getOriginalPrice() * cartGoods.getQty();
......@@ -89,6 +88,32 @@ public class CalculationCommonService {
shoppingCartGoodsResponseVo.setTotalDiscountAmount(discountResult == null ? 0L : discountResult.getTotalDiscountAmount());
}
private void rowRealAmount(List<CalculationSharingDiscountResponseDto.CalculationDiscountResult.Goods> goods, CartGoods cartGoods) {
CalculationSharingDiscountResponseDto.CalculationDiscountResult.Goods find = goods
.stream().filter((k) -> k.getCartGoodsUid().equals(cartGoods.getCartGoodsUid()))
.findFirst()
.get();
if (find == null) return;
cartGoods.setAmount(find.getRealAmount());
if (CollectionUtils.isEmpty(cartGoods.getProductGroupList())) return;
Map<String, CalculationSharingDiscountResponseDto.CalculationDiscountResult.Goods.SmallMaterial> choices = find.getSmallMaterial()
.stream().filter(d -> "2".equals(d.getType()))
.collect(Collectors.toMap(CalculationSharingDiscountResponseDto.CalculationDiscountResult.Goods.SmallMaterial::getGoodsId, Function.identity(), (k1, k2) -> k1));
long amount = 0L;
for (CartGoods.ComboxGoods choice : cartGoods.getProductGroupList()) {
CalculationSharingDiscountResponseDto.CalculationDiscountResult.Goods.SmallMaterial mt = choices.get(choice.getGoodsId());
if (mt == null) {
amount = choice.getAmount() * cartGoods.getQty();
} else {
amount = mt.getRealAmount();
choice.setAmount(mt.getRealAmount().longValue());
}
}
cartGoods.setAmount(cartGoods.getAmount() + amount);
}
/**
* 设置行记录享受的优惠及总优惠
*
......@@ -471,9 +496,10 @@ public class CalculationCommonService {
for (CalculationSharingDiscountResponseDto.CalculationDiscountResult.Goods goods : goodsList) {
dis = goods.getDiscounts()
.stream()
.filter(g -> types.contains(types)).findFirst().orElse(null);
.filter(g -> types.contains(g.getType())).findFirst().orElse(null);
if (null == dis) continue;
if (goods.getGoodsQuantity() > dis.getActualGoodsNumber()) {
//goods.get
toastMsg = "该商品限" + dis.getActualGoodsNumber() + "份优惠 超出按照原价计算哦";
uid = goods.getCartGoodsUid();
}
......
......@@ -100,8 +100,9 @@ public class CalculationSharingCartService {
/**
* 可选搭配的价格累加到套餐的成交价上
* this.combineGroupRowAmount(cartGoodsList);
*/
this.combineGroupRowAmount(cartGoodsList);
/**
* 特价类型超出部分提示
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment