Просмотр исходного кода

add 领取实物权益;实物分销

zoujiajian 3 лет назад
Родитель
Сommit
46c3f5014c

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

@@ -79,6 +79,11 @@ public class GoodsDon extends BaseEntity {
      */
     private Integer rate;
 
+    /**
+     * 第二分销比例 不包含套餐
+     */
+    private Integer secondRate;
+
     /**
      * 排序
      */

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

@@ -23,5 +23,10 @@ public class UserPlatDistributeRate extends BaseEntity{
 	 * 分销比例
 	 */
 	private Integer rate;
+
+	/**
+	 * 第二分销比例 不包含套餐
+	 */
+	private Integer secondRate;
 }
 

+ 5 - 0
netflix-dao/src/main/java/com/cyksj/model/manage/request/ReqGoodsSpuInsert.java

@@ -80,6 +80,11 @@ public class ReqGoodsSpuInsert {
      */
     private Integer rate;
 
+    /**
+     * 第二分销比例 不包含套餐
+     */
+    private Integer secondRate;
+
     /**
      * 排序
      */

+ 6 - 3
netflix-dao/src/main/java/com/cyksj/model/manage/views/GoodsDonViewer.java

@@ -118,12 +118,15 @@ public class GoodsDonViewer {
     @DbField("g.second_type")
     private Integer secondType;
 
-    /**
-     * banner
-     */
     @DbField("g.rate")
     private Integer rate;
 
+    /**
+     * 第二分销比例 不包含套餐
+     */
+    @DbField("g.second_rate")
+    private Integer secondRate;
+
     @DbField("g.sort_by")
     private Integer sortBy;
 

+ 5 - 0
netflix-dao/src/main/java/com/cyksj/model/request/ReceiveBenefitsReq.java

@@ -14,6 +14,11 @@ import javax.validation.constraints.NotNull;
 @Getter
 @Setter
 public class ReceiveBenefitsReq {
+	/**
+	 * 可获取权益id
+	 */
+	private Long benefitsId;
+
 	@NotNull
 	private Long goodsId;
 

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

@@ -1,5 +1,7 @@
 package com.cyksj.service.order;
 
+import com.cyksj.model.manage.views.GroupsRelationView;
+
 import java.util.List;
 
 /*
@@ -13,10 +15,15 @@ public interface UserRealOrderBenefitsService {
 	/**
 	 * 获取购买实物权益
 	 */
-	void receivePayRealGoodsBenefits(Long userId, Long id, Long id1, List<Long> skuIds);
+	void getPayRealGoodsBenefits(Long userId, Long goodsId, Long skuId, List<Long> skuIds);
 
 	/**
 	 * 扣除实物权益
 	 */
 	void deductUserRealGoodsBenefits(Long orderId);
+
+	/**
+	 * 领取实物权益
+	 */
+	GroupsRelationView receiveRealGoodsBenefits(Long userId, Long benefitsId, Long goodsId, Long skuId, Long relationId);
 }

+ 14 - 4
netflix-service/src/main/java/com/cyksj/service/order/impl/OrderDonServiceImpl.java

@@ -307,7 +307,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 		orderDon.setCouponExCode(payRequest.getCouponExCode());
 		if (isNoLogin == null || !isNoLogin) {
 			//虚拟商品订单,是否是分销订单
-			if (goodsDon.getType() == 1) {
+			if (goodsDon.getType() == 1 && goodsDon.getType() == 2) {
 				UserDistributeShared userDistributeShared = userDistributeSharedMapper.selectOne(Wrappers.lambdaQuery(UserDistributeShared.class).eq(UserDistributeShared::getUserId, user.getId()).last("limit 1"));
 				if (userDistributeShared != null) {
 					orderDon.setIsDistribute(true);
@@ -511,7 +511,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 							try {
 								List<Long> skuIds = Jsons.parseList(sku.getBenefitsList(), Long.class);
 								//自购实物 获取权益
-								userRealOrderBenefitsService.receivePayRealGoodsBenefits(order.getUserId(), order.getId(), goodsDon.getId(), skuIds);
+								userRealOrderBenefitsService.getPayRealGoodsBenefits(order.getUserId(), order.getId(), goodsDon.getId(), skuIds);
 							} catch (Exception e) {
 
 							}
@@ -800,7 +800,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 							try {
 								List<Long> skuIds = Jsons.parseList(sku.getBenefitsList(), Long.class);
 								//自购实物 获取权益
-								userRealOrderBenefitsService.receivePayRealGoodsBenefits(orderDon.getUserId(), orderDon.getId(), goodsDon.getId(), skuIds);
+								userRealOrderBenefitsService.getPayRealGoodsBenefits(orderDon.getUserId(), orderDon.getId(), goodsDon.getId(), skuIds);
 							} catch (Exception e) {
 
 							}
@@ -1362,6 +1362,16 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 					//普通分销
 					GoodsDon goodsDon = goodsDonMapper.selectById(order.getGoodsId());
 					if (goodsDon != null) {
+						//实物分销比例
+						if (goodsDon.getType() == 2) {
+							GoodsDonSku goodsDonSku = goodsDonSkuMapper.selectById(order.getSkuId());
+							if (goodsDonSku != null) {
+								//不包含套餐权益
+								if (!goodsDonSku.getIsBenefits()) {
+									goodsDon.setRate(goodsDon.getSecondRate());
+								}
+							}
+						}
 						returnMoney = orderMoney.multiply(BigDecimal.valueOf(goodsDon.getRate())).divide(BigDecimal.valueOf(100));
 					}
 				}else {
@@ -1382,7 +1392,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 				if (points != null && points.compareTo(BigDecimal.ZERO) > 0) {
 					log.info("用户{}邀请{},产生分销订单分发积分记录入库", userDistributeShared.getUserId(), order.getUserId());
 					distributeWaitingSendPoints.setSendStatus(DistributeWaitingSendPoints.Status.waiting);
-					distributeWaitingSendPoints.setSendTime(DateUtil.offsetDay(order.getPayTime(), 7));
+					distributeWaitingSendPoints.setSendTime(DateUtil.offsetDay(order.getPayTime(), 3));
 					distributeWaitingSendPointsMapper.insert(distributeWaitingSendPoints);
 				}
 			}

+ 53 - 1
netflix-service/src/main/java/com/cyksj/service/order/impl/UserRealOrderBenefitsImpl.java

@@ -21,6 +21,7 @@ import com.ejlchina.searcher.util.MapUtils;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
 import java.util.ArrayList;
@@ -55,7 +56,7 @@ public class UserRealOrderBenefitsImpl implements UserRealOrderBenefitsService {
 	private final OrderDonMapper orderDonMapper;
 
 	@Override
-	public void receivePayRealGoodsBenefits(Long userId, Long orderId, Long goodsId, List<Long> skuIds) {
+	public void getPayRealGoodsBenefits(Long userId, Long orderId, Long goodsId, List<Long> skuIds) {
 		skuIds.forEach(skuId->{
 			GoodsDonSku goodsDonSku = goodsDonSkuMapper.selectById(skuId);
 			if (goodsDonSku != null) {
@@ -111,6 +112,57 @@ public class UserRealOrderBenefitsImpl implements UserRealOrderBenefitsService {
 				.eq(UserPayEquipmentAvailableBenefits::getRealOrderId, orderId));
 	}
 
+	@Override
+	@Transactional(rollbackFor = Throwable.class)
+	public GroupsRelationView receiveRealGoodsBenefits(Long userId, Long benefitsId, Long goodsId, Long skuId, Long relationId) {
+		//可获取的权益是否存在
+		UserPayEquipmentAvailableBenefits availableBenefits = availableBenefitsMapper.selectById(benefitsId);
+		if (availableBenefits == null) {
+			throw BusinessRuntimeException.getInstance("可获取的权益不存在");
+		}
+		if (!availableBenefits.getDeleted()) {
+			throw BusinessRuntimeException.getInstance("购买的实物设备已退款,无法领取该权益");
+		}
+		if (!availableBenefits.getSkuId().equals(skuId)) {
+			throw BusinessRuntimeException.getInstance("可领取的车票权益规格错误");
+		}
+		GroupsRelationView groupsRelationView = beanSearcher.searchFirst(GroupsRelationView.class, MapUtils.builder()
+				.field(GroupsRelationView::getGoodsId, goodsId)
+				.field(GroupsRelationView::getId, relationId)
+				.field(GroupsRelationView::getStatus, GroupsRelation.Status.validity.name())
+				.field(GroupsRelationView::getUserId, userId)
+				.build());
+		Optional.ofNullable(groupRelationClearService).ifPresentOrElse(ticket -> {
+			Date expiryTime = groupsRelationView.getExpiryTime();
+			if (expiryTime == null) {
+				throw BusinessRuntimeException.getInstance("该车位暂未发车,请发车后再领取权益");
+			}
+			GoodsDonSku goodsDonSku = goodsDonSkuMapper.selectById(skuId);
+			if (goodsDonSku == null || !goodsDonSku.getGoodsId().equals(goodsId)) {
+				throw BusinessRuntimeException.getInstance("");
+			}
+			//删除可领取的权益
+			int update = availableBenefitsMapper.update(null, Wrappers.lambdaUpdate(UserPayEquipmentAvailableBenefits.class)
+					.set(UserPayEquipmentAvailableBenefits::getDeleted, false)
+					.eq(UserPayEquipmentAvailableBenefits::getDeleted, true)
+					.eq(UserPayEquipmentAvailableBenefits::getId, benefitsId));
+			if (update != 1) {
+				throw BusinessRuntimeException.getInstance("系统错误,请刷新页面重试");
+			}
+			DateTime updateExpiryTime = DateUtil.offset(expiryTime, DateField.MONTH, goodsDonSku.getMonths());
+			groupsRelationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
+					.eq(GroupsRelation::getId, groupsRelationView.getId())
+					.eq(GroupsRelation::getUserId, userId)
+					.set(GroupsRelation::getExpiryTime, updateExpiryTime));
+			groupsRelationView.setUpdateExpiryTime(updateExpiryTime);
+			//保存领取权益
+			saveReceiveBenefitsRecord(userId, skuId, availableBenefits.getRealOrderId(), null, relationId, goodsDonSku.getMonths(), 1);
+		}, () -> {
+			throw BusinessRuntimeException.getInstance("对应规格车票不存在");
+		});
+		return groupsRelationView;
+	}
+
 	/**
 	 * 保存获取权益记录
 	 */

+ 5 - 2
netflix-web/src/main/java/com/cyksj/web/controller/manage/distribute/DistributeController.java

@@ -64,6 +64,8 @@ public class DistributeController {
 
 	private final GoodsDonSkuMapper goodsDonSkuMapper;
 
+	private final HttpServletRequest request;
+
 	/**
 	 * 添加固定推广者
 	 */
@@ -133,8 +135,9 @@ public class DistributeController {
 	 * 获取平台分销比例
 	 */
 	@GetMapping("/get/plat")
-	public Result<List<GoodsDon>> getGoodsDistributeRate() {
-		return GatewayResponse.SUCCESS.newBuilder().toResult(goodsDonMapper.selectList(Wrappers.lambdaQuery(GoodsDon.class).eq(GoodsDon::getType, 1).eq(GoodsDon::getDeleted, true).orderByAsc(GoodsDon::getId).select(GoodsDon::getId, GoodsDon::getTitle, GoodsDon::getRate)));
+	public Result<SearchResult<GoodsDon>> getGoodsDistributeRate() {
+		SearchResult<GoodsDon> search = beanSearcher.search(GoodsDon.class, MapUtils.flatBuilder(request.getParameterMap()).field(GoodsDon::getDeleted, true).build());
+		return GatewayResponse.SUCCESS.newBuilder().toResult(search);
 	}
 
 	/**

+ 25 - 1
netflix-web/src/main/java/com/cyksj/web/controller/user/UserController.java

@@ -12,14 +12,19 @@ import com.cyksj.model.entity.CouponUser;
 import com.cyksj.model.entity.OrderDon;
 import com.cyksj.model.entity.User;
 import com.cyksj.model.entity.UserBindPhone;
+import com.cyksj.model.manage.views.GroupsRelationView;
 import com.cyksj.model.request.ExchangeCodeTicket;
+import com.cyksj.model.request.ReceiveBenefitsReq;
 import com.cyksj.model.views.RenewalView;
 import com.cyksj.model.views.UserPersonalView;
 import com.cyksj.service.exchange.ExchangeCodeService;
+import com.cyksj.service.order.UserRealOrderBenefitsService;
 import com.cyksj.service.relation.GroupRelationFrontService;
 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.List;
@@ -45,8 +50,10 @@ public class UserController {
 
     private final UserBindPhoneMapper userBindPhoneMapper;
 
+    private final UserRealOrderBenefitsService userRealOrderBenefitsService;
+
     @GetMapping(value = "/wx/whoami")
-    public Result<UserWhoami> whoami(){
+    public Result<UserWhoami> whoami() {
         long userId = StpUserUtil.getLoginIdAsLong();
 
         UserWhoami userWhoami = userService.whoami(userId);
@@ -98,4 +105,21 @@ public class UserController {
         }
         return GatewayResponse.SUCCESS.newBuilder().toResult(personalView);
     }
+
+    /**
+     * 用户已有实物权益 可选车票
+     */
+    @GetMapping("/get/")
+
+    /**
+     * 用户领取实物权益
+     */
+    @PostMapping("/receive/benefits")
+    public Result<GroupsRelationView> receiveRealGoodsBenefits(@RequestBody @Validated ReceiveBenefitsReq req) {
+        Long benefitsId = req.getBenefitsId(), goodsId = req.getGoodsId(), skuId = req.getSkuId(), relationId = req.getRelationId();
+        Long userId = StpUserUtil.getLoginIdAsLong();
+        Assert.notNull(benefitsId, "可获取的权益不存在");
+        GroupsRelationView groupsRelationView = userRealOrderBenefitsService.receiveRealGoodsBenefits(userId, benefitsId, goodsId, skuId, relationId);
+        return GatewayResponse.SUCCESS.newBuilder().toResult(groupsRelationView);
+    }
 }