| | |
| | | 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.conversion.MallTeamLeaderConversion; |
| | | import cc.mrbird.febs.mall.dto.*; |
| | | import cc.mrbird.febs.mall.entity.*; |
| | | import cc.mrbird.febs.mall.mapper.*; |
| | | import cc.mrbird.febs.mall.service.*; |
| | | import cc.mrbird.febs.mall.vo.ApiLeaderListVo; |
| | | 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.BrandWCPayRequestData; |
| | | import cc.mrbird.febs.pay.model.OrderStateDto; |
| | | import cc.mrbird.febs.pay.service.IPayService; |
| | | import cc.mrbird.febs.pay.service.IXcxPayService; |
| | | import cc.mrbird.febs.pay.util.WeixinServiceUtil; |
| | |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.crypto.SecureUtil; |
| | | import cn.hutool.json.JSONArray; |
| | | import cn.hutool.json.JSONObject; |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections.CollectionUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | private final IXcxPayService iXcxPayService; |
| | | private final IMallAchieveService mallAchieveService; |
| | | private final MallRefundMapper mallRefundMapper; |
| | | private final MallTeamLeaderMapper mallTeamLeaderMapper; |
| | | private final MallMemberMapper mallMemberMapper; |
| | | private final DataDictionaryCustomMapper dataDictionaryCustomMapper; |
| | | private final MallLeaderAchieveMapper mallLeaderAchieveMapper; |
| | | private final IApiMallTeamLeaderService iApiMallTeamLeaderService; |
| | | private final IMallElectronicFenceService iMallElectronicFenceService; |
| | | private final MallElectronicFenceMapper mallElectronicFenceMapper; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Long createOrder(AddOrderDto addOrderDto) { |
| | | // synchronized(this){ |
| | | MallMember member = LoginUserUtil.getLoginUser(); |
| | | String takeUniqueCode = addOrderDto.getTakeUniqueCode(); |
| | | if(StrUtil.isEmpty(takeUniqueCode)){ |
| | | throw new FebsException("请选择自提点"); |
| | | } |
| | | |
| | | MallTeamLeader mallTeamLeader = mallTeamLeaderMapper.selectLeaderByUniqueCode(takeUniqueCode); |
| | | if(ObjectUtil.isEmpty(mallTeamLeader)){ |
| | | throw new FebsException("请重新选择团长"); |
| | | } |
| | | |
| | | //订单范围内才允许下单 |
| | | MallAddressInfo address = mallAddressInfoMapper.selectAddressInfoByMemberIdAndId(member.getId(), addOrderDto.getAddressId()); |
| | | // MallElectronicFence mallElectronicFence = mallElectronicFenceMapper.selectByTeamLeaderCode(mallTeamLeader.getUniqueCode()); |
| | | // if(ObjectUtil.isNotEmpty(mallElectronicFence)){ |
| | | // String inStr = iMallElectronicFenceService.fenceToLocation(mallElectronicFence.getGKey(), |
| | | // mallElectronicFence.getServiceId(), address.getLongitude() + "," + address.getLatitude(), mallElectronicFence.getGid()); |
| | | // if("1".equals(inStr)){ |
| | | // throw new FebsException("不在当前团长的配送范围内"); |
| | | // } |
| | | // } |
| | | |
| | | String orderNo = MallUtils.getOrderNum(); |
| | | MallOrderInfo orderInfo = new MallOrderInfo(); |
| | |
| | | BigDecimal total = BigDecimal.ZERO; |
| | | BigDecimal carriage = BigDecimal.ZERO; |
| | | for (AddOrderItemDto item : addOrderDto.getItems()) { |
| | | MallOrderItem orderItem = new MallOrderItem(); |
| | | 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 (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() + "已下架"); |
| | | } |
| | | 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()); |
| | | 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()); |
| | | orderItem.setState(1); |
| | | |
| | | total = total.add(amount); |
| | | } else { |
| | | MallGoodsSku sku = mallGoodsSkuMapper.selectSkuInfoById(item.getSkuId()); |
| | | if (sku == null) { |
| | | throw new FebsException("购买商品或sku不存在"); |
| | | } |
| | | total = total.add(amount); |
| | | } else { |
| | | MallGoodsSku sku = mallGoodsSkuMapper.selectSkuInfoById(item.getSkuId()); |
| | | if (sku == null) { |
| | | throw new FebsException("购买商品或sku不存在"); |
| | | } |
| | | |
| | | if (sku.getStock() < item.getCnt()) { |
| | | throw new FebsException(sku.getSkuName() + "库存不足"); |
| | | } |
| | | if (sku.getStock() < item.getCnt()) { |
| | | throw new FebsException(sku.getSkuName() + "库存不足"); |
| | | } |
| | | |
| | | MallGoods mallGoods = mallGoodsMapper.selectById(sku.getGoodsId()); |
| | | 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 (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() + "已下架"); |
| | | } |
| | | |
| | | // mallGoods.setStock(mallGoods.getStock() - item.getCnt()); |
| | | // mallGoods.setVolume(mallGoods.getVolume() + item.getCnt()); |
| | | Integer goodsResult = mallGoodsMapper.upDateStockAndVolumeByGoodsId(mallGoods.getId(), item.getCnt()); |
| | | if(1 != goodsResult){ |
| | | throw new FebsException(mallGoods.getGoodsName() + "库存不足"); |
| | | } |
| | | |
| | | BigDecimal amount = sku.getPresentPrice().multiply(BigDecimal.valueOf(item.getCnt())); |
| | | orderItem.setAmount(amount); |
| | | orderItem.setCnt(item.getCnt()); |
| | | orderItem.setOrderId(orderInfo.getId()); |
| | | orderItem.setPrice(sku.getPresentPrice()); |
| | | orderItem.setGoodsId(sku.getGoodsId()); |
| | | orderItem.setGoodsName(sku.getGoodsName()); |
| | | orderItem.setSkuId(sku.getId()); |
| | | orderItem.setState(1); |
| | | 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()); |
| | | // mallGoodsSkuMapper.updateById(sku); |
| | | Integer skuResult = mallGoodsSkuMapper.upDateStockAndVolumeBySkuId(sku.getId(),item.getCnt()); |
| | | if(1 != skuResult){ |
| | | throw new FebsException(sku.getSkuName() + "库存不足"); |
| | | } |
| | | if (addOrderDto.getType() == 1) { |
| | | mallShoppingCartMapper.delBySkuId(sku.getId(), member.getId()); |
| | | } |
| | | } |
| | | |
| | | if (MallGoods.ISSALE_STATUS_DISABLED.equals(mallGoods.getIsSale())) { |
| | | throw new FebsException(mallGoods.getGoodsName() + "已下架"); |
| | | } |
| | | |
| | | BigDecimal amount = sku.getPresentPrice().multiply(BigDecimal.valueOf(item.getCnt())); |
| | | orderItem.setAmount(amount); |
| | | orderItem.setCnt(item.getCnt()); |
| | | orderItem.setOrderId(orderInfo.getId()); |
| | | orderItem.setPrice(sku.getPresentPrice()); |
| | | orderItem.setGoodsId(sku.getGoodsId()); |
| | | orderItem.setGoodsName(sku.getGoodsName()); |
| | | orderItem.setSkuId(sku.getId()); |
| | | 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()); |
| | | mallGoodsSkuMapper.updateById(sku); |
| | | |
| | | if (addOrderDto.getType() == 1) { |
| | | mallShoppingCartMapper.delBySkuId(sku.getId(), member.getId()); |
| | | } |
| | | } |
| | | mallOrderItemMapper.insert(orderItem); |
| | | mallOrderItemMapper.insert(orderItem); |
| | | } |
| | | |
| | | //配送费 |
| | | BigDecimal delivaryAmount = addOrderDto.getDeliveryAmount() == null ? BigDecimal.ZERO : addOrderDto.getDeliveryAmount(); |
| | | if(BigDecimal.ZERO.compareTo(delivaryAmount) < 0 && 1 == addOrderDto.getIsHome()){ |
| | | total = total.add(delivaryAmount); |
| | | orderInfo.setCarriage(delivaryAmount); |
| | | } |
| | | orderInfo.setAmount(total); |
| | | orderInfo.setCarriage(carriage); |
| | | |
| | | MallAddressInfo address = mallAddressInfoMapper.selectAddressInfoByMemberIdAndId(member.getId(), addOrderDto.getAddressId()); |
| | | orderInfo.setName(address.getName()); |
| | | orderInfo.setPhone(address.getPhone()); |
| | | orderInfo.setIsHome(addOrderDto.getIsHome()); |
| | | //订单金额大于50,且选择送货上门,订单需要选择地址信息 |
| | | if(total.compareTo(new BigDecimal(50)) > 0 && 1 == addOrderDto.getIsHome()){ |
| | | if(1 == addOrderDto.getIsHome()){ |
| | | if (StrUtil.isBlank(address.getLatitude())||StrUtil.isBlank(address.getLongitude())) { |
| | | throw new FebsException("请添加地址"); |
| | | } |
| | |
| | | |
| | | agentProducer.sendOrderCancelDelayMsg(orderInfo.getId(), 15 * 60 * 1000L); |
| | | return orderInfo.getId(); |
| | | // } |
| | | } |
| | | |
| | | |
| | |
| | | orderInfo.setStatus(OrderStatusEnum.CANCEL.getValue()); |
| | | orderInfo.setCancelType(MallOrderInfo.CANCEL_BY_SELF); |
| | | this.baseMapper.updateById(orderInfo); |
| | | |
| | | |
| | | |
| | | List<MallOrderItem> mallOrderItemList = mallOrderItemMapper.selectListByOrderId(orderInfo.getId()); |
| | | if(CollUtil.isNotEmpty(mallOrderItemList)){ |
| | | for(MallOrderItem mallOrderItem : mallOrderItemList){ |
| | | MallGoodsSku sku = mallGoodsSkuMapper.selectSkuInfoById(mallOrderItem.getSkuId()); |
| | | if (sku == null) { |
| | | throw new FebsException("购买商品或sku不存在"); |
| | | } |
| | | |
| | | if (sku.getStock() < mallOrderItem.getCnt()) { |
| | | throw new FebsException(sku.getSkuName() + "库存不足"); |
| | | } |
| | | |
| | | MallGoods mallGoods = mallGoodsMapper.selectById(sku.getGoodsId()); |
| | | Integer goodsResult = mallGoodsMapper.updateStockAndVolumeByGoodsId(mallGoods.getId(), mallOrderItem.getCnt()); |
| | | if(1 != goodsResult){ |
| | | throw new FebsException(mallGoods.getGoodsName() + "库存不足"); |
| | | } |
| | | |
| | | Integer skuResult = mallGoodsSkuMapper.updateStockAndVolumeBySkuId(sku.getId(),mallOrderItem.getCnt()); |
| | | if(1 != skuResult){ |
| | | throw new FebsException(sku.getSkuName() + "库存不足"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 根据用户ID和订单ID获取所购买商品名称 |
| | | * @return 所含商品名称(多个以","隔开) |
| | | */ |
| | | public String getProductNames(Long memberId, Long orderId) { |
| | | MallOrderInfo mallOrderInfo = this.baseMapper.selectOrderByMemberIdAndId(memberId, orderId); |
| | | List<MallOrderItem> details = mallOrderInfo.getItems(); |
| | | if (CollectionUtils.isEmpty(details)) { |
| | | return ""; |
| | | } |
| | | StringBuffer productNameBuffer = new StringBuffer(); |
| | | Integer maxLength = 30; |
| | | for (int i = 0; i< details.size(); i++) { |
| | | MallOrderItem mallOrderItem = details.get(i); |
| | | String goodsName = mallOrderItem.getGoodsName(); |
| | | if (goodsName == null) { |
| | | continue; |
| | | } |
| | | if (i == 0 && goodsName.length() > maxLength) { |
| | | productNameBuffer.append(goodsName.substring(0, maxLength) + "..."); |
| | | break; |
| | | } |
| | | if ((productNameBuffer.length() + goodsName.length()) > maxLength) { |
| | | productNameBuffer.append("等"); |
| | | break; |
| | | } |
| | | productNameBuffer.append(goodsName + ","); |
| | | } |
| | | String productNames = productNameBuffer.toString(); |
| | | if (productNames.endsWith(",")) { |
| | | productNames = productNames.substring(0, productNames.length() - 1); |
| | | } |
| | | if (productNames.endsWith(",等")) { |
| | | productNames = productNames.substring(0, productNames.length() - 2) + "等"; |
| | | } |
| | | return productNames; |
| | | } |
| | | |
| | | @Override |
| | |
| | | wxResultStr = JSONUtil.toJsonStr(brandWCPayRequestData); |
| | | payResultStr = brandWCPayRequestData.getPrepay_id(); |
| | | orderInfo.setPayMethod("微信支付"); |
| | | agentProducer.sendOrderReturn(orderInfo.getId()); |
| | | // agentProducer.sendOrderReturn(orderInfo.getId()); |
| | | break; |
| | | case "2": |
| | | if (StrUtil.isNotBlank(orderInfo.getPayOrderNo())) { |
| | |
| | | orderInfo.setStatus(OrderStatusEnum.WAIT_SHIPPING.getValue()); |
| | | orderInfo.setPayTime(new Date()); |
| | | orderInfo.setPayResult("1"); |
| | | orderInfo.setDeliveryState(OrderDeliveryStateEnum.DELIVERY_WAIT.getValue()); |
| | | |
| | | 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); |
| | | } |
| | | |
| | | 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()); |
| | | } |
| | | } |
| | | } |
| | | // 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); |
| | | // } |
| | | // |
| | | // 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); |
| | | } |
| | | } |
| | | // 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()); |
| | | // agentProducer.sendAutoLevelUpMsg(member.getId()); |
| | | // agentProducer.sendOrderReturn(orderInfo.getId()); |
| | | break; |
| | | case "4": |
| | | if (orderInfo.getOrderType() != 2) { |
| | |
| | | orderInfo.setTakeCode(takeCode); |
| | | |
| | | this.baseMapper.updateById(orderInfo); |
| | | |
| | | |
| | | |
| | | // OrderStateDto orderStateDto = new OrderStateDto(); |
| | | // orderStateDto.setOrderNo(orderInfo.getOrderNo()); |
| | | // String productNames = getProductNames(orderInfo.getMemberId(), orderInfo.getId()); |
| | | // orderStateDto.setGoodsName(StrUtil.isEmpty(productNames)?"商品":productNames); |
| | | // orderStateDto.setOrderState("已送达自提点"); |
| | | // orderStateDto.setTakeCode(orderInfo.getTakeCode()); |
| | | // String takeUniqueCode = orderInfo.getTakeUniqueCode(); |
| | | // MallTeamLeader mallTeamLeader = mallTeamLeaderMapper.selectLeaderByUniqueCode(takeUniqueCode); |
| | | // orderStateDto.setAddressArea(mallTeamLeader.getAddressArea()); |
| | | // orderStateDto.setOpenId(mallMemberMapper.selectById(orderInfo.getMemberId()).getOpenId()); |
| | | // DataDictionaryCustom dataDictionaryCustom = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.WX_TEMPLATE_ID_ONE.getType(), DataDictionaryEnum.WX_TEMPLATE_ID_ONE.getCode()); |
| | | // orderStateDto.setTemplateId(dataDictionaryCustom.getValue()); |
| | | //// iXcxPayService.pushOrderToAddress(orderStateDto); |
| | | // iXcxPayService.uniformMessageSend(orderStateDto); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("orderInfo", payResultStr); |
| | | map.put("orderNo", orderInfo.getOrderNo()); |
| | |
| | | |
| | | @Override |
| | | public List<OrderListVo> findOrderList(OrderListDto orderListDto) { |
| | | log.info("订单查询"); |
| | | MallMember member = LoginUserUtil.getLoginUser(); |
| | | IPage<MallOrderInfo> page = new Page<>(orderListDto.getPageNum(), orderListDto.getPageSize()); |
| | | |
| | | orderListDto.setMemberId(member.getId()); |
| | | IPage<MallOrderInfo> mallOrderInfos = this.baseMapper.selectApiOrderListInPage(page, orderListDto); |
| | | // IPage<MallOrderInfo> mallOrderInfos = this.baseMapper.selectApiOrderListInPage(page, orderListDto); |
| | | IPage<MallOrderInfo> mallOrderInfos = this.baseMapper.selectNewApiOrderListInPage(page, orderListDto); |
| | | if (CollUtil.isNotEmpty(mallOrderInfos.getRecords())) { |
| | | mallOrderInfos.getRecords().forEach(item -> { |
| | | item.setItems(mallOrderItemMapper.selectListByOrderId(item.getId())); |
| | | }); |
| | | } |
| | | return MallOrderInfoConversion.INSTANCE.entitysToVos(mallOrderInfos.getRecords()); |
| | | } |
| | | |
| | | @Override |
| | | public OrderDetailVo findOrderDetailsById(Long id) { |
| | | MallOrderInfo orderInfo = this.baseMapper.selectOrderDetailsById(id); |
| | | if (orderInfo == null || AppContants.DEL_FLAG_Y == orderInfo.getDelFlag()) { |
| | | // if (orderInfo == null || AppContants.DEL_FLAG_Y == orderInfo.getDelFlag()) { |
| | | if (ObjectUtil.isNull(orderInfo)) { |
| | | throw new FebsException("订单不存在"); |
| | | } |
| | | |
| | | OrderDetailVo orderDetailVo = MallOrderInfoConversion.INSTANCE.entityToDetailVo(orderInfo); |
| | | |
| | | if (orderInfo.getStatus() == OrderStatusEnum.WAIT_FINISH.getValue()) { |
| | | MallExpressInfo expressInfo = expressInfoMapper.selectByOrderId(orderInfo.getId()); |
| | | orderDetailVo.setExpressNo(expressInfo.getExpressNo()); |
| | | orderDetailVo.setExpressCom(expressInfo.getExpressCom()); |
| | | } |
| | | // if (orderInfo.getStatus() == OrderStatusEnum.WAIT_FINISH.getValue()) { |
| | | // MallExpressInfo expressInfo = expressInfoMapper.selectByOrderId(orderInfo.getId()); |
| | | // orderDetailVo.setExpressNo(expressInfo.getExpressNo()); |
| | | // orderDetailVo.setExpressCom(expressInfo.getExpressCom()); |
| | | // } |
| | | |
| | | if (orderInfo.getStatus() == OrderStatusEnum.REFUNDING.getValue() || orderInfo.getStatus() == OrderStatusEnum.REFUNDED.getValue()) { |
| | | MallOrderRefund orderRefund = mallOrderRefundMapper.selectOrderRefundByOrderId(orderInfo.getId()); |
| | |
| | | throw new FebsException("该状态不能确认收货"); |
| | | } |
| | | |
| | | if (orderInfo.getDeliveryState() != OrderDeliveryStateEnum.DELIVERY_FINISH.getValue()) { |
| | | throw new FebsException("还未送至自提点"); |
| | | } |
| | | |
| | | List<MallRefundEntity> mallRefundEntities = mallRefundMapper.selectByItemIdAndOrderIdAndState(null, orderInfo.getId(), 3); |
| | | if(CollUtil.isNotEmpty(mallRefundEntities)){ |
| | | throw new FebsException("请先处理退款商品"); |
| | | } |
| | | |
| | | orderInfo.setStatus(OrderStatusEnum.FINISH.getValue()); |
| | | orderInfo.setReceivingTime(new Date()); |
| | | this.baseMapper.updateById(orderInfo); |
| | | |
| | | //生成一条团长提成记录 |
| | | Long orderInfoId = orderInfo.getId(); |
| | | List<MallOrderItem> mallOrderItemList = mallOrderItemMapper.selectListByOrderId(orderInfoId); |
| | | if(CollUtil.isNotEmpty(mallOrderItemList)){ |
| | | |
| | | MallTeamLeader mallTeamLeader = mallTeamLeaderMapper.selectLeaderByUniqueCode(orderInfo.getTakeUniqueCode()); |
| | | Integer profitSwitch = mallTeamLeader.getProfitSwitch()==null?2:mallTeamLeader.getProfitSwitch(); |
| | | BigDecimal bonusPercent =new BigDecimal(mallTeamLeader.getBonusPercent()==null?"0":mallTeamLeader.getBonusPercent()); |
| | | |
| | | if(1 == profitSwitch){ |
| | | for(MallOrderItem mallOrderItem : mallOrderItemList){ |
| | | Integer state = mallOrderItem.getState() == null ? 1 : mallOrderItem.getState(); |
| | | if(1 == state){ |
| | | MallLeaderAchieve mallLeaderAchieve = new MallLeaderAchieve(); |
| | | mallLeaderAchieve.setMemberId(orderInfo.getMemberId()); |
| | | mallLeaderAchieve.setOrderNo(orderInfo.getOrderNo()); |
| | | mallLeaderAchieve.setOrderItemId(mallOrderItem.getId()); |
| | | BigDecimal itemAmount = mallOrderItem.getAmount(); |
| | | mallLeaderAchieve.setAmount(itemAmount); |
| | | BigDecimal bigDecimal = bonusPercent.multiply(itemAmount).setScale(2, BigDecimal.ROUND_DOWN); |
| | | mallLeaderAchieve.setProfitAmount(bigDecimal); |
| | | mallLeaderAchieve.setUniqueCode(orderInfo.getTakeUniqueCode()); |
| | | mallLeaderAchieve.setState(MallLeaderAchieve.STATE_ONE); |
| | | mallLeaderAchieveMapper.insert(mallLeaderAchieve); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | orderInfo.setStatus(OrderStatusEnum.CANCEL.getValue()); |
| | | orderInfo.setCancelType(MallOrderInfo.CANCEL_OVERTIME_NO_PAY); |
| | | this.baseMapper.updateById(orderInfo); |
| | | |
| | | List<MallOrderItem> mallOrderItemList = mallOrderItemMapper.selectListByOrderId(orderInfo.getId()); |
| | | if(CollUtil.isNotEmpty(mallOrderItemList)){ |
| | | for(MallOrderItem mallOrderItem : mallOrderItemList){ |
| | | MallGoodsSku sku = mallGoodsSkuMapper.selectSkuInfoById(mallOrderItem.getSkuId()); |
| | | if (sku == null) { |
| | | throw new FebsException("购买商品或sku不存在"); |
| | | } |
| | | |
| | | if (sku.getStock() < mallOrderItem.getCnt()) { |
| | | throw new FebsException(sku.getSkuName() + "库存不足"); |
| | | } |
| | | |
| | | MallGoods mallGoods = mallGoodsMapper.selectById(sku.getGoodsId()); |
| | | Integer goodsResult = mallGoodsMapper.updateStockAndVolumeByGoodsId(mallGoods.getId(), mallOrderItem.getCnt()); |
| | | if(1 != goodsResult){ |
| | | throw new FebsException(mallGoods.getGoodsName() + "库存不足"); |
| | | } |
| | | |
| | | Integer skuResult = mallGoodsSkuMapper.updateStockAndVolumeBySkuId(sku.getId(),mallOrderItem.getCnt()); |
| | | if(1 != skuResult){ |
| | | throw new FebsException(sku.getSkuName() + "库存不足"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | if(1 != deliveryState){ |
| | | return new FebsResponse().fail().message("订单不是待配送状态"); |
| | | } |
| | | QueryWrapper<MallRefundEntity> objectQueryWrapper = new QueryWrapper<>(); |
| | | objectQueryWrapper.eq("member_id",member.getId()); |
| | | objectQueryWrapper.eq("order_id",mallOrderInfo.getId()); |
| | | MallRefundEntity mallRefund = mallRefundMapper.selectOne(objectQueryWrapper); |
| | | //根据子订单生成退款记录 |
| | | List<MallOrderItem> mallOrderItemList = mallOrderItemMapper.selectListByOrderId(id); |
| | | if(CollUtil.isEmpty(mallOrderItemList)){ |
| | | return new FebsResponse().fail().message("订单不存在"); |
| | | } |
| | | for(MallOrderItem mallOrderItem : mallOrderItemList){ |
| | | QueryWrapper<MallRefundEntity> objectQueryWrapper = new QueryWrapper<>(); |
| | | objectQueryWrapper.eq("member_id",member.getId()); |
| | | objectQueryWrapper.eq("order_id",mallOrderInfo.getId()); |
| | | objectQueryWrapper.eq("item_id",mallOrderItem.getId()); |
| | | MallRefundEntity mallRefund = mallRefundMapper.selectOne(objectQueryWrapper); |
| | | MallRefundEntity mallRefundEntity = new MallRefundEntity(); |
| | | if(ObjectUtil.isEmpty(mallRefund)){ |
| | | mallRefundEntity.setRefundNo(mallOrderInfo.getOrderNo()+"_RITEM"+mallOrderItem.getId()); |
| | | mallRefundEntity.setMemberId(member.getId()); |
| | | mallRefundEntity.setOrderId(mallOrderInfo.getId()); |
| | | mallRefundEntity.setItemId(mallOrderItem.getId()); |
| | | if("余额支付".equals(mallOrderInfo.getPayMethod())){ |
| | | mallRefundEntity.setType(3); |
| | | }else if("微信支付".equals(mallOrderInfo.getPayMethod())){ |
| | | mallRefundEntity.setType(1); |
| | | }else{ |
| | | mallRefundEntity.setType(3); |
| | | } |
| | | mallRefundEntity.setState(3); |
| | | mallRefundEntity.setAmount(mallOrderItem.getAmount()); |
| | | mallRefundMapper.insert(mallRefundEntity); |
| | | }else{ |
| | | if(mallRefund.getState() == 1){ |
| | | return new FebsResponse().fail().message("订单已退款"); |
| | | } |
| | | if(mallRefund.getState() == 2 || mallRefund.getState() == 3){ |
| | | mallRefundEntity.setId(mallRefund.getId()); |
| | | mallRefundEntity.setRefundNo(mallRefund.getRefundNo()); |
| | | mallRefundEntity.setMemberId(mallRefund.getMemberId()); |
| | | mallRefundEntity.setOrderId(mallRefund.getOrderId()); |
| | | mallRefundEntity.setItemId(mallRefund.getItemId()); |
| | | mallRefundEntity.setType(mallRefund.getType()); |
| | | mallRefundEntity.setState(3); |
| | | mallRefundEntity.setAmount(mallRefund.getAmount()); |
| | | mallRefundMapper.updateById(mallRefundEntity); |
| | | } |
| | | } |
| | | ApiLeaderRefundOrderDto apiLeaderRefundOrderDto = new ApiLeaderRefundOrderDto(); |
| | | apiLeaderRefundOrderDto.setOrderId(mallOrderInfo.getId()); |
| | | apiLeaderRefundOrderDto.setItemId(mallOrderItem.getId()); |
| | | apiLeaderRefundOrderDto.setAgreeState(1); |
| | | iApiMallTeamLeaderService.leaderRefundOrder(apiLeaderRefundOrderDto); |
| | | } |
| | | return new FebsResponse().success(); |
| | | } |
| | | |
| | | @Override |
| | | public FebsResponse applyRefundOrder(ApplyRefundOrderDto applyRefundOrderDto) { |
| | | Long orderId = applyRefundOrderDto.getOrderId(); |
| | | Long itemId = applyRefundOrderDto.getItemId(); |
| | | MallMember member = LoginUserUtil.getLoginUser(); |
| | | MallOrderInfo mallOrderInfo = this.baseMapper.selectById(orderId); |
| | | if(ObjectUtil.isEmpty(mallOrderInfo)){ |
| | | return new FebsResponse().fail().message("订单不存在"); |
| | | } |
| | | |
| | | List<MallRefundEntity> mallRefundEntitieSuccess = mallRefundMapper.selectByItemIdAndOrderIdAndState(itemId,orderId,1); |
| | | List<MallRefundEntity> mallRefundEntitiesIng = mallRefundMapper.selectByItemIdAndOrderIdAndState(itemId,orderId,3); |
| | | if(CollUtil.isNotEmpty(mallRefundEntitieSuccess) || CollUtil.isNotEmpty(mallRefundEntitiesIng)){ |
| | | return new FebsResponse().fail().message("该订单无法申请退款"); |
| | | } |
| | | |
| | | MallRefundEntity mallRefundEntity = new MallRefundEntity(); |
| | | if(ObjectUtil.isEmpty(mallRefund)){ |
| | | mallRefundEntity.setRefundNo(mallOrderInfo.getOrderNo()+"_r"); |
| | | mallRefundEntity.setMemberId(member.getId()); |
| | | mallRefundEntity.setOrderId(mallOrderInfo.getId()); |
| | | mallRefundEntity.setType(1); |
| | | mallRefundEntity.setState(3); |
| | | mallRefundEntity.setAmount(mallOrderInfo.getAmount()); |
| | | mallRefundMapper.insert(mallRefundEntity); |
| | | } |
| | | if(mallRefund.getState() == 1){ |
| | | return new FebsResponse().fail().message("订单已退款"); |
| | | } |
| | | if(mallRefund.getState() == 3){ |
| | | return new FebsResponse().fail().message("订单退款中"); |
| | | } |
| | | if(mallRefund.getState() == 2){ |
| | | mallRefundEntity.setId(mallRefund.getId()); |
| | | mallRefundEntity.setRefundNo(mallRefund.getRefundNo()); |
| | | mallRefundEntity.setMemberId(mallRefund.getMemberId()); |
| | | mallRefundEntity.setOrderId(mallRefund.getOrderId()); |
| | | mallRefundEntity.setType(mallRefund.getType()); |
| | | mallRefundEntity.setState(3); |
| | | mallRefundEntity.setAmount(mallRefund.getAmount()); |
| | | mallRefundMapper.updateById(mallRefundEntity); |
| | | } |
| | | |
| | | //退款订单编号 |
| | | String orderNo = mallOrderInfo.getOrderNo(); |
| | | //退款退款编号 |
| | | String refundNo = mallRefundEntity.getRefundNo(); |
| | | //退款订单金额 |
| | | BigDecimal orderAmount = mallOrderInfo.getAmount(); |
| | | BigDecimal aa = new BigDecimal(100); |
| | | int orderMoney = orderAmount.multiply(aa).intValue(); |
| | | |
| | | //退款退款金额 |
| | | BigDecimal refundAmount = mallRefundEntity.getAmount(); |
| | | BigDecimal bb = new BigDecimal(100); |
| | | int refundMoney = refundAmount.multiply(bb).intValue(); |
| | | |
| | | Boolean flag = false; |
| | | Boolean debug = xcxProperties.getDebug(); |
| | | if (debug) { |
| | | boolean b = weixinServiceUtil.comRefund(orderNo, refundNo, 1, 1, null); |
| | | flag = b; |
| | | } else { |
| | | log.info("开始调用退款接口。。。退款编号为{}", refundNo); |
| | | boolean b = weixinServiceUtil.comRefund(orderNo, refundNo, orderMoney, refundMoney, null); |
| | | flag = b; |
| | | } |
| | | |
| | | /** |
| | | * 更新退款表 |
| | | * 更新订单表 |
| | | */ |
| | | Long refundId = mallRefundEntity.getId(); |
| | | MallRefundEntity mallRefundOld = mallRefundMapper.selectById(refundId); |
| | | MallOrderInfo mallOrderInfoOld = this.baseMapper.selectByOrderNo(orderNo); |
| | | if(flag){ |
| | | mallRefundOld.setState(1); |
| | | mallRefundMapper.updateById(mallRefundOld); |
| | | mallOrderInfoOld.setStatus(OrderStatusEnum.REFUNDED.getValue()); |
| | | this.baseMapper.updateById(mallOrderInfoOld); |
| | | MallOrderItem mallOrderItem = mallOrderItemMapper.selectById(itemId); |
| | | if(ObjectUtil.isNotEmpty(mallOrderItem)){ |
| | | mallOrderItem.setState(2); |
| | | mallOrderItemMapper.updateById(mallOrderItem); |
| | | mallRefundEntity.setRefundNo(mallOrderInfo.getOrderNo()+"_RITEM"+itemId); |
| | | mallRefundEntity.setItemId(itemId); |
| | | }else{ |
| | | mallRefundOld.setState(2); |
| | | mallRefundMapper.updateById(mallRefundOld); |
| | | return new FebsResponse().fail().message("退款失败,请联系客服人员"); |
| | | |
| | | mallRefundEntity.setRefundNo(mallOrderInfo.getOrderNo()+"_R"+orderId); |
| | | } |
| | | return new FebsResponse().success().message("退款成功"); |
| | | mallRefundEntity.setRefundReason(applyRefundOrderDto.getRefundReason()); |
| | | mallRefundEntity.setRefundRemark(applyRefundOrderDto.getRefundRemark()); |
| | | mallRefundEntity.setRefundPic(applyRefundOrderDto.getRefundPic()); |
| | | mallRefundEntity.setMemberId(member.getId()); |
| | | mallRefundEntity.setState(3); |
| | | mallRefundEntity.setType(applyRefundOrderDto.getType()); |
| | | mallRefundEntity.setOrderId(orderId); |
| | | mallRefundEntity.setAmount(mallOrderItem.getAmount()); |
| | | mallRefundMapper.insert(mallRefundEntity); |
| | | return new FebsResponse().success().message("已申请"); |
| | | } |
| | | |
| | | @Override |
| | | public FebsResponse cancelRefundOrder(Long id) { |
| | | MallRefundEntity mallRefundEntity = mallRefundMapper.selectById(id); |
| | | mallRefundEntity.setState(2); |
| | | mallRefundMapper.updateById(mallRefundEntity); |
| | | Long itemId = mallRefundEntity.getItemId(); |
| | | MallOrderItem mallOrderItem = mallOrderItemMapper.selectById(itemId); |
| | | mallOrderItem.setState(1); |
| | | mallOrderItemMapper.updateById(mallOrderItem); |
| | | return new FebsResponse().success().message("已取消"); |
| | | } |
| | | |
| | | @Override |
| | | public Boolean createOrderVerify(ApiCreateOrderVerifyDto apiCreateOrderVerifyDto) { |
| | | Boolean flag = false; |
| | | Long addressId = apiCreateOrderVerifyDto.getAddressId(); |
| | | String takeUniqueCode = apiCreateOrderVerifyDto.getTakeUniqueCode(); |
| | | |
| | | MallAddressInfo mallAddressInfo = mallAddressInfoMapper.selectById(addressId); |
| | | if(ObjectUtil.isEmpty(mallAddressInfo)){ |
| | | return flag; |
| | | } |
| | | MallElectronicFence mallElectronicFence = mallElectronicFenceMapper.selectByTeamLeaderCode(takeUniqueCode); |
| | | if(ObjectUtil.isEmpty(mallElectronicFence)){ |
| | | return flag; |
| | | } |
| | | //{"data":{"count":1,"results":[{"gfid":800899,"gfname":"87053658_fence","in":0}]},"errcode":10000,"errdetail":null,"errmsg":"OK"} |
| | | String resultsStr = iMallElectronicFenceService.fenceToLocation(mallElectronicFence.getGKey(), |
| | | mallElectronicFence.getServiceId(), |
| | | mallAddressInfo.getLongitude() + "," + mallAddressInfo.getLatitude(), |
| | | mallElectronicFence.getGid()); |
| | | if("fail".equals(resultsStr)){ |
| | | return flag; |
| | | } |
| | | JSONArray objects = JSONUtil.parseArray(resultsStr); |
| | | for(Object obj : objects){ |
| | | //{"gfid":800899,"gfname":"87053658_fence","in":0} |
| | | JSONObject jsonObject = JSONUtil.parseObj(obj); |
| | | String gfid = jsonObject.get("gfid").toString(); |
| | | String in = jsonObject.get("in").toString(); |
| | | String gfname = jsonObject.get("gfname").toString(); |
| | | //指定坐标是否在围栏中 |
| | | //1:在, |
| | | //0:不在; |
| | | if("1".equals(in)){ |
| | | flag = true; |
| | | } |
| | | } |
| | | return flag; |
| | | } |
| | | |
| | | } |