From 78bbc1dae1bb20acb51fd454adf53b3ab5ae97b3 Mon Sep 17 00:00:00 2001 From: xiaoyong931011 <15274802129@163.com> Date: Fri, 23 Dec 2022 15:20:11 +0800 Subject: [PATCH] 20221221 --- src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java | 232 ++++++++++++++++++++++----------------------------------- 1 files changed, 91 insertions(+), 141 deletions(-) diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java index 113348b..96edc5b 100644 --- a/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java +++ b/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java @@ -14,10 +14,7 @@ import cc.mrbird.febs.mall.entity.*; import cc.mrbird.febs.mall.mapper.*; import cc.mrbird.febs.mall.service.*; -import cc.mrbird.febs.mall.vo.ApiShopApplyVo; -import cc.mrbird.febs.mall.vo.OrderDetailVo; -import cc.mrbird.febs.mall.vo.OrderListVo; -import cc.mrbird.febs.mall.vo.OrderRefundVo; +import cc.mrbird.febs.mall.vo.*; import cc.mrbird.febs.pay.model.AgreementPayDto; import cc.mrbird.febs.pay.model.AgreementSignDto; import cc.mrbird.febs.pay.model.UnipayDto; @@ -69,6 +66,7 @@ private final MallShoppingCartMapper mallShoppingCartMapper; private final IApiMallMemberService memberService; private final IMallMoneyFlowService mallMoneyFlowService; + private final MallMoneyFlowMapper mallMoneyFlowMapper; private final RedisUtils redisUtils; private final AgentProducer agentProducer; @@ -98,6 +96,17 @@ if(memberLevelCode < goodsStarCode){ throw new FebsException("会员等级不够"); } + if (MallGoods.ISSALE_STATUS_DISABLED.equals(goods.getIsSale())) { + throw new FebsException(goods.getGoodsName() + "已下架"); + } + /** + * 存在未支付的订单无法下单 + */ + Integer orderIng = this.baseMapper.selectOrderInfoByStatusAndMemberId(OrderStatusEnum.FINISH.getValue(), mallMember.getId()); + if(1 <= orderIng){ + throw new FebsException("请先完成未完成的订单"); + } + /** * 会员一天最多下单次数 */ @@ -113,134 +122,54 @@ throw new FebsException("会员今日已无法购买"); } -// MallAddressInfo address = mallAddressInfoMapper.selectAddressInfoByMemberIdAndId(member.getId(), addOrderDto.getAddressId()); -// if (address == null) { -// throw new FebsException("地址不存在"); -// } - String orderNo = MallUtils.getOrderNum(); MallOrderInfo orderInfo = new MallOrderInfo(); orderInfo.setOrderNo(orderNo); orderInfo.setOrderTime(new Date()); orderInfo.setMemberId(member.getId()); orderInfo.setStatus(OrderStatusEnum.WAIT_PAY.getValue()); -// orderInfo.setName(address.getName()); -// orderInfo.setAddress(address.getArea() + address.getAddress()); -// orderInfo.setPhone(address.getPhone()); -// orderInfo.setLatitude(address.getLatitude()); -// orderInfo.setLongitude(address.getLongitude()); orderInfo.setRemark(addOrderDto.getRemark()); orderInfo.setOrderType(addOrderDto.getOrderType()); - - if (CollUtil.isEmpty(addOrderDto.getItems())) { - throw new FebsException("参数错误"); - } - -// int deliverType = ObjectUtil.isEmpty(addOrderDto.getDeliverType()) ? 1 : addOrderDto.getDeliverType(); -// if(2 == deliverType){ -// if(ObjectUtil.isEmpty(addOrderDto.getShopId())){ -// throw new FebsException("请选择门店"); -// } -// Long shopId = addOrderDto.getShopId(); -// MallShopApply mallShopApply = mallShopApplyMapper.selectById(shopId); -// if(ObjectUtil.isEmpty(mallShopApply)){ -// throw new FebsException("请选择门店"); -// } -// if(MallShopApply.APPLY_AGREE != mallShopApply.getStatus()){ -// throw new FebsException("请选择门店"); -// } -// orderInfo.setShopId(shopId); -// } + //补贴金额 + orderInfo.setSubsidyAmount(goods.getSubsidyAmount()); this.baseMapper.insert(orderInfo); - BigDecimal total = BigDecimal.ZERO; - BigDecimal carriage = BigDecimal.ZERO; - for (AddOrderItemDto item : addOrderDto.getItems()) { - MallOrderItem orderItem = new MallOrderItem(); - - // 积分商品提交订单 - if (addOrderDto.getOrderType() == 2) { - MallGoods mallGoods = mallGoodsMapper.selectById(item.getSkuId()); - if (mallGoods.getStock() < item.getCnt()) { - throw new FebsException(mallGoods.getGoodsName() + "库存不足"); - } - - if (MallGoods.ISSALE_STATUS_DISABLED.equals(mallGoods.getIsSale())) { - throw new FebsException(mallGoods.getGoodsName() + "已下架"); - } - - BigDecimal amount = mallGoods.getScore().multiply(BigDecimal.valueOf(item.getCnt())); - orderItem.setAmount(amount); - orderItem.setCnt(item.getCnt()); - orderItem.setOrderId(orderInfo.getId()); - orderItem.setPrice(mallGoods.getScore()); - orderItem.setGoodsId(mallGoods.getId()); - orderItem.setGoodsName(mallGoods.getGoodsName()); - orderItem.setStyleName(mallGoods.getGoodsName()); - orderItem.setSkuName(mallGoods.getGoodsName()); - orderItem.setSkuImage(mallGoods.getThumb()); - - total = total.add(amount); - } else { - MallGoodsSku sku = mallGoodsSkuMapper.selectSkuInfoById(item.getSkuId()); + List<MallGoodsSku> mallGoodsSkus = mallGoodsSkuMapper.selectSkuByGoodsId(goods.getId()); + for (MallGoodsSku sku : mallGoodsSkus) { + MallOrderItem orderItem = new MallOrderItem(); if (sku == null) { throw new FebsException("购买商品或sku不存在"); } - if (sku.getStock() < item.getCnt()) { + if (sku.getStock() < 1) { throw new FebsException(sku.getSkuName() + "库存不足"); } - MallGoods mallGoods = mallGoodsMapper.selectById(sku.getGoodsId()); - - // 零撸专区购买 - if (new BigDecimal(mallGoods.getPresentPrice()).compareTo(BigDecimal.ZERO) == 0) { - List<MallOrderItem> items = mallOrderItemMapper.selectItemByGoodsIdUnCancel(mallGoods.getId(), member.getId()); - if (CollUtil.isNotEmpty(items)) { - throw new FebsException("无法重复领取同一个商品"); - } - } - - if (MallGoods.ISSALE_STATUS_DISABLED.equals(mallGoods.getIsSale())) { - throw new FebsException(mallGoods.getGoodsName() + "已下架"); - } - - BigDecimal amount = sku.getPresentPrice().multiply(BigDecimal.valueOf(item.getCnt())); + BigDecimal amount = sku.getPresentPrice().multiply(BigDecimal.valueOf(1)); orderItem.setAmount(amount); - orderItem.setCnt(item.getCnt()); + orderItem.setCnt(1); orderItem.setOrderId(orderInfo.getId()); orderItem.setPrice(sku.getPresentPrice()); orderItem.setGoodsId(sku.getGoodsId()); - orderItem.setGoodsName(sku.getGoodsName()); + orderItem.setGoodsName(goods.getGoodsName()); orderItem.setSkuId(sku.getId()); orderItem.setStyleName(sku.getStyleName()); orderItem.setSkuName(sku.getSkuName()); orderItem.setSkuImage(sku.getSkuImage()); - orderItem.setIsNormal(mallGoods.getIsNormal()); + orderItem.setIsNormal(goods.getIsNormal()); orderItem.setCostPrice(sku.getCostPrice()); - total = total.add(amount); - carriage = carriage.add(mallGoods.getCarriage()); - - sku.setStock(sku.getStock() - item.getCnt()); - sku.setSkuVolume(sku.getSkuVolume() + item.getCnt()); + sku.setStock(sku.getStock() - 1); + sku.setSkuVolume(sku.getSkuVolume() + 1); mallGoodsSkuMapper.updateById(sku); - if (addOrderDto.getType() == 1) { + if (1 == addOrderDto.getType() ) { mallShoppingCartMapper.delBySkuId(sku.getId(), member.getId()); } - } - mallOrderItemMapper.insert(orderItem); + mallOrderItemMapper.insert(orderItem); } - - orderInfo.setAmount(total); -// if(2 == deliverType){ -// orderInfo.setDeliverType(2); -// orderInfo.setCarriage(BigDecimal.ZERO); -// }else{ -// orderInfo.setDeliverType(1); -// orderInfo.setCarriage(carriage); -// } + BigDecimal presentPrice = new BigDecimal(goods.getPresentPrice()).setScale(2,BigDecimal.ROUND_DOWN); + orderInfo.setAmount(presentPrice); this.baseMapper.updateById(orderInfo); agentProducer.sendOrderCancelDelayMsg(orderInfo.getId(), 15 * 60 * 1000L); @@ -285,10 +214,11 @@ if (OrderStatusEnum.WAIT_PAY.getValue() != orderInfo.getStatus()) { throw new FebsException("订单状态不能支付"); } - + String type = payOrderDto.getType(); + type = type == "3" ? type : "3"; String payResultStr = ""; String rcResult = ""; - switch (payOrderDto.getType()) { + switch (type) { case "1": UnipayDto unipayDtoWx = new UnipayDto(); // unipayDto.setAmount(new BigDecimal("0.01")); @@ -361,46 +291,22 @@ orderInfo.setPayTime(new Date()); orderInfo.setPayResult("1"); -// boolean hasTc = false; - // 静态倍数 -// List<MallOrderItem> orderItems = this.baseMapper.getMallOrderItemByOrderId(orderInfo.getId()); -// if (CollUtil.isNotEmpty(orderItems)) { -// for (MallOrderItem orderItem : orderItems) { -// MallGoods mallGoods = mallGoodsMapper.selectById(orderItem.getGoodsId()); -// BigDecimal score = BigDecimal.ZERO; -// MallGoodsSku sku = mallGoodsSkuMapper.selectById(orderItem.getSkuId()); -// if (mallGoods.getIsNormal() == 2) { -// hasTc = true; -// score = sku.getPresentPrice().multiply(mallGoods.getStaticMulti()).multiply(new BigDecimal(orderItem.getCnt())); -//// BigDecimal staticMulti = mallGoods.getStaticMulti() == null ? BigDecimal.ZERO : mallGoods.getStaticMulti(); -//// score = sku.getPresentPrice().multiply(staticMulti); -// // 普通商品也及时结算,不再10天结算 -// } else { -// score = sku.getPresentPrice(); -// } -// -// if (score.compareTo(BigDecimal.ZERO) > 0) { -// memberWalletService.add(score, member.getId(), "score"); -// mallMoneyFlowService.addMoneyFlow(member.getId(), score, MoneyFlowTypeEnum.STATIC_BONUS.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.SCORE.getValue()); -// -// // 添加业绩 -// mallAchieveService.add(orderItem.getId()); -// } -// } -// } +// mallMoneyFlowService.addMoneyFlow(member.getId(), orderInfo.getAmount().negate(), MoneyFlowTypeEnum.PAY.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.BALANCE.getValue()); + /** + * 生成下单的流水记录 + */ + Long payFlowId = mallMoneyFlowService.addMoneyFlow( + member.getId(), + orderInfo.getOrderNo(), + orderInfo.getAmount().negate().setScale(2, BigDecimal.ROUND_DOWN), + MallMoneyFlowTypeEnum.PAY.getCode(), + MallMoneyFlow.STATUS_SUCCESS, + MallMoneyFlow.IS_RETURN_N, + member.getId(), + FlowTypeEnum.BALANCE.getValue(), + MallMoneyFlowTypeEnum.PAY.getName() + ); - // 购买套餐后,升级为普通会员 -// if (hasTc) { -// MallMember mallMember = memberMapper.selectById(member.getId()); -// if (AgentLevelEnum.ZERO_LEVEL.name().equals(mallMember.getLevel())) { -// mallMember.setLevel(AgentLevelEnum.FIRST_LEVEL.name()); -// memberMapper.updateById(mallMember); -// } -// } - - mallMoneyFlowService.addMoneyFlow(member.getId(), orderInfo.getAmount().negate(), MoneyFlowTypeEnum.PAY.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.BALANCE.getValue()); -// agentProducer.sendAutoLevelUpMsg(member.getId()); -// agentProducer.sendOrderReturn(orderInfo.getId()); break; case "4": if (orderInfo.getOrderType() != 2) { @@ -600,6 +506,23 @@ orderInfo.setStatus(OrderStatusEnum.FINISH.getValue()); orderInfo.setReceivingTime(new Date()); this.baseMapper.updateById(orderInfo); + /** + * 通过支付流水记录,返回下单金额 + */ + MallMoneyFlow payFlow = mallMoneyFlowMapper.selectOneByMemberIdAndOrderNoAndTypeAndStatusAndIsReturn( + member.getId(), + orderInfo.getOrderNo(), + MallMoneyFlowTypeEnum.PAY.getCode(), + MallMoneyFlow.STATUS_SUCCESS, + MallMoneyFlow.IS_RETURN_N); + if(ObjectUtil.isNotEmpty(payFlow)){ + memberWalletService.addBalance(payFlow.getAmount().negate(),payFlow.getRtMemberId()); + payFlow.setIsReturn(MallMoneyFlow.IS_RETURN_Y); + mallMoneyFlowMapper.updateById(payFlow); + } + //产生补贴流水记录 + agentProducer.sendDirectRewardMsg(orderInfo.getId()); + } @Override @@ -766,4 +689,31 @@ } } + @Override + public FebsResponse subsidyAmountInfo() { + MallMember member = LoginUserUtil.getLoginUser(); + ApiMallSubsidyAmountInfoVo apiMallSubsidyAmountInfoVo = new ApiMallSubsidyAmountInfoVo(); + DateTime today = DateUtil.date(); + DateTime yesterday = DateUtil.yesterday(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + String yyyyMMddToday = sdf.format(today); + String yyyyMMddYesterday = sdf.format(yesterday); + //今日补贴 + BigDecimal todayAmount = this.baseMapper.selectTodayAmountByCreateTimeAndMemberId(yyyyMMddToday,member.getId()); + apiMallSubsidyAmountInfoVo.setTodayAmount(todayAmount); + //今日累计接单 + Integer todayTotalCnt = this.baseMapper.selectCountByCreateTimeAndMemberId(yyyyMMddToday,member.getId()); + apiMallSubsidyAmountInfoVo.setTodayTotalCnt(todayTotalCnt); + //昨日补贴 + BigDecimal yesterdayAmount = this.baseMapper.selectTodayAmountByCreateTimeAndMemberId(yyyyMMddYesterday,member.getId()); + apiMallSubsidyAmountInfoVo.setYesterdayAmount(yesterdayAmount); + //昨日累计接单 + Integer totalYesterdayCnt = this.baseMapper.selectCountByCreateTimeAndMemberId(yyyyMMddYesterday,member.getId()); + apiMallSubsidyAmountInfoVo.setTotalYesterdayCnt(totalYesterdayCnt); + //获得总额 + BigDecimal totalAmount = this.baseMapper.selectTodayAmountByCreateTimeAndMemberId(null,member.getId()); + apiMallSubsidyAmountInfoVo.setTotalAmount(totalAmount); + return new FebsResponse().success().data(apiMallSubsidyAmountInfoVo); + } + } -- Gitblit v1.9.1