|
|
@@ -0,0 +1,238 @@
|
|
|
+package com.cyksj.web.controller.manage.distribute;
|
|
|
+
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
+import com.cyksj.dto.Result;
|
|
|
+import com.cyksj.enums.GatewayResponse;
|
|
|
+import com.cyksj.mapper.GoodsDonMapper;
|
|
|
+import com.cyksj.mapper.OrderDonMapper;
|
|
|
+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.UserDistributeMapper;
|
|
|
+import com.cyksj.model.entity.*;
|
|
|
+import com.cyksj.model.request.DistributeApplyMoneyReq;
|
|
|
+import com.cyksj.model.request.UserDistributeReq;
|
|
|
+import com.cyksj.model.views.DistributeMoneyApplyView;
|
|
|
+import com.cyksj.model.views.MoneyApplyView;
|
|
|
+import com.cyksj.model.views.UserDistributeView;
|
|
|
+import com.cyksj.model.views.UserDistributeViews;
|
|
|
+import com.cyksj.service.distribute.DistributeService;
|
|
|
+import com.ejlchina.searcher.BeanSearcher;
|
|
|
+import com.ejlchina.searcher.SearchResult;
|
|
|
+import com.ejlchina.searcher.param.Operator;
|
|
|
+import com.ejlchina.searcher.util.MapUtils;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.validation.constraints.NotNull;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Optional;
|
|
|
+
|
|
|
+/*
|
|
|
+ *项目名: netflix
|
|
|
+ *文件名: DistributeController
|
|
|
+ *创建者: JavaZou
|
|
|
+ *创建时间:2022/11/14 12:06
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/manage/distribute")
|
|
|
+@RequiredArgsConstructor
|
|
|
+@Slf4j
|
|
|
+public class DistributeController {
|
|
|
+
|
|
|
+ private final DistributeService distributeService;
|
|
|
+
|
|
|
+ private final UserDistributeMapper userDistributeMapper;
|
|
|
+
|
|
|
+ private final BeanSearcher beanSearcher;
|
|
|
+
|
|
|
+ private final OrderDonMapper orderDonMapper;
|
|
|
+
|
|
|
+ private final DistributeMoneyApplyMapper distributeMoneyApplyMapper;
|
|
|
+
|
|
|
+ private final DistributePointsExchangeMoneyMapper distributePointsExchangeMoneyMapper;
|
|
|
+
|
|
|
+ private final GoodsDonMapper goodsDonMapper;
|
|
|
+
|
|
|
+ private final UserMapper userMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加固定推广者
|
|
|
+ */
|
|
|
+ @PostMapping
|
|
|
+ public Result<String> saveDistributes(@RequestBody @NotNull UserDistributeReq userDistributeReq) {
|
|
|
+ distributeService.insertDistribute(userDistributeReq);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult("添加成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除固定推广者
|
|
|
+ */
|
|
|
+ @DeleteMapping("/del/{id}")
|
|
|
+ public Result<String> deleteDistributesById(@PathVariable Long id) {
|
|
|
+ if (id == null || id < 1) {
|
|
|
+ throw BusinessRuntimeException.getInstance("id不存在");
|
|
|
+ }
|
|
|
+ userDistributeMapper.deleteById(id);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult("删除成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 推广者编辑
|
|
|
+ */
|
|
|
+ @PutMapping
|
|
|
+ public Result<String> editDistribute(@RequestBody UserDistributeReq userDistributeReq) {
|
|
|
+ distributeService.editDistribute(userDistributeReq);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult("编辑成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 固定推广者详情
|
|
|
+ */
|
|
|
+ @GetMapping("/get/detail/{id}")
|
|
|
+ public Result<List<UserDistributeView>> getDetailById(@PathVariable Long id) {
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(beanSearcher.searchAll(UserDistributeView.class, MapUtils.builder()
|
|
|
+ .field(UserDistributeView::getDistribute_id, id).op(Operator.Equal)
|
|
|
+ .orderBy(UserDistributeView::getGoodsId).asc()
|
|
|
+ .build()));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 固定推广者列表
|
|
|
+ */
|
|
|
+ @GetMapping
|
|
|
+ public Result<SearchResult<UserDistributeViews>> distributeList(HttpServletRequest request) {
|
|
|
+ SearchResult<UserDistributeViews> search = beanSearcher.search(UserDistributeViews.class, MapUtils.flatBuilder(request.getParameterMap()).build());
|
|
|
+ DistributePointsExchangeMoney pointsMoneyRate = distributePointsExchangeMoneyMapper.selectOne(null);
|
|
|
+ Optional.ofNullable(search.getDataList()).ifPresent(list -> list.forEach(view -> {
|
|
|
+ BigDecimal num = view.getPoints().divide(BigDecimal.valueOf(pointsMoneyRate.getPoints()), RoundingMode.DOWN);
|
|
|
+ view.setAvailableMoney(pointsMoneyRate.getMoney().multiply(num));
|
|
|
+ List<DistributeMoneyApply> moneyApplies = distributeMoneyApplyMapper.selectList(Wrappers.lambdaQuery(DistributeMoneyApply.class).eq(DistributeMoneyApply::getVerifyStatus, DistributeMoneyApply.Status.success).eq(DistributeMoneyApply::getUserId, view.getUserId()).select(DistributeMoneyApply::getMoney));
|
|
|
+ Optional<BigDecimal> money = moneyApplies.stream().map(apply -> apply.getMoney()).reduce(BigDecimal::add);
|
|
|
+ view.setGotMoney(money.isPresent() ? money.get() : BigDecimal.ZERO);
|
|
|
+ Integer orders = userDistributeMapper.count(view.getUserId());
|
|
|
+ view.setOrders(orders);
|
|
|
+ }));
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取平台分销比例
|
|
|
+ */
|
|
|
+ @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)));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 平台分销比例修改
|
|
|
+ */
|
|
|
+ @PutMapping("/put/goods/rate")
|
|
|
+ public Result<String> editGoodsDistributeRate(@RequestBody UserDistributeReq userDistributeReq) {
|
|
|
+ for (UserPlatDistributeRate rate : userDistributeReq.getRates()) {
|
|
|
+ if (rate.getRate() < 0 || rate.getRate() > 100) {
|
|
|
+ throw new BusinessRuntimeException("比例错误");
|
|
|
+ }
|
|
|
+ GoodsDon goodsDon = goodsDonMapper.selectById(rate.getGoodsId());
|
|
|
+ if (goodsDon == null || goodsDon.getType() == 2) {
|
|
|
+ throw new BusinessRuntimeException("平台错误");
|
|
|
+ }
|
|
|
+ goodsDon.setRate(rate.getRate());
|
|
|
+ goodsDonMapper.updateById(goodsDon);
|
|
|
+ }
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult("编辑成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 提现title
|
|
|
+ */
|
|
|
+ @GetMapping("/get/applyMoney/title")
|
|
|
+ public Result<MoneyApplyView> applyMoneyTitle() {
|
|
|
+ MoneyApplyView moneyApplyView = new MoneyApplyView();
|
|
|
+ moneyApplyView.setThreshold(distributePointsExchangeMoneyMapper.selectOne(null));
|
|
|
+ List<DistributeMoneyApply> distributeMoneyApplies = distributeMoneyApplyMapper.selectList(Wrappers.lambdaQuery(DistributeMoneyApply.class).eq(DistributeMoneyApply::getVerifyStatus, DistributeMoneyApply.Status.success).select(DistributeMoneyApply::getMoney));
|
|
|
+ Optional<BigDecimal> reduce = distributeMoneyApplies.stream().map(DistributeMoneyApply::getMoney).reduce(BigDecimal::add);
|
|
|
+ moneyApplyView.setGotMoney(reduce.isPresent() ? reduce.get() : BigDecimal.ZERO);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(moneyApplyView);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 提现列表
|
|
|
+ */
|
|
|
+ @GetMapping("/get/applyMoney/list")
|
|
|
+ public Result<SearchResult<DistributeMoneyApplyView>> applyMoneyList(HttpServletRequest request) {
|
|
|
+ SearchResult<DistributeMoneyApplyView> search = beanSearcher.search(DistributeMoneyApplyView.class, MapUtils.flatBuilder(request.getParameterMap()).build());
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 提现审核
|
|
|
+ */
|
|
|
+ @PutMapping("/verify/applyMoney")
|
|
|
+ public Result<String> verifyApplyMoney(@RequestBody @Validated DistributeApplyMoneyReq distributeApplyMoneyReq) {
|
|
|
+ DistributeMoneyApply.Status status = DistributeMoneyApply.Status.checkStatus(distributeApplyMoneyReq.getVerifyStatus());
|
|
|
+ if (status == null || status == DistributeMoneyApply.Status.verifying) {
|
|
|
+ throw BusinessRuntimeException.getInstance("审核状态错误");
|
|
|
+ }
|
|
|
+ DistributeMoneyApply distributeMoneyApply = distributeMoneyApplyMapper.selectById(distributeApplyMoneyReq.getId());
|
|
|
+ if (distributeMoneyApply == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("提现记录不存在");
|
|
|
+ }
|
|
|
+ if (distributeMoneyApply.getVerifyStatus() != DistributeMoneyApply.Status.verifying) {
|
|
|
+ throw BusinessRuntimeException.getInstance("该提现记录已处理,无法再进行审核");
|
|
|
+ }
|
|
|
+ distributeMoneyApply.setVerifyStatus(status);
|
|
|
+ if (DistributeMoneyApply.Status.fail.name().equals(distributeApplyMoneyReq.getVerifyStatus()) && StrUtil.isEmpty(distributeApplyMoneyReq.getReason())) {
|
|
|
+ throw BusinessRuntimeException.getInstance("拒绝原因为空");
|
|
|
+ }
|
|
|
+ if (DistributeMoneyApply.Status.fail.name().equals(distributeApplyMoneyReq.getVerifyStatus())) {
|
|
|
+ distributeMoneyApply.setReason(distributeApplyMoneyReq.getReason());
|
|
|
+ while (true) {
|
|
|
+ User user = userMapper.selectById(distributeMoneyApply.getUserId());
|
|
|
+ if (user == null) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ BigDecimal points = user.getPoints();
|
|
|
+ Integer update = userMapper.updatePoints(user.getId(), points, distributeMoneyApply.getPoints());
|
|
|
+ if (update == 1) {
|
|
|
+ log.info("归还积分:{}至用户{}结束", distributeMoneyApply.getPoints(), user.getId());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (DistributeMoneyApply.Status.success.name().equals(distributeApplyMoneyReq.getVerifyStatus())) {
|
|
|
+ if (StrUtil.isBlank(distributeApplyMoneyReq.getImg())) {
|
|
|
+ throw BusinessRuntimeException.getInstance("审核成功时,打款图片不存在");
|
|
|
+ }
|
|
|
+ distributeMoneyApply.setImg(distributeApplyMoneyReq.getImg());
|
|
|
+ }
|
|
|
+ distributeMoneyApplyMapper.updateById(distributeMoneyApply);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult("审核操作成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 审核成功,编辑打款截图
|
|
|
+ */
|
|
|
+ @PutMapping("/verify/applyMoney/img")
|
|
|
+ public Result<String> putApplyMoneyImg(@RequestBody @Validated DistributeApplyMoneyReq distributeApplyMoneyReq) {
|
|
|
+ DistributeMoneyApply entity = distributeMoneyApplyMapper.selectById(distributeApplyMoneyReq.getId());
|
|
|
+ if (entity == null || entity.getVerifyStatus() != DistributeMoneyApply.Status.success) {
|
|
|
+ throw BusinessRuntimeException.getInstance("审核记录错误");
|
|
|
+ }
|
|
|
+ if (StrUtil.isBlank(distributeApplyMoneyReq.getImg())) {
|
|
|
+ throw BusinessRuntimeException.getInstance("打款截图为空");
|
|
|
+ }
|
|
|
+ DistributeMoneyApply apply = new DistributeMoneyApply();
|
|
|
+ apply.setImg(distributeApplyMoneyReq.getImg());
|
|
|
+ apply.setId(distributeApplyMoneyReq.getId());
|
|
|
+ distributeMoneyApplyMapper.updateById(apply);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult("编辑成功");
|
|
|
+ }
|
|
|
+}
|