|
@@ -0,0 +1,173 @@
|
|
|
|
|
+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.manage.distribute.DistributeMoneyApplyMapper;
|
|
|
|
|
+import com.cyksj.mapper.manage.distribute.DistributePointsExchangeMoneyMapper;
|
|
|
|
|
+import com.cyksj.mapper.manage.distribute.UserDistributeMapper;
|
|
|
|
|
+import com.cyksj.model.entity.DistributeMoneyApply;
|
|
|
|
|
+import com.cyksj.model.entity.DistributePointsExchangeMoney;
|
|
|
|
|
+import com.cyksj.model.entity.GoodsDon;
|
|
|
|
|
+import com.cyksj.model.entity.UserPlatDistributeRate;
|
|
|
|
|
+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.UserDistributeViews;
|
|
|
|
|
+import com.cyksj.service.distribute.DistributeService;
|
|
|
|
|
+import com.ejlchina.searcher.BeanSearcher;
|
|
|
|
|
+import com.ejlchina.searcher.SearchResult;
|
|
|
|
|
+import com.ejlchina.searcher.util.MapUtils;
|
|
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
+
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
+import javax.validation.constraints.NotNull;
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Optional;
|
|
|
|
|
+
|
|
|
|
|
+/*
|
|
|
|
|
+ *项目名: netflix
|
|
|
|
|
+ *文件名: DistributeController
|
|
|
|
|
+ *创建者: JavaZou
|
|
|
|
|
+ *创建时间:2022/11/14 12:06
|
|
|
|
|
+ */
|
|
|
|
|
+@RestController
|
|
|
|
|
+@RequestMapping("/manage/distribute")
|
|
|
|
|
+@RequiredArgsConstructor
|
|
|
|
|
+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;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 添加固定推广者
|
|
|
|
|
+ */
|
|
|
|
|
+ @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
|
|
|
|
|
+ public 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->{
|
|
|
|
|
+ Integer num = view.getPoints() / pointsMoneyRate.getPoints();
|
|
|
|
|
+ view.setAvailableMoney(pointsMoneyRate.getMoney().multiply(new BigDecimal(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 search;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取平台分销比例
|
|
|
|
|
+ */
|
|
|
|
|
+ @GetMapping("/get/plat")
|
|
|
|
|
+ public Result<List<GoodsDon>> getGoodsDistributeRate() {
|
|
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(goodsDonMapper.selectList(Wrappers.lambdaQuery(GoodsDon.class).eq(GoodsDon::getType, 1).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("编辑成功");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 提现列表
|
|
|
|
|
+ */
|
|
|
|
|
+ @GetMapping("/get/applyMoney/list")
|
|
|
|
|
+ public Result<MoneyApplyView> applyMoneyList(HttpServletRequest request) {
|
|
|
|
|
+ MoneyApplyView moneyApplyView = new MoneyApplyView();
|
|
|
|
|
+ SearchResult<DistributeMoneyApplyView> search = beanSearcher.search(DistributeMoneyApplyView.class, MapUtils.flatBuilder(request.getParameterMap()).build());
|
|
|
|
|
+ moneyApplyView.setDetails(search.getDataList());
|
|
|
|
|
+ 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);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 提现审核
|
|
|
|
|
+ */
|
|
|
|
|
+ @PutMapping("/verify/applyMoney")
|
|
|
|
|
+ public Result<String> verifyApplyMoney(@RequestBody @NotNull DistributeApplyMoneyReq distributeApplyMoneyReq) {
|
|
|
|
|
+ DistributeMoneyApply.Status status = DistributeMoneyApply.Status.checkStatus(distributeApplyMoneyReq.getVerifyStatus());
|
|
|
|
|
+ if (status == null) {
|
|
|
|
|
+ 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("拒绝原因为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ distributeMoneyApplyMapper.updateById(distributeMoneyApply);
|
|
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult("审核操作成功");
|
|
|
|
|
+ }
|
|
|
|
|
+}
|