GroupRelationFrontServiceImpl.java 42 KB

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