| | |
| | | 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.pay.service.UnipayService; |
| | | import cc.mrbird.febs.rabbit.producter.AgentProducer; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.date.DateTime; |
| | | import cn.hutool.core.date.DateUnit; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.text.DecimalFormat; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | |
| | | /** |
| | |
| | | private final MallShoppingCartMapper mallShoppingCartMapper; |
| | | private final IApiMallMemberService memberService; |
| | | private final IMallMoneyFlowService mallMoneyFlowService; |
| | | private final MallMoneyFlowMapper mallMoneyFlowMapper; |
| | | private final RedisUtils redisUtils; |
| | | |
| | | private final AgentProducer agentProducer; |
| | |
| | | |
| | | private final MallMemberBankSignMapper mallMemberBankSignMapper; |
| | | private final MallMemberBankMapper mallMemberBankMapper; |
| | | private final MallShopApplyMapper mallShopApplyMapper; |
| | | private final DataDictionaryCustomMapper dataDictionaryCustomMapper; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Long createOrder(AddOrderDto addOrderDto) { |
| | | MallMember member = LoginUserUtil.getLoginUser(); |
| | | |
| | | MallAddressInfo address = mallAddressInfoMapper.selectAddressInfoByMemberIdAndId(member.getId(), addOrderDto.getAddressId()); |
| | | if (address == null) { |
| | | throw new FebsException("地址不存在"); |
| | | /** |
| | | * 根据会员星级判断是否可以购买该商品 |
| | | */ |
| | | MallMember mallMember = memberMapper.selectById(member.getId()); |
| | | String accountLevel = mallMember.getAccountLevel(); |
| | | Integer memberLevelCode = MemberAccountLevelEnum.NORMAL.getMemberLevelCode(accountLevel); |
| | | //获取商品星级 |
| | | MallGoods goods = mallGoodsMapper.selectById(addOrderDto.getGoodsId()); |
| | | String starRating = goods.getStarRating(); |
| | | Integer goodsStarCode = StarRatingEnum.NORMAL.getGoodsStarCode(starRating); |
| | | if(memberLevelCode < goodsStarCode){ |
| | | throw new FebsException("会员等级不够"); |
| | | } |
| | | /** |
| | | * 会员一天最多下单次数 |
| | | */ |
| | | DataDictionaryCustom buyTimesDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | DataDictionaryEnum.BUY_TIMES.getType(), DataDictionaryEnum.BUY_TIMES.getCode()); |
| | | Integer buyTimes = Integer.parseInt(buyTimesDic.getValue()); |
| | | |
| | | DateTime date = DateUtil.date(); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | String yyyyMMdd = sdf.format(date); |
| | | Integer times = this.baseMapper.selectCountByCreateTimeAndMemberId(yyyyMMdd,member.getId()); |
| | | if(buyTimes <= times){ |
| | | 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.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.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()); |
| | | |
| | | //补贴金额 |
| | | orderInfo.setSubsidyAmount(goods.getSubsidyAmount()); |
| | | 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); |
| | | // } |
| | | |
| | | this.baseMapper.insert(orderInfo); |
| | | BigDecimal total = BigDecimal.ZERO; |
| | |
| | | } |
| | | |
| | | orderInfo.setAmount(total); |
| | | orderInfo.setCarriage(carriage); |
| | | // if(2 == deliverType){ |
| | | // orderInfo.setDeliverType(2); |
| | | // orderInfo.setCarriage(BigDecimal.ZERO); |
| | | // }else{ |
| | | // orderInfo.setDeliverType(1); |
| | | // orderInfo.setCarriage(carriage); |
| | | // } |
| | | this.baseMapper.updateById(orderInfo); |
| | | |
| | | agentProducer.sendOrderCancelDelayMsg(orderInfo.getId(), 15 * 60 * 1000L); |
| | |
| | | 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")); |
| | | unipayDtoWx.setAmount(orderInfo.getAmount()); |
| | | unipayDtoWx.setFrpCode("WEIXIN_APP3"); |
| | | unipayDtoWx.setTradeMerchantNo("777180800385820"); |
| | | unipayDtoWx.setOrderNo(orderInfo.getOrderNo()); |
| | | List<MallOrderItem> itemsWx = orderInfo.getItems(); |
| | | if(CollUtil.isEmpty(itemsWx)){ |
| | | unipayDtoWx.setProductName("商品"); |
| | | }else{ |
| | | unipayDtoWx.setProductName(itemsWx.get(0).getGoodsName()); |
| | | } |
| | | String unipayStrWx = unipayService.unipay(unipayDtoWx); |
| | | if("fail" == unipayStrWx){ |
| | | throw new FebsException("支付失败"); |
| | | }else{ |
| | | // JSONUtil.parseObj(unipayStr); |
| | | JSONObject jsonObject = JSONUtil.parseObj(unipayStrWx); |
| | | payResultStr = (String) jsonObject.get("r7_TrxNo"); |
| | | rcResult = (String) jsonObject.get("rc_Result"); |
| | | } |
| | | orderInfo.setPayOrderNo(payResultStr); |
| | | // orderInfo.setPayOrderNo(payOrderDto.getPayOrderNo()); |
| | | // orderInfo.setPayImage(payOrderDto.getPayImage()); |
| | | orderInfo.setPayMethod("微信支付"); |
| | | agentProducer.sendOrderReturn(orderInfo.getId()); |
| | | break; |
| | | case "2": |
| | | // if (StrUtil.isNotBlank(orderInfo.getPayOrderNo())) { |
| | |
| | | // unipayDto.setAmount(new BigDecimal("0.01")); |
| | | unipayDto.setAmount(orderInfo.getAmount()); |
| | | unipayDto.setFrpCode("ALIPAY_H5"); |
| | | unipayDto.setTradeMerchantNo("777180800385820"); |
| | | unipayDto.setTradeMerchantNo("777184100385821"); |
| | | unipayDto.setOrderNo(orderInfo.getOrderNo()); |
| | | List<MallOrderItem> items = orderInfo.getItems(); |
| | | if(CollUtil.isEmpty(items)){ |
| | |
| | | |
| | | orderInfo.setPayOrderNo(orderInfo.getOrderNo()); |
| | | orderInfo.setPayMethod("余额支付"); |
| | | orderInfo.setStatus(OrderStatusEnum.WAIT_SHIPPING.getValue()); |
| | | // orderInfo.setStatus(OrderStatusEnum.WAIT_SHIPPING.getValue()); |
| | | //订单支付成功后,订单直接变成待收货 |
| | | orderInfo.setStatus(OrderStatusEnum.WAIT_FINISH.getValue()); |
| | | //生成物流编号 |
| | | String logisticsNo = MallUtils.getLogisticsNum(StrUtil.subSuf(payResultStr, payResultStr.length() - 2)); |
| | | orderInfo.setPayTradeNo(logisticsNo); |
| | | 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(); |
| | | } |
| | | // 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 (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.sendOrderReturn(orderInfo.getId()); |
| | | break; |
| | | case "4": |
| | | if (orderInfo.getOrderType() != 2) { |
| | |
| | | |
| | | OrderDetailVo orderDetailVo = MallOrderInfoConversion.INSTANCE.entityToDetailVo(orderInfo); |
| | | |
| | | if (orderInfo.getStatus() == OrderStatusEnum.WAIT_FINISH.getValue()) { |
| | | Integer deliverType = (ObjectUtil.isEmpty(orderInfo.getDeliverType()) ? new Integer(0):orderInfo.getDeliverType()); |
| | | if (orderInfo.getStatus() == OrderStatusEnum.WAIT_FINISH.getValue() && 2 != deliverType) { |
| | | MallExpressInfo expressInfo = expressInfoMapper.selectByOrderId(orderInfo.getId()); |
| | | orderDetailVo.setExpressNo(expressInfo.getExpressNo()); |
| | | orderDetailVo.setExpressCom(expressInfo.getExpressCom()); |
| | |
| | | |
| | | long remainTime = DateUtil.between(new Date(), endTime, DateUnit.SECOND, false); |
| | | orderDetailVo.setRemainTime(remainTime); |
| | | } |
| | | if(2 == deliverType){ |
| | | MallShopApply mallShopApply = mallShopApplyMapper.selectById(orderInfo.getShopId()); |
| | | if(ObjectUtil.isNotEmpty(mallShopApply)){ |
| | | ApiShopApplyVo apiShopApplyVo = new ApiShopApplyVo(); |
| | | apiShopApplyVo.setName(mallShopApply.getName()); |
| | | apiShopApplyVo.setPhone(mallShopApply.getPhone()); |
| | | apiShopApplyVo.setSaleArea(mallShopApply.getSaleArea()); |
| | | apiShopApplyVo.setLatitude(mallShopApply.getLatitude()); |
| | | apiShopApplyVo.setLongitude(mallShopApply.getLongitude()); |
| | | apiShopApplyVo.setShopName(mallShopApply.getShopName()); |
| | | apiShopApplyVo.setAddress(mallShopApply.getAddress()); |
| | | orderDetailVo.setApiShopApplyVo(apiShopApplyVo); |
| | | } |
| | | } |
| | | return orderDetailVo; |
| | | } |
| | |
| | | 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 |