| | |
| | | import com.doumee.dao.business.join.GoodsorderJoinMapper; |
| | | import com.doumee.dao.business.join.PlanorderDetailJoinMapper; |
| | | import com.doumee.dao.business.model.*; |
| | | import com.doumee.dao.system.dto.PlatformConfigDTO; |
| | | import com.doumee.dao.web.dto.CouponDTO; |
| | | import com.doumee.dao.web.request.*; |
| | | import com.doumee.dao.web.request.goods.MemberOrderRequest; |
| | | import com.doumee.dao.web.request.goods.DealOrderRequest; |
| | | import com.doumee.dao.web.request.goods.OrderCommentRequest; |
| | | import com.doumee.dao.web.request.goods.OrderGoodsCommentRequest; |
| | | import com.doumee.dao.web.request.goods.*; |
| | | import com.doumee.dao.web.response.HomeInfoResponse; |
| | | import com.doumee.dao.web.response.MyPageResponse; |
| | | import com.doumee.dao.web.response.goods.*; |
| | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.doumee.service.business.IntegralService; |
| | | import com.doumee.service.system.SystemDictDataService; |
| | | import com.github.binarywang.wxpay.bean.request.BaseWxPayRequest; |
| | | import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest; |
| | | import com.github.binarywang.wxpay.bean.result.WxPayRefundResult; |
| | |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.net.InetAddress; |
| | | import java.net.UnknownHostException; |
| | | import java.util.*; |
| | |
| | | |
| | | @Autowired |
| | | private SystemDictDataBiz systemDictDataBiz; |
| | | |
| | | @Autowired |
| | | private SystemDictDataService systemDictDataService; |
| | | |
| | | @Autowired |
| | | private PlanorderDetailJoinMapper planorderDetailJoinMapper; |
| | |
| | | goodsorder.setMemberId(member.getId()); |
| | | goodsorder.setType(Constants.ZERO); |
| | | goodsorder.setStatus(Constants.ZERO); |
| | | |
| | | Shop shop = null; |
| | | if(Constants.equalsInteger(orderPayRequest.getReceiveType(),Constants.ZERO)){ |
| | | //查询收货地址 |
| | | Addr addr = addrMapper.selectById(orderPayRequest.getAddressId()); |
| | |
| | | if(Objects.isNull(area)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"收货地址区划信息发生变化,请更新后下单!"); |
| | | } |
| | | |
| | | goodsorder.setAddrId(addr.getId()); |
| | | goodsorder.setLinkaddr(area.getProvinceName()+area.getCityName() + area.getName() + addr.getAddr()); |
| | | goodsorder.setLinkphone(addr.getPhone()); |
| | | goodsorder.setLinkname(addr.getName()); |
| | | if(Objects.nonNull(member.getBindShopId())){ |
| | | goodsorder.setDistributionShopId(member.getBindShopId()); |
| | | shop = shopMapper.selectById(member.getBindShopId()); |
| | | } |
| | | }else{ |
| | | if(Objects.isNull(orderPayRequest.getShopId())){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"请选择正确的自提门店!"); |
| | | } |
| | | Shop shop = shopMapper.selectById(orderPayRequest.getShopId()); |
| | | shop = shopMapper.selectById(orderPayRequest.getShopId()); |
| | | if(Objects.isNull(shop)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"请选择正确的自提门店!"); |
| | | } |
| | | |
| | | |
| | | //根据选择商户进行会员与商户信息绑定 |
| | | if(Objects.isNull(member.getBindShopId())){ |
| | |
| | | member.setBindShopId(shop.getId()); |
| | | } |
| | | } |
| | | |
| | | //单据编号 自增 |
| | | goodsorder.setCode(getNextInCode()); |
| | | //计算订单总金额 |
| | | BigDecimal sumPrice = BigDecimal.ZERO; |
| | | |
| | | //存储记录明细 |
| | | OrderPayConfirmResponse orderPayConfirmResponse = this.orderPayConfirm(orderPayRequest.getReceiveType(),orderPayRequest.getPayDetailRequestList(),orderPayRequest.getAddressId(),memberCouponService,member.getId()); |
| | | OrderPayConfirmRequest payConfirmRequest = new OrderPayConfirmRequest(); |
| | | payConfirmRequest.setReceiveType(orderPayRequest.getReceiveType()); |
| | | payConfirmRequest.setPayDetailRequestList(orderPayRequest.getPayDetailRequestList()); |
| | | payConfirmRequest.setAddressId(orderPayRequest.getAddressId()); |
| | | payConfirmRequest.setMemberId(member.getId()); |
| | | payConfirmRequest.setCouponId(orderPayRequest.getCouponId()); |
| | | //通过支付确认接口获取生成支付信息 |
| | | OrderPayConfirmResponse orderPayConfirmResponse = this.orderPayConfirm(payConfirmRequest,memberCouponService); |
| | | if(Objects.isNull(orderPayConfirmResponse)){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"系统支付错误,请联系管理员"); |
| | | } |
| | |
| | | goodsorder.setUseIntegral(orderPayConfirmResponse.getDeductIntegral()); |
| | | goodsorder.setIntegral(goodsorder.getUseIntegral()); |
| | | goodsorder.setIntegralPrice(orderPayConfirmResponse.getIntegralAmount()); |
| | | |
| | | goodsorder.setMailPrice(orderPayConfirmResponse.getMailAmount()); |
| | | goodsorder.setPayMethod(goodsorder.getPrice().compareTo(BigDecimal.ZERO)>Constants.ZERO?Constants.ZERO:Constants.ONE); |
| | | if(Objects.nonNull(orderPayConfirmResponse.getMemberCoupon())){ |
| | | MemberCoupon memberCoupon = memberCouponMapper.selectById(orderPayConfirmResponse.getMemberCoupon().getId()); |
| | | if(Objects.isNull(memberCoupon)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到优惠券信息!"); |
| | | } |
| | | if(memberCoupon.getStatus().equals(Constants.ONE)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"优惠券已使用!"); |
| | | } |
| | | sumPrice = sumPrice.subtract(memberCoupon.getPrice()); |
| | | goodsorder.setCouponId(memberCoupon.getId()); |
| | | sumPrice = sumPrice.subtract(orderPayConfirmResponse.getMemberCoupon().getPrice()); |
| | | goodsorder.setCouponId(orderPayConfirmResponse.getMemberCoupon().getId()); |
| | | goodsorder.setCouponPrice(orderPayConfirmResponse.getMemberCoupon().getValidAmount()); |
| | | |
| | | memberCouponMapper.update(null,new UpdateWrapper<MemberCoupon>().lambda() |
| | | .set(MemberCoupon::getStatus,Constants.ONE) |
| | | .set(MemberCoupon::getUseDate,DateUtil.getCurrDateTime()) |
| | | .eq(MemberCoupon::getId,memberCoupon.getId()) |
| | | .eq(MemberCoupon::getId,orderPayConfirmResponse.getMemberCoupon().getId()) |
| | | ); |
| | | } |
| | | |
| | | goodsorderMapper.insert(goodsorder); |
| | | List<OrderGoodsCalculateResponse> goodsCalculateList = orderPayConfirmResponse.getGoodsCalculateList(); |
| | | if(CollectionUtils.isEmpty(goodsCalculateList)){ |
| | |
| | | .last(" limit 1 ") |
| | | ); |
| | | if(Objects.isNull(shopGoodsRelation)){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,关联经销商未绑定["+goods.getName()+"]商品,请联系管理员!"); |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,经销商未绑定["+goods.getName()+"]商品,请联系管理员!"); |
| | | } |
| | | goodsOrderDetail.setShopSettlement(shopGoodsRelation.getPrice()); |
| | | |
| | | PlatformConfigDTO platformConfigDTO = systemDictDataService.getPlatformConfigDTO(); |
| | | //经销商优惠承担占比 |
| | | BigDecimal shopRate = new BigDecimal("100").subtract(platformConfigDTO.getTotalRate()); |
| | | //计算经销商优惠承担金额 (优惠券抵扣金额 + 积分抵扣金额) * 占比比例 |
| | | BigDecimal shopDeductAmount = payDetailRequest.getCouponDeductCash().add(payDetailRequest.getIntegralDeductCash()) |
| | | .multiply(shopRate).divide(new BigDecimal("100"),2, RoundingMode.HALF_UP); |
| | | //根据经销商销售模式 计算应结算金额 |
| | | if(shop.getSaleType().equals(Constants.ONE)){ |
| | | goodsOrderDetail.setShopSettlement(goodsOrderDetail.getPrice().subtract(shopDeductAmount)); |
| | | }else { |
| | | goodsOrderDetail.setShopSettlement( |
| | | shopGoodsRelation.getPrice().subtract(shopGoodsRelation.getPrice()).subtract(shopDeductAmount)); |
| | | } |
| | | if(goodsOrderDetail.getShopSettlement().compareTo(BigDecimal.ZERO)<Constants.ZERO){ |
| | | goodsOrderDetail.setShopSettlement(BigDecimal.ZERO); |
| | | } |
| | | }else{ |
| | | goodsOrderDetail.setShopSettlement(BigDecimal.ZERO); |
| | | } |
| | | goodsOrderDetailList.add(goodsOrderDetail); |
| | | //删除购物车商品 |
| | |
| | | if(goodsorder.getPrice().compareTo(orderPayRequest.getTitlePrice())!=Constants.ZERO){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"商品价格发生变化,请刷新后重新支付!"); |
| | | } |
| | | |
| | | return this.wxPay(goodsorder,member); |
| | | //存在现金支付 |
| | | if(Constants.equalsInteger(goodsorder.getPayMethod(),Constants.ZERO)){ |
| | | return this.wxPay(goodsorder,member); |
| | | } |
| | | //无现金支付 |
| | | goodsorderMapper.update(null,new UpdateWrapper<Goodsorder>().lambda() |
| | | .set(Goodsorder::getStatus,Constants.ONE) |
| | | .set(Goodsorder::getPayStatus,Constants.OrderStatus.PAY_DONE.getKey()) |
| | | .set(Goodsorder::getPayDate,DateUtil.getCurrDateTime()) |
| | | .set(Goodsorder::getId,goodsorder.getId()) |
| | | ); |
| | | PayResponse payResponse = new PayResponse(); |
| | | payResponse.setOrderId(goodsorder.getId()); |
| | | payResponse.setPayType(Constants.ONE); |
| | | return payResponse; |
| | | } |
| | | |
| | | |
| | | public void shopBalance(GoodsorderDetail detail,Shop shop){ |
| | | if(Objects.isNull(shop)){ |
| | | detail.setShopSettlement(BigDecimal.ZERO); |
| | | return; |
| | | } |
| | | PlatformConfigDTO platformConfigDTO = systemDictDataService.getPlatformConfigDTO(); |
| | | //经销商优惠承担占比 |
| | | BigDecimal shopRate = new BigDecimal("100").subtract(platformConfigDTO.getTotalRate()); |
| | | |
| | | ShopGoodsRelation shopGoodsRelation = shopGoodsRelationMapper.selectOne(new QueryWrapper<ShopGoodsRelation>().lambda() |
| | | .eq(ShopGoodsRelation::getIsdeleted,Constants.ZERO) |
| | | .eq(ShopGoodsRelation::getStatus,Constants.ZERO) |
| | | .eq(ShopGoodsRelation::getShopId,shop.getId()) |
| | | .eq(ShopGoodsRelation::getGoodsSkuId,detail.getGoodsSkuId()) |
| | | .last(" limit 1 ") |
| | | ); |
| | | if(Objects.isNull(shopGoodsRelation)){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,关联经销商未绑定["+detail.getName()+"]商品,请联系管理员!"); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 重新支付 |
| | |
| | | PayResponse payResponse = new PayResponse(); |
| | | payResponse.setResponse(response); |
| | | payResponse.setOrderId(goodsorder.getId()); |
| | | payResponse.setPayType(Constants.ZERO); |
| | | return payResponse; |
| | | } catch (WxPayException e) { |
| | | e.printStackTrace(); |
| | |
| | | |
| | | /** |
| | | * 订单确认接口 |
| | | * @param receiveType 0=快递配送 1=自提 |
| | | * @param requestList |
| | | * @param addressId |
| | | * @param memberCouponService |
| | | * @param memberId |
| | | * @param request |
| | | */ |
| | | public OrderPayConfirmResponse orderPayConfirm(Integer receiveType,List<PayDetailRequest> requestList,Integer addressId, |
| | | MemberCouponServiceImpl memberCouponService,Integer memberId){ |
| | | @Override |
| | | public OrderPayConfirmResponse orderPayConfirm(OrderPayConfirmRequest request, |
| | | MemberCouponServiceImpl memberCouponService){ |
| | | OrderPayConfirmResponse orderPayConfirmResponse = new OrderPayConfirmResponse(); |
| | | List<Goods> goodsList = goodsMapper.selectJoinList(Goods.class, |
| | | new MPJLambdaWrapper<Goods>() |
| | |
| | | .selectAs(GoodsSku::getWeight,Goods::getWeight) |
| | | .selectAs(GoodsSku::getImgurl,Goods::getSkuImg) |
| | | .leftJoin(GoodsSku.class,GoodsSku::getGoodsId,Goods::getId) |
| | | .in(GoodsSku::getId,requestList.stream().map(i->i.getGoodsSkuId()).collect(Collectors.toList()))); |
| | | .in(GoodsSku::getId,request.getPayDetailRequestList().stream().map(i->i.getGoodsSkuId()).collect(Collectors.toList()))); |
| | | if(CollectionUtils.isEmpty(goodsList)){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"未匹配到商品信息"); |
| | | } |
| | | |
| | | List<OrderGoodsCalculateResponse> goodsCalculateList = ListUtil.copyProperties(goodsList,OrderGoodsCalculateResponse::new); |
| | | |
| | | //订单总金额 |
| | |
| | | //邮费金额 |
| | | BigDecimal mailAmount = BigDecimal.ZERO; |
| | | for (OrderGoodsCalculateResponse response:goodsCalculateList) { |
| | | List<PayDetailRequest> request = requestList.stream().filter(i->Constants.equalsInteger(i.getGoodsSkuId(), response.getSkuId())).collect(Collectors.toList()); |
| | | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(request)){ |
| | | PayDetailRequest payDetailRequest = request.get(Constants.ZERO); |
| | | List<PayDetailRequest> payDetailRequestList = request.getPayDetailRequestList().stream() |
| | | .filter(i->Constants.equalsInteger(i.getGoodsSkuId(), response.getSkuId())).collect(Collectors.toList()); |
| | | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(payDetailRequestList)){ |
| | | PayDetailRequest payDetailRequest = payDetailRequestList.get(Constants.ZERO); |
| | | response.setSkuAmount(response.getSkuPrice().multiply(new BigDecimal(payDetailRequest.getGoodsNum()+""))); |
| | | response.setGoodsNum(payDetailRequest.getGoodsNum()); |
| | | amount = amount.add(response.getSkuAmount()); |
| | | } |
| | | } |
| | | //获取优惠券优惠金额 |
| | | List<MemberCoupon> memberCouponList = memberCouponService.getApplyCoupon(requestList,memberId); |
| | | MemberCoupon memberCoupon = new MemberCoupon(); |
| | | orderPayConfirmResponse.setCouponAmount(couponAmount); |
| | | //获取可以使用的优惠券 |
| | | List<MemberCoupon> memberCouponList = memberCouponService.getApplyCoupon(request.getPayDetailRequestList(),request.getMemberId()); |
| | | if(CollectionUtils.isNotEmpty(memberCouponList)){ |
| | | memberCoupon = memberCouponList.get(Constants.ZERO); |
| | | couponAmount = memberCoupon.getValidAmount(); |
| | | memberCouponService.calculateCouponRata(memberCoupon,goodsCalculateList,amount); |
| | | orderPayConfirmResponse.setMemberCoupon(memberCoupon); |
| | | } |
| | | //积分抵扣金额 |
| | | //查询用户总积分 |
| | | Member member = memberMapper.selectById(memberId); |
| | | //积分大于0 且大于可用积分配置项 才可以使用 |
| | | if(member.getIntegral().compareTo(BigDecimal.ZERO)>Constants.ZERO){ |
| | | //最低可用启用积分 |
| | | BigDecimal minimumIntegral = new BigDecimal(systemDictDataBiz.queryByCode(Constants.SHOP_CONFIG,Constants.MINIMUM_AVAILABLE_INTEGRAL).getCode()); |
| | | if(member.getIntegral().compareTo(minimumIntegral)>=Constants.ZERO){ |
| | | this.calculateIntegralRata(goodsCalculateList,member.getIntegral()); |
| | | orderPayConfirmResponse.setMemberCouponList(memberCouponList); |
| | | //如果选择了优惠券,则判断选择的优惠券是否有效 |
| | | if(Objects.nonNull(request.getCouponId())){ |
| | | List<MemberCoupon> memberCoupons = memberCouponList.stream().filter(i->Constants.equalsInteger(i.getId(),request.getCouponId())).collect(Collectors.toList()); |
| | | if(CollectionUtils.isEmpty(memberCoupons)){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"选择的优惠券无效,请刷新重试"); |
| | | } |
| | | memberCoupon = memberCouponList.get(Constants.ZERO); |
| | | couponAmount = memberCoupon.getValidAmount(); |
| | | memberCouponService.calculateCouponRata(memberCoupon,goodsCalculateList,amount); |
| | | orderPayConfirmResponse.setMemberCoupon(memberCoupon); |
| | | } |
| | | }else { |
| | | if(Objects.nonNull(request.getCouponId())){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"无可用优惠券,请刷新查看"); |
| | | } |
| | | } |
| | | //邮费金额 |
| | | if(Constants.equalsInteger(receiveType,Constants.ZERO)){ |
| | | //TODO 根据收货地址 查询运费配置 |
| | | |
| | | //计算商品信息总重量 |
| | | BigDecimal totalWeight = goodsCalculateList.stream().map(i-> |
| | | i.getWeight().multiply(new BigDecimal(i.getGoodsNum().toString())) |
| | | ).reduce(BigDecimal.ZERO,BigDecimal::add); |
| | | |
| | | } |
| | | |
| | | orderPayConfirmResponse.setAmount(amount); |
| | | orderPayConfirmResponse.setCouponAmount(couponAmount); |
| | | orderPayConfirmResponse.setDeductIntegral(deductIntegral); |
| | | orderPayConfirmResponse.setMailAmount(mailAmount); |
| | | orderPayConfirmResponse.setIntegralAmount(integralAmount); |
| | | orderPayConfirmResponse.setPayAmount(amount.subtract(couponAmount).subtract(mailAmount).subtract(integralAmount)); |
| | | orderPayConfirmResponse.setGoodsCalculateList(goodsCalculateList); |
| | | BigDecimal cashToIntegralRata = new BigDecimal(systemDictDataBiz.queryByCode(Constants.SHOP_CONFIG,Constants.CASH_EXCHANGE_INTEGRAL_RATA).getCode()); |
| | | orderPayConfirmResponse.setIntegralBack( |
| | | orderPayConfirmResponse.getPayAmount().multiply(cashToIntegralRata) |
| | | //查询用户总积分 |
| | | Member member = memberMapper.selectById(request.getMemberId()); |
| | | //最低可用启用积分 |
| | | BigDecimal minimumIntegral = new BigDecimal(systemDictDataBiz.queryByCode(Constants.SHOP_CONFIG,Constants.MINIMUM_AVAILABLE_INTEGRAL).getCode()); |
| | | //积分可使用状态 大于0 大于最小可用配置积分值 |
| | | orderPayConfirmResponse.setIntegralStatus( |
| | | (member.getIntegral().compareTo(BigDecimal.ZERO)<=Constants.ZERO|| |
| | | member.getIntegral().compareTo(minimumIntegral)<Constants.ZERO)?Constants.ONE:Constants.ZERO |
| | | ); |
| | | |
| | | orderPayConfirmResponse.setDeductIntegral(deductIntegral); |
| | | orderPayConfirmResponse.setIntegralAmount(integralAmount); |
| | | if(Constants.equalsInteger(orderPayConfirmResponse.getIntegralStatus(),Constants.ZERO)){ |
| | | integralAmount = this.calculateIntegralRata(orderPayConfirmResponse,goodsCalculateList,member.getIntegral()); |
| | | } |
| | | |
| | | //邮费金额 |
| | | if(Objects.nonNull(request.getReceiveType())){ |
| | | if(Constants.equalsInteger(request.getReceiveType(),Constants.ZERO)){ |
| | | //TODO 根据收货地址 查询运费配置 |
| | | //计算商品信息总重量 |
| | | BigDecimal totalWeight = goodsCalculateList.stream().map(i-> |
| | | i.getWeight().multiply(new BigDecimal(i.getGoodsNum().toString())) |
| | | ).reduce(BigDecimal.ZERO,BigDecimal::add); |
| | | //TODO 暂时无运费金额 |
| | | mailAmount = BigDecimal.ZERO; |
| | | |
| | | amount = amount.add(mailAmount); |
| | | } |
| | | } |
| | | orderPayConfirmResponse.setAmount(amount); |
| | | orderPayConfirmResponse.setMailAmount(mailAmount); |
| | | //使用积分 减去积分抵扣金额 |
| | | if(Constants.equalsInteger(request.getUseIntegral(), Constants.ONE)){ |
| | | orderPayConfirmResponse.setIntegralAmount(integralAmount); |
| | | } |
| | | //使用优惠券 减去优惠券抵扣金额 |
| | | if(Objects.nonNull(request.getCouponId())){ |
| | | orderPayConfirmResponse.setCouponAmount(couponAmount); |
| | | } |
| | | //实际支付金额 减去优惠券、积分抵扣金额 |
| | | orderPayConfirmResponse.setPayAmount(amount.subtract(couponAmount).subtract(orderPayConfirmResponse.getIntegralAmount())); |
| | | orderPayConfirmResponse.setGoodsCalculateList(goodsCalculateList); |
| | | |
| | | orderPayConfirmResponse.setIntegralBack(getBackIntegral(orderPayConfirmResponse.getPayAmount(),Constants.ZERO)); |
| | | return orderPayConfirmResponse; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * |
| | | * 计算赠送积分数量 |
| | | * @param payAmount |
| | | * @param type 0=消费者积分 1=经销商积分 |
| | | * @return |
| | | */ |
| | | public BigDecimal getBackIntegral(BigDecimal payAmount,Integer type){ |
| | | BigDecimal integralBack = BigDecimal.ZERO; |
| | | if(payAmount.compareTo(BigDecimal.ZERO)<=Constants.ZERO){ |
| | | return integralBack; |
| | | } |
| | | PlatformConfigDTO platformConfigDTO = systemDictDataService.getPlatformConfigDTO(); |
| | | if(Objects.isNull(platformConfigDTO)){ |
| | | return integralBack; |
| | | } |
| | | if(Constants.equalsInteger(type,Constants.ZERO)){ |
| | | if( Constants.equalsInteger(platformConfigDTO.getReturnMemberIntegralStatus(),Constants.ZERO) |
| | | && Objects.nonNull(platformConfigDTO.getReturnMemberIntegral())){ |
| | | integralBack = payAmount.divide(platformConfigDTO.getReturnMemberIntegral(),0,BigDecimal.ROUND_DOWN); |
| | | } |
| | | }else{ |
| | | if( Constants.equalsInteger(platformConfigDTO.getReturnShopIntegralStatus(),Constants.ZERO) |
| | | && Objects.nonNull(platformConfigDTO.getReturnShopIntegral())){ |
| | | integralBack = payAmount.divide(platformConfigDTO.getReturnShopIntegral(),0,BigDecimal.ROUND_DOWN); |
| | | } |
| | | } |
| | | return integralBack; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 计算积分抵扣信息 |
| | | * @param goodsCalculateList 商品集合 |
| | | * @param totalIntegral 用户总积分 |
| | | */ |
| | | public void calculateIntegralRata(List<OrderGoodsCalculateResponse> goodsCalculateList,BigDecimal totalIntegral){ |
| | | public BigDecimal calculateIntegralRata(OrderPayConfirmResponse orderPayConfirmResponse,List<OrderGoodsCalculateResponse> goodsCalculateList,BigDecimal totalIntegral){ |
| | | //当前选择商品最大可用积分抵扣的金额 |
| | | BigDecimal maxDeductionCash = goodsCalculateList.stream().map(i->i.getSkuAmount().subtract(i.getCouponDeductCash()) |
| | | .multiply(i.getDeductRata())).reduce(BigDecimal.ZERO,BigDecimal::add); |
| | | .multiply(i.getDeductRata()).multiply(new BigDecimal("0.01"))).reduce(BigDecimal.ZERO,BigDecimal::add); |
| | | //积分 - 现金 比例 |
| | | BigDecimal cashToIntegralRata = new BigDecimal(systemDictDataBiz.queryByCode(Constants.SHOP_CONFIG,Constants.INTEGRAL_EXCHANGE_CASH_RATA).getCode()); |
| | | //当前选择商品抵扣需要使用的积分 |
| | | BigDecimal maxDeductionIntegral = maxDeductionCash.multiply(cashToIntegralRata).multiply(new BigDecimal("100")); |
| | | BigDecimal deductionRata = BigDecimal.ONE; |
| | | //获取当前需要支付的现金总额 |
| | | BigDecimal payCash = goodsCalculateList.stream().map(i->i.getSkuAmount().subtract(i.getCouponDeductCash())).reduce(BigDecimal.ZERO,BigDecimal::add); |
| | | |
| | | //如果实际积分少于最大需要积分 需要计算比例占比 去对应添加至对应的商品里 |
| | | if(totalIntegral.compareTo(maxDeductionIntegral)<=Constants.ZERO) { |
| | | deductionRata = totalIntegral.divide(maxDeductionIntegral, 2, BigDecimal.ROUND_HALF_UP); |
| | | } |
| | | //获取总的抵扣金额 与 每个商品可抵扣金额 |
| | | //已用占比比例值 |
| | | BigDecimal rata = BigDecimal.ZERO; |
| | | //剩余可分配金额 |
| | | BigDecimal surplusValidAmount = maxDeductionCash; |
| | | //循环下单商品列表 计算应该使用的积分值 |
| | | BigDecimal realDeductionCash = BigDecimal.ZERO; |
| | | for (int j = 0; j < goodsCalculateList.size(); j++) { |
| | | if(Constants.equalsInteger(j+1,goodsCalculateList.size())){ |
| | | goodsCalculateList.get(j).setIntegralMaxDeductCash(surplusValidAmount); |
| | | goodsCalculateList.get(j).setOrderIntegralRata(new BigDecimal("1").subtract(rata)); |
| | | }else{ |
| | | //积分最大可抵扣金额 |
| | | goodsCalculateList.get(j).setIntegralMaxDeductCash( |
| | | goodsCalculateList.get(j).getSkuAmount() |
| | | .subtract(goodsCalculateList.get(j).getCouponDeductCash()) |
| | | .multiply(goodsCalculateList.get(j).getDeductRata())); |
| | | //订单中积分金额实际占比 |
| | | goodsCalculateList.get(j).setOrderIntegralRata( |
| | | goodsCalculateList.get(j) |
| | | .getIntegralMaxDeductCash().divide(maxDeductionCash,2,BigDecimal.ROUND_DOWN) |
| | | ); |
| | | rata = rata.add(goodsCalculateList.get(j).getOrderIntegralRata()); |
| | | surplusValidAmount = surplusValidAmount.subtract(goodsCalculateList.get(j).getIntegralMaxDeductCash()); |
| | | BigDecimal deductionCash = goodsCalculateList.get(j).getSkuAmount().subtract(goodsCalculateList.get(j).getCouponDeductCash()); |
| | | goodsCalculateList.get(j).setIntegralMaxDeductCash(deductionCash); |
| | | //如果剩余积分大于可以使用积分 则直接满额计算 反之 剩余积分不能满足全部抵扣 单独计算每个商品占比 |
| | | if(totalIntegral.compareTo(maxDeductionIntegral)<Constants.ZERO){ |
| | | deductionCash = deductionCash.divide(payCash).multiply(totalIntegral); |
| | | } |
| | | //如果用户积分大于本次需要使用的最大积分 则直接使用否则需要重新计算 |
| | | goodsCalculateList.get(j).setIntegralDeductCash(goodsCalculateList.get(j).getIntegralMaxDeductCash().multiply(deductionRata)); |
| | | goodsCalculateList.get(j).setIntegralDeduct(goodsCalculateList.get(j).getIntegralMaxDeductCash().multiply(cashToIntegralRata).multiply(deductionRata)); |
| | | goodsCalculateList.get(j).setIntegralDeductCash(deductionCash); |
| | | realDeductionCash = realDeductionCash.add(deductionCash); |
| | | } |
| | | //剩余积分值 |
| | | orderPayConfirmResponse.setSurplusIntegral(totalIntegral); |
| | | //实际抵扣使用积分 |
| | | orderPayConfirmResponse.setDeductIntegral(totalIntegral.compareTo(maxDeductionCash)<=Constants.ZERO?totalIntegral:maxDeductionIntegral); |
| | | return realDeductionCash; |
| | | |
| | | } |
| | | |
| | |
| | | goodsorder.setStatus(Constants.OrderStatus.DONE.getKey()); |
| | | goodsorder.setDoneDate(new Date()); |
| | | goodsorderMapper.updateById(goodsorder); |
| | | //经销商分销 添加分销金额记录 |
| | | this.addShopIntegral(goodsorder); |
| | | //根据订单类型进行积分赠送 |
| | | //下单确认收货 ,赠送经销商积分 |
| | | this.orderAddShopIntegral(goodsorder); |
| | | //消费者确认收货 |
| | | this.orderAddMemberIntegral(goodsorder); |
| | | //经销商 结算金额 |
| | | this.orderAddShopCash(goodsorder); |
| | | } |
| | | |
| | | /** |
| | | * 订单核销 |
| | | * @param code |
| | | * @param |
| | | * @param memberId |
| | | */ |
| | | @Override |
| | |
| | | if(!goodsorder.getStatus().equals(Constants.OrderStatus.PAY_DONE.getKey())){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"操作失败:订单状态已流转,无法进行该操作!"); |
| | | } |
| | | Shop shop = shopMapper.selectById(goodsorder.getPickUpShopId());/*selectOne(new QueryWrapper<Shop>().lambda().eq(Shop::getMemberId,memberId) |
| | | .eq(Shop::getIsdeleted,Constants.ZERO).last("limit 1 ") |
| | | );*/ |
| | | Shop shop = shopMapper.selectById(goodsorder.getPickUpShopId()); |
| | | if(Objects.isNull(shop)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到订单关联经销商信息,请联系管理员"); |
| | | } |
| | |
| | | goodsorder.setStatus(Constants.OrderStatus.DONE.getKey()); |
| | | goodsorder.setDoneDate(new Date()); |
| | | goodsorderMapper.updateById(goodsorder); |
| | | //经销商分销 添加分销金额记录 |
| | | this.addShopIntegral(goodsorder); |
| | | //存在现金支付 赠送 积分 |
| | | if(Constants.equalsInteger(goodsorder.getPayMethod(),Constants.ZERO)){ |
| | | //赠送消费者积分 |
| | | this.orderAddMemberIntegral(goodsorder); |
| | | //经销商 添加赠送积分 |
| | | this.orderAddShopIntegral(goodsorder); |
| | | //经销商 结算金额 |
| | | this.orderAddShopCash(goodsorder); |
| | | } |
| | | } |
| | | |
| | | |
| | | public void addShopIntegral(Goodsorder goodsorder){ |
| | | if(Objects.isNull(goodsorder.getDistributionShopId())){ |
| | | /** |
| | | * 赠送经销商下单积分 |
| | | * @param goodsorder |
| | | */ |
| | | public void orderAddShopIntegral(Goodsorder goodsorder){ |
| | | if(Objects.isNull(goodsorder.getDistributionShopId()) || Constants.equalsInteger(goodsorder.getPayMethod(),Constants.ONE)){ |
| | | return; |
| | | } |
| | | List<GoodsorderDetail> detailList = goodsorderDetailMapper.selectList(new QueryWrapper<GoodsorderDetail>().lambda() |
| | | .eq(GoodsorderDetail::getOrderId,goodsorder.getId()) |
| | | .isNotNull(GoodsorderDetail::getShopSettlement) |
| | | ); |
| | | if(CollectionUtils.isNotEmpty(detailList)){ |
| | | BigDecimal settlement = detailList.stream().map(i->i.getShopSettlement()).reduce(BigDecimal.ZERO,BigDecimal::add); |
| | | BigDecimal backIntegral = getBackIntegral(goodsorder.getPrice(),Constants.ONE); |
| | | if (backIntegral.compareTo(BigDecimal.ZERO) >= 0) { |
| | | //更新余额信息 添加积分变动记录 |
| | | DealIntegralRequest dealIntegralRequest = new DealIntegralRequest(); |
| | | dealIntegralRequest.setIntegralNum(backIntegral); |
| | | dealIntegralRequest.setDealType(Constants.ZERO); |
| | | dealIntegralRequest.setMemberId(goodsorder.getDistributionShopId()); |
| | | dealIntegralRequest.setObjId(goodsorder.getId()); |
| | | dealIntegralRequest.setOrderCode(goodsorder.getCode().toString()); |
| | | dealIntegralRequest.setIntegralObjType(Constants.IntegralObjType.ORDER_DONATE); |
| | | integralService.dealShopIntegral(dealIntegralRequest); |
| | | } |
| | | } |
| | | |
| | | public void orderAddShopCash(Goodsorder goodsorder){ |
| | | if(Objects.isNull(goodsorder.getDistributionShopId()) || Constants.equalsInteger(goodsorder.getPayMethod(),Constants.ONE)){ |
| | | return; |
| | | } |
| | | List<GoodsorderDetail> goodsorderDetails = goodsorderDetailMapper.selectList(new QueryWrapper<GoodsorderDetail>().lambda() |
| | | .eq(GoodsorderDetail::getOrderId,goodsorder.getId()) |
| | | ); |
| | | BigDecimal settlement = goodsorderDetails.stream().map(i->i.getShopSettlement()).reduce(BigDecimal.ZERO,BigDecimal::add); |
| | | if(settlement.compareTo(BigDecimal.ZERO)>Constants.ZERO ){ |
| | | DealIntegralRequest dealIntegralRequest = new DealIntegralRequest(); |
| | | dealIntegralRequest.setIntegralNum(settlement); |
| | | dealIntegralRequest.setDealType(Constants.ZERO); |
| | | dealIntegralRequest.setMemberId(goodsorder.getDistributionShopId()); |
| | | dealIntegralRequest.setObjId(goodsorder.getId()); |
| | | dealIntegralRequest.setOrderCode(goodsorder.getCode().toString()); |
| | | dealIntegralRequest.setIntegralObjType(Constants.IntegralObjType.SHOP_ORDER_SETTLEMENT); |
| | | integralService.dealShopIntegral(dealIntegralRequest); |
| | | dealIntegralRequest.setIntegralObjType(Constants.IntegralObjType.ORDER_DONE_AMOUNT); |
| | | integralService.dealShopAmount(dealIntegralRequest); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 赠送消费者下单积分 |
| | | * @param goodsorder |
| | | */ |
| | | public void orderAddMemberIntegral(Goodsorder goodsorder){ |
| | | if(Constants.equalsInteger(goodsorder.getPayMethod(),Constants.ONE)){ |
| | | return; |
| | | } |
| | | BigDecimal backIntegral = getBackIntegral(goodsorder.getPrice(),Constants.ZERO); |
| | | if (backIntegral.compareTo(BigDecimal.ZERO) >= 0) { |
| | | //更新余额信息 添加积分变动记录 |
| | | DealIntegralRequest dealIntegralRequest = new DealIntegralRequest(); |
| | | dealIntegralRequest.setIntegralNum(backIntegral); |
| | | dealIntegralRequest.setDealType(Constants.ZERO); |
| | | dealIntegralRequest.setMemberId(goodsorder.getDistributionShopId()); |
| | | dealIntegralRequest.setObjId(goodsorder.getId()); |
| | | dealIntegralRequest.setOrderCode(goodsorder.getCode().toString()); |
| | | dealIntegralRequest.setIntegralObjType(Constants.IntegralObjType.ORDER_DONATE); |
| | | integralService.dealIntegral(dealIntegralRequest); |
| | | } |
| | | } |
| | | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |