|
|
@@ -1,5 +1,8 @@
|
|
|
package com.cyksj.web.controller.user;
|
|
|
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.extra.qrcode.QrCodeUtil;
|
|
|
import cn.hutool.extra.qrcode.QrConfig;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
@@ -13,12 +16,14 @@ import com.cyksj.mapper.GoodsDonSkuMapper;
|
|
|
import com.cyksj.mapper.UserMapper;
|
|
|
import com.cyksj.mapper.manage.distribute.DistributeMoneyApplyMapper;
|
|
|
import com.cyksj.mapper.manage.distribute.DistributePointsExchangeMoneyMapper;
|
|
|
+import com.cyksj.mapper.manage.distribute.DistributeWaitingSendPointsMapper;
|
|
|
+import com.cyksj.mapper.manage.distribute.UserDistributeMapper;
|
|
|
import com.cyksj.model.entity.*;
|
|
|
+import com.cyksj.model.request.ApplyMoneyReq;
|
|
|
import com.cyksj.model.views.DistributeMoneyApplyView;
|
|
|
-import com.cyksj.model.views.DistributeOrdersView;
|
|
|
import com.cyksj.model.views.DistributePopularizeOrdersView;
|
|
|
import com.cyksj.model.views.DistributePopularizeView;
|
|
|
-import com.cyksj.redis.RedisService;
|
|
|
+import com.cyksj.model.views.UserDistributeView;
|
|
|
import com.cyksj.web.util.StpUserUtil;
|
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
|
import com.ejlchina.searcher.SearchResult;
|
|
|
@@ -26,13 +31,13 @@ import com.ejlchina.searcher.param.Operator;
|
|
|
import com.ejlchina.searcher.util.MapUtils;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Optional;
|
|
|
|
|
|
/*
|
|
|
*项目名: netflix
|
|
|
@@ -59,31 +64,40 @@ public class DistributePopularizeController {
|
|
|
|
|
|
private final DistributeMoneyApplyMapper distributeMoneyApplyMapper;
|
|
|
|
|
|
- private final RedisService redisService;
|
|
|
+ private final UserDistributeMapper userDistributeMapper;
|
|
|
+
|
|
|
+ private final DistributeWaitingSendPointsMapper distributeWaitingSendPointsMapper;
|
|
|
|
|
|
/**
|
|
|
* 推广订单明细
|
|
|
*/
|
|
|
@GetMapping("/orders/detail")
|
|
|
- public SearchResult<DistributePopularizeOrdersView> getOrdersView() {
|
|
|
+ public Result<SearchResult<DistributePopularizeOrdersView>> getOrdersView(HttpServletRequest request) {
|
|
|
Long userId = StpUserUtil.getLoginIdAsLong();
|
|
|
SearchResult<DistributePopularizeOrdersView> search = beanSearcher.search(DistributePopularizeOrdersView.class,
|
|
|
- MapUtils.builder().field(DistributePopularizeOrdersView::getSharedId, userId).build());
|
|
|
+ MapUtils.flatBuilder(request.getParameterMap())
|
|
|
+ .field(DistributePopularizeOrdersView::getSharedId, userId)
|
|
|
+ .build());
|
|
|
search.getDataList().forEach(data -> {
|
|
|
GoodsDon goodsDon = goodsDonMapper.selectById(data.getGoodsId());
|
|
|
GoodsDonSku goodsDonSku = goodsDonSkuMapper.selectById(data.getSkuId());
|
|
|
data.setGoodsTitle(goodsDon.getTitle());
|
|
|
data.setSpecVal(goodsDonSku.getSpecVal());
|
|
|
});
|
|
|
- return search;
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 提现明细
|
|
|
*/
|
|
|
@GetMapping("/applyMoney/detail")
|
|
|
- public SearchResult<DistributeMoneyApplyView> getApplyMoneyView() {
|
|
|
- return beanSearcher.search(DistributeMoneyApplyView.class, null);
|
|
|
+ public Result<SearchResult<DistributeMoneyApplyView>> getApplyMoneyView(HttpServletRequest request) {
|
|
|
+ Long userId = StpUserUtil.getLoginIdAsLong();
|
|
|
+ SearchResult<DistributeMoneyApplyView> search = beanSearcher.search(DistributeMoneyApplyView.class,
|
|
|
+ MapUtils.flatBuilder(request.getParameterMap())
|
|
|
+ .field(DistributeMoneyApplyView::getUserId, userId).op(Operator.Equal)
|
|
|
+ .build());
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -94,12 +108,35 @@ public class DistributePopularizeController {
|
|
|
Long userId = StpUserUtil.getLoginIdAsLong();
|
|
|
DistributePopularizeView distributePopularizeView = new DistributePopularizeView();
|
|
|
String domain = envCommonService.getHost();
|
|
|
- distributePopularizeView.setUrl(String.format("https://%s/8081/api/auth/weChat?url=https://%s/yinhe/web?sharedId=%s", domain, domain, userId));
|
|
|
+// distributePopularizeView.setUrl(String.format("https://%s/8081/api/auth/weChat?url=https://%s/yinhe/web&sharedId=%s", domain, domain, userId));
|
|
|
+ distributePopularizeView.setUrl(String.format("https://%s/yinhe/web?sharedId=%s", domain, userId));
|
|
|
distributePopularizeView.setUrlCode(QrCodeUtil.generateAsBase64(distributePopularizeView.getUrl(), QrConfig.create(), "png"));
|
|
|
User user = userMapper.selectById(userId);
|
|
|
distributePopularizeView.setGotPoints(user.getPoints());
|
|
|
- Number number = beanSearcher.searchCount(DistributeOrdersView.class, MapUtils.builder().field(DistributeOrdersView::getUserId, userId).op(Operator.Equal).build());
|
|
|
- distributePopularizeView.setDistributeOrders(number.intValue());
|
|
|
+ Integer orders = userDistributeMapper.count(userId);
|
|
|
+ distributePopularizeView.setDistributeOrders(orders);
|
|
|
+ UserDistribute userDistribute = userDistributeMapper.selectOne(Wrappers.lambdaQuery(UserDistribute.class).eq(UserDistribute::getUserId, userId).select(UserDistribute::getId).last("limit 1"));
|
|
|
+ if (userDistribute != null) {
|
|
|
+ //是否是固定推广者
|
|
|
+ UserDistributeView userDistributeView = beanSearcher.searchFirst(UserDistributeView.class, MapUtils.builder()
|
|
|
+ .field(UserDistributeView::getDistribute_id, userDistribute.getId()).op(Operator.Equal)
|
|
|
+ .orderBy(UserDistributeView::getRate).desc()
|
|
|
+ .build());
|
|
|
+ //最高平台比例
|
|
|
+ distributePopularizeView.setHighestRate(userDistributeView.getRate());
|
|
|
+ }else {
|
|
|
+ GoodsDon goodsDon = goodsDonMapper.selectOne(Wrappers.lambdaQuery(GoodsDon.class).orderByDesc(GoodsDon::getRate).select(GoodsDon::getRate).last("limit 1"));
|
|
|
+ distributePopularizeView.setHighestRate(goodsDon.getRate());
|
|
|
+ }
|
|
|
+ List<DistributeWaitingSendPoints> distributeWaitingSendPoints = distributeWaitingSendPointsMapper.selectList(Wrappers.lambdaQuery(DistributeWaitingSendPoints.class).eq(DistributeWaitingSendPoints::getSendStatus, DistributeWaitingSendPoints.Status.waiting).eq(DistributeWaitingSendPoints::getSharedId, userId).select(DistributeWaitingSendPoints::getPoints));
|
|
|
+ BigDecimal waitingPoints = BigDecimal.ZERO;
|
|
|
+ if (!distributeWaitingSendPoints.isEmpty()) {
|
|
|
+ Optional<BigDecimal> points = distributeWaitingSendPoints.stream().map(DistributeWaitingSendPoints::getPoints).reduce(BigDecimal::add);
|
|
|
+ if (points.isPresent()) {
|
|
|
+ waitingPoints = points.get();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ distributePopularizeView.setWaitingSendPoints(waitingPoints);
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(distributePopularizeView);
|
|
|
}
|
|
|
|
|
|
@@ -109,29 +146,58 @@ public class DistributePopularizeController {
|
|
|
@NoSubmit
|
|
|
@PostMapping("/post/applyMoney")
|
|
|
@Transactional(rollbackFor = Throwable.class)
|
|
|
- public Result<String> applyMoney() {
|
|
|
+ public Result<Integer> applyMoney(@RequestBody ApplyMoneyReq applyMoneyReq) {
|
|
|
Long userId = StpUserUtil.getLoginIdAsLong();
|
|
|
User user = userMapper.selectById(userId);
|
|
|
if (user == null) {
|
|
|
throw BusinessRuntimeException.getInstance("请先授权登录");
|
|
|
}
|
|
|
+ if (ObjectUtil.hasEmpty(applyMoneyReq.getAccount(), applyMoneyReq.getRealName())) {
|
|
|
+ throw BusinessRuntimeException.getInstance("必填项不能为空");
|
|
|
+ }
|
|
|
DistributePointsExchangeMoney distributePointsExchangeMoney = distributePointsExchangeMoneyMapper.selectOne(Wrappers.lambdaQuery(DistributePointsExchangeMoney.class).orderByDesc(DistributePointsExchangeMoney::getPoints).last("limit 1"));
|
|
|
+ BigDecimal minPoints = BigDecimal.valueOf(distributePointsExchangeMoney.getMinPoints());
|
|
|
BigDecimal min = BigDecimal.valueOf(distributePointsExchangeMoney.getPoints());
|
|
|
- if (user.getPoints().compareTo(min) < 0) {
|
|
|
- throw BusinessRuntimeException.getInstance("您当前积分不够,无法提现");
|
|
|
+ if (user.getPoints().compareTo(minPoints) < 0) {
|
|
|
+ throw BusinessRuntimeException.getInstance("您当前积分未达到积分门槛,无法提现");
|
|
|
+ }
|
|
|
+ //今日是否已提现
|
|
|
+ DistributeMoneyApply apply = distributeMoneyApplyMapper.selectOne(Wrappers.lambdaQuery(DistributeMoneyApply.class).eq(DistributeMoneyApply::getUserId, userId).between(DistributeMoneyApply::getCreatedTime, DateUtil.beginOfDay(DateTime.now()), DateUtil.endOfDay(DateTime.now())).last("limit 1"));
|
|
|
+ if (apply != null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("今日已提现,请明日再进行操作");
|
|
|
}
|
|
|
BigDecimal num = user.getPoints().divide(min, RoundingMode.DOWN);
|
|
|
- int points = min.multiply(num).intValue();
|
|
|
+ BigDecimal points = min.multiply(num);
|
|
|
Integer update = userMapper.subPoints(user.getId(), points);
|
|
|
if (update == 1) {
|
|
|
DistributeMoneyApply distributeMoneyApply = new DistributeMoneyApply();
|
|
|
distributeMoneyApply.setUserId(userId);
|
|
|
distributeMoneyApply.setPoints(points);
|
|
|
distributeMoneyApply.setMoney(num.multiply(distributePointsExchangeMoney.getMoney()));
|
|
|
- distributeMoneyApply.setVerifyStatus(DistributeMoneyApply.Status.Verifying);
|
|
|
+ distributeMoneyApply.setVerifyStatus(DistributeMoneyApply.Status.verifying);
|
|
|
+ distributeMoneyApply.setAccount(applyMoneyReq.getAccount());
|
|
|
+ distributeMoneyApply.setRealName(applyMoneyReq.getRealName());
|
|
|
distributeMoneyApplyMapper.insert(distributeMoneyApply);
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult("申请提现成功,待客服审核打款");
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(distributeMoneyApply.getMoney().intValue());
|
|
|
}
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult("系统异常,请重新提交提现申请");
|
|
|
+ throw BusinessRuntimeException.getInstance("系统异常,请重新提交提现申请");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取积分兑换门槛
|
|
|
+ */
|
|
|
+ @GetMapping("/applyMoney/threshold")
|
|
|
+ public Result<DistributePointsExchangeMoney> getThreshold() {
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(distributePointsExchangeMoneyMapper.selectOne(Wrappers.lambdaQuery(DistributePointsExchangeMoney.class).last("limit 1")));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 提现缓存数据
|
|
|
+ */
|
|
|
+ @GetMapping("/get/applyMoney/detail")
|
|
|
+ public Result<DistributeMoneyApply> getLastApplyDetail() {
|
|
|
+ Long userId = StpUserUtil.getLoginIdAsLong();
|
|
|
+ DistributeMoneyApply apply = distributeMoneyApplyMapper.selectOne(Wrappers.lambdaQuery(DistributeMoneyApply.class).eq(DistributeMoneyApply::getUserId, userId).orderByDesc(DistributeMoneyApply::getId).last("limit 1"));
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(apply);
|
|
|
}
|
|
|
-}
|
|
|
+}
|