Compare commits
4 Commits
a20ca370b9
...
c91fc181c9
| Author | SHA1 | Date | |
|---|---|---|---|
| c91fc181c9 | |||
| 002baf3ffd | |||
| 3aef824fbe | |||
| a7f2a7ac14 |
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|||||||
import com.suisung.mall.common.api.CommonResult;
|
import com.suisung.mall.common.api.CommonResult;
|
||||||
import com.suisung.mall.common.modules.activity.ShopActivityCutprice;
|
import com.suisung.mall.common.modules.activity.ShopActivityCutprice;
|
||||||
import com.suisung.mall.core.web.service.IBaseService;
|
import com.suisung.mall.core.web.service.IBaseService;
|
||||||
|
import org.springframework.data.util.Pair;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -28,4 +29,13 @@ public interface ShopActivityCutpriceService extends IBaseService<ShopActivityCu
|
|||||||
|
|
||||||
CommonResult doCutPrice(Integer ac_id, Integer user_id);
|
CommonResult doCutPrice(Integer ac_id, Integer user_id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 砍价活动是否可以下单
|
||||||
|
*
|
||||||
|
* @param ac_id 活动 自增Id
|
||||||
|
* @param order_user_id 下单用户
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Pair<Boolean, String> canDoOrderCutPriceActivity(Integer ac_id, Integer order_user_id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,6 +35,7 @@ import com.suisung.mall.shop.base.service.AccountBaseConfigService;
|
|||||||
import com.suisung.mall.shop.store.service.ShopStoreActivityBaseService;
|
import com.suisung.mall.shop.store.service.ShopStoreActivityBaseService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
|
import org.springframework.data.util.Pair;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@ -397,4 +398,41 @@ public class ShopActivityCutpriceServiceImpl extends BaseServiceImpl<ShopActivit
|
|||||||
return CommonResult.success(ach_data);
|
return CommonResult.success(ach_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 砍价活动是否可以下单
|
||||||
|
*
|
||||||
|
* @param activity_id 活动 Id
|
||||||
|
* @param order_user_id 下单用户
|
||||||
|
* <p>
|
||||||
|
* 判断逻辑:
|
||||||
|
* 1、活动是否过期
|
||||||
|
* 2、活动是否是下单用户的
|
||||||
|
* 3、活动是否是砍到最低价
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Pair<Boolean, String> canDoOrderCutPriceActivity(Integer activity_id, Integer order_user_id) {
|
||||||
|
QueryWrapper<ShopStoreActivityBase> params = new QueryWrapper<>();
|
||||||
|
params.eq("activity_id", activity_id);
|
||||||
|
ShopStoreActivityBase storeActivityBase = shopStoreActivityBaseService.getOne(params);
|
||||||
|
if (storeActivityBase == null) {
|
||||||
|
return Pair.of(false, I18nUtil._("该活动不存在!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!shopStoreActivityBaseService.isActivityTimeValid(storeActivityBase.getActivity_starttime(), storeActivityBase.getActivity_endtime())) {
|
||||||
|
return Pair.of(false, I18nUtil._("该活动已过期!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
QueryWrapper<ShopActivityCutprice> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.eq("activity_id", activity_id);
|
||||||
|
queryWrapper.eq("user_id", order_user_id);
|
||||||
|
queryWrapper.orderByDesc("ac_id");
|
||||||
|
ShopActivityCutprice shopActivityCutprice = getOne(queryWrapper);
|
||||||
|
if (shopActivityCutprice == null) {
|
||||||
|
return Pair.of(false, I18nUtil._("未找到用户发起的砍价活动!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1155,13 +1155,13 @@ public class ShopOrderInfoServiceImpl extends BaseServiceImpl<ShopOrderInfoMappe
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 时间槽间隔(分钟)
|
// 时间槽间隔(分钟)
|
||||||
int slotInterval = 30;
|
int slotInterval = 15;
|
||||||
|
|
||||||
// 对于今天,需要特殊处理:第二个时间槽从当前时间+50分钟开始
|
// 对于今天,需要特殊处理:第二个时间槽从当前时间+50分钟开始
|
||||||
Date startTime = openTime;
|
Date startTime = openTime;
|
||||||
if (isToday) {
|
if (isToday) {
|
||||||
// 当前时间+50分钟作为第二个时间槽的开始时间
|
// 当前时间+50分钟作为第二个时间槽的开始时间
|
||||||
Date nowPlusFifty = DateUtil.offsetMinute(new Date(), 50);
|
Date nowPlusFifty = DateUtil.offsetMinute(new Date(), 35);
|
||||||
|
|
||||||
// 如果当前时间+50分钟在营业时间范围内,则从该时间开始
|
// 如果当前时间+50分钟在营业时间范围内,则从该时间开始
|
||||||
if (nowPlusFifty.after(openTime) && nowPlusFifty.before(closeTime)) {
|
if (nowPlusFifty.after(openTime) && nowPlusFifty.before(closeTime)) {
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import com.suisung.mall.core.web.service.IBaseService;
|
|||||||
import com.suisung.mall.shop.product.pojo.vo.ProductVo;
|
import com.suisung.mall.shop.product.pojo.vo.ProductVo;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -58,6 +59,15 @@ public interface ShopStoreActivityBaseService extends IBaseService<ShopStoreActi
|
|||||||
List<Long> getActivityAllItemIds(Map activity_row);
|
List<Long> getActivityAllItemIds(Map activity_row);
|
||||||
|
|
||||||
boolean isActivityTimeValid(Map activity_row);
|
boolean isActivityTimeValid(Map activity_row);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证活动时间是否有效
|
||||||
|
*
|
||||||
|
* @param starTime 活动开始时间
|
||||||
|
* @param endTime 活动结束时间
|
||||||
|
* @return 时间是否有效
|
||||||
|
*/
|
||||||
|
boolean isActivityTimeValid(Date starTime, Date endTime);
|
||||||
|
|
||||||
Map listsMarketing();
|
Map listsMarketing();
|
||||||
|
|
||||||
@ -169,4 +179,6 @@ public interface ShopStoreActivityBaseService extends IBaseService<ShopStoreActi
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
Map getGiftbag(Integer activity_id);
|
Map getGiftbag(Integer activity_id);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2055,6 +2055,7 @@ public class ShopStoreActivityBaseServiceImpl extends BaseServiceImpl<ShopStoreA
|
|||||||
* @param activityRow 活动数据
|
* @param activityRow 活动数据
|
||||||
* @return 时间是否有效
|
* @return 时间是否有效
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public boolean isActivityTimeValid(Map activityRow) {
|
public boolean isActivityTimeValid(Map activityRow) {
|
||||||
if (CollUtil.isEmpty(activityRow)) {
|
if (CollUtil.isEmpty(activityRow)) {
|
||||||
return false;
|
return false;
|
||||||
@ -2078,6 +2079,23 @@ public class ShopStoreActivityBaseServiceImpl extends BaseServiceImpl<ShopStoreA
|
|||||||
return !now.before(startTime) && !now.after(endTime);
|
return !now.before(startTime) && !now.after(endTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证活动时间是否有效
|
||||||
|
*
|
||||||
|
* @param starTime 活动开始时间
|
||||||
|
* @param endTime 活动结束时间
|
||||||
|
* @return 时间是否有效
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean isActivityTimeValid(Date starTime, Date endTime) {
|
||||||
|
if (starTime == null || endTime == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Date now = new Date();
|
||||||
|
return !now.before(starTime) && !now.after(endTime);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map listsMarketing() {
|
public Map listsMarketing() {
|
||||||
Integer page = Convert.toInt(getParameter("page"), 1);
|
Integer page = Convert.toInt(getParameter("page"), 1);
|
||||||
@ -3983,43 +4001,68 @@ public class ShopStoreActivityBaseServiceImpl extends BaseServiceImpl<ShopStoreA
|
|||||||
return item_row;
|
return item_row;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算砍价活动中每次砍价的价格
|
||||||
|
*
|
||||||
|
* @param activity_row 活动基础信息
|
||||||
|
* @param ac_row 砍价活动记录
|
||||||
|
* @return 砍价金额
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public BigDecimal getCutDownPrice(ShopStoreActivityBase activity_row, ShopActivityCutprice ac_row) {
|
public BigDecimal getCutDownPrice(ShopStoreActivityBase activity_row, ShopActivityCutprice ac_row) {
|
||||||
|
// 1. 参数校验
|
||||||
if (activity_row == null || ac_row == null) {
|
if (activity_row == null || ac_row == null) {
|
||||||
throw new ApiException(I18nUtil._("活动不存在!"));
|
throw new ApiException(I18nUtil._("活动不存在!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 2. 活动类型校验
|
||||||
Integer activity_type_id = activity_row.getActivity_type_id();
|
Integer activity_type_id = activity_row.getActivity_type_id();
|
||||||
if (ObjectUtil.notEqual(StateCode.ACTIVITY_TYPE_CUTPRICE, activity_type_id)) {
|
if (ObjectUtil.notEqual(StateCode.ACTIVITY_TYPE_CUTPRICE, activity_type_id)) {
|
||||||
throw new ApiException(I18nUtil._("活动不存在!"));
|
throw new ApiException(I18nUtil._("活动不存在!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
BigDecimal price = BigDecimal.ZERO;
|
BigDecimal price;
|
||||||
|
|
||||||
|
// 3. 解析活动规则
|
||||||
String str_activity_rule = activity_row.getActivity_rule();
|
String str_activity_rule = activity_row.getActivity_rule();
|
||||||
JSONObject activity_rule = JSONObject.parseObject(str_activity_rule);
|
JSONObject activity_rule = JSONObject.parseObject(str_activity_rule);
|
||||||
Integer cut_down_type = activity_rule.getObject("cut_down_type", Integer.class);
|
Integer cut_down_type = activity_rule.getObject("cut_down_type", Integer.class);
|
||||||
BigDecimal ac_sale_price = ac_row.getAc_sale_price();
|
BigDecimal ac_sale_price = ac_row.getAc_sale_price();
|
||||||
BigDecimal ac_mix_limit_price = ac_row.getAc_mix_limit_price();
|
BigDecimal ac_mix_limit_price = ac_row.getAc_mix_limit_price();
|
||||||
|
|
||||||
|
// 4. 根据砍价类型计算砍价金额
|
||||||
switch (cut_down_type) {
|
switch (cut_down_type) {
|
||||||
case 1:
|
case 1:
|
||||||
|
// 固定金额砍价
|
||||||
price = activity_rule.getObject("cut_down_fixed_price", BigDecimal.class);
|
price = activity_rule.getObject("cut_down_fixed_price", BigDecimal.class);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
|
// 随机金额砍价
|
||||||
BigDecimal cut_down_min_limit_price = activity_rule.getObject("cut_down_min_limit_price", BigDecimal.class);
|
BigDecimal cut_down_min_limit_price = activity_rule.getObject("cut_down_min_limit_price", BigDecimal.class);
|
||||||
Integer cut_down_user_num = activity_rule.getObject("cut_down_user_num", Integer.class);
|
Integer cut_down_user_num = activity_rule.getObject("cut_down_user_num", Integer.class);
|
||||||
Integer ac_num = ac_row.getAc_num();
|
Integer ac_num = ac_row.getAc_num();
|
||||||
List<Integer> arr = randMoney(NumberUtil.sub(ac_sale_price, cut_down_min_limit_price), cut_down_user_num - ac_num);
|
|
||||||
|
|
||||||
Integer randPrice = arr.size() == 1 ? arr.get(0) : arr.get(RandomUtil.randomInt(0, arr.size() - 1));
|
// 计算剩余可砍价金额和剩余次数
|
||||||
|
List<Integer> arr = randMoney(
|
||||||
|
NumberUtil.sub(ac_sale_price, cut_down_min_limit_price),
|
||||||
|
cut_down_user_num - ac_num
|
||||||
|
);
|
||||||
|
|
||||||
|
// 随机选择一个砍价金额
|
||||||
|
Integer randPrice = arr.size() == 1 ? arr.get(0) : arr.get(RandomUtil.randomInt(0, arr.size()));
|
||||||
price = NumberUtil.div(BigDecimal.valueOf(randPrice), 100, 2);
|
price = NumberUtil.div(BigDecimal.valueOf(randPrice), 100, 2);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
// 未知砍价类型,返回0
|
||||||
|
price = BigDecimal.ZERO;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 5. 返回砍价金额,不超过可砍价的上限
|
||||||
return NumberUtil.min(NumberUtil.sub(ac_sale_price, ac_mix_limit_price), price);
|
return NumberUtil.min(NumberUtil.sub(ac_sale_price, ac_mix_limit_price), price);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ShopStoreActivityBase> getCouponsList(Integer activity_type_id) {
|
public List<ShopStoreActivityBase> getCouponsList(Integer activity_type_id) {
|
||||||
QueryWrapper<ShopStoreActivityBase> wrapper = new QueryWrapper<>();
|
QueryWrapper<ShopStoreActivityBase> wrapper = new QueryWrapper<>();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user