| | |
| | | package cc.mrbird.febs.mall.service.impl; |
| | | |
| | | import cc.mrbird.febs.common.entity.FebsResponse; |
| | | import cc.mrbird.febs.common.enumerates.*; |
| | | import cc.mrbird.febs.common.exception.FebsException; |
| | | import cc.mrbird.febs.common.utils.AppContants; |
| | | import cc.mrbird.febs.common.utils.LoginUserUtil; |
| | | import cc.mrbird.febs.common.utils.MallUtils; |
| | | import cc.mrbird.febs.common.utils.RedisUtils; |
| | | import cc.mrbird.febs.mall.conversion.MallGoodsCommentConversion; |
| | | import cc.mrbird.febs.mall.conversion.MallOrderInfoConversion; |
| | | import cc.mrbird.febs.mall.conversion.MallOrderRefundConversion; |
| | | import cc.mrbird.febs.mall.dto.*; |
| | |
| | | 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.pay.model.AgreementSignDto; |
| | | import cc.mrbird.febs.pay.model.UnipayDto; |
| | | import cc.mrbird.febs.pay.service.IPayService; |
| | | import cc.mrbird.febs.pay.service.UnipayService; |
| | | import cc.mrbird.febs.rabbit.producter.AgentProducer; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.date.DateUnit; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.crypto.SecureUtil; |
| | | import cn.hutool.json.JSONObject; |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | |
| | | /** |
| | |
| | | private final MallAddressInfoMapper mallAddressInfoMapper; |
| | | private final MallOrderItemMapper mallOrderItemMapper; |
| | | private final MallMemberMapper memberMapper; |
| | | private final MallGoodsCommentMapper mallGoodsCommentMapper; |
| | | private final IApiMallMemberWalletService memberWalletService; |
| | | private final MallExpressInfoMapper expressInfoMapper; |
| | | private final MallOrderRefundMapper mallOrderRefundMapper; |
| | |
| | | |
| | | private final AgentProducer agentProducer; |
| | | private final IPayService payService; |
| | | private final IMallAchieveService mallAchieveService; |
| | | private final UnipayService unipayService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | |
| | | this.baseMapper.insert(orderInfo); |
| | | BigDecimal total = BigDecimal.ZERO; |
| | | BigDecimal carriage = BigDecimal.ZERO; |
| | | for (AddOrderItemDto item : addOrderDto.getItems()) { |
| | | MallOrderItem orderItem = new MallOrderItem(); |
| | | |
| | |
| | | } |
| | | |
| | | 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() + "已下架"); |
| | | } |
| | |
| | | orderItem.setStyleName(sku.getStyleName()); |
| | | orderItem.setSkuName(sku.getSkuName()); |
| | | orderItem.setSkuImage(sku.getSkuImage()); |
| | | orderItem.setIsNormal(mallGoods.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()); |
| | |
| | | } |
| | | |
| | | orderInfo.setAmount(total); |
| | | orderInfo.setCarriage(carriage); |
| | | this.baseMapper.updateById(orderInfo); |
| | | |
| | | agentProducer.sendOrderCancelDelayMsg(orderInfo.getId(), 15 * 60 * 1000L); |
| | |
| | | this.baseMapper.updateById(orderInfo); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | String unipayStr = "{\"r1_MerchantNo\":\"888118000001971\",\"rd_Pic\":\"\",\"r6_FrpCode\":\"ALIPAY_H5\",\"r7_TrxNo\":\"100222082332490699\",\"r0_Version\":\"1.0\",\"r3_Amount\":\"0.01\",\"r4_Cur\":\"1\",\"r2_OrderNo\":\"2022082212510288174\",\"rb_CodeMsg\":\"\",\"hmac\":\"1659BB77DEDDF9956EA4D6DF227C3B14\",\"ra_Code\":100,\"rc_Result\":\"<html><head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8'><title></title></head><body><script type='text/javascript'>location.href='https://qr.alipay.com/bax019737vbdwoisxcdp00a2';</script></body></html>\"}"; |
| | | JSONObject jsonObject = JSONUtil.parseObj(unipayStr); |
| | | String r7_trxNo = (String) jsonObject.get("r7_TrxNo"); |
| | | System.out.println(r7_trxNo); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Map<String, Object> payOrder(PayOrderDto payOrderDto) { |
| | |
| | | } |
| | | |
| | | String payResultStr = ""; |
| | | String rcResult = ""; |
| | | switch (payOrderDto.getType()) { |
| | | case "1": |
| | | // orderInfo.setPayOrderNo(payOrderDto.getPayOrderNo()); |
| | | // orderInfo.setPayImage(payOrderDto.getPayImage()); |
| | | orderInfo.setPayMethod("微信支付"); |
| | | agentProducer.sendOrderReturn(orderInfo.getId()); |
| | | break; |
| | | case "2": |
| | | if (StrUtil.isNotBlank(orderInfo.getPayOrderNo())) { |
| | | payResultStr = orderInfo.getPayOrderNo(); |
| | | } else { |
| | | payResultStr = payService.aliPay(orderInfo); |
| | | // if (StrUtil.isNotBlank(orderInfo.getPayOrderNo())) { |
| | | // payResultStr = orderInfo.getPayOrderNo(); |
| | | // } else { |
| | | // payResultStr = payService.aliPay(orderInfo); |
| | | // } |
| | | UnipayDto unipayDto = new UnipayDto(); |
| | | // unipayDto.setAmount(new BigDecimal("0.01")); |
| | | unipayDto.setAmount(orderInfo.getAmount()); |
| | | unipayDto.setFrpCode("ALIPAY_H5"); |
| | | unipayDto.setTradeMerchantNo("777180800385820"); |
| | | unipayDto.setOrderNo(orderInfo.getOrderNo()); |
| | | List<MallOrderItem> items = orderInfo.getItems(); |
| | | if(CollUtil.isEmpty(items)){ |
| | | unipayDto.setProductName("商品"); |
| | | }else{ |
| | | unipayDto.setProductName(items.get(0).getGoodsName()); |
| | | } |
| | | |
| | | String unipayStr = unipayService.unipay(unipayDto); |
| | | if("fail" == unipayStr){ |
| | | throw new FebsException("支付失败"); |
| | | }else{ |
| | | JSONUtil.parseObj(unipayStr); |
| | | JSONObject jsonObject = JSONUtil.parseObj(unipayStr); |
| | | payResultStr = (String) jsonObject.get("r7_TrxNo"); |
| | | rcResult = (String) jsonObject.get("rc_Result"); |
| | | } |
| | | orderInfo.setPayOrderNo(payResultStr); |
| | | orderInfo.setPayMethod("支付宝支付"); |
| | | // agentProducer.sendOrderReturn(orderInfo.getId()); |
| | | break; |
| | | case "3": |
| | | payResultStr = balancePay(orderInfo, payOrderDto.getTradePwd(), "balance"); |
| | |
| | | orderInfo.setPayTime(new Date()); |
| | | orderInfo.setPayResult("1"); |
| | | |
| | | // MallMember mallMember = memberMapper.selectById(member.getId()); |
| | | // if (AgentLevelEnum.ZERO_LEVEL.name().equals(mallMember.getLevel())) { |
| | | // mallMember.setLevel(AgentLevelEnum.FIRST_LEVEL.name()); |
| | | // memberMapper.updateById(mallMember); |
| | | // } |
| | | |
| | | 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) { |
| | | MallGoodsSku sku = mallGoodsSkuMapper.selectById(orderItem.getSkuId()); |
| | | BigDecimal score = sku.getOriginalPrice().multiply(mallGoods.getStaticMulti()); |
| | | 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()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 购买套餐后,升级为普通会员 |
| | | 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.sendReturnMoneyMsg(orderInfo.getId()); |
| | | agentProducer.sendAutoLevelUpMsg(member.getId()); |
| | | agentProducer.sendOrderReturn(orderInfo.getId()); |
| | | break; |
| | | case "4": |
| | | if (orderInfo.getOrderType() != 2) { |
| | |
| | | orderInfo.setPayTime(new Date()); |
| | | orderInfo.setPayResult("1"); |
| | | |
| | | |
| | | mallMoneyFlowService.addMoneyFlow(member.getId(), orderInfo.getAmount().negate(), MoneyFlowTypeEnum.PAY.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.PRIZE_SCORE.getValue()); |
| | | break; |
| | | case "5": |
| | | AgreementSignDto agreementSignDto = new AgreementSignDto(); |
| | | agreementSignDto.setOrderNo(orderInfo.getOrderNo()); |
| | | unipayService.agreementSign(agreementSignDto); |
| | | // UnipayDto unipayDto = new UnipayDto(); |
| | | //// unipayDto.setAmount(new BigDecimal("0.01")); |
| | | // unipayDto.setAmount(orderInfo.getAmount()); |
| | | // unipayDto.setFrpCode("ALIPAY_H5"); |
| | | // unipayDto.setTradeMerchantNo("777180800385820"); |
| | | // unipayDto.setOrderNo(orderInfo.getOrderNo()); |
| | | // List<MallOrderItem> items = orderInfo.getItems(); |
| | | // if(CollUtil.isEmpty(items)){ |
| | | // unipayDto.setProductName("商品"); |
| | | // }else{ |
| | | // unipayDto.setProductName(items.get(0).getGoodsName()); |
| | | // } |
| | | // String agreementSignStr = ""; |
| | | // if("fail" == unipayStr){ |
| | | // throw new FebsException("支付失败"); |
| | | // }else{ |
| | | // JSONUtil.parseObj(unipayStr); |
| | | // JSONObject jsonObject = JSONUtil.parseObj(unipayStr); |
| | | // payResultStr = (String) jsonObject.get("r7_TrxNo"); |
| | | // rcResult = (String) jsonObject.get("rc_Result"); |
| | | // } |
| | | orderInfo.setPayOrderNo(payResultStr); |
| | | orderInfo.setPayMethod("支付宝支付"); |
| | | // agentProducer.sendOrderReturn(orderInfo.getId()); |
| | | break; |
| | | default: |
| | | |
| | |
| | | map.put("orderInfo", payResultStr); |
| | | map.put("orderNo", orderInfo.getOrderNo()); |
| | | map.put("orderId", orderInfo.getId()); |
| | | map.put("rcResult", rcResult); |
| | | |
| | | return map; |
| | | } |
| | |
| | | throw new FebsException("支付密码错误"); |
| | | } |
| | | |
| | | memberWalletService.reduce(orderInfo.getAmount(), mallMember.getId(), field); |
| | | int reduce = memberWalletService.reduce(orderInfo.getAmount().add(orderInfo.getCarriage()), mallMember.getId(), field); |
| | | if (reduce == 2) { |
| | | throw new FebsException("余额不足"); |
| | | } |
| | | return orderInfo.getOrderNo(); |
| | | } |
| | | |
| | |
| | | orderRefund.setRefundTime(new Date()); |
| | | orderRefund.setBeforeStatus(beforeStatus); |
| | | orderRefund.setStatus(OrderRefundStatusEnum.REFUND_APPLY.getValue()); |
| | | |
| | | // 未发货则退运费,发货了则不退 |
| | | if (beforeStatus == 2) { |
| | | orderRefund.setAmount(orderInfo.getAmount().add(orderInfo.getCarriage())); |
| | | } else { |
| | | orderRefund.setAmount(orderInfo.getAmount()); |
| | | } |
| | | mallOrderRefundMapper.insert(orderRefund); |
| | | } else { |
| | | orderRefund.setDesp(addRefundDto.getDesp()); |
| | |
| | | orderRefund.setRefundTime(new Date()); |
| | | orderRefund.setBeforeStatus(beforeStatus); |
| | | orderRefund.setStatus(OrderRefundStatusEnum.REFUND_APPLY.getValue()); |
| | | // 未发货则退运费,发货了则不退 |
| | | if (beforeStatus == 2) { |
| | | orderRefund.setAmount(orderInfo.getAmount().add(orderInfo.getCarriage())); |
| | | } else { |
| | | orderRefund.setAmount(orderInfo.getAmount()); |
| | | } |
| | | mallOrderRefundMapper.updateById(orderRefund); |
| | | } |
| | | |
| | |
| | | this.baseMapper.updateById(orderInfo); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void goodsComment(ApiAddCommentDtos addCommentDtos) { |
| | | Long orderId = addCommentDtos.getOrderId(); |
| | | MallMember member = LoginUserUtil.getLoginUser(); |
| | | MallOrderInfo orderInfo = this.baseMapper.selectOrderDetailsById(orderId); |
| | | if (orderInfo == null || AppContants.DEL_FLAG_Y == orderInfo.getDelFlag()) { |
| | | throw new FebsException("订单不存在"); |
| | | } |
| | | if (OrderStatusEnum.FINISH.getValue() != orderInfo.getStatus()) { |
| | | throw new FebsException("该状态不能评价"); |
| | | } |
| | | if (MallOrderInfo.COMMENT_STATE_YES == orderInfo.getCommentState()) { |
| | | throw new FebsException("该状态不能评价"); |
| | | } |
| | | |
| | | orderInfo.setCommentState(MallOrderInfo.COMMENT_STATE_YES); |
| | | this.baseMapper.updateById(orderInfo); |
| | | |
| | | List<ApiAddCommentDto> apiAddCommentDtos = addCommentDtos.getApiAddCommentDtos(); |
| | | if(CollUtil.isNotEmpty(apiAddCommentDtos)){ |
| | | for(ApiAddCommentDto apiAddCommentDto : apiAddCommentDtos){ |
| | | Long skuId = apiAddCommentDto.getSkuId(); |
| | | MallGoodsSku mallGoodsSku = mallGoodsSkuMapper.selectById(skuId); |
| | | Long goodsId = apiAddCommentDto.getGoodsId(); |
| | | MallGoods mallGoods = mallGoodsMapper.selectById(goodsId); |
| | | MallGoodsComment mallGoodsComment = MallGoodsCommentConversion.INSTANCE.dtoToEntity(apiAddCommentDto); |
| | | mallGoodsComment.setMemberId(member.getId()); |
| | | mallGoodsComment.setOrderId(orderId); |
| | | mallGoodsComment.setGoodsName(mallGoods.getGoodsName()); |
| | | mallGoodsComment.setSkuName(mallGoodsSku.getSkuName()); |
| | | mallGoodsComment.setStyleId(mallGoodsSku.getStyleId()); |
| | | mallGoodsComment.setStyleName(mallGoodsSku.getStyleName()); |
| | | mallGoodsComment.setShowState(MallGoodsComment.SHOW_STATE_ENABLE); |
| | | mallGoodsCommentMapper.insert(mallGoodsComment); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |