GroupRelationFrontServiceImpl.java 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921
  1. package com.cyksj.service.relation.impl;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.collection.CollectionUtil;
  4. import cn.hutool.core.date.BetweenFormater;
  5. import cn.hutool.core.date.DateTime;
  6. import cn.hutool.core.date.DateUtil;
  7. import cn.hutool.core.lang.Assert;
  8. import cn.hutool.core.lang.Validator;
  9. import cn.hutool.core.util.StrUtil;
  10. import cn.hutool.http.HttpRequest;
  11. import cn.hutool.http.HttpStatus;
  12. import cn.hutool.http.HttpUtil;
  13. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  14. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  15. import com.cyksj.common.constant.Constant;
  16. import com.cyksj.common.exception.BusinessRuntimeException;
  17. import com.cyksj.common.task.GlobalThreadPoolTaskExecutor;
  18. import com.cyksj.common.util.Jsons;
  19. import com.cyksj.common.util.StringUtil;
  20. import com.cyksj.common.util.TicketCodeCommonUtil;
  21. import com.cyksj.enums.GatewayApiCode;
  22. import com.cyksj.mapper.*;
  23. import com.cyksj.mapper.manage.distribute.DistributeGeneralSkuRateMapper;
  24. import com.cyksj.mapper.manage.distribute.UserDistributeMapper;
  25. import com.cyksj.mapper.manage.distribute.UserPlatDistributeRateMapper;
  26. import com.cyksj.mapper.manage.distribute.UserPlatSkuDistributeRateMapper;
  27. import com.cyksj.mapper.sys.SysEmailMapper;
  28. import com.cyksj.model.entity.*;
  29. import com.cyksj.model.request.SpecialGoodsTicketReq;
  30. import com.cyksj.model.views.*;
  31. import com.cyksj.redis.RedisService;
  32. import com.cyksj.service.chatgpt.ChatGptAccountService;
  33. import com.cyksj.service.chatgpt.ChatGptAuthService;
  34. import com.cyksj.service.groups.GroupsFuncService;
  35. import com.cyksj.service.mail.CuiQiuMailService;
  36. import com.cyksj.service.mail.MailService;
  37. import com.cyksj.service.mange.coupon.CouponCommonService;
  38. import com.cyksj.service.midjourney.MidjourneyAccountService;
  39. import com.cyksj.service.relation.GroupRelationFrontService;
  40. import com.cyksj.service.relation.GroupsRelationNetflixService;
  41. import com.cyksj.service.user.UserBindRelationService;
  42. import com.cyksj.service.user.UserLoginRecordService;
  43. import com.ejlchina.searcher.BeanSearcher;
  44. import com.ejlchina.searcher.SearchResult;
  45. import com.ejlchina.searcher.param.Operator;
  46. import com.ejlchina.searcher.util.MapBuilder;
  47. import com.ejlchina.searcher.util.MapUtils;
  48. import com.github.rholder.retry.*;
  49. import lombok.RequiredArgsConstructor;
  50. import lombok.extern.slf4j.Slf4j;
  51. import org.springframework.stereotype.Service;
  52. import org.springframework.transaction.annotation.Transactional;
  53. import javax.servlet.http.HttpServletRequest;
  54. import java.math.BigDecimal;
  55. import java.math.RoundingMode;
  56. import java.util.*;
  57. import java.util.concurrent.ExecutionException;
  58. import java.util.concurrent.TimeUnit;
  59. import java.util.concurrent.atomic.AtomicInteger;
  60. import java.util.stream.Collectors;
  61. import static com.cyksj.enums.GatewayApiCode.GROUP_INDEX_ALREADY_BE_USER;
  62. import static com.cyksj.enums.GatewayApiCode.GROUP_INDEX_NOT_FIND;
  63. /*
  64. *项目名: netflix
  65. *文件名: GroupRelationFrontServiceImpl
  66. *创建者: JavaZou
  67. *创建时间:2022/12/29 15:42
  68. */
  69. @Service
  70. @RequiredArgsConstructor
  71. @Slf4j
  72. public class GroupRelationFrontServiceImpl implements GroupRelationFrontService {
  73. private final UserBindRelationService userBindRelationService;
  74. private final UserMapper userMapper;
  75. private final BeanSearcher beanSearcher;
  76. private final CouponCommonService couponCommonService;
  77. private final GroupsRelationMapper groupsRelationMapper;
  78. private final GroupsMapper groupsMapper;
  79. private final ChatGptAuthService chatGptAuthService;
  80. private final RedisService redisService;
  81. private final MailService mailService;
  82. private final OrderDonMapper orderDonMapper;
  83. private final GroupsRelationExpiryNotifyRecordMapper groupsRelationExpiryNotifyRecordMapper;
  84. private final HttpServletRequest request;
  85. private final GroupsFuncService groupsFuncService;
  86. private final OrderDiscountPlusPurchaseSkuRelationMapper orderDiscountPlusPurchaseSkuRelationMapper;
  87. private final GroupsRelationLoginCodeRecordMapper groupsRelationLoginCodeRecordMapper;
  88. private final SysEmailMapper sysEmailMapper;
  89. private final GoodsDonSkuMapper goodsDonSkuMapper;
  90. private final UserFuncPropertyMapper userFuncPropertyMapper;
  91. private static final GlobalThreadPoolTaskExecutor TASK_EXECUTOR = GlobalThreadPoolTaskExecutor.getInstance();
  92. private final UserLoginRecordService userLoginRecordService;
  93. private final CuiQiuMailService cuiQiuMailService;
  94. private final UserCertRecordMapper userCertRecordMapper;
  95. private final MidjourneyAccountService midjourneyAccountService;
  96. private final ChatGptAccountService chatGptAccountService;
  97. //脆球邮箱后缀
  98. private final static String CUI_QIU_EMAIL_SUFFIX = "@kindvd.com";
  99. private final UpgradePackageMapper upgradePackageMapper;
  100. private final GoodsDonQaRelateMapper goodsDonQaRelateMapper;
  101. private final GroupsRelationNetflixService groupsRelationNetflixService;
  102. private final UserDistributeMapper userDistributeMapper;
  103. private final UserPlatDistributeRateMapper userPlatDistributeRateMapper;
  104. private final GoodsDonMapper goodsDonMapper;
  105. private final UserPlatSkuDistributeRateMapper userPlatSkuDistributeRateMapper;
  106. private final DistributeGeneralSkuRateMapper distributeGeneralSkuRateMapper;
  107. @Override
  108. public SearchResult<RenewalView> getMyTicket(long userId, Boolean isLoginPopularize, String customId, String account) {
  109. User u = userMapper.selectById(userId);
  110. if (u == null) throw BusinessRuntimeException.getGatewayApiCode(GatewayApiCode.CMS_TOKEN_VALID);
  111. if (u.getIsBlack()) {
  112. return new SearchResult<>();
  113. }
  114. List<Long> userIds = userBindRelationService.getRelationUserIdList(userId, u);
  115. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  116. //Long yhsId = yhShopFrontService.getYhsIdByCustomId(customId);
  117. DateTime now = DateTime.now();
  118. if (StrUtil.isNotBlank(account)) {
  119. builder.field(RenewalView::getAccount, account).op(Operator.Contain);
  120. }
  121. SearchResult<RenewalView> list = beanSearcher.search(RenewalView.class, builder
  122. .field(RenewalView::getUserId, 0).op(Operator.GreaterThan)
  123. .field(RenewalView::getUserId, userIds).op(Operator.InList)
  124. //.field(RenewalView::getYhsId, yhsId)
  125. .put("condition", String.format("(gr.expiry_time is null or gr.expiry_time > '%s')", now))
  126. .field(RenewalView::getStatus, List.of("validity", "overdue", "outside")).op(Operator.InList)
  127. .orderBy(RenewalView::getExpiryTime).asc()
  128. .build());
  129. //过滤邀请制、已失效的车位
  130. Integer size = list.getTotalCount().intValue();
  131. list.getDataList().forEach(ticket -> {
  132. if (ticket.getSkuId() == null || ticket.getGoodsId() == null) {
  133. return;
  134. }
  135. if (ticket.getGoodsId() == 18 && ticket.getSkuNum() > 1) {
  136. ticket.setPassword(null);
  137. }
  138. ticket.setIsMulti(false);
  139. if (ticket.getSkuNum() > 1) {
  140. ticket.setIsMulti(true);
  141. }
  142. //chatGPT直连
  143. if (ticket.getGoodsId().equals(42l)) {
  144. if (StrUtil.isNotBlank(ticket.getAccount())) {
  145. String accessToken;
  146. try {
  147. accessToken = chatGptAuthService.getAccessToken(ticket.getAccount());
  148. ticket.setGptRefreshToken(accessToken);
  149. } catch (Exception e) {
  150. redisService.set(RedisService.key.CHAT_GPT_TOKEN_EXCEPTION_KEY.getName() + ticket.getAccount(), ticket.getAccount());
  151. }
  152. }
  153. ticket.setAccount(null);
  154. ticket.setPassword(null);
  155. } else {
  156. ticket.setGptRefreshToken(null);
  157. }
  158. if (ticket.getSecondType() == 1) {
  159. ticket.setAccount(null);
  160. ticket.setPassword(null);
  161. }
  162. if (isLoginPopularize != null && isLoginPopularize) {
  163. GoodsDonViews views = beanSearcher.searchFirst(GoodsDonViews.class, MapUtils.builder().field(GoodsDonViews::getId, ticket.getGoodsId()).build());
  164. views.setSpecs(beanSearcher.searchFirst(GoodsDonSpecFrontView.class, MapUtils.builder().field(GoodsDonSpecFrontView::getGoodsId, views.getId()).build()));
  165. views.setSkuList(beanSearcher.searchAll(GoodsDonSkuFrontView.class, MapUtils.builder().field(GoodsDonSkuFrontView::getGoodsId, views.getId()).field(GoodsDonSkuFrontView::getStatus, true).build()));
  166. ticket.setGoodsDonViews(views);
  167. }
  168. if (ticket.getMonths() != null && ticket.getMonths() >= 300) {
  169. ticket.setExpiryTime(null);
  170. }
  171. if (ticket.getExpiryTime() != null && ticket.getGoodsType() == 1 && ticket.getSecondType() == 2) {
  172. String remainDays = DateUtil.formatBetween(now, ticket.getExpiryTime(), BetweenFormater.Level.DAY);
  173. if ("0天".equals(remainDays)) {
  174. remainDays = "小于1天";
  175. } else {
  176. //当天也算
  177. int days = Integer.parseInt(remainDays.substring(0, remainDays.indexOf("天")));
  178. remainDays = days + 1 + "天";
  179. }
  180. ticket.setRemainDays(remainDays);
  181. }
  182. OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
  183. .eq(OrderDon::getRelationId, ticket.getRelationId())
  184. .eq(OrderDon::getUserId, ticket.getUserId())
  185. .notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
  186. .orderByDesc(OrderDon::getId)
  187. .last("limit 1"));
  188. if (orderDon != null) {
  189. ticket.setOrderNo(orderDon.getOrderNo());
  190. ticket.setOrderId(orderDon.getId());
  191. ticket.setTransactionId(orderDon.getTransactionId());
  192. }
  193. if (size > 1 && ticket.getGoodsId() != 18) {
  194. Date payTime = null;
  195. if (orderDon != null) {
  196. payTime = Optional.ofNullable(orderDon.getPayTime()).orElse(orderDon.getCreatedTime());
  197. }
  198. //加购订单
  199. if (orderDon == null) {
  200. List<OrderDiscountPlusPurchaseSkuRelation> plusPurchaseSkuRelations = orderDiscountPlusPurchaseSkuRelationMapper.selectPlusRelationByIdAndUserId(ticket.getRelationId(), ticket.getUserId());
  201. for (OrderDiscountPlusPurchaseSkuRelation data : plusPurchaseSkuRelations) {
  202. String relationIds = data.getRelationIds();
  203. if (StrUtil.isEmpty(relationIds)) {
  204. return;
  205. }
  206. try {
  207. List<Long> relationList = Jsons.parseList(relationIds, Long.class);
  208. if (relationList.contains(ticket.getRelationId())) {
  209. OrderDon plusOrder = orderDonMapper.selectById(data.getOrderId());
  210. if (plusOrder != null) {
  211. payTime = Optional.ofNullable(plusOrder.getPayTime()).orElse(plusOrder.getCreatedTime());
  212. }
  213. break;
  214. }
  215. } catch (Exception e) {
  216. }
  217. }
  218. }
  219. ticket.setPayTime(payTime);
  220. }
  221. if (ticket.getGoodsId() == 26 && ticket.getIsMirror()){
  222. List<UpgradePackage> upgradePackages = upgradePackageMapper.selectList(Wrappers.lambdaQuery(UpgradePackage.class).apply("JSON_CONTAINS(sku_ids,'\"" + ticket.getSkuId() + "\"')").eq(UpgradePackage::getStatus, Boolean.TRUE).eq(UpgradePackage::getDeleted, Boolean.TRUE));
  223. if (CollectionUtil.isNotEmpty(upgradePackages)){
  224. upgradePackages.stream().map(e -> e.getPrice().divide(BigDecimal.valueOf(e.getNum()), 2, RoundingMode.HALF_UP)).min(BigDecimal::compareTo).ifPresent(ticket::setMjPackagePrice);
  225. }
  226. try {
  227. MidjourneyUserView search = beanSearcher.searchFirst(MidjourneyUserView.class, MapUtils.flatBuilder(request.getParameterMap())
  228. .field(MidjourneyUserView::getUserId, ticket.getUserId()).field(MidjourneyUserView::getRelationId, ticket.getRelationId())
  229. .onlySelect(MidjourneyUserView::getMjFastNum, MidjourneyUserView::getMjRelaxNum)
  230. .build());
  231. if (search == null) {
  232. MidjourneyUser midjourneyUser = midjourneyAccountService.getMidjourneyUserToken(ticket.getUserId(), ticket.getRelationId());
  233. ticket.setMjUserFastNum(midjourneyUser.getMjFastNum());
  234. ticket.setMjUserRelaxNum(midjourneyUser.getMjRelaxNum());
  235. } else {
  236. ticket.setMjUserFastNum(search.getMjFastNum());
  237. ticket.setMjUserRelaxNum(search.getMjRelaxNum());
  238. }
  239. } catch (Exception e) {
  240. }
  241. }
  242. if (ticket.getGoodsId() == 18 && ticket.getIsCar() && ticket.getExpiryTime() != null) {
  243. //gpt用户镜像
  244. ChatGptUserView userInfo = chatGptAccountService.getUserInfo(userId, ticket.getRelationId());
  245. ticket.setGptUserLimitNum(userInfo.getLimitNum());
  246. ticket.setGptUserLimitTime(userInfo.getLimitTime());
  247. ticket.setUse(userInfo.getUse());
  248. Integer count = upgradePackageMapper.selectCount(Wrappers.lambdaQuery(UpgradePackage.class).apply("JSON_CONTAINS(sku_ids,'\"" + ticket.getSkuId() + "\"')")
  249. .gt(UpgradePackage::getNum, userInfo.getLimitNum())
  250. .eq(UpgradePackage::getStatus, Boolean.TRUE)
  251. .eq(UpgradePackage::getGptType, 0)
  252. .eq(UpgradePackage::getDeleted, Boolean.TRUE));
  253. ticket.setUpgrade(count > 0 ? true : false);
  254. ticket.setPackageId(userInfo.getPackageId());
  255. if (userInfo.getPackageId() != 0) {
  256. UpgradePackage upgradePackage = upgradePackageMapper.selectById(userInfo.getPackageId());
  257. ticket.setPackagePrice(upgradePackage.getPrice());
  258. }
  259. }
  260. List<GroupsRelationUserView> relationUserViews = groupsRelationMapper.getUserRelationUserViews(ticket.getGroupId(), ticket.getRelationId(), ticket.getUserId(), List.of(GroupsRelation.Status.validity, GroupsRelation.Status.outside));
  261. ticket.setRelationViews(relationUserViews);
  262. if (ticket.getExpiryTime() != null) {
  263. ticket.setExpiryTimeStr(DateUtil.format(ticket.getExpiryTime(), "yyyy-MM-dd"));
  264. }
  265. //查看双重验证码
  266. if (StrUtil.isNotEmpty(ticket.getApiSecret())) {
  267. Boolean isHasVerifyCode = StrUtil.isNotBlank(ticket.getVerifyCode()) ? true : false;
  268. Integer codeNum = getUserCodeNumBySkuId(ticket.getUserId(), ticket.getSkuId(), isHasVerifyCode);
  269. ticket.setCodeNum(codeNum);
  270. }
  271. Long qaId = groupsRelationMapper.selectGoodsDonQaByGoodsId(ticket.getGoodsId());
  272. ticket.setQa(qaId > 0 ? true : false);
  273. //是否存在海报
  274. ticket.setPosterInfo(setGoodsPoster(ticket, u));
  275. });
  276. userLoginRecordService.saveUserLoginDayRecord(userId);
  277. return list;
  278. }
  279. @Override
  280. public Boolean isJoinCorpWx(Long userId, Boolean isJoin, Boolean noCoupon) {
  281. if (!isJoin) {
  282. User user = userMapper.selectById(userId);
  283. if (user == null || StrUtil.isEmpty(user.getUnionid())) {
  284. return true;
  285. }
  286. // CorpUser corpUser = corpUserMapper.selectOne(Wrappers.lambdaQuery(CorpUser.class)
  287. // .ne(CorpUser::getUnionid, "")
  288. // .eq(CorpUser::getUnionid, user.getUnionid())
  289. // .last("limit 1")
  290. // .select(CorpUser::getId)
  291. // );
  292. CorpUserFollowView corpUserFollowView = beanSearcher.searchFirst(CorpUserFollowView.class, MapUtils.builder()
  293. .field(CorpUserFollowView::getUnionId, user.getUnionid())
  294. .field(CorpUserFollowView::getStatus, 1).build());
  295. if (corpUserFollowView == null) {
  296. return false;
  297. }
  298. }
  299. //用户是否买了奈飞车票
  300. Number number = beanSearcher.searchCount(RenewalView.class, MapUtils.builder()
  301. .field(RenewalView::getUserId, userId)
  302. .field(RenewalView::getGoodsId, 1)
  303. .field(RenewalView::getStatus, List.of("validity", "overdue")).op(Operator.InList)
  304. .build());
  305. if (number.intValue() > 0 && !noCoupon) {
  306. couponCommonService.sendCouponToUser(userId, 34l, 0l, 0l, 0l, CouponUser.Channel.wxCorp);
  307. }
  308. return true;
  309. }
  310. @Override
  311. public GroupsRelation getSimilarExpiredGroupRelation(GoodsDonSku sku, List<Long> errorsRelationIds, String ip) {
  312. Long skuId = sku.getId();
  313. Integer days = sku.getDays();
  314. Integer months = sku.getMonths();
  315. Integer maxNum = sku.getNum();
  316. DateTime expiryTime = null;
  317. if (days != null && days > 0) {
  318. expiryTime = DateUtil.offsetDay(DateTime.now(), days);
  319. } else {
  320. expiryTime = DateUtil.offsetMonth(DateTime.now(), months);
  321. }
  322. Integer extraNum = 5;
  323. if (sku.getId() == 178l) {
  324. extraNum = 2;
  325. }
  326. maxNum += extraNum;
  327. DateTime minExpiryTime = DateUtil.offsetDay(expiryTime, -5);
  328. Long groupsId = groupsRelationMapper.selectSimilarExpiredRelation(skuId, minExpiryTime, maxNum, ip);
  329. if (groupsId == null) {
  330. log.info("暂无相似过期时间车队");
  331. return null;
  332. }
  333. GroupsRelation relation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
  334. .notIn(errorsRelationIds != null && errorsRelationIds.size() > 0, GroupsRelation::getId, errorsRelationIds)
  335. .eq(GroupsRelation::getGroupsId, groupsId)
  336. .eq(GroupsRelation::getStatus, GroupsRelation.Status.none)
  337. .eq(GroupsRelation::getUserId, 0)
  338. .orderByAsc(GroupsRelation::getNum)
  339. .last("limit 1"));
  340. if (relation != null) {
  341. log.info("用户userId:{},获取相似车队的车位relationId:{}", relation.getId());
  342. }
  343. return relation;
  344. }
  345. @Override
  346. public Page<UserRecommendGoodsFrontView> getRecommendGoodsViews(Boolean isPayNf, List<Long> filter_goods_id, Boolean filterCourseGoods, Integer start, Integer limit) {
  347. return groupsRelationMapper.getRecommendGoodsViews(new Page<>(start, limit), filter_goods_id, isPayNf, filterCourseGoods);
  348. }
  349. @Override
  350. @Transactional(rollbackFor = Throwable.class)
  351. public void sendCourseWare(SpecialGoodsTicketReq request) throws Exception {
  352. Long userId = request.getUserId();
  353. Long relationId = request.getRelationId();
  354. String email = request.getEmail();
  355. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  356. RenewalView relation = beanSearcher.searchFirst(RenewalView.class, MapUtils.builder().field(RenewalView::getRelationId, relationId).build());
  357. Assert.notNull(relation, "您的车票不存在");
  358. Long relationUserId = relation.getUserId();
  359. if (!userIdList.contains(relationUserId)) {
  360. throw BusinessRuntimeException.getInstance("您的车票不存在");
  361. }
  362. if (relation.getSpecialType() != GoodsDon.SpecialType.courseware) {
  363. throw BusinessRuntimeException.getInstance("");
  364. }
  365. //是否已发送
  366. if (StrUtil.isNotBlank(relation.getGrAccount())) {
  367. throw BusinessRuntimeException.getInstance("已领取课件,请前往邮箱查看");
  368. }
  369. if (!Validator.isEmail(email)) {
  370. throw BusinessRuntimeException.getInstance("请输入正确的邮箱");
  371. }
  372. int update = groupsRelationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
  373. .set(GroupsRelation::getAccount, email)
  374. .and(qr -> qr.isNull(GroupsRelation::getAccount).or().eq(GroupsRelation::getAccount, StrUtil.EMPTY))
  375. .eq(GroupsRelation::getId, relationId));
  376. if (update > 0) {
  377. orderDonMapper.update(null, Wrappers.lambdaUpdate(OrderDon.class)
  378. .set(OrderDon::getStatus, OrderDon.Status.complete)
  379. .eq(OrderDon::getRelationId, relationId)
  380. .eq(OrderDon::getUserId, userId)
  381. .eq(OrderDon::getStatus, OrderDon.Status.hasPayment));
  382. mailService.sendCoursewareByGoodsId(relation.getGoodsId(), relation.getRelationId(), relation.getUserId(), relation.getTitle(), email);
  383. }
  384. }
  385. @Override
  386. public GroupsRelation getRelation(Long payRelationId, Long userId, GoodsDonSku sku, String ip) {
  387. GroupsRelation relation = null;
  388. Integer maxNum = sku.getNum();
  389. if (payRelationId != null && payRelationId > 0) {
  390. relation = groupsRelationMapper.selectById(payRelationId);
  391. if (relation == null) {
  392. throw new BusinessRuntimeException(GROUP_INDEX_NOT_FIND.getCode(), GROUP_INDEX_NOT_FIND.getMsg());
  393. }
  394. if (relation.getUserId() != null && relation.getUserId() > 0L) {
  395. throw new BusinessRuntimeException(GROUP_INDEX_ALREADY_BE_USER.getCode(), GROUP_INDEX_ALREADY_BE_USER.getMsg());
  396. }
  397. } else {
  398. GroupsTrips groups = null;
  399. //ChatGpt Plus、Midjourney非独立规格 上车先获取硬塞座位 硬塞5个座位
  400. //主账号过期时间25天以外
  401. //23-12-06 MidJourney 不硬塞
  402. if (sku.getNum() > 1 && Constant.AI_goodsIds.get(0) == sku.getGoodsId()) {
  403. Integer extraNum = 5;
  404. if (sku.getId() == 178l || sku.getId() == 423l) {
  405. extraNum = 2;
  406. }
  407. maxNum += extraNum;
  408. DateTime time = DateUtil.offsetDay(DateUtil.beginOfDay(DateTime.now()), 25);
  409. //不塞存在该用户的车队
  410. Long groupsId = groupsRelationMapper.getOutSideGroupsTripsRelationByGoodsId(sku.getId(), time, extraNum, userId, sku.getNum(), maxNum);
  411. if (groupsId != null) {
  412. relation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
  413. .eq(GroupsRelation::getGroupsId, groupsId)
  414. .eq(GroupsRelation::getUserId, 0)
  415. .eq(GroupsRelation::getStatus, GroupsRelation.Status.outside)
  416. .last("limit 1"));
  417. if (relation == null) {
  418. relation = new GroupsRelation();
  419. relation.setStatus(GroupsRelation.Status.outside);
  420. relation.setUserId(userId);
  421. relation.setGroupsId(groupsId);
  422. GroupsRelation maxNumRelation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class).eq(GroupsRelation::getGroupsId, groupsId).orderByDesc(GroupsRelation::getNum).last("limit 1"));
  423. Integer nextNum = maxNumRelation.getNum() + 1;
  424. if (redisService.setNx(RedisService.key.GROUPS_TRIPS_OUTSIDE_RELATION.getNameFormat(groupsId, nextNum), nextNum, RedisService.key.GROUPS_TRIPS_OUTSIDE_RELATION.getTimeout())) {
  425. relation.setNum(nextNum);
  426. groupsRelationMapper.insert(relation);
  427. } else {
  428. throw BusinessRuntimeException.getInstance("系统繁忙,请重试...");
  429. }
  430. }
  431. groups = groupsMapper.selectById(groupsId);
  432. }
  433. }
  434. if (groups == null) {
  435. //寻找差不多过期时间规格的车位
  436. relation = getSimilarExpiredGroupRelation(sku, null, ip);
  437. if (relation == null) {
  438. //TODO 如果没指定座位,等待逻辑确认
  439. groups = groupsMapper.selectTicketGroups(sku.getId(), GroupsTrips.Status.validity, maxNum, ip);
  440. if (groups == null) {
  441. //待发车
  442. groups = groupsMapper.selectTicketGroups(sku.getId(), GroupsTrips.Status.waiting, maxNum, ip);
  443. }
  444. //新增空车队
  445. if (groups == null) {
  446. relation = groupsFuncService.createNewGroupsTrips(sku);
  447. }
  448. //获取车位
  449. if (relation == null) {
  450. //寻找快满编车队进行占座
  451. relation = groupsRelationMapper.selectRandomOneRelationByGroupsId(groups.getId());
  452. if (relation == null) {
  453. Long groupsId = groups.getId();
  454. TASK_EXECUTOR.execute(() -> groupsMapper.updateAvailableNum(groupsId));
  455. throw BusinessRuntimeException.getInstance("系统繁忙,请重试...");
  456. }
  457. }
  458. }
  459. }
  460. if (groups == null) {
  461. groups = groupsMapper.selectById(relation.getGroupsId());
  462. }
  463. //车队目前可用停车数
  464. relation.setGroupsAvailParkingNum(groups.getAvailableParkingNum());
  465. relation.setMaxNum(maxNum);
  466. }
  467. return relation;
  468. }
  469. @Override
  470. public String getAiVerifyCode(Long userId, Long relationId, Integer type, Boolean sync) throws Exception {
  471. List<Long> relationUserIdList = userBindRelationService.getRelationUserIdList(userId, null);
  472. RenewalView renewalView = beanSearcher.searchFirst(RenewalView.class, MapUtils.builder().field(RenewalView::getUserId, relationUserIdList).op(Operator.InList)
  473. .field(RenewalView::getRelationId, relationId).build());
  474. if (renewalView == null) {
  475. throw BusinessRuntimeException.getInstance("您的车票不存在...");
  476. }
  477. if (StrUtil.isEmpty(renewalView.getAccount())) {
  478. throw BusinessRuntimeException.getInstance("车票未配置账号");
  479. }
  480. String account = renewalView.getAccount();
  481. String password = renewalView.getPassword();
  482. if (StrUtil.hasEmpty(account, password)) {
  483. throw BusinessRuntimeException.getInstance("您的车票账号密码异常,请联系客服...");
  484. }
  485. if (renewalView.getAccount().contains(CUI_QIU_EMAIL_SUFFIX)) {
  486. return cuiQiuMailService.getVerifyCode(renewalView.getAccount(), renewalView.getGoodsId(), type, sync);
  487. }
  488. //获取邮箱密码
  489. SysEmail sysEmail = sysEmailMapper.selectOne(Wrappers.lambdaQuery(SysEmail.class)
  490. .eq(SysEmail::getEmail, account)
  491. .last("limit 1"));
  492. if (sysEmail == null) {
  493. log.info("获取账号:{}验证码异常,未配置对应系统邮箱", account);
  494. throw BusinessRuntimeException.getInstance("获取账号验证码异常,请联系客服...");
  495. }
  496. String url = "http://yinhelx.com/api/controller.php";
  497. Map<String, Object> params = new HashMap<>();
  498. params.put("imap_key", "imap_56568niua@@");
  499. params.put("fun", "imap_read");
  500. params.put("imap_ip", "yinhelx.com");
  501. params.put("port", "143");
  502. params.put("username", account);
  503. params.put("password", sysEmail.getPassword());
  504. params.put("mbox_id", "0");
  505. params.put("delete", "0");
  506. HttpRequest post = HttpUtil.createPost(url);
  507. post.form(params);
  508. cn.hutool.http.HttpResponse execute = post.execute();
  509. if (execute.getStatus() != HttpStatus.HTTP_OK) {
  510. throw BusinessRuntimeException.getInstance("获取验证码异常,请联系客服...");
  511. }
  512. String code = getDifferentGoodsCode(renewalView.getGoodsId(), execute.body(), type, sync);
  513. GroupsRelationLoginCodeRecord record = new GroupsRelationLoginCodeRecord();
  514. record.setUserId(userId);
  515. record.setRelationId(relationId);
  516. record.setAccount(renewalView.getAccount());
  517. record.setGoodsId(renewalView.getGoodsId());
  518. record.setSkuId(renewalView.getSkuId());
  519. groupsRelationLoginCodeRecordMapper.insert(record);
  520. return code;
  521. }
  522. @Override
  523. public void checkGroupsAvailParkingNum(Long skuId, Long groupsId, Integer availableParkingNum, Integer maxNum) {
  524. //GPT10人月付、4人月付
  525. if (skuId == 161l || skuId == 178l) {
  526. //为0时,不参与限制
  527. if (availableParkingNum == 0) {
  528. return;
  529. }
  530. //目前车队可用停车数
  531. //目前上车人数
  532. Integer currentParkingNum = groupsRelationMapper.selectCount(Wrappers.lambdaQuery(GroupsRelation.class)
  533. .eq(GroupsRelation::getGroupsId, groupsId)
  534. .ne(GroupsRelation::getUserId, 0)
  535. .le(GroupsRelation::getNum, maxNum));
  536. if (currentParkingNum > availableParkingNum) {
  537. throw BusinessRuntimeException.getInstance("系统繁忙,请重试...");
  538. }
  539. }
  540. }
  541. @Override
  542. public void adjustGroupsParkingTime(Long relationId, GoodsDonSku sku) {
  543. Long skuId = sku.getId();
  544. //更新GPT Plus10人、4人月付车队状态 待优化
  545. if (skuId == 161l || skuId == 178l || skuId == 422l || skuId == 423l) {
  546. GroupsRelation relation = groupsRelationMapper.selectById(relationId);
  547. Long groupsId = relation.getGroupsId();
  548. GroupsTrips groupsTrips = groupsMapper.selectById(groupsId);
  549. Integer availableParkingNum = groupsTrips.getAvailableParkingNum();
  550. //为0时 不参与限制
  551. if (availableParkingNum == 0) {
  552. return;
  553. }
  554. Integer extraNum = 5;
  555. if (skuId == 178l || skuId == 423l) {
  556. extraNum = 2;
  557. }
  558. Integer maxNum = sku.getNum() + extraNum;
  559. if (availableParkingNum >= maxNum) {
  560. return;
  561. }
  562. //目前上车人数
  563. Integer currentParkingNum = groupsRelationMapper.selectCount(Wrappers.lambdaQuery(GroupsRelation.class)
  564. .eq(GroupsRelation::getGroupsId, groupsId)
  565. .ne(GroupsRelation::getUserId, 0)
  566. .le(GroupsRelation::getNum, maxNum));
  567. if (currentParkingNum >= availableParkingNum) {
  568. //锁住
  569. DateTime parkingTime = DateUtil.offsetDay(DateTime.now(), 1);
  570. groupsMapper.update(null, Wrappers.lambdaUpdate(GroupsTrips.class)
  571. .eq(GroupsTrips::getId, groupsTrips.getId())
  572. .set(GroupsTrips::getParkingTime, parkingTime)
  573. .isNull(GroupsTrips::getParkingTime));
  574. }
  575. }
  576. }
  577. @Override
  578. public void setGroupsTripsParkingTimeEmpty(GoodsDonSku sku, Long relationId) {
  579. Long skuId = sku.getId();
  580. if (skuId == 161l || skuId == 178l) {
  581. GroupsRelation relation = groupsRelationMapper.selectById(relationId);
  582. Long groupsId = relation.getGroupsId();
  583. GroupsTrips groupsTrips = groupsMapper.selectById(groupsId);
  584. Integer availableParkingNum = groupsTrips.getAvailableParkingNum();
  585. if (groupsTrips.getParkingTime() == null || availableParkingNum == 0) {
  586. return;
  587. }
  588. Integer extraNum = 5;
  589. if (skuId == 178l) {
  590. extraNum = 2;
  591. }
  592. Integer skuNum = sku.getNum();
  593. if (availableParkingNum >= skuNum + extraNum) {
  594. return;
  595. }
  596. //目前上车人数
  597. Integer currentParkingNum = groupsRelationMapper.selectCount(Wrappers.lambdaQuery(GroupsRelation.class)
  598. .eq(GroupsRelation::getGroupsId, groupsId)
  599. .ne(GroupsRelation::getUserId, 0));
  600. if (currentParkingNum < availableParkingNum) {
  601. groupsMapper.update(null, Wrappers.lambdaUpdate(GroupsTrips.class)
  602. .eq(GroupsTrips::getId, groupsTrips.getId())
  603. .set(GroupsTrips::getParkingTime, null)
  604. .isNotNull(GroupsTrips::getParkingTime));
  605. }
  606. }
  607. }
  608. @Override
  609. public Integer getUserCodeNumBySkuId(Long userId, Long skuId, Boolean isHasVerifyCode) {
  610. //查看双重验证码
  611. UserFuncProperty userFuncProperty = userFuncPropertyMapper.selectOne(Wrappers.lambdaQuery(UserFuncProperty.class).eq(UserFuncProperty::getUserId, userId).last("limit 1"));
  612. //默认2次
  613. int num = 2;
  614. //有安全码查看次数 置为0
  615. if (isHasVerifyCode) {
  616. num = 0;
  617. //存在身份实名认证有两次机会
  618. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  619. Integer selectCount = userCertRecordMapper.selectCount(Wrappers.lambdaQuery(UserCertRecord.class)
  620. .in(UserCertRecord::getUserId, userIdList));
  621. if (selectCount > 0) {
  622. num = 2;
  623. }
  624. return num;
  625. }
  626. //查看双重验证码次数
  627. GoodsDonSku sku = goodsDonSkuMapper.selectById(skuId);
  628. if (sku.getCodeNum() > 0) {
  629. num = sku.getCodeNum();
  630. }
  631. if (userFuncProperty != null) num = userFuncProperty.getVerifyCheckNum();
  632. return num;
  633. }
  634. @Override
  635. public List<RenewalView> getHasPayGoods(long userId) {
  636. User user = userMapper.selectById(userId);
  637. List<Long> userIds = userBindRelationService.getRelationUserIdList(userId, user);
  638. DateTime now = DateTime.now();
  639. List<RenewalView> list = groupsRelationMapper.getUserHasPayGoods(userIds, now);
  640. return list;
  641. }
  642. @Override
  643. public List<RenewalView> getExpiryRenewalNotify(Long userId) {
  644. DateTime now = DateTime.now();
  645. DateTime thisZero = DateUtil.beginOfDay(now);
  646. String thisDate = thisZero.toDateStr();
  647. Object exists = redisService.get(RedisService.key.TICKET_EXPIRY_NOTIFY_DAY.getNameFormat(thisDate, userId));
  648. if (exists != null) {
  649. return null;
  650. }
  651. User u = userMapper.selectById(userId);
  652. if (u == null) throw BusinessRuntimeException.getGatewayApiCode(GatewayApiCode.CMS_TOKEN_VALID);
  653. if (u.getIsBlack()) {
  654. redisService.setNx(RedisService.key.TICKET_EXPIRY_NOTIFY_DAY.getNameFormat(thisDate, userId), userId, RedisService.key.TICKET_EXPIRY_NOTIFY_DAY.getTimeout());
  655. return null;
  656. }
  657. List<Long> userIds = userBindRelationService.getRelationUserIdList(userId, u);
  658. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  659. List<RenewalView> list = beanSearcher.searchAll(RenewalView.class, builder
  660. .field(RenewalView::getUserId, 0).op(Operator.GreaterThan)
  661. .field(RenewalView::getUserId, userIds).op(Operator.InList)
  662. .field(RenewalView::getExpiryTime, now).op(Operator.GreaterThan)
  663. .field(RenewalView::getStatus, List.of("validity", "overdue", "outside")).op(Operator.InList)
  664. .field(RenewalView::getAqType, 1)
  665. .orderBy(RenewalView::getExpiryTime).asc()
  666. .onlySelect(RenewalView::getMonths, RenewalView::getExpiryTime, RenewalView::getRelationId, RenewalView::getAccount, RenewalView::getGoodsId, RenewalView::getTitle, RenewalView::getLogo, RenewalView::getImg, RenewalView::getGroupId, RenewalView::getSkuId, RenewalView::getSpecVal, RenewalView::getGoodsStatus, RenewalView::getSkuStatus)
  667. .build());
  668. if (list.size() > 5) {
  669. redisService.setNx(RedisService.key.TICKET_EXPIRY_NOTIFY_DAY.getNameFormat(thisDate, userId), userId, RedisService.key.TICKET_EXPIRY_NOTIFY_DAY.getTimeout());
  670. return null;
  671. }
  672. //提前7天
  673. AtomicInteger day = new AtomicInteger(7);
  674. List<RenewalView> expiryTickets = list.stream().filter(ticket -> {
  675. //下架
  676. if (ticket.getGoodsStatus() == null || ticket.getSkuStatus() == null || !ticket.getGoodsStatus() || !ticket.getSkuStatus()) {
  677. return false;
  678. }
  679. Integer skuMonths = ticket.getMonths();
  680. Date expiryTime = ticket.getExpiryTime();
  681. //年付 提前一个月
  682. if (skuMonths >= 12) {
  683. day.set(30);
  684. } else {
  685. day.set(7);
  686. }
  687. if (DateUtil.beginOfDay(expiryTime).compareTo(DateUtil.offsetDay(thisZero, day.get())) <= 0) {
  688. ticket.setExpiryTimeStr(DateUtil.format(ticket.getExpiryTime(), "yyyy-MM-dd"));
  689. ticket.setExpiryTime(null);
  690. return true;
  691. }
  692. return false;
  693. }).collect(Collectors.toList());
  694. redisService.setNx(RedisService.key.TICKET_EXPIRY_NOTIFY_DAY.getNameFormat(thisDate, userId), userId, RedisService.key.TICKET_EXPIRY_NOTIFY_DAY.getTimeout());
  695. if (CollUtil.isNotEmpty(expiryTickets)) {
  696. groupsRelationExpiryNotifyRecordMapper.batchInsert(userId, expiryTickets);
  697. }
  698. return expiryTickets;
  699. }
  700. public String getDifferentGoodsCode(Long goodsId, String body, Integer type, Boolean sync) {
  701. String code = null;
  702. //奈飞
  703. if (goodsId == 1) {
  704. if (type != null && type == 1) {
  705. if (body.contains("輸入此代碼登入") || body.contains("输入此代码登录")) {
  706. code = StrUtil.subBetween(body, "輸入此代碼登入", "請在裝置上輸入上");
  707. if (StrUtil.isEmpty(code)) {
  708. code = StrUtil.subAfter(body, "输入此代码登录", true);
  709. }
  710. }
  711. if (StrUtil.isEmpty(code)) {
  712. throw BusinessRuntimeException.getInstance("查询失败,请检查是否发送了登陆码..");
  713. }
  714. } else {
  715. String urlPref = "https://www.netflix.com/account/update-primary-location";
  716. code = StrUtil.subBetween(body, "[" + urlPref, "]");
  717. if (StrUtil.isEmpty(code)) {
  718. urlPref = "https://www.netflix.com/account/travel/verify";
  719. code = StrUtil.subBetween(body, "[" + urlPref, "]");
  720. if (StrUtil.isEmpty(code)) {
  721. throw BusinessRuntimeException.getInstance("获取认证链接失败,请重新获取");
  722. }
  723. }
  724. String url = urlPref + code;
  725. //非点击装置同步更新按钮 直接返回链接
  726. if (!sync) return url;
  727. //失败返回验证链接
  728. if (!groupsRelationNetflixService.confirmUpdate(url)) {
  729. return url;
  730. }
  731. return StrUtil.EMPTY;
  732. }
  733. }
  734. //除奈飞
  735. if (StrUtil.isEmpty(code)) {
  736. code = TicketCodeCommonUtil.getTicketCodeStr(body, goodsId);
  737. }
  738. int length = 4;
  739. if (goodsId == 33l) {
  740. length = 6;
  741. }
  742. code = StringUtil.getVerifyCodePattern(code, length);
  743. if (!Validator.isNumber(code)) {
  744. log.error("获取账号验证码失败:{}", StrUtil.subSufByLength(code, 512));
  745. throw BusinessRuntimeException.getInstance("获取验证码失败,请重新获取..");
  746. }
  747. return code.trim();
  748. }
  749. @Override
  750. public void getCollegeStudentUserGptTicket(Long userId) {
  751. Retryer<Boolean> build = RetryerBuilder.<Boolean>newBuilder()
  752. .retryIfException()
  753. //运行时异常重试
  754. .retryIfRuntimeException()
  755. //false重试
  756. .retryIfResult(res -> Objects.equals(res, false))
  757. //1s 间隔
  758. .withWaitStrategy(WaitStrategies.fixedWait(1, TimeUnit.SECONDS))
  759. //停止策略 : 尝试请求3次
  760. .withStopStrategy(StopStrategies.stopAfterAttempt(3)).build();
  761. try {
  762. build.call(() -> {
  763. //体验规格
  764. Long gptMirrorSkuId = Constant.GPT_MIRROR_SKU_ID;
  765. GroupsTrips groups = groupsMapper.selectCollegeStudentUserGptTicket(gptMirrorSkuId);
  766. GroupsRelation relation = null;
  767. if (groups != null) {
  768. relation = groupsRelationMapper.selectRandomOneRelationByGroupsId(groups.getId());
  769. }
  770. if (relation == null) {
  771. //生成空车队
  772. GoodsDonSku sku = goodsDonSkuMapper.selectById(gptMirrorSkuId);
  773. relation = groupsFuncService.createNewGroupsTrips(sku);
  774. }
  775. DateTime startTime = DateTime.now();
  776. DateTime expiryTime = DateUtil.offsetDay(startTime, 1);
  777. int update = groupsRelationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
  778. .set(GroupsRelation::getUserId, userId)
  779. .set(GroupsRelation::getStartTime, startTime)
  780. .set(GroupsRelation::getExpiryTime, expiryTime)
  781. .set(GroupsRelation::getStatus, GroupsRelation.Status.validity)
  782. .set(GroupsRelation::getAqType, 2)
  783. .eq(GroupsRelation::getId, relation.getId())
  784. .eq(GroupsRelation::getUserId, 0));
  785. if (update > 0) {
  786. groupsMapper.decrAvailableNum(groups.getId());
  787. return true;
  788. }
  789. log.error("发送用户:{} GPT镜像车票体验失败,进行重试", userId);
  790. return false;
  791. });
  792. } catch (ExecutionException | RetryException e) {
  793. log.error("发送用户GPT镜像体验失败:{}", StringUtil.getErrorText(e));
  794. }
  795. }
  796. @Override
  797. public RenewalView getTicketDetail(long userId, Long relationId) {
  798. User u = userMapper.selectById(userId);
  799. List<Long> userIds = userBindRelationService.getRelationUserIdList(userId, u);
  800. MapBuilder builder = MapUtils.builder();
  801. RenewalView renewalView = beanSearcher.searchFirst(RenewalView.class, builder
  802. .field(RenewalView::getRelationId, relationId)
  803. .field(RenewalView::getUserId, 0).op(Operator.GreaterThan)
  804. .field(RenewalView::getUserId, userIds).op(Operator.InList)
  805. .field("condition", String.format("(gr.expiry_time is null or gr.expiry_time > '%s')", DateTime.now()))
  806. .field(RenewalView::getStatus, List.of("validity", "outside")).op(Operator.InList)
  807. .orderBy(RenewalView::getExpiryTime).asc()
  808. .onlySelect(RenewalView::getRelationId, RenewalView::getExpiryTime, RenewalView::getTitle, RenewalView::getSpecVal, RenewalView::getGoodsId, RenewalView::getSkuId, RenewalView::getSkuNum, RenewalView::getSkuStatus, RenewalView::getGoodsStatus)
  809. .build());
  810. if (renewalView != null) {
  811. renewalView.setExpiryTimeStr(DateUtil.format(renewalView.getExpiryTime(), "yyyy-MM-dd"));
  812. }
  813. return renewalView;
  814. }
  815. private DistributePosterGoodsDetailView setGoodsPoster(RenewalView ticket, User user) {
  816. DistributePosterGoodsDetailView distributePosterGoodsDetailView = beanSearcher.searchFirst(DistributePosterGoodsDetailView.class, MapUtils.flatBuilder(request.getParameterMap())
  817. .field(DistributePosterGoodsFrontView::getGoodsId, ticket.getGoodsId()).build());
  818. if (distributePosterGoodsDetailView == null) {
  819. return null;
  820. }
  821. distributePosterGoodsDetailView.setNickname(user.getNickname());
  822. UserDistribute userDistribute = userDistributeMapper.selectOne(Wrappers.lambdaQuery(UserDistribute.class)
  823. .eq(UserDistribute::getUserId, user.getId())
  824. .eq(UserDistribute::getDeleted, 1)
  825. .last("limit 1"));
  826. if (userDistribute != null) {
  827. UserPlatDistributeRate userPlatDistributeRate = userPlatDistributeRateMapper.selectOne(Wrappers.lambdaQuery(UserPlatDistributeRate.class)
  828. .eq(UserPlatDistributeRate::getDistributeId, userDistribute.getId())
  829. .eq(UserPlatDistributeRate::getGoodsId, ticket.getGoodsId())
  830. .last("limit 1"));
  831. if (userPlatDistributeRate != null) {
  832. distributePosterGoodsDetailView.setRate(userPlatDistributeRate.getRate());
  833. }
  834. }
  835. GoodsDon goodsDon = goodsDonMapper.selectById(ticket.getGoodsId());
  836. if (goodsDon.getIsSkuDistribute()) {
  837. if (userDistribute != null) {
  838. UserPlatSkuDistributeRate userPlatSkuDistributeRate = userPlatSkuDistributeRateMapper.selectOne(Wrappers.lambdaQuery(UserPlatSkuDistributeRate.class)
  839. .eq(UserPlatSkuDistributeRate::getDistributeId, userDistribute.getId())
  840. .eq(UserPlatSkuDistributeRate::getSkuId, ticket.getSkuId())
  841. .last("limit 1"));
  842. if (userPlatSkuDistributeRate != null) {
  843. distributePosterGoodsDetailView.setRate(userPlatSkuDistributeRate.getRate());
  844. }
  845. } else {
  846. DistributeGeneralSkuRate distributeGeneralSkuRate = distributeGeneralSkuRateMapper.selectOne(Wrappers.lambdaQuery(DistributeGeneralSkuRate.class)
  847. .eq(DistributeGeneralSkuRate::getSkuId, ticket.getSkuId())
  848. .last("limit 1"));
  849. if (distributeGeneralSkuRate != null) {
  850. distributePosterGoodsDetailView.setRate(distributeGeneralSkuRate.getRate());
  851. }
  852. }
  853. }
  854. return distributePosterGoodsDetailView;
  855. }
  856. }