DistributePopularizeController.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. package com.cyksj.web.controller.user;
  2. import cn.hutool.core.date.DateTime;
  3. import cn.hutool.core.date.DateUtil;
  4. import cn.hutool.core.util.ObjectUtil;
  5. import cn.hutool.core.util.StrUtil;
  6. import cn.hutool.extra.qrcode.QrCodeUtil;
  7. import cn.hutool.extra.qrcode.QrConfig;
  8. import com.alipay.api.AlipayResponse;
  9. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  10. import com.cyksj.common.EnvCommonService;
  11. import com.cyksj.common.annotation.NoSubmit;
  12. import com.cyksj.common.constant.Constant;
  13. import com.cyksj.common.exception.BusinessRuntimeException;
  14. import com.cyksj.common.i18n.I18nMessageUtil;
  15. import com.cyksj.common.util.SmsUtil;
  16. import com.cyksj.common.util.ValidatorUtil;
  17. import com.cyksj.dto.Result;
  18. import com.cyksj.enums.GatewayResponse;
  19. import com.cyksj.mapper.GoodsDonMapper;
  20. import com.cyksj.mapper.GoodsDonSkuMapper;
  21. import com.cyksj.mapper.OrderDonMapper;
  22. import com.cyksj.mapper.UserMapper;
  23. import com.cyksj.mapper.manage.coupon.CouponDistributePopularizeMapper;
  24. import com.cyksj.mapper.manage.coupon.CouponMapper;
  25. import com.cyksj.mapper.manage.distribute.DistributeMoneyApplyMapper;
  26. import com.cyksj.mapper.manage.distribute.DistributePointsExchangeMoneyMapper;
  27. import com.cyksj.mapper.manage.distribute.DistributeWaitingSendPointsMapper;
  28. import com.cyksj.mapper.manage.distribute.UserDistributeMapper;
  29. import com.cyksj.model.entity.*;
  30. import com.cyksj.model.request.ApplyMoneyReq;
  31. import com.cyksj.model.request.TransferAccountsReq;
  32. import com.cyksj.model.views.*;
  33. import com.cyksj.service.distribute.DistributeService;
  34. import com.cyksj.service.order.OrderDonService;
  35. import com.cyksj.service.user.UserBenefitsService;
  36. import com.cyksj.service.user.UserService;
  37. import com.cyksj.web.util.StpUserUtil;
  38. import com.ejlchina.searcher.BeanSearcher;
  39. import com.ejlchina.searcher.SearchResult;
  40. import com.ejlchina.searcher.param.Operator;
  41. import com.ejlchina.searcher.util.MapUtils;
  42. import lombok.RequiredArgsConstructor;
  43. import org.springframework.transaction.annotation.Transactional;
  44. import org.springframework.web.bind.annotation.*;
  45. import javax.servlet.http.HttpServletRequest;
  46. import java.math.BigDecimal;
  47. import java.math.RoundingMode;
  48. import java.util.List;
  49. import java.util.Map;
  50. import java.util.Optional;
  51. import java.util.stream.Collectors;
  52. /*
  53. *项目名: netflix
  54. *文件名: DistributePopularizeController
  55. *创建者: JavaZou
  56. *创建时间:2022/11/15 13:59
  57. * 服务端-》我的分发推广controller
  58. */
  59. @RestController
  60. @RequestMapping("/distribute/popularize")
  61. @RequiredArgsConstructor
  62. public class DistributePopularizeController {
  63. private final EnvCommonService envCommonService;
  64. private final UserMapper userMapper;
  65. private final UserService userService;
  66. private final BeanSearcher beanSearcher;
  67. private final GoodsDonMapper goodsDonMapper;
  68. private final GoodsDonSkuMapper goodsDonSkuMapper;
  69. private final DistributePointsExchangeMoneyMapper distributePointsExchangeMoneyMapper;
  70. private final DistributeMoneyApplyMapper distributeMoneyApplyMapper;
  71. private final UserDistributeMapper userDistributeMapper;
  72. private final DistributeWaitingSendPointsMapper distributeWaitingSendPointsMapper;
  73. private final OrderDonMapper orderDonMapper;
  74. private final OrderDonService orderService;
  75. private final UserBenefitsService userBenefitsService;
  76. private final DistributeService distributeService;
  77. private final CouponDistributePopularizeMapper couponDistributePopularizeMapper;
  78. private final CouponMapper couponMapper;
  79. /**
  80. * 推广订单明细
  81. */
  82. @GetMapping("/orders/detail")
  83. public Result<SearchResult<DistributePopularizeOrdersView>> getOrdersView(HttpServletRequest request) {
  84. Long userId = StpUserUtil.getLoginIdAsLong();
  85. SearchResult<DistributePopularizeOrdersView> search = beanSearcher.search(DistributePopularizeOrdersView.class,
  86. MapUtils.flatBuilder(request.getParameterMap())
  87. .field(DistributePopularizeOrdersView::getSharedId, userId)
  88. .build());
  89. DistributePointsExchangeMoney distributePointsExchangeMoney = distributePointsExchangeMoneyMapper.selectOne(Wrappers.lambdaQuery(DistributePointsExchangeMoney.class).orderByDesc(DistributePointsExchangeMoney::getPoints).last("limit 1"));
  90. BigDecimal points = BigDecimal.valueOf(distributePointsExchangeMoney.getPoints());
  91. BigDecimal money = distributePointsExchangeMoney.getMoney();
  92. BigDecimal oneHundred = BigDecimal.valueOf(100);
  93. search.getDataList().forEach(data -> {
  94. GoodsDon goodsDon = goodsDonMapper.selectById(data.getGoodsId());
  95. GoodsDonSku goodsDonSku = goodsDonSkuMapper.selectById(data.getSkuId());
  96. data.setGoodsTitle(goodsDon.getTitle());
  97. data.setSpecVal(goodsDonSku.getSpecVal());
  98. data.setWaitGetMoney(data.getPoints().divide(points).multiply(money).divide(oneHundred));
  99. });
  100. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  101. }
  102. /**
  103. * 提现明细
  104. */
  105. @GetMapping("/applyMoney/detail")
  106. public Result<SearchResult<DistributeMoneyApplyView>> getApplyMoneyView(HttpServletRequest request) {
  107. Long userId = StpUserUtil.getLoginIdAsLong();
  108. SearchResult<DistributeMoneyApplyView> search = beanSearcher.search(DistributeMoneyApplyView.class,
  109. MapUtils.flatBuilder(request.getParameterMap())
  110. .field(DistributeMoneyApplyView::getUserId, userId).op(Operator.Equal)
  111. .build());
  112. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  113. }
  114. /**
  115. * 个人推广详情
  116. */
  117. @GetMapping("/get/detail")
  118. public Result<DistributePopularizeView> getDetail() {
  119. Long userId = StpUserUtil.getLoginIdAsLong();
  120. User user = userMapper.selectById(userId);
  121. if (StrUtil.isEmpty(user.getShowId())) {
  122. user.setShowId(userService.getUserShowId(userId));
  123. }
  124. DistributePopularizeView distributePopularizeView = new DistributePopularizeView();
  125. String dsUrl = String.format(envCommonService.DISTRIBUTE_DEFAULT_URL_PREFIX, user.getShowId());
  126. // distributePopularizeView.setUrl(String.format("https://%s/8081/api/auth/weChat?url=https://%s/yinhe/web&sharedId=%s", domain, domain, userId));
  127. distributePopularizeView.setUrl(dsUrl);
  128. distributePopularizeView.setUrlCode(QrCodeUtil.generateAsBase64(distributePopularizeView.getUrl(), QrConfig.create(), "png"));
  129. distributePopularizeView.setGotPoints(user.getPoints());
  130. Integer orders = userDistributeMapper.count(userId);
  131. distributePopularizeView.setDistributeOrders(orders);
  132. UserDistribute userDistribute = userDistributeMapper.selectOne(Wrappers.lambdaQuery(UserDistribute.class).eq(UserDistribute::getUserId, userId).select(UserDistribute::getId).last("limit 1"));
  133. if (userDistribute != null) {
  134. //是否是固定推广者
  135. UserDistributeView userDistributeView = beanSearcher.searchFirst(UserDistributeView.class, MapUtils.builder()
  136. .field(UserDistributeView::getDistribute_id, userDistribute.getId()).op(Operator.Equal)
  137. .orderBy(UserDistributeView::getRate).desc()
  138. .build());
  139. //最高平台比例
  140. distributePopularizeView.setHighestRate(userDistributeView.getRate());
  141. } else {
  142. GoodsDon goodsDon = goodsDonMapper.selectOne(Wrappers.lambdaQuery(GoodsDon.class).eq(GoodsDon::getDeleted, true).eq(GoodsDon::getStatus, true).orderByDesc(GoodsDon::getRate).select(GoodsDon::getRate).last("limit 1"));
  143. distributePopularizeView.setIsGeneral(true);
  144. distributePopularizeView.setHighestRate(goodsDon.getRate());
  145. Optional.ofNullable(couponDistributePopularizeMapper.selectOne(Wrappers.lambdaQuery(CouponDistributePopularize.class)
  146. .eq(CouponDistributePopularize::getUserId, userId)
  147. .eq(CouponDistributePopularize::getIsGeneral, true)
  148. .last("limit 1")))
  149. .ifPresent(couponPopularize -> {
  150. Coupon coupon = couponMapper.getCouponById(couponPopularize.getCouponId());
  151. distributePopularizeView.setGeneralCode(couponPopularize.getExCode());
  152. BigDecimal discount = coupon.getDiscount();
  153. String discountStr = String.format("%s折", discount.multiply(BigDecimal.valueOf(100)).intValue());
  154. distributePopularizeView.setGeneralDiscount(discountStr);
  155. });
  156. }
  157. List<DistributeWaitingSendPoints> distributeWaitingSendPoints = distributeWaitingSendPointsMapper.selectList(Wrappers.lambdaQuery(DistributeWaitingSendPoints.class).eq(DistributeWaitingSendPoints::getSendStatus, DistributeWaitingSendPoints.Status.waiting).eq(DistributeWaitingSendPoints::getSharedId, userId).select(DistributeWaitingSendPoints::getPoints));
  158. BigDecimal waitingPoints = BigDecimal.ZERO;
  159. if (!distributeWaitingSendPoints.isEmpty()) {
  160. Optional<BigDecimal> points = distributeWaitingSendPoints.stream().map(DistributeWaitingSendPoints::getPoints).reduce(BigDecimal::add);
  161. if (points.isPresent()) {
  162. waitingPoints = points.get();
  163. }
  164. }
  165. distributePopularizeView.setWaitingSendPoints(waitingPoints);
  166. if (user.getPoints().compareTo(BigDecimal.ZERO) <= 0 && waitingPoints.compareTo(BigDecimal.ZERO) <= 0) {
  167. distributePopularizeView.setGotMoney(BigDecimal.ZERO);
  168. distributePopularizeView.setWaitingMoney(BigDecimal.ZERO);
  169. }else {
  170. DistributePointsExchangeMoney distributePointsExchangeMoney = distributePointsExchangeMoneyMapper.selectOne(Wrappers.lambdaQuery(DistributePointsExchangeMoney.class).orderByDesc(DistributePointsExchangeMoney::getPoints).last("limit 1"));
  171. BigDecimal points = BigDecimal.valueOf(distributePointsExchangeMoney.getPoints());
  172. BigDecimal money = distributePointsExchangeMoney.getMoney();
  173. BigDecimal oneHundred = BigDecimal.valueOf(100);
  174. if (user.getPoints().compareTo(BigDecimal.ZERO) >= 0) {
  175. distributePopularizeView.setGotMoney(user.getPoints().divide(points).multiply(money).divide(oneHundred));
  176. }
  177. if (user.getPoints().compareTo(BigDecimal.ZERO) >= 0) {
  178. distributePopularizeView.setWaitingMoney(waitingPoints.divide(points).multiply(money).divide(oneHundred));
  179. }
  180. }
  181. return GatewayResponse.SUCCESS.newBuilder().toResult(distributePopularizeView);
  182. }
  183. /**
  184. * 个人推广用户每日订单情况折线图
  185. */
  186. @GetMapping("/get/order/brokenLine")
  187. public Result<BrokenLineObjView> getPersonDistributeBrokenLineView(Long firstDate, Long lastDate) {
  188. Long userId = StpUserUtil.getLoginIdAsLong();
  189. String first = null;
  190. String end = null;
  191. if (firstDate != null) {
  192. first = DateUtil.format(DateTime.of(firstDate), "yyyy-MM-dd");
  193. }
  194. if (lastDate != null) {
  195. end = DateUtil.format(DateTime.of(lastDate), "yyyy-MM-dd");
  196. }
  197. BrokenLineObjView brokenLineObjView = Optional.ofNullable(orderDonMapper.selectPersonDistributeBrokenLine(userId, first, end))
  198. .orElse(new BrokenLineObjView());
  199. if (brokenLineObjView != null) {
  200. List<PersonDistributeBrokenLineView> views = beanSearcher.searchAll(PersonDistributeBrokenLineView.class, MapUtils.builder()
  201. .field(PersonDistributeBrokenLineView::getDate, first, end).op(Operator.Between)
  202. .put("userId", String.format("dw.shared_id = %s", userId))
  203. .orderBy(PersonDistributeBrokenLineView::getDate).asc()
  204. .build());
  205. Map<Long, List<PersonDistributeBrokenLineView>> distributeMap = views.stream().collect(Collectors.groupingBy(PersonDistributeBrokenLineView::getGoodsId));
  206. brokenLineObjView.setDistributeData(distributeMap);
  207. }
  208. return GatewayResponse.SUCCESS.newBuilder().toResult(brokenLineObjView);
  209. }
  210. /**
  211. * 提现
  212. */
  213. @NoSubmit
  214. @PostMapping("/post/applyMoney")
  215. @Transactional(rollbackFor = Throwable.class)
  216. public Result<DistributeMoneyApply> applyMoney(@RequestBody ApplyMoneyReq applyMoneyReq) throws Exception {
  217. Long userId = StpUserUtil.getLoginIdAsLong();
  218. User user = userMapper.selectById(userId);
  219. if (user == null) {
  220. throw BusinessRuntimeException.getInstance(I18nMessageUtil.getI18nMsg("login_code_expired"));
  221. }
  222. Boolean isTakeAll = applyMoneyReq.getIsTakeAll();
  223. DistributeMoneyApply.Type type = applyMoneyReq.getType();
  224. if (type == null) type = DistributeMoneyApply.Type.zfb;
  225. if (type == DistributeMoneyApply.Type.zfb) {
  226. if (ObjectUtil.hasEmpty(applyMoneyReq.getAccount(), applyMoneyReq.getRealName())) {
  227. throw BusinessRuntimeException.getInstance(I18nMessageUtil.getI18nMsg("params_error"));
  228. }
  229. if (applyMoneyReq.getAccount().length() > 255 || applyMoneyReq.getRealName().length() > 32) {
  230. throw BusinessRuntimeException.getInstance(I18nMessageUtil.getI18nMsg("distribute_apply_money_account_error"));
  231. }
  232. }
  233. if (type == DistributeMoneyApply.Type.usdt) {
  234. if (StrUtil.isEmpty(applyMoneyReq.getWalletAddr())) {
  235. throw BusinessRuntimeException.getInstance(I18nMessageUtil.getI18nMsg("distribute_apply_money_usdt_address_error"));
  236. }
  237. if (applyMoneyReq.getWalletAddr().length() > 1000) {
  238. throw BusinessRuntimeException.getInstance(I18nMessageUtil.getI18nMsg("distribute_apply_money_usdt_address_error"));
  239. }
  240. if (StrUtil.isNotBlank(applyMoneyReq.getRemark()) && applyMoneyReq.getRemark().length() > 512) {
  241. throw BusinessRuntimeException.getInstance(I18nMessageUtil.getI18nMsg("distribute_apply_money_remark_length_error"));
  242. }
  243. isTakeAll = true;
  244. }
  245. DistributeMoneyApply distributeMoneyApply = null;
  246. if (type == DistributeMoneyApply.Type.pwdRed) {
  247. distributeMoneyApply = userDistributeMapper.selectRelationBusiness(userId);
  248. isTakeAll = true;
  249. }
  250. BigDecimal userPoints = user.getPoints();
  251. DistributePointsExchangeMoney distributePointsExchangeMoney = distributePointsExchangeMoneyMapper.selectOne(Wrappers.lambdaQuery(DistributePointsExchangeMoney.class).orderByDesc(DistributePointsExchangeMoney::getPoints).last("limit 1"));
  252. BigDecimal minPoints = BigDecimal.valueOf(distributePointsExchangeMoney.getMinPoints());
  253. BigDecimal ratePoints = BigDecimal.valueOf(distributePointsExchangeMoney.getPoints());
  254. BigDecimal minMoney = distributePointsExchangeMoney.getMoney();
  255. if (userPoints.compareTo(minPoints) < 0) {
  256. throw BusinessRuntimeException.getInstance(I18nMessageUtil.getI18nMsg("distribute_apply_money_thresholds_error"));
  257. }
  258. // //今日是否已提现
  259. // 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"));
  260. // if (apply != null) {
  261. // throw BusinessRuntimeException.getInstance("今日已提现,请明日再进行操作");
  262. // }
  263. BigDecimal num = userPoints.divide(ratePoints, 0, RoundingMode.DOWN);
  264. BigDecimal needApplyMoney = num.multiply(minMoney);
  265. BigDecimal needSubPoints = num.multiply(ratePoints);
  266. BigDecimal fourHundred = BigDecimal.valueOf(4 * 100 * 100);
  267. if (isTakeAll == null || !isTakeAll) {
  268. if (needApplyMoney.compareTo(fourHundred) > 0) {
  269. needApplyMoney = fourHundred;
  270. needSubPoints = fourHundred.divide(minMoney).multiply(ratePoints);
  271. }
  272. }
  273. Integer update = userMapper.subPoints(user.getId(), needSubPoints);
  274. if (update == 1) {
  275. distributeMoneyApply = Optional.ofNullable(distributeMoneyApply).orElse(new DistributeMoneyApply());
  276. distributeMoneyApply.setUserId(userId);
  277. distributeMoneyApply.setPoints(needSubPoints);
  278. distributeMoneyApply.setMoney(needApplyMoney);
  279. distributeMoneyApply.setAccount(applyMoneyReq.getAccount());
  280. distributeMoneyApply.setRealName(applyMoneyReq.getRealName());
  281. distributeMoneyApply.setWalletAddr(applyMoneyReq.getWalletAddr());
  282. distributeMoneyApply.setRemark(applyMoneyReq.getRemark());
  283. distributeMoneyApply.setType(applyMoneyReq.getType());
  284. if (isTakeAll != null && isTakeAll) {
  285. distributeMoneyApply.setVerifyStatus(DistributeMoneyApply.Status.verifying);
  286. } else {
  287. TransferAccountsReq req = new TransferAccountsReq();
  288. req.setMoney(needApplyMoney);
  289. req.setAccount(applyMoneyReq.getAccount());
  290. req.setName(applyMoneyReq.getRealName());
  291. req.setPoints(needSubPoints);
  292. req.setUserId(userId);
  293. AlipayResponse alipayResponse = orderService.transferAccounts(req);
  294. if (alipayResponse.isSuccess()) {
  295. distributeMoneyApply.setVerifyStatus(DistributeMoneyApply.Status.success);
  296. } else {
  297. distributeMoneyApply.setVerifyStatus(DistributeMoneyApply.Status.fail);
  298. distributeMoneyApply.setReason(alipayResponse.getSubMsg());
  299. userBenefitsService.addDistributePoints(userId, distributeMoneyApply.getPoints());
  300. if (StrUtil.equals(alipayResponse.getSubCode(), "SECURITY_CHECK_FAILED")) {
  301. return GatewayResponse.FAIL.newBuilder().setMsg("当前支付宝提现人数较多,请稍后再试").toResult();
  302. }
  303. return GatewayResponse.FAIL.newBuilder().setMsg(alipayResponse.getSubMsg()).toResult();
  304. }
  305. }
  306. try {
  307. distributeMoneyApplyMapper.insert(distributeMoneyApply);
  308. //大额提现 超过400
  309. if (distributeMoneyApply.getVerifyStatus() == DistributeMoneyApply.Status.verifying && distributeMoneyApply.getMoney().compareTo(fourHundred) > 0) {
  310. SmsUtil.sendLuoKey2Msg(Constant.ZK_MOBILE, "海外推广有大额提现申请【银河录像局】");
  311. }
  312. } catch (Exception e) {
  313. userBenefitsService.addDistributePoints(userId, distributeMoneyApply.getPoints());
  314. return GatewayResponse.FAIL.newBuilder().setMsg(I18nMessageUtil.getI18nMsg("sys_error")).toResult();
  315. }
  316. return GatewayResponse.SUCCESS.newBuilder().toResult(distributeMoneyApply);
  317. }
  318. throw BusinessRuntimeException.getInstance(I18nMessageUtil.getI18nMsg("sys_error"));
  319. }
  320. /**
  321. * 获取积分兑换门槛
  322. */
  323. @GetMapping("/applyMoney/threshold")
  324. public Result<DistributePointsExchangeMoney> getThreshold() {
  325. return GatewayResponse.SUCCESS.newBuilder().toResult(distributePointsExchangeMoneyMapper.selectOne(Wrappers.lambdaQuery(DistributePointsExchangeMoney.class).last("limit 1")));
  326. }
  327. /**
  328. * 提现缓存数据
  329. */
  330. @GetMapping("/get/applyMoney/detail")
  331. public Result<DistributeMoneyApply> getLastApplyDetail() {
  332. Long userId = StpUserUtil.getLoginIdAsLong();
  333. DistributeMoneyApply apply = distributeMoneyApplyMapper.selectOne(Wrappers.lambdaQuery(DistributeMoneyApply.class).eq(DistributeMoneyApply::getUserId, userId).orderByDesc(DistributeMoneyApply::getId).last("limit 1"));
  334. return GatewayResponse.SUCCESS.newBuilder().toResult(apply);
  335. }
  336. /**
  337. * 是否是普通分销者
  338. */
  339. @GetMapping("/get/isGeneral/distribute")
  340. public Result<Boolean> isGeneralDistribute() {
  341. Long userId = StpUserUtil.getLoginIdAsLong();
  342. UserDistribute userDistribute = userDistributeMapper.selectOne(Wrappers.lambdaQuery(UserDistribute.class)
  343. .eq(UserDistribute::getUserId, userId));
  344. if (userDistribute != null) {
  345. return GatewayResponse.SUCCESS.newBuilder().toResult(false);
  346. }
  347. return GatewayResponse.SUCCESS.newBuilder().toResult(true);
  348. }
  349. /**
  350. * 普通分销者弹窗
  351. */
  352. @GetMapping("/get/general/distribute/detail")
  353. public Result<DistributePopularizeView> getGeneralDistributeDetail() {
  354. Long userId = StpUserUtil.getLoginIdAsLong();
  355. List<GoodsDon> goodsDons = goodsDonMapper.selectList(Wrappers.lambdaQuery(GoodsDon.class).eq(GoodsDon::getDeleted, true).gt(GoodsDon::getRate, 0).orderByAsc(GoodsDon::getRate).select(GoodsDon::getRate, GoodsDon::getTitle));
  356. if (goodsDons.isEmpty()) {
  357. return GatewayResponse.SUCCESS.newBuilder().toResult();
  358. }
  359. DistributePopularizeView distributePopularizeView = new DistributePopularizeView();
  360. GoodsDon highestRateGoods = goodsDons.get(goodsDons.size() - 1);
  361. distributePopularizeView.setHighestRate(highestRateGoods.getRate());
  362. List<GoodsDon> generalDistributes = goodsDons.stream().filter(gd -> !gd.getRate().equals(highestRateGoods.getRate())).collect(Collectors.toList());
  363. distributePopularizeView.setGeneralDistributes(generalDistributes);
  364. return GatewayResponse.SUCCESS.newBuilder().toResult(distributePopularizeView);
  365. }
  366. /**
  367. * 设置普通推广码
  368. * 绑定个人专属码
  369. */
  370. @PostMapping("/general/code/{code}")
  371. public Result<String> setGeneralCode(@PathVariable("code") String code) {
  372. long userId = StpUserUtil.getLoginIdAsLong();
  373. if (StrUtil.isBlank(code)) {
  374. throw BusinessRuntimeException.getInstance("专属推广优惠码不能为空");
  375. }
  376. if (!ValidatorUtil.isEnNum(code) || code.length() > 20) {
  377. throw BusinessRuntimeException.getInstance("请输入英文数字组合的专属推广优惠码");
  378. }
  379. code = code.trim();
  380. distributeService.bindPopularizeCode(userId, code);
  381. return GatewayResponse.SUCCESS.newBuilder().toResult("设置成功");
  382. }
  383. }