|
@@ -11,10 +11,12 @@ import com.iamberry.wechat.core.entity.mq.MQMessage;
|
|
|
import com.iamberry.wechat.core.entity.order.Order;
|
|
|
import com.iamberry.wechat.core.entity.order.OrderItem;
|
|
|
import com.iamberry.wechat.core.entity.pay.PayResult;
|
|
|
+import com.iamberry.wechat.core.entity.product.Product;
|
|
|
import com.iamberry.wechat.core.entity.product.ProductColor;
|
|
|
import com.iamberry.wechat.face.admin.SystemService;
|
|
|
import com.iamberry.wechat.face.cart.CartService;
|
|
|
import com.iamberry.wechat.face.cart.ProductInfoService;
|
|
|
+import com.iamberry.wechat.face.cart.SettlementGiftService;
|
|
|
import com.iamberry.wechat.face.coupon.CouponItemService;
|
|
|
import com.iamberry.wechat.face.coupon.CouponTypeService;
|
|
|
import com.iamberry.wechat.face.coupon.ExchangeService;
|
|
@@ -31,6 +33,7 @@ import com.iamberry.wechat.tools.NameUtils;
|
|
|
import com.iamberry.wechat.tools.OrderNOUtil;
|
|
|
import com.iamberry.wechat.tools.ResultInfo;
|
|
|
import com.iamberry.wechat.tools.ValidatorUtil;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
@@ -42,10 +45,7 @@ import javax.servlet.ServletException;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* @author 何秀刚
|
|
@@ -94,6 +94,8 @@ public class OrderHandler {
|
|
|
private ProductColorService productColorService;
|
|
|
@Autowired
|
|
|
private ActivityUtil activityUtil;
|
|
|
+ @Autowired
|
|
|
+ private SettlementGiftService settlementGiftService;
|
|
|
/**
|
|
|
* 支付前,调用方法
|
|
|
* @param request
|
|
@@ -146,41 +148,45 @@ public class OrderHandler {
|
|
|
}
|
|
|
|
|
|
//根据openid查询该用户是否购买过订单
|
|
|
- ShopSalesOrderDto shopSalesOrderDto = new ShopSalesOrderDto();
|
|
|
- shopSalesOrderDto.setSalesOpenid(member.getUserOpenid());
|
|
|
- shopSalesOrderDto.setSalesStatus("2");
|
|
|
- int orderNum = cartService.selectOrderCount(shopSalesOrderDto);
|
|
|
+// ShopSalesOrderDto shopSalesOrderDto = new ShopSalesOrderDto();
|
|
|
+// shopSalesOrderDto.setSalesOpenid(member.getUserOpenid());
|
|
|
+// shopSalesOrderDto.setSalesStatus("2");
|
|
|
+// int orderNum = cartService.selectOrderCount(shopSalesOrderDto);
|
|
|
//如果购买过订单,则滤芯的价格可按折扣价购买
|
|
|
- if (orderNum > 0) {
|
|
|
- if (cartDtos != null && cartDtos.size() >= 1) {
|
|
|
- for (CartDto cartDto : cartDtos) {
|
|
|
- if (cartDto.getProductType().intValue() == 2) {
|
|
|
- UserGiftDto userGiftDto = new UserGiftDto();
|
|
|
- userGiftDto.setUserLevel(3);
|
|
|
- userGiftDto.setUserProductId(cartDto.getCartProductId());
|
|
|
- userGiftDto.setUserColorId(cartDto.getCartColorId());
|
|
|
- //根据商品id和会员等级查询礼品信息
|
|
|
- userGiftDto = productInfoService.selectUserGift(userGiftDto);
|
|
|
- if (userGiftDto != null) {
|
|
|
- cartDto.setProductPrice(userGiftDto.getUserDiscount());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+// if (orderNum > 0) {
|
|
|
+// if (cartDtos != null && cartDtos.size() >= 1) {
|
|
|
+// for (CartDto cartDto : cartDtos) {
|
|
|
+// if (cartDto.getProductType().intValue() == 2) {
|
|
|
+// UserGiftDto userGiftDto = new UserGiftDto();
|
|
|
+// userGiftDto.setUserLevel(3);
|
|
|
+// userGiftDto.setUserProductId(cartDto.getCartProductId());
|
|
|
+// userGiftDto.setUserColorId(cartDto.getCartColorId());
|
|
|
+// //根据商品id和会员等级查询礼品信息
|
|
|
+// userGiftDto = productInfoService.selectUserGift(userGiftDto);
|
|
|
+// if (userGiftDto != null) {
|
|
|
+// cartDto.setProductPrice(userGiftDto.getUserDiscount());
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+ //添加赠品
|
|
|
+ ActivityDate activityDate = activityUtil.isActivity();
|
|
|
+ if(activityDate.isStatus()){
|
|
|
+ giftCart(cartDtos);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 判断当前提交的购物车ID,有多少产品在售
|
|
|
int total = 0; // 支付金额
|
|
|
int sum = 0; // 产品数量
|
|
|
int productNum = 0; //计算商品为滤芯的数量
|
|
|
boolean disable = true; //标识,是否可用优惠券,当购买商品只有滤芯时禁止使用优惠券
|
|
|
-
|
|
|
- List<CartDto> tempCarts = new ArrayList<CartDto>();
|
|
|
+
|
|
|
for (CartDto cartDto : cartDtos) {
|
|
|
if (cartDto.getProductStatus() != null && cartDto.getProductStatus().intValue() == 1) {
|
|
|
total += cartDto.getCartNum() * cartDto.getProductPrice();
|
|
|
sum++;
|
|
|
- tempCarts.add(cartDto);
|
|
|
}
|
|
|
//计算商品为滤芯的数量
|
|
|
if (cartDto.getProductType().intValue() == 2) {
|
|
@@ -197,7 +203,7 @@ public class OrderHandler {
|
|
|
msg.setMessage(ResultInfo.cartEmptyError);
|
|
|
return msg;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
//未使用的优惠券
|
|
|
CouponItemDto cDto = new CouponItemDto();
|
|
|
cDto.setUseropenid(member.getUserOpenid());
|
|
@@ -246,19 +252,12 @@ public class OrderHandler {
|
|
|
dto.setUserIsVip(member.getUserIsVip());
|
|
|
dto.setCartId(cartIds);// 购物车ID
|
|
|
dto.setPayTotal(total); // 支付金额,单位为分
|
|
|
- dto.setCartItems(tempCarts); // 订单项
|
|
|
+ dto.setCartItems(cartDtos); // 订单项
|
|
|
dto.setSuccess(true); // 请求成功
|
|
|
dto.setMeonyProportion(0);
|
|
|
dto.setBalance(member.getUserIncome());
|
|
|
+ dto.setUser38Interests(2); //活动过期
|
|
|
|
|
|
- ActivityDate activityDate = activityUtil.doubleTwelve();
|
|
|
- if(activityDate.isStatus() && activityUtil.getFullReduction(member.getUserOpenid())){
|
|
|
- dto.setUser38Interests(1); //有权益
|
|
|
- }else{
|
|
|
- dto.setUser38Interests(2); //无权益
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
dto.setDisable(disable);
|
|
|
|
|
|
//回显用户支付过的地址信息
|
|
@@ -376,10 +375,10 @@ public class OrderHandler {
|
|
|
}
|
|
|
|
|
|
//根据openid查询该用户是否购买过订单
|
|
|
- ShopSalesOrderDto shopSalesOrderDto = new ShopSalesOrderDto();
|
|
|
- shopSalesOrderDto.setSalesOpenid(member.getUserOpenid());
|
|
|
- shopSalesOrderDto.setSalesStatus("2");
|
|
|
- int orderNum = cartService.selectOrderCount(shopSalesOrderDto);
|
|
|
+// ShopSalesOrderDto shopSalesOrderDto = new ShopSalesOrderDto();
|
|
|
+// shopSalesOrderDto.setSalesOpenid(member.getUserOpenid());
|
|
|
+// shopSalesOrderDto.setSalesStatus("2");
|
|
|
+// int orderNum = cartService.selectOrderCount(shopSalesOrderDto);
|
|
|
|
|
|
int total = 0; // 需要支付的总额, 单位为分
|
|
|
|
|
@@ -397,17 +396,23 @@ public class OrderHandler {
|
|
|
order.setSalesOrderid(OrderNOUtil.createOrderCode(member.getUserId())); // 订单ID
|
|
|
List<OrderItem> list = new ArrayList<OrderItem>();
|
|
|
List<Integer> cartIds = new ArrayList<Integer>();
|
|
|
+
|
|
|
+ //添加赠品
|
|
|
+ ActivityDate activityDate = activityUtil.isActivity();
|
|
|
+ if(activityDate.isStatus()){
|
|
|
+ giftCart(cartDtos);
|
|
|
+ }
|
|
|
|
|
|
for (CartDto cartDto : cartDtos) {
|
|
|
//如果购买过订单,则滤芯的价格可按折扣价购买
|
|
|
- if (orderNum > 0) {
|
|
|
- if (cartDto.getProductType().intValue() == 2) {
|
|
|
- UserGiftDto userGiftDto = new UserGiftDto();
|
|
|
- userGiftDto.setUserLevel(3);
|
|
|
- userGiftDto.setUserProductId(cartDto.getCartProductId());
|
|
|
- userGiftDto.setUserColorId(cartDto.getCartColorId());
|
|
|
- }
|
|
|
- }
|
|
|
+// if (orderNum > 0) {
|
|
|
+// if (cartDto.getProductType().intValue() == 2) {
|
|
|
+// UserGiftDto userGiftDto = new UserGiftDto();
|
|
|
+// userGiftDto.setUserLevel(3);
|
|
|
+// userGiftDto.setUserProductId(cartDto.getCartProductId());
|
|
|
+// userGiftDto.setUserColorId(cartDto.getCartColorId());
|
|
|
+// }
|
|
|
+// }
|
|
|
//VIP用户滤芯年套减一百
|
|
|
if(cartDto.getCartColorId() == 5 && member.getUserIsVip() == 2){
|
|
|
priceReduction += 10000*cartDto.getCartNum();
|
|
@@ -439,8 +444,7 @@ public class OrderHandler {
|
|
|
// 准备订单对象
|
|
|
order.setSalesOpenid(member.getUserOpenid()); // openid
|
|
|
order.setSalesAmount(total); // 订单金额
|
|
|
- total -= priceReduction;
|
|
|
-
|
|
|
+
|
|
|
int mustPay=0;
|
|
|
|
|
|
String couponId=temp.getCouponId();
|
|
@@ -516,27 +520,8 @@ public class OrderHandler {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- ActivityDate activityDate = activityUtil.doubleTwelve();
|
|
|
- if(activityDate.isStatus()&& activityUtil.getFullReduction(member.getUserOpenid())){
|
|
|
- if(total > 200000){
|
|
|
- ProductColor productColor = productColorService.selectProductColorById(48);
|
|
|
- OrderItem item = new OrderItem();
|
|
|
- item.setItemNum(1);
|
|
|
- item.setItemProductDiscount(0);
|
|
|
- item.setItemProductId(productColor.getColorProductId());
|
|
|
- item.setItemProductName(productColor.getColorProductName());
|
|
|
- item.setItemProductPic(productColor.getColorImg());
|
|
|
- item.setItemSalesOrderid(order.getSalesOrderid());
|
|
|
- item.setItemTotal(0);
|
|
|
- item.setItemProductType(productColor.getColorProductType());
|
|
|
- item.setItemProductPrice(0);
|
|
|
- item.setItemColorId(productColor.getColorId());
|
|
|
- list.add(item);
|
|
|
- }
|
|
|
- if(total > 300000){
|
|
|
- total = total - 10000;
|
|
|
- }
|
|
|
- }
|
|
|
+ // 套装减去100元
|
|
|
+ total -= priceReduction;
|
|
|
|
|
|
if(total==0 || total<0){
|
|
|
total=0;
|
|
@@ -768,4 +753,64 @@ public class OrderHandler {
|
|
|
}
|
|
|
return cartIntList;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 赠送赠品
|
|
|
+ * @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();
|
|
|
+ }
|
|
|
+ cartDto.setCartNum(num);
|
|
|
+ cartDto.setProductDiscount(sg.getSettGiftPrice());
|
|
|
+ cartDto.setProductPrice(sg.getSettGiftPrice());
|
|
|
+ cartDto.setTotal(sg.getSettGiftPrice()*num);
|
|
|
+ giftList.add(cartDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(giftList != null && giftList.size() > 0){
|
|
|
+ for (CartDto carD:giftList) {
|
|
|
+ boolean flag = false;
|
|
|
+ for (CartDto cd:cartDtoList) {
|
|
|
+ if(Objects.equals(cd.getCartColorId(), carD.getCartColorId())){
|
|
|
+ flag = true;
|
|
|
+ cd.setCartNum(cd.getCartNum() + carD.getCartNum());
|
|
|
+ cd.setProductDiscount(cd.getProductDiscount() + carD.getProductDiscount());
|
|
|
+ cd.setProductPrice( cd.getProductPrice() + carD.getProductPrice());
|
|
|
+ cd.setTotal(cd.getTotal() + carD.getTotal());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!flag){
|
|
|
+ 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.setColorImg(product.getColorImg());
|
|
|
+ CartDto newCartDto = new CartDto();
|
|
|
+ BeanUtils.copyProperties(carD,newCartDto);
|
|
|
+ cartDtoList.add(newCartDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|