Sfoglia il codice sorgente

add 特定抽奖奖池

zoujiajian 3 anni fa
parent
commit
92cd394a0f

+ 10 - 0
netflix-common/src/main/java/com/cyksj/common/constant/Constant.java

@@ -30,4 +30,14 @@ public interface Constant {
 	 * 默认头像
 	 */
 	String DEFAULT_HEAD_IMG = "https://cdn.sxfoundation.com/picture/f6ee11101c4f5f0bc48d88aca7a5dbfd-1666945673391.png";
+
+	/**
+	 * 普通奖池积分配置key
+	 */
+	String LOTTERY_POINTS_LIMIT = "lottery_points_limit";
+
+	/**
+	 * 特定奖池平台配置key
+	 */
+	String LOTTERY_SPECIFIC_GOODS = "lottery_specific_goods";
 }

+ 20 - 0
netflix-dao/src/main/java/com/cyksj/mapper/market/draw/LuckyDrawSpecificChanceMapper.java

@@ -0,0 +1,20 @@
+package com.cyksj.mapper.market.draw;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.cyksj.model.entity.LuckyDrawSpecificChance;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Update;
+
+/*
+ *项目名: netflix
+ *文件名: LuckyDrawSpecificChanceMapper
+ *创建者: JavaZou
+ *创建时间:2023/2/20 15:36
+ */
+public interface LuckyDrawSpecificChanceMapper extends BaseMapper<LuckyDrawSpecificChance> {
+	@Update("update lucky_draw_specific_chance set num = num - 1 where user_id = #{userId} and num = #{num} and num > 0")
+	Integer subChanceNum(@Param("userId") Long userId, @Param("num") Integer num);
+
+	@Update("update lucky_draw_specific_chance set num = num + 1 where user_id = #{userId} and num >= 0")
+	void addChanceNum(Long userId);
+}

+ 13 - 0
netflix-dao/src/main/java/com/cyksj/mapper/market/draw/LuckyDrawSpecificChanceRecordMapper.java

@@ -0,0 +1,13 @@
+package com.cyksj.mapper.market.draw;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.cyksj.model.entity.LuckyDrawSpecificChanceRecord;
+
+/*
+ *项目名: netflix
+ *文件名: LuckyDrawSpecificChanceRecordMapper
+ *创建者: JavaZou
+ *创建时间:2023/2/20 15:36
+ */
+public interface LuckyDrawSpecificChanceRecordMapper extends BaseMapper<LuckyDrawSpecificChanceRecord> {
+}

+ 17 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/LuckyDraw.java

@@ -30,6 +30,8 @@ public class LuckyDraw extends BaseEntity {
 
 	private Long skuId;
 
+	private Integer days;
+
 	private Integer cost;
 
 	private Integer num;
@@ -42,6 +44,8 @@ public class LuckyDraw extends BaseEntity {
 
 	private String picture;
 
+	private LuckyDraw.DrawType drawType;
+
 	private Boolean status;
 
 	private Boolean deleted;
@@ -52,6 +56,7 @@ public class LuckyDraw extends BaseEntity {
 		coupon("优惠券"),
 		realGoods("实物"),
 		virtualGoods("虚物"),
+		duration("车票时长"),
 		;
 		String desc;
 
@@ -59,4 +64,16 @@ public class LuckyDraw extends BaseEntity {
 			this.desc = desc;
 		}
 	}
+
+	@Getter
+	public enum DrawType {
+		normal("普通奖池"),
+		specific("特定奖池"),
+		;
+		String desc;
+
+		DrawType(String desc) {
+			this.desc = desc;
+		}
+	}
 }

+ 4 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/LuckyDrawRecord.java

@@ -30,6 +30,8 @@ public class LuckyDrawRecord extends BaseEntity{
 
 	private Long skuId;
 
+	private Integer days;
+
 	private Integer cost;
 
 	/**
@@ -39,6 +41,8 @@ public class LuckyDrawRecord extends BaseEntity{
 
 	private String picture;
 
+	private LuckyDraw.DrawType drawType;
+
 	private Status status;
 
 	@Getter

+ 21 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/LuckyDrawSpecificChance.java

@@ -0,0 +1,21 @@
+package com.cyksj.model.entity;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/*
+ *项目名: netflix
+ *文件名: LuckyDrawSpecificChance
+ *创建者: JavaZou
+ *创建时间:2023/2/20 15:34
+ */
+@Getter
+@Setter
+public class LuckyDrawSpecificChance extends BaseEntity{
+	private Long userId;
+
+	/**
+	 * 抽奖次数
+	 */
+	private Integer num;
+}

+ 22 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/LuckyDrawSpecificChanceRecord.java

@@ -0,0 +1,22 @@
+package com.cyksj.model.entity;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/*
+ *项目名: netflix
+ *文件名: LuckyDrawSpecificChanceRecord
+ *创建者: JavaZou
+ *创建时间:2023/2/20 15:35
+ */
+@Getter
+@Setter
+public class LuckyDrawSpecificChanceRecord extends BaseEntity{
+	private Long userId;
+
+	private Long orderId;
+
+	private Long goodsId;
+
+	private Long skuId;
+}

+ 6 - 0
netflix-dao/src/main/java/com/cyksj/model/request/LuckyDrawReq.java

@@ -23,4 +23,10 @@ public class LuckyDrawReq {
 
 	@NotNull
 	private Long recordId;
+
+	/**
+	 * 座位号
+	 */
+	@NotNull
+	private Long relationId;
 }

+ 6 - 0
netflix-dao/src/main/java/com/cyksj/model/views/LuckyDrawRecordView.java

@@ -69,6 +69,12 @@ public class LuckyDrawRecordView {
 	@DbField("lr.cost")
 	private Integer cost;
 
+	@DbField("lr.days")
+	private Integer days;
+
+	@DbField("lr.draw_type")
+	private LuckyDraw.DrawType drawType;
+
 	@DbField("lr.status")
 	private LuckyDrawRecord.Status status;
 

+ 6 - 0
netflix-dao/src/main/java/com/cyksj/model/views/LuckyDrawView.java

@@ -71,12 +71,18 @@ public class LuckyDrawView {
 	@DbField("ld.probability")
 	private BigDecimal probability;
 
+	@DbField("ld.days")
+	private Integer days;
+
 	@DbField("ld.num")
 	private Integer num;
 
 	@DbField("ld.picture")
 	private String picture;
 
+	@DbField("ld.draw_type")
+	private LuckyDraw.DrawType drawType;
+
 	@DbField("ld.status")
 	private Boolean status;
 

+ 9 - 1
netflix-service/src/main/java/com/cyksj/service/market/MarketFrontService.java

@@ -1,12 +1,16 @@
 package com.cyksj.service.market;
 
 
+import com.cyksj.model.entity.LuckyDraw;
 import com.cyksj.model.entity.SignUser;
+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;
 import com.cyksj.model.views.TaskFrontView;
 
+import java.util.List;
+
 public interface MarketFrontService {
 	SignUser signByUserId(Long userId);
 
@@ -17,7 +21,7 @@ public interface MarketFrontService {
 	 */
 	void pointsRecord(Long userId, Integer points, String remark, Boolean isLottery);
 
-	LuckyDrawView lottery(Long userId);
+	LuckyDrawView lottery(Long userId, LuckyDraw.DrawType drawType) throws Exception;
 
 	void receivedLuckyDraw(Long userId, LuckyDrawReq luckyDrawReq);
 
@@ -28,4 +32,8 @@ public interface MarketFrontService {
 	void toCompleteFollowTask(TaskFollowReq taskFollowReq);
 
 	void updateFailFollowTask(TaskFollowReq taskFollowReq);
+
+	Integer getSpecificChanceNum(Long userId);
+
+	List<GroupsRelationView> getSpecificTickets(Long userId) throws Exception;
 }

+ 7 - 0
netflix-service/src/main/java/com/cyksj/service/market/draw/impl/LuckyDrawServiceImpl.java

@@ -97,6 +97,13 @@ public class LuckyDrawServiceImpl implements LuckyDrawService {
 			if (luckyDraw.getPoints() == null || luckyDraw.getPoints() < 0) {
 				throw BusinessRuntimeException.getInstance("积分为空");
 			}
+		} else if (luckyDraw.getType() == LuckyDraw.Type.duration) {
+			if (luckyDraw.getDays() == null || luckyDraw.getDays() < 1) {
+				throw BusinessRuntimeException.getInstance("时长要大于0");
+			}
+			if (luckyDraw.getDrawType() != LuckyDraw.DrawType.specific) {
+				throw BusinessRuntimeException.getInstance("该奖池下不允许配置该奖品类型");
+			}
 		} else {
 			GoodsDonSkuView goodsDonSkuView = beanSearcher.searchFirst(GoodsDonSkuView.class, MapUtils.builder()
 					.field(GoodsDonSkuView::getGoodsId, luckyDraw.getGoodsId()).op(Operator.Equal)

+ 170 - 49
netflix-service/src/main/java/com/cyksj/service/market/impl/MarketFrontServiceImpl.java

@@ -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);
+	}
 }

+ 65 - 0
netflix-service/src/main/java/com/cyksj/service/order/impl/OrderDonServiceImpl.java

@@ -39,6 +39,8 @@ import com.cyksj.mapper.manage.coupon.CouponMapper;
 import com.cyksj.mapper.manage.coupon.CouponSkuMapper;
 import com.cyksj.mapper.manage.coupon.CouponUserMapper;
 import com.cyksj.mapper.manage.distribute.*;
+import com.cyksj.mapper.market.draw.LuckyDrawSpecificChanceMapper;
+import com.cyksj.mapper.market.draw.LuckyDrawSpecificChanceRecordMapper;
 import com.cyksj.mapper.market.task.TaskTypeMapper;
 import com.cyksj.model.dto.AliPayParams;
 import com.cyksj.model.dto.CouponPopularizeDto;
@@ -58,6 +60,7 @@ import com.cyksj.service.exchange.ExchangeCodeService;
 import com.cyksj.service.mange.stock.GoodsDonStockService;
 import com.cyksj.service.market.task.TaskService;
 import com.cyksj.service.order.OrderDonService;
+import com.cyksj.service.sys.SysConfigService;
 import com.cyksj.service.template.TemplateCommonService;
 import com.cyksj.service.wechat.WeChatService;
 import com.cyksj.task.JobManager;
@@ -167,6 +170,12 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 
 	private final TemplateCommonService templateCommonService;
 
+	private final SysConfigService sysConfigService;
+
+	private final LuckyDrawSpecificChanceMapper luckyDrawSpecificChanceMapper;
+
+	private final LuckyDrawSpecificChanceRecordMapper luckyDrawSpecificChanceRecordMapper;
+
 	private final List<String> noChekGoodsTemp = List.of("Apple One", "Youtube", "Spotify");
 
 	@Transactional(rollbackFor = Throwable.class)
@@ -477,6 +486,14 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 		}
 		this.updateById(order);
 
+		//配置了特定奖池,增加抽奖机会
+		TASK_POOL.execute(() -> {
+			try {
+				addSpecificChanceNum(order.getUserId(), order.getId(), order.getGoodsId(), order.getSkuId());
+			} catch (Exception e) {
+				log.error("wx增加抽奖机会error:{}", e);
+			}
+		});
 	}
 
 	@Override
@@ -737,6 +754,15 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 			handleServiceRenewOrder(orderDon);
 		}
 		this.updateById(orderDon);
+
+		//配置了特定奖池,增加抽奖机会
+		TASK_POOL.execute(() -> {
+			try {
+				addSpecificChanceNum(orderDon.getUserId(), orderDon.getId(), orderDon.getGoodsId(), orderDon.getSkuId());
+			} catch (Exception e) {
+				log.error("zfb增加抽奖机会error:{}", e);
+			}
+		});
 	}
 
 	@Override
@@ -1496,4 +1522,43 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 			}
 		}
 	}
+
+	private void addSpecificChanceNum(Long userId, Long orderId, Long goodsId, Long skuId) 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;
+		}
+		String sysValue = lottery_specific_goods.getSysValue();
+		if (sysValue == null) {
+			return;
+		}
+		List<Long> goodsIdList = Jsons.parseList(sysValue, Long.class);
+		if (!goodsIdList.contains(goodsId)) {
+			return;
+		}
+		LuckyDrawSpecificChance chance = luckyDrawSpecificChanceMapper.selectOne(Wrappers.lambdaQuery(LuckyDrawSpecificChance.class)
+				.eq(LuckyDrawSpecificChance::getUserId, userId).last("limit 1").select(LuckyDrawSpecificChance::getNum));
+		if (chance == null) {
+			try {
+				LuckyDrawSpecificChance entity = new LuckyDrawSpecificChance();
+				entity.setUserId(userId);
+				entity.setNum(1);
+				luckyDrawSpecificChanceMapper.insert(entity);
+			} catch (DuplicateKeyException e) {
+
+			}
+		} else {
+			luckyDrawSpecificChanceMapper.addChanceNum(userId);
+		}
+		saveChanceRecord(userId, orderId, goodsId, skuId);
+	}
+
+	public void saveChanceRecord(Long userId, Long orderId, Long goodsId, Long skuId) {
+		LuckyDrawSpecificChanceRecord record = new LuckyDrawSpecificChanceRecord();
+		record.setUserId(userId);
+		record.setOrderId(orderId);
+		record.setGoodsId(goodsId);
+		record.setSkuId(skuId);
+		luckyDrawSpecificChanceRecordMapper.insert(record);
+	}
 }

+ 24 - 2
netflix-web/src/main/java/com/cyksj/web/controller/market/LuckyDrawFrontController.java

@@ -7,7 +7,9 @@ import com.cyksj.common.util.StringUtil;
 import com.cyksj.dto.Result;
 import com.cyksj.enums.GatewayResponse;
 import com.cyksj.mapper.UserMapper;
+import com.cyksj.model.entity.LuckyDraw;
 import com.cyksj.model.entity.User;
+import com.cyksj.model.manage.views.GroupsRelationView;
 import com.cyksj.model.request.LuckyDrawReq;
 import com.cyksj.model.views.LuckyDrawRecordView;
 import com.cyksj.model.views.LuckyDrawView;
@@ -86,14 +88,34 @@ public class LuckyDrawFrontController {
 		return GatewayResponse.SUCCESS.newBuilder().toResult(search);
 	}
 
+	/**
+	 * 特定抽奖机会
+	 */
+	@GetMapping("/get/specific/num")
+	public Result<Integer> getSpecificNum() {
+		long userId = StpUserUtil.getLoginIdAsLong();
+		Integer num = marketFrontService.getSpecificChanceNum(userId);
+		return GatewayResponse.SUCCESS.newBuilder().toResult(num);
+	}
+
+	/**
+	 * 特定奖池 可选平台车票
+	 */
+	@GetMapping("/get/specific/tickets")
+	public Result<List<GroupsRelationView>> getSpecificTickets() throws Exception {
+		long userId = StpUserUtil.getLoginIdAsLong();
+		List<GroupsRelationView> result = marketFrontService.getSpecificTickets(userId);
+		return GatewayResponse.SUCCESS.newBuilder().toResult(result);
+	}
+
 	/**
 	 * 抽奖
 	 */
 	@PostMapping("/lottery")
 	@NoSubmit
-	public Result<LuckyDrawView> lottery() {
+	public Result<LuckyDrawView> lottery(@RequestParam(defaultValue = "normal") LuckyDraw.DrawType drawType) throws Exception {
 		Long userId = StpUserUtil.getLoginIdAsLong();
-		LuckyDrawView luckyDrawView = marketFrontService.lottery(userId);
+		LuckyDrawView luckyDrawView = marketFrontService.lottery(userId, drawType);
 		return GatewayResponse.SUCCESS.newBuilder().toResult(luckyDrawView);
 	}
 

+ 0 - 4
netflix-web/src/main/java/com/cyksj/web/controller/payment/OrderController.java

@@ -3,7 +3,6 @@ package com.cyksj.web.controller.payment;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.extra.qrcode.QrCodeUtil;
 import cn.hutool.extra.qrcode.QrConfig;
-import com.cyksj.common.EnvCommonService;
 import com.cyksj.common.exception.BusinessRuntimeException;
 import com.cyksj.common.util.IoKit;
 import com.cyksj.common.util.Xmls;
@@ -60,9 +59,6 @@ public class OrderController {
     @Resource
     private HttpServletRequest request;
 
-    @Autowired
-    private EnvCommonService envCommonService;
-
     @Autowired
     private OrderDonMapper orderDonMapper;