| | |
| | | package com.doumee.service.business.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.Wrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | |
| | | import java.net.UnknownHostException; |
| | | import java.util.*; |
| | | import java.util.Date; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | |
| | | @Autowired |
| | | private IntegralMapper integralMapper; |
| | | |
| | | |
| | | private final static String GOODS_ORDER_CREATE_LOCK = "goods:order:create:lock:"; |
| | | |
| | | @Override |
| | | public Integer create(Goodsorder goodsorder) { |
| | |
| | | goodsorder.getKdName()+"(单号:"+goodsorder.getKdCode()+")"); |
| | | |
| | | } |
| | | |
| | | //发送发货站内信 |
| | | Notice notice = Notice.getNotice( |
| | | Constants.NoticeType.NOTICE_ORDER_SEND, |
| | | goodsorder.getMemberId(), |
| | | goodsorder.getId() |
| | | ); |
| | | notice.setContent(notice.getContent().replace("{param}",goodsorder.getCode().toString())); |
| | | noticeMapper.insert(notice); |
| | | |
| | | |
| | | /* // TODO 发送微信模板消息 |
| | | Member member=memberMapper.selectById(query.getMemberId()); |
| | |
| | | queryWrapper.le(pageWrap.getModel().getEndtime()!=null,Goodsorder::getCreateDate, pageWrap.getModel().getEndtime()); |
| | | queryWrapper.eq(pageWrap.getModel().getReceiveType()!=null,Goodsorder::getReceiveType,pageWrap.getModel().getReceiveType()); |
| | | queryWrapper.eq(pageWrap.getModel().getPayOrderId()!=null,Goodsorder::getPayOrderId,pageWrap.getModel().getPayOrderId()); |
| | | if (StringUtils.isNotBlank(pageWrap.getModel().getGoodsName())) { |
| | | queryWrapper.exists("select gs.id from goodsorder_detail gs where gs.order_id=t.id and gs.isdeleted=0 and gs.NAME like '%"+pageWrap.getModel().getGoodsName()+"%' "); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class,BusinessException.class}) |
| | | public PayResponse orderPay(ShopOrderPayRequest orderPayRequest,MemberCouponServiceImpl memberCouponService){ |
| | | String lockKey = GOODS_ORDER_CREATE_LOCK + orderPayRequest.getMemberId(); |
| | | //判断前端是否在同一页面创建了两次订单 |
| | | if (redisTemplate.hasKey(lockKey)) { |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"正在创建订单,请勿重复调用!"); |
| | | } else { |
| | | redisTemplate.opsForValue().set(lockKey, "", 5, TimeUnit.SECONDS); |
| | | } |
| | | Member member = memberMapper.selectById(orderPayRequest.getMemberId()); |
| | | |
| | | Goodsorder goodsorder = new Goodsorder(); |
| | |
| | | } |
| | | goodsorder.setPickUpShopId(shop.getId()); |
| | | goodsorder.setDistributionShopId(shop.getId()); |
| | | goodsorder.setLinkname(member.getName()); |
| | | goodsorder.setLinkphone(member.getPhone()); |
| | | if(Objects.isNull(member.getBindShopId())){ |
| | | member.setBindShopId(shop.getId()); |
| | | member.setBindShopDate(new Date()); |
| | |
| | | } |
| | | goodsorder.setPrice(orderPayConfirmResponse.getPayAmount()); |
| | | goodsorder.setTotalPrice(orderPayConfirmResponse.getAmount()); |
| | | goodsorder.setUseIntegral(orderPayConfirmResponse.getDeductIntegral()); |
| | | goodsorder.setIntegral(orderPayConfirmResponse.getIntegralAmount()); |
| | | goodsorder.setUseIntegral(Constants.equalsInteger(orderPayRequest.getUseIntegral(),Constants.ONE)?orderPayConfirmResponse.getDeductIntegral():BigDecimal.ZERO); |
| | | goodsorder.setIntegral(Constants.equalsInteger(orderPayRequest.getUseIntegral(),Constants.ONE)?orderPayConfirmResponse.getIntegralAmount():BigDecimal.ZERO); |
| | | goodsorder.setMailPrice(orderPayConfirmResponse.getMailAmount()); |
| | | goodsorder.setPayMethod(goodsorder.getPrice().compareTo(BigDecimal.ZERO)>Constants.ZERO?Constants.ZERO:Constants.ONE); |
| | | goodsorder.setGoodsNum(orderPayRequest.getPayDetailRequestList().stream().mapToInt(PayDetailRequest::getGoodsNum).sum()); |
| | |
| | | for (OrderGoodsCalculateResponse payDetailRequest:goodsCalculateList) { |
| | | //查询商品 |
| | | GoodsSku goodsSku = goodsSkuMapper.selectById(payDetailRequest.getSkuId()); |
| | | if(Objects.isNull(goodsSku)){ |
| | | if(Objects.isNull(goodsSku)||!Constants.equalsInteger(goodsSku.getIsdeleted(),Constants.ZERO)){ |
| | | 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)){ |
| | | if(!Constants.equalsInteger(goods.getStatus(),Constants.ZERO)||!Constants.equalsInteger(goods.getIsdeleted(),Constants.ZERO)){ |
| | | 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(),"商品价格发生变化,请刷新后重新支付!"); |
| | | } |
| | | |
| | | |
| | | //存在现金支付 |
| | | if(Constants.equalsInteger(goodsorder.getPayMethod(),Constants.ZERO)){ |
| | | return this.wxPay(goodsorder,member); |
| | | PayResponse payResponse = this.wxPay(goodsorder,member); |
| | | payResponse.setLockKey(lockKey); |
| | | return payResponse; |
| | | } |
| | | //无现金支付 |
| | | goodsorderMapper.update(null,new UpdateWrapper<Goodsorder>().lambda() |
| | |
| | | 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()); |
| | | } |
| | | |
| | | payResponse.setLockKey(lockKey); |
| | | // //发送通知 |
| | | // if(Objects.nonNull(goodsorder.getPickUpShopId())){ |
| | | // //发送站内信 - 经销商 |
| | | // noticeService.orderPayNotice(goodsorder.getPickUpShopId(),goodsorder.getId(),goodsorder.getReceiveType()); |
| | | // } |
| | | |
| | | return payResponse; |
| | | } |
| | |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到订单信息"); |
| | | } |
| | | if(memberOrderResponse.getOrderStatus().equals(Constants.OrderStatus.WAIT_PAY.getKey())){ |
| | | memberOrderResponse.setCountdown(memberOrderResponse.getCancelDate().getTime()>System.currentTimeMillis()?memberOrderResponse.getCancelDate().getTime()-System.currentTimeMillis():Constants.ZERO); |
| | | memberOrderResponse.setCountdown(memberOrderResponse.getCancelOptDate().getTime()>System.currentTimeMillis()?memberOrderResponse.getCancelOptDate().getTime()-System.currentTimeMillis():Constants.ZERO); |
| | | } |
| | | String fullUrl = systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode()+ |
| | | systemDictDataBiz.queryByCode(Constants.OSS,Constants.GOODS_FILE).getCode(); |
| | |
| | | goodsorder.setCancelInfo(cancelInfo); |
| | | goodsorder.setCancelUser(optUserId); |
| | | goodsorderMapper.updateById(goodsorder); |
| | | if(Constants.equalsInteger(goodsorder.getReceiveType(),Constants.ONE)){ |
| | | //释放核销码 |
| | | this.releaseExchangeCode(goodsorder.getExchangeCode()); |
| | | } |
| | | String goodsName = ""; |
| | | List<GoodsorderDetail> goodsorderDetailList = goodsorderDetailMapper.selectList(new QueryWrapper<GoodsorderDetail>().eq("ORDER_ID",goodsorder.getId())); |
| | | if(!Objects.isNull(goodsorderDetailList)&&goodsorderDetailList.size()>Constants.ZERO){ |
| | |
| | | } |
| | | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class,BusinessException.class}) |
| | | public void cancelOrderNew(Integer orderId,Integer optUserId,String cancelInfo){ |
| | | if(Objects.isNull(orderId)){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | Goodsorder goodsorder = goodsorderMapper.selectById(orderId); |
| | | if(Objects.isNull(goodsorder)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY); |
| | | } |
| | | if(!(Constants.equalsInteger(goodsorder.getStatus(),Constants.OrderStatus.WAIT_PAY.getKey()) |
| | | || Constants.equalsInteger(goodsorder.getStatus(),Constants.OrderStatus.PAY_DONE.getKey()) )){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"订单取消失败:订单状态已流转!"); |
| | | } |
| | | public void cancel(Goodsorder goodsorder,Integer optUserId,String cancelInfo){ |
| | | if(Constants.formatBigdecimal(goodsorder.getPrice()).compareTo(BigDecimal.ZERO)>Constants.ZERO |
| | | && Constants.equalsObject(goodsorder.getPayStatus(),Constants.ONE) ){ |
| | | //微信现金退款 |
| | |
| | | fundMapper.insert(fund); |
| | | } |
| | | //订单已支付状态 , 使用了积分 且积分使用大于0 |
| | | if(goodsorder.getIntegral().compareTo(BigDecimal.ZERO)>Constants.ZERO){ |
| | | if(goodsorder.getUseIntegral().compareTo(BigDecimal.ZERO)>Constants.ZERO){ |
| | | //更新余额信息 添加积分变动记录 |
| | | DealIntegralRequest dealIntegralRequest = new DealIntegralRequest(); |
| | | dealIntegralRequest.setIntegralNum(goodsorder.getIntegral()); |
| | | dealIntegralRequest.setIntegralNum(goodsorder.getUseIntegral()); |
| | | dealIntegralRequest.setDealType(Constants.ZERO); |
| | | dealIntegralRequest.setMemberId(goodsorder.getMemberId()); |
| | | dealIntegralRequest.setObjId(goodsorder.getId()); |
| | |
| | | goodsorder.setCancelInfo(StringUtils.isBlank(cancelInfo)?"用户主动取消":cancelInfo); |
| | | goodsorder.setCancelUser(optUserId); |
| | | goodsorderMapper.updateById(goodsorder); |
| | | if(Constants.equalsInteger(goodsorder.getReceiveType(),Constants.ONE)){ |
| | | //释放核销码 |
| | | this.releaseExchangeCode(goodsorder.getExchangeCode()); |
| | | } |
| | | String goodsName = ""; |
| | | List<GoodsorderDetail> goodsorderDetailList = goodsorderDetailMapper.selectList(new QueryWrapper<GoodsorderDetail>().eq("ORDER_ID",goodsorder.getId())); |
| | | if(!Objects.isNull(goodsorderDetailList)&&goodsorderDetailList.size()>Constants.ZERO){ |
| | |
| | | } |
| | | |
| | | // 用户主动取消 发送经销商站内消息 |
| | | if(Objects.nonNull(goodsorder.getPickUpShopId())&&StringUtils.isBlank(cancelInfo)){ |
| | | noticeService.orderCancelNotice(goodsorder.getPickUpShopId(),goodsorder.getId(),goodsorder.getCode().toString()); |
| | | } |
| | | // if(Objects.nonNull(goodsorder.getPickUpShopId())&&StringUtils.isBlank(cancelInfo)){ |
| | | // noticeService.orderCancelNotice(goodsorder.getPickUpShopId(),goodsorder.getId(),goodsorder.getCode().toString()); |
| | | // } |
| | | |
| | | //查询优惠券信息记录 |
| | | if(!Objects.isNull(goodsorder.getCouponId())){ |
| | |
| | | memberCouponMapper.updateById(memberCoupon); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class,BusinessException.class}) |
| | | public void cancelOrderNew(Integer orderId,Integer optUserId,String cancelInfo){ |
| | | if(Objects.isNull(orderId)){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | Goodsorder goodsorder = goodsorderMapper.selectById(orderId); |
| | | if(Objects.isNull(goodsorder)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY); |
| | | } |
| | | if(!(Constants.equalsInteger(goodsorder.getStatus(),Constants.OrderStatus.WAIT_PAY.getKey()) |
| | | || Constants.equalsInteger(goodsorder.getStatus(),Constants.OrderStatus.PAY_DONE.getKey()) )){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"订单取消失败:订单状态已流转!"); |
| | | } |
| | | this.cancel(goodsorder,optUserId,cancelInfo); |
| | | |
| | | } |
| | | |
| | |
| | | this.orderAddShopIntegral(goodsorder); |
| | | //下单完成 根据信息确认是否需要赠送邀请者优惠券 |
| | | this.orderDoneRewardInviteCoupon(goodsorder); |
| | | //消费者确认收货 |
| | | //赠送消费者下单积分 |
| | | this.orderAddMemberIntegral(goodsorder); |
| | | //经销商 结算金额 |
| | | this.orderAddShopCash(goodsorder); |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | List<MemberCoupon> memberCouponList = new ArrayList<>(); |
| | | List<CouponNoticeRequest> requestList = new ArrayList<>(); |
| | | for (JSONObject jsonObject:shareCouponRewardList) { |
| | | if(!jsonObject.containsKey("couponId")||!jsonObject.containsKey("num")){ |
| | | continue; |
| | | } |
| | | Integer couponId = jsonObject.getInteger("couponId"); |
| | | Integer num = jsonObject.getInteger("num"); |
| | | Coupon coupon = couponMapper.selectById(couponId); |
| | |
| | | } |
| | | MemberCoupon memberCoupon = MemberCoupon.couponToBean(coupon,inviteMember,new Date(),Constants.ONE,null); |
| | | for (int i = 0; i < num; i++) { |
| | | //满减卷不会生成maxPrice 需要根据优惠券减少金额设置 |
| | | if(Constants.equalsInteger(coupon.getCouponType(),Constants.ZERO)){ |
| | | memberCoupon.setMaxPrice(coupon.getPrice()); |
| | | } |
| | | memberCouponList.add(memberCoupon); |
| | | } |
| | | 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); |
| | | |
| | | Notice notice = Notice.getNotice(Constants.NoticeType.COUPON, |
| | | member.getId(),null); |
| | | notice.setContent(notice.getContent().replace("{param}",Constants.getCouponInfo(memberCoupon,num))); |
| | | noticeMapper.insert(notice); |
| | | } |
| | | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(memberCouponList)){ |
| | | memberCouponJoinMapper.insert(memberCouponList); |
| | | } |
| | | if(CollectionUtils.isNotEmpty(requestList)){ |
| | | //发送站内信 |
| | | noticeService.couponNotice(inviteMember.getId(),requestList); |
| | | } |
| | | // if(CollectionUtils.isNotEmpty(requestList)){ |
| | | // //发送站内信 |
| | | // noticeService.couponNotice(inviteMember.getId(),requestList); |
| | | // } |
| | | } |
| | | inviteRecordMapper.update(new UpdateWrapper<InviteRecord>().lambda() |
| | | .set(InviteRecord::getFirstOrderStatus,Constants.ONE) |
| | |
| | | goodsorder.setStatus(Constants.OrderStatus.DONE.getKey()); |
| | | goodsorder.setDoneDate(new Date()); |
| | | goodsorderMapper.updateById(goodsorder); |
| | | //释放核销码 |
| | | this.releaseExchangeCode(goodsorder.getExchangeCode()); |
| | | //存在现金支付 赠送 积分 |
| | | if(Constants.equalsInteger(goodsorder.getPayMethod(),Constants.ZERO)){ |
| | | //赠送消费者积分 |
| | |
| | | //经销商 结算金额 |
| | | this.orderAddShopCash(goodsorder); |
| | | } |
| | | //发送核销通知 |
| | | Notice notice = Notice.getNotice( |
| | | Constants.NoticeType.NOTICE_ORDER_WRITE_OFF, |
| | | goodsorder.getMemberId(), |
| | | goodsorder.getId() |
| | | ); |
| | | notice.setContent(notice.getContent().replace("{param}",goodsorder.getCode().toString())); |
| | | noticeMapper.insert(notice); |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | if(!goodsorder.getStatus().equals(Constants.OrderStatus.DONE.getKey())){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"操作失败:订单未完成,无法退款!"); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | |
| | | |
| | | @Override |
| | | public String createExchangeCode(){ |
| | | List<Goodsorder> goodsorderList = goodsorderMapper.selectList(new QueryWrapper<Goodsorder>().lambda() |
| | | .eq(Goodsorder::getIsdeleted,Constants.ZERO) |
| | | .eq(Goodsorder::getReceiveType,Constants.ONE) |
| | | .in(Goodsorder::getStatus,Constants.OrderStatus.WAIT_RECEIVE.getKey(), |
| | | Constants.OrderStatus.WAIT_PAY.getKey(), |
| | | Constants.OrderStatus.PAY_DONE.getKey()) |
| | | ); |
| | | String exchangeCode = UniqueVerificationCodeGenerator.generateNumericCode(); |
| | | if(CollectionUtils.isNotEmpty(goodsorderList)){ |
| | | Boolean flag = true; |
| | | while (flag){ |
| | | String finalExchangeCode = exchangeCode; |
| | | flag = goodsorderList.stream().filter(i->i.getExchangeCode().equals(finalExchangeCode)).count()>0L?true:false; |
| | | if(flag){ |
| | | exchangeCode = UniqueVerificationCodeGenerator.generateNumericCode(); |
| | | } |
| | | } |
| | | } |
| | | RedisUtil.addObject(redisTemplate,Constants.RedisKeys.EXCHANGE_KEY+exchangeCode,exchangeCode); |
| | | return exchangeCode; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 释放核销码 |
| | | * @param code |
| | | */ |
| | | public void releaseExchangeCode(String code){ |
| | | if(StringUtils.isNotBlank(code)){ |
| | | RedisUtil.deleteObject(redisTemplate,Constants.RedisKeys.EXCHANGE_KEY+code); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 订单未支付超时自动取消 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void autoCancelOrder(){ |
| | | List<Goodsorder> goodsorderList = goodsorderMapper.selectList(new QueryWrapper<Goodsorder>().lambda() |
| | | .eq(Goodsorder::getIsdeleted, Constants.ZERO) |
| | | .eq(Goodsorder::getStatus, Constants.OrderStatus.WAIT_PAY.getKey()) |
| | | .ge(Goodsorder::getCreateDate, "DATE_SUB(NOW(), INTERVAL 15 MINUTE)") |
| | | ); |
| | | if(CollectionUtils.isNotEmpty(goodsorderList)){ |
| | | for (Goodsorder goodsorder:goodsorderList) { |
| | | this.cancel(goodsorder,null,"订单未支付超时自动取消"); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | } |