店铺开业筹备状态到期转正。

This commit is contained in:
Jack 2025-11-19 16:56:51 +08:00
parent 8c9661c77c
commit 023bd790df
5 changed files with 172 additions and 112 deletions

View File

@ -330,13 +330,11 @@ public class ShopActivityCutpriceServiceImpl extends BaseServiceImpl<ShopActivit
// 该砍价记录过期时间戳
Integer cut_hour = activityBase.getCut_hour();
// log.info("砍价失效小时cut_hour:{}", cut_hour);
if (CheckUtil.isEmpty(cut_hour)) {
cut_hour = 48;
}
cutprice_row.setExpired_at(now.getTime() + cut_hour * 3600000L);
// log.info("砍价失效时间戳:{}", cutprice_row.getExpired_at());
cutprice_row.setAc_datetime(now);
cutprice_row.setOrder_id("");
@ -344,7 +342,7 @@ public class ShopActivityCutpriceServiceImpl extends BaseServiceImpl<ShopActivit
// 保存砍价记录
if (!saveOrUpdate(cutprice_row)) {
throw new ApiException(I18nUtil._("创建砍价失败!"));
throw new ApiException(I18nUtil._("砍价活动参加失败!"));
}
is_join_activity = true;
@ -390,7 +388,7 @@ public class ShopActivityCutpriceServiceImpl extends BaseServiceImpl<ShopActivit
/**
* 自己或朋友砍价
*
* @param ac_id 活动 Id
* @param ac_id 活动Id
* @param user_id 砍价用户
* @return CommonResult 砍价结果
*/
@ -398,142 +396,168 @@ public class ShopActivityCutpriceServiceImpl extends BaseServiceImpl<ShopActivit
@Transactional
public CommonResult doCutPrice(Integer ac_id, Integer user_id) {
// 参数校验
if (ac_id == null || ac_id <= 0) {
return CommonResult.failed(I18nUtil._("活动ID无效"));
}
if (user_id == null || user_id <= 0) {
return CommonResult.failed(I18nUtil._("用户ID无效"));
if (ac_id == null || ac_id <= 0 || user_id == null || user_id <= 0) {
return CommonResult.failed(I18nUtil._("活动ID或用户ID无效"));
}
// 获取砍价记录
ShopActivityCutprice shopActivityCutprice = get(ac_id);
if (shopActivityCutprice == null) {
return CommonResult.failed(I18nUtil._("抱歉,砍价记录已失效!"));
ShopActivityCutprice cutprice = get(ac_id);
if (cutprice == null) {
return CommonResult.failed(I18nUtil._("砍价记录不存在!"));
}
// 检查活动状态
if (shopStoreActivityBaseService == null) {
return CommonResult.failed(I18nUtil._("系统繁忙,请稍后再试!"));
}
ShopStoreActivityBase activityBase = shopStoreActivityBaseService.get(cutprice.getActivity_id());
if (activityBase == null) {
updateCutPriceState(cutprice.getAc_id(), null, CommonConstant.CutPrice_Order_State_Canceled);
return CommonResult.failed(I18nUtil._("砍价活动已失效!"));
}
Integer activity_id = shopActivityCutprice.getActivity_id();
// 检查活动状态是否正常
ShopStoreActivityBase shopStoreActivityBase = shopStoreActivityBaseService.get(shopActivityCutprice.getActivity_id());
if (shopStoreActivityBase == null) {
// 活动不存在更新砍价订单状态为已取消
updateCutPriceState(shopActivityCutprice.getAc_id(), null, CommonConstant.CutPrice_Order_State_Canceled);
return CommonResult.failed(I18nUtil._("抱歉,砍价活动已失效!"));
}
// 活动状态不是正常状态
if (!ObjectUtil.equal(shopStoreActivityBase.getActivity_state(), StateCode.ACTIVITY_STATE_NORMAL)) {
// 如果活动已结束或已关闭更新砍价订单状态为已取消
if (ObjectUtil.equal(shopStoreActivityBase.getActivity_state(), StateCode.ACTIVITY_STATE_FINISHED)
|| ObjectUtil.equal(shopStoreActivityBase.getActivity_state(), StateCode.ACTIVITY_STATE_CLOSED)) {
updateCutPriceState(shopActivityCutprice.getAc_id(), null, CommonConstant.CutPrice_Order_State_Canceled);
if (!ObjectUtil.equal(activityBase.getActivity_state(), StateCode.ACTIVITY_STATE_NORMAL)) {
if (ObjectUtil.equal(activityBase.getActivity_state(), StateCode.ACTIVITY_STATE_FINISHED)
|| ObjectUtil.equal(activityBase.getActivity_state(), StateCode.ACTIVITY_STATE_CLOSED)) {
updateCutPriceState(cutprice.getAc_id(), null, CommonConstant.CutPrice_Order_State_Canceled);
}
return CommonResult.failed(I18nUtil._("抱歉,砍价活动已失效"));
return CommonResult.failed(I18nUtil._("砍价活动已结束!"));
}
Date now = new Date();
Long expired_at = shopActivityCutprice.getExpired_at();
Long expiredAt = cutprice.getExpired_at();
// 检查砍价订单是否过期
if (CheckUtil.isNotEmpty(expired_at) && expired_at < now.getTime()) {
// 砍价订单已过期更新状态为已过期
updateCutPriceState(shopActivityCutprice.getAc_id(), null, CommonConstant.CutPrice_Order_State_Expired);
return CommonResult.failed(I18nUtil._("砍价已过期,下次早点来!"));
// 检查砍价记录是否过期
if (CheckUtil.isNotEmpty(expiredAt) && expiredAt < now.getTime()) {
updateCutPriceState(cutprice.getAc_id(), null, CommonConstant.CutPrice_Order_State_Expired);
return CommonResult.failed(I18nUtil._("砍价已过期!"));
}
// 检查活动是否已结束活动时间已过
if (!shopStoreActivityBaseService.isActivityTimeValid(shopStoreActivityBase, now)) {
// 活动已结束更新砍价订单状态为已过期
updateCutPriceState(shopActivityCutprice.getAc_id(), null, CommonConstant.CutPrice_Order_State_Expired);
return CommonResult.failed(I18nUtil._("砍价已过期,下次早点来!"));
// 检查活动时间是否有效
try {
if (!shopStoreActivityBaseService.isActivityTimeValid(activityBase, now)) {
updateCutPriceState(cutprice.getAc_id(), null, CommonConstant.CutPrice_Order_State_Expired);
return CommonResult.failed(I18nUtil._("活动已结束!"));
}
} catch (Exception e) {
return CommonResult.failed(I18nUtil._("系统繁忙,请稍后再试!"));
}
// 检查是否是帮别人砍价且次数已用完
if (!shopActivityCutprice.getUser_id().equals(user_id)) {
DateTime today = DateUtil.beginOfDay(new Date());
Integer num = accountBaseConfigService.getConfig("user_cutprice_num", 0);
Integer cut_num = Convert.toInt(redisService.hGet("cutprice-" + today, user_id.toString()), 0);
// 检查帮砍次数限制
if (!cutprice.getUser_id().equals(user_id)) {
try {
if (accountBaseConfigService != null && redisService != null) {
DateTime today = DateUtil.beginOfDay(new Date());
Integer maxCuts = accountBaseConfigService.getConfig("user_cutprice_num", 0);
Integer usedCuts = Convert.toInt(redisService.hGet("cutprice-" + today, user_id.toString()), 0);
if (num > 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<ShopActivityCutpriceHistory> 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<ShopActivityCutpriceHistory> 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);
}

View File

@ -65,6 +65,9 @@ public class StoreValidTimeJod extends QuartzJobBean {
}
page++;
}
// 准备筹备中的店铺到期转正常营业
storeBaseService.batchUpdateStoreBizStateToOpening();
}
}

View File

@ -255,6 +255,15 @@ public interface ShopStoreBaseService extends IBaseService<ShopStoreBase> {
*/
Date getLatestBizOpeningDate(String storeIds);
/**
* 批量更新店铺营业状态为营业中
* 将符合条件的"筹备中"状态店铺更新为"营业中"状态
*
* @return Boolean 更新是否成功
*/
Boolean batchUpdateStoreBizStateToOpening();
// Page<ShopStoreBase> getMobileStoreList(Integer page, Integer rows);
}

View File

@ -339,9 +339,10 @@ public class ShopMchEntryServiceImpl extends BaseServiceImpl<ShopMchEntryMapper,
Map<String, Object> 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<ShopMchEntryMapper,
Map<String, Object> 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);
}
}

View File

@ -4404,6 +4404,29 @@ public class ShopStoreBaseServiceImpl extends BaseServiceImpl<ShopStoreBaseMappe
}
}
/**
* 批量更新店铺营业状态为营业中
* 将符合条件的"筹备中"状态店铺更新为"营业中"状态
*
* @return Boolean 更新是否成功
*/
@Override
public Boolean batchUpdateStoreBizStateToOpening() {
try {
UpdateWrapper<ShopStoreBase> 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<ShopStoreBase> getMobileStoreList(Integer page, Integer rows) {