| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034 |
- package com.cyksj.web.controller.group;
- import cn.hutool.core.collection.CollUtil;
- import cn.hutool.core.date.DateTime;
- import cn.hutool.core.date.DateUnit;
- import cn.hutool.core.date.DateUtil;
- import cn.hutool.core.lang.Assert;
- import cn.hutool.core.thread.ThreadUtil;
- import cn.hutool.core.util.StrUtil;
- import cn.hutool.extra.servlet.ServletUtil;
- import cn.hutool.json.JSONObject;
- import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
- import com.baomidou.mybatisplus.core.toolkit.Wrappers;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.cyksj.common.annotation.NoSubmit;
- import com.cyksj.common.constant.Constant;
- import com.cyksj.common.exception.BusinessRuntimeException;
- import com.cyksj.common.snowflake.Sequence;
- import com.cyksj.common.task.GlobalThreadPoolTaskExecutor;
- import com.cyksj.common.util.GoogleGenerator;
- import com.cyksj.common.util.Jsons;
- import com.cyksj.dto.Result;
- import com.cyksj.enums.GatewayResponse;
- import com.cyksj.mapper.*;
- import com.cyksj.mapper.manage.form.FormFieldsDataMapper;
- import com.cyksj.mapper.manage.form.QuestionnairePromotionMapper;
- import com.cyksj.model.dto.DoubleVerifyDto;
- import com.cyksj.model.dto.QuestionnaireView;
- import com.cyksj.model.entity.*;
- import com.cyksj.model.manage.views.GroupsRelationView;
- import com.cyksj.model.request.*;
- import com.cyksj.model.response.GptStandbyResp;
- import com.cyksj.model.views.*;
- import com.cyksj.redis.RedisService;
- import com.cyksj.service.chatgpt.ChatGptAuthService;
- import com.cyksj.service.mange.CmsOrderDonService;
- import com.cyksj.service.mange.coupon.CouponCommonService;
- import com.cyksj.service.mange.ticket.TicketAdvertiseConfigClickRecordService;
- import com.cyksj.service.order.OrderDonService;
- import com.cyksj.service.relation.GroupRelationFrontService;
- import com.cyksj.service.relation.GroupsRelationNetflixService;
- import com.cyksj.service.user.UserBindRelationService;
- import com.cyksj.service.user.UserService;
- import com.cyksj.web.util.StpUserUtil;
- import com.ejlchina.searcher.BeanSearcher;
- import com.ejlchina.searcher.SearchResult;
- import com.ejlchina.searcher.operator.LessEqual;
- import com.ejlchina.searcher.param.Operator;
- import com.ejlchina.searcher.util.MapBuilder;
- import com.ejlchina.searcher.util.MapUtils;
- import lombok.RequiredArgsConstructor;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.validation.annotation.Validated;
- import org.springframework.web.bind.annotation.*;
- import javax.servlet.http.HttpServletRequest;
- import javax.validation.constraints.NotEmpty;
- import javax.validation.constraints.NotNull;
- import java.math.BigDecimal;
- import java.math.RoundingMode;
- import java.util.*;
- import java.util.concurrent.TimeUnit;
- import java.util.concurrent.atomic.AtomicInteger;
- import java.util.concurrent.atomic.AtomicLong;
- import java.util.stream.Collectors;
- /**
- * @author chan
- * @date 2022/9/27 11:48 AM
- */
- @Slf4j
- @RequiredArgsConstructor
- @RestController
- @RequestMapping("/applets/group/relation")
- public class GroupRelationController {
- private final BeanSearcher beanSearcher;
- private final OrderDonService orderDonService;
- private final GroupsRelationMapper relationMapper;
- private final GroupRelationFrontService groupRelationFrontService;
- private final UserService userService;
- private final UserBindRelationService userBindRelationService;
- private final TicketPwdViewRecordMapper ticketPwdViewRecordMapper;
- private final HttpServletRequest request;
- private final AccountDoubleVerifyRecordMapper accountDoubleVerifyRecordMapper;
- private final DoubleVerifyClickRecordMapper doubleVerifyRecordMapper;
- private final RedisService redisService;
- private final DoubleVerifyClickRefreshRecordMapper refreshRecordMapper;
- private final QuestionResponseRecordMapper questionResponseRecordMapper;
- private final CouponCommonService couponCommonService;
- private final FormFieldsDataMapper formFieldsDataMapper;
- private final QuestionnairePromotionMapper questionnairePromotionMapper;
- private final TicketAdvertiseConfigClickRecordService ticketAdvertiseConfigClickRecordService;
- private final GlobalThreadPoolTaskExecutor THREAD_POOL;
- private final ChatGptAuthService chatGptAuthService;
- private final GoodsCoursewareFileMapper goodsCoursewareFileMapper;
- private final GptTicketStandbyMapper gptTicketStandbyMapper;
- private final CmsOrderDonService cmsOrderDonService;
- private final GoodsDonSkuMapper goodsDonSkuMapper;
- private final AccountBlockedReplaceRecordMapper accountBlockedReplaceRecordMapper;
- private final OrderDonMapper orderDonMapper;
- private final UserGoodsNewbieGuideRecordMapper userGoodsNewbieGuideRecordMapper;
- private final GroupsRelationNetflixService groupsRelationNetflixService;
- private final ChatgptUserMapper chatgptUserMapper;
- private final UpgradeOrderDonMapper upgradeOrderDonMapper;
- private final static Sequence SEQUENCE = new Sequence(0);
- @RequestMapping("/get/renewal")
- public Result<SearchResult<RenewalView>> get(Boolean isLoginPopularize, String customId, String account) {
- long userId = StpUserUtil.getLoginIdAsLong();
- SearchResult<RenewalView> list = groupRelationFrontService.getMyTicket(userId, isLoginPopularize, customId, account);
- return GatewayResponse.SUCCESS.newBuilder().toResult(list);
- }
- @GetMapping("/get/pay/goods")
- public Result<List<RenewalView>> getHasPayGoods() {
- long userId = StpUserUtil.getLoginIdAsLong();
- List<RenewalView> hasPayGoods = groupRelationFrontService.getHasPayGoods(userId);
- return GatewayResponse.SUCCESS.newBuilder().toResult(hasPayGoods);
- }
- @PostMapping("/post/renewal")
- public Result<OrderDon> renewal(@RequestBody OrderPayRequest payRequest) throws Exception {
- long userId = StpUserUtil.getLoginIdAsLong();
- payRequest.setUserId(userId);
- String ip = ServletUtil.getClientIP(request);
- payRequest.setIp(ip);
- OrderDon orderDon = orderDonService.renewal(payRequest);
- return GatewayResponse.SUCCESS.newBuilder().toResult(orderDon);
- }
- @PutMapping("/update/set/account")
- public Result<String> setAccount(@RequestBody GroupsRelation relation) {
- long userId = StpUserUtil.getLoginIdAsLong();
- List<Long> userIds = userBindRelationService.getRelationUserIdList(userId, null);
- GroupsRelation re = relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
- .eq(GroupsRelation::getId, relation.getId())
- .in(GroupsRelation::getUserId, userIds)
- .last(" limit 1"));
- if (re == null) {
- throw new BusinessRuntimeException("该车票不存在,请联系客服.");
- }
- LambdaUpdateWrapper<GroupsRelation> updateWrapper = Wrappers.lambdaUpdate(GroupsRelation.class)
- .set(GroupsRelation::getAccount, relation.getAccount())
- .set(GroupsRelation::getPassword, relation.getPassword())
- .eq(GroupsRelation::getId, relation.getId());
- if (re.getRechargeStatus() != null) {
- if (re.getRechargeStatus() == GroupsRelation.RechargeStatus.complete) {
- throw BusinessRuntimeException.getInstance("代充账号已充值");
- }
- if (StrUtil.isEmpty(relation.getAccount()) || StrUtil.isEmpty(relation.getPassword())) {
- throw BusinessRuntimeException.getInstance("请输入正确的账号密码信息");
- }
- if (re.getRechargeStatus() == GroupsRelation.RechargeStatus.error) {
- updateWrapper.set(GroupsRelation::getRechargeStatus, GroupsRelation.RechargeStatus.waiting);
- }
- }
- relationMapper.update(relation, updateWrapper);
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- /**
- * 查询是否加入了企业微信
- */
- @GetMapping("/check/joinCorpWx")
- public Result<Boolean> isJoinCorpWx() {
- long userId = StpUserUtil.getLoginIdAsLong();
- Boolean flag = groupRelationFrontService.isJoinCorpWx(userId, false, false);
- return GatewayResponse.SUCCESS.newBuilder().toResult(flag);
- }
- /**
- * 获取全部车票
- */
- @GetMapping("/get")
- public Result<List<UserTicketView>> getUserTicketView() {
- long userId = StpUserUtil.getLoginIdAsLong();
- List<Long> userIds = userBindRelationService.getRelationUserIdList(userId, null);
- List<UserTicketView> ticketViews = beanSearcher.searchAll(UserTicketView.class, MapUtils.flatBuilder(request.getParameterMap())
- .field(UserTicketView::getUserId, userIds).op(Operator.InList)
- .field(RenewalView::getStatus, List.of("validity", "outside")).op(Operator.InList)
- .orderBy(UserTicketView::getRelationId).asc()
- .build());
- return GatewayResponse.SUCCESS.newBuilder().toResult(ticketViews);
- }
- /**
- * 记录查看ChatGPT车票密码
- */
- @GetMapping("/recordView/{relationId}")
- public Result<String> recordGPTPwdView(@PathVariable Long relationId) {
- long userId = StpUserUtil.getLoginIdAsLong();
- List<Long> userIds = userBindRelationService.getRelationUserIdList(userId, null);
- GroupsRelationView groupsRelationView = beanSearcher.searchFirst(GroupsRelationView.class, MapUtils.builder()
- .field(GroupsRelationView::getUserId, userIds).op(Operator.InList)
- .field(GroupsRelationView::getId, relationId).build());
- if (groupsRelationView == null) {
- log.info("userId:{}查看relationId:{}车票不存在", userId, relationId);
- throw BusinessRuntimeException.getInstance("该车票已不存在");
- }
- if (groupsRelationView.getAccountId() == null) throw BusinessRuntimeException.getInstance("该车队未配置账号");
- if (groupRelationFrontService == null) throw BusinessRuntimeException.getInstance("车票已不存在");
- TicketPwdViewRecord viewRecord = new TicketPwdViewRecord();
- viewRecord.setUserId(userId);
- viewRecord.setRelationId(relationId);
- viewRecord.setSkuId(groupsRelationView.getSkuId());
- viewRecord.setOperateLocation(ServletUtil.getClientIP(request));
- viewRecord.setAccount(groupsRelationView.getTripsAccount());
- viewRecord.setPassword(groupsRelationView.getTripsPassword());
- ticketPwdViewRecordMapper.insert(viewRecord);
- if (groupsRelationView.getGoodsId() == 18 && StrUtil.isEmpty(groupsRelationView.getApiSecret())) {
- THREAD_POOL.execute(() -> {
- //车队所有人查看密码
- Integer num = groupsRelationView.getGtNum();
- Integer viewNum = relationMapper.selectViewPwdCount(groupsRelationView.getGroupsId());
- if (num <= viewNum) {
- AccountDoubleVerifyRecord exist = accountDoubleVerifyRecordMapper.selectOne(Wrappers.lambdaQuery(AccountDoubleVerifyRecord.class)
- .eq(AccountDoubleVerifyRecord::getAccountId, groupsRelationView.getAccountId())
- .eq(AccountDoubleVerifyRecord::getDeleted, true).last("limit 1"));
- if (exist == null) {
- if (redisService.setNx(String.format("%s-%s", groupsRelationView.getAccountId(), groupsRelationView.getId()), groupsRelationView.getId(), 60l)) {
- //记录
- AccountDoubleVerifyRecord accountDoubleVerifyRecord = new AccountDoubleVerifyRecord();
- accountDoubleVerifyRecord.setAccountId(groupsRelationView.getAccountId());
- accountDoubleVerifyRecord.setAccount(groupsRelationView.getTripsAccount());
- accountDoubleVerifyRecord.setGroupsId(groupsRelationView.getGroupsId());
- accountDoubleVerifyRecord.setSkuId(groupsRelationView.getSkuId());
- accountDoubleVerifyRecord.setRemark("车队所有人看过密码");
- accountDoubleVerifyRecordMapper.insert(accountDoubleVerifyRecord);
- }
- }
- }
- });
- }
- return GatewayResponse.SUCCESS.newBuilder().toResult(groupsRelationView.getTripsPassword());
- }
- /**
- * 获取AI类 ChatGPT产品谷歌验证码
- */
- @GetMapping("/get/authCode")
- public Result<String> getAuthCode(Long relationId) {
- long userId = StpUserUtil.getLoginIdAsLong();
- List<Long> userIds = userBindRelationService.getRelationUserIdList(userId, null);
- if (relationId == null) throw BusinessRuntimeException.getInstance("车票不存在");
- GroupsRelationView groupsRelationView = beanSearcher.searchFirst(GroupsRelationView.class, MapUtils.builder()
- .field(GroupsRelationView::getId, relationId)
- .field(GroupsRelationView::getUserId, userIds).op(Operator.InList).build());
- if (groupsRelationView == null) throw BusinessRuntimeException.getInstance("车票不存在");
- if (StrUtil.isEmpty(groupsRelationView.getApiSecret())) throw BusinessRuntimeException.getInstance("未开启验证");
- DateTime now = DateTime.now();
- Integer count = doubleVerifyRecordMapper.selectCount(Wrappers.lambdaQuery(DoubleVerifyClickRecord.class)
- .in(DoubleVerifyClickRecord::getUserId, userIds)
- .eq(DoubleVerifyClickRecord::getRelationId, relationId)
- .eq(DoubleVerifyClickRecord::getAccountId, groupsRelationView.getAccountId())
- .between(DoubleVerifyClickRecord::getCreatedTime, DateUtil.beginOfMonth(now), DateUtil.endOfMonth(now)));
- //获取双重验证码
- Boolean isHasVerifyCode = StrUtil.isNotBlank(groupsRelationView.getVerifyCode()) ? true : false;
- //出去亚马逊 获取限制
- if (groupsRelationView.getGoodsId() != 6) {
- Integer num = groupRelationFrontService.getUserCodeNumBySkuId(userId, groupsRelationView.getSkuId(), isHasVerifyCode);
- if (count >= num) throw BusinessRuntimeException.getInstance("获取双重验证码次数上限");
- }
- //一分钟内 只能一人获取
- boolean b = redisService.setNx(RedisService.key.DOUBLE_VERIFY_CODE_VIEW_MINUTES_KEY.getName() + groupsRelationView.getTripsAccount(), relationId, RedisService.key.DOUBLE_VERIFY_CODE_VIEW_MINUTES_KEY.getTimeout());
- if (!b) {
- throw BusinessRuntimeException.getInstance("一分钟内已有人获取该账号验证码,请稍后获取..");
- }
- int second = now.second();
- if (second < 30 && 30 - second < 3) {
- ThreadUtil.sleep(30 - second + 1, TimeUnit.SECONDS);
- } else if (second > 30 && 60 - second < 3) {
- ThreadUtil.sleep(60 - second + 1, TimeUnit.SECONDS);
- }
- StringBuilder sb = new StringBuilder();
- JSONObject re = new JSONObject();
- try {
- long code = GoogleGenerator.getCode(groupsRelationView.getApiSecret(), now.getTime());
- sb.append(code);
- while (sb.length() < 6) {
- sb.insert(0, 0);
- }
- re.putOpt("code", sb.toString());
- int nowSecond = DateTime.now().second();
- int time = 0;
- if (nowSecond < 30) {
- time = 30 - nowSecond;
- } else {
- time = 60 - nowSecond;
- }
- re.putOpt("time", time);
- DoubleVerifyClickRecord doubleVerifyClickRecord = new DoubleVerifyClickRecord();
- doubleVerifyClickRecord.setRelationId(relationId);
- doubleVerifyClickRecord.setUserId(userId);
- doubleVerifyClickRecord.setAccountId(groupsRelationView.getAccountId());
- doubleVerifyClickRecord.setAccount(groupsRelationView.getTripsAccount());
- doubleVerifyClickRecord.setSkuId(groupsRelationView.getSkuId());
- doubleVerifyClickRecord.setCode(sb.toString());
- doubleVerifyClickRecord.setRemainTime(time);
- doubleVerifyRecordMapper.insert(doubleVerifyClickRecord);
- DoubleVerifyDto doubleVerifyDto = new DoubleVerifyDto();
- doubleVerifyDto.setClickId(doubleVerifyClickRecord.getId());
- doubleVerifyDto.setApiSecret(groupsRelationView.getApiSecret());
- redisService.set(String.format("%s-%s", userId, sb.toString()), 0, 60 * 10l);
- redisService.set(String.format("%s/%s", userId, sb.toString()), Jsons.toJson(doubleVerifyDto), 60 * 10l);
- } catch (Exception e) {
- throw BusinessRuntimeException.getInstance("获取双重验证码错误,请联系客服");
- }
- return GatewayResponse.SUCCESS.newBuilder().toResult(re.toString());
- }
- /**
- * 刷新验证码
- */
- @GetMapping("/refresh/code")
- public Result<String> refreshCode(String code) {
- long userId = StpUserUtil.getLoginIdAsLong();
- String numKey = String.format("%s-%s", userId, code);
- Object num = redisService.get(numKey);
- String objKey = String.format("%s/%s", userId, code);
- Object objValue = redisService.get(objKey);
- if (objValue == null || num == null) {
- throw BusinessRuntimeException.getInstance("请重新获取双重验证码");
- }
- Integer refreshNum = Integer.parseInt(num.toString());
- String apiSecret = null;
- Long clickId = 0l;
- try {
- DoubleVerifyDto dto = Jsons.parseObject(objValue.toString(), DoubleVerifyDto.class);
- apiSecret = dto.getApiSecret();
- clickId = dto.getClickId();
- } catch (Exception e) {
- apiSecret = objValue.toString();
- }
- if (refreshNum >= 3) {
- redisService.del(numKey);
- redisService.del(objKey);
- throw BusinessRuntimeException.getInstance("刷新次数已达到3次,请重新获取验证码");
- }
- if (apiSecret == null) {
- throw BusinessRuntimeException.getInstance("请重新获取双重验证码");
- }
- StringBuilder sb = new StringBuilder();
- try {
- long c = GoogleGenerator.getCode(apiSecret, DateTime.now().getTime());
- sb.append(c);
- while (sb.length() < 6) {
- sb.insert(0, 0);
- }
- redisService.incr(numKey, 1l);
- } catch (Exception e) {
- throw BusinessRuntimeException.getInstance("刷新双重验证码错误,请联系客服");
- }
- if (clickId != 0) {
- int nowSecond = DateTime.now().second();
- int time = 0;
- if (nowSecond < 30) {
- time = 30 - nowSecond;
- } else {
- time = 60 - nowSecond;
- }
- //刷新双重验证码记录
- DoubleVerifyClickRefreshRecord refreshRecord = new DoubleVerifyClickRefreshRecord();
- refreshRecord.setClickId(clickId);
- refreshRecord.setUserId(userId);
- refreshRecord.setCode(sb.toString());
- refreshRecord.setRemainTime(time);
- refreshRecordMapper.insert(refreshRecord);
- }
- return GatewayResponse.SUCCESS.newBuilder().toResult(sb.toString());
- }
- /**
- * 获取双重验证码记录
- */
- @GetMapping("/get/doubleVerify/codeList")
- public Result<List<DoubleVerifyCodeView>> getDoubleVerifyCodeList(Long relationId) {
- long userId = StpUserUtil.getLoginIdAsLong();
- List<DoubleVerifyCodeView> views = doubleVerifyRecordMapper.getDoubleVerifyCodeList(userId, relationId);
- return GatewayResponse.SUCCESS.newBuilder().toResult(views);
- }
- /**
- * 用户是不是自然流量渠道
- * 且未回答答题
- */
- @GetMapping("/natural/channel")
- public Result<Boolean> isNaturalChannel() {
- long userId = StpUserUtil.getLoginIdAsLong();
- String question_key = RedisService.key.QUESTION_RESPONSE_KEY.getNameFormat(userId);
- if (redisService.get(question_key) != null) {
- return GatewayResponse.SUCCESS.newBuilder().toResult(false);
- }
- User user = userService.getById(userId);
- if (user.getPopularizeId() != 0) {
- redisService.set(question_key, userId, RedisService.key.QUESTION_RESPONSE_KEY.getTimeout());
- return GatewayResponse.SUCCESS.newBuilder().toResult(false);
- }
- if (user.getPopularizeId() == 0) {
- QuestionResponseRecord record = questionResponseRecordMapper.selectOne(Wrappers.lambdaQuery(QuestionResponseRecord.class)
- .eq(QuestionResponseRecord::getUserId, userId).select(QuestionResponseRecord::getId).last("limit 1"));
- if (record != null) {
- redisService.set(question_key, userId, RedisService.key.QUESTION_RESPONSE_KEY.getTimeout());
- return GatewayResponse.SUCCESS.newBuilder().toResult(false);
- }
- return GatewayResponse.SUCCESS.newBuilder().toResult(true);
- }
- return GatewayResponse.SUCCESS.newBuilder().toResult(false);
- }
- /**
- * 问卷记录
- */
- @PostMapping("/record/replyQuestion")
- public Result<String> recordReplyQuestion(@RequestBody @Validated QuestionResponseRecord record) {
- long userId = StpUserUtil.getLoginIdAsLong();
- User user = userService.getById(userId);
- String nickname = user.getNickname();
- String question_key = RedisService.key.QUESTION_RESPONSE_KEY.getNameFormat(userId);
- QuestionResponseRecord dbRecord = questionResponseRecordMapper.selectOne(Wrappers.lambdaQuery(QuestionResponseRecord.class)
- .eq(QuestionResponseRecord::getUserId, userId).select(QuestionResponseRecord::getId).last("limit 1"));
- if (dbRecord == null) {
- if (redisService.setNx(String.format("%s-%s", userId, nickname), userId, 10l)) {
- record.setUserId(userId);
- record.setNickname(nickname);
- questionResponseRecordMapper.insert(record);
- //发放优惠券
- couponCommonService.sendCouponToUser(userId, 100l, 0l, 0l, 0l, CouponUser.Channel.ques_response);
- redisService.set(question_key, userId, RedisService.key.QUESTION_RESPONSE_KEY.getTimeout());
- }
- }
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- /**
- * 获取对应的动态问卷
- */
- @GetMapping("/get/questionnaire")
- public Result<List<QuestionnaireView>> getQuestionnaireView(Long promotionId) {
- QuestionnairePromotion promotion = questionnairePromotionMapper.selectById(promotionId);
- if (promotion == null || !promotion.getDeleted()) throw BusinessRuntimeException.getInstance("问卷不存在");
- Long templateId = promotion.getTemplateId();
- List<QuestionnaireView> questionnaireViews = beanSearcher.searchAll(QuestionnaireView.class, MapUtils.builder()
- .field(QuestionnaireView::getPromotionId, promotionId)
- .orderBy(QuestionnaireView::getSorted).asc()
- .orderBy(QuestionnaireView::getFieldsId).asc()
- .build());
- return GatewayResponse.SUCCESS.newBuilder().toResult(questionnaireViews);
- }
- /**
- * 记录问卷
- */
- @PostMapping("/record/questionnaire/{promotionId}")
- @Transactional(rollbackFor = Exception.class)
- @NoSubmit
- public Result<String> recordQuestionnaire(@PathVariable Long promotionId, String showId, @RequestBody List<FormFieldsData> answers) {
- Long userId = StpUserUtil.getUserIdAfterLogin();
- Long groupsId = SEQUENCE.nextId();
- List<QuestionnairePromotionFieldsListView> promotionFieldsListViews = beanSearcher.searchAll(QuestionnairePromotionFieldsListView.class, MapUtils.builder().field(QuestionnairePromotionFieldsListView::getPromotionId, promotionId).build());
- if (CollUtil.isEmpty(promotionFieldsListViews)) throw BusinessRuntimeException.getInstance("问卷已结束");
- if (promotionFieldsListViews.size() != answers.size()) throw BusinessRuntimeException.getInstance("请完成所有问题");
- log.info("开始记录问卷:{}", promotionId);
- answers.forEach(answer -> {
- // if (StringUtil.isNotBlank(showId)) {
- // answer.setUserId(userService.getUserIdByShowId(showId));
- // }
- answer.setUserId(userId);
- Long fieldsId = answer.getFieldsId();
- String content = answer.getContent();
- if (fieldsId == null || StrUtil.isBlank(content)) {
- throw BusinessRuntimeException.getInstance("必填项为空");
- }
- answer.setPromotionId(promotionId);
- answer.setGroupsId(groupsId);
- formFieldsDataMapper.insert(answer);
- });
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- /**
- * 查询用户是否填写问卷
- */
- @GetMapping("/check/questionnaire/{promotionId}")
- public Result<Boolean> checkQuestionnaire(@PathVariable Long promotionId) {
- long userId = StpUserUtil.getLoginIdAsLong();
- List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
- Integer count = formFieldsDataMapper.selectCount(Wrappers.lambdaQuery(FormFieldsData.class).in(FormFieldsData::getUserId, userIdList).eq(FormFieldsData::getPromotionId, promotionId));
- return GatewayResponse.SUCCESS.newBuilder().toResult(count > 0);
- }
- /**
- * 对应平台车票 广告配置列表
- */
- @GetMapping("/get/advertise/{goodsId}")
- public Result<List<TicketAdvertiseConfigFrontView>> getTicketAdvertiseConfig(@PathVariable Long goodsId) {
- long userId = StpUserUtil.getLoginIdAsLong();
- log.info("userId:{}获取广告位配置", userId);
- List<TicketAdvertiseConfigFrontView> views = beanSearcher.searchAll(TicketAdvertiseConfigFrontView.class, MapUtils.flatBuilder(request.getParameterMap())
- .field(TicketAdvertiseConfig::getGoodsId, goodsId)
- .orderBy(TicketAdvertiseConfig::getSorted).desc()
- .orderBy(TicketAdvertiseConfig::getId).desc()
- .build());
- return GatewayResponse.SUCCESS.newBuilder().toResult(views);
- }
- /**
- * 记录用户点击车票广告
- */
- @PostMapping("/click/ticket/advertise/record/{configId}")
- public Result<String> recordClickTicketAdvertise(@PathVariable Long configId) {
- long userId = StpUserUtil.getLoginIdAsLong();
- ticketAdvertiseConfigClickRecordService.recordUserClickTicketAdvertise(userId, configId);
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- /**
- * 推荐平台
- */
- @GetMapping("/get/recommend/goods")
- public Result<Page<UserRecommendGoodsFrontView>> getRecommendGoodsViews(@RequestParam(defaultValue = "0") Integer start, @RequestParam(defaultValue = "5") Integer limit) {
- //推荐用户未购买的车票平台 优先展示ai类平台 然后是影视流媒体
- long userId = StpUserUtil.getLoginIdAsLong();
- List<Long> userIds = userBindRelationService.getRelationUserIdList(userId, null);
- List<Long> filter_goods_id = relationMapper.getTicketGoodsId(userIds, List.of("validity", "overdue", "outside"));
- //用户是否购买过奈飞产品
- Boolean isPayNf = false;
- if (filter_goods_id.contains(1l)) {
- isPayNf = true;
- } else {
- int count = orderDonService.count(Wrappers.lambdaQuery(OrderDon.class)
- .eq(OrderDon::getGoodsId, 1)
- .eq(OrderDon::getUserId, userId)
- .notIn(OrderDon::getStatus, Constant.noOrderAllStatus));
- if (count > 0) {
- //优先展示路由器、ai、流媒体
- isPayNf = true;
- }
- }
- Boolean filterCourseGoods = false;
- //GPT Plus基础2月 课程不展示
- Integer orders = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
- .in(OrderDon::getUserId, userIds)
- .eq(OrderDon::getSkuId, 444)
- .notIn(OrderDon::getStatus, Constant.noOrderStatus));
- if (orders > 0) {
- filterCourseGoods = true;
- }
- Page<UserRecommendGoodsFrontView> page = groupRelationFrontService.getRecommendGoodsViews(isPayNf, filter_goods_id, filterCourseGoods, start, limit);
- return GatewayResponse.SUCCESS.newBuilder().toResult(page);
- }
- /**
- * 查看GPT token
- */
- @GetMapping("/get/gptAccessToken")
- public Result<String> getGptAccessToken(Long relationId) throws Exception {
- long userId = StpUserUtil.getLoginIdAsLong();
- List<Long> userIds = userBindRelationService.getRelationUserIdList(userId, null);
- //存在该车票
- RenewalView renewalView = beanSearcher.searchFirst(RenewalView.class, MapUtils.builder()
- .field(RenewalView::getRelationId, relationId)
- .field(RenewalView::getUserId, userIds).op(Operator.InList).build());
- Assert.notNull(renewalView, "您的车票不存在");
- if (renewalView.getGoodsId() != 42) {
- throw BusinessRuntimeException.getInstance("该平台类型车票无法获取GPT直连token");
- }
- String account = renewalView.getAccount();
- String accessToken = chatGptAuthService.getAccessToken(account);
- return GatewayResponse.SUCCESS.newBuilder().toResult(accessToken);
- }
- /**
- * 获取特殊类型课程 通过邮件发送课程
- * 领取课件
- */
- @PostMapping("/courseware")
- public Result<String> getCourseWare(@RequestBody SpecialGoodsTicketReq request) throws Exception {
- long userId = StpUserUtil.getLoginIdAsLong();
- request.setUserId(userId);
- groupRelationFrontService.sendCourseWare(request);
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- //获取课程云盘链接
- @GetMapping("/get/courseware")
- public Result<GoodsCoursewareFile> getGoodsCourseware(Long relationId) {
- long userId = StpUserUtil.getLoginIdAsLong();
- List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
- RenewalView relationView = beanSearcher.searchFirst(RenewalView.class, MapUtils.builder()
- .field(RenewalView::getUserId, userIdList).op(Operator.InList)
- .field(RenewalView::getRelationId, relationId).build());
- if (relationView == null) {
- throw BusinessRuntimeException.getInstance("您的车票不存在");
- }
- GoodsCoursewareFile goodsCoursewareFile = goodsCoursewareFileMapper.selectOne(Wrappers.lambdaQuery(GoodsCoursewareFile.class)
- .eq(GoodsCoursewareFile::getGoodsId, relationView.getGoodsId())
- .eq(GoodsCoursewareFile::getStatus, true)
- .select(GoodsCoursewareFile::getLink, GoodsCoursewareFile::getCode)
- .last("limit 1"));
- if (goodsCoursewareFile == null) {
- throw BusinessRuntimeException.getInstance("暂未配置课件链接地址,请联系客服");
- }
- return GatewayResponse.SUCCESS.newBuilder().toResult(goodsCoursewareFile);
- }
- /**
- * 读取车票账号登录验证码
- */
- @PostMapping("/get/verifyCode")
- public Result<String> getAiVerifyCode(@RequestBody TicketLoginReq loginReq) throws Exception {
- long userId = StpUserUtil.getLoginIdAsLong();
- loginReq.setUserId(userId);
- return GatewayResponse.SUCCESS.newBuilder().toResult(groupRelationFrontService.getAiVerifyCode(loginReq));
- }
- /**
- * 车票后台登录
- */
- @PostMapping("/ticket/login")
- public Result<GroupsRelation> ticketLogin(@RequestBody TicketLoginReq loginReq) {
- GroupsRelation relation = groupRelationFrontService.ticketLogin(loginReq);
- return GatewayResponse.SUCCESS.newBuilder().toResult(relation);
- }
- /**
- * 奈飞验证校验
- */
- @PostMapping("/ticket/verify")
- public Result<String> outsideTicketVerify(@RequestBody TicketLoginReq loginReq) {
- return GatewayResponse.SUCCESS.newBuilder().toResult(groupRelationFrontService.outsideTicketVerify(loginReq));
- }
- /**
- * 是否有mid车票可候补
- */
- @GetMapping("/get/standby")
- public Result<GptStandbyResp> getGptStandby() {
- long userId = StpUserUtil.getLoginIdAsLong();
- List<Long> relationUserIdList = userBindRelationService.getRelationUserIdList(userId, null);
- String condition = "(a.account like '%@yinhe.ac.cn%' or exists (select id from account_blocked_replace_record abrr where abrr.account = a.account and abrr.goods_id = g.id limit 1))";
- List<RenewalView> renewalViewList = beanSearcher.searchAll(RenewalView.class, MapUtils.builder()
- .field(RenewalView::getUserId, relationUserIdList).op(Operator.InList)
- .field(RenewalView::getGoodsId, 26)
- .put("condition", condition)
- .field(RenewalView::getExpiryTime).op(Operator.NotNull)
- .onlySelect(RenewalView::getAccount, RenewalView::getExpiryTime)
- .build());
- GptStandbyResp gptStandbyResp = new GptStandbyResp();
- if (renewalViewList.isEmpty()) {
- gptStandbyResp.setIsHasAccount(false);
- return GatewayResponse.SUCCESS.newBuilder().toResult(gptStandbyResp);
- }
- List<RenewalView> overTen = new ArrayList<>();
- List<RenewalView> underTen = new ArrayList<>();
- DateTime now = DateTime.now();
- renewalViewList.forEach(e -> {
- if (e.getExpiryTime().compareTo(DateUtil.offsetDay(now, 10)) > 0) {
- overTen.add(e);
- } else underTen.add(e);
- });
- Integer accountBlockedCount = 1;
- if (overTen.size() > 1) {
- List<String> accountList = overTen.stream().map(RenewalView::getAccount).distinct().collect(Collectors.toList());
- accountBlockedCount = accountBlockedReplaceRecordMapper.selectCount(Wrappers.lambdaQuery(AccountBlockedReplaceRecord.class)
- .eq(AccountBlockedReplaceRecord::getGoodsId, 26)
- .in(AccountBlockedReplaceRecord::getAccount, accountList));
- }
- if (accountBlockedCount > 1) {
- gptStandbyResp.setIsHasAccount(false);
- return GatewayResponse.SUCCESS.newBuilder().toResult(gptStandbyResp);
- }
- gptStandbyResp.setIsHasAccount(true);
- gptStandbyResp.setOverTen(overTen);
- gptStandbyResp.setUnderTen(underTen);
- Integer count = gptTicketStandbyMapper.selectCount(Wrappers.lambdaQuery(GptTicketStandby.class)
- .in(GptTicketStandby::getUserId, relationUserIdList));
- gptStandbyResp.setIsApply(count > 0 ? true : false);
- return GatewayResponse.SUCCESS.newBuilder().toResult(gptStandbyResp);
- }
- /**
- * 申请候补
- */
- @PostMapping("/apply/standby")
- @NoSubmit
- public Result<Boolean> applyGptStandby() {
- long userId = StpUserUtil.getLoginIdAsLong();
- List<Long> relationUserIdList = userBindRelationService.getRelationUserIdList(userId, null);
- String condition = "(a.account like '%@yinhe.ac.cn%' or exists (select id from account_blocked_replace_record abrr where abrr.account = a.account and abrr.goods_id = g.id limit 1))";
- List<RenewalView> renewalViewList = beanSearcher.searchAll(RenewalView.class, MapUtils.builder()
- .field(RenewalView::getUserId, relationUserIdList).op(Operator.InList)
- .field(RenewalView::getGoodsId, 26)
- .put("condition", condition)
- .field(RenewalView::getExpiryTime, DateUtil.offsetDay(DateTime.now(), 10)).op(Operator.GreaterThan)
- .onlySelect(RenewalView::getAccount)
- .build());
- if (renewalViewList.isEmpty()) {
- throw BusinessRuntimeException.getInstance("你未有车票账号");
- }
- Integer count = gptTicketStandbyMapper.selectCount(Wrappers.lambdaQuery(GptTicketStandby.class)
- .in(GptTicketStandby::getUserId, relationUserIdList));
- if (count > 0) {
- throw BusinessRuntimeException.getInstance("你已申请车票账号候补");
- }
- if (renewalViewList.size() > 1) {
- Set<String> accountSet = renewalViewList.stream().map(RenewalView::getAccount).collect(Collectors.toSet());
- Integer accountBlockedCount = accountBlockedReplaceRecordMapper.selectCount(Wrappers.lambdaQuery(AccountBlockedReplaceRecord.class)
- .eq(AccountBlockedReplaceRecord::getGoodsId, 26)
- .in(AccountBlockedReplaceRecord::getAccount, accountSet));
- if (accountBlockedCount > 1) {
- return GatewayResponse.SUCCESS.newBuilder().toResult(true);
- }
- }
- GptTicketStandby gptTicketStandby = new GptTicketStandby();
- gptTicketStandby.setUserId(userId);
- gptTicketStandbyMapper.insert(gptTicketStandby);
- return GatewayResponse.SUCCESS.newBuilder().toResult(true);
- }
- /**
- * midjourney车票退款
- */
- @PutMapping("/refund/ticketOrder/{relationId}")
- @NoSubmit
- public Result<String> ticketRefundOrders(@PathVariable Long relationId) throws Exception {
- long userId = StpUserUtil.getLoginIdAsLong();
- List<Long> relationUserIdList = userBindRelationService.getRelationUserIdList(userId, null);
- String condition = "(a.account like '%@yinhe.ac.cn%' or exists (select id from account_blocked_replace_record abrr where abrr.account = a.account and abrr.goods_id = g.id limit 1))";
- RenewalView renewalView = beanSearcher.searchFirst(RenewalView.class, MapUtils.builder()
- .field(RenewalView::getRelationId, relationId)
- .field(RenewalView::getUserId, relationUserIdList).op(Operator.InList)
- .put("condition", condition)
- .field(RenewalView::getGoodsId, 26)
- .field(RenewalView::getExpiryTime, DateUtil.offsetDay(DateTime.now(), 10)).op(Operator.LessEqual)
- .build());
- if (renewalView == null) {
- throw BusinessRuntimeException.getInstance("你车票不存在或不符合退款要求");
- }
- OrderDon orderDon = orderDonService.getOne(Wrappers.lambdaQuery(OrderDon.class)
- .in(OrderDon::getUserId, relationUserIdList)
- .eq(OrderDon::getRelationId, relationId)
- .notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
- .orderByDesc(OrderDon::getId)
- .last("limit 1"));
- if (orderDon == null) {
- throw BusinessRuntimeException.getInstance("你对应车票的订单不存在");
- }
- GoodsDonSku sku = goodsDonSkuMapper.selectById(orderDon.getSkuId());
- if (sku == null) {
- throw BusinessRuntimeException.getInstance("该车票规格不存在,请联系客服进行人工退款..");
- }
- Date expiryTime = renewalView.getExpiryTime();
- long remainDay = DateUtil.between(DateTime.now(), expiryTime, DateUnit.DAY) + 1;
- BigDecimal money = orderDon.getMoney();
- BigDecimal refundMoney = null;
- BigDecimal refundBalance= null;
- String refundType = null;
- if (money.compareTo(BigDecimal.ZERO) > 0) {
- BigDecimal dayMoney = money.divide(BigDecimal.valueOf(sku.getMonths()).multiply(BigDecimal.valueOf(30)), 2, RoundingMode.HALF_DOWN);
- refundMoney = BigDecimal.valueOf(remainDay).multiply(dayMoney);
- refundType = "money";
- }
- OrderRefundReq refundReq = new OrderRefundReq();
- if (orderDon.getBalance().compareTo(BigDecimal.ZERO) > 0) {
- BigDecimal dayMoney = orderDon.getBalance().divide(BigDecimal.valueOf(sku.getMonths()).multiply(BigDecimal.valueOf(30)), 2, RoundingMode.HALF_DOWN);
- refundBalance = BigDecimal.valueOf(remainDay).multiply(dayMoney);
- refundReq.setIsOnly(true);
- }
- refundReq.setOrderId(orderDon.getId());
- refundReq.setRefundDesc("失效车票退款");
- refundReq.setRefundMoney(Optional.ofNullable(refundMoney).orElse(BigDecimal.ZERO));
- refundReq.setRefundBalance(Optional.ofNullable(refundBalance).orElse(BigDecimal.ZERO));
- refundReq.setRefundType(Optional.ofNullable(refundType).orElse("balance"));
- cmsOrderDonService.unifiedRefund(refundReq);
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- /**
- * 每日车票到期弹窗
- */
- @GetMapping("/get/expiry/notify")
- public Result<List<RenewalView>> getExpiryRenewalNotify() {
- Long userId = StpUserUtil.getLoginIdAsLong();
- List<RenewalView> expiryRenewals = groupRelationFrontService.getExpiryRenewalNotify(userId);
- return GatewayResponse.SUCCESS.newBuilder().toResult(expiryRenewals);
- }
- /**
- * 车票详情
- */
- @GetMapping("/get/detail")
- public Result<RenewalView> getTicketDetail(Long relationId) {
- if (relationId == null) {
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- long userId = StpUserUtil.getLoginIdAsLong();
- RenewalView ticketDetail = groupRelationFrontService.getTicketDetail(userId, relationId);
- return GatewayResponse.SUCCESS.newBuilder().toResult(ticketDetail);
- }
- /**
- * 车票售后常见问题
- */
- @GetMapping("/get/questions/{goodsId}")
- public Result<List<GoodsDonQaFrontView>> getTicketQuestions(@PathVariable Long goodsId, @RequestParam(defaultValue = "1") Integer type) {
- long userId = StpUserUtil.getLoginIdAsLong();
- log.info("userId:{}查看车票:{}售后问题", userId, goodsId);
- if (type < 1 || type > 2) {
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- String key = RedisService.key.YH_GOODS_QUESTIONS_DETAIL.getNameFormat(type, goodsId);
- Object o = redisService.get(key);
- if (o == null) {
- List<GoodsDonQaFrontView> donQaFrontViews = beanSearcher.searchAll(GoodsDonQaFrontView.class, MapUtils.builder().field(GoodsDonQaFrontView::getGoodsId, goodsId).field(GoodsDonQaFrontView::getType, type).build());
- if (CollUtil.isEmpty(donQaFrontViews)) {
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- redisService.setNx(key, donQaFrontViews, RedisService.key.YH_GOODS_QUESTIONS_DETAIL.getTimeout());
- o = redisService.get(key);
- }
- List<GoodsDonQaFrontView> donQaFrontViews = Jsons.parseList(o, GoodsDonQaFrontView.class);
- return GatewayResponse.SUCCESS.newBuilder().toResult(donQaFrontViews);
- }
- /**
- * 是否首次购买车票
- */
- @GetMapping("/get/first/pay/{goodsId}")
- public Result<Boolean> getFirstPay(@PathVariable Long goodsId) {
- long userId = StpUserUtil.getLoginIdAsLong();
- List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
- Number number = beanSearcher.searchCount(OrderDon.class, MapUtils.builder()
- .field(OrderDon::getGoodsId, goodsId)
- .field(OrderDon::getCreatedTime, new DateTime().toDateStr()).op(Operator.LessEqual)
- .field(OrderDon::getUserId, userIdList).op(Operator.InList)
- .field(OrderDon::getStatus, Constant.noOrderStatus).op(Operator.NotIn)
- .build());
- if (number.intValue() == 0) {
- UserGoodsNewbieGuideRecord userGoodsNewbieGuideRecord = new UserGoodsNewbieGuideRecord();
- userGoodsNewbieGuideRecord.setGoodsId(goodsId);
- userGoodsNewbieGuideRecord.setUserId(userId);
- userGoodsNewbieGuideRecordMapper.insert(userGoodsNewbieGuideRecord);
- return GatewayResponse.SUCCESS.newBuilder().toResult(true);
- }
- return GatewayResponse.SUCCESS.newBuilder().toResult(false);
- }
- /**
- * 设置pin码
- */
- @PutMapping("/set/pin/{relationId}")
- public Result<String> setPin(@PathVariable Long relationId, String code) {
- long userId = StpUserUtil.getLoginIdAsLong();
- JSONObject data = groupsRelationNetflixService.setNetflixPin(relationId, userId, code);
- return GatewayResponse.SUCCESS.newBuilder().toResult(data.toString());
- }
- /**
- * 查询是否设置成功
- */
- @GetMapping("/get/pin/status/{taskId}")
- public Result<Integer> getPinStatus(@PathVariable String taskId) throws Exception {
- long userId = StpUserUtil.getLoginIdAsLong();
- log.info("userId:{}查看设置pin码状态", userId);
- return GatewayResponse.SUCCESS.newBuilder().toResult(groupsRelationNetflixService.getPinStatus(taskId));
- }
- /**
- * 踢出奈飞设备
- */
- @PostMapping("/kickOut/nf/{relationId}")
- public Result<String> nfKickOut(@PathVariable Long relationId) {
- long userId = StpUserUtil.getLoginIdAsLong();
- JSONObject data = groupsRelationNetflixService.nfKickOut(userId, relationId);
- return GatewayResponse.SUCCESS.newBuilder().toResult(data.toString());
- }
- /**
- * 奈飞同户装置链接
- */
- @GetMapping("/get/nf/household/device")
- public Result<String> getNfHouseholdDevice(@NotNull Long relationId) throws Exception {
- long userId = StpUserUtil.getLoginIdAsLong();
- String url = groupRelationFrontService.getNfHouseholdDevice(userId, relationId);
- return GatewayResponse.SUCCESS.newBuilder().toResult(url);
- }
- /**
- * 代点奈飞同户装置
- */
- @PostMapping("/click/nf/household/device")
- public void clickNfHouseholdDevice(@RequestBody NfDeviceReq nfDeviceReq) {
- groupsRelationNetflixService.clickNfHouseholdDevice(nfDeviceReq);
- }
- /**
- * 可选 续费升级车票
- */
- @GetMapping("/get/renew/skus/{relationId}/{skuId}")
- public Result<List<RenewUpgradePackageFrontView>> getRenewSkus(@PathVariable Long relationId, @PathVariable Long skuId) {
- long userId = StpUserUtil.getLoginIdAsLong();
- List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
- ChatgptUser chatgptUser = chatgptUserMapper.selectOne(Wrappers.lambdaQuery(ChatgptUser.class)
- .eq(ChatgptUser::getRelationId, relationId));
- if (chatgptUser == null) return GatewayResponse.SUCCESS.newBuilder().toResult();
- //目前续费升级的规格
- Long renewSkuId = chatgptUser.getRenewSkuId();
- GoodsDonSku sku = goodsDonSkuMapper.selectById(skuId);
- AtomicInteger minMonths = new AtomicInteger(sku.getMonths());
- AtomicInteger minNum = new AtomicInteger(chatgptUser.getLimitNum());
- AtomicLong minTime = new AtomicLong(chatgptUser.getLimitTime());
- if (renewSkuId != null) {
- GoodsDonSku presentRenew = goodsDonSkuMapper.selectById(renewSkuId);
- minMonths.set(presentRenew.getMonths());
- }
- if (chatgptUser.getPackageId() != 0) {
- Long packageId = chatgptUser.getPackageId();
- UpgradeOrderDon upgradeOrderDon = upgradeOrderDonMapper.selectOne(Wrappers.lambdaQuery(UpgradeOrderDon.class)
- .eq(UpgradeOrderDon::getPackageId, packageId)
- .eq(UpgradeOrderDon::getRelationId, relationId)
- .in(UpgradeOrderDon::getUserId, userIdList)
- .last("limit 1"));
- Long upgradeOrderDonSkuId = upgradeOrderDon.getSkuId();
- GoodsDonSku upgradeSku = goodsDonSkuMapper.selectById(upgradeOrderDonSkuId);
- if (upgradeSku != null) {
- if (upgradeSku.getMonths() > minMonths.get()) {
- minMonths.set(upgradeSku.getMonths());
- }
- }
- }
- List<RenewUpgradePackageFrontView> renewUpgradePackageFrontViews = beanSearcher.searchAll(RenewUpgradePackageFrontView.class, MapUtils.builder().field(RenewUpgradePackageFrontView::getSkuId, skuId).build());
- renewUpgradePackageFrontViews.forEach(renew -> {
- try {
- List<Long> upgradeSkuIds = Jsons.parseList(renew.getUpgradeSkuIds(), Long.class);
- //年付展示
- MapBuilder builder = MapUtils.builder();
- // if (minMonths.get() == 12) {
- // builder.field(RenewUpgradePackageFrontView.RenewSkuView::getMonths, minMonths.get()).op(Operator.GreaterEqual);
- // if (renewSkuId != null) {
- // upgradeSkuIds.remove(renewSkuId);
- // }
- // } else {
- // builder.field(RenewUpgradePackageFrontView.RenewSkuView::getMonths, minMonths.get()).op(Operator.GreaterEqual);
- // }
- //同续费时间规格
- builder.field(RenewUpgradePackageFrontView.RenewSkuView::getMonths, minMonths.get()).op(Operator.GreaterEqual);
- if (renewSkuId != null) {
- upgradeSkuIds.remove(renewSkuId);
- }
- List<RenewUpgradePackageFrontView.RenewSkuView> renewSkuViews = beanSearcher.searchAll(RenewUpgradePackageFrontView.RenewSkuView.class, builder
- .field(RenewUpgradePackageFrontView.RenewSkuView::getGptLimitNum, minNum.get()).op(Operator.GreaterEqual)
- .field(RenewUpgradePackageFrontView.RenewSkuView::getGptLimitTime, minTime.get()).op(LessEqual.class)
- .field(RenewUpgradePackageFrontView.RenewSkuView::getSkuId, upgradeSkuIds).op(Operator.InList)
- .build());
- renew.setRenewSkus(renewSkuViews);
- } catch (Exception e) {
- }
- });
- return GatewayResponse.SUCCESS.newBuilder().toResult(renewUpgradePackageFrontViews);
- }
- /**
- * 独立规格续费套餐列表
- */
- @GetMapping("/get/independent/renew/skus/{skuId}")
- public Result<List<RenewUpgradePackageFrontView>> getRenewSkus(@PathVariable Long skuId) {
- long userId = StpUserUtil.getLoginIdAsLong();
- List<RenewUpgradePackageFrontView> renewUpgradePackageFrontViews = beanSearcher.searchAll(RenewUpgradePackageFrontView.class, MapUtils.builder().field(RenewUpgradePackageFrontView::getSkuId, skuId).build());
- renewUpgradePackageFrontViews.forEach(renew -> {
- try {
- List<Long> upgradeSkuIds = Jsons.parseList(renew.getUpgradeSkuIds(), Long.class);
- MapBuilder builder = MapUtils.builder();
- List<RenewUpgradePackageFrontView.RenewSkuView> renewSkuViews = beanSearcher.searchAll(RenewUpgradePackageFrontView.RenewSkuView.class, builder
- .field(RenewUpgradePackageFrontView.RenewSkuView::getSkuId, upgradeSkuIds).op(Operator.InList)
- .build());
- renew.setRenewSkus(renewSkuViews);
- } catch (Exception e) {
- }
- });
- return GatewayResponse.SUCCESS.newBuilder().toResult(renewUpgradePackageFrontViews);
- }
- /**
- * 获取GPT PLUS登录验证码
- */
- @GetMapping("/get/verify/code")
- public Result<String> getVerifyCode(@NotEmpty String account) throws Exception {
- String code = groupRelationFrontService.getVerifyCode(account);
- if (StrUtil.isEmpty(code)) {
- throw BusinessRuntimeException.getInstance("请重新发送验证码");
- }
- return GatewayResponse.SUCCESS.newBuilder().toResult(code);
- }
- }
|