| | |
| | | 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.business.NoticeService; |
| | | import com.doumee.service.system.SystemDictDataService; |
| | | import com.github.binarywang.wxpay.bean.request.BaseWxPayRequest; |
| | | import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest; |
| | |
| | | private MemberMapper memberMapper; |
| | | @Autowired |
| | | private CouponMapper couponMapper; |
| | | @Autowired |
| | | private NoticeService noticeService; |
| | | @Autowired |
| | | private NoticeMapper noticeMapper; |
| | | @Autowired |
| | | private MemberCouponJoinMapper memberCouponJoinMapper; |
| | | @Autowired |
| | |
| | | |
| | | /****************************************移动端接口开始********************************************************************/ |
| | | |
| | | |
| | | @Transactional(rollbackFor = {Exception.class,BusinessException.class}) |
| | | public PayResponse orderPay(OrderPayRequest orderPayRequest){ |
| | | Member member = memberMapper.selectById(orderPayRequest.getMemberId()); |
| | | //查询收货地址 |
| | | Addr addr = addrMapper.selectById(orderPayRequest.getAddressId()); |
| | | if(Objects.isNull(addr)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到收货地址信息!"); |
| | | } |
| | | Areas area = areasService.findById(addr.getAreaId(), Constants.TWO); |
| | | if(Objects.isNull(area)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"收货地址区划信息发生变化,请更新后下单!"); |
| | | } |
| | | Goodsorder goodsorder = new Goodsorder(); |
| | | goodsorder.setCreator(orderPayRequest.getMemberId()); |
| | | goodsorder.setIntegral(BigDecimal.ZERO); |
| | | goodsorder.setCreateDate(new Date()); |
| | | goodsorder.setIsdeleted(Constants.ZERO); |
| | | goodsorder.setMemberInfo(orderPayRequest.getRemark()); |
| | | goodsorder.setAddrId(addr.getId()); |
| | | goodsorder.setLinkaddr(area.getProvinceName()+area.getCityName() + area.getName() + addr.getAddr()); |
| | | goodsorder.setLinkphone(addr.getPhone()); |
| | | goodsorder.setLinkname(addr.getName()); |
| | | goodsorder.setMemberId(member.getId()); |
| | | goodsorder.setType(orderPayRequest.getOrderType()); |
| | | //单据编号 自增 |
| | | goodsorder.setCode(getNextInCode()); |
| | | //计算订单总金额 |
| | | BigDecimal sumPrice = BigDecimal.ZERO; |
| | | //存储记录明细 |
| | | List<PayDetailRequest> payDetailRequestList = orderPayRequest.getPayDetailRequestList(); |
| | | if(Objects.isNull(payDetailRequestList)||payDetailRequestList.size()==Constants.ZERO){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"无明细数据,请检查选择数据!"); |
| | | } |
| | | List<GoodsorderDetail> goodsOrderDetailList = new ArrayList<>(); |
| | | for (PayDetailRequest payDetailRequest:payDetailRequestList) { |
| | | //查询商品 |
| | | GoodsSku goodsSku = goodsSkuMapper.selectById(payDetailRequest.getGoodsSkuId()); |
| | | if(Objects.isNull(goodsSku)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到商品SKU信息!"); |
| | | } |
| | | Goods goods = goodsMapper.selectById(goodsSku.getGoodsId()); |
| | | if(Objects.isNull(goods)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到商品信息!"); |
| | | } |
| | | if(goods.getStatus().equals(Constants.ONE)){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"存在商品已删除或已下架,无法下单"); |
| | | } |
| | | if(goodsSku.getStock().compareTo(new BigDecimal(Constants.formatIntegerNum(payDetailRequest.getGoodsNum())))<Constants.ZERO){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"存在商品库存不足,无法下单!"); |
| | | } |
| | | //商品库存扣除 |
| | | goodsSku.setStock(goodsSku.getStock().subtract(new BigDecimal(Constants.formatIntegerNum(payDetailRequest.getGoodsNum())))); |
| | | goodsSkuMapper.updateById(goodsSku); |
| | | GoodsorderDetail goodsOrderDetail = new GoodsorderDetail(); |
| | | goodsOrderDetail.setCreator(member.getId()); |
| | | goodsOrderDetail.setCreateDate(new Date()); |
| | | goodsOrderDetail.setImgurl(StringUtils.isBlank(goodsSku.getImgurl())?goods.getImgurl():goodsSku.getImgurl()); |
| | | goodsOrderDetail.setName(goods.getName()); |
| | | goodsOrderDetail.setGoodsSkuId(goodsSku.getId().toString()); |
| | | goodsOrderDetail.setSkuName(goodsSku.getName()); |
| | | goodsOrderDetail.setPrice(goodsSku.getPrice()); |
| | | goodsOrderDetail.setGoodsNum(payDetailRequest.getGoodsNum()); |
| | | goodsOrderDetailList.add(goodsOrderDetail); |
| | | sumPrice = sumPrice.add(goodsSku.getPrice().multiply(new BigDecimal(payDetailRequest.getGoodsNum()))); |
| | | //购物车支付 删除购物车商品 |
| | | if(orderPayRequest.getIsShopChart().equals(Constants.ONE)){ |
| | | shopcartMapper.deleteById(payDetailRequest.getShopCartId()); |
| | | } |
| | | } |
| | | |
| | | //订单支付现金金额 |
| | | goodsorder.setPrice((sumPrice.subtract(orderPayRequest.getDeductionBalance()))); |
| | | MemberCoupon memberCoupon = new MemberCoupon(); |
| | | if(!Objects.isNull(orderPayRequest.getCouponId())){ |
| | | memberCoupon = memberCouponMapper.selectById(orderPayRequest.getCouponId()); |
| | | if(Objects.isNull(memberCoupon)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到优惠券信息!"); |
| | | } |
| | | if(sumPrice.compareTo(memberCoupon.getLimitPrice())<Constants.ZERO){ |
| | | 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(orderPayRequest.getCouponId()); |
| | | goodsorder.setCouponPrice(memberCoupon.getPrice()); |
| | | } |
| | | |
| | | goodsorder.setCode(getNextInCode()); |
| | | if(!Objects.isNull(memberCoupon)){ |
| | | memberCoupon.setStatus(Constants.ONE); |
| | | memberCouponMapper.updateById(memberCoupon); |
| | | } |
| | | //咖豆商城订单 单独处理 扣减积分 添加积分变动记录 |
| | | if(orderPayRequest.getOrderType().equals(Constants.ONE)){ |
| | | if(member.getIntegral().compareTo(sumPrice)<=Constants.ZERO){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "咖豆不足,无法兑换!"); |
| | | } |
| | | goodsorder.setStatus(Constants.OrderStatus.PAY_DONE.getKey()); |
| | | goodsorder.setPayStatus(Constants.ZERO); |
| | | goodsorder.setPayDate(new Date()); |
| | | goodsorderMapper.insert(goodsorder); |
| | | //更新用户积分 |
| | | memberMapper.subtractIntegral(member.getId(),sumPrice); |
| | | PayResponse payResponse = new PayResponse(); |
| | | payResponse.setOrderId(goodsorder.getId()); |
| | | return payResponse; |
| | | } |
| | | goodsorder.setIntegral(orderPayRequest.getDeductionBalance()); |
| | | goodsorderMapper.insert(goodsorder); |
| | | //数据存储 |
| | | BigDecimal total = Constants.formatBigdecimal(goodsorder.getPrice()).add(Constants.formatBigdecimal(goodsorder.getIntegral())).add(Constants.formatBigdecimal(goodsorder.getCouponPrice())); |
| | | BigDecimal rate =Constants.formatBigdecimal(goodsorder.getCouponPrice()).divide(total,4,BigDecimal.ROUND_HALF_UP); |
| | | BigDecimal totalWxMoney = new BigDecimal(0); |
| | | BigDecimal totalIntegral = new BigDecimal(0); |
| | | for (int i =0;i< goodsOrderDetailList.size();i++) { |
| | | GoodsorderDetail goodsOrderDetail= goodsOrderDetailList.get(i); |
| | | goodsOrderDetail.setOrderId(goodsorder.getId()); |
| | | BigDecimal wxMoney ; |
| | | BigDecimal integral; |
| | | if(i!=0 && i == goodsOrderDetailList.size() -1){ |
| | | //处理因为四舍五入造成的可退金额损失 |
| | | wxMoney = Constants.formatBigdecimal(goodsorder.getPrice()).subtract(totalWxMoney); |
| | | integral = Constants.formatBigdecimal(goodsorder.getIntegral()).subtract(totalIntegral);; |
| | | }else{ |
| | | //当前明细实际价格 |
| | | BigDecimal detialTotal = Constants.formatBigdecimal(goodsOrderDetail.getPrice()).multiply(new BigDecimal(Constants.formatIntegerNum(goodsOrderDetail.getGoodsNum()))); |
| | | //折算优惠券后支付价格(包含现金和余额部分) |
| | | BigDecimal actDetialTotal = detialTotal.subtract(detialTotal.multiply(rate)); |
| | | //按现金和积分支付比例,折算每个明细现金和积分支付的数量 |
| | | BigDecimal rate1 = detialTotal .divide(total,4,BigDecimal.ROUND_HALF_UP); |
| | | //可退现金金额 |
| | | wxMoney = Constants.formatBigdecimal(goodsorder.getPrice()).multiply(rate1); |
| | | //剩下的是余额抵扣 |
| | | integral =actDetialTotal.subtract(wxMoney); |
| | | totalWxMoney = totalWxMoney.add(wxMoney);//累计 |
| | | totalIntegral= totalIntegral.add(integral);//累计 |
| | | } |
| | | goodsOrderDetail.setMoney(wxMoney); |
| | | goodsOrderDetail.setIntegral(integral); |
| | | goodsorderDetailMapper.insert(goodsOrderDetail); |
| | | } |
| | | //如果抵扣金额大于 0 则进行余额业务处理 |
| | | if(orderPayRequest.getDeductionBalance().compareTo(BigDecimal.ZERO)>Constants.ZERO){ |
| | | //抵扣金额小于会员剩余余额 |
| | | if(orderPayRequest.getDeductionBalance().compareTo(member.getIntegral())<=Constants.ZERO){ |
| | | //更新余额信息 添加积分变动记录 |
| | | DealIntegralRequest dealIntegralRequest = new DealIntegralRequest(); |
| | | dealIntegralRequest.setIntegralNum(orderPayRequest.getDeductionBalance()); |
| | | dealIntegralRequest.setDealType(Constants.ONE); |
| | | dealIntegralRequest.setMemberId(member.getId()); |
| | | dealIntegralRequest.setObjId(goodsorder.getId()); |
| | | dealIntegralRequest.setOrderCode(goodsorder.getCode().toString()); |
| | | dealIntegralRequest.setIntegralObjType(Constants.IntegralObjType.SHOP_ORDER); |
| | | integralService.dealIntegral(dealIntegralRequest); |
| | | //发送微信小程序订阅消息 |
| | | SendWxMessage.integralChangeNotice(member,orderPayRequest.getDeductionBalance()); |
| | | //余额全部抵扣 |
| | | if(goodsorder.getPrice().compareTo(BigDecimal.ZERO)==Constants.ZERO){ |
| | | goodsorder.setStatus(Constants.OrderStatus.PAY_DONE.getKey()); |
| | | goodsorder.setPayStatus(Constants.ONE); |
| | | goodsorder.setPayDate(new Date()); |
| | | goodsorderMapper.updateById(goodsorder); |
| | | PayResponse payResponse = new PayResponse(); |
| | | payResponse.setOrderId(goodsorder.getId()); |
| | | return payResponse; |
| | | } |
| | | }else{ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"余额不足,无法进行支付,当前剩余余额:【"+member.getIntegral()+"】!"); |
| | | } |
| | | } |
| | | if(goodsorder.getPrice().compareTo(orderPayRequest.getTitlePrice())!=Constants.ZERO){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"商品价格发生变化,请刷新后重新支付!"); |
| | | } |
| | | return this.wxPay(goodsorder,member); |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class,BusinessException.class}) |
| | | public PayResponse orderPay(ShopOrderPayRequest orderPayRequest,MemberCouponServiceImpl memberCouponService){ |
| | |
| | | dealIntegralRequest.setMemberId(member.getId()); |
| | | dealIntegralRequest.setObjId(goodsorder.getId()); |
| | | dealIntegralRequest.setOrderCode(goodsorder.getCode().toString()); |
| | | dealIntegralRequest.setIntegralObjType(Constants.IntegralObjType.SHOP_ORDER); |
| | | dealIntegralRequest.setIntegralObjType(Constants.IntegralObjType.MEMBER_ORDER); |
| | | integralService.dealIntegral(dealIntegralRequest); |
| | | } |
| | | |
| | |
| | | PayResponse payResponse = new PayResponse(); |
| | | payResponse.setOrderId(goodsorder.getId()); |
| | | payResponse.setPayType(Constants.ONE); |
| | | //发送通知 |
| | | if(Objects.nonNull(goodsorder.getPickUpShopId())){ |
| | | //发送站内信 - 经销商 |
| | | noticeService.orderPayNotice(goodsorder.getPickUpShopId(),goodsorder.getId(),goodsorder.getReceiveType()); |
| | | } |
| | | |
| | | |
| | | return payResponse; |
| | | } |
| | | |
| | |
| | | dealIntegralRequest.setMemberId(goodsorder.getMemberId()); |
| | | dealIntegralRequest.setObjId(goodsorder.getId()); |
| | | dealIntegralRequest.setOrderCode(goodsorder.getCode().toString()); |
| | | dealIntegralRequest.setIntegralObjType(Constants.IntegralObjType.SHOP_ORDER_CANCEL); |
| | | dealIntegralRequest.setIntegralObjType(Constants.IntegralObjType.MEMBER_ORDER_CANCEL); |
| | | integralService.dealIntegral(dealIntegralRequest); |
| | | } |
| | | //订单信息取消 |
| | |
| | | } |
| | | |
| | | SendWxMessage.orderCancel(goodsorder,memberMapper.selectById(goodsorder.getMemberId()),goodsName); |
| | | |
| | | |
| | | |
| | | //查询优惠券信息记录 |
| | | if(!Objects.isNull(goodsorder.getCouponId())){ |
| | |
| | | dealIntegralRequest.setMemberId(goodsorder.getMemberId()); |
| | | dealIntegralRequest.setObjId(goodsorder.getId()); |
| | | dealIntegralRequest.setOrderCode(goodsorder.getCode().toString()); |
| | | dealIntegralRequest.setIntegralObjType(Constants.IntegralObjType.SHOP_ORDER_CANCEL); |
| | | dealIntegralRequest.setIntegralObjType(Constants.IntegralObjType.MEMBER_ORDER_CANCEL); |
| | | integralService.dealIntegral(dealIntegralRequest); |
| | | } |
| | | //订单信息取消 |
| | |
| | | } |
| | | } |
| | | |
| | | //SendWxMessage.orderCancel(goodsorder,memberMapper.selectById(goodsorder.getMemberId()),goodsName); |
| | | // 用户主动取消 发送经销商站内消息 |
| | | if(Objects.nonNull(goodsorder.getPickUpShopId())&&StringUtils.isBlank(cancelInfo)){ |
| | | noticeService.orderCancelNotice(goodsorder.getPickUpShopId(),goodsorder.getId(),goodsorder.getCode().toString()); |
| | | } |
| | | |
| | | //查询优惠券信息记录 |
| | | if(!Objects.isNull(goodsorder.getCouponId())){ |
| | |
| | | String couponNames = ""; |
| | | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(shareCouponRewardList)){ |
| | | List<MemberCoupon> memberCouponList = new ArrayList<>(); |
| | | List<CouponNoticeRequest> requestList = new ArrayList<>(); |
| | | for (JSONObject jsonObject:shareCouponRewardList) { |
| | | Integer couponId = jsonObject.getInteger("couponId"); |
| | | Integer num = jsonObject.getInteger("num"); |
| | |
| | | } |
| | | couponIds = couponIds + (StringUtils.isBlank(couponIds)? ",":"" )+ couponId ; |
| | | couponNames = couponNames + (StringUtils.isBlank(couponNames)? ",":"" )+ coupon.getName() ; |
| | | |
| | | |
| | | CouponNoticeRequest couponNoticeRequest = new CouponNoticeRequest(); |
| | | couponNoticeRequest.setMemberCoupon(memberCoupon); |
| | | couponNoticeRequest.setNum(num); |
| | | requestList.add(couponNoticeRequest); |
| | | } |
| | | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(memberCouponList)){ |
| | | memberCouponJoinMapper.insert(memberCouponList); |
| | | } |
| | | if(CollectionUtils.isNotEmpty(requestList)){ |
| | | //发送站内信 |
| | | noticeService.couponNotice(inviteMember.getId(),requestList); |
| | | } |
| | | } |
| | | inviteRecordMapper.update(new UpdateWrapper<InviteRecord>().lambda() |
| | |
| | | dealIntegralRequest.setMemberId(goodsorder.getDistributionShopId()); |
| | | dealIntegralRequest.setObjId(goodsorder.getId()); |
| | | dealIntegralRequest.setOrderCode(goodsorder.getCode().toString()); |
| | | dealIntegralRequest.setIntegralObjType(Constants.IntegralObjType.ORDER_DONATE); |
| | | dealIntegralRequest.setIntegralObjType(Constants.IntegralObjType.SHOP_ORDER); |
| | | Member member = memberMapper.selectById(goodsorder.getMemberId()); |
| | | if(Objects.nonNull(member)){ |
| | | dealIntegralRequest.setParam1(member.getNickname()); |
| | | } |
| | | integralService.dealShopIntegral(dealIntegralRequest); |
| | | } |
| | | } |
| | |
| | | .eq(Collect::getMemberId,member.getId()) |
| | | ) |
| | | ); |
| | | homeInfoResponse.setUnRead( |
| | | noticeMapper.selectCount(new QueryWrapper<Notice>().lambda() |
| | | .eq(Notice::getIsdeleted,Constants.ZERO) |
| | | .eq(Notice::getMemberId,member.getId()) |
| | | .eq(Notice::getStatus,Constants.ZERO) |
| | | )>=Constants.ZERO?Constants.ZERO:Constants.ONE |
| | | ); |
| | | |
| | | return homeInfoResponse; |
| | | } |