| | |
| | | public ApiResponse findById(@PathVariable Integer id) { |
| | | return ApiResponse.success(couponService.findById(id)); |
| | | } |
| | | |
| | | @ApiOperation("有效优惠券列表") |
| | | @GetMapping("/validList") |
| | | public ApiResponse<List<Coupon>> validList() { |
| | | return ApiResponse.success(couponService.findValidList()); |
| | | } |
| | | } |
| | |
| | | INSERT INTO `SYSTEM_DICT_DATA` (`DICT_ID`, `CODE`, `LABEL`, `REMARK`, `SORT`, `DISABLED`, `CREATE_USER`, `CREATE_TIME`, `DELETED`) VALUES (105, '', 'REGISTER_COUPON_YEARS', '注册赠送-注册年数', 3, 0, 1, NOW(), 0); |
| | | INSERT INTO `SYSTEM_DICT_DATA` (`DICT_ID`, `CODE`, `LABEL`, `REMARK`, `SORT`, `DISABLED`, `CREATE_USER`, `CREATE_TIME`, `DELETED`) VALUES (105, '', 'REGISTER_COUPON_GIFT_COUNT', '注册赠送-至多赠送次数', 4, 0, 1, NOW(), 0); |
| | | INSERT INTO `SYSTEM_DICT_DATA` (`DICT_ID`, `CODE`, `LABEL`, `REMARK`, `SORT`, `DISABLED`, `CREATE_USER`, `CREATE_TIME`, `DELETED`) VALUES (105, '', 'REGISTER_COUPON_ID', '注册赠送-优惠券ID', 5, 0, 1, NOW(), 0); |
| | | INSERT INTO `SYSTEM_DICT_DATA` (`DICT_ID`, `CODE`, `LABEL`, `REMARK`, `SORT`, `DISABLED`, `CREATE_USER`, `CREATE_TIME`, `DELETED`) VALUES (105, '', 'REGISTER_GIFT_COUPON_IDS', '新注册赠送-优惠券IDs(多选,分割)', 6, 0, 1, NOW(), 0); |
| | | |
| | | |
| | | -- ============================================================ |
| | |
| | | dto.setRegisterCouponYears(getValue(Constants.OP_REGISTER_COUPON_YEARS)); |
| | | dto.setRegisterCouponGiftCount(getValue(Constants.OP_REGISTER_COUPON_GIFT_COUNT)); |
| | | dto.setRegisterCouponId(getValue(Constants.OP_REGISTER_COUPON_ID)); |
| | | dto.setRegisterGiftCouponIds(getValue(Constants.OP_REGISTER_GIFT_COUPON_IDS)); |
| | | return dto; |
| | | } |
| | | |
| | |
| | | saveOrUpdate(Constants.OP_REGISTER_COUPON_YEARS, "注册赠送-注册年数", dto.getRegisterCouponYears()); |
| | | saveOrUpdate(Constants.OP_REGISTER_COUPON_GIFT_COUNT, "注册赠送-至多赠送次数", dto.getRegisterCouponGiftCount()); |
| | | saveOrUpdate(Constants.OP_REGISTER_COUPON_ID, "注册赠送-优惠券ID", dto.getRegisterCouponId()); |
| | | saveOrUpdate(Constants.OP_REGISTER_GIFT_COUPON_IDS, "新注册赠送-优惠券IDs", dto.getRegisterGiftCouponIds()); |
| | | } |
| | | |
| | | private String getValue(String label) { |
| | |
| | | |
| | | com.wechat.pay.java.service.payments.jsapi.model.Amount amount = |
| | | new com.wechat.pay.java.service.payments.jsapi.model.Amount(); |
| | | amount.setTotal(totalCents.intValue()); |
| | | amount.setTotal(1);//totalCents.intValue()); |
| | | amount.setCurrency("CNY"); |
| | | request.setAmount(amount); |
| | | |
| | |
| | | request.setNotifyUrl(notifyUrl); |
| | | |
| | | AmountReq amount = new AmountReq(); |
| | | amount.setRefund(refundCents); |
| | | amount.setTotal(totalCents); |
| | | amount.setRefund(1L);//refundCents); |
| | | amount.setTotal(1L);//totalCents); |
| | | amount.setCurrency("CNY"); |
| | | request.setAmount(amount); |
| | | |
| | |
| | | public static final String OP_REGISTER_COUPON_YEARS = "REGISTER_COUPON_YEARS"; |
| | | public static final String OP_REGISTER_COUPON_GIFT_COUNT = "REGISTER_COUPON_GIFT_COUNT"; |
| | | public static final String OP_REGISTER_COUPON_ID = "REGISTER_COUPON_ID"; |
| | | public static final String OP_REGISTER_GIFT_COUPON_IDS = "REGISTER_GIFT_COUPON_IDS"; |
| | | |
| | | // 芯烨云打印机配置 |
| | | public static final String XPYUN_CONFIG = "XPYUN_CONFIG"; |
| | |
| | | @ApiModelProperty(value = "下单满X次赠送优惠券-至多赠送次数") |
| | | private String orderCouponGiftCount; |
| | | |
| | | @ApiModelProperty(value = "下单满X次赠送优惠券-赠送优惠券ID") |
| | | @ApiModelProperty(value = "下单满X次赠送优惠券-赠送优惠券ID(多个以,分割)") |
| | | private String orderCouponId; |
| | | |
| | | @ApiModelProperty(value = "注册满X年赠送优惠券-注册年数") |
| | |
| | | @ApiModelProperty(value = "注册满X年赠送优惠券-至多赠送次数") |
| | | private String registerCouponGiftCount; |
| | | |
| | | @ApiModelProperty(value = "注册满X年赠送优惠券-赠送优惠券ID") |
| | | @ApiModelProperty(value = "注册满X年赠送优惠券-赠送优惠券ID(多个以,分割)") |
| | | private String registerCouponId; |
| | | |
| | | @ApiModelProperty(value = "新注册用户赠送优惠券ID(多个以,分割)") |
| | | private String registerGiftCouponIds; |
| | | |
| | | } |
| | |
| | | PageData<Coupon> findPage(PageWrap<Coupon> pageWrap); |
| | | |
| | | long count(Coupon coupon); |
| | | |
| | | List<Coupon> findValidList(); |
| | | } |
| | |
| | | return couponMapper.selectCount(wrapper); |
| | | } |
| | | |
| | | @Override |
| | | public List<Coupon> findValidList() { |
| | | return couponMapper.selectList(new QueryWrapper<Coupon>().lambda() |
| | | .eq(Coupon::getIsdeleted, Constants.ZERO) |
| | | .eq(Coupon::getStatus, Constants.ZERO) |
| | | .orderByDesc(Coupon::getId)); |
| | | } |
| | | |
| | | private void validateCoupon(Coupon coupon) { |
| | | if (Objects.isNull(coupon) || StringUtils.isBlank(coupon.getName())) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "优惠券名称不能为空"); |
| | |
| | | OperationConfigDTO config = operationConfigBiz.getConfig(); |
| | | String yearsStr = config.getRegisterCouponYears(); |
| | | String maxGiftStr = config.getRegisterCouponGiftCount(); |
| | | String couponIdStr = config.getRegisterCouponId(); |
| | | if (StringUtils.isBlank(yearsStr) || StringUtils.isBlank(maxGiftStr) || StringUtils.isBlank(couponIdStr)) { |
| | | String couponIdsStr = config.getRegisterCouponId(); |
| | | if (StringUtils.isBlank(yearsStr) || StringUtils.isBlank(maxGiftStr) || StringUtils.isBlank(couponIdsStr)) { |
| | | return; |
| | | } |
| | | int configYears = Integer.parseInt(yearsStr); |
| | | int maxGiftCount = Integer.parseInt(maxGiftStr); |
| | | int couponId = Integer.parseInt(couponIdStr); |
| | | if (configYears <= 0 || maxGiftCount <= 0) { |
| | | return; |
| | | } |
| | | |
| | | // 2. 校验优惠券存在且启用 |
| | | Coupon coupon = couponMapper.selectById(couponId); |
| | | if (coupon == null || !Constants.equalsInteger(coupon.getIsdeleted(), Constants.ZERO) |
| | | || !Constants.equalsInteger(coupon.getStatus(), Constants.ZERO)) { |
| | | // 2. 解析优惠券ID列表,查询有效优惠券 |
| | | List<Integer> couponIdList = Arrays.stream(couponIdsStr.split(",")) |
| | | .map(String::trim).filter(StringUtils::isNotBlank) |
| | | .map(Integer::parseInt).collect(Collectors.toList()); |
| | | List<Coupon> validCoupons = couponMapper.selectList(new QueryWrapper<Coupon>().lambda() |
| | | .in(Coupon::getId, couponIdList) |
| | | .eq(Coupon::getIsdeleted, Constants.ZERO) |
| | | .eq(Coupon::getStatus, Constants.ZERO)); |
| | | if (CollectionUtils.isEmpty(validCoupons)) { |
| | | return; |
| | | } |
| | | |
| | |
| | | |
| | | for (Member member : members) { |
| | | int alreadyGifted = member.getRegisterCouponGiftCount() != null ? member.getRegisterCouponGiftCount() : 0; |
| | | // 已注册年数(取整) |
| | | int registeredYears = (int) ((now.getTime() - member.getCreateTime().getTime()) / msPerYear); |
| | | // 应赠送总次数 |
| | | int shouldGiftTotal = registeredYears / configYears; |
| | | // 实际还需赠送次数 |
| | | int remainGift = Math.min(shouldGiftTotal, maxGiftCount) - alreadyGifted; |
| | | if (remainGift <= 0) { |
| | | continue; |
| | | } |
| | | |
| | | // 4. 赠送优惠券 |
| | | // 4. 每次赠送所有有效优惠券 |
| | | for (int i = 0; i < remainGift; i++) { |
| | | for (Coupon coupon : validCoupons) { |
| | | MemberCoupon mc = new MemberCoupon(); |
| | | mc.setCouponId(couponId); |
| | | mc.setCouponId(coupon.getId()); |
| | | mc.setMemberId(member.getId()); |
| | | mc.setStatus(Constants.CouponStatus.waitClaim.getKey()); |
| | | // 推送后领取有效期 |
| | | Calendar validCal = Calendar.getInstance(); |
| | | validCal.add(Calendar.DAY_OF_MONTH, coupon.getPushDays() != null ? coupon.getPushDays() : 7); |
| | | mc.setValidDate(validCal.getTime()); |
| | | // 拷贝优惠券信息 |
| | | mc.setName(coupon.getName()); |
| | | mc.setInfo(coupon.getInfo()); |
| | | mc.setType(coupon.getType()); |
| | |
| | | mc.setEditDate(now); |
| | | memberCouponMapper.insert(mc); |
| | | } |
| | | } |
| | | |
| | | // 5. 更新会员已赠送次数 |
| | | memberMapper.update(new UpdateWrapper<Member>().lambda() |
| | |
| | | DriverInfo originalDriver = originalDriverId != null ? driverInfoMapper.selectById(originalDriverId) : null; |
| | | |
| | | ShopInfo depositShop = shopInfoMapper.selectById(order.getDepositShopId()); |
| | | // 取件点信息更新为存件门店,使用 UpdateWrapper 确保 null 字段也能生效 |
| | | |
| | | // 计算就地寄存存件门店分成比例 |
| | | Integer cityId = Integer.valueOf(order.getCityId()); |
| | | boolean isCompany = depositShop != null && Constants.equalsInteger(depositShop.getCompanyType(), Constants.ONE); |
| | | int fallbackFieldA = isCompany ? Constants.FIVE : Constants.SIX; |
| | | BigDecimal localDepositRata = getShopRevenueShare(depositShop, "localDeposit", cityId, fallbackFieldA); |
| | | Long totalAmount = order.getTotalAmount() != null ? order.getTotalAmount() : 0L; |
| | | Long localDepositFee = new BigDecimal(totalAmount).multiply(localDepositRata) |
| | | .setScale(0, RoundingMode.HALF_UP).longValue(); |
| | | |
| | | // 取件点信息更新为存件门店,重算分成 |
| | | UpdateWrapper<Orders> updateWrapper = new UpdateWrapper<>(); |
| | | updateWrapper.lambda() |
| | | .eq(Orders::getId, order.getId()) |
| | | .set(Orders::getType, Constants.ZERO) |
| | | .set(Orders::getStatus, Constants.OrderStatus.arrived.getKey()) |
| | | .set(Orders::getIsConverted, Constants.ONE) |
| | | .set(Orders::getTakeShopId, order.getDepositShopId()) |
| | | .set(Orders::getTakeShopName, order.getDepositShopName()) |
| | | .set(Orders::getTakeShopAddress, order.getDepositShopAddress()) |
| | | .set(Orders::getTakeShopLinkPhone, order.getDepositShopLinkPhone()) |
| | | .set(Orders::getTakeLocation, order.getDepositLocation()) |
| | | .set(Orders::getTakeLocationRemark, order.getDepositLocationRemark()) |
| | | .set(Orders::getTakeLat, order.getDepositLat()) |
| | | .set(Orders::getTakeLgt, order.getDepositLgt()) |
| | | .set(Orders::getExpectedTakeTime, new Date()); |
| | | .set(Orders::getExpectedTakeTime, new Date()) |
| | | // 存件门店分成按就地寄存重算 |
| | | .set(Orders::getDepositShopFeeRata, localDepositRata) |
| | | .set(Orders::getDepositShopFee, localDepositFee) |
| | | // 司机、取件门店分成归零 |
| | | .set(Orders::getDriverFeeRata, BigDecimal.ZERO) |
| | | .set(Orders::getDriverFee, 0L) |
| | | .set(Orders::getTakeShopFeeRata, BigDecimal.ZERO) |
| | | .set(Orders::getTakeShopFee, 0L); |
| | | if (Constants.equalsInteger(status, Constants.OrderStatus.accepted.getStatus())) { |
| | | updateWrapper.lambda() |
| | | .set(Orders::getAcceptDriver, null) |