| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213 |
- 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.common.util.StringUtil;
- 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.AccountView;
- 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 UserBenefitsOrderRecordMapper userBenefitsOrderRecordMapper;
- private final ClaudeUserMapper claudeUserMapper;
- private final static Sequence SEQUENCE = new Sequence(0);
- @RequestMapping("/get/renewal")
- public Result<SearchResult<RenewalView>> get(Boolean isLoginPopularize, String customId, String account, String orderNo, Integer cmt) {
- long userId = StpUserUtil.getLoginIdAsLong();
- SearchResult<RenewalView> list = groupRelationFrontService.getMyTicket(userId, isLoginPopularize, customId, account, orderNo, cmt);
- 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())
- .set(GroupsRelation::getContact, relation.getContact())
- .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 goodsId, Long skuId) {
- long userId = StpUserUtil.getLoginIdAsLong();
- List<Long> userIds = userBindRelationService.getRelationUserIdList(userId, null);
- List<UserTicketView> tickets = relationMapper.selectUserTickets(userIds, goodsId, skuId);
- return GatewayResponse.SUCCESS.newBuilder().toResult(tickets);
- }
- /**
- * 记录查看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")
- public Result<List<TicketAdvertiseConfigFrontView>> getTicketAdvertiseConfig() {
- long userId = StpUserUtil.getLoginIdAsLong();
- List<RenewalView> hasPayGoods = groupRelationFrontService.getHasPayGoods(userId);
- if (CollUtil.isEmpty(hasPayGoods)) {
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- List<Long> goodsIds = hasPayGoods.stream().map(RenewalView::getGoodsId).collect(Collectors.toList());
- log.info("userId:{}获取广告位配置", userId);
- List<TicketAdvertiseConfigFrontView> views = beanSearcher.searchAll(TicketAdvertiseConfigFrontView.class, MapUtils.flatBuilder(request.getParameterMap())
- .field(TicketAdvertiseConfigFrontView::getGoodsId, goodsIds).op(Operator.InList)
- .orderBy(TicketAdvertiseConfigFrontView::getSorted).desc()
- .orderBy(TicketAdvertiseConfigFrontView::getGoodsId).asc()
- .orderBy(TicketAdvertiseConfigFrontView::getConfigId).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/questions")
- public Result<List<GoodsDonQaFrontView>> getAllTicketQuestions(String participle) {
- MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
- if (StrUtil.isNotBlank(participle)) {
- char[] charArray = participle.toCharArray();
- StringBuilder p = new StringBuilder();
- p.append("and (");
- for (int i = 0; i < charArray.length; i++) {
- char c = charArray[i];
- p.append(String.format(" ga.problem like '%%%s%%'", c));
- if (i != charArray.length - 1) {
- p.append(" or ");
- }
- }
- p.append(")");
- builder.put("p", p);
- }
- List<GoodsDonQaFrontView> donQaFrontViews = beanSearcher.searchAll(GoodsDonQaFrontView.class, builder.build());
- 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)
- .last("limit 1"));
- 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);
- // }
- //GPT镜像2月规格 特殊处理
- if (sku.getGoodsId() == 18 && sku.getMonths() == 2) {
- } else {
- //同续费时间规格
- builder.field(RenewUpgradePackageFrontView.RenewSkuView::getMonths, minMonths.get()).op(Operator.GreaterEqual);
- }
- if (renewSkuId != null) {
- upgradeSkuIds.remove(renewSkuId);
- }
- List<RenewUpgradePackageFrontView.RenewSkuView> renewSkuViews = new ArrayList<>();
- if (CollUtil.isNotEmpty(upgradeSkuIds)) {
- 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);
- }
- /**
- * claude pro续费升级
- */
- @GetMapping("/get/claude/renew/skus/{relationId}/{skuId}")
- public Result<List<RenewUpgradePackageFrontView> > getClaudeRenewSkus(@PathVariable Long relationId, @PathVariable Long skuId) {
- long userId = StpUserUtil.getLoginIdAsLong();
- ClaudeUser claudeUser = claudeUserMapper.selectOne(Wrappers.lambdaQuery(ClaudeUser.class)
- .eq(ClaudeUser::getRelationId, relationId)
- .last("limit 1"));
- if (claudeUser == null) return GatewayResponse.SUCCESS.newBuilder().toResult();
- 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)
- .field(RenewUpgradePackageFrontView.RenewSkuView::getGptLimitNum, claudeUser.getLimitNum()).op(Operator.GreaterEqual)
- .build());
- renew.setRenewSkus(renewSkuViews);
- } catch (Exception e) {
- }
- });
- return GatewayResponse.SUCCESS.newBuilder().toResult(renewUpgradePackageFrontViews);
- }
- /**
- * 已配置的续费升级规格ids
- */
- @GetMapping("/get/renew/skus/configured")
- public Result<List<Long> > getClaudeRenewSkus() {
- long userId = StpUserUtil.getLoginIdAsLong();
- List<RenewUpgradePackageFrontView> renewUpgradePackageFrontViews = beanSearcher.searchAll(RenewUpgradePackageFrontView.class, MapUtils.builder().onlySelect(RenewUpgradePackageFrontView::getSkuId).build());
- List<Long> collect = renewUpgradePackageFrontViews.stream().map(RenewUpgradePackageFrontView::getSkuId).collect(Collectors.toList());
- return GatewayResponse.SUCCESS.newBuilder().toResult(collect);
- }
- /**
- * 获取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);
- }
- /**
- * 独立规格续费减免
- */
- @GetMapping("/get/renew/reduce")
- public Result<UserBenefitsFrontView> getRenewReduce(Long skuId, Long relationId) {
- long userId = StpUserUtil.getLoginIdAsLong();
- List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
- UserBenefitsFrontView data = beanSearcher.searchFirst(UserBenefitsFrontView.class, MapUtils.builder().field(UserBenefitsFrontView::getSkuId, skuId).field(UserBenefitsFrontView::getType, UserBenefits.Type.RENEW.name()).build());
- if (data == null) {
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- Date startTime = null;
- if (relationId != null) {
- GroupsRelation relation = relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
- .eq(GroupsRelation::getId, relationId)
- .in(GroupsRelation::getUserId, userIdList));
- if (relation == null) {
- throw BusinessRuntimeException.getInstance("车票不存在");
- }
- startTime = relation.getStartTime();
- }
- Integer renewCount = userBenefitsOrderRecordMapper.selectUseComboRecordByUid(userIdList, data.getType(), data.getGoodsId(), data.getSkuId(), Constant.noOrderAllStatus, null, startTime, relationId);
- data.setRenewCount(renewCount);
- return GatewayResponse.SUCCESS.newBuilder().toResult(data);
- }
- /**
- * 申请更换车票
- */
- @PostMapping("/change/ticket")
- public Result<String> changeTicket(@RequestBody ChangeTicketReq changeTicketReq) {
- long userId = StpUserUtil.getLoginIdAsLong();
- List<Long> relationIds = changeTicketReq.getRelationIds();
- if (CollUtil.isEmpty(relationIds)) {
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
- //奈飞超过3帐车票不给看
- Number number = beanSearcher.searchCount(RenewalView.class, MapUtils.builder()
- .field(RenewalView::getUserId, userIdList).op(Operator.InList)
- .field(RenewalView::getGoodsId, 1)
- .field(RenewalView::getExpiryTime, DateTime.now()).op(Operator.GreaterThan)
- .build());
- if (number.intValue() > 2) {
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- relationIds.forEach(relationId -> {
- try {
- groupRelationFrontService.changeTicket(userId, relationId);
- } catch (Exception e) {
- log.error("更换车票失败:{}", StringUtil.getErrorText(e));
- if (relationIds.size() == 1) {
- throw BusinessRuntimeException.getInstance(e.getMessage());
- }
- }
- });
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- /**
- * 查看临时账号
- */
- @GetMapping("/get/temp/account/{relationId}")
- public Result<AccountView> getTempAccount(@PathVariable Long relationId) {
- long userId = StpUserUtil.getLoginIdAsLong();
- AccountView accountView = groupRelationFrontService.getTempAccount(userId, relationId);
- return GatewayResponse.SUCCESS.newBuilder().toResult(accountView);
- }
- /**
- * 申请提交记录
- */
- @GetMapping("/get/netflix/get/error/submit/record")
- public Result<List<NetflixUserAccountStatusRecord>> getUserNetflixSubmitRecord() {
- long userId = StpUserUtil.getLoginIdAsLong();
- List<NetflixUserAccountStatusRecord> netflixUserAccountStatusRecords = groupRelationFrontService.getUserNetflixSubmitRecord(userId);
- return GatewayResponse.SUCCESS.newBuilder().toResult(netflixUserAccountStatusRecords);
- }
- /**
- * 奈飞账号异常检测提交
- */
- @PostMapping("/netflix/error/account/submit/{relationId}")
- public Result<String> nfErrorAccountSubmit(@PathVariable Long relationId) {
- long userId = StpUserUtil.getLoginIdAsLong();
- groupRelationFrontService.nfErrorAccountSubmit(userId, relationId);
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- /**
- * 奈飞账号检测结果
- */
- @GetMapping("/get/netflix/error/account/status/{relationId}")
- public Result<Integer> getNetflixErrorAccountStatus(@PathVariable Long relationId) {
- long userId = StpUserUtil.getLoginIdAsLong();
- Integer state = groupRelationFrontService.getNetflixErrorAccountStatus(userId, relationId);
- return GatewayResponse.SUCCESS.newBuilder().toResult(state);
- }
- }
|