|
|
@@ -11,14 +11,13 @@ import com.cyksj.common.constant.PointsRecordConst;
|
|
|
import com.cyksj.common.constant.TaskTypeEnum;
|
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
import com.cyksj.common.snowflake.Sequence;
|
|
|
-import com.cyksj.mapper.AddressMapper;
|
|
|
-import com.cyksj.mapper.OrderDonMapper;
|
|
|
-import com.cyksj.mapper.OrderDonTransportMapper;
|
|
|
-import com.cyksj.mapper.UserMapper;
|
|
|
+import com.cyksj.common.util.Jsons;
|
|
|
+import com.cyksj.mapper.*;
|
|
|
import com.cyksj.mapper.corp.CorpUserMapper;
|
|
|
import com.cyksj.mapper.manage.coupon.CouponUserMapper;
|
|
|
import com.cyksj.mapper.manage.distribute.UserDistributeSharedMapper;
|
|
|
import com.cyksj.mapper.market.draw.LuckyDrawRecordMapper;
|
|
|
+import com.cyksj.mapper.market.draw.LuckyDrawSpecificChanceMapper;
|
|
|
import com.cyksj.mapper.market.sign.SignConfigMapper;
|
|
|
import com.cyksj.mapper.market.sign.SignUserMapper;
|
|
|
import com.cyksj.mapper.market.sign.UserPointsRecordMapper;
|
|
|
@@ -26,6 +25,7 @@ import com.cyksj.mapper.market.task.TaskFollowPlatVerifyMapper;
|
|
|
import com.cyksj.mapper.market.task.TaskUserCompleteRecordMapper;
|
|
|
import com.cyksj.mapper.market.task.UserBindPhoneMapper;
|
|
|
import com.cyksj.model.entity.*;
|
|
|
+import com.cyksj.model.manage.views.GroupsRelationView;
|
|
|
import com.cyksj.model.request.LuckyDrawReq;
|
|
|
import com.cyksj.model.request.TaskFollowReq;
|
|
|
import com.cyksj.model.views.LuckyDrawView;
|
|
|
@@ -37,6 +37,7 @@ import com.cyksj.service.market.MarketFrontService;
|
|
|
import com.cyksj.service.sys.SysConfigService;
|
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
|
import com.ejlchina.searcher.param.Operator;
|
|
|
+import com.ejlchina.searcher.util.MapBuilder;
|
|
|
import com.ejlchina.searcher.util.MapUtils;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -45,6 +46,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.concurrent.ThreadLocalRandom;
|
|
|
@@ -93,6 +95,10 @@ public class MarketFrontServiceImpl implements MarketFrontService {
|
|
|
|
|
|
private final TaskFollowPlatVerifyMapper taskFollowPlatVerifyMapper;
|
|
|
|
|
|
+ private final GroupsRelationMapper groupsRelationMapper;
|
|
|
+
|
|
|
+ private final LuckyDrawSpecificChanceMapper luckyDrawSpecificChanceMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public SignUser signByUserId(Long userId) {
|
|
|
//第一次签到
|
|
|
@@ -147,21 +153,16 @@ public class MarketFrontServiceImpl implements MarketFrontService {
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Throwable.class)
|
|
|
- public LuckyDrawView lottery(Long userId) {
|
|
|
- SysConfig lottery_points_limit = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class).eq(SysConfig::getSysKey, "lottery_points_limit").last("limit 1"));
|
|
|
- User user = userMapper.selectById(userId);
|
|
|
- BigDecimal subPoints = BigDecimal.valueOf(Long.parseLong(lottery_points_limit.getSysValue()));
|
|
|
- if (user.getActivePoints().compareTo(subPoints) < 0) {
|
|
|
- throw BusinessRuntimeException.getInstance("积分不足");
|
|
|
- }
|
|
|
- //扣减积分
|
|
|
- Integer sub = userMapper.subActivePoints(userId, subPoints);
|
|
|
- if (sub != 1) {
|
|
|
- throw BusinessRuntimeException.getInstance("积分不足");
|
|
|
+ public LuckyDrawView lottery(Long userId, LuckyDraw.DrawType drawType) throws Exception {
|
|
|
+ List<Long> goodsIdList = null;
|
|
|
+ if (drawType == LuckyDraw.DrawType.normal) {
|
|
|
+ luckyDrawNormalCheck(userId);
|
|
|
+ } else {
|
|
|
+ goodsIdList = luckyDrawSpecificCheck(userId);
|
|
|
}
|
|
|
- pointsRecord(userId, -subPoints.intValue(), PointsRecordConst.POINTS_LOTTERY, true);
|
|
|
List<LuckyDrawView> drawViews = beanSearcher.searchAll(LuckyDrawView.class, MapUtils.builder()
|
|
|
.field(LuckyDrawView::getStatus, true).op(Operator.Equal)
|
|
|
+ .field(LuckyDrawView::getDrawType, drawType)
|
|
|
.orderBy(LuckyDrawView::getProbability).asc()
|
|
|
.build());
|
|
|
if (drawViews.isEmpty()) {
|
|
|
@@ -172,7 +173,7 @@ public class MarketFrontServiceImpl implements MarketFrontService {
|
|
|
throw BusinessRuntimeException.getInstance("系统异常,请刷新页面重新操作");
|
|
|
}
|
|
|
LuckyDrawView luckyDraw = drawViews.get(index);
|
|
|
- if (luckyDraw.getType() != LuckyDraw.Type.points) {
|
|
|
+ if (luckyDraw.getType() != LuckyDraw.Type.points && luckyDraw.getType() != LuckyDraw.Type.duration) {
|
|
|
Integer num = 1;
|
|
|
luckyDraw = randomNum(luckyDraw, drawViews, num, userId);
|
|
|
if (luckyDraw == null) {
|
|
|
@@ -199,6 +200,23 @@ public class MarketFrontServiceImpl implements MarketFrontService {
|
|
|
record.setStatus(LuckyDrawRecord.Status.pending);
|
|
|
} else if (luckyDraw.getType() == LuckyDraw.Type.realGoods) {
|
|
|
record.setStatus(LuckyDrawRecord.Status.pending);
|
|
|
+ } else if (luckyDraw.getType() == LuckyDraw.Type.duration) {
|
|
|
+ MapBuilder builder = MapUtils.builder()
|
|
|
+ .field(GroupsRelationView::getUserId, userId)
|
|
|
+ .field(GroupsRelationView::getStatus, "validity")
|
|
|
+ .field(GroupsRelationView::getExpiryTime).op(Operator.NotNull);
|
|
|
+ if (goodsIdList != null && goodsIdList.size() > 0) {
|
|
|
+ builder.field(GroupsRelationView::getGoodsId, goodsIdList).op(Operator.InList);
|
|
|
+ }
|
|
|
+ //若对应平台车票仅有一张且已发车,直接增加车票时长
|
|
|
+ List<GroupsRelationView> relations = beanSearcher.searchAll(GroupsRelationView.class, builder.build());
|
|
|
+ if (relations != null && relations.size() == 1) {
|
|
|
+ Long relationId = relations.get(0).getId();
|
|
|
+ updateRelationExpiryTime(userId, relationId, luckyDraw.getDays());
|
|
|
+ record.setStatus(LuckyDrawRecord.Status.success);
|
|
|
+ } else {
|
|
|
+ record.setStatus(LuckyDrawRecord.Status.pending);
|
|
|
+ }
|
|
|
}
|
|
|
record.setUserId(userId);
|
|
|
record.setDrawId(luckyDraw.getId());
|
|
|
@@ -218,39 +236,16 @@ public class MarketFrontServiceImpl implements MarketFrontService {
|
|
|
if (record.getStatus() == LuckyDrawRecord.Status.success) {
|
|
|
throw BusinessRuntimeException.getInstance("您已领取该中奖奖品");
|
|
|
}
|
|
|
- User user = userMapper.selectById(userId);
|
|
|
- /* 生成订单 */
|
|
|
- String donNo = SEQUENCE.nextId().toString();
|
|
|
- OrderDon orderDon = new OrderDon();
|
|
|
- orderDon.setOrderNo(donNo);
|
|
|
- orderDon.setOpenId(user.getOpenId());
|
|
|
- BigDecimal zero = BigDecimal.ZERO;
|
|
|
- orderDon.setMoney(zero);
|
|
|
- orderDon.setRealMoney(zero);
|
|
|
- orderDon.setSkuId(record.getSkuId());
|
|
|
- orderDon.setRelationId(0L);
|
|
|
- orderDon.setNum(1);
|
|
|
- orderDon.setGoodsId(record.getGoodsId());
|
|
|
- orderDon.setStatus(record.getType() == LuckyDraw.Type.realGoods ? OrderDon.Status.hasPayment : OrderDon.Status.complete);
|
|
|
- orderDon.setUserId(user.getId());
|
|
|
- orderDon.setType(OrderDon.Type.LOTTERY);
|
|
|
- orderDonMapper.insert(orderDon);
|
|
|
-
|
|
|
- Address address = addressMapper.selectById(luckyDrawReq.getAddressId());
|
|
|
- if (address == null) {
|
|
|
- throw new BusinessRuntimeException("请添加收货地址.");
|
|
|
+ Long orderId = null;
|
|
|
+ if (record.getType() == LuckyDraw.Type.realGoods) {
|
|
|
+ orderId = receiveRealGoodsReward(userId, record, luckyDrawReq.getAddressId());
|
|
|
+ } else if (record.getType() == LuckyDraw.Type.duration) {
|
|
|
+ updateRelationExpiryTime(userId, luckyDrawReq.getRelationId(), record.getDays());
|
|
|
}
|
|
|
- OrderDonTransport transport = new OrderDonTransport();
|
|
|
- transport.setOrderId(orderDon.getId());
|
|
|
- transport.setReceiver(address.getReceiver());
|
|
|
- transport.setPhone(address.getPhone());
|
|
|
- transport.setProvince(address.getProvince());
|
|
|
- transport.setCity(address.getCity());
|
|
|
- transport.setDistrict(address.getDistrict());
|
|
|
- transport.setAddress(address.getAddress());
|
|
|
- orderDonTransportMapper.insert(transport);
|
|
|
-
|
|
|
- Integer update = luckyDrawRecordMapper.updateStatus(record.getId(), orderDon.getId(), LuckyDrawRecord.Status.success);
|
|
|
+ if (orderId == null) {
|
|
|
+ orderId = 0l;;
|
|
|
+ }
|
|
|
+ Integer update = luckyDrawRecordMapper.updateStatus(record.getId(), orderId, LuckyDrawRecord.Status.success);
|
|
|
if (update != 1) {
|
|
|
throw BusinessRuntimeException.getInstance("系统异常,请刷新页面重新操作");
|
|
|
}
|
|
|
@@ -564,4 +559,130 @@ public class MarketFrontServiceImpl implements MarketFrontService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public void luckyDrawNormalCheck(Long userId) {
|
|
|
+ SysConfig lottery_points_limit = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class).eq(SysConfig::getSysKey, Constant.LOTTERY_POINTS_LIMIT).last("limit 1"));
|
|
|
+ User user = userMapper.selectById(userId);
|
|
|
+ BigDecimal subPoints = BigDecimal.valueOf(Long.parseLong(lottery_points_limit.getSysValue()));
|
|
|
+ if (user.getActivePoints().compareTo(subPoints) < 0) {
|
|
|
+ throw BusinessRuntimeException.getInstance("积分不足");
|
|
|
+ }
|
|
|
+ //扣减积分
|
|
|
+ Integer sub = userMapper.subActivePoints(userId, subPoints);
|
|
|
+ if (sub != 1) {
|
|
|
+ throw BusinessRuntimeException.getInstance("积分不足");
|
|
|
+ }
|
|
|
+ pointsRecord(userId, -subPoints.intValue(), PointsRecordConst.POINTS_LOTTERY, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Long> luckyDrawSpecificCheck(Long userId) throws Exception {
|
|
|
+ SysConfig lottery_specific_goods = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class).eq(SysConfig::getSysKey, Constant.LOTTERY_SPECIFIC_GOODS).last("limit 1"));
|
|
|
+ if (lottery_specific_goods == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("暂未配置特定奖池平台,请联系客服");
|
|
|
+ }
|
|
|
+ String sysValue = lottery_specific_goods.getSysValue();
|
|
|
+ if (sysValue == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("");
|
|
|
+ }
|
|
|
+ List<Long> goodsIdList = Jsons.parseList(sysValue, Long.class);
|
|
|
+ Integer num = getSpecificChanceNum(userId);
|
|
|
+ if (num <= 0) {
|
|
|
+ throw BusinessRuntimeException.getInstance("您的抽奖次数为0");
|
|
|
+ }
|
|
|
+ Integer update = luckyDrawSpecificChanceMapper.subChanceNum(userId, num);
|
|
|
+ if (update != 1) {
|
|
|
+ throw BusinessRuntimeException.getInstance("操作频繁,请稍后再试");
|
|
|
+ }
|
|
|
+ return goodsIdList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Integer getSpecificChanceNum(Long userId) {
|
|
|
+ //是否有特定奖池抽奖机会
|
|
|
+ LuckyDrawSpecificChance chance = luckyDrawSpecificChanceMapper.selectOne(Wrappers.lambdaQuery(LuckyDrawSpecificChance.class)
|
|
|
+ .eq(LuckyDrawSpecificChance::getUserId, userId).last("limit 1").select(LuckyDrawSpecificChance::getNum));
|
|
|
+ Integer num = 0;
|
|
|
+ if (chance == null) {
|
|
|
+ return num;
|
|
|
+ }
|
|
|
+ num = chance.getNum();
|
|
|
+ return num;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<GroupsRelationView> getSpecificTickets(Long userId) throws Exception {
|
|
|
+ SysConfig lottery_specific_goods = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class).eq(SysConfig::getSysKey, Constant.LOTTERY_SPECIFIC_GOODS).last("limit 1"));
|
|
|
+ if (lottery_specific_goods == null) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ String sysValue = lottery_specific_goods.getSysValue();
|
|
|
+ if (sysValue == null) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ List<Long> goodsIdList = Jsons.parseList(sysValue, Long.class);
|
|
|
+ MapBuilder builder = MapUtils.builder()
|
|
|
+ .field(GroupsRelationView::getUserId, userId)
|
|
|
+ .field(GroupsRelationView::getStatus, "validity")
|
|
|
+ .field(GroupsRelationView::getExpiryTime).op(Operator.NotNull);
|
|
|
+ if (goodsIdList != null && goodsIdList.size() > 0) {
|
|
|
+ builder.field(GroupsRelationView::getGoodsId, goodsIdList).op(Operator.InList);
|
|
|
+ }
|
|
|
+ List<GroupsRelationView> relations = beanSearcher.searchAll(GroupsRelationView.class, builder.build());
|
|
|
+ return relations;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Long receiveRealGoodsReward(Long userId, LuckyDrawRecord record, Long addressId) {
|
|
|
+ User user = userMapper.selectById(userId);
|
|
|
+ /* 生成订单 */
|
|
|
+ String donNo = SEQUENCE.nextId().toString();
|
|
|
+ OrderDon orderDon = new OrderDon();
|
|
|
+ orderDon.setOrderNo(donNo);
|
|
|
+ orderDon.setOpenId(user.getOpenId());
|
|
|
+ BigDecimal zero = BigDecimal.ZERO;
|
|
|
+ orderDon.setMoney(zero);
|
|
|
+ orderDon.setRealMoney(zero);
|
|
|
+ orderDon.setSkuId(record.getSkuId());
|
|
|
+ orderDon.setRelationId(0L);
|
|
|
+ orderDon.setNum(1);
|
|
|
+ orderDon.setGoodsId(record.getGoodsId());
|
|
|
+ orderDon.setStatus(record.getType() == LuckyDraw.Type.realGoods ? OrderDon.Status.hasPayment : OrderDon.Status.complete);
|
|
|
+ orderDon.setUserId(user.getId());
|
|
|
+ orderDon.setType(OrderDon.Type.LOTTERY);
|
|
|
+ orderDonMapper.insert(orderDon);
|
|
|
+
|
|
|
+ Address address = addressMapper.selectById(addressId);
|
|
|
+ if (address == null) {
|
|
|
+ throw new BusinessRuntimeException("请添加收货地址.");
|
|
|
+ }
|
|
|
+ OrderDonTransport transport = new OrderDonTransport();
|
|
|
+ transport.setOrderId(orderDon.getId());
|
|
|
+ transport.setReceiver(address.getReceiver());
|
|
|
+ transport.setPhone(address.getPhone());
|
|
|
+ transport.setProvince(address.getProvince());
|
|
|
+ transport.setCity(address.getCity());
|
|
|
+ transport.setDistrict(address.getDistrict());
|
|
|
+ transport.setAddress(address.getAddress());
|
|
|
+ orderDonTransportMapper.insert(transport);
|
|
|
+
|
|
|
+ return orderDon.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void updateRelationExpiryTime(Long userId, Long relationId, Integer days) {
|
|
|
+ //增加续费时长
|
|
|
+ GroupsRelation relation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
|
|
|
+ .eq(GroupsRelation::getUserId, userId)
|
|
|
+ .eq(GroupsRelation::getId, relationId)
|
|
|
+ .eq(GroupsRelation::getStatus, GroupsRelation.Status.validity)
|
|
|
+ .last("limit 1"));
|
|
|
+ if (relation == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("该车票不存在");
|
|
|
+ }
|
|
|
+ if (relation.getExpiryTime() == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("该车位未发车,请在发车后延长车票时长");
|
|
|
+ }
|
|
|
+ Date expiryTime = relation.getExpiryTime();
|
|
|
+ relation.setExpiryTime(DateUtil.offsetDay(expiryTime, days));
|
|
|
+ groupsRelationMapper.updateById(relation);
|
|
|
+ }
|
|
|
}
|