GroupRelationFrontServiceImpl.java 109 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460
  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.ObjectUtil;
  10. import cn.hutool.core.util.StrUtil;
  11. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  12. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  13. import com.cyksj.common.constant.Constant;
  14. import com.cyksj.common.exception.BusinessRuntimeException;
  15. import com.cyksj.common.snowflake.Sequence;
  16. import com.cyksj.common.task.GlobalThreadPoolTaskExecutor;
  17. import com.cyksj.common.util.Jsons;
  18. import com.cyksj.common.util.StringUtil;
  19. import com.cyksj.enums.GatewayApiCode;
  20. import com.cyksj.mapper.*;
  21. import com.cyksj.mapper.manage.distribute.DistributeGeneralSkuRateMapper;
  22. import com.cyksj.mapper.manage.distribute.UserDistributeMapper;
  23. import com.cyksj.mapper.manage.distribute.UserPlatDistributeRateMapper;
  24. import com.cyksj.mapper.manage.distribute.UserPlatSkuDistributeRateMapper;
  25. import com.cyksj.mapper.mirrorshop.UserMirrorShopMapper;
  26. import com.cyksj.mapper.renew.RenewUpgradePackageMapper;
  27. import com.cyksj.mapper.sys.SysConfigMapper;
  28. import com.cyksj.mapper.sys.SysEmailMapper;
  29. import com.cyksj.mapper.vip.VipGoodsSkuMapper;
  30. import com.cyksj.mapper.vip.VipUserMapper;
  31. import com.cyksj.model.dto.ErrorNetflixChangeOtherSkuTicketDto;
  32. import com.cyksj.model.dto.TicketChangeDto;
  33. import com.cyksj.model.entity.*;
  34. import com.cyksj.model.manage.views.AccountView;
  35. import com.cyksj.model.manage.views.GroupsRelationView;
  36. import com.cyksj.model.request.ErrorNetflixChangeReq;
  37. import com.cyksj.model.request.OrderRefundReq;
  38. import com.cyksj.model.request.SpecialGoodsTicketReq;
  39. import com.cyksj.model.request.TicketLoginReq;
  40. import com.cyksj.model.response.NetflixErrorAccountStatus;
  41. import com.cyksj.model.response.NetflixRecoverResp;
  42. import com.cyksj.model.response.NetflixRefundInfoResp;
  43. import com.cyksj.model.views.*;
  44. import com.cyksj.redis.RedisService;
  45. import com.cyksj.service.chatgpt.ChatGptAccountService;
  46. import com.cyksj.service.chatgpt.ChatGptAuthService;
  47. import com.cyksj.service.claude.ClaudeCodeService;
  48. import com.cyksj.service.claude.ClaudeService;
  49. import com.cyksj.service.groups.GroupsFuncService;
  50. import com.cyksj.service.luma.LumaService;
  51. import com.cyksj.service.mail.CommonMailService;
  52. import com.cyksj.service.mail.MailService;
  53. import com.cyksj.service.mange.coupon.CouponCommonService;
  54. import com.cyksj.service.midjourney.MidjourneyAccountService;
  55. import com.cyksj.service.order.OrderRefundService;
  56. import com.cyksj.service.relation.GroupRelationClearService;
  57. import com.cyksj.service.relation.GroupRelationFrontService;
  58. import com.cyksj.service.relation.GroupsRelationChangeService;
  59. import com.cyksj.service.translations.BackInfoTranslationsFrontService;
  60. import com.cyksj.service.user.UserBenefitsService;
  61. import com.cyksj.service.user.UserBindRelationService;
  62. import com.cyksj.service.user.UserLoginRecordService;
  63. import com.ejlchina.searcher.BeanSearcher;
  64. import com.ejlchina.searcher.SearchResult;
  65. import com.ejlchina.searcher.param.Operator;
  66. import com.ejlchina.searcher.util.MapBuilder;
  67. import com.ejlchina.searcher.util.MapUtils;
  68. import com.github.rholder.retry.*;
  69. import lombok.RequiredArgsConstructor;
  70. import lombok.extern.slf4j.Slf4j;
  71. import org.springframework.dao.DuplicateKeyException;
  72. import org.springframework.stereotype.Service;
  73. import org.springframework.transaction.annotation.Transactional;
  74. import javax.servlet.http.HttpServletRequest;
  75. import java.math.BigDecimal;
  76. import java.math.RoundingMode;
  77. import java.util.*;
  78. import java.util.concurrent.ExecutionException;
  79. import java.util.concurrent.TimeUnit;
  80. import java.util.concurrent.atomic.AtomicInteger;
  81. import java.util.stream.Collectors;
  82. import static com.cyksj.enums.GatewayApiCode.GROUP_INDEX_ALREADY_BE_USER;
  83. import static com.cyksj.enums.GatewayApiCode.GROUP_INDEX_NOT_FIND;
  84. /*
  85. *项目名: netflix
  86. *文件名: GroupRelationFrontServiceImpl
  87. *创建者: JavaZou
  88. *创建时间:2022/12/29 15:42
  89. */
  90. @Service
  91. @RequiredArgsConstructor
  92. @Slf4j
  93. public class GroupRelationFrontServiceImpl implements GroupRelationFrontService {
  94. private final UserBindRelationService userBindRelationService;
  95. private final UserMapper userMapper;
  96. private final BeanSearcher beanSearcher;
  97. private final CouponCommonService couponCommonService;
  98. private final GroupsRelationMapper groupsRelationMapper;
  99. private final GroupsMapper groupsMapper;
  100. private final ChatGptAuthService chatGptAuthService;
  101. private final RedisService redisService;
  102. private final MailService mailService;
  103. private final OrderDonMapper orderDonMapper;
  104. private final GroupsRelationExpiryNotifyRecordMapper groupsRelationExpiryNotifyRecordMapper;
  105. private final HttpServletRequest request;
  106. private final GroupsFuncService groupsFuncService;
  107. private final OrderDiscountPlusPurchaseSkuRelationMapper orderDiscountPlusPurchaseSkuRelationMapper;
  108. private final GroupsRelationLoginCodeRecordMapper groupsRelationLoginCodeRecordMapper;
  109. private final SysEmailMapper sysEmailMapper;
  110. private final GoodsDonSkuMapper goodsDonSkuMapper;
  111. private final UserFuncPropertyMapper userFuncPropertyMapper;
  112. private static final GlobalThreadPoolTaskExecutor TASK_EXECUTOR = GlobalThreadPoolTaskExecutor.getInstance();
  113. private final UserLoginRecordService userLoginRecordService;
  114. private final UserCertRecordMapper userCertRecordMapper;
  115. private final MidjourneyAccountService midjourneyAccountService;
  116. private final ChatGptAccountService chatGptAccountService;
  117. private final UpgradePackageMapper upgradePackageMapper;
  118. private final LumaService lumaService;
  119. private final BackInfoTranslationsFrontService backInfoTranslationsFrontService;
  120. private final UserDistributeMapper userDistributeMapper;
  121. private final UserPlatDistributeRateMapper userPlatDistributeRateMapper;
  122. private final GoodsDonMapper goodsDonMapper;
  123. private final UserPlatSkuDistributeRateMapper userPlatSkuDistributeRateMapper;
  124. private final DistributeGeneralSkuRateMapper distributeGeneralSkuRateMapper;
  125. private final RenewUpgradePackageMapper renewUpgradePackageMapper;
  126. private final ClaudeService claudeService;
  127. private final UserDistributePosterRecordMapper userDistributePosterRecordMapper;
  128. private final OrderDonRenewRecordMapper orderDonRenewRecordMapper;
  129. private final AccountMapper accountMapper;
  130. private final UserBenefitsMapper userBenefitsMapper;
  131. private final GroupsRelationChangeService changeTickerRelation;
  132. private final NetflixTempAccountUserMapper netflixTempAccountUserMapper;
  133. private final NetflixUserAccountStatusRecordMapper netflixUserAccountStatusRecordMapper;
  134. private final AccountNetflixStateMapper accountNetflixStateMapper;
  135. private final UserMirrorShopMapper userMirrorShopMapper;
  136. private final CommonMailService commonMailService;
  137. private final SysConfigMapper sysConfigMapper;
  138. private final GptMirrorDayCardGiveawayActivityMapper gptMirrorDayCardGiveawayActivityMapper;
  139. private final MirrorTicketPopupsRecordMapper mirrorTicketPopupsRecordMapper;
  140. private final VipUserMapper vipUserMapper;
  141. private final VipGoodsSkuMapper vipGoodsSkuMapper;
  142. private static final Sequence SEQUENCE = new Sequence(0);
  143. private final NetflixUserChangeOtherTicketRecordMapper netflixUserChangeOtherTicketRecordMapper;
  144. private final NetflixUserAccountSubmitRecoverRecordMapper netflixUserAccountSubmitRecoverRecordMapper;
  145. private final OrderRefundService orderRefundService;
  146. private final GroupRelationClearService clearService;
  147. private final UserBenefitsService userBenefitsService;
  148. private final ChatgptUserMapper chatgptUserMapper;
  149. private final ClaudeCodeUserRenewExpiryRecordMapper claudeCodeUserRenewExpiryRecordMapper;
  150. private final GoodsDonCategoryRelateMapper goodsDonCategoryRelateMapper;
  151. private final ClaudeCodeService claudeCodeService;
  152. private final NanoUserQuotaMapper nanoUserQuotaMapper;
  153. @Override
  154. public SearchResult<RenewalView> getMyTicket(long userId, Boolean isLoginPopularize, String customId, String account, String orderNo, Integer cmt) {
  155. User u = userMapper.selectById(userId);
  156. if (u == null) throw BusinessRuntimeException.getGatewayApiCode(GatewayApiCode.CMS_TOKEN_VALID);
  157. if (u.getIsBlack()) {
  158. return new SearchResult<>();
  159. }
  160. List<Long> userIds = userBindRelationService.getRelationUserIdList(userId, u);
  161. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  162. if (cmt != null && cmt == 2 && StrUtil.isNotBlank(customId)) {
  163. UserMirrorShop userMirrorShop = userMirrorShopMapper.selectOne(Wrappers.lambdaQuery(UserMirrorShop.class)
  164. .eq(UserMirrorShop::getCustomId, customId)
  165. .last("limit 1"));
  166. if (userMirrorShop != null) {
  167. builder.field(RenewalView::getCmt, cmt).field(RenewalView::getYhsId, userMirrorShop.getId());
  168. }
  169. }
  170. if (cmt == null || cmt != 2) {
  171. builder.field(RenewalView::getCmt, 2).op(Operator.NotEqual);
  172. }
  173. // Long yhsId = yhShopFrontService.getYhsIdByCustomId(customId);
  174. DateTime now = DateTime.now();
  175. if (StrUtil.isNotBlank(account)) {
  176. builder.field(RenewalView::getAccount, account).op(Operator.Contain);
  177. }
  178. //代充剩余次数大于0/未发车/过期时间/冻结时
  179. String conditionSql = String.format("(gr.recharge_remain_num > 0 or gr.expiry_time is null or gr.expiry_time > '%s' or gr.is_frozen = true", now);
  180. //镜像车票 过期7天后清除
  181. //个人店铺和AI店铺 暂不支持过期续费
  182. if (cmt == null && StrUtil.isEmpty(customId)) {
  183. conditionSql += String.format(" or (sku.is_mirror and gr.expiry_time > '%s')", DateUtil.offsetDay(now, -7));
  184. }
  185. conditionSql += ")";
  186. if (StrUtil.isNotEmpty(orderNo)) {
  187. OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
  188. .eq(OrderDon::getOrderNo, orderNo)
  189. .notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
  190. .last("limit 1"));
  191. Long orderId = orderDon != null ? orderDon.getId() : 0l;
  192. conditionSql += String.format(" and exists(select 1 from order_don o where o.relation_id = gr.id and o.user_id = gr.user_id and o.id = %s)", orderId);
  193. }
  194. SearchResult<RenewalView> list = beanSearcher.search(RenewalView.class, builder
  195. .field(RenewalView::getUserId, 0).op(Operator.GreaterThan)
  196. .field(RenewalView::getUserId, userIds).op(Operator.InList)
  197. .put("condition", conditionSql)
  198. .field(RenewalView::getStatus, List.of("validity", "overdue", "outside")).op(Operator.InList)
  199. .orderBy(RenewalView::getExpiryTime).asc()
  200. .build());
  201. if (list.getDataList().size() > 0) {
  202. String lang = request.getHeader("lang");
  203. //过滤邀请制、已失效的车位
  204. Integer size = list.getTotalCount().intValue();
  205. //赠送GPT日卡 参与平台ids
  206. List<Long> renewReduceSkuIds = userBenefitsMapper.selectList(Wrappers.lambdaQuery(UserBenefits.class)
  207. .eq(UserBenefits::getType, UserBenefits.Type.RENEW).eq(UserBenefits::getStatus, 1).select(UserBenefits::getSkuId)).stream().map(UserBenefits::getSkuId).collect(Collectors.toList());
  208. List<Long> gptBuyGids = getGptMirrorGiveawayBuyGids();
  209. //gpt日卡活动
  210. GptMirrorDayCardGiveawayActivity gptMirrorDayCardGiveawayActivity = gptMirrorDayCardGiveawayActivityMapper.selectOne(Wrappers.lambdaQuery(GptMirrorDayCardGiveawayActivity.class)
  211. .last("limit 1"));
  212. SysConfig sysConfig = sysConfigMapper.selectOne(Wrappers.lambdaQuery(SysConfig.class)
  213. .eq(SysConfig::getSysKey, Constant.EMAIL_PWD_SHOW_GID_KEY)
  214. .last("limit 1"));
  215. List<Long> showEmailPwdGids = new ArrayList<>();
  216. if (sysConfig != null && StrUtil.isNotBlank(sysConfig.getSysValue())) {
  217. try {
  218. showEmailPwdGids.addAll(Jsons.parseList(sysConfig.getSysValue(), Long.class));
  219. } catch (Exception e) {
  220. }
  221. }
  222. List<Long> vipSkuIds = vipGoodsSkuMapper.selectList(null).stream().map(VipGoodsSku::getSkuId).collect(Collectors.toList());
  223. Set<Long> vipGoodsIds = goodsDonSkuMapper.selectList(Wrappers.lambdaQuery(GoodsDonSku.class)
  224. .in(GoodsDonSku::getId, vipSkuIds)).stream().map(GoodsDonSku::getGoodsId).collect(Collectors.toSet());
  225. Integer vipUserCount = vipUserMapper.selectCount(Wrappers.lambdaQuery(VipUser.class)
  226. .in(VipUser::getUserId, userIds)
  227. .gt(VipUser::getExpiryTime, now));
  228. list.getDataList().forEach(ticket -> {
  229. if (ticket.getSkuId() == null || ticket.getGoodsId() == null) {
  230. return;
  231. }
  232. if (ticket.getGoodsId() == 18 && ticket.getSkuNum() > 1) {
  233. ticket.setPassword(null);
  234. }
  235. ticket.setIsMulti(false);
  236. if (ticket.getSkuNum() > 1) {
  237. ticket.setIsMulti(true);
  238. }
  239. //分类ids
  240. ticket.setCategoryIdList(goodsDonCategoryRelateMapper.selectCategoryIdsByGid(ticket.getGoodsId()));
  241. //chatGPT直连
  242. if (ticket.getGoodsId().equals(42l)) {
  243. if (StrUtil.isNotBlank(ticket.getAccount())) {
  244. String accessToken;
  245. try {
  246. accessToken = chatGptAuthService.getAccessToken(ticket.getAccount());
  247. ticket.setGptRefreshToken(accessToken);
  248. } catch (Exception e) {
  249. redisService.set(RedisService.key.CHAT_GPT_TOKEN_EXCEPTION_KEY.getName() + ticket.getAccount(), ticket.getAccount());
  250. }
  251. }
  252. ticket.setAccount(null);
  253. ticket.setPassword(null);
  254. } else {
  255. ticket.setGptRefreshToken(null);
  256. }
  257. if (ticket.getSecondType() == 1) {
  258. ticket.setAccount(null);
  259. ticket.setPassword(null);
  260. }
  261. //gpt 2月的独立账号可看到邮箱密码
  262. if (ticket.getGoodsId() == 18l && ticket.getSkuNum() == 1 && ticket.getAccount() != null && ticket.getCreatedTime().compareTo(DateUtil.parse("2025-02-01")) > 0) {
  263. } else {
  264. if (!showEmailPwdGids.contains(ticket.getGoodsId())) {
  265. ticket.setGptEmailPwd(null);
  266. }
  267. }
  268. if (isLoginPopularize != null && isLoginPopularize) {
  269. GoodsDonViews views = beanSearcher.searchFirst(GoodsDonViews.class, MapUtils.builder().field(GoodsDonViews::getId, ticket.getGoodsId()).build());
  270. views.setSpecs(beanSearcher.searchFirst(GoodsDonSpecFrontView.class, MapUtils.builder().field(GoodsDonSpecFrontView::getGoodsId, views.getId()).build()));
  271. views.setSkuList(beanSearcher.searchAll(GoodsDonSkuFrontView.class, MapUtils.builder().field(GoodsDonSkuFrontView::getGoodsId, views.getId()).field(GoodsDonSkuFrontView::getStatus, true).build()));
  272. ticket.setGoodsDonViews(views);
  273. }
  274. if (ticket.getMonths() != null && ticket.getMonths() >= 300) {
  275. ticket.setExpiryTime(null);
  276. }
  277. if (ticket.getExpiryTime() != null && ticket.getGoodsType() == 1) {
  278. String remainDays = DateUtil.formatBetween(now, ticket.getExpiryTime(), BetweenFormater.Level.DAY);
  279. if ("0天".equals(remainDays)) {
  280. remainDays = "小于1天";
  281. } else {
  282. //当天也算
  283. int days = Integer.parseInt(remainDays.substring(0, remainDays.indexOf("天")));
  284. remainDays = days + 1 + "天";
  285. }
  286. ticket.setRemainDays(remainDays);
  287. ticket.setTotal(DateUtil.betweenDay(ticket.getStartTime(), ticket.getExpiryTime(), false) + 1);
  288. }
  289. OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
  290. .eq(OrderDon::getRelationId, ticket.getRelationId())
  291. .eq(OrderDon::getUserId, ticket.getUserId())
  292. .eq(OrderDon::getOrderType, 1)
  293. .notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
  294. .orderByDesc(OrderDon::getId)
  295. .last("limit 1"));
  296. if (orderDon != null) {
  297. ticket.setOrderNo(orderDon.getOrderNo());
  298. ticket.setOrderId(orderDon.getId());
  299. ticket.setTransactionId(orderDon.getTransactionId());
  300. if (ticket.getSecondType() == 1) {
  301. //是否完成邀请 根据订单状态
  302. ticket.setIsComplete(orderDon.getStatus() == OrderDon.Status.complete ? true : false);
  303. }
  304. }
  305. if (lang != null && !StrUtil.equals(UserPageLanguage.Language.zh_CN.name(), lang)) {
  306. String languageSpecVal = backInfoTranslationsFrontService.getLanguageSpecVal(ticket.getSkuId(), lang);
  307. if (StrUtil.isNotBlank(languageSpecVal)) {
  308. ticket.setSpecVal(languageSpecVal);
  309. }
  310. }
  311. if (size > 1 && ticket.getGoodsId() != 18) {
  312. Date payTime = null;
  313. if (orderDon != null) {
  314. payTime = Optional.ofNullable(orderDon.getPayTime()).orElse(orderDon.getCreatedTime());
  315. }
  316. //加购订单
  317. if (orderDon == null) {
  318. List<OrderDiscountPlusPurchaseSkuRelation> plusPurchaseSkuRelations = orderDiscountPlusPurchaseSkuRelationMapper.selectPlusRelationByIdAndUserId(ticket.getRelationId(), ticket.getUserId());
  319. for (OrderDiscountPlusPurchaseSkuRelation data : plusPurchaseSkuRelations) {
  320. String relationIds = data.getRelationIds();
  321. if (StrUtil.isEmpty(relationIds)) {
  322. return;
  323. }
  324. try {
  325. List<Long> relationList = Jsons.parseList(relationIds, Long.class);
  326. if (relationList.contains(ticket.getRelationId())) {
  327. OrderDon plusOrder = orderDonMapper.selectById(data.getOrderId());
  328. if (plusOrder != null) {
  329. payTime = Optional.ofNullable(plusOrder.getPayTime()).orElse(plusOrder.getCreatedTime());
  330. }
  331. break;
  332. }
  333. } catch (Exception e) {
  334. }
  335. }
  336. }
  337. ticket.setPayTime(payTime);
  338. }
  339. if (ticket.getSkuNum() != null && ticket.getSkuNum() == 1) {
  340. }
  341. //奈飞、gpt
  342. if (ticket.getGoodsId() == 1 || ticket.getGoodsId() == 18 || ticket.getGoodsId() == 33l) {
  343. ticket.setEmail(null);
  344. }
  345. //设置镜像车票信息
  346. // setMirrorTicketInfo(ticket);
  347. // List<GroupsRelationUserView> relationUserViews = groupsRelationMapper.getUserRelationUserViews(ticket.getGroupId(), ticket.getRelationId(), ticket.getUserId(), List.of(GroupsRelation.Status.validity, GroupsRelation.Status.outside));
  348. // ticket.setRelationViews(relationUserViews);
  349. if (ticket.getExpiryTime() != null) {
  350. ticket.setExpiryTimeStr(DateUtil.format(ticket.getExpiryTime(), "yyyy-MM-dd"));
  351. }
  352. //查看双重验证码
  353. if (StrUtil.isNotEmpty(ticket.getApiSecret())) {
  354. Boolean isHasVerifyCode = StrUtil.isNotBlank(ticket.getVerifyCode()) ? true : false;
  355. Integer codeNum = getUserCodeNumBySkuId(ticket.getUserId(), ticket.getSkuId(), isHasVerifyCode);
  356. ticket.setCodeNum(codeNum);
  357. }
  358. Long qaId = groupsRelationMapper.selectGoodsDonQaByGoodsId(ticket.getGoodsId());
  359. ticket.setQa(qaId > 0 ? true : false);
  360. //是否存在海报
  361. ticket.setPosterInfo(setGoodsPoster(ticket, u, userIds));
  362. //续费升级折扣
  363. BigDecimal renewDiscount = getRenewDiscount(ticket.getGoodsId(), ticket.getSkuId(), ticket.getIsMirror(), ticket.getSkuNum());
  364. ticket.setDiscount(renewDiscount);
  365. if (CollUtil.isNotEmpty(renewReduceSkuIds) && renewReduceSkuIds.contains(ticket.getSkuId())) {
  366. ticket.setIsRenewReduce(true);
  367. }
  368. if (CollUtil.isNotEmpty(gptBuyGids) && gptBuyGids.contains(ticket.getGoodsId())) {
  369. if (gptMirrorDayCardGiveawayActivity != null && orderDon != null && orderDon.getCreatedTime().compareTo(gptMirrorDayCardGiveawayActivity.getCreatedTime()) > 0) {
  370. //是否领取过GPT日卡
  371. Long orderId = orderDon.getId();
  372. Number count = beanSearcher.searchCount(GptMirrorDayCardActivityRecord.class, MapUtils.builder().field(GptMirrorDayCardActivityRecord::getOrderId, orderId).build());
  373. ticket.setReceivedGptGift(count.intValue() > 0);
  374. }
  375. }
  376. markVipDeductTicket(userIds, ticket, vipGoodsIds, vipUserCount > 0);
  377. });
  378. }
  379. userLoginRecordService.saveUserLoginDayRecord(userId);
  380. return list;
  381. }
  382. @Override
  383. public Boolean isJoinCorpWx(Long userId, Boolean isJoin, Boolean noCoupon) {
  384. if (!isJoin) {
  385. User user = userMapper.selectById(userId);
  386. if (user == null || StrUtil.isEmpty(user.getUnionid())) {
  387. return true;
  388. }
  389. // CorpUser corpUser = corpUserMapper.selectOne(Wrappers.lambdaQuery(CorpUser.class)
  390. // .ne(CorpUser::getUnionid, "")
  391. // .eq(CorpUser::getUnionid, user.getUnionid())
  392. // .last("limit 1")
  393. // .select(CorpUser::getId)
  394. // );
  395. CorpUserFollowView corpUserFollowView = beanSearcher.searchFirst(CorpUserFollowView.class, MapUtils.builder()
  396. .field(CorpUserFollowView::getUnionId, user.getUnionid())
  397. .field(CorpUserFollowView::getStatus, 1).build());
  398. if (corpUserFollowView == null) {
  399. return false;
  400. }
  401. }
  402. //用户是否买了奈飞车票
  403. Number number = beanSearcher.searchCount(RenewalView.class, MapUtils.builder()
  404. .field(RenewalView::getUserId, userId)
  405. .field(RenewalView::getGoodsId, 1)
  406. .field(RenewalView::getStatus, List.of("validity", "overdue")).op(Operator.InList)
  407. .build());
  408. if (number.intValue() > 0 && !noCoupon) {
  409. couponCommonService.sendCouponToUser(userId, 34l, 0l, 0l, 0l, CouponUser.Channel.wxCorp);
  410. }
  411. return true;
  412. }
  413. @Override
  414. public GroupsRelation getSimilarExpiredGroupRelation(GoodsDonSku sku, List<Long> errorsRelationIds, String ip) {
  415. Long skuId = sku.getId();
  416. Integer days = sku.getDays();
  417. Integer months = sku.getMonths();
  418. Integer maxNum = sku.getNum();
  419. DateTime expiryTime = null;
  420. if (days != null && days > 0) {
  421. expiryTime = DateUtil.offsetDay(DateTime.now(), days);
  422. } else {
  423. expiryTime = DateUtil.offsetMonth(DateTime.now(), months);
  424. }
  425. Integer extraNum = 5;
  426. if (sku.getId() == 178l) {
  427. extraNum = 2;
  428. }
  429. maxNum += extraNum;
  430. DateTime minExpiryTime = DateUtil.offsetDay(expiryTime, -5);
  431. Long groupsId = groupsRelationMapper.selectSimilarExpiredRelation(skuId, minExpiryTime, maxNum, ip);
  432. if (groupsId == null) {
  433. log.info("暂无相似过期时间车队");
  434. return null;
  435. }
  436. GroupsRelation relation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
  437. .notIn(errorsRelationIds != null && errorsRelationIds.size() > 0, GroupsRelation::getId, errorsRelationIds)
  438. .eq(GroupsRelation::getGroupsId, groupsId)
  439. .eq(GroupsRelation::getStatus, GroupsRelation.Status.none)
  440. .eq(GroupsRelation::getUserId, 0)
  441. .orderByAsc(GroupsRelation::getNum)
  442. .last("limit 1"));
  443. if (relation != null) {
  444. log.info("用户userId:{},获取相似车队的车位relationId:{}", relation.getId());
  445. }
  446. return relation;
  447. }
  448. @Override
  449. public Page<UserRecommendGoodsFrontView> getRecommendGoodsViews(List<Long> yhShopGoodsIds, Boolean isPayNf, List<Long> filter_goods_id, Boolean filterCourseGoods, Integer start, Integer limit) {
  450. return groupsRelationMapper.getRecommendGoodsViews(new Page<>(start, limit), filter_goods_id, isPayNf, filterCourseGoods, yhShopGoodsIds);
  451. }
  452. @Override
  453. @Transactional(rollbackFor = Throwable.class)
  454. public void sendCourseWare(SpecialGoodsTicketReq request) throws Exception {
  455. Long userId = request.getUserId();
  456. Long relationId = request.getRelationId();
  457. String email = request.getEmail();
  458. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  459. RenewalView relation = beanSearcher.searchFirst(RenewalView.class, MapUtils.builder().field(RenewalView::getRelationId, relationId).build());
  460. Assert.notNull(relation, "您的车票不存在");
  461. Long relationUserId = relation.getUserId();
  462. if (!userIdList.contains(relationUserId)) {
  463. throw BusinessRuntimeException.getInstance("您的车票不存在");
  464. }
  465. if (relation.getSpecialType() != GoodsDon.SpecialType.courseware) {
  466. throw BusinessRuntimeException.getInstance("");
  467. }
  468. //是否已发送
  469. if (StrUtil.isNotBlank(relation.getGrAccount())) {
  470. throw BusinessRuntimeException.getInstance("已领取课件,请前往邮箱查看");
  471. }
  472. if (!Validator.isEmail(email)) {
  473. throw BusinessRuntimeException.getInstance("请输入正确的邮箱");
  474. }
  475. int update = groupsRelationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
  476. .set(GroupsRelation::getAccount, email)
  477. .and(qr -> qr.isNull(GroupsRelation::getAccount).or().eq(GroupsRelation::getAccount, StrUtil.EMPTY))
  478. .eq(GroupsRelation::getId, relationId));
  479. if (update > 0) {
  480. orderDonMapper.update(null, Wrappers.lambdaUpdate(OrderDon.class)
  481. .set(OrderDon::getStatus, OrderDon.Status.complete)
  482. .eq(OrderDon::getRelationId, relationId)
  483. .eq(OrderDon::getUserId, userId)
  484. .eq(OrderDon::getStatus, OrderDon.Status.hasPayment));
  485. mailService.sendCoursewareByGoodsId(relation.getGoodsId(), relation.getRelationId(), relation.getUserId(), relation.getTitle(), email);
  486. }
  487. }
  488. @Override
  489. public GroupsRelation getRelation(Long payRelationId, Long userId, GoodsDonSku sku, String ip) {
  490. GroupsRelation relation = null;
  491. Integer maxNum = sku.getNum();
  492. if (payRelationId != null && payRelationId > 0) {
  493. relation = groupsRelationMapper.selectById(payRelationId);
  494. if (relation == null) {
  495. throw new BusinessRuntimeException(GROUP_INDEX_NOT_FIND.getCode(), GROUP_INDEX_NOT_FIND.getMsg());
  496. }
  497. if (relation.getUserId() != null && relation.getUserId() > 0L) {
  498. throw new BusinessRuntimeException(GROUP_INDEX_ALREADY_BE_USER.getCode(), GROUP_INDEX_ALREADY_BE_USER.getMsg());
  499. }
  500. } else {
  501. GroupsTrips groups = null;
  502. //ChatGpt Plus、Midjourney非独立规格 上车先获取硬塞座位 硬塞5个座位
  503. //主账号过期时间25天以外
  504. //23-12-06 MidJourney 不硬塞
  505. if (sku.getNum() > 1 && Constant.AI_goodsIds.get(0) == sku.getGoodsId()) {
  506. Integer extraNum = 5;
  507. if (sku.getId() == 178l || sku.getId() == 423l) {
  508. extraNum = 2;
  509. }
  510. maxNum += extraNum;
  511. DateTime time = DateUtil.offsetDay(DateUtil.beginOfDay(DateTime.now()), 25);
  512. //不塞存在该用户的车队
  513. Long groupsId = groupsRelationMapper.getOutSideGroupsTripsRelationByGoodsId(sku.getId(), time, extraNum, userId, sku.getNum(), maxNum);
  514. if (groupsId != null) {
  515. relation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
  516. .eq(GroupsRelation::getGroupsId, groupsId)
  517. .eq(GroupsRelation::getUserId, 0)
  518. .eq(GroupsRelation::getStatus, GroupsRelation.Status.outside)
  519. .last("limit 1"));
  520. if (relation == null) {
  521. relation = new GroupsRelation();
  522. relation.setStatus(GroupsRelation.Status.outside);
  523. relation.setGroupsId(groupsId);
  524. GroupsRelation maxNumRelation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class).eq(GroupsRelation::getGroupsId, groupsId).orderByDesc(GroupsRelation::getNum).last("limit 1"));
  525. Integer nextNum = maxNumRelation.getNum() + 1;
  526. if (redisService.setNx(RedisService.key.GROUPS_TRIPS_OUTSIDE_RELATION.getNameFormat(groupsId, nextNum), nextNum, RedisService.key.GROUPS_TRIPS_OUTSIDE_RELATION.getTimeout())) {
  527. relation.setNum(nextNum);
  528. groupsRelationMapper.insert(relation);
  529. } else {
  530. throw BusinessRuntimeException.getInstance("系统繁忙,请重试...");
  531. }
  532. }
  533. groups = groupsMapper.selectById(groupsId);
  534. }
  535. }
  536. if (groups == null) {
  537. //寻找差不多过期时间规格的车位
  538. relation = getSimilarExpiredGroupRelation(sku, null, ip);
  539. if (relation == null) {
  540. //TODO 如果没指定座位,等待逻辑确认
  541. DateTime filterAccountTime = null;
  542. //奈飞过滤6月23号之前的车队
  543. if (sku.getGoodsId() == Constant.NETFLIX_GID) {
  544. filterAccountTime = DateUtil.parse("2025-06-23");
  545. }
  546. groups = groupsMapper.selectTicketGroups(sku.getId(), GroupsTrips.Status.validity, maxNum, ip, filterAccountTime);
  547. if (groups == null) {
  548. //待发车
  549. groups = groupsMapper.selectTicketGroups(sku.getId(), GroupsTrips.Status.waiting, maxNum, ip, null);
  550. }
  551. //新增空车队
  552. if (groups == null) {
  553. relation = groupsFuncService.createNewGroupsTrips(sku);
  554. }
  555. //获取车位
  556. if (relation == null) {
  557. //寻找快满编车队进行占座
  558. relation = groupsRelationMapper.selectRandomOneRelationByGroupsId(groups.getId());
  559. if (relation == null) {
  560. Long groupsId = groups.getId();
  561. TASK_EXECUTOR.execute(() -> groupsMapper.updateAvailableNum(groupsId));
  562. throw BusinessRuntimeException.getInstance("系统繁忙,请重试...");
  563. }
  564. }
  565. }
  566. }
  567. if (groups == null) {
  568. groups = groupsMapper.selectById(relation.getGroupsId());
  569. }
  570. //车队目前可用停车数
  571. relation.setGroupsAvailParkingNum(groups.getAvailableParkingNum());
  572. relation.setMaxNum(maxNum);
  573. }
  574. return relation;
  575. }
  576. @Override
  577. public String getAiVerifyCode(TicketLoginReq loginReq) throws Exception {
  578. Integer type = loginReq.getType();
  579. RenewalView renewalView;
  580. String account;
  581. Long userId = 0l;
  582. Long relationId = 0l;
  583. if (loginReq.getMerchants()) {
  584. renewalView = new RenewalView();
  585. renewalView.setGoodsId(loginReq.getGoodsId());
  586. renewalView.setAccount(loginReq.getAccount());
  587. if (loginReq.getAccountId() != null && loginReq.getAccountId() != 0l) {
  588. GroupsTrips groupsTrips = groupsMapper.selectOne(Wrappers.lambdaQuery(GroupsTrips.class)
  589. .eq(GroupsTrips::getAccountId, loginReq.getAccountId())
  590. .last("limit 1"));
  591. if (groupsTrips != null) {
  592. renewalView.setSkuId(groupsTrips.getSkuId());
  593. }
  594. }
  595. renewalView.setUserId(userId);
  596. account = loginReq.getAccount();
  597. } else {
  598. userId = loginReq.getUserId();
  599. relationId = loginReq.getRelationId();
  600. List<Long> relationUserIdList = userBindRelationService.getRelationUserIdList(userId, null);
  601. renewalView = beanSearcher.searchFirst(RenewalView.class, MapUtils.builder().field(RenewalView::getUserId, relationUserIdList).op(Operator.InList)
  602. .field(RenewalView::getRelationId, relationId).build());
  603. if (renewalView == null) {
  604. throw BusinessRuntimeException.getInstance("您的车票不存在...");
  605. }
  606. if (StrUtil.isEmpty(renewalView.getAccount())) {
  607. throw BusinessRuntimeException.getInstance("车票未配置账号");
  608. }
  609. account = renewalView.getAccount();
  610. String password = renewalView.getPassword();
  611. if (StrUtil.hasEmpty(account, password)) {
  612. throw BusinessRuntimeException.getInstance("您的车票账号密码异常,请联系客服...");
  613. }
  614. }
  615. if (renewalView.getGoodsId() == 1l) {
  616. Integer linkType = loginReq.getLinkType();
  617. if (type == null && linkType == null) {
  618. throw BusinessRuntimeException.getInstance("系统异常");
  619. }
  620. if (linkType != null) {
  621. String key = RedisService.key.NF_UPGRAD_USER_LIMIT_KEY.getNameFormat(DateUtil.hour(DateTime.now(), true), linkType, renewalView.getUserId());
  622. if (!redisService.hasKey(key)) {
  623. redisService.set(key, 0l, RedisService.key.NF_UPGRAD_USER_LIMIT_KEY.getTimeout());
  624. } else {
  625. Integer value = (Integer) redisService.get(key);
  626. if (value >= 5) {
  627. throw BusinessRuntimeException.getInstance("获取奈飞同步更新装置过于频繁");
  628. }
  629. }
  630. }
  631. }
  632. String code = commonMailService.getTicketMailCode(renewalView.getGoodsId(), account, renewalView.getRelateEmail(), renewalView.getGptEmailPwd(), renewalView.getCreatedTime(), type, loginReq.getLinkType(), false);
  633. GroupsRelationLoginCodeRecord record = new GroupsRelationLoginCodeRecord();
  634. record.setUserId(userId);
  635. record.setRelationId(relationId);
  636. record.setAccount(renewalView.getAccount());
  637. record.setGoodsId(renewalView.getGoodsId());
  638. record.setSkuId(renewalView.getSkuId());
  639. groupsRelationLoginCodeRecordMapper.insert(record);
  640. //奈飞同步装置
  641. if (renewalView.getGoodsId() == 1l && loginReq.getLinkType() != null) {
  642. String key = RedisService.key.NF_UPGRAD_USER_LIMIT_KEY.getNameFormat(DateUtil.hour(DateTime.now(), true), loginReq.getLinkType(), renewalView.getUserId());
  643. redisService.incr(key, 1L);
  644. }
  645. return code;
  646. }
  647. @Override
  648. public void checkGroupsAvailParkingNum(Long skuId, Long groupsId, Integer availableParkingNum, Integer maxNum) {
  649. //GPT10人月付、4人月付
  650. if (skuId == 161l || skuId == 178l) {
  651. //为0时,不参与限制
  652. if (availableParkingNum == 0) {
  653. return;
  654. }
  655. //目前车队可用停车数
  656. //目前上车人数
  657. Integer currentParkingNum = groupsRelationMapper.selectCount(Wrappers.lambdaQuery(GroupsRelation.class)
  658. .eq(GroupsRelation::getGroupsId, groupsId)
  659. .ne(GroupsRelation::getUserId, 0)
  660. .le(GroupsRelation::getNum, maxNum));
  661. if (currentParkingNum > availableParkingNum) {
  662. throw BusinessRuntimeException.getInstance("系统繁忙,请重试...");
  663. }
  664. }
  665. }
  666. @Override
  667. public void adjustGroupsParkingTime(Long relationId, GoodsDonSku sku) {
  668. if (sku == null) {
  669. return;
  670. }
  671. Long skuId = sku.getId();
  672. //更新GPT Plus10人、4人月付车队状态 待优化
  673. if (skuId == 161l || skuId == 178l || skuId == 422l || skuId == 423l) {
  674. GroupsRelation relation = groupsRelationMapper.selectById(relationId);
  675. Long groupsId = relation.getGroupsId();
  676. GroupsTrips groupsTrips = groupsMapper.selectById(groupsId);
  677. Integer availableParkingNum = groupsTrips.getAvailableParkingNum();
  678. //为0时 不参与限制
  679. if (availableParkingNum == 0) {
  680. return;
  681. }
  682. Integer extraNum = 5;
  683. if (skuId == 178l || skuId == 423l) {
  684. extraNum = 2;
  685. }
  686. Integer maxNum = sku.getNum() + extraNum;
  687. if (availableParkingNum >= maxNum) {
  688. return;
  689. }
  690. //目前上车人数
  691. Integer currentParkingNum = groupsRelationMapper.selectCount(Wrappers.lambdaQuery(GroupsRelation.class)
  692. .eq(GroupsRelation::getGroupsId, groupsId)
  693. .ne(GroupsRelation::getUserId, 0)
  694. .le(GroupsRelation::getNum, maxNum));
  695. if (currentParkingNum >= availableParkingNum) {
  696. //锁住
  697. DateTime parkingTime = DateUtil.offsetDay(DateTime.now(), 1);
  698. groupsMapper.update(null, Wrappers.lambdaUpdate(GroupsTrips.class)
  699. .eq(GroupsTrips::getId, groupsTrips.getId())
  700. .set(GroupsTrips::getParkingTime, parkingTime)
  701. .isNull(GroupsTrips::getParkingTime));
  702. }
  703. }
  704. }
  705. @Override
  706. public void setGroupsTripsParkingTimeEmpty(GoodsDonSku sku, Long relationId) {
  707. if (sku == null) {
  708. return;
  709. }
  710. Long skuId = sku.getId();
  711. if (skuId == 161l || skuId == 178l) {
  712. GroupsRelation relation = groupsRelationMapper.selectById(relationId);
  713. Long groupsId = relation.getGroupsId();
  714. GroupsTrips groupsTrips = groupsMapper.selectById(groupsId);
  715. Integer availableParkingNum = groupsTrips.getAvailableParkingNum();
  716. if (groupsTrips.getParkingTime() == null || availableParkingNum == 0) {
  717. return;
  718. }
  719. Integer extraNum = 5;
  720. if (skuId == 178l) {
  721. extraNum = 2;
  722. }
  723. Integer skuNum = sku.getNum();
  724. if (availableParkingNum >= skuNum + extraNum) {
  725. return;
  726. }
  727. //目前上车人数
  728. Integer currentParkingNum = groupsRelationMapper.selectCount(Wrappers.lambdaQuery(GroupsRelation.class)
  729. .eq(GroupsRelation::getGroupsId, groupsId)
  730. .ne(GroupsRelation::getUserId, 0));
  731. if (currentParkingNum < availableParkingNum) {
  732. groupsMapper.update(null, Wrappers.lambdaUpdate(GroupsTrips.class)
  733. .eq(GroupsTrips::getId, groupsTrips.getId())
  734. .set(GroupsTrips::getParkingTime, null)
  735. .isNotNull(GroupsTrips::getParkingTime));
  736. }
  737. }
  738. }
  739. @Override
  740. public Integer getUserCodeNumBySkuId(Long userId, Long skuId, Boolean isHasVerifyCode) {
  741. //查看双重验证码
  742. UserFuncProperty userFuncProperty = userFuncPropertyMapper.selectOne(Wrappers.lambdaQuery(UserFuncProperty.class).eq(UserFuncProperty::getUserId, userId).last("limit 1"));
  743. //默认2次
  744. int num = 2;
  745. //有安全码查看次数 置为0
  746. if (isHasVerifyCode) {
  747. num = 0;
  748. //存在身份实名认证有两次机会
  749. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  750. Integer selectCount = userCertRecordMapper.selectCount(Wrappers.lambdaQuery(UserCertRecord.class)
  751. .in(UserCertRecord::getUserId, userIdList));
  752. if (selectCount > 0) {
  753. num = 2;
  754. }
  755. return num;
  756. }
  757. //查看双重验证码次数
  758. GoodsDonSku sku = goodsDonSkuMapper.selectById(skuId);
  759. if (sku.getCodeNum() > 0) {
  760. num = sku.getCodeNum();
  761. }
  762. if (userFuncProperty != null) num = userFuncProperty.getVerifyCheckNum();
  763. return num;
  764. }
  765. @Override
  766. public List<RenewalView> getHasPayGoods(long userId) {
  767. User user = userMapper.selectById(userId);
  768. List<Long> userIds = userBindRelationService.getRelationUserIdList(userId, user);
  769. DateTime now = DateTime.now();
  770. List<RenewalView> list = groupsRelationMapper.getUserHasPayGoods(userIds, now);
  771. return list;
  772. }
  773. @Override
  774. public List<RenewalView> getExpiryRenewalNotify(Long userId) {
  775. DateTime now = DateTime.now();
  776. DateTime thisZero = DateUtil.beginOfDay(now);
  777. String thisDate = thisZero.toDateStr();
  778. Object exists = redisService.get(RedisService.key.TICKET_EXPIRY_NOTIFY_DAY.getNameFormat(thisDate, userId));
  779. if (exists != null) {
  780. return null;
  781. }
  782. User u = userMapper.selectById(userId);
  783. if (u == null) throw BusinessRuntimeException.getGatewayApiCode(GatewayApiCode.CMS_TOKEN_VALID);
  784. if (u.getIsBlack()) {
  785. redisService.setNx(RedisService.key.TICKET_EXPIRY_NOTIFY_DAY.getNameFormat(thisDate, userId), userId, RedisService.key.TICKET_EXPIRY_NOTIFY_DAY.getTimeout());
  786. return null;
  787. }
  788. List<Long> userIds = userBindRelationService.getRelationUserIdList(userId, u);
  789. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  790. List<RenewalView> list = beanSearcher.searchAll(RenewalView.class, builder
  791. .field(RenewalView::getUserId, 0).op(Operator.GreaterThan)
  792. .field(RenewalView::getUserId, userIds).op(Operator.InList)
  793. .field(RenewalView::getExpiryTime, now).op(Operator.GreaterThan)
  794. .field(RenewalView::getStatus, List.of("validity", "overdue", "outside")).op(Operator.InList)
  795. .field(RenewalView::getAqType, 1)
  796. .field(RenewalView::getIsVip, Boolean.TRUE)
  797. .orderBy(RenewalView::getExpiryTime).asc()
  798. .build());
  799. if (list.size() > 5) {
  800. redisService.setNx(RedisService.key.TICKET_EXPIRY_NOTIFY_DAY.getNameFormat(thisDate, userId), userId, RedisService.key.TICKET_EXPIRY_NOTIFY_DAY.getTimeout());
  801. return null;
  802. }
  803. List<Long> renewReduceSkuIds = userBenefitsMapper.selectList(Wrappers.lambdaQuery(UserBenefits.class)
  804. .eq(UserBenefits::getType, UserBenefits.Type.RENEW).eq(UserBenefits::getStatus, 1).select(UserBenefits::getSkuId)).stream().map(UserBenefits::getSkuId).collect(Collectors.toList());
  805. //提前7天
  806. AtomicInteger day = new AtomicInteger(7);
  807. List<RenewalView> expiryTickets = list.stream().filter(ticket -> {
  808. //下架
  809. if (ticket.getGoodsStatus() == null || ticket.getSkuStatus() == null || !ticket.getGoodsStatus() || !ticket.getSkuStatus()) {
  810. return false;
  811. }
  812. Integer skuMonths = ticket.getMonths();
  813. if (skuMonths == null) {
  814. return false;
  815. }
  816. Date expiryTime = ticket.getExpiryTime();
  817. //年付 提前一个月
  818. if (skuMonths >= 12) {
  819. day.set(30);
  820. } else {
  821. day.set(7);
  822. }
  823. if (DateUtil.beginOfDay(expiryTime).compareTo(DateUtil.offsetDay(thisZero, day.get())) <= 0) {
  824. ticket.setExpiryTimeStr(DateUtil.format(ticket.getExpiryTime(), "yyyy-MM-dd"));
  825. //GPT镜像信息
  826. setGptMirrorInfo(ticket);
  827. ticket.setExpiryTime(null);
  828. if (CollUtil.isNotEmpty(renewReduceSkuIds) && renewReduceSkuIds.contains(ticket.getSkuId())) {
  829. ticket.setIsRenewReduce(true);
  830. }
  831. return true;
  832. }
  833. return false;
  834. }).collect(Collectors.toList());
  835. redisService.setNx(RedisService.key.TICKET_EXPIRY_NOTIFY_DAY.getNameFormat(thisDate, userId), userId, RedisService.key.TICKET_EXPIRY_NOTIFY_DAY.getTimeout());
  836. if (CollUtil.isNotEmpty(expiryTickets)) {
  837. groupsRelationExpiryNotifyRecordMapper.batchInsert(userId, expiryTickets);
  838. }
  839. return expiryTickets;
  840. }
  841. @Override
  842. public void getCollegeStudentUserGptTicket(Long userId) {
  843. Retryer<Boolean> build = RetryerBuilder.<Boolean>newBuilder()
  844. .retryIfException()
  845. //运行时异常重试
  846. .retryIfRuntimeException()
  847. //false重试
  848. .retryIfResult(res -> Objects.equals(res, false))
  849. //1s 间隔
  850. .withWaitStrategy(WaitStrategies.fixedWait(1, TimeUnit.SECONDS))
  851. //停止策略 : 尝试请求3次
  852. .withStopStrategy(StopStrategies.stopAfterAttempt(3)).build();
  853. try {
  854. build.call(() -> {
  855. //体验规格
  856. Long gptMirrorSkuId = Constant.GPT_MIRROR_SKU_ID;
  857. GroupsTrips groups = groupsMapper.selectCollegeStudentUserGptTicket(gptMirrorSkuId);
  858. if (groups == null) {
  859. groups = groupsMapper.selectOne(Wrappers.lambdaQuery(GroupsTrips.class)
  860. .eq(GroupsTrips::getStatus, GroupsTrips.Status.waiting)
  861. .eq(GroupsTrips::getSkuId, gptMirrorSkuId)
  862. .last("limit 1"));
  863. }
  864. GroupsRelation relation = null;
  865. if (groups != null) {
  866. relation = groupsRelationMapper.selectRandomOneRelationByGroupsId(groups.getId());
  867. }
  868. if (relation == null) {
  869. //生成空车队
  870. GoodsDonSku sku = goodsDonSkuMapper.selectById(gptMirrorSkuId);
  871. relation = groupsFuncService.createNewGroupsTrips(sku);
  872. }
  873. DateTime startTime = DateTime.now();
  874. DateTime expiryTime = DateUtil.offsetDay(startTime, 1);
  875. int update = groupsRelationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
  876. .set(GroupsRelation::getUserId, userId)
  877. .set(GroupsRelation::getStartTime, startTime)
  878. .set(GroupsRelation::getExpiryTime, expiryTime)
  879. .set(GroupsRelation::getStatus, GroupsRelation.Status.validity)
  880. .set(GroupsRelation::getAqType, 2)
  881. .eq(GroupsRelation::getId, relation.getId())
  882. .eq(GroupsRelation::getUserId, 0));
  883. if (update > 0) {
  884. groupsMapper.decrAvailableNum(relation.getGroupsId());
  885. return true;
  886. }
  887. log.error("发送用户:{} GPT镜像车票体验失败,进行重试", userId);
  888. return false;
  889. });
  890. } catch (ExecutionException | RetryException e) {
  891. log.error("发送用户GPT镜像体验失败:{}", StringUtil.getErrorText(e));
  892. }
  893. }
  894. @Override
  895. public RenewalView getTicketDetail(long userId, Long relationId) {
  896. User u = userMapper.selectById(userId);
  897. List<Long> userIds = userBindRelationService.getRelationUserIdList(userId, u);
  898. MapBuilder builder = MapUtils.builder();
  899. RenewalView renewalView = beanSearcher.searchFirst(RenewalView.class, builder
  900. .field(RenewalView::getRelationId, relationId)
  901. .field(RenewalView::getUserId, 0).op(Operator.GreaterThan)
  902. .field(RenewalView::getUserId, userIds).op(Operator.InList)
  903. .field("condition", String.format("(gr.expiry_time is null or gr.expiry_time > '%s')", DateTime.now()))
  904. .field(RenewalView::getStatus, List.of("validity", "outside")).op(Operator.InList)
  905. .orderBy(RenewalView::getExpiryTime).asc()
  906. .onlySelect(RenewalView::getRelationId, RenewalView::getExpiryTime, RenewalView::getTitle, RenewalView::getSpecVal, RenewalView::getGoodsId, RenewalView::getSkuId, RenewalView::getSkuNum, RenewalView::getSkuStatus, RenewalView::getGoodsStatus)
  907. .build());
  908. if (renewalView != null) {
  909. renewalView.setExpiryTimeStr(DateUtil.format(renewalView.getExpiryTime(), "yyyy-MM-dd"));
  910. }
  911. return renewalView;
  912. }
  913. @Override
  914. public GroupsRelation ticketLogin(TicketLoginReq loginReq) {
  915. String account = loginReq.getAccount();
  916. if (StrUtil.isEmpty(account)) {
  917. throw BusinessRuntimeException.getInstance("请输入对应账号");
  918. }
  919. if (loginReq.getMerchants()) {
  920. if (account.contains(Constant.YH_EMAIL_DOMAIN_SUFFIX)) {
  921. SysEmail sysEmail = sysEmailMapper.selectOne(Wrappers.lambdaQuery(SysEmail.class)
  922. .eq(SysEmail::getEmail, account)
  923. .last("limit 1"));
  924. if (sysEmail == null) {
  925. throw BusinessRuntimeException.getInstance("账号错误,请联系客服");
  926. }
  927. }
  928. GroupsRelation relation = new GroupsRelation();
  929. relation.setId(0l);
  930. return relation;
  931. }
  932. String password = loginReq.getPassword();
  933. Integer num = loginReq.getNum();
  934. if (ObjectUtil.hasEmpty(password, num)) {
  935. throw BusinessRuntimeException.getInstance("参数错误");
  936. }
  937. Long goodsId = Optional.ofNullable(loginReq.getGoodsId()).orElse(1l);
  938. GroupsRelation relation = groupsRelationMapper.selectRelationByAccountAndNum(account, password, goodsId, num);
  939. if (relation == null) {
  940. log.info("外部入口使用账号account:{},pwd:{},座位num:{}登录失败...", account, password, num);
  941. if (StrUtil.equals(loginReq.getLang(), Constant.EN_US)) {
  942. throw BusinessRuntimeException.getInstance("Please enter the correct account information");
  943. }
  944. throw BusinessRuntimeException.getInstance("请输入正确的账号信息");
  945. }
  946. return relation;
  947. }
  948. @Override
  949. public String outsideTicketVerify(TicketLoginReq loginReq) {
  950. String account = loginReq.getAccount();
  951. if (StrUtil.isEmpty(account)) {
  952. throw BusinessRuntimeException.getInstance("账号错误");
  953. }
  954. if (loginReq.getMerchants()) {
  955. if (account.contains(Constant.YH_EMAIL_DOMAIN_SUFFIX)) {
  956. SysEmail sysEmail = sysEmailMapper.selectOne(Wrappers.lambdaQuery(SysEmail.class)
  957. .eq(SysEmail::getEmail, account)
  958. .last("limit 1"));
  959. if (sysEmail == null) {
  960. throw BusinessRuntimeException.getInstance("账号错误,请联系客服");
  961. }
  962. }
  963. loginReq.setGoodsId(1l);
  964. loginReq.setAccountId(0l);
  965. } else {
  966. String password = loginReq.getPassword();
  967. Integer num = loginReq.getNum();
  968. if (ObjectUtil.hasEmpty(password, num)) {
  969. throw BusinessRuntimeException.getInstance("参数错误");
  970. }
  971. Long goodsId = Optional.ofNullable(loginReq.getGoodsId()).orElse(1l);
  972. GroupsRelation relation = groupsRelationMapper.selectRelationByAccountAndNum(account, password, goodsId, num);
  973. if (relation == null) {
  974. log.info("外部入口使用账号account:{},pwd:{},座位num:{}同步验证链接失败...", account, password, num);
  975. if (StrUtil.equals(loginReq.getLang(), Constant.EN_US)) {
  976. throw BusinessRuntimeException.getInstance("This account is no longer valid");
  977. }
  978. throw BusinessRuntimeException.getInstance("该账号已失效");
  979. }
  980. loginReq.setUserId(relation.getUserId());
  981. loginReq.setRelationId(relation.getId());
  982. loginReq.setGoodsId(goodsId);
  983. }
  984. try {
  985. String aiVerifyCode = getAiVerifyCode(loginReq);
  986. if (StrUtil.isEmpty(aiVerifyCode)) {
  987. throw BusinessRuntimeException.getInstance("");
  988. }
  989. return aiVerifyCode;
  990. } catch (Exception e) {
  991. if (StrUtil.equals(loginReq.getLang(), Constant.EN_US)) {
  992. throw BusinessRuntimeException.getInstance("Please verify that the link was sent");
  993. }
  994. throw BusinessRuntimeException.getInstance("请校验链接是否已发送");
  995. }
  996. }
  997. @Override
  998. public String getNfHouseholdDevice(long userId, Long relationId) throws Exception {
  999. List<Long> relationUserIdList = userBindRelationService.getRelationUserIdList(userId, null);
  1000. RenewalView renewalView = beanSearcher.searchFirst(RenewalView.class, MapUtils.builder().field(RenewalView::getUserId, relationUserIdList).op(Operator.InList)
  1001. .field(RenewalView::getRelationId, relationId).build());
  1002. if (renewalView == null) {
  1003. throw BusinessRuntimeException.getInstance("您的车票不存在...");
  1004. }
  1005. if (StrUtil.isEmpty(renewalView.getAccount())) {
  1006. throw BusinessRuntimeException.getInstance("车票未配置账号");
  1007. }
  1008. String account = renewalView.getAccount();
  1009. String password = renewalView.getPassword();
  1010. if (StrUtil.hasEmpty(account, password)) {
  1011. throw BusinessRuntimeException.getInstance("您的车票账号密码异常,请联系客服...");
  1012. }
  1013. String code = commonMailService.getTicketMailCode(renewalView.getGoodsId(), account, renewalView.getRelateEmail(), renewalView.getGptEmailPwd(), renewalView.getCreatedTime(), null, 1, true);
  1014. return code;
  1015. }
  1016. @Override
  1017. public String getVerifyCode(String account) throws Exception {
  1018. Account at = accountMapper.selectOne(Wrappers.lambdaQuery(Account.class)
  1019. .eq(Account::getAccount, account)
  1020. .eq(Account::getGoodsId, 18));
  1021. if (at == null) {
  1022. return null;
  1023. }
  1024. String password = at.getPassword();
  1025. if (StrUtil.hasEmpty(account, password)) {
  1026. throw BusinessRuntimeException.getInstance("账号异常");
  1027. }
  1028. String code = commonMailService.getTicketMailCode(at.getGoodsId(), account, at.getRelateEmail(), at.getGptEmailPwd(), at.getCreatedTime(), null, null, false);
  1029. return code;
  1030. }
  1031. @Override
  1032. public void changeTicket(long userId, Long relationId) {
  1033. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  1034. RenewalView renewalView = beanSearcher.searchFirst(RenewalView.class, MapUtils.builder()
  1035. .field(RenewalView::getUserId, userIdList).op(Operator.InList)
  1036. .field(RenewalView::getRelationId, relationId)
  1037. .field(RenewalView::getExpiryTime, DateTime.now()).op(Operator.GreaterThan)
  1038. .build());
  1039. if (renewalView == null) {
  1040. throw BusinessRuntimeException.getInstance("车票不存在");
  1041. }
  1042. if (renewalView.getGoodsId() != 1) {
  1043. throw BusinessRuntimeException.getInstance("只针对奈飞车票");
  1044. }
  1045. AccountNetflixState accountNetflixState = accountNetflixStateMapper.selectOne(Wrappers.lambdaQuery(AccountNetflixState.class)
  1046. .eq(AccountNetflixState::getAccount, renewalView.getAccount())
  1047. .orderByDesc(AccountNetflixState::getId)
  1048. .last("limit 1"));
  1049. if (accountNetflixState == null || accountNetflixState.getState() != 3) {
  1050. throw BusinessRuntimeException.getInstance("只支持异常账号更换车票");
  1051. }
  1052. String key = RedisService.key.NETFLIX_CHANGE_TICKET_KEY.getName() + relationId;
  1053. if (!redisService.setNx(key, relationId, RedisService.key.NETFLIX_CHANGE_TICKET_KEY.getTimeout())) {
  1054. throw BusinessRuntimeException.getInstance("正在更换车票中..");
  1055. }
  1056. Long groupId = renewalView.getGroupId();
  1057. Long skuId = renewalView.getSkuId();
  1058. Date expiryTime = renewalView.getExpiryTime();
  1059. //随机选择同规格得车票
  1060. Long item_groupsId = groupsMapper.selectRandomGroupsTripsBySkuId(groupId, skuId, expiryTime);
  1061. GroupsRelation newRelation = null;
  1062. if (item_groupsId != null) {
  1063. //存在就随机分配一个,没有就不做处理
  1064. newRelation = changeTickerRelation.changeTicket(renewalView.getUserId(), relationId, item_groupsId, renewalView.getSkuId());
  1065. }
  1066. //若无移至空车队
  1067. if (newRelation == null) {
  1068. newRelation = changeTickerRelation.getEmptyGroupsRelation(renewalView.getUserId(), renewalView.getRelationId(), renewalView.getSkuId());
  1069. }
  1070. if (newRelation == null) {
  1071. throw BusinessRuntimeException.getInstance("更换异常,请重新提交");
  1072. }
  1073. NetflixUserAccountStatusRecord netflixUserAccountStatusRecord = netflixUserAccountStatusRecordMapper.selectOne(Wrappers.lambdaQuery(NetflixUserAccountStatusRecord.class)
  1074. .eq(NetflixUserAccountStatusRecord::getRelationId, relationId)
  1075. .last("limit 1"));
  1076. if (netflixUserAccountStatusRecord != null) {
  1077. netflixUserAccountStatusRecord.setDeleted(false);
  1078. netflixUserAccountStatusRecordMapper.updateById(netflixUserAccountStatusRecord);
  1079. }
  1080. redisService.del(key);
  1081. }
  1082. @Override
  1083. public AccountView getTempAccount(long userId, Long relationId) {
  1084. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  1085. RenewalView renewalView = beanSearcher.searchFirst(RenewalView.class, MapUtils.builder()
  1086. .field(RenewalView::getRelationId, relationId)
  1087. .field(RenewalView::getUserId, userIdList).op(Operator.InList)
  1088. .field(RenewalView::getGroupsStatus, GroupsTrips.Status.waiting.name())
  1089. .field(RenewalView::getExpiryTime, DateTime.now()).op(Operator.GreaterThan)
  1090. .build());
  1091. if (renewalView == null) {
  1092. throw BusinessRuntimeException.getInstance("车票不存在");
  1093. }
  1094. AccountView accountView = new AccountView();
  1095. //奈飞超过3帐车票不给看
  1096. Number number = beanSearcher.searchCount(RenewalView.class, MapUtils.builder()
  1097. .field(RenewalView::getUserId, userIdList).op(Operator.InList)
  1098. .field(RenewalView::getGoodsId, 1)
  1099. .field(RenewalView::getExpiryTime, DateTime.now()).op(Operator.GreaterThan)
  1100. .build());
  1101. if (number.intValue() > 2) {
  1102. return accountView;
  1103. }
  1104. NetflixTempAccountUser netflixTempAccountUser = netflixTempAccountUserMapper.selectOne(Wrappers.lambdaQuery(NetflixTempAccountUser.class)
  1105. .eq(NetflixTempAccountUser::getRelationId, relationId)
  1106. .in(NetflixTempAccountUser::getUserId, userIdList)
  1107. .last("limit 1"));
  1108. Account account;
  1109. if (netflixTempAccountUser == null) {
  1110. account = accountMapper.selectNetflixTempAccount();
  1111. if (account != null) {
  1112. netflixTempAccountUser = new NetflixTempAccountUser();
  1113. netflixTempAccountUser.setAccountId(account.getId());
  1114. netflixTempAccountUser.setRelationId(relationId);
  1115. netflixTempAccountUser.setUserId(renewalView.getUserId());
  1116. netflixTempAccountUserMapper.insert(netflixTempAccountUser);
  1117. }
  1118. } else {
  1119. account = accountMapper.selectById(netflixTempAccountUser.getAccountId());
  1120. }
  1121. if (account != null) {
  1122. accountView.setAccount(account.getAccount());
  1123. accountView.setPassword(account.getPassword());
  1124. }
  1125. return accountView;
  1126. }
  1127. @Override
  1128. public void nfErrorAccountSubmit(long userId, Long relationId) {
  1129. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  1130. RenewalView renewalView = beanSearcher.searchFirst(RenewalView.class, MapUtils.builder()
  1131. .field(RenewalView::getUserId, userIdList).op(Operator.InList)
  1132. .field(RenewalView::getRelationId, relationId)
  1133. .field(RenewalView::getExpiryTime, DateTime.now()).op(Operator.GreaterThan).build());
  1134. if (renewalView == null) {
  1135. throw BusinessRuntimeException.getInstance("车票不存在");
  1136. }
  1137. if (renewalView.getGoodsId() != 1) {
  1138. throw BusinessRuntimeException.getInstance("只支持奈飞车票");
  1139. }
  1140. String account = renewalView.getAccount();
  1141. String password = renewalView.getPassword();
  1142. Integer selectCount = netflixUserAccountStatusRecordMapper.selectCount(Wrappers.lambdaQuery(NetflixUserAccountStatusRecord.class)
  1143. .eq(NetflixUserAccountStatusRecord::getRelationId, relationId)
  1144. .in(NetflixUserAccountStatusRecord::getUserId, userIdList)
  1145. .eq(NetflixUserAccountStatusRecord::getAccount, account)
  1146. .eq(NetflixUserAccountStatusRecord::getState, 0)
  1147. .eq(NetflixUserAccountStatusRecord::getDeleted, 1));
  1148. if (selectCount > 0) {
  1149. throw BusinessRuntimeException.getInstance("该账号正在检测中");
  1150. }
  1151. AccountNetflixState accountNetflixState = accountNetflixStateMapper.selectOne(Wrappers.lambdaQuery(AccountNetflixState.class)
  1152. .eq(AccountNetflixState::getAccount, account)
  1153. .last("limit 1"));
  1154. Integer state = 0;
  1155. if (accountNetflixState != null && accountNetflixState.getState() == 3) {
  1156. state = accountNetflixState.getState();
  1157. }
  1158. //非正常状态
  1159. if (state != 1) {
  1160. //20号之前得校验 直接失败
  1161. if (renewalView.getCreatedTime().compareTo(DateUtil.parse("2025-06-20")) < 0) {
  1162. state = 3;
  1163. }
  1164. //如果账号下架了 直接失败
  1165. if (StrUtil.equals(GroupsTrips.Status.down.name(), renewalView.getGroupsStatus()) && renewalView.getSkuNum() > 1) {
  1166. state = 3;
  1167. }
  1168. }
  1169. NetflixUserAccountStatusRecord netflixUserAccountStatusRecord = new NetflixUserAccountStatusRecord();
  1170. netflixUserAccountStatusRecord.setAccount(account);
  1171. netflixUserAccountStatusRecord.setRelationId(relationId);
  1172. netflixUserAccountStatusRecord.setPassword(password);
  1173. netflixUserAccountStatusRecord.setUserId(renewalView.getUserId());
  1174. netflixUserAccountStatusRecord.setState(state);
  1175. OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
  1176. .eq(OrderDon::getRelationId, renewalView.getRelationId())
  1177. .in(OrderDon::getUserId, userIdList)
  1178. .notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
  1179. .orderByDesc(OrderDon::getId)
  1180. .last("limit 1"));
  1181. if (orderDon != null) {
  1182. netflixUserAccountStatusRecord.setOrderId(orderDon.getId());
  1183. }
  1184. netflixUserAccountStatusRecordMapper.insert(netflixUserAccountStatusRecord);
  1185. }
  1186. @Override
  1187. public NetflixErrorAccountStatus getNetflixErrorAccountStatus(long userId, Long relationId) {
  1188. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  1189. NetflixUserAccountStatusRecord netflixUseAccountStatusRecord = netflixUserAccountStatusRecordMapper.selectOne(Wrappers.lambdaQuery(NetflixUserAccountStatusRecord.class)
  1190. .eq(NetflixUserAccountStatusRecord::getRelationId, relationId)
  1191. .eq(NetflixUserAccountStatusRecord::getDeleted, 1)
  1192. .in(NetflixUserAccountStatusRecord::getUserId, userIdList)
  1193. .orderByDesc(NetflixUserAccountStatusRecord::getId)
  1194. .last("limit 1"));
  1195. NetflixErrorAccountStatus status = new NetflixErrorAccountStatus();
  1196. if (netflixUseAccountStatusRecord == null) {
  1197. //是否已经更换
  1198. NetflixUserAccountSubmitRecoverRecord replaceRecover = netflixUserAccountSubmitRecoverRecordMapper.selectOne(Wrappers.lambdaQuery(NetflixUserAccountSubmitRecoverRecord.class)
  1199. .eq(NetflixUserAccountSubmitRecoverRecord::getUserId, userIdList)
  1200. .eq(NetflixUserAccountSubmitRecoverRecord::getReplaceRelationId, relationId)
  1201. .last("limit 1"));
  1202. if (replaceRecover != null) {
  1203. status.setRecoverStatus(replaceRecover.getStatus());
  1204. }
  1205. return status;
  1206. }
  1207. Integer state = netflixUseAccountStatusRecord.getState();
  1208. //2是登录失败 3是被封号
  1209. // if (state == 3) {
  1210. // if (netflixUseAccountStatusRecord.getCreatedTime().compareTo(DateUtil.offsetMinute(DateTime.now(), -10)) > 0) {
  1211. // state = 0;
  1212. // }
  1213. // }
  1214. //登录失败 可继续申请检测
  1215. if (state == 2) {
  1216. return status;
  1217. }
  1218. //账号检测状态
  1219. status.setNfStatus(state);
  1220. NetflixUserAccountSubmitRecoverRecord recoverRecord = netflixUserAccountSubmitRecoverRecordMapper.selectOne(Wrappers.lambdaQuery(NetflixUserAccountSubmitRecoverRecord.class)
  1221. .in(NetflixUserAccountSubmitRecoverRecord::getUserId, userIdList)
  1222. .eq(NetflixUserAccountSubmitRecoverRecord::getRelationId, relationId)
  1223. .last("limit 1"));
  1224. if (recoverRecord != null) {
  1225. //申请恢复状态
  1226. status.setRecoverStatus(recoverRecord.getStatus());
  1227. }
  1228. return status;
  1229. }
  1230. @Override
  1231. public List<NetflixUserAccountStatusRecord> getUserNetflixSubmitRecord(long userId) {
  1232. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  1233. List<NetflixUserAccountStatusRecord> netflixUseAccountStatusRecords = netflixUserAccountStatusRecordMapper.selectList(Wrappers.lambdaQuery(NetflixUserAccountStatusRecord.class)
  1234. .in(NetflixUserAccountStatusRecord::getUserId, userIdList)
  1235. .eq(NetflixUserAccountStatusRecord::getDeleted, 1)
  1236. .select(NetflixUserAccountStatusRecord::getOrderId, NetflixUserAccountStatusRecord::getRelationId, NetflixUserAccountStatusRecord::getState, NetflixUserAccountStatusRecord::getCreatedTime));
  1237. return netflixUseAccountStatusRecords;
  1238. }
  1239. @Override
  1240. public Long getTrialTicketByUserIdAndGoodsId(Long userId, Long trialSkuId, Integer ticketType) {
  1241. Retryer<Long> build = RetryerBuilder.<Long>newBuilder()
  1242. .retryIfException()
  1243. //运行时异常重试
  1244. .retryIfRuntimeException()
  1245. //false重试
  1246. .retryIfResult(res -> res == null)
  1247. //1s 间隔
  1248. .withWaitStrategy(WaitStrategies.fixedWait(1, TimeUnit.SECONDS))
  1249. //停止策略 : 尝试请求3次
  1250. .withStopStrategy(StopStrategies.stopAfterAttempt(3)).build();
  1251. try {
  1252. return build.call(() -> {
  1253. //体验规格
  1254. GroupsTrips groups = groupsMapper.selectCollegeStudentUserGptTicket(trialSkuId);
  1255. GroupsRelation relation = null;
  1256. if (groups == null) {
  1257. groups = groupsMapper.selectOne(Wrappers.lambdaQuery(GroupsTrips.class)
  1258. .eq(GroupsTrips::getStatus, GroupsTrips.Status.waiting)
  1259. .eq(GroupsTrips::getSkuId, trialSkuId)
  1260. .last("limit 1"));
  1261. }
  1262. if (groups != null) {
  1263. relation = groupsRelationMapper.selectRandomOneRelationByGroupsId(groups.getId());
  1264. }
  1265. if (relation == null) {
  1266. //生成空车队
  1267. GoodsDonSku sku = goodsDonSkuMapper.selectById(trialSkuId);
  1268. relation = groupsFuncService.createNewGroupsTrips(sku);
  1269. }
  1270. DateTime startTime = DateTime.now();
  1271. DateTime expiryTime = DateUtil.offsetDay(startTime, 1);
  1272. int update = groupsRelationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
  1273. .set(GroupsRelation::getUserId, userId)
  1274. .set(GroupsRelation::getStartTime, startTime)
  1275. .set(GroupsRelation::getExpiryTime, expiryTime)
  1276. .set(GroupsRelation::getStatus, GroupsRelation.Status.validity)
  1277. .set(GroupsRelation::getAqType, ticketType)
  1278. .eq(GroupsRelation::getId, relation.getId())
  1279. .eq(GroupsRelation::getUserId, 0));
  1280. if (update > 0) {
  1281. groupsMapper.decrAvailableNum(relation.getGroupsId());
  1282. return relation.getId();
  1283. }
  1284. log.error("发送用户:{} GPT镜像车票体验失败,进行重试", userId);
  1285. return null;
  1286. });
  1287. } catch (ExecutionException | RetryException e) {
  1288. log.error("发送用户GPT镜像体验失败:{}", StringUtil.getErrorText(e));
  1289. return null;
  1290. }
  1291. }
  1292. @Override
  1293. public Boolean getMirrorPopups(long userId) {
  1294. //是否弹窗 默认否
  1295. Boolean flag = false;
  1296. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  1297. Number number = beanSearcher.searchCount(RenewalView.class, MapUtils.builder()
  1298. .field(RenewalView::getUserId, userIdList).op(Operator.InList)
  1299. .field(RenewalView::getStatus, GroupsRelation.Status.validity.name())
  1300. .field(RenewalView::getIsMirror, true)
  1301. .build());
  1302. if (number.intValue() == 0) {
  1303. flag = true;
  1304. }
  1305. if (!flag) {
  1306. String thisWeekBegin = DateUtil.beginOfWeek(DateTime.now()).toDateStr();
  1307. Integer selectCount = mirrorTicketPopupsRecordMapper.selectCount(Wrappers.lambdaQuery(MirrorTicketPopupsRecord.class)
  1308. .in(MirrorTicketPopupsRecord::getUserId, userIdList)
  1309. .eq(MirrorTicketPopupsRecord::getThisWeek, thisWeekBegin));
  1310. if (selectCount == 0) {
  1311. MirrorTicketPopupsRecord mirrorTicketPopupsRecord = new MirrorTicketPopupsRecord();
  1312. mirrorTicketPopupsRecord.setThisWeek(thisWeekBegin);
  1313. mirrorTicketPopupsRecord.setUserId(userId);
  1314. mirrorTicketPopupsRecordMapper.insert(mirrorTicketPopupsRecord);
  1315. } else {
  1316. flag = true;
  1317. }
  1318. }
  1319. return flag;
  1320. }
  1321. @Override
  1322. public Long getTicket(Long userId, Long skuId, Boolean isVip) {
  1323. Retryer<Long> build = RetryerBuilder.<Long>newBuilder()
  1324. .retryIfException()
  1325. //运行时异常重试
  1326. .retryIfRuntimeException()
  1327. //false重试
  1328. .retryIfResult(res -> res == null)
  1329. //1s 间隔
  1330. .withWaitStrategy(WaitStrategies.fixedWait(1, TimeUnit.SECONDS))
  1331. //停止策略 : 尝试请求1次
  1332. .withStopStrategy(StopStrategies.stopAfterAttempt(1)).build();
  1333. try {
  1334. return build.call(() -> {
  1335. GroupsTrips groups = groupsMapper.selectCollegeStudentUserGptTicket(skuId);
  1336. GroupsRelation relation = null;
  1337. if (groups == null) {
  1338. groups = groupsMapper.selectOne(Wrappers.lambdaQuery(GroupsTrips.class)
  1339. .eq(GroupsTrips::getStatus, GroupsTrips.Status.waiting)
  1340. .eq(GroupsTrips::getSkuId, skuId)
  1341. .last("limit 1"));
  1342. }
  1343. if (groups != null) {
  1344. relation = groupsRelationMapper.selectRandomOneRelationByGroupsId(groups.getId());
  1345. }
  1346. GoodsDonSku sku = goodsDonSkuMapper.selectById(skuId);
  1347. //生成空车队
  1348. if (relation == null) {
  1349. relation = groupsFuncService.createNewGroupsTrips(sku);
  1350. }
  1351. DateTime startTime = DateTime.now();
  1352. DateTime expiryTime;
  1353. if (sku.getDays() != null) {
  1354. expiryTime = DateUtil.offsetDay(startTime, sku.getDays());
  1355. } else {
  1356. expiryTime = DateUtil.offsetMonth(startTime, sku.getMonths());
  1357. }
  1358. int update = groupsRelationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
  1359. .set(GroupsRelation::getUserId, userId)
  1360. .set(GroupsRelation::getStartTime, startTime)
  1361. .set(GroupsRelation::getExpiryTime, expiryTime)
  1362. .set(GroupsRelation::getStatus, GroupsRelation.Status.validity)
  1363. .set(GroupsRelation::getIsVip, isVip)
  1364. .eq(GroupsRelation::getId, relation.getId())
  1365. .eq(GroupsRelation::getUserId, 0));
  1366. if (update > 0) {
  1367. groupsMapper.decrAvailableNum(relation.getGroupsId());
  1368. return relation.getId();
  1369. }
  1370. log.error("发送用户:{} GPT镜像车票失败,进行重试", userId);
  1371. return null;
  1372. });
  1373. } catch (ExecutionException | RetryException e) {
  1374. log.error("发送用户GPT镜像失败:{}", StringUtil.getErrorText(e));
  1375. return null;
  1376. }
  1377. }
  1378. @Override
  1379. public Boolean getVipMirrorTicketIfEmpty(long userId, Long skuId) {
  1380. Integer selectCount = vipGoodsSkuMapper.selectCount(Wrappers.lambdaQuery(VipGoodsSku.class)
  1381. .eq(VipGoodsSku::getSkuId, skuId));
  1382. if (selectCount == 0) {
  1383. return false;
  1384. }
  1385. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  1386. VipUser vipUser = vipUserMapper.selectOne(Wrappers.lambdaQuery(VipUser.class)
  1387. .in(VipUser::getUserId, userIdList)
  1388. .gt(VipUser::getExpiryTime, DateTime.now())
  1389. .last("limit 1"));
  1390. //不是会员 或已到期
  1391. if (vipUser == null) {
  1392. return false;
  1393. }
  1394. Number number = beanSearcher.searchCount(GroupsRelationView.class, MapUtils.builder()
  1395. .field(GroupsRelationView::getUserId, userIdList).op(Operator.InList)
  1396. .field(GroupsRelationView::getSkuId, skuId)
  1397. .field(GroupsRelationView::getIsVip, Boolean.TRUE)
  1398. .build());
  1399. if (number.intValue() == 0) {
  1400. Long relationId = getTicket(vipUser.getUserId(), skuId, Boolean.TRUE);
  1401. //同步时间
  1402. groupsRelationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
  1403. .set(GroupsRelation::getExpiryTime, vipUser.getExpiryTime())
  1404. .eq(GroupsRelation::getUserId, vipUser.getUserId())
  1405. .eq(GroupsRelation::getId, relationId));
  1406. return true;
  1407. }
  1408. return false;
  1409. }
  1410. @Override
  1411. @Transactional(rollbackFor = Throwable.class)
  1412. public NetflixRecoverResp netflixSubmitRecover(ErrorNetflixChangeReq req) {
  1413. NetflixRecoverResp recoverResp = new NetflixRecoverResp();
  1414. Long relationId = req.getRelationId();
  1415. Long userId = req.getUserId();
  1416. //校验奈飞账号状态
  1417. GroupsRelationView netflixRelationView = checkNetflixErrorStatus(relationId, userId);
  1418. if (netflixRelationView.getIsFrozen()) {
  1419. int update = groupsRelationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
  1420. .set(GroupsRelation::getIsFrozen, Boolean.FALSE)
  1421. .eq(GroupsRelation::getId, netflixRelationView.getId())
  1422. .eq(GroupsRelation::getIsFrozen, Boolean.TRUE));
  1423. if (update == 0) {
  1424. throw BusinessRuntimeException.getInstance("申请恢复账号失败,请重试");
  1425. }
  1426. try {
  1427. //获取同规格的车票
  1428. Long skuId = netflixRelationView.getSkuId();
  1429. GoodsDonSku sku = goodsDonSkuMapper.selectById(skuId);
  1430. GroupsRelation relation = getRelation(null, userId, sku, null);
  1431. if (relation == null) {
  1432. //还原冻结状态
  1433. groupsRelationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
  1434. .set(GroupsRelation::getIsFrozen, Boolean.TRUE)
  1435. .eq(GroupsRelation::getId, netflixRelationView.getId())
  1436. .eq(GroupsRelation::getIsFrozen, Boolean.FALSE));
  1437. }
  1438. if (relation != null) {
  1439. Long groupsId = relation.getGroupsId();
  1440. GroupsTrips groupsTrips = groupsMapper.selectById(groupsId);
  1441. //已发车
  1442. if (groupsTrips.getStatus() == GroupsTrips.Status.validity) {
  1443. resetUserTicket(netflixRelationView, relation);
  1444. recoverResp.setIsReset(Boolean.TRUE);
  1445. return recoverResp;
  1446. }
  1447. }
  1448. } catch (Exception e) {
  1449. throw BusinessRuntimeException.getInstance("申请恢复账号失败,请重试");
  1450. }
  1451. }
  1452. Date expiryTime = netflixRelationView.getExpiryTime();
  1453. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  1454. NetflixUserAccountSubmitRecoverRecord recoverRecord = netflixUserAccountSubmitRecoverRecordMapper.selectOne(Wrappers.lambdaQuery(NetflixUserAccountSubmitRecoverRecord.class)
  1455. .eq(NetflixUserAccountSubmitRecoverRecord::getRelationId, relationId)
  1456. .in(NetflixUserAccountSubmitRecoverRecord::getUserId, userIdList)
  1457. .eq(NetflixUserAccountSubmitRecoverRecord::getStatus, 0)
  1458. .last("limit 1"));
  1459. if (recoverRecord == null) {
  1460. recoverRecord = new NetflixUserAccountSubmitRecoverRecord();
  1461. recoverRecord.setRelationId(relationId);
  1462. recoverRecord.setUserId(netflixRelationView.getUserId());
  1463. recoverRecord.setSkuId(netflixRelationView.getSkuId());
  1464. recoverRecord.setAccount(netflixRelationView.getAccount());
  1465. Long betweenDay = DateUtil.betweenDay(DateTime.now(), expiryTime, false) + 1;
  1466. recoverRecord.setRemainDays(betweenDay);
  1467. recoverRecord.setAccount(netflixRelationView.getTripsAccount());
  1468. try {
  1469. netflixUserAccountSubmitRecoverRecordMapper.insert(recoverRecord);
  1470. } catch (DuplicateKeyException e) {
  1471. throw BusinessRuntimeException.getInstance("您已申请恢复");
  1472. }
  1473. }
  1474. //等待位数
  1475. Integer selectCount = netflixUserAccountSubmitRecoverRecordMapper.selectCount(Wrappers.lambdaQuery(NetflixUserAccountSubmitRecoverRecord.class)
  1476. .lt(NetflixUserAccountSubmitRecoverRecord::getCreatedTime, recoverRecord.getCreatedTime())
  1477. .eq(NetflixUserAccountSubmitRecoverRecord::getStatus, 0));
  1478. //往前加100位
  1479. recoverResp.setIndex(100 + selectCount + 1);
  1480. recoverResp.setRemainDays(recoverRecord.getRemainDays());
  1481. return recoverResp;
  1482. }
  1483. private void resetUserTicket(GroupsRelationView oldRelation, GroupsRelation newRelation) {
  1484. Long userId = oldRelation.getUserId();
  1485. Long oldRelationId = oldRelation.getId();
  1486. //清除车票
  1487. List<Long> userIdList;
  1488. try {
  1489. userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  1490. } catch (Exception e) {
  1491. userIdList = List.of(userId);
  1492. }
  1493. GroupsRelation clearRelation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
  1494. .eq(GroupsRelation::getId, oldRelationId)
  1495. .in(GroupsRelation::getUserId, userIdList)
  1496. .last("limit 1"));
  1497. if (clearRelation != null) {
  1498. clearRelation.setNewRelationId(newRelation.getId());
  1499. clearService.clearTicket(clearRelation, UserTicketClearedRecord.Source.ticket_replace);
  1500. }
  1501. //校验座位
  1502. int update = groupsRelationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
  1503. .set(GroupsRelation::getUserId, userId)
  1504. .eq(GroupsRelation::getUserId, 0)
  1505. .eq(GroupsRelation::getId, newRelation.getId()));
  1506. if (update == 0) {
  1507. throw BusinessRuntimeException.getInstance("申请恢复账号失败,请重试");
  1508. }
  1509. //恢复状态
  1510. newRelation.setStartTime(oldRelation.getStartTime());
  1511. newRelation.setExpiryTime(DateUtil.offsetDay(DateTime.now(), oldRelation.getReservedDays()));
  1512. newRelation.setStatus(GroupsRelation.Status.validity);
  1513. groupsRelationMapper.updateById(newRelation);
  1514. //原订单座位id更新
  1515. OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
  1516. .in(OrderDon::getUserId, userIdList)
  1517. .eq(OrderDon::getRelationId, oldRelationId)
  1518. .notIn(OrderDon::getStatus, Constant.noOrderStatus)
  1519. .orderByDesc(OrderDon::getId)
  1520. .last("limit 1"));
  1521. if (orderDon != null) {
  1522. orderDon.setRelationId(newRelation.getId());
  1523. orderDonMapper.updateById(orderDon);
  1524. }
  1525. }
  1526. @Override
  1527. @Transactional(rollbackFor = Throwable.class)
  1528. public void errorNetflixSubmitChangeOtherTicket(ErrorNetflixChangeReq req) throws Exception {
  1529. Long relationId = req.getRelationId();
  1530. Long userId = req.getUserId();
  1531. //校验奈飞账号状态
  1532. GroupsRelationView netflixRelationView = checkNetflixErrorStatus(relationId, userId);
  1533. Date expiryTime = netflixRelationView.getExpiryTime();
  1534. //小于15 不可替换其他车票
  1535. Long betweenDay = DateUtil.betweenDay(DateTime.now(), expiryTime, false) + 1;
  1536. if (betweenDay <= 30) {
  1537. throw BusinessRuntimeException.getInstance("您的车票有效期未超过30天");
  1538. }
  1539. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  1540. Integer count = netflixUserAccountSubmitRecoverRecordMapper.selectCount(Wrappers.lambdaQuery(NetflixUserAccountSubmitRecoverRecord.class)
  1541. .eq(NetflixUserAccountSubmitRecoverRecord::getRelationId, relationId)
  1542. .in(NetflixUserAccountSubmitRecoverRecord::getUserId, userIdList));
  1543. if (count > 0) {
  1544. throw BusinessRuntimeException.getInstance("您的车票申请恢复中...");
  1545. }
  1546. String key = RedisService.key.NETFLIX_CHANGE_TICKET_KEY.getName() + relationId;
  1547. if (!redisService.setNx(key, relationId, RedisService.key.NETFLIX_CHANGE_TICKET_KEY.getTimeout())) {
  1548. throw BusinessRuntimeException.getInstance("正在更换其他车票中..");
  1549. }
  1550. try {
  1551. Long skuId = req.getSkuId();
  1552. SysConfig sysConfig = sysConfigMapper.selectOne(Wrappers.lambdaQuery(SysConfig.class)
  1553. .eq(SysConfig::getSysKey, Constant.ERROR_NETFLIX_CHANGE_OTHER_SKU_KEY)
  1554. .last("limit 1"));
  1555. List<ErrorNetflixChangeOtherSkuTicketDto> errorNetflixChangeOtherSkuTicketDtos = Jsons.parseList(sysConfig.getSysValue(), ErrorNetflixChangeOtherSkuTicketDto.class);
  1556. ErrorNetflixChangeOtherSkuTicketDto errorNetflixChangeOtherSkuTicketDto;
  1557. //自定义顺序 直接获取
  1558. if (betweenDay <= 60) {
  1559. //检验规格
  1560. errorNetflixChangeOtherSkuTicketDto = errorNetflixChangeOtherSkuTicketDtos.get(0);
  1561. } else if (betweenDay <= 120) {
  1562. errorNetflixChangeOtherSkuTicketDto = errorNetflixChangeOtherSkuTicketDtos.get(1);
  1563. } else {
  1564. errorNetflixChangeOtherSkuTicketDto = errorNetflixChangeOtherSkuTicketDtos.get(2);
  1565. }
  1566. List<Long> availableSkuIds = errorNetflixChangeOtherSkuTicketDto.getSkuIds();
  1567. if (!availableSkuIds.contains(skuId)) {
  1568. throw BusinessRuntimeException.getInstance("不支持更换该类型车票");
  1569. }
  1570. //替换车票
  1571. TicketChangeDto changeDto = getTicketAndGenerateOrder(userId, skuId, null, null);
  1572. if (changeDto == null) {
  1573. throw BusinessRuntimeException.getInstance("系统繁忙,请重试");
  1574. }
  1575. //替换记录
  1576. NetflixUserChangeOtherTicketRecord changeOtherTicketRecord = new NetflixUserChangeOtherTicketRecord();
  1577. changeOtherTicketRecord.setUserId(userId);
  1578. changeOtherTicketRecord.setRelationId(relationId);
  1579. changeOtherTicketRecord.setOtherRelationId(changeDto.getOtherRelationId());
  1580. changeOtherTicketRecord.setRelateOrderId(changeDto.getOtherOrderId());
  1581. //该车票订单id
  1582. changeOtherTicketRecord.setOrderId(netflixRelationView.getNfOriOrderId());
  1583. changeOtherTicketRecord.setStartTime(netflixRelationView.getStartTime());
  1584. changeOtherTicketRecord.setExpiryTime(expiryTime);
  1585. netflixUserChangeOtherTicketRecordMapper.insert(changeOtherTicketRecord);
  1586. if (netflixRelationView.getNfCheckId() != null) {
  1587. netflixUserAccountStatusRecordMapper.update(null, Wrappers.lambdaUpdate(NetflixUserAccountStatusRecord.class)
  1588. .set(NetflixUserAccountStatusRecord::getDeleted, false)
  1589. .eq(NetflixUserAccountStatusRecord::getId, netflixRelationView.getNfCheckId()));
  1590. }
  1591. Long ticketUserId = null;
  1592. //清除车票
  1593. GroupsRelation clearRelation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
  1594. .eq(GroupsRelation::getId, relationId)
  1595. .in(GroupsRelation::getUserId, userIdList)
  1596. .last("limit 1"));
  1597. if (clearRelation != null) {
  1598. ticketUserId = clearRelation.getUserId();
  1599. clearService.clearTicket(clearRelation, UserTicketClearedRecord.Source.ticket_replace);
  1600. }
  1601. OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
  1602. .eq(OrderDon::getRelationId, relationId)
  1603. .in(OrderDon::getUserId, userIdList)
  1604. .notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
  1605. .orderByDesc(OrderDon::getId)
  1606. .last("limit 1"));
  1607. if (orderDon != null) {
  1608. if (ticketUserId == null) {
  1609. ticketUserId = orderDon.getUserId();
  1610. }
  1611. //替换sku
  1612. GoodsDonSku replaceSku = goodsDonSkuMapper.selectById(skuId);
  1613. GoodsDonSku oriTicketSku = goodsDonSkuMapper.selectById(orderDon.getSkuId());
  1614. //每天单价
  1615. BigDecimal dayPrice = oriTicketSku.getPrice().divide(BigDecimal.valueOf(oriTicketSku.getMonths() * 30), RoundingMode.DOWN);
  1616. //需要退款金额
  1617. BigDecimal refundMoney = dayPrice.multiply(BigDecimal.valueOf(betweenDay));
  1618. BigDecimal balance = Optional.ofNullable(orderDon.getBalance()).orElse(BigDecimal.ZERO);
  1619. BigDecimal finalOrderMoney = orderDon.getMoney().add(balance);
  1620. if (refundMoney.compareTo(finalOrderMoney) > 0) {
  1621. refundMoney = finalOrderMoney;
  1622. }
  1623. //车票价格高于替换的规格价格 退余额
  1624. if (refundMoney.compareTo(replaceSku.getPrice()) > 0) {
  1625. BigDecimal refundBalance = refundMoney.subtract(replaceSku.getPrice());
  1626. if (refundBalance.compareTo(BigDecimal.ZERO) > 0) {
  1627. userBenefitsService.addUserBalance(ticketUserId, refundBalance, UserBalanceSourceRecord.Source.TICKET_REPLACE, 0L, orderDon.getId(), UserBalanceSourceRecord.Source.TICKET_REPLACE.getDesc(), true);
  1628. }
  1629. }
  1630. }
  1631. } finally {
  1632. redisService.del(key);
  1633. }
  1634. }
  1635. @Override
  1636. public List<GoodsCategorySkuView> getNetflixReplaceOtherSkus(long userId, Long relationId) throws Exception {
  1637. //校验奈飞账号状态
  1638. GroupsRelationView netflixRelationView = checkNetflixErrorStatus(relationId, userId);
  1639. Date expiryTime = netflixRelationView.getExpiryTime();
  1640. //小于15 不可替换其他车票
  1641. Long betweenDay = DateUtil.betweenDay(DateTime.now(), expiryTime, false) + 1;
  1642. SysConfig sysConfig = sysConfigMapper.selectOne(Wrappers.lambdaQuery(SysConfig.class)
  1643. .eq(SysConfig::getSysKey, Constant.ERROR_NETFLIX_CHANGE_OTHER_SKU_KEY)
  1644. .last("limit 1"));
  1645. List<ErrorNetflixChangeOtherSkuTicketDto> errorNetflixChangeOtherSkuTicketDtos = Jsons.parseList(sysConfig.getSysValue(), ErrorNetflixChangeOtherSkuTicketDto.class);
  1646. ErrorNetflixChangeOtherSkuTicketDto errorNetflixChangeOtherSkuTicketDto;
  1647. if (betweenDay <= 30) {
  1648. return null;
  1649. }
  1650. //自定义顺序 直接获取
  1651. if (betweenDay <= 60) {
  1652. //检验规格
  1653. errorNetflixChangeOtherSkuTicketDto = errorNetflixChangeOtherSkuTicketDtos.get(0);
  1654. } else if (betweenDay <= 120) {
  1655. errorNetflixChangeOtherSkuTicketDto = errorNetflixChangeOtherSkuTicketDtos.get(1);
  1656. } else {
  1657. errorNetflixChangeOtherSkuTicketDto = errorNetflixChangeOtherSkuTicketDtos.get(2);
  1658. }
  1659. List<GoodsCategorySkuView> goodsCategorySkuViews = beanSearcher.searchAll(GoodsCategorySkuView.class, MapUtils.builder()
  1660. .field(GoodsCategorySkuView::getSkuId, errorNetflixChangeOtherSkuTicketDto.getSkuIds()).op(Operator.InList)
  1661. .orderBy(GoodsCategorySkuView::getPrice).desc()
  1662. .build());
  1663. return goodsCategorySkuViews;
  1664. }
  1665. @Override
  1666. public NetflixRefundInfoResp refundNetflixInfo(Long userId, Long relationId) {
  1667. //校验奈飞账号状态
  1668. GroupsRelationView netflixRelationView = checkNetflixErrorStatus(relationId, userId);
  1669. Date expiryTime = netflixRelationView.getExpiryTime();
  1670. //小于15
  1671. Long betweenDay = DateUtil.betweenDay(DateTime.now(), expiryTime, false) + 1;
  1672. NetflixRefundInfoResp refundInfoResp = new NetflixRefundInfoResp();
  1673. refundInfoResp.setIsRefund(true);
  1674. if (betweenDay > 30) {
  1675. refundInfoResp.setIsRefund(false);
  1676. }
  1677. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  1678. OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
  1679. .eq(OrderDon::getRelationId, relationId)
  1680. .in(OrderDon::getUserId, userIdList)
  1681. .notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
  1682. .orderByDesc(OrderDon::getId)
  1683. .last("limit 1"));
  1684. if (orderDon == null) {
  1685. refundInfoResp.setIsRefund(false);
  1686. }
  1687. Long skuId = netflixRelationView.getSkuId();
  1688. GoodsDonSku sku = goodsDonSkuMapper.selectById(skuId);
  1689. BigDecimal orderMoney = orderDon == null ? BigDecimal.ZERO : orderDon.getMoney();
  1690. if (orderMoney.compareTo(BigDecimal.ZERO) == 0) {
  1691. refundInfoResp.setIsRefund(false);
  1692. }
  1693. //每天单价
  1694. BigDecimal dayPrice = sku.getPrice().divide(BigDecimal.valueOf(sku.getMonths() * 30), RoundingMode.DOWN);
  1695. //需要退款金额
  1696. BigDecimal refundMoney = dayPrice.multiply(BigDecimal.valueOf(betweenDay));
  1697. refundInfoResp.setPrice(refundMoney);
  1698. BigDecimal balance = orderDon == null ? BigDecimal.ZERO : Optional.ofNullable(orderDon.getBalance()).orElse(BigDecimal.ZERO);
  1699. //超过本身订单金额 不允许退款
  1700. if (refundMoney.compareTo(orderMoney) > 0) {
  1701. refundInfoResp.setIsRefund(false);
  1702. }
  1703. if (refundMoney.compareTo(orderMoney.add(balance)) > 0) {
  1704. refundInfoResp.setPrice(orderMoney.add(balance));
  1705. }
  1706. refundInfoResp.setRemainDays(betweenDay);
  1707. return refundInfoResp;
  1708. }
  1709. @Override
  1710. public Boolean refundNetflix(ErrorNetflixChangeReq req) throws Exception {
  1711. Long relationId = req.getRelationId();
  1712. Long userId = req.getUserId();
  1713. //校验奈飞账号状态
  1714. GroupsRelationView netflixRelationView = checkNetflixErrorStatus(relationId, userId);
  1715. Date expiryTime = netflixRelationView.getExpiryTime();
  1716. //小于15
  1717. Long betweenDay = DateUtil.betweenDay(DateTime.now(), expiryTime, false) + 1;
  1718. if (betweenDay > 30) {
  1719. throw BusinessRuntimeException.getInstance("车票有效期不超过30天可退款");
  1720. }
  1721. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  1722. OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
  1723. .eq(OrderDon::getRelationId, relationId)
  1724. .in(OrderDon::getUserId, userIdList)
  1725. .notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
  1726. .orderByDesc(OrderDon::getId)
  1727. .last("limit 1"));
  1728. if (orderDon == null) {
  1729. throw BusinessRuntimeException.getInstance("对应车票订单不存在,请联系客服");
  1730. }
  1731. Long skuId = netflixRelationView.getSkuId();
  1732. GoodsDonSku sku = goodsDonSkuMapper.selectById(skuId);
  1733. BigDecimal orderMoney = orderDon.getMoney();
  1734. if (orderMoney.compareTo(BigDecimal.ZERO) == 0) {
  1735. throw BusinessRuntimeException.getInstance("不符合退款条件");
  1736. }
  1737. //每天单价
  1738. BigDecimal dayPrice = sku.getPrice().divide(BigDecimal.valueOf(sku.getMonths() * 30), RoundingMode.DOWN);
  1739. //需要退款金额
  1740. BigDecimal refundMoney = dayPrice.multiply(BigDecimal.valueOf(betweenDay));
  1741. if (refundMoney.compareTo(orderMoney) > 0) {
  1742. throw BusinessRuntimeException.getInstance("不符合退款条件");
  1743. }
  1744. //调用第三方接口退款
  1745. OrderRefundReq refundReq = new OrderRefundReq();
  1746. refundReq.setRefundMoney(refundMoney);
  1747. refundReq.setRefundType("money");
  1748. String outNo = orderRefundService.centerRefund(refundReq, orderDon);
  1749. orderDon.setStatus(OrderDon.Status.refund);
  1750. orderDon.setRefundMoney(refundMoney);
  1751. GoodsDon goodsDon = goodsDonMapper.selectById(orderDon.getGoodsId());
  1752. orderDonMapper.updateById(orderDon);
  1753. orderRefundService.refundRecord(orderDon, refundMoney, null, "系统", goodsDon, sku, outNo, orderDon.getType().name(), null);
  1754. //清除车票
  1755. GroupsRelation relation = groupsRelationMapper.selectById(relationId);
  1756. clearService.clearTicket(relation, UserTicketClearedRecord.Source.refund);
  1757. if (netflixRelationView.getNfCheckId() != null) {
  1758. netflixUserAccountStatusRecordMapper.update(null, Wrappers.lambdaUpdate(NetflixUserAccountStatusRecord.class)
  1759. .set(NetflixUserAccountStatusRecord::getDeleted, false)
  1760. .eq(NetflixUserAccountStatusRecord::getId, netflixRelationView.getNfCheckId()));
  1761. }
  1762. return true;
  1763. }
  1764. @Override
  1765. public List<UserMirrorTicketView> getMirrorTicket(long userId) {
  1766. User u = userMapper.selectById(userId);
  1767. if (u == null) throw BusinessRuntimeException.getGatewayApiCode(GatewayApiCode.CMS_TOKEN_VALID);
  1768. if (u.getIsBlack()) {
  1769. return null;
  1770. }
  1771. List<Long> userIds = userBindRelationService.getRelationUserIdList(userId, u);
  1772. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  1773. DateTime now = DateTime.now();
  1774. String lang = request.getHeader("lang");
  1775. List<UserMirrorTicketView> list = beanSearcher.searchAll(UserMirrorTicketView.class, builder
  1776. .field(UserMirrorTicketView::getUserId, userIds).op(Operator.InList)
  1777. .field(UserMirrorTicketView::getIsMirror, Boolean.TRUE)
  1778. //过期7天内的镜像车票都展示
  1779. .field(UserMirrorTicketView::getExpiryTime, DateUtil.offsetDay(now, -7)).op(Operator.GreaterThan)
  1780. .orderBy(RenewalView::getExpiryTime).asc()
  1781. .build());
  1782. list.forEach(ticket -> {
  1783. if (ticket.getExpiryTime() != null) {
  1784. String remainDays = DateUtil.formatBetween(now, ticket.getExpiryTime(), BetweenFormater.Level.DAY);
  1785. if ("0天".equals(remainDays)) {
  1786. remainDays = "小于1天";
  1787. } else {
  1788. //当天也算
  1789. int days = Integer.parseInt(remainDays.substring(0, remainDays.indexOf("天")));
  1790. remainDays = days + 1 + "天";
  1791. }
  1792. ticket.setRemainDays(remainDays);
  1793. ticket.setTotal(DateUtil.betweenDay(ticket.getStartTime(), ticket.getExpiryTime(), false) + 1);
  1794. }
  1795. if (ticket.getExpiryTime() != null) {
  1796. ticket.setExpiryTimeStr(DateUtil.format(ticket.getExpiryTime(), "yyyy-MM-dd"));
  1797. }
  1798. //续费升级折扣
  1799. BigDecimal renewDiscount = getRenewDiscount(ticket.getGoodsId(), ticket.getSkuId(), ticket.getIsMirror(), ticket.getSkuNum());
  1800. ticket.setDiscount(renewDiscount);
  1801. setAIZoneMirrorTicketInfo(ticket);
  1802. if (lang != null && !StrUtil.equals(UserPageLanguage.Language.zh_CN.name(), lang)) {
  1803. String languageSpecVal = backInfoTranslationsFrontService.getLanguageSpecVal(ticket.getSkuId(), lang);
  1804. if (StrUtil.isNotBlank(languageSpecVal)) {
  1805. ticket.setSpecVal(languageSpecVal);
  1806. }
  1807. }
  1808. OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
  1809. .eq(OrderDon::getRelationId, ticket.getRelationId())
  1810. .eq(OrderDon::getUserId, ticket.getUserId())
  1811. .eq(OrderDon::getOrderType, 1)
  1812. .notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
  1813. .orderByDesc(OrderDon::getId)
  1814. .last("limit 1"));
  1815. if (orderDon != null) {
  1816. ticket.setOrderId(orderDon.getId());
  1817. }
  1818. });
  1819. userLoginRecordService.saveUserLoginDayRecord(userId);
  1820. return list;
  1821. }
  1822. @Override
  1823. public TicketRenewUpgradeView getRenewUpgradeInfo(long userId, Long relationId) {
  1824. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  1825. GroupsRelationView groupsRelationView = beanSearcher.searchFirst(GroupsRelationView.class, MapUtils.builder()
  1826. .field(GroupsRelationView::getUserId, userIdList).op(Operator.InList)
  1827. .field(GroupsRelationView::getId, relationId)
  1828. .field(GroupsRelationView::getExpiryTime, DateTime.now()).op(Operator.GreaterThan)
  1829. .build());
  1830. TicketRenewUpgradeView ticketRenewUpgradeView = new TicketRenewUpgradeView();
  1831. if (groupsRelationView != null) {
  1832. String lang = request.getHeader("lang");
  1833. //clause pro
  1834. if (groupsRelationView.getGoodsId() == Constant.CLAUDE_PRO_GID) {
  1835. try {
  1836. ClaudeUserView userInfo = claudeService.getUserInfo(groupsRelationView.getUserId(), groupsRelationView.getId());
  1837. Long renewSkuId = userInfo.getRenewSkuId();
  1838. if (renewSkuId != null) {
  1839. GoodsDonSkuRenewView renewSku = beanSearcher.searchFirst(GoodsDonSkuRenewView.class, MapUtils.builder().field(GoodsDonSkuRenewView::getSkuId, renewSkuId).build());
  1840. ticketRenewUpgradeView.setRenewSku(renewSku);
  1841. }
  1842. ticketRenewUpgradeView.setGptUserLimitNum(userInfo.getLimitNum());
  1843. ticketRenewUpgradeView.setGptUserLimitTime(userInfo.getLimitTime());
  1844. } catch (Exception e) {
  1845. }
  1846. }
  1847. if (groupsRelationView.getGoodsId() == Constant.GPT_PLUS_GID) {
  1848. try {
  1849. //gpt用户镜像
  1850. ChatGptUserView userInfo = chatGptAccountService.getUserInfo(groupsRelationView.getUserId(), groupsRelationView.getId());
  1851. Integer count = upgradePackageMapper.selectCount(Wrappers.lambdaQuery(UpgradePackage.class).apply("JSON_CONTAINS(sku_ids,'\"" + groupsRelationView.getSkuId() + "\"')")
  1852. .gt(UpgradePackage::getNum, userInfo.getLimitNum())
  1853. .eq(UpgradePackage::getStatus, Boolean.TRUE)
  1854. .eq(UpgradePackage::getGptType, 0)
  1855. .eq(UpgradePackage::getDeleted, Boolean.TRUE));
  1856. ticketRenewUpgradeView.setUpgrade(count > 0 ? true : false);
  1857. ticketRenewUpgradeView.setPackageId(userInfo.getPackageId());
  1858. ticketRenewUpgradeView.setGptUserLimitNum(userInfo.getLimitNum());
  1859. ticketRenewUpgradeView.setGptUserLimitTime(userInfo.getLimitTime());
  1860. ticketRenewUpgradeView.setUserDsLimitNum(userInfo.getDsLimitNum());
  1861. ticketRenewUpgradeView.setUserDsLimitTime(userInfo.getDsLimitTime());
  1862. ticketRenewUpgradeView.setUserOtherLimitNum(userInfo.getOtherLimitNum());
  1863. ticketRenewUpgradeView.setUserOtherLimitTime(userInfo.getOtherLimitTime());
  1864. if (userInfo.getPackageId() != 0) {
  1865. UpgradePackage upgradePackage = upgradePackageMapper.selectById(userInfo.getPackageId());
  1866. ticketRenewUpgradeView.setPackagePrice(upgradePackage.getPrice());
  1867. Long upgradeOrderDonSkuId = upgradePackage.getUpgradeSkuId();
  1868. GoodsDonSkuRenewView renewSku = beanSearcher.searchFirst(GoodsDonSkuRenewView.class, MapUtils.builder().field(GoodsDonSkuRenewView::getSkuId, upgradeOrderDonSkuId).build());
  1869. renewSku.setPackageId(userInfo.getPackageId());
  1870. ticketRenewUpgradeView.setRenewSku(renewSku);
  1871. }
  1872. ticketRenewUpgradeView.setIsRenewPackage(userInfo.getIsRenewPackage());
  1873. Long renewSkuId = userInfo.getRenewSkuId();
  1874. if (renewSkuId != null) {
  1875. GoodsDonSkuRenewView upgradeSkuRenewView = ticketRenewUpgradeView.getRenewSku();
  1876. GoodsDonSkuRenewView renewSku = beanSearcher.searchFirst(GoodsDonSkuRenewView.class, MapUtils.builder().field(GoodsDonSkuRenewView::getSkuId, renewSkuId).build());
  1877. //续费升级是更高级规格
  1878. if (upgradeSkuRenewView == null || (renewSku.getGptUserLimitNum() >= upgradeSkuRenewView.getGptUserLimitNum() && renewSku.getMonths() >= userInfo.getMonths())) {
  1879. Optional.ofNullable(orderDonRenewRecordMapper.selectOne(Wrappers.lambdaQuery(OrderDonRenewRecord.class)
  1880. .eq(OrderDonRenewRecord::getOrderId, userInfo.getRenewOrderId())
  1881. .last("limit 1"))).ifPresent(e -> renewSku.setOriginalOrderId(e.getOrderId()));
  1882. if (lang != null && !StrUtil.equals(UserPageLanguage.Language.zh_CN.name(), lang)) {
  1883. String languageSpecVal = backInfoTranslationsFrontService.getLanguageSpecVal(renewSku.getSkuId(), lang);
  1884. if (StrUtil.isNotBlank(languageSpecVal)) {
  1885. renewSku.setSpecVal(languageSpecVal);
  1886. }
  1887. }
  1888. ticketRenewUpgradeView.setRenewSku(renewSku);
  1889. }
  1890. }
  1891. } catch (Exception e) {
  1892. }
  1893. }
  1894. //claude code
  1895. if (groupsRelationView.getGoodsId() == Constant.CLAUDE_CODE_GOODS_ID) {
  1896. try {
  1897. //gpt用户镜像
  1898. ClaudeCodeUserInfoView userInfo = claudeCodeService.getClaudeCodeUserSubsInfo(userId);
  1899. ticketRenewUpgradeView.setCodePoints(userInfo.getCodePoints());
  1900. ticketRenewUpgradeView.setCodeCreditRecovery(userInfo.getCodeCreditRecovery());
  1901. ticketRenewUpgradeView.setIsRenewPackage(userInfo.getRenewSkuId() != null ? true : false);
  1902. ticketRenewUpgradeView.setHighestUsage(userInfo.getHighestUsage());
  1903. Long renewSkuId = userInfo.getRenewSkuId();
  1904. if (renewSkuId != null) {
  1905. GoodsDonSkuRenewView renewSku = beanSearcher.searchFirst(GoodsDonSkuRenewView.class, MapUtils.builder().field(GoodsDonSkuRenewView::getSkuId, renewSkuId).build());
  1906. Optional.ofNullable(claudeCodeUserRenewExpiryRecordMapper.selectOne(Wrappers.lambdaQuery(ClaudeCodeUserRenewExpiryRecord.class)
  1907. .eq(ClaudeCodeUserRenewExpiryRecord::getOrderId, userInfo.getRenewOrderId())
  1908. .last("limit 1"))).ifPresent(e -> renewSku.setOriginalOrderId(e.getOrderId()));
  1909. if (lang != null && !StrUtil.equals(UserPageLanguage.Language.zh_CN.name(), lang)) {
  1910. String languageSpecVal = backInfoTranslationsFrontService.getLanguageSpecVal(renewSku.getSkuId(), lang);
  1911. if (StrUtil.isNotBlank(languageSpecVal)) {
  1912. renewSku.setSpecVal(languageSpecVal);
  1913. }
  1914. }
  1915. ticketRenewUpgradeView.setRenewSku(renewSku);
  1916. }
  1917. } catch (Exception e) {
  1918. }
  1919. }
  1920. }
  1921. return ticketRenewUpgradeView;
  1922. }
  1923. @Override
  1924. public void netflixSubmitFrozen(ErrorNetflixChangeReq req) {
  1925. Long relationId = req.getRelationId();
  1926. Long userId = req.getUserId();
  1927. //校验奈飞账号状态
  1928. GroupsRelationView netflixRelationView = checkNetflixErrorStatus(relationId, userId);
  1929. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  1930. Integer recoverCount = netflixUserAccountSubmitRecoverRecordMapper.selectCount(Wrappers.lambdaQuery(NetflixUserAccountSubmitRecoverRecord.class)
  1931. .eq(NetflixUserAccountSubmitRecoverRecord::getRelationId, relationId)
  1932. .in(NetflixUserAccountSubmitRecoverRecord::getUserId, userIdList)
  1933. .eq(NetflixUserAccountSubmitRecoverRecord::getStatus, 0));
  1934. if (recoverCount > 0) {
  1935. throw BusinessRuntimeException.getInstance("你已申请恢复账号,无法再申请冻结");
  1936. }
  1937. if (netflixRelationView.getIsFrozen()) {
  1938. throw BusinessRuntimeException.getInstance("你已申请冻结,无法再申请冻结");
  1939. }
  1940. Date expiryTime = netflixRelationView.getExpiryTime();
  1941. //保留天数
  1942. Long betweenDay = DateUtil.betweenDay(DateTime.now(), expiryTime, false) + 1;
  1943. groupsRelationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
  1944. .set(GroupsRelation::getIsFrozen, Boolean.TRUE)
  1945. //冻结2个月
  1946. .set(GroupsRelation::getUnfrozenTime, DateUtil.offsetMonth(DateTime.now(), 2))
  1947. .set(GroupsRelation::getReservedDays, betweenDay)
  1948. .eq(GroupsRelation::getId, netflixRelationView.getId())
  1949. .eq(GroupsRelation::getUserId, netflixRelationView.getUserId()));
  1950. }
  1951. private DistributePosterGoodsDetailView setGoodsPoster(RenewalView ticket, User user, List<Long> userIds) {
  1952. DistributePosterGoodsDetailView distributePosterGoodsDetailView = beanSearcher.searchFirst(DistributePosterGoodsDetailView.class, MapUtils.flatBuilder(request.getParameterMap())
  1953. .field(DistributePosterGoodsFrontView::getGoodsId, ticket.getGoodsId()).build());
  1954. if (distributePosterGoodsDetailView == null) {
  1955. return null;
  1956. }
  1957. distributePosterGoodsDetailView.setNickname(user.getNickname());
  1958. UserDistribute userDistribute = userDistributeMapper.selectOne(Wrappers.lambdaQuery(UserDistribute.class)
  1959. .eq(UserDistribute::getUserId, user.getId())
  1960. .eq(UserDistribute::getDeleted, 1)
  1961. .last("limit 1"));
  1962. if (userDistribute != null) {
  1963. UserPlatDistributeRate userPlatDistributeRate = userPlatDistributeRateMapper.selectOne(Wrappers.lambdaQuery(UserPlatDistributeRate.class)
  1964. .eq(UserPlatDistributeRate::getDistributeId, userDistribute.getId())
  1965. .eq(UserPlatDistributeRate::getGoodsId, ticket.getGoodsId())
  1966. .last("limit 1"));
  1967. if (userPlatDistributeRate != null) {
  1968. distributePosterGoodsDetailView.setRate(userPlatDistributeRate.getRate());
  1969. }
  1970. }
  1971. GoodsDon goodsDon = goodsDonMapper.selectById(ticket.getGoodsId());
  1972. if (goodsDon.getIsSkuDistribute()) {
  1973. if (userDistribute != null) {
  1974. UserPlatSkuDistributeRate userPlatSkuDistributeRate = userPlatSkuDistributeRateMapper.selectOne(Wrappers.lambdaQuery(UserPlatSkuDistributeRate.class)
  1975. .eq(UserPlatSkuDistributeRate::getDistributeId, userDistribute.getId())
  1976. .eq(UserPlatSkuDistributeRate::getSkuId, ticket.getSkuId())
  1977. .last("limit 1"));
  1978. if (userPlatSkuDistributeRate != null) {
  1979. distributePosterGoodsDetailView.setRate(userPlatSkuDistributeRate.getRate());
  1980. }
  1981. } else {
  1982. DistributeGeneralSkuRate distributeGeneralSkuRate = distributeGeneralSkuRateMapper.selectOne(Wrappers.lambdaQuery(DistributeGeneralSkuRate.class)
  1983. .eq(DistributeGeneralSkuRate::getSkuId, ticket.getSkuId())
  1984. .last("limit 1"));
  1985. if (distributeGeneralSkuRate != null) {
  1986. distributePosterGoodsDetailView.setRate(distributeGeneralSkuRate.getRate());
  1987. }
  1988. }
  1989. }
  1990. //用户推广海报记录id
  1991. Optional.ofNullable(userDistributePosterRecordMapper.selectOne(Wrappers.lambdaQuery(UserDistributePosterRecord.class)
  1992. .eq(UserDistributePosterRecord::getPosterId, distributePosterGoodsDetailView.getId())
  1993. .in(UserDistributePosterRecord::getUserId, userIds)
  1994. .last("limit 1"))).ifPresent(re -> distributePosterGoodsDetailView.setRid(re.getId()));
  1995. return distributePosterGoodsDetailView;
  1996. }
  1997. private BigDecimal getRenewDiscount(Long goodsId, Long skuId, Boolean isMirror, Integer skuNum) {
  1998. //镜像或者独立规格
  1999. if (goodsId == Constant.CLAUDE_CODE_GOODS_ID || isMirror || (skuNum != null && skuNum == 1)) {
  2000. RenewUpgradePackage renewUpgradePackage = renewUpgradePackageMapper.selectOne(Wrappers.lambdaQuery(RenewUpgradePackage.class)
  2001. .eq(RenewUpgradePackage::getGoodsId, goodsId)
  2002. .eq(RenewUpgradePackage::getStatus, 1)
  2003. .eq(RenewUpgradePackage::getDeleted, 1)
  2004. .eq(RenewUpgradePackage::getSkuId, skuId)
  2005. .orderByAsc(RenewUpgradePackage::getDiscount)
  2006. .last("limit 1")
  2007. .select(RenewUpgradePackage::getId, RenewUpgradePackage::getDiscount));
  2008. if (renewUpgradePackage != null) {
  2009. return renewUpgradePackage.getDiscount();
  2010. }
  2011. }
  2012. return null;
  2013. }
  2014. private void setMirrorTicketInfo(RenewalView ticket) {
  2015. //// //设置MJ镜像信息
  2016. // setMjMirrorInfo(ticket);
  2017. //设置GPT镜像信息
  2018. setGptMirrorInfo(ticket);
  2019. //// //clause pro
  2020. // setClaudeProInfo(ticket);
  2021. //// //luma
  2022. // setLumaInfo(ticket);
  2023. }
  2024. private void setMjMirrorInfo(RenewalView ticket) {
  2025. if (ticket.getGoodsId() == 26 && ticket.getIsMirror()) {
  2026. 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));
  2027. if (CollectionUtil.isNotEmpty(upgradePackages)) {
  2028. upgradePackages.stream().map(e -> e.getPrice().divide(BigDecimal.valueOf(e.getNum()), 2, RoundingMode.HALF_UP)).min(BigDecimal::compareTo).ifPresent(ticket::setMjPackagePrice);
  2029. }
  2030. try {
  2031. MidjourneyUserView search = beanSearcher.searchFirst(MidjourneyUserView.class, MapUtils.flatBuilder(request.getParameterMap())
  2032. .field(MidjourneyUserView::getUserId, ticket.getUserId()).field(MidjourneyUserView::getRelationId, ticket.getRelationId())
  2033. .onlySelect(MidjourneyUserView::getMjUserRelaxNum, MidjourneyUserView::getMjUserFastNum,MidjourneyUserView::getMjUserUpgradeNum, MidjourneyUserView::getIsCar)
  2034. .build());
  2035. if (search == null) {
  2036. MidjourneyUser midjourneyUser = midjourneyAccountService.getMidjourneyUserToken(ticket.getUserId(), ticket.getRelationId());
  2037. ticket.setMjUserFastNum(midjourneyUser.getMjFastNum());
  2038. ticket.setMjUserUpgradeNum(midjourneyUser.getMjUpgradeNum());
  2039. ticket.setMjUserRelaxNum(midjourneyUser.getMjRelaxNum());
  2040. ticket.setIsCar(false);
  2041. } else {
  2042. ticket.setIsCar(search.getIsCar());
  2043. ticket.setMjUserFastNum(search.getMjUserFastNum());
  2044. ticket.setMjUserUpgradeNum(search.getMjUserUpgradeNum());
  2045. ticket.setMjUserRelaxNum(search.getMjUserRelaxNum());
  2046. }
  2047. midjourneyAccountService.updateUserExpiryTime(ticket.getRelationId(), ticket.getExpiryTime());
  2048. } catch (Exception e) {
  2049. }
  2050. }
  2051. }
  2052. public void setGptMirrorInfo(RenewalView ticket) {
  2053. if (ticket.getGoodsId() == 18 && ticket.getIsCar() && ticket.getExpiryTime() != null) {
  2054. try {
  2055. //gpt用户镜像
  2056. ChatGptUserView userInfo = chatGptAccountService.getUserInfo(ticket.getUserId(), ticket.getRelationId());
  2057. ticket.setGptUserLimitNum(userInfo.getLimitNum());
  2058. ticket.setGptUserLimitTime(userInfo.getLimitTime());
  2059. ticket.setUserDsLimitNum(userInfo.getDsLimitNum());
  2060. ticket.setUserDsLimitTime(userInfo.getDsLimitTime());
  2061. ticket.setUserOtherLimitNum(userInfo.getOtherLimitNum());
  2062. ticket.setUserOtherLimitTime(userInfo.getOtherLimitTime());
  2063. ticket.setUserToken(userInfo.getUserToken());
  2064. ticket.setUse(userInfo.getUse());
  2065. ticket.setModel(userInfo.getModel());
  2066. // Integer count = upgradePackageMapper.selectCount(Wrappers.lambdaQuery(UpgradePackage.class).apply("JSON_CONTAINS(sku_ids,'\"" + ticket.getSkuId() + "\"')")
  2067. // .gt(UpgradePackage::getNum, userInfo.getLimitNum())
  2068. // .eq(UpgradePackage::getStatus, Boolean.TRUE)
  2069. // .eq(UpgradePackage::getGptType, 0)
  2070. // .eq(UpgradePackage::getDeleted, Boolean.TRUE));
  2071. // ticket.setUpgrade(count > 0 ? true : false);
  2072. // ticket.setPackageId(userInfo.getPackageId());
  2073. // if (userInfo.getPackageId() != 0) {
  2074. // UpgradePackage upgradePackage = upgradePackageMapper.selectById(userInfo.getPackageId());
  2075. // ticket.setPackagePrice(upgradePackage.getPrice());
  2076. // Long upgradeOrderDonSkuId = upgradePackage.getUpgradeSkuId();
  2077. // GoodsDonSkuRenewView renewSku = beanSearcher.searchFirst(GoodsDonSkuRenewView.class, MapUtils.builder().field(GoodsDonSkuRenewView::getSkuId, upgradeOrderDonSkuId).build());
  2078. // renewSku.setPackageId(userInfo.getPackageId());
  2079. // ticket.setRenewSku(renewSku);
  2080. // }
  2081. // ticket.setIsRenewPackage(userInfo.getIsRenewPackage());
  2082. // Long renewSkuId = userInfo.getRenewSkuId();
  2083. // if (renewSkuId != null) {
  2084. // GoodsDonSkuRenewView upgradeSkuRenewView = ticket.getRenewSku();
  2085. // GoodsDonSkuRenewView renewSku = beanSearcher.searchFirst(GoodsDonSkuRenewView.class, MapUtils.builder().field(GoodsDonSkuRenewView::getSkuId, renewSkuId).build());
  2086. // //续费升级是更高级规格
  2087. // if (upgradeSkuRenewView == null || (renewSku.getGptUserLimitNum() >= upgradeSkuRenewView.getGptUserLimitNum() && renewSku.getMonths() >= userInfo.getMonths())) {
  2088. // Optional.ofNullable(orderDonRenewRecordMapper.selectOne(Wrappers.lambdaQuery(OrderDonRenewRecord.class)
  2089. // .eq(OrderDonRenewRecord::getOrderId, userInfo.getRenewOrderId())
  2090. // .last("limit 1"))).ifPresent(e -> renewSku.setOriginalOrderId(e.getOrderId()));
  2091. // ticket.setRenewSku(renewSku);
  2092. // }
  2093. // }
  2094. } catch (Exception e) {
  2095. }
  2096. }
  2097. }
  2098. public void setClaudeProInfo(RenewalView ticket) {
  2099. //clause pro
  2100. if (ticket.getGoodsId() == 75l && ticket.getExpiryTime() != null) {
  2101. try {
  2102. ClaudeUserView userInfo = claudeService.getUserInfo(ticket.getUserId(), ticket.getRelationId());
  2103. ticket.setGptUserLimitNum(userInfo.getLimitNum());
  2104. ticket.setGptUserLimitTime(userInfo.getLimitTime());
  2105. ticket.setUse(userInfo.getUse());
  2106. Long renewSkuId = userInfo.getRenewSkuId();
  2107. if (renewSkuId != null) {
  2108. GoodsDonSkuRenewView renewSku = beanSearcher.searchFirst(GoodsDonSkuRenewView.class, MapUtils.builder().field(GoodsDonSkuRenewView::getSkuId, renewSkuId).build());
  2109. ticket.setRenewSku(renewSku);
  2110. }
  2111. } catch (Exception e) {
  2112. }
  2113. }
  2114. }
  2115. public void setLumaInfo(RenewalView ticket) {
  2116. if (ticket.getGoodsId() == Constant.LUMA_GOODS_ID && ticket.getExpiryTime() != null) {
  2117. try {
  2118. 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));
  2119. if (CollectionUtil.isNotEmpty(upgradePackages)){
  2120. upgradePackages.stream().map(e -> e.getPrice().divide(BigDecimal.valueOf(e.getNum()), 2, RoundingMode.HALF_UP)).min(BigDecimal::compareTo).ifPresent(ticket::setLumaPackagePrice);
  2121. }
  2122. LumaUser lumaUser = lumaService.getLumaUser(ticket.getUserId(), ticket.getRelationId());
  2123. ticket.setLumaUserNum(lumaUser.getNum());
  2124. } catch (Exception e) {
  2125. }
  2126. }
  2127. }
  2128. /**
  2129. * 获取gpt镜像天卡活动参与平台ids
  2130. * @return
  2131. */
  2132. private List<Long> getGptMirrorGiveawayBuyGids() {
  2133. GptMirrorDayCardGiveawayActivity gptMirrorDayCardGiveawayActivity = beanSearcher.searchFirst(GptMirrorDayCardGiveawayActivity.class, MapUtils.builder().build());
  2134. if (gptMirrorDayCardGiveawayActivity != null) {
  2135. String buyGoodsIds = gptMirrorDayCardGiveawayActivity.getBuyGoodsIds();
  2136. try {
  2137. return Jsons.parseList(buyGoodsIds, Long.class);
  2138. } catch (Exception e) {
  2139. }
  2140. }
  2141. return null;
  2142. }
  2143. /**
  2144. * 标记是否可抵扣会员车票
  2145. */
  2146. private void markVipDeductTicket(List<Long> userIds, RenewalView ticket, Set<Long> vipGoodsIds, Boolean isVip) {
  2147. if (CollUtil.isNotEmpty(vipGoodsIds) && ticket.getIsMirror() != null && ticket.getIsMirror() && !isVip) {
  2148. Long goodsId = ticket.getGoodsId();
  2149. //只购买
  2150. if (ticket.getAqType() != 1) {
  2151. return;
  2152. }
  2153. if (vipGoodsIds.contains(goodsId)) {
  2154. if (goodsId == Constant.NANO_GOODS_ID) {
  2155. NanoUserQuota nanoUserQuota = nanoUserQuotaMapper.selectOne(Wrappers.lambdaQuery(NanoUserQuota.class).in(NanoUserQuota::getUid, userIds).orderByDesc(NanoUserQuota::getRemainingQuota).last("limit 1"));
  2156. if (nanoUserQuota != null) {
  2157. if (ObjectUtil.equal(nanoUserQuota.getRelationId(), ticket.getRelationId())) {
  2158. ticket.setIsVipDeduct(true);
  2159. }
  2160. return;
  2161. }
  2162. RenewalView renewalView = beanSearcher.searchFirst(RenewalView.class, MapUtils.builder()
  2163. .field(RenewalView::getGoodsId, goodsId)
  2164. .field(RenewalView::getUserId, userIds).op(Operator.InList)
  2165. .orderBy(RenewalView::getSkuNanoQuota).desc()
  2166. .onlySelect(RenewalView::getRelationId)
  2167. .build());
  2168. if (renewalView != null && ObjectUtil.equal(renewalView.getRelationId(), ticket.getRelationId())) {
  2169. ticket.setIsVipDeduct(true);
  2170. }
  2171. return;
  2172. }
  2173. //是否时长最长
  2174. Number number = beanSearcher.searchCount(RenewalView.class, MapUtils.builder()
  2175. .field(RenewalView::getRelationId, ticket.getRelationId()).op(Operator.NotEqual)
  2176. .field(RenewalView::getGoodsId, goodsId)
  2177. .field(RenewalView::getUserId, userIds).op(Operator.InList)
  2178. .field(RenewalView::getExpiryTime, ticket.getExpiryTime()).op(Operator.GreaterThan)
  2179. .build());
  2180. if (number.intValue() == 0) {
  2181. ticket.setIsVipDeduct(true);
  2182. }
  2183. }
  2184. }
  2185. }
  2186. /**
  2187. * 检验奈飞账号状态
  2188. */
  2189. public GroupsRelationView checkNetflixErrorStatus(Long relationId, Long userId) {
  2190. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  2191. NetflixUserAccountStatusRecord netflixUseAccountStatusRecord = netflixUserAccountStatusRecordMapper.selectOne(Wrappers.lambdaQuery(NetflixUserAccountStatusRecord.class)
  2192. .eq(NetflixUserAccountStatusRecord::getRelationId, relationId)
  2193. .eq(NetflixUserAccountStatusRecord::getDeleted, 1)
  2194. .in(NetflixUserAccountStatusRecord::getUserId, userIdList)
  2195. .orderByDesc(NetflixUserAccountStatusRecord::getId)
  2196. .last("limit 1"));
  2197. if (netflixUseAccountStatusRecord == null) {
  2198. throw BusinessRuntimeException.getInstance("请先提交账号检测");
  2199. }
  2200. Integer state = netflixUseAccountStatusRecord.getState();
  2201. if (state == 0) {
  2202. throw BusinessRuntimeException.getInstance("您的账号检测中");
  2203. }
  2204. //2是登录失败 3是被封号
  2205. if (state != 3) {
  2206. throw BusinessRuntimeException.getInstance("您的账号未封禁");
  2207. }
  2208. GroupsRelationView netflixRelationView = beanSearcher.searchFirst(GroupsRelationView.class, MapUtils.builder()
  2209. .field(GroupsRelationView::getId, relationId)
  2210. .field(GroupsRelationView::getUserId, userIdList).op(Operator.InList)
  2211. .field(GroupsRelationView::getGoodsId, Constant.NETFLIX_GID)
  2212. .build());
  2213. if (netflixRelationView == null) {
  2214. throw BusinessRuntimeException.getInstance("奈飞车票已过期");
  2215. }
  2216. if (netflixRelationView != null) {
  2217. if (netflixRelationView.getIsFrozen() && netflixRelationView.getUnfrozenTime().after(DateTime.now())) {
  2218. throw BusinessRuntimeException.getInstance("冻结未结束");
  2219. }
  2220. if (netflixRelationView.getIsFrozen()) {
  2221. //重新设置车票时长
  2222. netflixRelationView.setExpiryTime(DateUtil.offsetDay(DateTime.now(), netflixRelationView.getReservedDays()));
  2223. }
  2224. if (netflixRelationView.getExpiryTime().before(DateTime.now())) {
  2225. throw BusinessRuntimeException.getInstance("奈飞车票已过期");
  2226. }
  2227. }
  2228. netflixRelationView.setNfCheckId(netflixUseAccountStatusRecord.getId());
  2229. netflixRelationView.setNfOriOrderId(netflixUseAccountStatusRecord.getOrderId());
  2230. return netflixRelationView;
  2231. }
  2232. /**
  2233. * 获取车票 并生成订单
  2234. */
  2235. public TicketChangeDto getTicketAndGenerateOrder(Long userId, Long skuId, Date startTime, Date expiryTime) {
  2236. Retryer<TicketChangeDto> build = RetryerBuilder.<TicketChangeDto>newBuilder()
  2237. .retryIfException()
  2238. //运行时异常重试
  2239. .retryIfRuntimeException()
  2240. //false重试
  2241. .retryIfResult(res -> res == null)
  2242. //1s 间隔
  2243. .withWaitStrategy(WaitStrategies.fixedWait(1, TimeUnit.SECONDS))
  2244. //停止策略 : 尝试请求1次
  2245. .withStopStrategy(StopStrategies.stopAfterAttempt(1)).build();
  2246. if (startTime == null) {
  2247. startTime = DateTime.now();
  2248. }
  2249. GoodsDonSku sku = goodsDonSkuMapper.selectById(skuId);
  2250. if (expiryTime == null) {
  2251. if (sku.getDays() != null) {
  2252. expiryTime = DateUtil.offsetDay(startTime, sku.getDays());
  2253. } else {
  2254. expiryTime = DateUtil.offsetMonth(startTime, sku.getMonths());
  2255. }
  2256. }
  2257. Date finalStartTime = startTime;
  2258. Date finalExpiryTime = expiryTime;
  2259. try {
  2260. return build.call(() -> {
  2261. GroupsTrips groups = groupsMapper.selectCollegeStudentUserGptTicket(skuId);
  2262. if (groups == null) {
  2263. groups = groupsMapper.selectOne(Wrappers.lambdaQuery(GroupsTrips.class)
  2264. .eq(GroupsTrips::getStatus, GroupsTrips.Status.waiting)
  2265. .eq(GroupsTrips::getSkuId, skuId)
  2266. .last("limit 1"));
  2267. }
  2268. GroupsRelation relation = null;
  2269. if (groups != null) {
  2270. relation = groupsRelationMapper.selectRandomOneRelationByGroupsId(groups.getId());
  2271. }
  2272. //生成空车队
  2273. if (relation == null) {
  2274. relation = groupsFuncService.createNewGroupsTrips(sku);
  2275. }
  2276. int update = groupsRelationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
  2277. .set(GroupsRelation::getUserId, userId)
  2278. .set(GroupsRelation::getStartTime, finalStartTime)
  2279. .set(GroupsRelation::getExpiryTime, finalExpiryTime)
  2280. .set(GroupsRelation::getStatus, GroupsRelation.Status.validity)
  2281. .eq(GroupsRelation::getId, relation.getId())
  2282. .eq(GroupsRelation::getUserId, 0));
  2283. if (update > 0) {
  2284. groupsMapper.decrAvailableNum(relation.getGroupsId());
  2285. Long relationId = relation.getId();
  2286. //生成新的订单
  2287. OrderDon otherOrderDon = generateNewTicketOrder(relationId, userId, sku);
  2288. TicketChangeDto ticketChangeDto = new TicketChangeDto();
  2289. ticketChangeDto.setOtherRelationId(relationId);
  2290. ticketChangeDto.setOtherOrderId(otherOrderDon.getId());
  2291. return ticketChangeDto;
  2292. }
  2293. log.error("发送用户:{} GPT镜像车票失败,进行重试", userId);
  2294. return null;
  2295. });
  2296. } catch (ExecutionException | RetryException e) {
  2297. log.error("发送用户GPT镜像失败:{}", StringUtil.getErrorText(e));
  2298. return null;
  2299. }
  2300. }
  2301. private OrderDon generateNewTicketOrder(Long relationId, Long userId, GoodsDonSku sku) {
  2302. OrderDon orderDon = new OrderDon();
  2303. orderDon.setUserId(userId);
  2304. orderDon.setOrderNo(SEQUENCE.nextId().toString());
  2305. orderDon.setMoney(BigDecimal.ZERO);
  2306. orderDon.setRelationId(relationId);
  2307. orderDon.setGoodsId(sku.getGoodsId());
  2308. orderDon.setSkuId(sku.getId());
  2309. orderDon.setType(OrderDon.Type.TICKET_REPLACE);
  2310. orderDon.setStatus(OrderDon.Status.complete);
  2311. orderDonMapper.insert(orderDon);
  2312. return orderDon;
  2313. }
  2314. private void setAIZoneMirrorTicketInfo(UserMirrorTicketView ticket) {
  2315. setAIZoneGptMirrorInfo(ticket);
  2316. }
  2317. private void setAIZoneGptMirrorInfo(UserMirrorTicketView ticket) {
  2318. if (ticket.getGoodsId() != null && ticket.getGoodsId() == Constant.GPT_PLUS_GID) {
  2319. ChatgptUser chatgptUser = chatgptUserMapper.selectOne(Wrappers.lambdaQuery(ChatgptUser.class)
  2320. .eq(ChatgptUser::getRelationId, ticket.getRelationId())
  2321. .last("limit 1"));
  2322. if (chatgptUser != null) {
  2323. ticket.setModel(chatgptUser.getModel());
  2324. }
  2325. }
  2326. }
  2327. }