Bläddra i källkod

fix 权益领取

zoujiajian 3 år sedan
förälder
incheckning
7a5c040211

+ 3 - 0
netflix-dao/src/main/java/com/cyksj/mapper/GroupsRelationMapper.java

@@ -3,6 +3,7 @@ package com.cyksj.mapper;
 import cn.hutool.core.date.DateTime;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.cyksj.model.entity.GroupsRelation;
+import com.cyksj.model.manage.views.GroupsRelationView;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Update;
 
@@ -25,4 +26,6 @@ public interface GroupsRelationMapper extends BaseMapper<GroupsRelation> {
 	void updateCustomerService(Long id);
 
 	Long selectSimilarExpiredRelation(@Param("skuId") Long skuId, @Param("minExpiryTime") DateTime minExpiryTime);
+
+	List<GroupsRelationView> selectRelationByGoodsId(@Param("goodsId") Long goodsId, @Param("userId") Long userId);
 }

+ 5 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/UserPayEquipmentAvailableBenefits.java

@@ -24,4 +24,9 @@ public class UserPayEquipmentAvailableBenefits extends BaseEntity {
 	private Long realOrderId;
 
 	private Boolean deleted;
+
+	/**
+	 * 1成功领取,0否
+	 */
+	private Integer statusCode;
 }

+ 1 - 1
netflix-dao/src/main/java/com/cyksj/model/manage/views/AccountView.java

@@ -83,7 +83,7 @@ public class AccountView {
     private String specVal;
 
     @DbField("select count(ur.id) from user_ticket_cleared_record ur where ur.account_id = a.id and deleted is true")
-    private Integer expiredCount;
+    private Integer expiryCount;
 
     @DbField("max(gr.expiry_time)")
     private Date lastTicketTime;

+ 11 - 0
netflix-dao/src/main/java/com/cyksj/model/views/UserAvailableGoodsTicketView.java

@@ -21,6 +21,8 @@ import java.util.List;
 @SearchBean(tables = "user_pay_equipment_available_benefits ub left join goods_don_sku gdk on gdk.id = ub.sku_id" +
 		" left join goods_don g on g.id = gdk.goods_id")
 public class UserAvailableGoodsTicketView {
+	@DbField("ub.id")
+	private Long benefitsId;
 
 	@DbField("g.id")
 	private Long goodsId;
@@ -31,9 +33,18 @@ public class UserAvailableGoodsTicketView {
 	@DbField("ub.sku_id")
 	private Long skuId;
 
+	@DbField("ub.real_order_id")
+	private Long realOrderId;
+
 	@DbField("ub.user_id")
 	private Long userId;
 
+	@DbField("gdk.months")
+	private Integer months;
+
+	@DbField("gdk.spec_val")
+	private String specVal;
+
 	@DbField("ub.deleted")
 	@JsonIgnore
 	private Boolean deleted;

+ 13 - 0
netflix-dao/src/main/resources/mapper/GroupRelationMapper.xml

@@ -51,4 +51,17 @@
         where s.minExpiryTime >= #{minExpiryTime}
         order by minExpiryTime desc limit 1
     </select>
+
+    <select id="selectRelationByGoodsId" resultType="com.cyksj.model.manage.views.GroupsRelationView">
+        select gr.*
+        from groups_relation gr
+                 left join groups_trips gt on gr.groups_id = gt.id
+                 left join account a on a.id = gt.account_id
+                 left join user u on gr.user_id = u.id
+                 left join goods_don g on a.goods_id = g.id
+        where g.id = #{goodsId}
+          and gr.user_id = #{userId}
+          and gt.status = 'validity'
+          and gr.status = 'validity'
+    </select>
 </mapper>

+ 1 - 1
netflix-service/src/main/java/com/cyksj/service/mange/statistics/impl/StatisticsDataServiceImpl.java

@@ -593,7 +593,7 @@ public class StatisticsDataServiceImpl implements StatisticsDataService {
 	public void setGoodsMoneyAndOrder(Integer type, BackgroundDataView backgroundDataView) {
 		List<OrderDonStatisticsView> orderDonStatisticsView = Optional.ofNullable(beanSearcher.searchAll(OrderDonStatisticsView.class,
 				MapUtils.builder().field(OrderDonStatisticsView::getGoodsType, type)
-						.field(OrderDonStatisticsView::getStatus, Constant.noOrderStatus).op(Operator.InList).build())).orElse(new ArrayList<>());
+						.field(OrderDonStatisticsView::getStatus, Constant.noOrderStatus).op(Operator.NotIn).build())).orElse(new ArrayList<>());
 		Optional<BigDecimal> orderMoneyReduce = orderDonStatisticsView.stream().map(OrderDonStatisticsView::getMoney).reduce(BigDecimal::add);
 		int totalOrder = orderDonStatisticsView.size();
 

+ 1 - 1
netflix-service/src/main/java/com/cyksj/service/order/UserRealOrderBenefitsService.java

@@ -32,5 +32,5 @@ public interface UserRealOrderBenefitsService {
 	/**
 	 * 实物权益可选车票
 	 */
-	List<UserAvailableGoodsTicketView> getAvailableBenefitsTickets(Long userId);
+	List<UserAvailableGoodsTicketView> getAvailableBenefitsTickets(Long userId, Long orderId);
 }

+ 18 - 10
netflix-service/src/main/java/com/cyksj/service/order/impl/UserRealOrderBenefitsImpl.java

@@ -60,12 +60,13 @@ public class UserRealOrderBenefitsImpl implements UserRealOrderBenefitsService {
 		for (GoodsDonSku sku : skuIds) {
 			Long skuId = sku.getId();
 			Long goodsId = sku.getGoodsId();
-			List<GroupsRelationView> relationViewList = beanSearcher.searchAll(GroupsRelationView.class, MapUtils.builder()
-					.field(GroupsRelationView::getGoodsId, goodsId)
-					.field(GroupsRelationView::getSkuId, skuId)
-					.field(GroupsRelationView::getUserId, userId)
-					.field(GroupsRelationView::getStatus, GroupsRelation.Status.validity.name())
-					.build());
+			sku = goodsDonSkuMapper.selectById(skuId);
+//			List<GroupsRelationView> relationViewList = beanSearcher.searchAll(GroupsRelationView.class, MapUtils.builder()
+//					.field(GroupsRelationView::getGoodsId, goodsId)
+//					.field(GroupsRelationView::getUserId, userId)
+//					.field(GroupsRelationView::getStatus, GroupsRelation.Status.validity.name())
+//					.build());
+			List<GroupsRelationView> relationViewList = groupsRelationMapper.selectRelationByGoodsId(goodsId, userId);
 			//是否有该规格车票,若无直接发放车票
 			if (CollUtil.isEmpty(relationViewList)) {
 				//领取权益时,没有车票的用户自动上车,获得对应车票
@@ -129,6 +130,9 @@ public class UserRealOrderBenefitsImpl implements UserRealOrderBenefitsService {
 		if (availableBenefits == null) {
 			throw BusinessRuntimeException.getInstance("可获取的权益不存在");
 		}
+		if (availableBenefits.getStatusCode() == 1) {
+			throw BusinessRuntimeException.getInstance("已领取该权益");
+		}
 		if (!availableBenefits.getDeleted()) {
 			throw BusinessRuntimeException.getInstance("购买的实物设备已退款,无法领取该权益");
 		}
@@ -152,6 +156,7 @@ public class UserRealOrderBenefitsImpl implements UserRealOrderBenefitsService {
 			}
 			//删除可领取的权益
 			int update = availableBenefitsMapper.update(null, Wrappers.lambdaUpdate(UserPayEquipmentAvailableBenefits.class)
+					.set(UserPayEquipmentAvailableBenefits::getStatusCode, 1)
 					.set(UserPayEquipmentAvailableBenefits::getDeleted, false)
 					.eq(UserPayEquipmentAvailableBenefits::getDeleted, true)
 					.eq(UserPayEquipmentAvailableBenefits::getId, benefitsId));
@@ -174,13 +179,16 @@ public class UserRealOrderBenefitsImpl implements UserRealOrderBenefitsService {
 	}
 
 	@Override
-	public List<UserAvailableGoodsTicketView> getAvailableBenefitsTickets(Long userId) {
-		List<UserAvailableGoodsTicketView> ticketViews = beanSearcher.searchAll(UserAvailableGoodsTicketView.class, MapUtils.builder().field(UserAvailableGoodsTicketView::getUserId, userId)
-				.field(UserAvailableGoodsTicketView::getDeleted, true).build());
+	public List<UserAvailableGoodsTicketView> getAvailableBenefitsTickets(Long userId, Long orderId) {
+		List<UserAvailableGoodsTicketView> ticketViews = beanSearcher.searchAll(UserAvailableGoodsTicketView.class, MapUtils.builder()
+				.field(UserAvailableGoodsTicketView::getUserId, userId)
+				.field(UserAvailableGoodsTicketView::getDeleted, true)
+				.field(UserAvailableGoodsTicketView::getRealOrderId, orderId)
+				.build());
 		ticketViews.forEach(ticket -> {
 			List<GroupsRelationView> relationViewList = beanSearcher.searchAll(GroupsRelationView.class, MapUtils.builder()
-					.field(GroupsRelationView::getSkuId, ticket.getSkuId())
 					.field(GroupsRelationView::getUserId, userId)
+					.field(GroupsRelationView::getGoodsId, ticket.getGoodsId())
 					.field(GroupsRelationView::getStatus, GroupsRelation.Status.validity.name())
 					.field(GroupsRelationView::getExpiryTime).op(Operator.NotNull)
 					.build());

+ 15 - 8
netflix-web/src/main/java/com/cyksj/web/controller/user/UserController.java

@@ -25,9 +25,9 @@ import com.cyksj.service.user.UserService;
 import com.cyksj.web.util.StpUserUtil;
 import lombok.RequiredArgsConstructor;
 import org.springframework.util.Assert;
-import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -111,9 +111,9 @@ public class UserController {
      * 用户已有实物权益 可选车票
      */
     @GetMapping("/get/available/benefits/tickets")
-    public Result<List<UserAvailableGoodsTicketView>> getAvailableBenefitsTickets() {
+    public Result<List<UserAvailableGoodsTicketView>> getAvailableBenefitsTickets(Long orderId) {
         Long userId = StpUserUtil.getLoginIdAsLong();
-        List<UserAvailableGoodsTicketView> tickets = userRealOrderBenefitsService.getAvailableBenefitsTickets(userId);
+        List<UserAvailableGoodsTicketView> tickets = userRealOrderBenefitsService.getAvailableBenefitsTickets(userId, orderId);
         return GatewayResponse.SUCCESS.newBuilder().toResult(tickets);
     }
 
@@ -121,11 +121,18 @@ public class UserController {
      * 用户领取实物权益
      */
     @PostMapping("/receive/benefits")
-    public Result<GroupsRelationView> receiveRealGoodsBenefits(@RequestBody @Validated ReceiveBenefitsReq req) {
-        Long benefitsId = req.getBenefitsId(), goodsId = req.getGoodsId(), skuId = req.getSkuId(), relationId = req.getRelationId();
+    public Result<List<GroupsRelationView>> receiveRealGoodsBenefits(@RequestBody List<ReceiveBenefitsReq> reqList) {
+        List<GroupsRelationView> re = new ArrayList<>();
         Long userId = StpUserUtil.getLoginIdAsLong();
-        Assert.notNull(benefitsId, "可获取的权益不存在");
-        GroupsRelationView groupsRelationView = userRealOrderBenefitsService.receiveRealGoodsBenefits(userId, benefitsId, goodsId, skuId, relationId);
-        return GatewayResponse.SUCCESS.newBuilder().toResult(groupsRelationView);
+        reqList.forEach(req -> {
+            Long benefitsId = req.getBenefitsId(), goodsId = req.getGoodsId(), skuId = req.getSkuId(), relationId = req.getRelationId();
+            Assert.notNull(benefitsId, "可获取的权益不存在");
+            Assert.notNull(goodsId, "请选择对应平台");
+            Assert.notNull(skuId, "请选择对应权益规格");
+            Assert.notNull(relationId, "请选择对应车票");
+            GroupsRelationView groupsRelationView = userRealOrderBenefitsService.receiveRealGoodsBenefits(userId, benefitsId, goodsId, skuId, relationId);
+            re.add(groupsRelationView);
+        });
+        return GatewayResponse.SUCCESS.newBuilder().toResult(re);
     }
 }