|
|
@ -11,6 +11,7 @@ package co.yixiang.modules.activity.service.impl; |
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
import cn.hutool.core.util.NumberUtil; |
|
|
|
import cn.hutool.core.util.NumberUtil; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
|
|
|
|
import cn.hutool.core.util.RandomUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import cn.iocoder.yudao.framework.common.exception.ShopException; |
|
|
|
import cn.iocoder.yudao.framework.common.exception.ShopException; |
|
|
|
import co.yixiang.app.common.bean.LocalUser; |
|
|
|
import co.yixiang.app.common.bean.LocalUser; |
|
|
@ -50,8 +51,10 @@ import co.yixiang.utils.FileUtil; |
|
|
|
import co.yixiang.utils.OrderUtil; |
|
|
|
import co.yixiang.utils.OrderUtil; |
|
|
|
import co.yixiang.utils.StringUtils; |
|
|
|
import co.yixiang.utils.StringUtils; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.context.ApplicationEventPublisher; |
|
|
|
import org.springframework.context.ApplicationEventPublisher; |
|
|
|
import org.springframework.data.domain.Pageable; |
|
|
|
import org.springframework.data.domain.Pageable; |
|
|
@ -71,6 +74,7 @@ import java.util.*; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Service |
|
|
|
@Service |
|
|
|
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) |
|
|
|
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) |
|
|
|
|
|
|
|
@Slf4j |
|
|
|
public class YxStoreBargainServiceImpl extends BaseServiceImpl<YxStoreBargainMapper, YxStoreBargain> implements YxStoreBargainService { |
|
|
|
public class YxStoreBargainServiceImpl extends BaseServiceImpl<YxStoreBargainMapper, YxStoreBargain> implements YxStoreBargainService { |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
@ -101,8 +105,10 @@ public class YxStoreBargainServiceImpl extends BaseServiceImpl<YxStoreBargainMap |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private YxUserService yxUserService; |
|
|
|
private YxUserService yxUserService; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 退回库存销量 |
|
|
|
* 退回库存销量 |
|
|
|
|
|
|
|
* |
|
|
|
* @param num 数量 |
|
|
|
* @param num 数量 |
|
|
|
* @param bargainId 砍价产品id |
|
|
|
* @param bargainId 砍价产品id |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -113,6 +119,7 @@ public class YxStoreBargainServiceImpl extends BaseServiceImpl<YxStoreBargainMap |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 增加销量 减少库存 |
|
|
|
* 增加销量 减少库存 |
|
|
|
|
|
|
|
* |
|
|
|
* @param num 数量 |
|
|
|
* @param num 数量 |
|
|
|
* @param bargainId 砍价id |
|
|
|
* @param bargainId 砍价id |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -134,38 +141,68 @@ public class YxStoreBargainServiceImpl extends BaseServiceImpl<YxStoreBargainMap |
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 开始帮助好友砍价 |
|
|
|
* 开始帮助好友砍价 |
|
|
|
|
|
|
|
* |
|
|
|
* @param bargainId 砍价产品id |
|
|
|
* @param bargainId 砍价产品id |
|
|
|
* @param bargainUserUid 开启砍价用户id |
|
|
|
* @param bargainUserUid 开启砍价用户id |
|
|
|
* @param uid 当前用户id |
|
|
|
* @param uid 当前用户id |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void doHelp(Long bargainId, Long bargainUserUid, Long uid) { |
|
|
|
public void doHelp(Long bargainId, Long bargainUserUid, Long uid) { |
|
|
|
|
|
|
|
// 砍价讯息
|
|
|
|
|
|
|
|
|
|
|
|
//开始真正的砍价
|
|
|
|
//开始真正的砍价
|
|
|
|
YxStoreBargainUser storeBargainUser = storeBargainUserService |
|
|
|
YxStoreBargainUser storeBargainUser = storeBargainUserService |
|
|
|
.getBargainUserInfo(bargainId, bargainUserUid); |
|
|
|
.getBargainUserInfo(bargainId, bargainUserUid); |
|
|
|
|
|
|
|
|
|
|
|
YxStoreBargain storeBargain = this.getById(bargainId); |
|
|
|
YxStoreBargain storeBargain = this.getById(bargainId); |
|
|
|
//用户可以砍掉的金额 好友砍价之前获取可以砍价金额
|
|
|
|
|
|
|
|
double coverPrice = NumberUtil.sub(storeBargainUser.getBargainPrice() |
|
|
|
|
|
|
|
,storeBargainUser.getBargainPriceMin()).doubleValue(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
double random = 0d; |
|
|
|
long joinNum = storeBargainUserHelpService.count(Wrappers.<YxStoreBargainUserHelp>lambdaQuery() |
|
|
|
if(coverPrice > 0 ){ |
|
|
|
.eq(YxStoreBargainUserHelp::getBargainId,bargainId) |
|
|
|
|
|
|
|
.eq(YxStoreBargainUserHelp::getBargainUserId,storeBargainUser.getId()) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (joinNum >= storeBargain.getBargainNum()){ |
|
|
|
|
|
|
|
log.info("砍价已经足够人了."); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//用户可以砍掉的金额 好友砍价之前获取可以砍价金额 | 顶点价格 - 最低价格 = 可以砍掉的价格
|
|
|
|
|
|
|
|
BigDecimal coverPrice = NumberUtil.sub(storeBargainUser.getBargainPrice() |
|
|
|
|
|
|
|
, storeBargainUser.getBargainPriceMin()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BigDecimal random = BigDecimal.ZERO; |
|
|
|
|
|
|
|
if (coverPrice.compareTo(BigDecimal.ZERO) > 0) { |
|
|
|
//用户剩余要砍掉的价格
|
|
|
|
//用户剩余要砍掉的价格
|
|
|
|
double surplusPrice = NumberUtil.sub(coverPrice, |
|
|
|
BigDecimal surplusPrice = NumberUtil.sub(coverPrice, |
|
|
|
storeBargainUser.getPrice()).doubleValue(); |
|
|
|
storeBargainUser.getPrice()); |
|
|
|
if(surplusPrice == 0) { |
|
|
|
if (surplusPrice.equals(BigDecimal.ZERO)) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 剩余砍价金额和单次金额哪个小取哪个
|
|
|
|
|
|
|
|
surplusPrice = surplusPrice.compareTo(storeBargain.getBargainMaxPrice()) > 0 |
|
|
|
|
|
|
|
? storeBargain.getBargainMaxPrice() |
|
|
|
|
|
|
|
: surplusPrice ; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 可以砍的最高价格
|
|
|
|
|
|
|
|
// surplusPrice = surplusPrice.subtract(fix);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 判断人头数 确保设定的人数可以全部参数与
|
|
|
|
|
|
|
|
// 还没有参与的人数 = 总人数 - 当前砍价人数
|
|
|
|
|
|
|
|
// 1 每个人至多能砍 (可砍的总价 - 还没有参与的人数 * 0.01),否则剩下的每人一分都没有
|
|
|
|
|
|
|
|
// 2 最后一个人将剩余金额全部砍掉
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( joinNum < storeBargain.getBargainNum() - 1){ |
|
|
|
//生成一个区间随机数
|
|
|
|
//生成一个区间随机数
|
|
|
|
random = OrderUtil.randomNumber( |
|
|
|
random = OrderUtil.randomNumber( |
|
|
|
storeBargain.getBargainMinPrice().doubleValue(), |
|
|
|
storeBargain.getBargainMinPrice(), |
|
|
|
storeBargain.getBargainMaxPrice().doubleValue()); |
|
|
|
surplusPrice); |
|
|
|
if(random > surplusPrice) { |
|
|
|
BigDecimal fix = NumberUtil.mul(storeBargain.getBargainNum() - joinNum , new BigDecimal("0.01")); |
|
|
|
|
|
|
|
random = NumberUtil.sub(random,fix); |
|
|
|
|
|
|
|
}else{ |
|
|
|
random = surplusPrice; |
|
|
|
random = surplusPrice; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -177,19 +214,21 @@ public class YxStoreBargainServiceImpl extends BaseServiceImpl<YxStoreBargainMap |
|
|
|
.uid(uid) |
|
|
|
.uid(uid) |
|
|
|
.bargainId(bargainId) |
|
|
|
.bargainId(bargainId) |
|
|
|
.bargainUserId(storeBargainUser.getId()) |
|
|
|
.bargainUserId(storeBargainUser.getId()) |
|
|
|
.price(BigDecimal.valueOf(random)) |
|
|
|
.price(random) |
|
|
|
.build(); |
|
|
|
.build(); |
|
|
|
storeBargainUserHelpService.save(storeBargainUserHelp); |
|
|
|
storeBargainUserHelpService.save(storeBargainUserHelp); |
|
|
|
|
|
|
|
|
|
|
|
//累计砍掉的金额
|
|
|
|
//累计砍掉的金额
|
|
|
|
double totalPrice = NumberUtil.add(storeBargainUser.getPrice().doubleValue(),random); |
|
|
|
BigDecimal totalPrice; |
|
|
|
|
|
|
|
totalPrice = NumberUtil.add(storeBargainUser.getPrice(), random); |
|
|
|
|
|
|
|
|
|
|
|
//更新砍价参与表
|
|
|
|
//更新砍价参与表
|
|
|
|
YxStoreBargainUser bargainUser = YxStoreBargainUser |
|
|
|
YxStoreBargainUser bargainUser = YxStoreBargainUser |
|
|
|
.builder() |
|
|
|
.builder() |
|
|
|
.id(storeBargainUser.getId()) |
|
|
|
.id(storeBargainUser.getId()) |
|
|
|
.price(BigDecimal.valueOf(totalPrice)) |
|
|
|
.price(totalPrice) |
|
|
|
.build(); |
|
|
|
.build(); |
|
|
|
|
|
|
|
|
|
|
|
//如果砍价完成这里为砍价发起人进行订阅推送
|
|
|
|
//如果砍价完成这里为砍价发起人进行订阅推送
|
|
|
|
if (totalPrice == coverPrice) { |
|
|
|
if (totalPrice == coverPrice) { |
|
|
|
TemplateBean templateBean = TemplateBean.builder() |
|
|
|
TemplateBean templateBean = TemplateBean.builder() |
|
|
@ -206,6 +245,7 @@ public class YxStoreBargainServiceImpl extends BaseServiceImpl<YxStoreBargainMap |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 顶部统计 |
|
|
|
* 顶部统计 |
|
|
|
|
|
|
|
* |
|
|
|
* @param bargainId 砍价商品id |
|
|
|
* @param bargainId 砍价商品id |
|
|
|
* @return TopCountVo |
|
|
|
* @return TopCountVo |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -223,6 +263,7 @@ public class YxStoreBargainServiceImpl extends BaseServiceImpl<YxStoreBargainMap |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 砍价 砍价帮总人数、剩余金额、进度条、已经砍掉的价格 |
|
|
|
* 砍价 砍价帮总人数、剩余金额、进度条、已经砍掉的价格 |
|
|
|
|
|
|
|
* |
|
|
|
* @param bargainId 砍价商品id |
|
|
|
* @param bargainId 砍价商品id |
|
|
|
* @param uid 砍价用户id |
|
|
|
* @param uid 砍价用户id |
|
|
|
* @param myUid 当前用户id |
|
|
|
* @param myUid 当前用户id |
|
|
@ -232,6 +273,9 @@ public class YxStoreBargainServiceImpl extends BaseServiceImpl<YxStoreBargainMap |
|
|
|
public BargainCountVo helpCount(Long bargainId, Long uid, Long myUid) { |
|
|
|
public BargainCountVo helpCount(Long bargainId, Long uid, Long myUid) { |
|
|
|
YxStoreBargainUser storeBargainUser = storeBargainUserService |
|
|
|
YxStoreBargainUser storeBargainUser = storeBargainUserService |
|
|
|
.getBargainUserInfo(bargainId, uid); |
|
|
|
.getBargainUserInfo(bargainId, uid); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
YxStoreBargain bargain = this.getById(bargainId); |
|
|
|
|
|
|
|
|
|
|
|
// 是否帮别人砍,没砍是true,砍了false
|
|
|
|
// 是否帮别人砍,没砍是true,砍了false
|
|
|
|
boolean userBargainStatus = true; |
|
|
|
boolean userBargainStatus = true; |
|
|
|
if (storeBargainUser == null) { |
|
|
|
if (storeBargainUser == null) { |
|
|
@ -241,7 +285,7 @@ public class YxStoreBargainServiceImpl extends BaseServiceImpl<YxStoreBargainMap |
|
|
|
.alreadyPrice(0d) |
|
|
|
.alreadyPrice(0d) |
|
|
|
.status(0) |
|
|
|
.status(0) |
|
|
|
.pricePercent(0) |
|
|
|
.pricePercent(0) |
|
|
|
.price(0d) |
|
|
|
.price(NumberUtil.sub(bargain.getPrice(),bargain.getMinPrice()).doubleValue()) |
|
|
|
.userBargainStatus(userBargainStatus) |
|
|
|
.userBargainStatus(userBargainStatus) |
|
|
|
.build(); |
|
|
|
.build(); |
|
|
|
} |
|
|
|
} |
|
|
@ -274,7 +318,6 @@ public class YxStoreBargainServiceImpl extends BaseServiceImpl<YxStoreBargainMap |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//剩余的砍价金额
|
|
|
|
//剩余的砍价金额
|
|
|
|
double surplusPrice = NumberUtil.sub(diffPrice, storeBargainUser.getPrice()).doubleValue(); |
|
|
|
double surplusPrice = NumberUtil.sub(diffPrice, storeBargainUser.getPrice()).doubleValue(); |
|
|
|
|
|
|
|
|
|
|
@ -290,11 +333,9 @@ public class YxStoreBargainServiceImpl extends BaseServiceImpl<YxStoreBargainMap |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 砍价详情 |
|
|
|
* 砍价详情 |
|
|
|
|
|
|
|
* |
|
|
|
* @param id 砍价id |
|
|
|
* @param id 砍价id |
|
|
|
* @param uid 用户uid |
|
|
|
* @param uid 用户uid |
|
|
|
* @return BargainVo |
|
|
|
* @return BargainVo |
|
|
@ -374,9 +415,9 @@ public class YxStoreBargainServiceImpl extends BaseServiceImpl<YxStoreBargainMap |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 获取砍价商品列表 |
|
|
|
* 获取砍价商品列表 |
|
|
|
|
|
|
|
* |
|
|
|
* @param page page |
|
|
|
* @param page page |
|
|
|
* @param limit limit |
|
|
|
* @param limit limit |
|
|
|
* @return List |
|
|
|
* @return List |
|
|
@ -414,6 +455,7 @@ public class YxStoreBargainServiceImpl extends BaseServiceImpl<YxStoreBargainMap |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 增加分享次数 |
|
|
|
* 增加分享次数 |
|
|
|
|
|
|
|
* |
|
|
|
* @param id 砍价商品id |
|
|
|
* @param id 砍价商品id |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void addBargainShare(Long id) { |
|
|
|
private void addBargainShare(Long id) { |
|
|
@ -422,6 +464,7 @@ public class YxStoreBargainServiceImpl extends BaseServiceImpl<YxStoreBargainMap |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 增加浏览次数 |
|
|
|
* 增加浏览次数 |
|
|
|
|
|
|
|
* |
|
|
|
* @param id 砍价商品id |
|
|
|
* @param id 砍价商品id |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void addBargainLook(Long id) { |
|
|
|
private void addBargainLook(Long id) { |
|
|
@ -431,6 +474,7 @@ public class YxStoreBargainServiceImpl extends BaseServiceImpl<YxStoreBargainMap |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 砍价支付成功订单数量 |
|
|
|
* 砍价支付成功订单数量 |
|
|
|
|
|
|
|
* |
|
|
|
* @param bargainId 砍价id |
|
|
|
* @param bargainId 砍价id |
|
|
|
* @return int |
|
|
|
* @return int |
|
|
|
*/ |
|
|
|
*/ |
|
|
|