UserController.java 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  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.StrUtil;
  5. import cn.hutool.core.util.URLUtil;
  6. import cn.hutool.extra.servlet.ServletUtil;
  7. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  8. import com.cyksj.common.annotation.NoSubmit;
  9. import com.cyksj.common.exception.BusinessRuntimeException;
  10. import com.cyksj.common.util.Jsons;
  11. import com.cyksj.dto.Result;
  12. import com.cyksj.enums.GatewayApiCode;
  13. import com.cyksj.enums.GatewayResponse;
  14. import com.cyksj.mapper.*;
  15. import com.cyksj.mapper.manage.coupon.CouponUserMapper;
  16. import com.cyksj.mapper.manage.distribute.*;
  17. import com.cyksj.mapper.mirrorshop.UserMirrorShopMapper;
  18. import com.cyksj.model.dto.UserWhoami;
  19. import com.cyksj.model.entity.*;
  20. import com.cyksj.model.manage.views.GroupsRelationView;
  21. import com.cyksj.model.request.*;
  22. import com.cyksj.model.response.UserAuthLoginResp;
  23. import com.cyksj.model.views.*;
  24. import com.cyksj.service.corp.CorpInteractiveReaderFrontService;
  25. import com.cyksj.service.corp.CropChatService;
  26. import com.cyksj.service.exchange.ExchangeCodeService;
  27. import com.cyksj.service.order.UserRealOrderBenefitsService;
  28. import com.cyksj.service.shop.YhShopFrontService;
  29. import com.cyksj.service.user.UserBindRelationService;
  30. import com.cyksj.service.user.UserService;
  31. import com.cyksj.service.user.WorkOrderFrontService;
  32. import com.cyksj.web.util.StpUserUtil;
  33. import com.ejlchina.searcher.BeanSearcher;
  34. import com.ejlchina.searcher.SearchResult;
  35. import com.ejlchina.searcher.param.Operator;
  36. import com.ejlchina.searcher.util.MapBuilder;
  37. import com.ejlchina.searcher.util.MapUtils;
  38. import lombok.RequiredArgsConstructor;
  39. import org.springframework.dao.DuplicateKeyException;
  40. import org.springframework.util.Assert;
  41. import org.springframework.validation.annotation.Validated;
  42. import org.springframework.web.bind.annotation.*;
  43. import javax.servlet.http.HttpServletRequest;
  44. import java.math.BigDecimal;
  45. import java.util.ArrayList;
  46. import java.util.List;
  47. import java.util.stream.Collectors;
  48. /**
  49. * @author chan
  50. * @date 2021/10/11 下午11:05
  51. */
  52. @RequestMapping("/applets/user")
  53. @RestController
  54. @RequiredArgsConstructor
  55. public class UserController {
  56. private final UserService userService;
  57. private final ExchangeCodeService exchangeCodeService;
  58. private final CouponUserMapper couponUserMapper;
  59. private final OrderDonMapper orderDonMapper;
  60. private final UserRealOrderBenefitsService userRealOrderBenefitsService;
  61. private final BeanSearcher beanSearcher;
  62. private final WorkOrderFrontService workOrderFrontService;
  63. private final HttpServletRequest request;
  64. private final CropChatService cropChatService;
  65. private final UserBindRelationService userBindRelationService;
  66. private final YhShopFrontService yhShopFrontService;
  67. private final CorpInteractiveReaderFrontService corpInteractiveReaderFrontService;
  68. private final UserPlatSkuDistributeRateMapper userPlatSkuDistributeRateMapper;
  69. private final UserPlatDistributeRateMapper userPlatDistributeRateMapper;
  70. private final DistributeGeneralSkuRateMapper distributeGeneralSkuRateMapper;
  71. private final GoodsDonSkuMapper skuMapper;
  72. private final UserDistributeMapper userDistributeMapper;
  73. private final UserDistributePosterRecordMapper userDistributePosterRecordMapper;
  74. private final DistributePosterGoodsMapper distributePosterGoodsMapper;
  75. private final UserIpRecordMapper userIpRecordMapper;
  76. private final BusinessDistributeDefaultRateConfigMapper businessDistributeDefaultRateConfigMapper;
  77. private final BusinessDistributeDefaultSkuRateConfigMapper businessDistributeDefaultSkuRateConfigMapper;
  78. private final UserMirrorShopMapper userMirrorShopMapper;
  79. private final UserGalaxyCoinRecordMapper userGalaxyCoinRecordMapper;
  80. @GetMapping(value = "/wx/whoami")
  81. public Result<UserWhoami> whoami(Long popularizeGoodsId) {
  82. long userId = StpUserUtil.getLoginIdAsLong();
  83. UserWhoami userWhoami = userService.whoami(userId, popularizeGoodsId);
  84. return GatewayResponse.SUCCESS.newBuilder().toResult(userWhoami);
  85. }
  86. /**
  87. * 兑换码兑换车票
  88. */
  89. @PostMapping("/get/ticket")
  90. public Result<String> getTicketByExchangeCode(@RequestBody ExchangeCodeTicket exchangeCodeTicket) throws Exception {
  91. Long userId = StpUserUtil.getLoginIdAsLong();
  92. return exchangeCodeService.getTicketByExchangeCode(exchangeCodeTicket, userId);
  93. }
  94. /**
  95. * 车票兑换码详情
  96. */
  97. @GetMapping("/get/ticket/code/detail")
  98. public Result<ExchangeCodeDetailView> getTicketCodeDetail(String code) throws Exception {
  99. code = URLUtil.decode(code);
  100. ExchangeCodeDetailView exchangeCodeDetailView = beanSearcher.searchFirst(ExchangeCodeDetailView.class, MapUtils.flatBuilder(request.getParameterMap()).field(ExchangeCodeDetailView::getCode, code).build());
  101. if (exchangeCodeDetailView == null) {
  102. throw BusinessRuntimeException.getInstance("错误兑换码");
  103. }
  104. List<Long> skuIds = Jsons.parseList(exchangeCodeDetailView.getSkuIds(), Long.class);
  105. exchangeCodeDetailView.setSkuDetails(skuMapper.selectExchangeTitleSkus(skuIds));
  106. return GatewayResponse.SUCCESS.newBuilder().toResult(exchangeCodeDetailView);
  107. }
  108. /**
  109. * 个人中心详情
  110. */
  111. @GetMapping("/personal")
  112. public Result<UserPersonalView> getPersonalView(String customId, Integer cmt) {
  113. long userId = StpUserUtil.getLoginIdAsLong();
  114. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  115. String userIds = userIdList.toString().replace("[", "(").replace("]", ")");
  116. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  117. if (cmt != null && cmt == 2 && StrUtil.isNotBlank(customId)) {
  118. UserMirrorShop userMirrorShop = userMirrorShopMapper.selectOne(Wrappers.lambdaQuery(UserMirrorShop.class)
  119. .eq(UserMirrorShop::getCustomId, customId)
  120. .last("limit 1"));
  121. if (userMirrorShop != null) {
  122. builder.field(RenewalView::getCmt, cmt).field(RenewalView::getYhsId, userMirrorShop.getId());
  123. }
  124. }
  125. if (cmt == null || cmt != 2) {
  126. // SQL NULL does not satisfy `<> 2`; keep legacy platform tickets visible
  127. // while still excluding mirror-shop tickets (cmt = 2).
  128. builder.field(RenewalView::getCmt).sql("$1 is null or $1 <> ?", 2);
  129. }
  130. List<RenewalView> renewalViews = beanSearcher.searchAll(RenewalView.class, builder
  131. .field(RenewalView::getUserId, 0).op(Operator.GreaterThan)
  132. .field(RenewalView::getUserId, userIdList).op(Operator.InList)
  133. .field(RenewalView::getStatus, List.of("validity", "overdue", "outside")).op(Operator.InList)
  134. .field(RenewalView::getIsVip, false)
  135. .orderBy(RenewalView::getExpiryTime).asc()
  136. .onlySelect(RenewalView::getExpiryTime)
  137. .build());
  138. DateTime now = DateTime.now();
  139. UserPersonalView personalView = new UserPersonalView();
  140. personalView.setTotalOfTickets(renewalViews.size());
  141. renewalViews = renewalViews.stream().filter(e -> {
  142. if (e.getExpiryTime() != null && e.getExpiryTime().before(now)) {
  143. return false;
  144. }
  145. return true;
  146. }).collect(Collectors.toList());
  147. //车票
  148. personalView.setNumOfTickets(renewalViews.size());
  149. //优惠券 需要排除已删除/后台失效的优惠券
  150. Integer couponSize = couponUserMapper.selectAvailableCoupons(userId, CouponUser.Status.unused, now);
  151. personalView.setNumOfCoupons(couponSize);
  152. //积分
  153. User user = userService.getById(userId);
  154. personalView.setGalaxyCoin(user.getGalaxyCoin());
  155. //30天内即将过期银河币数量
  156. BigDecimal expiredGalaxyCoinAfterDays = userGalaxyCoinRecordMapper.selectExpiredGalaxyCoinAfterDays(userId, DateUtil.offsetDay(now, -30));
  157. personalView.setExpiredGalaxyCoin(expiredGalaxyCoinAfterDays);
  158. //推广积分
  159. personalView.setPopularizePoints(user.getPoints());
  160. personalView.setBalance(user.getBalance());
  161. OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
  162. .eq(OrderDon::getUserId, userId)
  163. .eq(OrderDon::getStatus, OrderDon.Status.noPayment).last("limit 1"));
  164. personalView.setIsNoPayment(orderDon != null ? true : false);
  165. //礼品卡可用数量
  166. Number numOfGiftCard = beanSearcher.searchCount(GiftCardUserRecordView.class, MapUtils.builder()
  167. .put("uid", String.format("((user_id in %s and is_send = 0) or (to_user_id in %s and is_used = 0))", userIds, userIds))
  168. .field(GiftCardUserRecordView::getIsPay, true)
  169. .build());
  170. personalView.setNumOfGiftCard(numOfGiftCard.intValue());
  171. return GatewayResponse.SUCCESS.newBuilder().toResult(personalView);
  172. }
  173. /**
  174. * 用户已有实物权益 可选车票
  175. */
  176. @GetMapping("/get/available/benefits/tickets")
  177. public Result<List<UserAvailableGoodsTicketView>> getAvailableBenefitsTickets(Long orderId, String customId, Integer cmt) {
  178. Long userId = StpUserUtil.getLoginIdAsLong();
  179. List<UserAvailableGoodsTicketView> tickets = userRealOrderBenefitsService.getAvailableBenefitsTickets(userId, orderId, customId, cmt);
  180. return GatewayResponse.SUCCESS.newBuilder().toResult(tickets);
  181. }
  182. /**
  183. * 用户领取实物权益
  184. */
  185. @PostMapping("/receive/benefits")
  186. public Result<List<GroupsRelationView>> receiveRealGoodsBenefits(@RequestBody List<ReceiveBenefitsReq> reqList) {
  187. List<GroupsRelationView> re = new ArrayList<>();
  188. Long userId = StpUserUtil.getLoginIdAsLong();
  189. reqList.forEach(req -> {
  190. Long benefitsId = req.getBenefitsId(), goodsId = req.getGoodsId(), skuId = req.getSkuId(), relationId = req.getRelationId();
  191. Assert.notNull(benefitsId, "可获取的权益不存在");
  192. Assert.notNull(goodsId, "请选择对应平台");
  193. Assert.notNull(skuId, "请选择对应权益规格");
  194. Assert.notNull(relationId, "请选择对应车票");
  195. GroupsRelationView groupsRelationView = userRealOrderBenefitsService.receiveRealGoodsBenefits(userId, benefitsId, goodsId, skuId, relationId);
  196. re.add(groupsRelationView);
  197. });
  198. return GatewayResponse.SUCCESS.newBuilder().toResult(re);
  199. }
  200. /**
  201. * 用户提交工单
  202. */
  203. @PostMapping("/workOrder/submit")
  204. @NoSubmit
  205. public Result<String> submitWorkOrder(@RequestBody @Validated WorkOrderReq workOrderReq) {
  206. long userId = StpUserUtil.getLoginIdAsLong();
  207. workOrderReq.setUserId(userId);
  208. workOrderFrontService.submitWorkOrder(workOrderReq);
  209. return GatewayResponse.SUCCESS.newBuilder().toResult();
  210. }
  211. /**
  212. * 用户工单历史列表
  213. */
  214. @GetMapping("/workOrder/get")
  215. public Result<SearchResult<UserWorkOrderView>> getWorkOrder(String customId) {
  216. Long yhsId = yhShopFrontService.getYhsIdByCustomId(customId);
  217. long userId = StpUserUtil.getLoginIdAsLong();
  218. SearchResult<UserWorkOrderView> search = beanSearcher.search(UserWorkOrderView.class, MapUtils.flatBuilder(request.getParameterMap())
  219. .field(UserWorkOrderView::getUserId, userId)
  220. .field(UserWorkOrderView::getYhsId, yhsId)
  221. .orderBy(UserWorkOrderView::getCreatedTime).desc()
  222. .build());
  223. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  224. }
  225. /**
  226. * 用户工单详情
  227. */
  228. @GetMapping("/workOrder/get/detail/{id}")
  229. public Result<SearchResult<WorkOrderChatHistoryView>> getWorkOrderDetails(@PathVariable Long id) {
  230. long userId = StpUserUtil.getLoginIdAsLong();
  231. SearchResult<WorkOrderChatHistoryView> search = beanSearcher.search(WorkOrderChatHistoryView.class, MapUtils.builder()
  232. .field(WorkOrderChatHistoryView::getUserId, userId)
  233. .field(WorkOrderChatHistoryView::getWorkOrderId, id)
  234. .orderBy(WorkOrderChatHistoryView::getId).desc()
  235. .selectExclude(WorkOrderChatHistoryView::getReplyCustomerServiceId,
  236. WorkOrderChatHistoryView::getCustomer)
  237. .build());
  238. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  239. }
  240. /**
  241. * 工单状态查询
  242. */
  243. @GetMapping("/workOrder/get/status/{id}")
  244. public Result<WorkOrder> getWorkOrderStatus(@PathVariable Long id) {
  245. long userId = StpUserUtil.getLoginIdAsLong();
  246. WorkOrder workOrder = beanSearcher.searchFirst(WorkOrder.class, MapUtils.builder()
  247. .field(WorkOrder::getUserId, userId)
  248. .field(WorkOrder::getId, id)
  249. .onlySelect(WorkOrder::getId, WorkOrder::getUserId, WorkOrder::getStatus)
  250. .build());
  251. if (workOrder == null) {
  252. throw BusinessRuntimeException.getInstance("该工单不存在");
  253. }
  254. return GatewayResponse.SUCCESS.newBuilder().toResult(workOrder);
  255. }
  256. /**
  257. * 用户回复客服
  258. */
  259. @PostMapping("/workOrder/reply")
  260. public Result<String> userReplyWorkOrder(@RequestBody @Validated WorkOrderChatHistory history) {
  261. long userId = StpUserUtil.getLoginIdAsLong();
  262. history.setUserId(userId);
  263. workOrderFrontService.replyCustomer(history);
  264. return GatewayResponse.SUCCESS.newBuilder().toResult();
  265. }
  266. /**
  267. * 修改用户信息
  268. */
  269. @PutMapping("/update/userInfo")
  270. public Result<String> updateHeadImg(@RequestBody UserReq request) {
  271. long userId = StpUserUtil.getLoginIdAsLong();
  272. User user = userService.getById(userId);
  273. if (user == null) throw BusinessRuntimeException.getGatewayApiCode(GatewayApiCode.CMS_TOKEN_VALID);
  274. Boolean isFlag = false;
  275. if (StrUtil.isNotBlank(request.getNickname())) {
  276. if (request.getNickname().length() > 32) {
  277. throw BusinessRuntimeException.getInstance("名称过长");
  278. }
  279. user.setNickname(request.getNickname());
  280. isFlag = true;
  281. }
  282. if (request.getSex() != null) {
  283. user.setSex(request.getSex());
  284. isFlag = true;
  285. }
  286. if (StrUtil.isNotBlank(request.getHeadimgurl())) {
  287. user.setHeadimgurl(request.getHeadimgurl());
  288. isFlag = true;
  289. }
  290. if (isFlag) {
  291. userService.updateById(user);
  292. }
  293. return GatewayResponse.SUCCESS.newBuilder().toResult();
  294. }
  295. /**
  296. * 更新用户最后一次登录时间
  297. */
  298. @PutMapping("/update/lastTime")
  299. public Result<String> updateLastTime() {
  300. long userId = StpUserUtil.getLoginIdAsLong();
  301. User user = userService.getById(userId);
  302. if (user == null) {
  303. return GatewayResponse.SUCCESS.newBuilder().toResult();
  304. }
  305. user.setLastTime(DateTime.now());
  306. userService.updateById(user);
  307. return GatewayResponse.SUCCESS.newBuilder().toResult();
  308. }
  309. /**
  310. * 查看用户所有余额
  311. */
  312. @GetMapping("/get/balance")
  313. public Result<User> getUserBalance() {
  314. long userId = StpUserUtil.getLoginIdAsLong();
  315. User user = userService.getOne(Wrappers.lambdaQuery(User.class)
  316. .eq(User::getId, userId)
  317. .select(User::getNickname, User::getBalance, User::getGalaxyCoin)
  318. .last("limit 1"));
  319. return GatewayResponse.SUCCESS.newBuilder().toResult(user);
  320. }
  321. /**
  322. * 获取群聊二维码
  323. */
  324. @GetMapping("/get/corp/ChatCode/{goodsId}")
  325. public Result<String> getCorpChatCode(@PathVariable Long goodsId) throws Exception {
  326. long userId = StpUserUtil.getLoginIdAsLong();
  327. //获取对应产品的企业微信客户群
  328. String qrCode = cropChatService.getCropWxChatGroupByGoodsId(goodsId);
  329. return GatewayResponse.SUCCESS.newBuilder().toResult(qrCode);
  330. }
  331. /**
  332. * 获取奈飞客服活码弹窗
  333. */
  334. @GetMapping("/get/corp/serviceCode/{goodsId}")
  335. public Result<String> getCorpServiceCode(@PathVariable Long goodsId) {
  336. long userId = StpUserUtil.getLoginIdAsLong();
  337. String qrCode = cropChatService.getCorpServiceCode(goodsId);
  338. return GatewayResponse.SUCCESS.newBuilder().toResult(qrCode);
  339. }
  340. /**
  341. * 用户账号关联列表
  342. */
  343. @GetMapping("/get/userAccounts")
  344. public Result<List<UserBindAccountView>> getUserBindAccountViews() {
  345. long userId = StpUserUtil.getLoginIdAsLong();
  346. List<Long> relationUserIdList = userBindRelationService.getRelationUserIdList(userId, null);
  347. List<UserBindAccountView> accountViews = beanSearcher.searchAll(UserBindAccountView.class, MapUtils.builder().field(UserBindAccountView::getUserId, relationUserIdList)
  348. .op(Operator.InList)
  349. .build());
  350. if (relationUserIdList.size() > 1) {
  351. for (UserBindAccountView accountView : accountViews) {
  352. if (accountView.getUserId().equals(userId)) {
  353. accountViews.remove(accountView);
  354. accountViews.add(0, accountView);
  355. break;
  356. }
  357. }
  358. }
  359. return GatewayResponse.SUCCESS.newBuilder().toResult(accountViews);
  360. }
  361. /**
  362. * 切换账号
  363. */
  364. @PutMapping("/switch/account")
  365. public Result<UserAuthLoginResp> switchOtherAccount(@RequestBody UserBindAccountView request) {
  366. long userId = StpUserUtil.getLoginIdAsLong();
  367. Long switchUserId = request.getUserId();
  368. List<Long> relationUserIdList = userBindRelationService.getRelationUserIdList(userId, null);
  369. if (!relationUserIdList.contains(switchUserId)) {
  370. throw BusinessRuntimeException.getInstance("切换账号异常,请刷新页面重试");
  371. }
  372. User switch_user = userService.getById(switchUserId);
  373. Assert.notNull(switch_user, "切换的账号不存在");
  374. StpUserUtil.login(switch_user.getId());
  375. UserAuthLoginResp loginPhoneRep = new UserAuthLoginResp(StpUserUtil.getTokenValue(), switch_user.getShowId(), switch_user.getNickname(), switch_user.getHeadimgurl());
  376. return GatewayResponse.SUCCESS.newBuilder().toResult(loginPhoneRep);
  377. }
  378. /**
  379. * 个人礼品卡列表
  380. * @return
  381. */
  382. @GetMapping("/get/giftCard")
  383. public Result<SearchResult<GiftCardUserPayFrontView>> getGiftCard() {
  384. long userId = StpUserUtil.getLoginIdAsLong();
  385. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  386. String userIds = userIdList.toString().replace("[", "(").replace("]", ")");
  387. String condition = String.format("and (user_id in %s or to_user_id in %s)", userIds, userIds);
  388. SearchResult<GiftCardUserPayFrontView> view = beanSearcher.search(GiftCardUserPayFrontView.class, MapUtils.flatBuilder(request.getParameterMap())
  389. .put("condition", condition)
  390. .put("uid", userIds)
  391. .orderBy(GiftCardUserRecordView::getIsUsed).asc()
  392. .orderBy(GiftCardUserPayFrontView::getId).desc().build());
  393. return GatewayResponse.SUCCESS.newBuilder().toResult(view);
  394. }
  395. /**
  396. * 可用现金礼品卡列表
  397. */
  398. @GetMapping("/get/available/giftCard")
  399. public Result<List<GiftCardUserPayFrontView>> getAvailGiftCard() {
  400. long userId = StpUserUtil.getLoginIdAsLong();
  401. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  402. String userIds = userIdList.toString().replace("[", "(").replace("]", ")");
  403. String condition = String.format("and to_user_id in %s", userIds);
  404. List<GiftCardUserPayFrontView> view = beanSearcher.searchAll(GiftCardUserPayFrontView.class, MapUtils.builder()
  405. .put("condition", condition)
  406. .put("uid", userIds)
  407. //现金卡
  408. .field(GiftCardUserPayFrontView::getGcType, 1)
  409. .orderBy(GiftCardUserRecordView::getIsUsed).asc()
  410. .orderBy(GiftCardUserPayFrontView::getId).desc().build());
  411. return GatewayResponse.SUCCESS.newBuilder().toResult(view);
  412. }
  413. /**
  414. * 礼品卡分享详情
  415. */
  416. @GetMapping("/get/giftCard/detail/{code}")
  417. public Result<GiftCardDetailFrontView> getGiftCardDetailByCode(@PathVariable String code) {
  418. GiftCardDetailFrontView detail = beanSearcher.searchFirst(GiftCardDetailFrontView.class, MapUtils.builder().field(GiftCardDetailFrontView::getCode, code).build());
  419. return GatewayResponse.SUCCESS.newBuilder().toResult(detail);
  420. }
  421. /**
  422. * 领取他人礼品卡
  423. */
  424. @PostMapping("/receive/giftCard")
  425. public Result<String> receiveGiftCardByRc(@RequestBody GiftCardReceiveReq req) {
  426. long userId = StpUserUtil.getLoginIdAsLong();
  427. Long relationId = req.getRelationId();
  428. userService.receiveGiftCardByRc(userId, req.getCode(), relationId);
  429. return GatewayResponse.SUCCESS.newBuilder().toResult();
  430. }
  431. /**
  432. * 点击雷达链接
  433. */
  434. @PostMapping("/click/reader/{radarId}")
  435. public Result<String> clickInteractiveReader(@PathVariable Long radarId) throws Exception {
  436. long userId = StpUserUtil.getLoginIdAsLong();
  437. corpInteractiveReaderFrontService.clickReader(userId, radarId);
  438. return GatewayResponse.SUCCESS.newBuilder().toResult();
  439. }
  440. /**
  441. * 推广平台海报列表
  442. */
  443. @GetMapping("/get/ds/poster/goods")
  444. public Result<List<DistributePosterGoodsFrontView>> getPosterGoods() {
  445. long userId = StpUserUtil.getLoginIdAsLong();
  446. UserDistribute userDistribute = userDistributeMapper.selectOne(Wrappers.lambdaQuery(UserDistribute.class)
  447. .eq(UserDistribute::getUserId, userId)
  448. .eq(UserDistribute::getDeleted, 1)
  449. .last("limit 1"));
  450. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  451. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  452. List<DistributePosterGoodsFrontView> searchAll = beanSearcher.searchAll(DistributePosterGoodsFrontView.class, builder.build());
  453. searchAll.forEach(e -> {
  454. if (userDistribute != null) {
  455. UserPlatDistributeRate userPlatDistributeRate = userPlatDistributeRateMapper.selectOne(Wrappers.lambdaQuery(UserPlatDistributeRate.class)
  456. .eq(UserPlatDistributeRate::getDistributeId, userDistribute.getId())
  457. .eq(UserPlatDistributeRate::getGoodsId, e.getGoodsId())
  458. .last("limit 1"));
  459. if (userPlatDistributeRate != null) {
  460. e.setRate(userPlatDistributeRate.getRate());
  461. } else {
  462. BusinessDistributeDefaultRateConfig businessDistributeDefaultRateConfig = businessDistributeDefaultRateConfigMapper.selectOne(Wrappers.lambdaQuery(BusinessDistributeDefaultRateConfig.class)
  463. .eq(BusinessDistributeDefaultRateConfig::getGoodsId, e.getGoodsId())
  464. .last("limit 1"));
  465. if (businessDistributeDefaultRateConfig != null) {
  466. e.setRate(businessDistributeDefaultRateConfig.getRate());
  467. }
  468. }
  469. }
  470. if (e.getIsSkuRate()) {
  471. GoodsDonSku sku = skuMapper.selectOne(Wrappers.lambdaQuery(GoodsDonSku.class)
  472. .eq(GoodsDonSku::getGoodsId, e.getGoodsId())
  473. .eq(GoodsDonSku::getStatus, 1)
  474. .orderByAsc(GoodsDonSku::getPrice)
  475. .last("limit 1"));
  476. //先获取价格最低的规格对应的 比例
  477. //渠道
  478. if (userDistribute != null) {
  479. UserPlatSkuDistributeRate minPriceSkuRate = userPlatSkuDistributeRateMapper.selectOne(Wrappers.lambdaQuery(UserPlatSkuDistributeRate.class)
  480. .eq(UserPlatSkuDistributeRate::getDistributeId, userDistribute.getId())
  481. .eq(UserPlatSkuDistributeRate::getGoodsId, e.getGoodsId())
  482. .eq(UserPlatSkuDistributeRate::getSkuId, sku.getId())
  483. .last("limit 1"));
  484. if (minPriceSkuRate != null && minPriceSkuRate.getRate() != 0) {
  485. e.setRate(minPriceSkuRate.getRate());
  486. } else {
  487. UserPlatSkuDistributeRate userPlatSkuDistributeRate = userPlatSkuDistributeRateMapper.selectOne(Wrappers.lambdaQuery(UserPlatSkuDistributeRate.class)
  488. .eq(UserPlatSkuDistributeRate::getDistributeId, userDistribute.getId())
  489. .eq(UserPlatSkuDistributeRate::getGoodsId, e.getGoodsId())
  490. .ne(UserPlatSkuDistributeRate::getRate, 0)
  491. //上架
  492. .apply("exists (select 1 from goods_don_sku sku where sku.id = sku_id and sku.status is true limit 1)")
  493. .orderByAsc(UserPlatSkuDistributeRate::getRate)
  494. .last("limit 1"));
  495. if (userPlatSkuDistributeRate != null) {
  496. e.setRate(userPlatSkuDistributeRate.getRate());
  497. sku = skuMapper.selectById(userPlatSkuDistributeRate.getSkuId());
  498. e.setPrice(sku.getPrice());
  499. } else {
  500. BusinessDistributeDefaultSkuRateConfig businessDistributeDefaultSkuRateConfig = businessDistributeDefaultSkuRateConfigMapper.selectOne(Wrappers.lambdaQuery(BusinessDistributeDefaultSkuRateConfig.class)
  501. .eq(BusinessDistributeDefaultSkuRateConfig::getGoodsId, e.getGoodsId())
  502. .gt(BusinessDistributeDefaultSkuRateConfig::getRate, 0)
  503. .apply("exists (select 1 from goods_don_sku sku where sku.id = sku_id and sku.status is true limit 1)")
  504. .orderByAsc(BusinessDistributeDefaultSkuRateConfig::getRate)
  505. .last("limit 1"));
  506. if (businessDistributeDefaultSkuRateConfig != null) {
  507. e.setRate(businessDistributeDefaultSkuRateConfig.getRate());
  508. }
  509. }
  510. }
  511. } else {
  512. //普通
  513. DistributeGeneralSkuRate minPriceRate = distributeGeneralSkuRateMapper.selectOne(Wrappers.lambdaQuery(DistributeGeneralSkuRate.class)
  514. .eq(DistributeGeneralSkuRate::getGoodsId, e.getGoodsId())
  515. .eq(DistributeGeneralSkuRate::getSkuId, sku.getId())
  516. .last("limit 1"));
  517. if (minPriceRate != null && minPriceRate.getRate() > 0) {
  518. e.setRate(minPriceRate.getRate());
  519. } else {
  520. DistributeGeneralSkuRate distributeGeneralSkuRate = distributeGeneralSkuRateMapper.selectOne(Wrappers.lambdaQuery(DistributeGeneralSkuRate.class)
  521. .eq(DistributeGeneralSkuRate::getGoodsId, e.getGoodsId())
  522. .apply("exists (select 1 from goods_don_sku sku where sku.id = sku_id and sku.status is true limit 1)")
  523. .ne(DistributeGeneralSkuRate::getRate, 0)
  524. .orderByAsc(DistributeGeneralSkuRate::getRate)
  525. .last("limit 1"));
  526. if (distributeGeneralSkuRate != null) {
  527. e.setRate(distributeGeneralSkuRate.getRate());
  528. sku = skuMapper.selectById(distributeGeneralSkuRate.getSkuId());
  529. e.setPrice(sku.getPrice());
  530. }
  531. }
  532. }
  533. }
  534. UserDistributePosterRecord distributePosterRecord = userDistributePosterRecordMapper.selectOne(Wrappers.lambdaQuery(UserDistributePosterRecord.class)
  535. .eq(UserDistributePosterRecord::getPosterId, e.getId())
  536. .in(UserDistributePosterRecord::getUserId, userIdList)
  537. .last("limit 1"));
  538. if (distributePosterRecord != null) {
  539. e.setRid(distributePosterRecord.getId());
  540. } });
  541. return GatewayResponse.SUCCESS.newBuilder().toResult(searchAll);
  542. }
  543. /**
  544. * 海报详情
  545. */
  546. @GetMapping("/get/poster/{goodsId}")
  547. public Result<DistributePosterGoodsFrontView> getPosterDetail(@PathVariable Long goodsId) {
  548. DistributePosterGoodsFrontView distributePosterGoodsView = beanSearcher.searchFirst(DistributePosterGoodsFrontView.class, MapUtils.flatBuilder(request.getParameterMap())
  549. .field(DistributePosterGoodsFrontView::getGoodsId, goodsId)
  550. .build());
  551. return GatewayResponse.SUCCESS.newBuilder().toResult(distributePosterGoodsView);
  552. }
  553. /**
  554. * 用户下载海报记录
  555. */
  556. @PostMapping("/poster/record/{posterId}")
  557. public Result<Long> posterRecord(@PathVariable Long posterId) {
  558. long userId = StpUserUtil.getLoginIdAsLong();
  559. DistributePosterGoods distributePosterGoods = distributePosterGoodsMapper.selectById(posterId);
  560. if (distributePosterGoods == null) {
  561. return GatewayResponse.SUCCESS.newBuilder().toResult();
  562. }
  563. UserDistributePosterRecord distributePosterRecord = new UserDistributePosterRecord();
  564. distributePosterRecord.setPosterId(posterId);
  565. distributePosterRecord.setUserId(userId);
  566. try {
  567. userDistributePosterRecordMapper.insert(distributePosterRecord);
  568. } catch (DuplicateKeyException e) {
  569. distributePosterRecord = userDistributePosterRecordMapper.selectOne(Wrappers.lambdaQuery(UserDistributePosterRecord.class)
  570. .eq(UserDistributePosterRecord::getUserId, userId)
  571. .eq(UserDistributePosterRecord::getPosterId, posterId)
  572. .last("limit 1"));
  573. }
  574. return GatewayResponse.SUCCESS.newBuilder().toResult(distributePosterRecord.getId());
  575. }
  576. /**
  577. * 记录用户ip
  578. */
  579. @PostMapping("/user/ip/record")
  580. public Result<String> recordUserIpAddress() {
  581. long userId = StpUserUtil.getLoginIdAsLong();
  582. String ip = ServletUtil.getClientIP(request);
  583. Integer selectCount = userIpRecordMapper.selectCount(Wrappers.lambdaQuery(UserIpRecord.class)
  584. .eq(UserIpRecord::getUserId, userId)
  585. .eq(UserIpRecord::getIp, ip));
  586. if (selectCount == 0) {
  587. try {
  588. UserIpRecord userIpRecord = new UserIpRecord();
  589. userIpRecord.setUserId(userId);
  590. userIpRecord.setIp(ip);
  591. userIpRecordMapper.insert(userIpRecord);
  592. } catch (DuplicateKeyException e) {
  593. }
  594. }
  595. return GatewayResponse.SUCCESS.newBuilder().toResult();
  596. }
  597. /**
  598. * 用户认证信息总览
  599. */
  600. @GetMapping("/get/cert/overview")
  601. public Result<UserCertInfoView> getCertOverView() {
  602. long userId = StpUserUtil.getLoginIdAsLong();
  603. UserCertInfoView userCertInfoView = userService.getCertOverView(userId);
  604. return GatewayResponse.SUCCESS.newBuilder().toResult(userCertInfoView);
  605. }
  606. /**
  607. * 用户同步功能信息
  608. */
  609. @GetMapping("/get/user/syncInfo")
  610. public Result<UserSyncInfoView> getUserSyncInfo() {
  611. long userId = StpUserUtil.getLoginIdAsLong();
  612. UserSyncInfoView syncInfoView = userService.getUserSyncInfo(userId);
  613. return GatewayResponse.SUCCESS.newBuilder().toResult(syncInfoView);
  614. }
  615. /**
  616. * 注销账号
  617. */
  618. @PutMapping("/revoked/account")
  619. public Result<String> revokedAccount() {
  620. long userId = StpUserUtil.getLoginIdAsLong();
  621. userService.revokedAccount(userId);
  622. return GatewayResponse.SUCCESS.newBuilder().toResult();
  623. }
  624. }