From 023bd790dfdd2d47227276985be2ba541dc3f536 Mon Sep 17 00:00:00 2001 From: Jack <46790855@qq.com> Date: Wed, 19 Nov 2025 16:56:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=97=E9=93=BA=E5=BC=80=E4=B8=9A=E7=AD=B9?= =?UTF-8?q?=E5=A4=87=E7=8A=B6=E6=80=81=E5=88=B0=E6=9C=9F=E8=BD=AC=E6=AD=A3?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/ShopActivityCutpriceServiceImpl.java | 234 ++++++++++-------- .../quartz/job/StoreValidTimeJod.java | 3 + .../store/service/ShopStoreBaseService.java | 9 + .../service/impl/ShopMchEntryServiceImpl.java | 15 +- .../impl/ShopStoreBaseServiceImpl.java | 23 ++ 5 files changed, 172 insertions(+), 112 deletions(-) diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/activity/service/impl/ShopActivityCutpriceServiceImpl.java b/mall-shop/src/main/java/com/suisung/mall/shop/activity/service/impl/ShopActivityCutpriceServiceImpl.java index ba64148c..9b9ec778 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/activity/service/impl/ShopActivityCutpriceServiceImpl.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/activity/service/impl/ShopActivityCutpriceServiceImpl.java @@ -330,13 +330,11 @@ public class ShopActivityCutpriceServiceImpl extends BaseServiceImpl 0 && cut_num >= num) { - return CommonResult.failed(I18nUtil._("今日帮砍次数已用完!")); + if (maxCuts > 0 && usedCuts >= maxCuts) { + return CommonResult.failed(I18nUtil._("今日帮砍次数已达上限!")); + } + } + } catch (Exception e) { + // Redis检查失败时继续执行砍价操作 } } - BigDecimal ac_sale_price = shopActivityCutprice.getAc_sale_price(); - BigDecimal ac_mix_limit_price = shopActivityCutprice.getAc_mix_limit_price(); + BigDecimal salePrice = cutprice.getAc_sale_price(); + BigDecimal minPrice = cutprice.getAc_mix_limit_price(); - // 检查价格数据是否完整 - if (ac_sale_price == null || ac_mix_limit_price == null) { - return CommonResult.failed(I18nUtil._("价格数据异常!")); + // 检查价格数据完整性 + if (salePrice == null || minPrice == null) { + return CommonResult.failed(I18nUtil._("商品价格数据异常!")); } // 检查是否已达到最低价 - if (NumberUtil.isLessOrEqual(ac_sale_price, ac_mix_limit_price)) { - // 根据上次的状态,立即更改状态:6-砍价助力已完成待下单; - updateCutPriceState(shopActivityCutprice.getAc_id(), null, CommonConstant.CutPrice_Order_State_CutFinished); - - return CommonResult.failed(I18nUtil._("已达到最低价!")); + if (NumberUtil.isLessOrEqual(salePrice, minPrice)) { + updateCutPriceState(cutprice.getAc_id(), null, CommonConstant.CutPrice_Order_State_CutFinished); + return CommonResult.failed(I18nUtil._("已砍到最低价啦!")); } - // 检查是否已经帮过好友砍了价 - QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("user_id", user_id).eq("ac_id", ac_id); - long ach_num = shopActivityCutpriceHistoryService.count(queryWrapper); - if (ach_num > 0) { - return CommonResult.failed(I18nUtil._("已经帮好友砍过价!")); + // 检查是否已经帮过好友砍价 + try { + if (shopActivityCutpriceHistoryService == null) { + return CommonResult.failed(I18nUtil._("系统繁忙,请稍后再试!")); + } + + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("user_id", user_id).eq("ac_id", ac_id); + if (shopActivityCutpriceHistoryService.count(queryWrapper) > 0) { + return CommonResult.failed(I18nUtil._("您已经帮好友砍过价了!")); + } + } catch (Exception e) { + return CommonResult.failed(I18nUtil._("系统繁忙,请稍后再试!")); } // 计算砍价金额 - BigDecimal cut_price = shopStoreActivityBaseService.getCutDownPrice(shopStoreActivityBase, shopActivityCutprice); - if (cut_price == null || cut_price.compareTo(BigDecimal.ZERO) <= 0) { - return CommonResult.failed(I18nUtil._("砍价失败!")); + BigDecimal cutPrice; + try { + cutPrice = shopStoreActivityBaseService.getCutDownPrice(activityBase, cutprice); + if (cutPrice == null || cutPrice.compareTo(BigDecimal.ZERO) <= 0) { + return CommonResult.failed(I18nUtil._("砍价失败,请重试!")); + } + } catch (Exception e) { + return CommonResult.failed(I18nUtil._("砍价失败,请重试!")); } // 获取商品ID - String str_activity_rule = shopStoreActivityBase.getActivity_rule(); - if (StrUtil.isBlank(str_activity_rule)) { + String ruleStr = activityBase.getActivity_rule(); + if (StrUtil.isBlank(ruleStr)) { return CommonResult.failed(I18nUtil._("活动规则数据异常!")); } - JSONObject activity_rule = JSONUtil.parseObj(str_activity_rule); - Long item_id = activity_rule.get("item_id", Long.class); - if (item_id == null) { - return CommonResult.failed(I18nUtil._("未找到商品信息!")); + try { + JSONObject activityRule = JSONUtil.parseObj(ruleStr); + Long itemId = activityRule.get("item_id", Long.class); + if (itemId == null) { + return CommonResult.failed(I18nUtil._("未找到对应商品!")); + } + + // 创建砍价历史记录 + ShopActivityCutpriceHistory history = new ShopActivityCutpriceHistory(); + history.setActivity_id(cutprice.getActivity_id()); + history.setUser_id(user_id); + history.setAch_price(cutPrice); + history.setItem_id(itemId); + history.setAch_datetime(new Date()); + history.setAc_id(ac_id); + + // 保存历史记录 + if (!shopActivityCutpriceHistoryService.saveOrUpdate(history)) { + throw new ApiException(I18nUtil._("保存砍价记录失败!")); + } + + // 更新砍价信息 + cutprice.setAc_sale_price(NumberUtil.sub(salePrice, cutPrice)); + cutprice.setAc_num(cutprice.getAc_num() + 1); + if (!edit(cutprice)) { + throw new ApiException(I18nUtil._("更新砍价信息失败!")); + } + + // 更新帮砍次数 + if (!cutprice.getUser_id().equals(user_id) && redisService != null) { + try { + DateTime today = DateUtil.beginOfDay(new Date()); + Integer cutNum = Convert.toInt(redisService.hGet("cutprice-" + today, user_id.toString()), 0); + redisService.hSet("cutprice-" + today, user_id.toString(), cutNum + 1, 24 * 60 * 60 * 1000); + } catch (Exception e) { + // Redis更新失败不影响主流程 + } + } + + // 如果已达到最低价,更新状态 + if (NumberUtil.isLessOrEqual(cutprice.getAc_sale_price(), minPrice)) { + updateCutPriceState(cutprice.getAc_id(), null, CommonConstant.CutPrice_Order_State_CutFinished); + } + + return CommonResult.success(history); + } catch (ApiException e) { + throw e; + } catch (Exception e) { + throw new ApiException(I18nUtil._("砍价操作失败!")); } - - // 创建砍价历史记录 - ShopActivityCutpriceHistory ach_data = new ShopActivityCutpriceHistory(); - ach_data.setActivity_id(activity_id); - ach_data.setUser_id(user_id); - ach_data.setAch_price(cut_price); - ach_data.setItem_id(item_id); - ach_data.setAch_datetime(new Date()); - ach_data.setAc_id(ac_id); - - // 保存砍价历史记录 - if (!shopActivityCutpriceHistoryService.saveOrUpdate(ach_data)) { - throw new ApiException(I18nUtil._("保存砍价历史失败!")); - } - - // 更新砍价信息 - shopActivityCutprice.setAc_sale_price(NumberUtil.sub(ac_sale_price, cut_price)); - shopActivityCutprice.setAc_num(shopActivityCutprice.getAc_num() + 1); - if (!edit(shopActivityCutprice)) { - throw new ApiException(I18nUtil._("更新砍价信息失败!")); - } - - // 更新帮砍次数(如果不是自己砍自己的话) - if (!shopActivityCutprice.getUser_id().equals(user_id)) { - DateTime today = DateUtil.beginOfDay(new Date()); - Integer cut_num = Convert.toInt(redisService.hGet("cutprice-" + today, user_id.toString()), 0); - redisService.hSet("cutprice-" + today, user_id.toString(), cut_num + 1, 24 * 60 * 60 * 1000); - } - - // 根据最新砍价信息(最后一次砍价成功之后,达到最低砍价价格),更新砍价订单状态 - if (NumberUtil.isGreaterOrEqual(shopActivityCutprice.getAc_sale_price(), ac_mix_limit_price)) { - updateCutPriceState(shopActivityCutprice.getAc_id(), null, CommonConstant.CutPrice_Order_State_CutFinished); - } - - return CommonResult.success(ach_data); } diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/components/quartz/job/StoreValidTimeJod.java b/mall-shop/src/main/java/com/suisung/mall/shop/components/quartz/job/StoreValidTimeJod.java index c1789a87..12cb0120 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/components/quartz/job/StoreValidTimeJod.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/components/quartz/job/StoreValidTimeJod.java @@ -65,6 +65,9 @@ public class StoreValidTimeJod extends QuartzJobBean { } page++; } + + // 准备筹备中的店铺,到期转正常营业 + storeBaseService.batchUpdateStoreBizStateToOpening(); } } \ No newline at end of file diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/store/service/ShopStoreBaseService.java b/mall-shop/src/main/java/com/suisung/mall/shop/store/service/ShopStoreBaseService.java index b00c7986..a24f75e2 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/store/service/ShopStoreBaseService.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/store/service/ShopStoreBaseService.java @@ -255,6 +255,15 @@ public interface ShopStoreBaseService extends IBaseService { */ Date getLatestBizOpeningDate(String storeIds); + + /** + * 批量更新店铺营业状态为营业中 + * 将符合条件的"筹备中"状态店铺更新为"营业中"状态 + * + * @return Boolean 更新是否成功 + */ + Boolean batchUpdateStoreBizStateToOpening(); + // Page getMobileStoreList(Integer page, Integer rows); } diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/store/service/impl/ShopMchEntryServiceImpl.java b/mall-shop/src/main/java/com/suisung/mall/shop/store/service/impl/ShopMchEntryServiceImpl.java index cddf2a7d..0f5a945f 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/store/service/impl/ShopMchEntryServiceImpl.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/store/service/impl/ShopMchEntryServiceImpl.java @@ -339,9 +339,10 @@ public class ShopMchEntryServiceImpl extends BaseServiceImpl tmplArgs = new HashMap<>(1); tmplArgs.put("name", record.getStore_name()); // 商家店铺名 - // 【桂平发发网络】通知管理员有商家申请入驻 - if (!shopMessageTemplateService.aliyunSmsSend(mobileAndLicenseNumber.getFirst(), "SMS_498535058", tmplArgs)) { - shopMessageTemplateService.aliyunSmsSend(mobileAndLicenseNumber.getFirst(), "SMS_486545331", tmplArgs); // 【小发同城】通知管理员有商家申请入驻 + // 【小发同城】通知管理员有商家申请入驻 + if (!shopMessageTemplateService.aliyunSmsSend(mobileAndLicenseNumber.getFirst(), "SMS_486545331", tmplArgs)) { + // 【桂平发发网络】通知管理员有商家申请入驻 + shopMessageTemplateService.aliyunSmsSend(mobileAndLicenseNumber.getFirst(), "SMS_498535058", tmplArgs); } } @@ -471,10 +472,10 @@ public class ShopMchEntryServiceImpl extends BaseServiceImpl tmplArgs = new HashMap<>(1); tmplArgs.put("name", mchName); // 商家公司名称 - // 【桂平发发网络】通知管理员有商家申请入驻 - if (!shopMessageTemplateService.aliyunSmsSend(mobileAndLicenseNumber.getFirst(), "SMS_498535058", tmplArgs)) { - // 尊敬的管理员,商家 ${name},提交了入驻我们平台的申请,请及时对相关资质材料予以审核,以便推进后续流程。 - shopMessageTemplateService.aliyunSmsSend(mobileAndLicenseNumber.getFirst(), "SMS_486545331", tmplArgs); // 【小发同城】通知管理员有商家申请入驻 + // 【小发同城】通知管理员有商家申请入驻:尊敬的管理员,商家 ${name},提交了入驻我们平台的申请,请及时对相关资质材料予以审核,以便推进后续流程。 + if (!shopMessageTemplateService.aliyunSmsSend(mobileAndLicenseNumber.getFirst(), "SMS_486545331", tmplArgs)) { + // 【桂平发发网络】通知管理员有商家申请入驻 + shopMessageTemplateService.aliyunSmsSend(mobileAndLicenseNumber.getFirst(), "SMS_498535058", tmplArgs); } } diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/store/service/impl/ShopStoreBaseServiceImpl.java b/mall-shop/src/main/java/com/suisung/mall/shop/store/service/impl/ShopStoreBaseServiceImpl.java index c0807867..dd0b8419 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/store/service/impl/ShopStoreBaseServiceImpl.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/store/service/impl/ShopStoreBaseServiceImpl.java @@ -4404,6 +4404,29 @@ public class ShopStoreBaseServiceImpl extends BaseServiceImpl updateWrapper = new UpdateWrapper<>(); + updateWrapper.eq("store_biz_state", CommonConstant.Store_Biz_State_PreActivity) // 筹备中状态 + .eq("store_is_open", CommonConstant.Enable) // 店铺已开启 + .le("store_biz_opening_date", new Date()) // 开业日期小于等于当前日期 + .set("store_biz_state", CommonConstant.Store_Biz_State_Opening); // 更新为营业中状态 + + return update(updateWrapper); + } catch (Exception e) { + log.error("批量更新店铺营业状态失败", e); + // 发生异常时返回true,避免影响主流程执行 + return Boolean.TRUE; + } + } + // @Override // public Page getMobileStoreList(Integer page, Integer rows) {