| | |
| | | package com.doumee.service.business.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.doumee.biz.system.AreasBiz; |
| | | import com.doumee.config.xyy.XyyConfig; |
| | | import com.doumee.config.xyy.dto.PrintRequest; |
| | | import com.doumee.biz.system.OperationConfigBiz; |
| | | import com.doumee.biz.system.SystemDictDataBiz; |
| | | import com.doumee.config.wx.WxMiniConfig; |
| | | import com.doumee.config.wx.WxPayProperties; |
| | | import com.doumee.config.wx.WxPayV3Service; |
| | | import com.doumee.core.utils.jpush.JPushUtil; |
| | | import com.wechat.pay.java.service.refund.model.Refund; |
| | | import com.doumee.core.constants.Constants; |
| | | import com.doumee.core.constants.ResponseStatus; |
| | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.*; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | |
| | | private AreasService areasService; |
| | | |
| | | @Autowired |
| | | private AreasMapper aareasMapper; |
| | | |
| | | @Autowired |
| | | private NoticeService noticeService; |
| | | |
| | | @Autowired |
| | |
| | | |
| | | @Autowired |
| | | private WxPayProperties wxPayProperties; |
| | | |
| | | @Autowired |
| | | private XyyConfig xyyConfig; |
| | | |
| | | @Autowired |
| | | private PrintService printService; |
| | | |
| | | @Override |
| | | public Integer create(Orders orders) { |
| | |
| | | .leftJoin("shop_info s2 on s2.id = t.TAKE_SHOP_ID"); |
| | | ; |
| | | Utils.MP.blankToNull(pageWrap.getModel()); |
| | | pageWrap.getModel().setDeleted(Constants.ZERO); |
| | | queryWrapper.eq(pageWrap.getModel().getDeleted() != null, Orders::getDeleted, pageWrap.getModel().getDeleted()); |
| | | queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getCode()), Orders::getCode, pageWrap.getModel().getCode()); |
| | | queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getDepositShopName()), "s1.name", pageWrap.getModel().getDepositShopName()); |
| | | queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getTakeShopName()), "s2.name", pageWrap.getModel().getTakeShopName()); |
| | | queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getGoodsInfo()), Orders::getGoodsInfo, pageWrap.getModel().getGoodsInfo()); |
| | | queryWrapper.ge(pageWrap.getModel().getCreateStartTime() != null, Orders::getCreateTime, Utils.Date.getStart(pageWrap.getModel().getCreateStartTime())); |
| | | queryWrapper.le(pageWrap.getModel().getCreateEndTime() != null, Orders::getCreateTime, Utils.Date.getEnd(pageWrap.getModel().getCreateEndTime())); |
| | | queryWrapper.ge(pageWrap.getModel().getCreateStartTime() != null, Orders::getCreateTime, pageWrap.getModel().getCreateStartTime()); |
| | | queryWrapper.le(pageWrap.getModel().getCreateEndTime() != null, Orders::getCreateTime, pageWrap.getModel().getCreateEndTime()); |
| | | queryWrapper.eq(pageWrap.getModel().getDepositShopId() != null, Orders::getDepositShopId, pageWrap.getModel().getDepositShopId()); |
| | | queryWrapper.eq(pageWrap.getModel().getType() != null, Orders::getType, pageWrap.getModel().getType()); |
| | | queryWrapper.eq(pageWrap.getModel().getStatus() != null, Orders::getStatus, pageWrap.getModel().getStatus()); |
| | |
| | | queryWrapper.and(pageWrap.getModel().getDriverKeyword() != null, i->i.like(DriverInfo::getName, pageWrap.getModel().getDriverKeyword()) |
| | | .or().like(DriverInfo::getTelephone, pageWrap.getModel().getDriverKeyword())); |
| | | queryWrapper.eq(pageWrap.getModel().getSettlementStatus() != null, Orders::getSettlementStatus, pageWrap.getModel().getSettlementStatus()); |
| | | for (PageWrap.SortData sortData : pageWrap.getSorts()) { |
| | | if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) { |
| | | queryWrapper.orderByDesc(sortData.getProperty()); |
| | | } else { |
| | | queryWrapper.orderByAsc(sortData.getProperty()); |
| | | } |
| | | } |
| | | queryWrapper.eq(pageWrap.getModel().getAcceptDriver() != null, Orders::getAcceptDriver, pageWrap.getModel().getAcceptDriver()); |
| | | queryWrapper.and(pageWrap.getModel().getShopId() != null, i -> i.eq(Orders::getDepositShopId, pageWrap.getModel().getShopId()) |
| | | .or().eq(Orders::getTakeShopId, pageWrap.getModel().getShopId())); |
| | | queryWrapper.orderByDesc(Orders::getId); |
| | | PageData<Orders> pageData = PageData.from(ordersMapper.selectJoinPage(page, Orders.class, queryWrapper)); |
| | | for (Orders o : pageData.getRecords()) { |
| | | if (o.getStatus() != null) { |
| | |
| | | queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getDepositShopName()), "s1.name", pageWrap.getModel().getDepositShopName()); |
| | | queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getTakeShopName()), "s2.name", pageWrap.getModel().getTakeShopName()); |
| | | queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getGoodsInfo()), Orders::getGoodsInfo, pageWrap.getModel().getGoodsInfo()); |
| | | queryWrapper.ge(pageWrap.getModel().getCreateStartTime() != null, Orders::getCreateTime, Utils.Date.getStart(pageWrap.getModel().getCreateStartTime())); |
| | | queryWrapper.le(pageWrap.getModel().getCreateEndTime() != null, Orders::getCreateTime, Utils.Date.getEnd(pageWrap.getModel().getCreateEndTime())); |
| | | queryWrapper.ge(pageWrap.getModel().getCreateStartTime() != null, Orders::getCreateTime, pageWrap.getModel().getCreateStartTime()); |
| | | queryWrapper.le(pageWrap.getModel().getCreateEndTime() != null, Orders::getCreateTime, pageWrap.getModel().getCreateEndTime()); |
| | | queryWrapper.eq(pageWrap.getModel().getDepositShopId() != null, Orders::getDepositShopId, pageWrap.getModel().getDepositShopId()); |
| | | queryWrapper.eq(pageWrap.getModel().getType() != null, Orders::getType, pageWrap.getModel().getType()); |
| | | queryWrapper.eq(pageWrap.getModel().getStatus() != null, Orders::getStatus, pageWrap.getModel().getStatus()); |
| | |
| | | queryWrapper.and(pageWrap.getModel().getDriverKeyword() != null, i->i.like(DriverInfo::getName, pageWrap.getModel().getDriverKeyword()) |
| | | .or().like(DriverInfo::getTelephone, pageWrap.getModel().getDriverKeyword())); |
| | | queryWrapper.eq(pageWrap.getModel().getSettlementStatus() != null, Orders::getSettlementStatus, pageWrap.getModel().getSettlementStatus()); |
| | | queryWrapper.eq(pageWrap.getModel().getAcceptDriver() != null, Orders::getAcceptDriver, pageWrap.getModel().getAcceptDriver()); |
| | | queryWrapper.and(pageWrap.getModel().getShopId() != null, i -> i.eq(Orders::getDepositShopId, pageWrap.getModel().getShopId()) |
| | | .or().eq(Orders::getTakeShopId, pageWrap.getModel().getShopId())); |
| | | |
| | | queryWrapper.select( |
| | | "IFNULL(SUM(t.total_amount), 0) as total_amount_sum", |
| | |
| | | for (Category c : categories) { |
| | | categoryNameMap.put(c.getId(), c.getName()); |
| | | categoryDetailMap.put(c.getId(), c.getDetail()); |
| | | categoryOtherFieldMap.put(c.getId(),c.getOtherField()); |
| | | categoryOtherFieldMap.put(c.getId(),c.getRemark()); |
| | | } |
| | | |
| | | // 计算每项物品费用:小计 = 单价 × 数量 × 天数 |
| | |
| | | for (Category c : categories) { |
| | | categoryNameMap.put(c.getId(), c.getName()); |
| | | categoryDetailMap.put(c.getId(), c.getDetail()); |
| | | categoryOtherFieldMap.put(c.getId(),c.getOtherField()); |
| | | categoryOtherFieldMap.put(c.getId(),c.getRemark()); |
| | | } |
| | | |
| | | // 3. 逐项计算运费:起步价 + 超出部分阶梯价 |
| | |
| | | insuranceFeeFen = insuranceFeeYuan.multiply(new BigDecimal(100)).longValue(); |
| | | } |
| | | |
| | | // 5. 加急费用:物品价格 × 加急系数(字典 URGENT_COEFFICIENT) |
| | | // 5. 加急费用:物品价格 × (加急系数-1),如150%表示增加50% |
| | | long urgentFeeFen = 0L; |
| | | String urgentRateStr = systemDictDataBiz.queryByCode( |
| | | Constants.OPERATION_CONFIG, Constants.OP_URGENT_COEFFICIENT).getCode(); |
| | | BigDecimal urgentRate = new BigDecimal(urgentRateStr); |
| | | urgentFeeFen = new BigDecimal(itemPriceTotal).multiply(urgentRate) |
| | | BigDecimal urgentIncreaseRate = urgentRate.subtract(BigDecimal.ONE); |
| | | urgentFeeFen = new BigDecimal(itemPriceTotal).multiply(urgentIncreaseRate) |
| | | .setScale(0, RoundingMode.HALF_UP).longValue(); |
| | | |
| | | // 6. 总价格 = 物品价格 + 保价费用 + 加急费用(加急时才包含加急费) |
| | | long totalPrice = itemPriceTotal + insuranceFeeFen; |
| | | if (Boolean.TRUE.equals(dto.getUrgent())) { |
| | | totalPrice += urgentFeeFen; |
| | | // 加急时更新物品明细单价和小计 |
| | | for (ItemPriceVO vo : itemList) { |
| | | long adjustedUnitPrice = new BigDecimal(vo.getUnitPrice()).multiply(urgentRate) |
| | | .setScale(0, RoundingMode.HALF_UP).longValue(); |
| | | vo.setUnitPrice(adjustedUnitPrice); |
| | | vo.setSubtotal(adjustedUnitPrice * vo.getQuantity()); |
| | | } |
| | | } |
| | | |
| | | PriceCalculateVO result = new PriceCalculateVO(); |
| | |
| | | orders.setEstimatedAmount(priceResult.getTotalPrice()); |
| | | orders.setTotalAmount(priceResult.getTotalPrice()); |
| | | orders.setUrgentAmount(priceResult.getUrgentFee()); |
| | | // 存储加急系数 |
| | | if (Constants.ONE.equals(dto.getType()) && Constants.ONE.equals(dto.getIsUrgent())) { |
| | | String urgentRateStr = systemDictDataBiz.queryByCode( |
| | | Constants.OPERATION_CONFIG, Constants.OP_URGENT_COEFFICIENT).getCode(); |
| | | orders.setUrgentRata(new BigDecimal(urgentRateStr)); |
| | | } |
| | | if (dto.getDeclaredAmount() != null && dto.getDeclaredAmount().compareTo(BigDecimal.ZERO) > 0) { |
| | | orders.setDeclaredAmount(dto.getDeclaredAmount().multiply(new BigDecimal(100)).longValue()); |
| | | } else { |
| | |
| | | orderLogService.create(createLog); |
| | | |
| | | // ========== 7. 创建订单明细 ========== |
| | | // 异地寄存极速达时,按加急比例计算明细行单价 |
| | | BigDecimal urgentIncreaseRate = null; |
| | | if (Constants.ONE.equals(dto.getType()) && Constants.ONE.equals(dto.getIsUrgent())) { |
| | | String urgentRateStr = systemDictDataBiz.queryByCode( |
| | | Constants.OPERATION_CONFIG, Constants.OP_URGENT_COEFFICIENT).getCode(); |
| | | urgentIncreaseRate = new BigDecimal(urgentRateStr).subtract(BigDecimal.ONE); |
| | | } |
| | | for (ItemPriceVO itemVO : priceResult.getItemList()) { |
| | | OrdersDetail detail = new OrdersDetail(); |
| | | detail.setOrderId(orderId); |
| | |
| | | detail.setLuggageName(itemVO.getCategoryName()); |
| | | detail.setLuggageDetail(itemVO.getDetail()); |
| | | detail.setNum(itemVO.getQuantity()); |
| | | detail.setUnitPrice(itemVO.getUnitPrice()); |
| | | long detailUnitPrice = itemVO.getUnitPrice(); |
| | | if (urgentIncreaseRate != null) { |
| | | detailUnitPrice = new BigDecimal(detailUnitPrice) |
| | | .multiply(BigDecimal.ONE.add(urgentIncreaseRate)) |
| | | .setScale(0, RoundingMode.HALF_UP).longValue(); |
| | | } |
| | | detail.setUnitPrice(detailUnitPrice); |
| | | detail.setStartDistance(itemVO.getStartDistance()); |
| | | detail.setStartPrice(itemVO.getStartPrice()); |
| | | if (urgentIncreaseRate != null && itemVO.getStartPrice() != null) { |
| | | detail.setStartPrice(new BigDecimal(itemVO.getStartPrice()) |
| | | .multiply(BigDecimal.ONE.add(urgentIncreaseRate)) |
| | | .setScale(0, RoundingMode.HALF_UP).longValue()); |
| | | } else { |
| | | detail.setStartPrice(itemVO.getStartPrice()); |
| | | } |
| | | detail.setExtraDistance(itemVO.getExtraDistance()); |
| | | detail.setExtraPrice(itemVO.getExtraPrice()); |
| | | if (urgentIncreaseRate != null && itemVO.getExtraPrice() != null) { |
| | | detail.setExtraPrice(new BigDecimal(itemVO.getExtraPrice()) |
| | | .multiply(BigDecimal.ONE.add(urgentIncreaseRate)) |
| | | .setScale(0, RoundingMode.HALF_UP).longValue()); |
| | | } else { |
| | | detail.setExtraPrice(itemVO.getExtraPrice()); |
| | | } |
| | | detail.setLocallyPrice(itemVO.getLocallyPrice()); |
| | | detail.setDeleted(Constants.ZERO); |
| | | detail.setCreateTime(now); |
| | |
| | | // 门店待处理订单:按业务环节区分门店角色 |
| | | if (combinedStatus != null && Constants.equalsInteger(combinedStatus, Constants.SEVEN)) { |
| | | wrapper.and(w -> w |
| | | .and(w1 -> w1.eq(Orders::getDepositShopId, shopId) |
| | | .and(w1 -> w1.eq(Orders::getType, Constants.ZERO).eq(Orders::getDepositShopId, shopId) |
| | | .in(Orders::getStatus, Constants.OrderStatus.waitDeposit.getStatus(), |
| | | Constants.OrderStatus.deposited.getStatus())) |
| | | .or(w2 -> w2.eq(Orders::getTakeShopId, shopId) |
| | | .in(Orders::getStatus, Constants.OrderStatus.delivering.getStatus(), |
| | | Constants.OrderStatus.arrived.getStatus())) |
| | | Constants.OrderStatus.arrived.getStatus()) |
| | | .or(w3-> w3.eq(Orders::getType, Constants.ONE).eq(Orders::getDepositShopId, shopId) |
| | | .eq(Orders::getStatus, Constants.OrderStatus.waitDeposit.getStatus())) |
| | | .or(w2 -> w2.eq(Orders::getType, Constants.ONE).eq(Orders::getTakeShopId, shopId) |
| | | .eq(Orders::getStatus, Constants.OrderStatus.arrived.getStatus()))) |
| | | ); |
| | | } else { |
| | | wrapper.and(w -> w.eq(Orders::getDepositShopId, shopId).or().eq(Orders::getTakeShopId, shopId)); |
| | |
| | | vo.setMemberVerifyCode(order.getMemberVerifyCode()); |
| | | } |
| | | |
| | | // 异地寄存经纬度(就地寄存不返回) |
| | | if (Constants.ONE.equals(order.getType())) { |
| | | // status=3(已接单):返回存件门店经纬度 + 司机经纬度 |
| | | if (Constants.equalsInteger(status, Constants.OrderStatus.accepted.getStatus())) { |
| | | ShopInfo depositShop = shopInfoMapper.selectById(order.getDepositShopId()); |
| | | if (depositShop != null) { |
| | | vo.setDepositShopLng(depositShop.getLongitude()); |
| | | vo.setDepositShopLat(depositShop.getLatitude()); |
| | | } |
| | | if (order.getAcceptDriver() != null) { |
| | | DriverInfo driver = driverInfoMapper.selectById(order.getAcceptDriver()); |
| | | if (driver != null) { |
| | | vo.setDriverLng(driver.getLongitude()); |
| | | vo.setDriverLat(driver.getLatitude()); |
| | | } |
| | | } |
| | | } |
| | | // status=4(配送中):返回取件点经纬度 + 司机经纬度 |
| | | if (Constants.equalsInteger(status, Constants.OrderStatus.delivering.getStatus())) { |
| | | // 取件点经纬度(优先取件门店,否则订单上的取件坐标) |
| | | if (order.getTakeShopId() != null) { |
| | | ShopInfo takeShop = shopInfoMapper.selectById(order.getTakeShopId()); |
| | | if (takeShop != null) { |
| | | vo.setTakeLng(takeShop.getLongitude()); |
| | | vo.setTakeLat(takeShop.getLatitude()); |
| | | } |
| | | } else if (order.getTakeLgt() != null && order.getTakeLat() != null) { |
| | | vo.setTakeLng(order.getTakeLgt().doubleValue()); |
| | | vo.setTakeLat(order.getTakeLat().doubleValue()); |
| | | } |
| | | if (order.getAcceptDriver() != null) { |
| | | DriverInfo driver = driverInfoMapper.selectById(order.getAcceptDriver()); |
| | | if (driver != null) { |
| | | vo.setDriverLng(driver.getLongitude()); |
| | | vo.setDriverLat(driver.getLatitude()); |
| | | } |
| | | } |
| | | } |
| | | vo.setDepositShopLng(order.getDepositLgt().doubleValue()); |
| | | vo.setDepositShopLat(order.getDepositLat().doubleValue()); |
| | | // 取件点经纬度 |
| | | vo.setTakeLng(order.getTakeLgt().doubleValue()); |
| | | vo.setTakeLat(order.getTakeLat().doubleValue()); |
| | | //司机经纬度 |
| | | DriverInfo driver = driverInfoMapper.selectById(order.getAcceptDriver()); |
| | | if (driver != null) { |
| | | vo.setDriverLng(driver.getLongitude()); |
| | | vo.setDriverLat(driver.getLatitude()); |
| | | } |
| | | |
| | | // 评价信息 |
| | | vo.setCommentStatus(order.getCommentStatus()); |
| | | if (Constants.equalsInteger(order.getCommentStatus(), Constants.ONE)) { |
| | |
| | | public PayResponse payShopDeposit(Integer memberId) { |
| | | // 1. 查询门店信息 |
| | | ShopInfo shopInfo = shopInfoMapper.selectOne(new QueryWrapper<ShopInfo>().lambda() |
| | | .eq(ShopInfo::getDeleted,Constants.ZERO) |
| | | .eq(ShopInfo::getRegionMemberId,memberId)); |
| | | if (shopInfo == null) { |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "门店不存在"); |
| | |
| | | sendSmsNotify(shopInfo.getTelephone(), |
| | | Constants.SmsNotify.SHOP_AUTH_SUCCESS, |
| | | "storeName", shopInfo.getName(), |
| | | "phone", shopInfo.getTelephone() != null ? shopInfo.getTelephone() : "", |
| | | "password", rawPassword); |
| | | |
| | | // 6. 押金支付完成后,若城市未开通则自动开通 |
| | | if (shopInfo.getAreaId() != null) { |
| | | Areas shopArea = areasBiz.resolveArea(shopInfo.getAreaId()); |
| | | Areas shopArea = aareasMapper.selectById(shopInfo.getAreaId()); |
| | | if (shopArea != null && shopArea.getParentId() != null) { |
| | | Areas cityArea = areasBiz.resolveArea(shopArea.getParentId()); |
| | | Areas cityArea = aareasMapper.selectById(shopArea.getParentId()); |
| | | if (cityArea != null && !Constants.equalsInteger(cityArea.getStatus(), Constants.ONE)) { |
| | | cityArea.setStatus(Constants.ONE); |
| | | cityArea.setEditDate(now); |
| | | areasService.updateById(cityArea); |
| | | aareasMapper.updateById(cityArea); |
| | | areasService.cacheData(); |
| | | } |
| | | } |
| | |
| | | .eq(Orders::getDeleted, Constants.ZERO) |
| | | .eq(Orders::getStatus, Constants.OrderStatus.finished.getStatus()) |
| | | .eq(Orders::getSettlementStatus, Constants.ZERO) |
| | | .le(Orders::getFinishTime, deadline)); |
| | | .le(Orders::getFinishTime, deadline) |
| | | ); |
| | | if (ordersList == null || ordersList.isEmpty()) { |
| | | return; |
| | | } |
| | |
| | | } else if (Constants.equalsInteger(revenue.getMemberType(), Constants.TWO)) { |
| | | // 门店:通过 memberId 查 ShopInfo(regionMemberId),更新 balance / totalBalance |
| | | ShopInfo shop = shopInfoMapper.selectOne(new QueryWrapper<ShopInfo>().lambda() |
| | | .eq(ShopInfo::getRegionMemberId, revenue.getMemberId()) |
| | | .eq(ShopInfo::getId, revenue.getMemberId()) |
| | | .eq(ShopInfo::getDeleted, Constants.ZERO) |
| | | .last("limit 1")); |
| | | if (shop != null) { |
| | |
| | | // 异地寄存 → 待抢单 |
| | | sendOrderNotice(order.getMemberId(), Constants.MemberOrderNotify.WAIT_GRAB, order.getId(), |
| | | "orderNo", order.getCode()); |
| | | // 推送通知司机 |
| | | pushDriverNewOrder(order); |
| | | } else { |
| | | // 就地寄存 → 待取件提醒 |
| | | sendOrderNotice(order.getMemberId(), Constants.MemberOrderNotify.WAIT_PICKUP_REMIND, order.getId(), |
| | |
| | | // 异地寄存 → 待抢单 |
| | | sendOrderNotice(order.getMemberId(), Constants.MemberOrderNotify.WAIT_GRAB, order.getId(), |
| | | "orderNo", order.getCode()); |
| | | // 推送通知司机 |
| | | pushDriverNewOrder(order); |
| | | } else { |
| | | // 就地寄存 → 待取件提醒 |
| | | sendOrderNotice(order.getMemberId(), Constants.MemberOrderNotify.WAIT_PICKUP_REMIND, order.getId(), |
| | |
| | | // 存件门店收益 |
| | | if (depositShopFee > 0 && order.getDepositShopId() != null) { |
| | | ShopInfo depositShop = shopInfoMapper.selectById(order.getDepositShopId()); |
| | | if (depositShop != null && depositShop.getRegionMemberId() != null) { |
| | | revenueMapper.insert(buildRevenue(depositShop.getRegionMemberId(), Constants.TWO, |
| | | if (depositShop != null && depositShop.getId() != null) { |
| | | revenueMapper.insert(buildRevenue(depositShop.getId(), Constants.TWO, |
| | | depositShopFee, orderId, order.getCode())); |
| | | } |
| | | } |
| | |
| | | // 取件门店收益(异地寄存且有取件门店) |
| | | if (takeShopFee > 0 && order.getTakeShopId() != null) { |
| | | ShopInfo takeShop = shopInfoMapper.selectById(order.getTakeShopId()); |
| | | if (takeShop != null && takeShop.getRegionMemberId() != null) { |
| | | revenueMapper.insert(buildRevenue(takeShop.getRegionMemberId(), Constants.TWO, |
| | | if (takeShop != null && takeShop.getId() != null) { |
| | | revenueMapper.insert(buildRevenue(takeShop.getId(), Constants.TWO, |
| | | takeShopFee, orderId, order.getCode())); |
| | | } |
| | | } |
| | |
| | | * 供分页等已查询明细的业务场景复用,避免重复查询 |
| | | */ |
| | | private OverdueFeeVO calculateOverdueFeeInternal(Orders order, List<OrdersDetail> details) { |
| | | if (CollectionUtils.isEmpty(details)) { |
| | | if (CollectionUtils.isEmpty(details)|| |
| | | Constants.equalsInteger(order.getStatus(),Constants.ZERO) |
| | | || Constants.equalsInteger(order.getStatus(),Constants.ONE) |
| | | ) { |
| | | OverdueFeeVO vo = new OverdueFeeVO(); |
| | | vo.setOverdue(false); |
| | | vo.setOverdueDays(0); |
| | |
| | | QueryWrapper<Orders> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("MEMBER_ID", memberId) |
| | | .in("STATUS", 0, 1, 2, 3, 4, 5) |
| | | .orderByDesc("CREATE_TIME") |
| | | .orderByAsc("CREATE_TIME") |
| | | .last("LIMIT 1"); |
| | | Orders order = ordersMapper.selectOne(wrapper); |
| | | if (order == null) { |
| | |
| | | for (int i = 0; i < paramPairs.length - 1; i += 2) { |
| | | templateParam.put(paramPairs[i], paramPairs[i + 1]); |
| | | } |
| | | boolean result = AliSmsService.sendSms(phone, smsNotify.getTemplateCode(), |
| | | String error = AliSmsService.sendSms(phone, smsNotify.getTemplateCode(), |
| | | templateParam.toJSONString()); |
| | | if (result) { |
| | | log.info("短信发送成功: phone={}, template={}", phone, smsNotify.name()); |
| | | } else { |
| | | log.warn("短信发送失败: phone={}, template={}", phone, smsNotify.name()); |
| | | } |
| | | // 存储短信记录 |
| | | Smsrecord record = new Smsrecord(); |
| | | record.setPhone(phone); |
| | | record.setContent(content); |
| | | record.setType(Constants.ONE); // 1=订单通知 |
| | | record.setStatus(result ? Constants.ONE : Constants.ZERO); // 1=已发送, 0=发送失败 |
| | | record.setType(Constants.ONE); |
| | | record.setStatus(error == null ? Constants.ONE : Constants.ZERO); |
| | | if (error != null) { |
| | | record.setRemark(error); |
| | | } |
| | | record.setCreateTime(new Date()); |
| | | record.setDeleted(Constants.ZERO); |
| | | smsrecordMapper.insert(record); |
| | | } catch (Exception e) { |
| | | log.error("短信发送异常: phone={}, template={}, error={}", phone, smsNotify.name(), e.getMessage()); |
| | | // 异常也记录 |
| | | try { |
| | | Smsrecord record = new Smsrecord(); |
| | | record.setPhone(phone); |
| | | record.setContent(content); |
| | | record.setType(Constants.ONE); |
| | | record.setStatus(Constants.ZERO); // 发送失败 |
| | | record.setStatus(Constants.ZERO); |
| | | record.setRemark(e.getMessage()); |
| | | record.setCreateTime(new Date()); |
| | | record.setDeleted(Constants.ZERO); |
| | | smsrecordMapper.insert(record); |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void printOrderLabel(Integer orderId, Integer shopId) { |
| | | Orders orders = ordersMapper.selectById(orderId); |
| | | if (orders == null) { |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "订单不存在"); |
| | | } |
| | | if (!Constants.equalsInteger(orders.getDepositShopId(), shopId)) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "当前门店不是该订单的存件门店"); |
| | | } |
| | | if (orders.getStatus() < 2 || orders.getStatus() > 5) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "当前订单状态不允许打印"); |
| | | } |
| | | ShopInfo shop = shopInfoMapper.selectById(shopId); |
| | | if (shop == null) { |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "存件门店不存在"); |
| | | } |
| | | if (StringUtils.isBlank(shop.getPrinterSn())) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "存件门店未绑定打印机"); |
| | | } |
| | | List<OrdersDetail> detailList = ordersDetailMapper.selectList( |
| | | new QueryWrapper<OrdersDetail>().lambda().eq(OrdersDetail::getOrderId, orderId)); |
| | | // 拼接客户信息 |
| | | String userInfo = ""; |
| | | if (StringUtils.isNotBlank(orders.getTakeUser())) { |
| | | String phone = orders.getTakePhone(); |
| | | userInfo = orders.getTakeUser(); |
| | | if (StringUtils.isNotBlank(phone) && phone.length() >= 4) { |
| | | userInfo += "(" + phone.substring(phone.length() - 4) + ")"; |
| | | } |
| | | } |
| | | String content = printService.getPrintContent(shop.getName(), detailList, userInfo, orders.getCode(), orders.getRemark(), |
| | | orders.getTakeLocationRemark(), |
| | | orders.getPayTime() != null ? new SimpleDateFormat("yyyy-MM-dd HH:mm").format(orders.getPayTime()) : "", |
| | | orders.getExpectedTakeTime() != null ? new SimpleDateFormat("yyyy-MM-dd HH:mm").format(orders.getExpectedTakeTime()) : ""); |
| | | if (StringUtils.isBlank(content)) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "打印内容为空"); |
| | | } |
| | | PrintRequest request = new PrintRequest(); |
| | | xyyConfig.createRequestHeader(request); |
| | | request.setSn(shop.getPrinterSn()); |
| | | request.setContent(content); |
| | | request.setCopies(1); |
| | | request.setVoice(2); |
| | | request.setMode(0); |
| | | com.doumee.config.xyy.vo.ObjectRestResponse<String> resp = printService.printLabel(request); |
| | | if (resp.getCode() != 0) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "打印失败:" + resp.getMsg()); |
| | | } |
| | | log.info("订单标签打印成功: orderId={}, orderIndex={}", orderId, resp.getData()); |
| | | } |
| | | |
| | | /** |
| | | * 异地订单寄存成功后推送通知给司机 |
| | | * 1、未加急:推送同城且门店配送范围内接单中的司机 |
| | | * 2、加急:推送同城所有接单中的司机 |
| | | * 城市匹配:司机AREA_ID关联areas表,逐级parent_id找到城市级,与订单cityId匹配 |
| | | */ |
| | | private void pushDriverNewOrder(Orders order) { |
| | | ShopInfo shop = shopInfoMapper.selectById(order.getDepositShopId()); |
| | | if (shop == null || shop.getLongitude() == null || shop.getLatitude() == null) { |
| | | return; |
| | | } |
| | | String orderCityId = order.getCityId(); |
| | | if (StringUtils.isBlank(orderCityId)) { |
| | | return; |
| | | } |
| | | String distSql = "(ST_Distance_Sphere(POINT(t.LONGITUDE, t.LATITUDE), POINT(" + shop.getLongitude() + ", " + shop.getLatitude() + ")) / 1000)"; |
| | | // MPJ关联查询:司机 → areas(区县) → areas_city(城市),匹配订单cityId |
| | | MPJLambdaWrapper<DriverInfo> wrapper = new MPJLambdaWrapper<>(); |
| | | wrapper.selectAll(DriverInfo.class) |
| | | .leftJoin(Areas.class,Areas::getId,DriverInfo::getAreaId) |
| | | .eq(DriverInfo::getAcceptingStatus, Constants.ONE) |
| | | .eq(DriverInfo::getStatus, Constants.ZERO) |
| | | .eq(DriverInfo::getDeleted, Constants.ZERO) |
| | | .eq(DriverInfo::getAuditStatus, Constants.THREE) |
| | | .eq(Areas::getParentId, orderCityId); |
| | | if (!Constants.equalsInteger(order.getIsUrgent(), Constants.ONE)) { |
| | | // 未加急:门店配送范围内 |
| | | double rangeKm = shop.getDeliveryArea() != null ? shop.getDeliveryArea().doubleValue() : 5.0; |
| | | wrapper.apply(distSql + " <= {0}", rangeKm); |
| | | } |
| | | List<DriverInfo> drivers = driverInfoMapper.selectJoinList(DriverInfo.class, wrapper); |
| | | if (drivers.isEmpty()) { |
| | | return; |
| | | } |
| | | List<String> aliases = new ArrayList<>(); |
| | | for (DriverInfo d : drivers) { |
| | | aliases.add(org.springframework.util.DigestUtils.md5DigestAsHex(d.getTelephone().getBytes())); |
| | | } |
| | | String title = Constants.equalsInteger(order.getIsUrgent(), Constants.ONE) ? "新加急订单" : "新订单"; |
| | | String content = "订单号:" + order.getCode(); |
| | | java.util.Map<String, String> extras = new java.util.HashMap<>(); |
| | | extras.put("orderId", String.valueOf(order.getId())); |
| | | extras.put("orderCode", order.getCode()); |
| | | extras.put("type", "new_order"); |
| | | JPushUtil.sendByAliases(aliases, title, content, extras); |
| | | } |
| | | |
| | | } |