|
@@ -13,6 +13,7 @@ import com.iamberry.wechat.core.entity.channel.ChildChannel;
|
|
|
import com.iamberry.wechat.core.entity.channel.MainChannel;
|
|
|
import com.iamberry.wechat.core.entity.coupon.*;
|
|
|
import com.iamberry.wechat.core.entity.customized.CustomizedTooth;
|
|
|
+import com.iamberry.wechat.core.entity.gift.SettlementGift;
|
|
|
import com.iamberry.wechat.core.entity.integral.StayIntegral;
|
|
|
import com.iamberry.wechat.core.entity.member.Member;
|
|
|
import com.iamberry.wechat.core.entity.order.Order;
|
|
@@ -31,6 +32,7 @@ import com.iamberry.wechat.face.coupon.CouponItemService;
|
|
|
import com.iamberry.wechat.face.coupon.CouponTypeService;
|
|
|
import com.iamberry.wechat.face.coupon.SalesActivitiesService;
|
|
|
import com.iamberry.wechat.face.customized.CustomizedToothService;
|
|
|
+import com.iamberry.wechat.face.gift.SettlementGiftService;
|
|
|
import com.iamberry.wechat.face.home.HomeService;
|
|
|
import com.iamberry.wechat.face.integral.UseIntegralService;
|
|
|
import com.iamberry.wechat.face.member.CashLogService;
|
|
@@ -47,6 +49,7 @@ import com.iamberry.wechat.tools.OrderNOUtil;
|
|
|
import com.iamberry.wechat.tools.ResultInfo;
|
|
|
import com.iamberry.wechat.tools.ValidatorUtil;
|
|
|
import com.iamberry.wechat.utils.ActivityUtil;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
@@ -73,19 +76,14 @@ import java.util.regex.Pattern;
|
|
|
public class OrderHandler {
|
|
|
@Autowired
|
|
|
private RatFWLogger ratFWLogger;
|
|
|
-
|
|
|
@Autowired
|
|
|
private CartService cartService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private HomeService homeService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private SystemService systemService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private ValidatorUtil validatorUtil;
|
|
|
-
|
|
|
@Autowired
|
|
|
private PayService payService;
|
|
|
@Autowired
|
|
@@ -126,6 +124,8 @@ public class OrderHandler {
|
|
|
private ActivityUtil activityUtil;
|
|
|
@Autowired
|
|
|
private SalesActivitiesService salesActivitiesService;
|
|
|
+ @Autowired
|
|
|
+ private SettlementGiftService settlementGiftService;
|
|
|
|
|
|
/**
|
|
|
* 支付前,调用方法
|
|
@@ -155,7 +155,7 @@ public class OrderHandler {
|
|
|
|
|
|
if(channelType > 0 && channelId > 0){
|
|
|
if(channelType == 1){
|
|
|
- MainChannel mainChannel = mainChannelService.getMainChannelById(channelId);
|
|
|
+ MainChannel mainChannel = mainChannelService.getMainChannelById(channelId);
|
|
|
dto.setChannelName(mainChannel.getMainChannelName());
|
|
|
}else{
|
|
|
ChildChannel childChannel = childChannelService.getChildChannelById(channelId);
|
|
@@ -230,35 +230,15 @@ public class OrderHandler {
|
|
|
}
|
|
|
|
|
|
ActivityDate activityDate = activityUtil.doubleTwelve();
|
|
|
- if(channelType > 0 && channelId > 0){
|
|
|
+ if(channelType > 0 && channelId > 0){ ///非分销渠道,才能有促销
|
|
|
activityDate.setStatus(false);
|
|
|
}else{
|
|
|
- //非分销渠道,才能有促销
|
|
|
if(activityDate.isStatus()){
|
|
|
+ /*满减*/
|
|
|
+ Integer promotionAmout = fullReduc(activityDate,allAmount);; //促销之后的金额 -- 总金额减去满减,满减的优先级高一些
|
|
|
|
|
|
- /*计算促销之后的支付金额*/
|
|
|
- Integer promotionAmout = allAmount; //促销之后的金额 -- 总金额减去满减,满减的优先级高一些
|
|
|
-
|
|
|
- SalesActivities sa = new SalesActivities();
|
|
|
- sa.setSalesActivitiesStatus(1);
|
|
|
- sa.setSalesActivitiesType(1);
|
|
|
- sa.setSalesActivitiesScenes(1);
|
|
|
- List<SalesActivities> salesActivitiesList = salesActivitiesService.getSalesActivitiesList(sa);
|
|
|
- activityDate.setSalesActivitiesList(salesActivitiesList);
|
|
|
- for (SalesActivities salesActivities : activityDate.getSalesActivitiesList()){
|
|
|
- if(promotionAmout >= salesActivities.getSalesActivitiesFull()){
|
|
|
- promotionAmout = allAmount - salesActivities.getSalesActivitiesReduction();
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- Integer num[] = new Integer[0];
|
|
|
- if(toothKidsbrush > 0){
|
|
|
- addFullReduction(5,cartDtos,num);
|
|
|
- }
|
|
|
- if(toothAuthbrush > 0 || toothKidsbrush > 0){
|
|
|
- num = new Integer[]{toothKidsbrush+toothAuthbrush};
|
|
|
- addFullReduction(1,cartDtos,num);
|
|
|
- }
|
|
|
+ //满赠
|
|
|
+ giftCart(cartDtos);
|
|
|
}
|
|
|
}
|
|
|
dto.setActivityDate(activityDate);
|
|
@@ -341,9 +321,6 @@ public class OrderHandler {
|
|
|
cDto.setUseropenid(member.getUserOpenid());
|
|
|
cDto.setCouponUseStatus(1);
|
|
|
cDto.setBeginDate(new Date()); ////*未过期*/
|
|
|
- //cDto.setPage(new PageBean());
|
|
|
- //cDto.getPage().setPageSize(12);
|
|
|
- //cDto.getPage().setPageNumber(pageNO);
|
|
|
List<CouponItemDto> couponItemDtoList = couponItemService.getCouponItemDtoList(cDto);
|
|
|
List<CouponItemDto> list = new ArrayList<>();
|
|
|
for(CouponItemDto couponItemDto : couponItemDtoList){
|
|
@@ -534,35 +511,15 @@ public class OrderHandler {
|
|
|
allAmount += cd.getCartNum()*cd.getProductPrice();
|
|
|
}
|
|
|
|
|
|
- if(temp.getChannelType() > 0 && temp.getChannelId() > 0){
|
|
|
+ if(temp.getChannelType() > 0 && temp.getChannelId() > 0){ //非分销渠道,才能有促销
|
|
|
activityDate.setStatus(false);
|
|
|
}else {
|
|
|
- /*计算促销之后的支付金额*/
|
|
|
- Integer promotionAmout = allAmount; //促销之后的金额
|
|
|
-
|
|
|
- SalesActivities sa = new SalesActivities();
|
|
|
- sa.setSalesActivitiesStatus(1);
|
|
|
- sa.setSalesActivitiesType(1);
|
|
|
- sa.setSalesActivitiesScenes(1);
|
|
|
- List<SalesActivities> salesActivitiesList = salesActivitiesService.getSalesActivitiesList(sa);
|
|
|
- activityDate.setSalesActivitiesList(salesActivitiesList);
|
|
|
- for (SalesActivities salesActivities : activityDate.getSalesActivitiesList()){
|
|
|
- if(promotionAmout >= salesActivities.getSalesActivitiesFull()){
|
|
|
- promotionAmout = allAmount - salesActivities.getSalesActivitiesReduction();
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //非分销渠道,才能有促销
|
|
|
if (activityDate.isStatus()) {
|
|
|
- Integer num[] = new Integer[0];
|
|
|
- if(toothKidsbrush > 0){
|
|
|
- addFullReduction(5,cartDtos,num);
|
|
|
- }
|
|
|
- if(toothAuthbrush > 0 || toothKidsbrush > 0){
|
|
|
- num = new Integer[]{toothKidsbrush+toothAuthbrush};
|
|
|
- addFullReduction(1,cartDtos,num);
|
|
|
- }
|
|
|
+ /*满减*/
|
|
|
+ Integer promotionAmout = fullReduc(activityDate,allAmount);; //促销之后的金额 -- 总金额减去满减,满减的优先级高一些
|
|
|
+
|
|
|
+ //满赠
|
|
|
+ giftCart(cartDtos);
|
|
|
}
|
|
|
}
|
|
|
}else if("2".equals(temp.getIsCustomize())){
|
|
@@ -1135,58 +1092,158 @@ public class OrderHandler {
|
|
|
* @param
|
|
|
* @return
|
|
|
*/
|
|
|
- private void addCartDtos(List<CartDto> cartDtos,Integer id,Integer num){
|
|
|
- boolean flag = false;
|
|
|
- for (CartDto cartDto : cartDtos) {
|
|
|
- if(id.equals(cartDto.getCartColorId())){
|
|
|
- flag = true;
|
|
|
+// private void addCartDtos(List<CartDto> cartDtos,Integer id,Integer num){
|
|
|
+// boolean flag = false;
|
|
|
+// for (CartDto cartDto : cartDtos) {
|
|
|
+// if(id.equals(cartDto.getCartColorId())){
|
|
|
+// flag = true;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if(!flag){
|
|
|
+// CartDto cd = getGiftCartDtos(id,num);
|
|
|
+// cartDtos.add(cd);
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取赠品信息
|
|
|
+ * @param colorId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+// private CartDto getGiftCartDtos(Integer colorId,Integer num){
|
|
|
+// CartDto cartDto = new CartDto();
|
|
|
+// Product product = productInfoService.selectProductByColorId(colorId);
|
|
|
+// if((product.getColorSoldNum()+1) > product.getColorAllNum()){
|
|
|
+// return null;
|
|
|
+// }
|
|
|
+// cartDto.setCartId(1);
|
|
|
+// cartDto.setCartProductId(product.getProductId());
|
|
|
+// cartDto.setCartColorId(colorId);
|
|
|
+// cartDto.setCartNum(num);
|
|
|
+// cartDto.setProductName(product.getProductName());
|
|
|
+// cartDto.setProductType(product.getProductTypeId());
|
|
|
+// cartDto.setProductPrice(product.getColorDiscount());
|
|
|
+// cartDto.setProductStatus(1);
|
|
|
+// cartDto.setProductIntroduceImg(product.getColorImg());
|
|
|
+// cartDto.setTotal(0);
|
|
|
+// cartDto.setProductDiscount(product.getColorDiscount());
|
|
|
+// cartDto.setProductRemark(product.getColorPresent());
|
|
|
+// cartDto.setProductColor(product.getColorName());
|
|
|
+// cartDto.setColorAllNum(product.getColorAllNum());
|
|
|
+// cartDto.setColorSoldNum(product.getColorSoldNum());
|
|
|
+// cartDto.setIsSelfLifting(2);
|
|
|
+// return cartDto;
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 赠送赠品
|
|
|
+ * @param cartDtoList
|
|
|
+ */
|
|
|
+ private void giftCart(List<CartDto> cartDtoList){
|
|
|
+ List<CartDto> giftList = new ArrayList<>();
|
|
|
+ SettlementGift settlementGift = new SettlementGift();
|
|
|
+ settlementGift.setSettGiftStatus(1);
|
|
|
+ List<SettlementGift> settlementGiftList = settlementGiftService.getSettlementGiftList(settlementGift);
|
|
|
+ for (CartDto cd:cartDtoList) {
|
|
|
+ for (SettlementGift sg:settlementGiftList) {
|
|
|
+ if(Objects.equals(cd.getCartColorId(), sg.getSettGiftFillColorId())){//添加赠送产品
|
|
|
+ CartDto cartDto = new CartDto();
|
|
|
+ cartDto.setCartColorId(sg.getSettGiftGiftColorId());
|
|
|
+ Integer num = sg.getSettGiftNum();
|
|
|
+ if(sg.getSettGiftNum() < 1){ //判断赠送数量,大于0就用该数量
|
|
|
+ num = cd.getCartNum();
|
|
|
+ }
|
|
|
+ if(num > sg.getSettGiftMaxNum()){
|
|
|
+ num = sg.getSettGiftMaxNum();
|
|
|
+ }
|
|
|
+ cartDto.setCartNum(num);
|
|
|
+ cartDto.setProductDiscount(sg.getSettGiftPrice());
|
|
|
+ cartDto.setProductPrice(sg.getSettGiftPrice());
|
|
|
+ cartDto.setTotal(sg.getSettGiftPrice()*num);
|
|
|
+ giftList.add(cartDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //赠品合并
|
|
|
+ List<CartDto> newGiftList = new ArrayList<>();
|
|
|
+ if(giftList != null && giftList.size() > 0){
|
|
|
+ for (CartDto carD:giftList) {
|
|
|
+ boolean fl = false;
|
|
|
+ for(CartDto newCarD:newGiftList) {
|
|
|
+ if(Objects.equals(newCarD.getCartColorId(), carD.getCartColorId())){ //赠品相同,合并
|
|
|
+ fl = true;
|
|
|
+ Integer oldNum = newCarD.getCartNum();
|
|
|
+ newCarD.setCartNum(newCarD.getCartNum() + carD.getCartNum());
|
|
|
+ if( newCarD.getCartNum() > newCarD.getColorGiftMaxNum()){ //(赠送数量+已售出<=总数)
|
|
|
+ newCarD.setCartNum(newCarD.getColorGiftMaxNum());
|
|
|
+ }
|
|
|
+ Integer num = newCarD.getCartNum()+newCarD.getColorSoldNum();
|
|
|
+ if(num > newCarD.getColorAllNum()){
|
|
|
+ //newCarD.setCartNum(newCarD.getColorAllNum() - num);
|
|
|
+ newCarD.setCartNum(oldNum);
|
|
|
+ }
|
|
|
+
|
|
|
+ newCarD.setProductDiscount(newCarD.getProductDiscount() + carD.getProductDiscount());
|
|
|
+ newCarD.setProductPrice( newCarD.getProductPrice() + carD.getProductPrice());
|
|
|
+ newCarD.setTotal(newCarD.getTotal() + carD.getTotal());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!fl){
|
|
|
+ Product product = productInfoService.selectProductByColorId(carD.getCartColorId());
|
|
|
+ carD.setCartId(1);
|
|
|
+ carD.setCartProductId(product.getProductId());
|
|
|
+ carD.setProductName(product.getProductName());
|
|
|
+ carD.setProductType(product.getProductTypeId());
|
|
|
+ carD.setProductStatus(1);
|
|
|
+ carD.setProductIntroduceImg(product.getColorImg());
|
|
|
+ carD.setProductRemark(product.getColorPresent());
|
|
|
+ carD.setProductColor(product.getColorName());
|
|
|
+ carD.setCartColorId(product.getColorId());
|
|
|
+ carD.setProductRemark("");
|
|
|
+ carD.setColorAllNum(product.getColorAllNum());
|
|
|
+ carD.setColorSoldNum(product.getColorSoldNum());
|
|
|
+ carD.setColorToothType(1);
|
|
|
+ carD.setProductIntroduceImg(product.getColorImg()); //productIntroduceImg
|
|
|
+ carD.setColorGiftMaxNum(product.getColorGiftMaxNum());
|
|
|
+ if( carD.getCartNum() > carD.getColorGiftMaxNum()){ //(赠送数量+已售出<=总数)
|
|
|
+ carD.setCartNum(carD.getColorGiftMaxNum());
|
|
|
+ }
|
|
|
+ Integer num = carD.getCartNum()+carD.getColorSoldNum();
|
|
|
+ if(num <= carD.getColorAllNum()){ //库存加赠品数量 要小于 总库存才能到结算页面
|
|
|
+ CartDto newCartDto = new CartDto();
|
|
|
+ BeanUtils.copyProperties(carD,newCartDto);
|
|
|
+ newGiftList.add(newCartDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- if(!flag){
|
|
|
- CartDto cd = getGiftCartDtos(id,num);
|
|
|
- cartDtos.add(cd);
|
|
|
+
|
|
|
+ //将赠品并入结算列表
|
|
|
+ if(newGiftList != null && newGiftList.size() > 0){
|
|
|
+ cartDtoList.addAll(newGiftList);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取赠品信息
|
|
|
- * @param colorId
|
|
|
+ * 满减
|
|
|
* @return
|
|
|
*/
|
|
|
- private CartDto getGiftCartDtos(Integer colorId,Integer num){
|
|
|
- CartDto cartDto = new CartDto();
|
|
|
- Product product = productInfoService.selectProductByColorId(colorId);
|
|
|
- if((product.getColorSoldNum()+1) > product.getColorAllNum()){
|
|
|
- return null;
|
|
|
+ public Integer fullReduc(ActivityDate activityDate, Integer allAmount){
|
|
|
+ Integer promotionAmout = 0;
|
|
|
+ SalesActivities sa = new SalesActivities();
|
|
|
+ sa.setSalesActivitiesStatus(1);
|
|
|
+ sa.setSalesActivitiesType(activityDate.getType());
|
|
|
+ sa.setSalesActivitiesScenes(1);
|
|
|
+ List<SalesActivities> salesActivitiesList = salesActivitiesService.getSalesActivitiesList(sa);
|
|
|
+ activityDate.setSalesActivitiesList(salesActivitiesList);
|
|
|
+ for (SalesActivities salesActivities : salesActivitiesList){
|
|
|
+ if(promotionAmout >= salesActivities.getSalesActivitiesFull()){
|
|
|
+ promotionAmout = allAmount - salesActivities.getSalesActivitiesReduction();
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
- cartDto.setCartId(1);
|
|
|
- cartDto.setCartProductId(product.getProductId());
|
|
|
- cartDto.setCartColorId(colorId);
|
|
|
- cartDto.setCartNum(num);
|
|
|
- cartDto.setProductName(product.getProductName());
|
|
|
- cartDto.setProductType(product.getProductTypeId());
|
|
|
- cartDto.setProductPrice(product.getColorDiscount());
|
|
|
- cartDto.setProductStatus(1);
|
|
|
- cartDto.setProductIntroduceImg(product.getColorImg());
|
|
|
- cartDto.setTotal(0);
|
|
|
- cartDto.setProductDiscount(product.getColorDiscount());
|
|
|
- cartDto.setProductRemark(product.getColorPresent());
|
|
|
- cartDto.setProductColor(product.getColorName());
|
|
|
- cartDto.setColorAllNum(product.getColorAllNum());
|
|
|
- cartDto.setColorSoldNum(product.getColorSoldNum());
|
|
|
- cartDto.setIsSelfLifting(2);
|
|
|
- return cartDto;
|
|
|
+ return promotionAmout;
|
|
|
}
|
|
|
-
|
|
|
-//
|
|
|
-// public static void main(String[] args) {
|
|
|
-// String tel = "13265476840";
|
|
|
-// String regExp = "^((13[0-9])|(15[0-9])|(18[0-9])|(17[0-9])|(147))\\d{8}$";
|
|
|
-// Pattern p = Pattern.compile(regExp);
|
|
|
-// Matcher m = p.matcher(tel);
|
|
|
-// if(m.matches()){
|
|
|
-// System.out.println("电话号码错误,请重新添加收货地址信息!");
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
}
|