GroupRelationController.java 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213
  1. package com.cyksj.web.controller.group;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.date.DateTime;
  4. import cn.hutool.core.date.DateUnit;
  5. import cn.hutool.core.date.DateUtil;
  6. import cn.hutool.core.lang.Assert;
  7. import cn.hutool.core.thread.ThreadUtil;
  8. import cn.hutool.core.util.StrUtil;
  9. import cn.hutool.extra.servlet.ServletUtil;
  10. import cn.hutool.json.JSONObject;
  11. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  12. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  13. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  14. import com.cyksj.common.annotation.NoSubmit;
  15. import com.cyksj.common.constant.Constant;
  16. import com.cyksj.common.exception.BusinessRuntimeException;
  17. import com.cyksj.common.snowflake.Sequence;
  18. import com.cyksj.common.task.GlobalThreadPoolTaskExecutor;
  19. import com.cyksj.common.util.GoogleGenerator;
  20. import com.cyksj.common.util.Jsons;
  21. import com.cyksj.common.util.StringUtil;
  22. import com.cyksj.dto.Result;
  23. import com.cyksj.enums.GatewayResponse;
  24. import com.cyksj.mapper.*;
  25. import com.cyksj.mapper.manage.form.FormFieldsDataMapper;
  26. import com.cyksj.mapper.manage.form.QuestionnairePromotionMapper;
  27. import com.cyksj.model.dto.DoubleVerifyDto;
  28. import com.cyksj.model.dto.QuestionnaireView;
  29. import com.cyksj.model.entity.*;
  30. import com.cyksj.model.manage.views.AccountView;
  31. import com.cyksj.model.manage.views.GroupsRelationView;
  32. import com.cyksj.model.request.*;
  33. import com.cyksj.model.response.GptStandbyResp;
  34. import com.cyksj.model.views.*;
  35. import com.cyksj.redis.RedisService;
  36. import com.cyksj.service.chatgpt.ChatGptAuthService;
  37. import com.cyksj.service.mange.CmsOrderDonService;
  38. import com.cyksj.service.mange.coupon.CouponCommonService;
  39. import com.cyksj.service.mange.ticket.TicketAdvertiseConfigClickRecordService;
  40. import com.cyksj.service.order.OrderDonService;
  41. import com.cyksj.service.relation.GroupRelationFrontService;
  42. import com.cyksj.service.relation.GroupsRelationNetflixService;
  43. import com.cyksj.service.user.UserBindRelationService;
  44. import com.cyksj.service.user.UserService;
  45. import com.cyksj.web.util.StpUserUtil;
  46. import com.ejlchina.searcher.BeanSearcher;
  47. import com.ejlchina.searcher.SearchResult;
  48. import com.ejlchina.searcher.operator.LessEqual;
  49. import com.ejlchina.searcher.param.Operator;
  50. import com.ejlchina.searcher.util.MapBuilder;
  51. import com.ejlchina.searcher.util.MapUtils;
  52. import lombok.RequiredArgsConstructor;
  53. import lombok.extern.slf4j.Slf4j;
  54. import org.springframework.transaction.annotation.Transactional;
  55. import org.springframework.validation.annotation.Validated;
  56. import org.springframework.web.bind.annotation.*;
  57. import javax.servlet.http.HttpServletRequest;
  58. import javax.validation.constraints.NotEmpty;
  59. import javax.validation.constraints.NotNull;
  60. import java.math.BigDecimal;
  61. import java.math.RoundingMode;
  62. import java.util.*;
  63. import java.util.concurrent.TimeUnit;
  64. import java.util.concurrent.atomic.AtomicInteger;
  65. import java.util.concurrent.atomic.AtomicLong;
  66. import java.util.stream.Collectors;
  67. /**
  68. * @author chan
  69. * @date 2022/9/27 11:48 AM
  70. */
  71. @Slf4j
  72. @RequiredArgsConstructor
  73. @RestController
  74. @RequestMapping("/applets/group/relation")
  75. public class GroupRelationController {
  76. private final BeanSearcher beanSearcher;
  77. private final OrderDonService orderDonService;
  78. private final GroupsRelationMapper relationMapper;
  79. private final GroupRelationFrontService groupRelationFrontService;
  80. private final UserService userService;
  81. private final UserBindRelationService userBindRelationService;
  82. private final TicketPwdViewRecordMapper ticketPwdViewRecordMapper;
  83. private final HttpServletRequest request;
  84. private final AccountDoubleVerifyRecordMapper accountDoubleVerifyRecordMapper;
  85. private final DoubleVerifyClickRecordMapper doubleVerifyRecordMapper;
  86. private final RedisService redisService;
  87. private final DoubleVerifyClickRefreshRecordMapper refreshRecordMapper;
  88. private final QuestionResponseRecordMapper questionResponseRecordMapper;
  89. private final CouponCommonService couponCommonService;
  90. private final FormFieldsDataMapper formFieldsDataMapper;
  91. private final QuestionnairePromotionMapper questionnairePromotionMapper;
  92. private final TicketAdvertiseConfigClickRecordService ticketAdvertiseConfigClickRecordService;
  93. private final GlobalThreadPoolTaskExecutor THREAD_POOL;
  94. private final ChatGptAuthService chatGptAuthService;
  95. private final GoodsCoursewareFileMapper goodsCoursewareFileMapper;
  96. private final GptTicketStandbyMapper gptTicketStandbyMapper;
  97. private final CmsOrderDonService cmsOrderDonService;
  98. private final GoodsDonSkuMapper goodsDonSkuMapper;
  99. private final AccountBlockedReplaceRecordMapper accountBlockedReplaceRecordMapper;
  100. private final OrderDonMapper orderDonMapper;
  101. private final UserGoodsNewbieGuideRecordMapper userGoodsNewbieGuideRecordMapper;
  102. private final GroupsRelationNetflixService groupsRelationNetflixService;
  103. private final ChatgptUserMapper chatgptUserMapper;
  104. private final UpgradeOrderDonMapper upgradeOrderDonMapper;
  105. private final UserBenefitsOrderRecordMapper userBenefitsOrderRecordMapper;
  106. private final ClaudeUserMapper claudeUserMapper;
  107. private final static Sequence SEQUENCE = new Sequence(0);
  108. @RequestMapping("/get/renewal")
  109. public Result<SearchResult<RenewalView>> get(Boolean isLoginPopularize, String customId, String account, String orderNo, Integer cmt) {
  110. long userId = StpUserUtil.getLoginIdAsLong();
  111. SearchResult<RenewalView> list = groupRelationFrontService.getMyTicket(userId, isLoginPopularize, customId, account, orderNo, cmt);
  112. return GatewayResponse.SUCCESS.newBuilder().toResult(list);
  113. }
  114. @GetMapping("/get/pay/goods")
  115. public Result<List<RenewalView>> getHasPayGoods() {
  116. long userId = StpUserUtil.getLoginIdAsLong();
  117. List<RenewalView> hasPayGoods = groupRelationFrontService.getHasPayGoods(userId);
  118. return GatewayResponse.SUCCESS.newBuilder().toResult(hasPayGoods);
  119. }
  120. @PostMapping("/post/renewal")
  121. public Result<OrderDon> renewal(@RequestBody OrderPayRequest payRequest) throws Exception {
  122. long userId = StpUserUtil.getLoginIdAsLong();
  123. payRequest.setUserId(userId);
  124. String ip = ServletUtil.getClientIP(request);
  125. payRequest.setIp(ip);
  126. OrderDon orderDon = orderDonService.renewal(payRequest);
  127. return GatewayResponse.SUCCESS.newBuilder().toResult(orderDon);
  128. }
  129. @PutMapping("/update/set/account")
  130. public Result<String> setAccount(@RequestBody GroupsRelation relation) {
  131. long userId = StpUserUtil.getLoginIdAsLong();
  132. List<Long> userIds = userBindRelationService.getRelationUserIdList(userId, null);
  133. GroupsRelation re = relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
  134. .eq(GroupsRelation::getId, relation.getId())
  135. .in(GroupsRelation::getUserId, userIds)
  136. .last(" limit 1"));
  137. if (re == null) {
  138. throw new BusinessRuntimeException("该车票不存在,请联系客服.");
  139. }
  140. LambdaUpdateWrapper<GroupsRelation> updateWrapper = Wrappers.lambdaUpdate(GroupsRelation.class)
  141. .set(GroupsRelation::getAccount, relation.getAccount())
  142. .set(GroupsRelation::getPassword, relation.getPassword())
  143. .set(GroupsRelation::getContact, relation.getContact())
  144. .eq(GroupsRelation::getId, relation.getId());
  145. if (re.getRechargeStatus() != null) {
  146. if (re.getRechargeStatus() == GroupsRelation.RechargeStatus.complete) {
  147. throw BusinessRuntimeException.getInstance("代充账号已充值");
  148. }
  149. if (StrUtil.isEmpty(relation.getAccount()) || StrUtil.isEmpty(relation.getPassword())) {
  150. throw BusinessRuntimeException.getInstance("请输入正确的账号密码信息");
  151. }
  152. if (re.getRechargeStatus() == GroupsRelation.RechargeStatus.error) {
  153. updateWrapper.set(GroupsRelation::getRechargeStatus, GroupsRelation.RechargeStatus.waiting);
  154. }
  155. }
  156. relationMapper.update(relation, updateWrapper);
  157. return GatewayResponse.SUCCESS.newBuilder().toResult();
  158. }
  159. /**
  160. * 查询是否加入了企业微信
  161. */
  162. @GetMapping("/check/joinCorpWx")
  163. public Result<Boolean> isJoinCorpWx() {
  164. long userId = StpUserUtil.getLoginIdAsLong();
  165. Boolean flag = groupRelationFrontService.isJoinCorpWx(userId, false, false);
  166. return GatewayResponse.SUCCESS.newBuilder().toResult(flag);
  167. }
  168. /**
  169. * 获取全部车票
  170. */
  171. @GetMapping("/get")
  172. public Result<List<UserTicketView>> getUserTicketView(Long goodsId, Long skuId) {
  173. long userId = StpUserUtil.getLoginIdAsLong();
  174. List<Long> userIds = userBindRelationService.getRelationUserIdList(userId, null);
  175. List<UserTicketView> tickets = relationMapper.selectUserTickets(userIds, goodsId, skuId);
  176. return GatewayResponse.SUCCESS.newBuilder().toResult(tickets);
  177. }
  178. /**
  179. * 记录查看ChatGPT车票密码
  180. */
  181. @GetMapping("/recordView/{relationId}")
  182. public Result<String> recordGPTPwdView(@PathVariable Long relationId) {
  183. long userId = StpUserUtil.getLoginIdAsLong();
  184. List<Long> userIds = userBindRelationService.getRelationUserIdList(userId, null);
  185. GroupsRelationView groupsRelationView = beanSearcher.searchFirst(GroupsRelationView.class, MapUtils.builder()
  186. .field(GroupsRelationView::getUserId, userIds).op(Operator.InList)
  187. .field(GroupsRelationView::getId, relationId).build());
  188. if (groupsRelationView == null) {
  189. log.info("userId:{}查看relationId:{}车票不存在", userId, relationId);
  190. throw BusinessRuntimeException.getInstance("该车票已不存在");
  191. }
  192. if (groupsRelationView.getAccountId() == null) throw BusinessRuntimeException.getInstance("该车队未配置账号");
  193. if (groupRelationFrontService == null) throw BusinessRuntimeException.getInstance("车票已不存在");
  194. TicketPwdViewRecord viewRecord = new TicketPwdViewRecord();
  195. viewRecord.setUserId(userId);
  196. viewRecord.setRelationId(relationId);
  197. viewRecord.setSkuId(groupsRelationView.getSkuId());
  198. viewRecord.setOperateLocation(ServletUtil.getClientIP(request));
  199. viewRecord.setAccount(groupsRelationView.getTripsAccount());
  200. viewRecord.setPassword(groupsRelationView.getTripsPassword());
  201. ticketPwdViewRecordMapper.insert(viewRecord);
  202. if (groupsRelationView.getGoodsId() == 18 && StrUtil.isEmpty(groupsRelationView.getApiSecret())) {
  203. THREAD_POOL.execute(() -> {
  204. //车队所有人查看密码
  205. Integer num = groupsRelationView.getGtNum();
  206. Integer viewNum = relationMapper.selectViewPwdCount(groupsRelationView.getGroupsId());
  207. if (num <= viewNum) {
  208. AccountDoubleVerifyRecord exist = accountDoubleVerifyRecordMapper.selectOne(Wrappers.lambdaQuery(AccountDoubleVerifyRecord.class)
  209. .eq(AccountDoubleVerifyRecord::getAccountId, groupsRelationView.getAccountId())
  210. .eq(AccountDoubleVerifyRecord::getDeleted, true).last("limit 1"));
  211. if (exist == null) {
  212. if (redisService.setNx(String.format("%s-%s", groupsRelationView.getAccountId(), groupsRelationView.getId()), groupsRelationView.getId(), 60l)) {
  213. //记录
  214. AccountDoubleVerifyRecord accountDoubleVerifyRecord = new AccountDoubleVerifyRecord();
  215. accountDoubleVerifyRecord.setAccountId(groupsRelationView.getAccountId());
  216. accountDoubleVerifyRecord.setAccount(groupsRelationView.getTripsAccount());
  217. accountDoubleVerifyRecord.setGroupsId(groupsRelationView.getGroupsId());
  218. accountDoubleVerifyRecord.setSkuId(groupsRelationView.getSkuId());
  219. accountDoubleVerifyRecord.setRemark("车队所有人看过密码");
  220. accountDoubleVerifyRecordMapper.insert(accountDoubleVerifyRecord);
  221. }
  222. }
  223. }
  224. });
  225. }
  226. return GatewayResponse.SUCCESS.newBuilder().toResult(groupsRelationView.getTripsPassword());
  227. }
  228. /**
  229. * 获取AI类 ChatGPT产品谷歌验证码
  230. */
  231. @GetMapping("/get/authCode")
  232. public Result<String> getAuthCode(Long relationId) {
  233. long userId = StpUserUtil.getLoginIdAsLong();
  234. List<Long> userIds = userBindRelationService.getRelationUserIdList(userId, null);
  235. if (relationId == null) throw BusinessRuntimeException.getInstance("车票不存在");
  236. GroupsRelationView groupsRelationView = beanSearcher.searchFirst(GroupsRelationView.class, MapUtils.builder()
  237. .field(GroupsRelationView::getId, relationId)
  238. .field(GroupsRelationView::getUserId, userIds).op(Operator.InList).build());
  239. if (groupsRelationView == null) throw BusinessRuntimeException.getInstance("车票不存在");
  240. if (StrUtil.isEmpty(groupsRelationView.getApiSecret())) throw BusinessRuntimeException.getInstance("未开启验证");
  241. DateTime now = DateTime.now();
  242. Integer count = doubleVerifyRecordMapper.selectCount(Wrappers.lambdaQuery(DoubleVerifyClickRecord.class)
  243. .in(DoubleVerifyClickRecord::getUserId, userIds)
  244. .eq(DoubleVerifyClickRecord::getRelationId, relationId)
  245. .eq(DoubleVerifyClickRecord::getAccountId, groupsRelationView.getAccountId())
  246. .between(DoubleVerifyClickRecord::getCreatedTime, DateUtil.beginOfMonth(now), DateUtil.endOfMonth(now)));
  247. //获取双重验证码
  248. Boolean isHasVerifyCode = StrUtil.isNotBlank(groupsRelationView.getVerifyCode()) ? true : false;
  249. //出去亚马逊 获取限制
  250. if (groupsRelationView.getGoodsId() != 6) {
  251. Integer num = groupRelationFrontService.getUserCodeNumBySkuId(userId, groupsRelationView.getSkuId(), isHasVerifyCode);
  252. if (count >= num) throw BusinessRuntimeException.getInstance("获取双重验证码次数上限");
  253. }
  254. //一分钟内 只能一人获取
  255. 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());
  256. if (!b) {
  257. throw BusinessRuntimeException.getInstance("一分钟内已有人获取该账号验证码,请稍后获取..");
  258. }
  259. int second = now.second();
  260. if (second < 30 && 30 - second < 3) {
  261. ThreadUtil.sleep(30 - second + 1, TimeUnit.SECONDS);
  262. } else if (second > 30 && 60 - second < 3) {
  263. ThreadUtil.sleep(60 - second + 1, TimeUnit.SECONDS);
  264. }
  265. StringBuilder sb = new StringBuilder();
  266. JSONObject re = new JSONObject();
  267. try {
  268. long code = GoogleGenerator.getCode(groupsRelationView.getApiSecret(), now.getTime());
  269. sb.append(code);
  270. while (sb.length() < 6) {
  271. sb.insert(0, 0);
  272. }
  273. re.putOpt("code", sb.toString());
  274. int nowSecond = DateTime.now().second();
  275. int time = 0;
  276. if (nowSecond < 30) {
  277. time = 30 - nowSecond;
  278. } else {
  279. time = 60 - nowSecond;
  280. }
  281. re.putOpt("time", time);
  282. DoubleVerifyClickRecord doubleVerifyClickRecord = new DoubleVerifyClickRecord();
  283. doubleVerifyClickRecord.setRelationId(relationId);
  284. doubleVerifyClickRecord.setUserId(userId);
  285. doubleVerifyClickRecord.setAccountId(groupsRelationView.getAccountId());
  286. doubleVerifyClickRecord.setAccount(groupsRelationView.getTripsAccount());
  287. doubleVerifyClickRecord.setSkuId(groupsRelationView.getSkuId());
  288. doubleVerifyClickRecord.setCode(sb.toString());
  289. doubleVerifyClickRecord.setRemainTime(time);
  290. doubleVerifyRecordMapper.insert(doubleVerifyClickRecord);
  291. DoubleVerifyDto doubleVerifyDto = new DoubleVerifyDto();
  292. doubleVerifyDto.setClickId(doubleVerifyClickRecord.getId());
  293. doubleVerifyDto.setApiSecret(groupsRelationView.getApiSecret());
  294. redisService.set(String.format("%s-%s", userId, sb.toString()), 0, 60 * 10l);
  295. redisService.set(String.format("%s/%s", userId, sb.toString()), Jsons.toJson(doubleVerifyDto), 60 * 10l);
  296. } catch (Exception e) {
  297. throw BusinessRuntimeException.getInstance("获取双重验证码错误,请联系客服");
  298. }
  299. return GatewayResponse.SUCCESS.newBuilder().toResult(re.toString());
  300. }
  301. /**
  302. * 刷新验证码
  303. */
  304. @GetMapping("/refresh/code")
  305. public Result<String> refreshCode(String code) {
  306. long userId = StpUserUtil.getLoginIdAsLong();
  307. String numKey = String.format("%s-%s", userId, code);
  308. Object num = redisService.get(numKey);
  309. String objKey = String.format("%s/%s", userId, code);
  310. Object objValue = redisService.get(objKey);
  311. if (objValue == null || num == null) {
  312. throw BusinessRuntimeException.getInstance("请重新获取双重验证码");
  313. }
  314. Integer refreshNum = Integer.parseInt(num.toString());
  315. String apiSecret = null;
  316. Long clickId = 0l;
  317. try {
  318. DoubleVerifyDto dto = Jsons.parseObject(objValue.toString(), DoubleVerifyDto.class);
  319. apiSecret = dto.getApiSecret();
  320. clickId = dto.getClickId();
  321. } catch (Exception e) {
  322. apiSecret = objValue.toString();
  323. }
  324. if (refreshNum >= 3) {
  325. redisService.del(numKey);
  326. redisService.del(objKey);
  327. throw BusinessRuntimeException.getInstance("刷新次数已达到3次,请重新获取验证码");
  328. }
  329. if (apiSecret == null) {
  330. throw BusinessRuntimeException.getInstance("请重新获取双重验证码");
  331. }
  332. StringBuilder sb = new StringBuilder();
  333. try {
  334. long c = GoogleGenerator.getCode(apiSecret, DateTime.now().getTime());
  335. sb.append(c);
  336. while (sb.length() < 6) {
  337. sb.insert(0, 0);
  338. }
  339. redisService.incr(numKey, 1l);
  340. } catch (Exception e) {
  341. throw BusinessRuntimeException.getInstance("刷新双重验证码错误,请联系客服");
  342. }
  343. if (clickId != 0) {
  344. int nowSecond = DateTime.now().second();
  345. int time = 0;
  346. if (nowSecond < 30) {
  347. time = 30 - nowSecond;
  348. } else {
  349. time = 60 - nowSecond;
  350. }
  351. //刷新双重验证码记录
  352. DoubleVerifyClickRefreshRecord refreshRecord = new DoubleVerifyClickRefreshRecord();
  353. refreshRecord.setClickId(clickId);
  354. refreshRecord.setUserId(userId);
  355. refreshRecord.setCode(sb.toString());
  356. refreshRecord.setRemainTime(time);
  357. refreshRecordMapper.insert(refreshRecord);
  358. }
  359. return GatewayResponse.SUCCESS.newBuilder().toResult(sb.toString());
  360. }
  361. /**
  362. * 获取双重验证码记录
  363. */
  364. @GetMapping("/get/doubleVerify/codeList")
  365. public Result<List<DoubleVerifyCodeView>> getDoubleVerifyCodeList(Long relationId) {
  366. long userId = StpUserUtil.getLoginIdAsLong();
  367. List<DoubleVerifyCodeView> views = doubleVerifyRecordMapper.getDoubleVerifyCodeList(userId, relationId);
  368. return GatewayResponse.SUCCESS.newBuilder().toResult(views);
  369. }
  370. /**
  371. * 用户是不是自然流量渠道
  372. * 且未回答答题
  373. */
  374. @GetMapping("/natural/channel")
  375. public Result<Boolean> isNaturalChannel() {
  376. long userId = StpUserUtil.getLoginIdAsLong();
  377. String question_key = RedisService.key.QUESTION_RESPONSE_KEY.getNameFormat(userId);
  378. if (redisService.get(question_key) != null) {
  379. return GatewayResponse.SUCCESS.newBuilder().toResult(false);
  380. }
  381. User user = userService.getById(userId);
  382. if (user.getPopularizeId() != 0) {
  383. redisService.set(question_key, userId, RedisService.key.QUESTION_RESPONSE_KEY.getTimeout());
  384. return GatewayResponse.SUCCESS.newBuilder().toResult(false);
  385. }
  386. if (user.getPopularizeId() == 0) {
  387. QuestionResponseRecord record = questionResponseRecordMapper.selectOne(Wrappers.lambdaQuery(QuestionResponseRecord.class)
  388. .eq(QuestionResponseRecord::getUserId, userId).select(QuestionResponseRecord::getId).last("limit 1"));
  389. if (record != null) {
  390. redisService.set(question_key, userId, RedisService.key.QUESTION_RESPONSE_KEY.getTimeout());
  391. return GatewayResponse.SUCCESS.newBuilder().toResult(false);
  392. }
  393. return GatewayResponse.SUCCESS.newBuilder().toResult(true);
  394. }
  395. return GatewayResponse.SUCCESS.newBuilder().toResult(false);
  396. }
  397. /**
  398. * 问卷记录
  399. */
  400. @PostMapping("/record/replyQuestion")
  401. public Result<String> recordReplyQuestion(@RequestBody @Validated QuestionResponseRecord record) {
  402. long userId = StpUserUtil.getLoginIdAsLong();
  403. User user = userService.getById(userId);
  404. String nickname = user.getNickname();
  405. String question_key = RedisService.key.QUESTION_RESPONSE_KEY.getNameFormat(userId);
  406. QuestionResponseRecord dbRecord = questionResponseRecordMapper.selectOne(Wrappers.lambdaQuery(QuestionResponseRecord.class)
  407. .eq(QuestionResponseRecord::getUserId, userId).select(QuestionResponseRecord::getId).last("limit 1"));
  408. if (dbRecord == null) {
  409. if (redisService.setNx(String.format("%s-%s", userId, nickname), userId, 10l)) {
  410. record.setUserId(userId);
  411. record.setNickname(nickname);
  412. questionResponseRecordMapper.insert(record);
  413. //发放优惠券
  414. couponCommonService.sendCouponToUser(userId, 100l, 0l, 0l, 0l, CouponUser.Channel.ques_response);
  415. redisService.set(question_key, userId, RedisService.key.QUESTION_RESPONSE_KEY.getTimeout());
  416. }
  417. }
  418. return GatewayResponse.SUCCESS.newBuilder().toResult();
  419. }
  420. /**
  421. * 获取对应的动态问卷
  422. */
  423. @GetMapping("/get/questionnaire")
  424. public Result<List<QuestionnaireView>> getQuestionnaireView(Long promotionId) {
  425. QuestionnairePromotion promotion = questionnairePromotionMapper.selectById(promotionId);
  426. if (promotion == null || !promotion.getDeleted()) throw BusinessRuntimeException.getInstance("问卷不存在");
  427. Long templateId = promotion.getTemplateId();
  428. List<QuestionnaireView> questionnaireViews = beanSearcher.searchAll(QuestionnaireView.class, MapUtils.builder()
  429. .field(QuestionnaireView::getPromotionId, promotionId)
  430. .orderBy(QuestionnaireView::getSorted).asc()
  431. .orderBy(QuestionnaireView::getFieldsId).asc()
  432. .build());
  433. return GatewayResponse.SUCCESS.newBuilder().toResult(questionnaireViews);
  434. }
  435. /**
  436. * 记录问卷
  437. */
  438. @PostMapping("/record/questionnaire/{promotionId}")
  439. @Transactional(rollbackFor = Exception.class)
  440. @NoSubmit
  441. public Result<String> recordQuestionnaire(@PathVariable Long promotionId, String showId, @RequestBody List<FormFieldsData> answers) {
  442. Long userId = StpUserUtil.getUserIdAfterLogin();
  443. Long groupsId = SEQUENCE.nextId();
  444. List<QuestionnairePromotionFieldsListView> promotionFieldsListViews = beanSearcher.searchAll(QuestionnairePromotionFieldsListView.class, MapUtils.builder().field(QuestionnairePromotionFieldsListView::getPromotionId, promotionId).build());
  445. if (CollUtil.isEmpty(promotionFieldsListViews)) throw BusinessRuntimeException.getInstance("问卷已结束");
  446. if (promotionFieldsListViews.size() != answers.size()) throw BusinessRuntimeException.getInstance("请完成所有问题");
  447. log.info("开始记录问卷:{}", promotionId);
  448. answers.forEach(answer -> {
  449. // if (StringUtil.isNotBlank(showId)) {
  450. // answer.setUserId(userService.getUserIdByShowId(showId));
  451. // }
  452. answer.setUserId(userId);
  453. Long fieldsId = answer.getFieldsId();
  454. String content = answer.getContent();
  455. if (fieldsId == null || StrUtil.isBlank(content)) {
  456. throw BusinessRuntimeException.getInstance("必填项为空");
  457. }
  458. answer.setPromotionId(promotionId);
  459. answer.setGroupsId(groupsId);
  460. formFieldsDataMapper.insert(answer);
  461. });
  462. return GatewayResponse.SUCCESS.newBuilder().toResult();
  463. }
  464. /**
  465. * 查询用户是否填写问卷
  466. */
  467. @GetMapping("/check/questionnaire/{promotionId}")
  468. public Result<Boolean> checkQuestionnaire(@PathVariable Long promotionId) {
  469. long userId = StpUserUtil.getLoginIdAsLong();
  470. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  471. Integer count = formFieldsDataMapper.selectCount(Wrappers.lambdaQuery(FormFieldsData.class).in(FormFieldsData::getUserId, userIdList).eq(FormFieldsData::getPromotionId, promotionId));
  472. return GatewayResponse.SUCCESS.newBuilder().toResult(count > 0);
  473. }
  474. /**
  475. * 对应平台车票 广告配置列表
  476. */
  477. @GetMapping("/get/advertise")
  478. public Result<List<TicketAdvertiseConfigFrontView>> getTicketAdvertiseConfig() {
  479. long userId = StpUserUtil.getLoginIdAsLong();
  480. List<RenewalView> hasPayGoods = groupRelationFrontService.getHasPayGoods(userId);
  481. if (CollUtil.isEmpty(hasPayGoods)) {
  482. return GatewayResponse.SUCCESS.newBuilder().toResult();
  483. }
  484. List<Long> goodsIds = hasPayGoods.stream().map(RenewalView::getGoodsId).collect(Collectors.toList());
  485. log.info("userId:{}获取广告位配置", userId);
  486. List<TicketAdvertiseConfigFrontView> views = beanSearcher.searchAll(TicketAdvertiseConfigFrontView.class, MapUtils.flatBuilder(request.getParameterMap())
  487. .field(TicketAdvertiseConfigFrontView::getGoodsId, goodsIds).op(Operator.InList)
  488. .orderBy(TicketAdvertiseConfigFrontView::getSorted).desc()
  489. .orderBy(TicketAdvertiseConfigFrontView::getGoodsId).asc()
  490. .orderBy(TicketAdvertiseConfigFrontView::getConfigId).desc()
  491. .build());
  492. return GatewayResponse.SUCCESS.newBuilder().toResult(views);
  493. }
  494. /**
  495. * 记录用户点击车票广告
  496. */
  497. @PostMapping("/click/ticket/advertise/record/{configId}")
  498. public Result<String> recordClickTicketAdvertise(@PathVariable Long configId) {
  499. long userId = StpUserUtil.getLoginIdAsLong();
  500. ticketAdvertiseConfigClickRecordService.recordUserClickTicketAdvertise(userId, configId);
  501. return GatewayResponse.SUCCESS.newBuilder().toResult();
  502. }
  503. /**
  504. * 推荐平台
  505. */
  506. @GetMapping("/get/recommend/goods")
  507. public Result<Page<UserRecommendGoodsFrontView>> getRecommendGoodsViews(@RequestParam(defaultValue = "0") Integer start, @RequestParam(defaultValue = "5") Integer limit) {
  508. //推荐用户未购买的车票平台 优先展示ai类平台 然后是影视流媒体
  509. long userId = StpUserUtil.getLoginIdAsLong();
  510. List<Long> userIds = userBindRelationService.getRelationUserIdList(userId, null);
  511. List<Long> filter_goods_id = relationMapper.getTicketGoodsId(userIds, List.of("validity", "overdue", "outside"));
  512. //用户是否购买过奈飞产品
  513. Boolean isPayNf = false;
  514. if (filter_goods_id.contains(1l)) {
  515. isPayNf = true;
  516. } else {
  517. int count = orderDonService.count(Wrappers.lambdaQuery(OrderDon.class)
  518. .eq(OrderDon::getGoodsId, 1)
  519. .eq(OrderDon::getUserId, userId)
  520. .notIn(OrderDon::getStatus, Constant.noOrderAllStatus));
  521. if (count > 0) {
  522. //优先展示路由器、ai、流媒体
  523. isPayNf = true;
  524. }
  525. }
  526. Boolean filterCourseGoods = false;
  527. //GPT Plus基础2月 课程不展示
  528. Integer orders = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
  529. .in(OrderDon::getUserId, userIds)
  530. .eq(OrderDon::getSkuId, 444)
  531. .notIn(OrderDon::getStatus, Constant.noOrderStatus));
  532. if (orders > 0) {
  533. filterCourseGoods = true;
  534. }
  535. Page<UserRecommendGoodsFrontView> page = groupRelationFrontService.getRecommendGoodsViews(isPayNf, filter_goods_id, filterCourseGoods, start, limit);
  536. return GatewayResponse.SUCCESS.newBuilder().toResult(page);
  537. }
  538. /**
  539. * 查看GPT token
  540. */
  541. @GetMapping("/get/gptAccessToken")
  542. public Result<String> getGptAccessToken(Long relationId) throws Exception {
  543. long userId = StpUserUtil.getLoginIdAsLong();
  544. List<Long> userIds = userBindRelationService.getRelationUserIdList(userId, null);
  545. //存在该车票
  546. RenewalView renewalView = beanSearcher.searchFirst(RenewalView.class, MapUtils.builder()
  547. .field(RenewalView::getRelationId, relationId)
  548. .field(RenewalView::getUserId, userIds).op(Operator.InList).build());
  549. Assert.notNull(renewalView, "您的车票不存在");
  550. if (renewalView.getGoodsId() != 42) {
  551. throw BusinessRuntimeException.getInstance("该平台类型车票无法获取GPT直连token");
  552. }
  553. String account = renewalView.getAccount();
  554. String accessToken = chatGptAuthService.getAccessToken(account);
  555. return GatewayResponse.SUCCESS.newBuilder().toResult(accessToken);
  556. }
  557. /**
  558. * 获取特殊类型课程 通过邮件发送课程
  559. * 领取课件
  560. */
  561. @PostMapping("/courseware")
  562. public Result<String> getCourseWare(@RequestBody SpecialGoodsTicketReq request) throws Exception {
  563. long userId = StpUserUtil.getLoginIdAsLong();
  564. request.setUserId(userId);
  565. groupRelationFrontService.sendCourseWare(request);
  566. return GatewayResponse.SUCCESS.newBuilder().toResult();
  567. }
  568. //获取课程云盘链接
  569. @GetMapping("/get/courseware")
  570. public Result<GoodsCoursewareFile> getGoodsCourseware(Long relationId) {
  571. long userId = StpUserUtil.getLoginIdAsLong();
  572. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  573. RenewalView relationView = beanSearcher.searchFirst(RenewalView.class, MapUtils.builder()
  574. .field(RenewalView::getUserId, userIdList).op(Operator.InList)
  575. .field(RenewalView::getRelationId, relationId).build());
  576. if (relationView == null) {
  577. throw BusinessRuntimeException.getInstance("您的车票不存在");
  578. }
  579. GoodsCoursewareFile goodsCoursewareFile = goodsCoursewareFileMapper.selectOne(Wrappers.lambdaQuery(GoodsCoursewareFile.class)
  580. .eq(GoodsCoursewareFile::getGoodsId, relationView.getGoodsId())
  581. .eq(GoodsCoursewareFile::getStatus, true)
  582. .select(GoodsCoursewareFile::getLink, GoodsCoursewareFile::getCode)
  583. .last("limit 1"));
  584. if (goodsCoursewareFile == null) {
  585. throw BusinessRuntimeException.getInstance("暂未配置课件链接地址,请联系客服");
  586. }
  587. return GatewayResponse.SUCCESS.newBuilder().toResult(goodsCoursewareFile);
  588. }
  589. /**
  590. * 读取车票账号登录验证码
  591. */
  592. @PostMapping("/get/verifyCode")
  593. public Result<String> getAiVerifyCode(@RequestBody TicketLoginReq loginReq) throws Exception {
  594. long userId = StpUserUtil.getLoginIdAsLong();
  595. loginReq.setUserId(userId);
  596. return GatewayResponse.SUCCESS.newBuilder().toResult(groupRelationFrontService.getAiVerifyCode(loginReq));
  597. }
  598. /**
  599. * 车票后台登录
  600. */
  601. @PostMapping("/ticket/login")
  602. public Result<GroupsRelation> ticketLogin(@RequestBody TicketLoginReq loginReq) {
  603. GroupsRelation relation = groupRelationFrontService.ticketLogin(loginReq);
  604. return GatewayResponse.SUCCESS.newBuilder().toResult(relation);
  605. }
  606. /**
  607. * 奈飞验证校验
  608. */
  609. @PostMapping("/ticket/verify")
  610. public Result<String> outsideTicketVerify(@RequestBody TicketLoginReq loginReq) {
  611. return GatewayResponse.SUCCESS.newBuilder().toResult(groupRelationFrontService.outsideTicketVerify(loginReq));
  612. }
  613. /**
  614. * 是否有mid车票可候补
  615. */
  616. @GetMapping("/get/standby")
  617. public Result<GptStandbyResp> getGptStandby() {
  618. long userId = StpUserUtil.getLoginIdAsLong();
  619. List<Long> relationUserIdList = userBindRelationService.getRelationUserIdList(userId, null);
  620. 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))";
  621. List<RenewalView> renewalViewList = beanSearcher.searchAll(RenewalView.class, MapUtils.builder()
  622. .field(RenewalView::getUserId, relationUserIdList).op(Operator.InList)
  623. .field(RenewalView::getGoodsId, 26)
  624. .put("condition", condition)
  625. .field(RenewalView::getExpiryTime).op(Operator.NotNull)
  626. .onlySelect(RenewalView::getAccount, RenewalView::getExpiryTime)
  627. .build());
  628. GptStandbyResp gptStandbyResp = new GptStandbyResp();
  629. if (renewalViewList.isEmpty()) {
  630. gptStandbyResp.setIsHasAccount(false);
  631. return GatewayResponse.SUCCESS.newBuilder().toResult(gptStandbyResp);
  632. }
  633. List<RenewalView> overTen = new ArrayList<>();
  634. List<RenewalView> underTen = new ArrayList<>();
  635. DateTime now = DateTime.now();
  636. renewalViewList.forEach(e -> {
  637. if (e.getExpiryTime().compareTo(DateUtil.offsetDay(now, 10)) > 0) {
  638. overTen.add(e);
  639. } else underTen.add(e);
  640. });
  641. Integer accountBlockedCount = 1;
  642. if (overTen.size() > 1) {
  643. List<String> accountList = overTen.stream().map(RenewalView::getAccount).distinct().collect(Collectors.toList());
  644. accountBlockedCount = accountBlockedReplaceRecordMapper.selectCount(Wrappers.lambdaQuery(AccountBlockedReplaceRecord.class)
  645. .eq(AccountBlockedReplaceRecord::getGoodsId, 26)
  646. .in(AccountBlockedReplaceRecord::getAccount, accountList));
  647. }
  648. if (accountBlockedCount > 1) {
  649. gptStandbyResp.setIsHasAccount(false);
  650. return GatewayResponse.SUCCESS.newBuilder().toResult(gptStandbyResp);
  651. }
  652. gptStandbyResp.setIsHasAccount(true);
  653. gptStandbyResp.setOverTen(overTen);
  654. gptStandbyResp.setUnderTen(underTen);
  655. Integer count = gptTicketStandbyMapper.selectCount(Wrappers.lambdaQuery(GptTicketStandby.class)
  656. .in(GptTicketStandby::getUserId, relationUserIdList));
  657. gptStandbyResp.setIsApply(count > 0 ? true : false);
  658. return GatewayResponse.SUCCESS.newBuilder().toResult(gptStandbyResp);
  659. }
  660. /**
  661. * 申请候补
  662. */
  663. @PostMapping("/apply/standby")
  664. @NoSubmit
  665. public Result<Boolean> applyGptStandby() {
  666. long userId = StpUserUtil.getLoginIdAsLong();
  667. List<Long> relationUserIdList = userBindRelationService.getRelationUserIdList(userId, null);
  668. 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))";
  669. List<RenewalView> renewalViewList = beanSearcher.searchAll(RenewalView.class, MapUtils.builder()
  670. .field(RenewalView::getUserId, relationUserIdList).op(Operator.InList)
  671. .field(RenewalView::getGoodsId, 26)
  672. .put("condition", condition)
  673. .field(RenewalView::getExpiryTime, DateUtil.offsetDay(DateTime.now(), 10)).op(Operator.GreaterThan)
  674. .onlySelect(RenewalView::getAccount)
  675. .build());
  676. if (renewalViewList.isEmpty()) {
  677. throw BusinessRuntimeException.getInstance("你未有车票账号");
  678. }
  679. Integer count = gptTicketStandbyMapper.selectCount(Wrappers.lambdaQuery(GptTicketStandby.class)
  680. .in(GptTicketStandby::getUserId, relationUserIdList));
  681. if (count > 0) {
  682. throw BusinessRuntimeException.getInstance("你已申请车票账号候补");
  683. }
  684. if (renewalViewList.size() > 1) {
  685. Set<String> accountSet = renewalViewList.stream().map(RenewalView::getAccount).collect(Collectors.toSet());
  686. Integer accountBlockedCount = accountBlockedReplaceRecordMapper.selectCount(Wrappers.lambdaQuery(AccountBlockedReplaceRecord.class)
  687. .eq(AccountBlockedReplaceRecord::getGoodsId, 26)
  688. .in(AccountBlockedReplaceRecord::getAccount, accountSet));
  689. if (accountBlockedCount > 1) {
  690. return GatewayResponse.SUCCESS.newBuilder().toResult(true);
  691. }
  692. }
  693. GptTicketStandby gptTicketStandby = new GptTicketStandby();
  694. gptTicketStandby.setUserId(userId);
  695. gptTicketStandbyMapper.insert(gptTicketStandby);
  696. return GatewayResponse.SUCCESS.newBuilder().toResult(true);
  697. }
  698. /**
  699. * midjourney车票退款
  700. */
  701. @PutMapping("/refund/ticketOrder/{relationId}")
  702. @NoSubmit
  703. public Result<String> ticketRefundOrders(@PathVariable Long relationId) throws Exception {
  704. long userId = StpUserUtil.getLoginIdAsLong();
  705. List<Long> relationUserIdList = userBindRelationService.getRelationUserIdList(userId, null);
  706. 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))";
  707. RenewalView renewalView = beanSearcher.searchFirst(RenewalView.class, MapUtils.builder()
  708. .field(RenewalView::getRelationId, relationId)
  709. .field(RenewalView::getUserId, relationUserIdList).op(Operator.InList)
  710. .put("condition", condition)
  711. .field(RenewalView::getGoodsId, 26)
  712. .field(RenewalView::getExpiryTime, DateUtil.offsetDay(DateTime.now(), 10)).op(Operator.LessEqual)
  713. .build());
  714. if (renewalView == null) {
  715. throw BusinessRuntimeException.getInstance("你车票不存在或不符合退款要求");
  716. }
  717. OrderDon orderDon = orderDonService.getOne(Wrappers.lambdaQuery(OrderDon.class)
  718. .in(OrderDon::getUserId, relationUserIdList)
  719. .eq(OrderDon::getRelationId, relationId)
  720. .notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
  721. .orderByDesc(OrderDon::getId)
  722. .last("limit 1"));
  723. if (orderDon == null) {
  724. throw BusinessRuntimeException.getInstance("你对应车票的订单不存在");
  725. }
  726. GoodsDonSku sku = goodsDonSkuMapper.selectById(orderDon.getSkuId());
  727. if (sku == null) {
  728. throw BusinessRuntimeException.getInstance("该车票规格不存在,请联系客服进行人工退款..");
  729. }
  730. Date expiryTime = renewalView.getExpiryTime();
  731. long remainDay = DateUtil.between(DateTime.now(), expiryTime, DateUnit.DAY) + 1;
  732. BigDecimal money = orderDon.getMoney();
  733. BigDecimal refundMoney = null;
  734. BigDecimal refundBalance= null;
  735. String refundType = null;
  736. if (money.compareTo(BigDecimal.ZERO) > 0) {
  737. BigDecimal dayMoney = money.divide(BigDecimal.valueOf(sku.getMonths()).multiply(BigDecimal.valueOf(30)), 2, RoundingMode.HALF_DOWN);
  738. refundMoney = BigDecimal.valueOf(remainDay).multiply(dayMoney);
  739. refundType = "money";
  740. }
  741. OrderRefundReq refundReq = new OrderRefundReq();
  742. if (orderDon.getBalance().compareTo(BigDecimal.ZERO) > 0) {
  743. BigDecimal dayMoney = orderDon.getBalance().divide(BigDecimal.valueOf(sku.getMonths()).multiply(BigDecimal.valueOf(30)), 2, RoundingMode.HALF_DOWN);
  744. refundBalance = BigDecimal.valueOf(remainDay).multiply(dayMoney);
  745. refundReq.setIsOnly(true);
  746. }
  747. refundReq.setOrderId(orderDon.getId());
  748. refundReq.setRefundDesc("失效车票退款");
  749. refundReq.setRefundMoney(Optional.ofNullable(refundMoney).orElse(BigDecimal.ZERO));
  750. refundReq.setRefundBalance(Optional.ofNullable(refundBalance).orElse(BigDecimal.ZERO));
  751. refundReq.setRefundType(Optional.ofNullable(refundType).orElse("balance"));
  752. cmsOrderDonService.unifiedRefund(refundReq);
  753. return GatewayResponse.SUCCESS.newBuilder().toResult();
  754. }
  755. /**
  756. * 每日车票到期弹窗
  757. */
  758. @GetMapping("/get/expiry/notify")
  759. public Result<List<RenewalView>> getExpiryRenewalNotify() {
  760. Long userId = StpUserUtil.getLoginIdAsLong();
  761. List<RenewalView> expiryRenewals = groupRelationFrontService.getExpiryRenewalNotify(userId);
  762. return GatewayResponse.SUCCESS.newBuilder().toResult(expiryRenewals);
  763. }
  764. /**
  765. * 车票详情
  766. */
  767. @GetMapping("/get/detail")
  768. public Result<RenewalView> getTicketDetail(Long relationId) {
  769. if (relationId == null) {
  770. return GatewayResponse.SUCCESS.newBuilder().toResult();
  771. }
  772. long userId = StpUserUtil.getLoginIdAsLong();
  773. RenewalView ticketDetail = groupRelationFrontService.getTicketDetail(userId, relationId);
  774. return GatewayResponse.SUCCESS.newBuilder().toResult(ticketDetail);
  775. }
  776. /**
  777. * 车票售后常见问题
  778. */
  779. @GetMapping("/get/questions/{goodsId}")
  780. public Result<List<GoodsDonQaFrontView>> getTicketQuestions(@PathVariable Long goodsId, @RequestParam(defaultValue = "1") Integer type) {
  781. long userId = StpUserUtil.getLoginIdAsLong();
  782. log.info("userId:{}查看车票:{}售后问题", userId, goodsId);
  783. if (type < 1 || type > 2) {
  784. return GatewayResponse.SUCCESS.newBuilder().toResult();
  785. }
  786. String key = RedisService.key.YH_GOODS_QUESTIONS_DETAIL.getNameFormat(type, goodsId);
  787. Object o = redisService.get(key);
  788. if (o == null) {
  789. List<GoodsDonQaFrontView> donQaFrontViews = beanSearcher.searchAll(GoodsDonQaFrontView.class, MapUtils.builder().field(GoodsDonQaFrontView::getGoodsId, goodsId).field(GoodsDonQaFrontView::getType, type).build());
  790. if (CollUtil.isEmpty(donQaFrontViews)) {
  791. return GatewayResponse.SUCCESS.newBuilder().toResult();
  792. }
  793. redisService.setNx(key, donQaFrontViews, RedisService.key.YH_GOODS_QUESTIONS_DETAIL.getTimeout());
  794. o = redisService.get(key);
  795. }
  796. List<GoodsDonQaFrontView> donQaFrontViews = Jsons.parseList(o, GoodsDonQaFrontView.class);
  797. return GatewayResponse.SUCCESS.newBuilder().toResult(donQaFrontViews);
  798. }
  799. /**
  800. * 车票所有常见问题
  801. */
  802. @GetMapping("/get/questions")
  803. public Result<List<GoodsDonQaFrontView>> getAllTicketQuestions(String participle) {
  804. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  805. if (StrUtil.isNotBlank(participle)) {
  806. char[] charArray = participle.toCharArray();
  807. StringBuilder p = new StringBuilder();
  808. p.append("and (");
  809. for (int i = 0; i < charArray.length; i++) {
  810. char c = charArray[i];
  811. p.append(String.format(" ga.problem like '%%%s%%'", c));
  812. if (i != charArray.length - 1) {
  813. p.append(" or ");
  814. }
  815. }
  816. p.append(")");
  817. builder.put("p", p);
  818. }
  819. List<GoodsDonQaFrontView> donQaFrontViews = beanSearcher.searchAll(GoodsDonQaFrontView.class, builder.build());
  820. return GatewayResponse.SUCCESS.newBuilder().toResult(donQaFrontViews);
  821. }
  822. /**
  823. * 是否首次购买车票
  824. */
  825. @GetMapping("/get/first/pay/{goodsId}")
  826. public Result<Boolean> getFirstPay(@PathVariable Long goodsId) {
  827. long userId = StpUserUtil.getLoginIdAsLong();
  828. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  829. Number number = beanSearcher.searchCount(OrderDon.class, MapUtils.builder()
  830. .field(OrderDon::getGoodsId, goodsId)
  831. .field(OrderDon::getCreatedTime, new DateTime().toDateStr()).op(Operator.LessEqual)
  832. .field(OrderDon::getUserId, userIdList).op(Operator.InList)
  833. .field(OrderDon::getStatus, Constant.noOrderStatus).op(Operator.NotIn)
  834. .build());
  835. if (number.intValue() == 0) {
  836. UserGoodsNewbieGuideRecord userGoodsNewbieGuideRecord = new UserGoodsNewbieGuideRecord();
  837. userGoodsNewbieGuideRecord.setGoodsId(goodsId);
  838. userGoodsNewbieGuideRecord.setUserId(userId);
  839. userGoodsNewbieGuideRecordMapper.insert(userGoodsNewbieGuideRecord);
  840. return GatewayResponse.SUCCESS.newBuilder().toResult(true);
  841. }
  842. return GatewayResponse.SUCCESS.newBuilder().toResult(false);
  843. }
  844. /**
  845. * 设置pin码
  846. */
  847. @PutMapping("/set/pin/{relationId}")
  848. public Result<String> setPin(@PathVariable Long relationId, String code) {
  849. long userId = StpUserUtil.getLoginIdAsLong();
  850. JSONObject data = groupsRelationNetflixService.setNetflixPin(relationId, userId, code);
  851. return GatewayResponse.SUCCESS.newBuilder().toResult(data.toString());
  852. }
  853. /**
  854. * 查询是否设置成功
  855. */
  856. @GetMapping("/get/pin/status/{taskId}")
  857. public Result<Integer> getPinStatus(@PathVariable String taskId) throws Exception {
  858. long userId = StpUserUtil.getLoginIdAsLong();
  859. log.info("userId:{}查看设置pin码状态", userId);
  860. return GatewayResponse.SUCCESS.newBuilder().toResult(groupsRelationNetflixService.getPinStatus(taskId));
  861. }
  862. /**
  863. * 踢出奈飞设备
  864. */
  865. @PostMapping("/kickOut/nf/{relationId}")
  866. public Result<String> nfKickOut(@PathVariable Long relationId) {
  867. long userId = StpUserUtil.getLoginIdAsLong();
  868. JSONObject data = groupsRelationNetflixService.nfKickOut(userId, relationId);
  869. return GatewayResponse.SUCCESS.newBuilder().toResult(data.toString());
  870. }
  871. /**
  872. * 奈飞同户装置链接
  873. */
  874. @GetMapping("/get/nf/household/device")
  875. public Result<String> getNfHouseholdDevice(@NotNull Long relationId) throws Exception {
  876. long userId = StpUserUtil.getLoginIdAsLong();
  877. String url = groupRelationFrontService.getNfHouseholdDevice(userId, relationId);
  878. return GatewayResponse.SUCCESS.newBuilder().toResult(url);
  879. }
  880. /**
  881. * 代点奈飞同户装置
  882. */
  883. @PostMapping("/click/nf/household/device")
  884. public void clickNfHouseholdDevice(@RequestBody NfDeviceReq nfDeviceReq) {
  885. groupsRelationNetflixService.clickNfHouseholdDevice(nfDeviceReq);
  886. }
  887. /**
  888. * 可选 续费升级车票
  889. */
  890. @GetMapping("/get/renew/skus/{relationId}/{skuId}")
  891. public Result<List<RenewUpgradePackageFrontView>> getRenewSkus(@PathVariable Long relationId, @PathVariable Long skuId) {
  892. long userId = StpUserUtil.getLoginIdAsLong();
  893. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  894. ChatgptUser chatgptUser = chatgptUserMapper.selectOne(Wrappers.lambdaQuery(ChatgptUser.class)
  895. .eq(ChatgptUser::getRelationId, relationId)
  896. .last("limit 1"));
  897. if (chatgptUser == null) return GatewayResponse.SUCCESS.newBuilder().toResult();
  898. //目前续费升级的规格
  899. Long renewSkuId = chatgptUser.getRenewSkuId();
  900. GoodsDonSku sku = goodsDonSkuMapper.selectById(skuId);
  901. AtomicInteger minMonths = new AtomicInteger(sku.getMonths());
  902. AtomicInteger minNum = new AtomicInteger(chatgptUser.getLimitNum());
  903. AtomicLong minTime = new AtomicLong(chatgptUser.getLimitTime());
  904. if (renewSkuId != null) {
  905. GoodsDonSku presentRenew = goodsDonSkuMapper.selectById(renewSkuId);
  906. minMonths.set(presentRenew.getMonths());
  907. }
  908. if (chatgptUser.getPackageId() != 0) {
  909. Long packageId = chatgptUser.getPackageId();
  910. UpgradeOrderDon upgradeOrderDon = upgradeOrderDonMapper.selectOne(Wrappers.lambdaQuery(UpgradeOrderDon.class)
  911. .eq(UpgradeOrderDon::getPackageId, packageId)
  912. .eq(UpgradeOrderDon::getRelationId, relationId)
  913. .in(UpgradeOrderDon::getUserId, userIdList)
  914. .last("limit 1"));
  915. Long upgradeOrderDonSkuId = upgradeOrderDon.getSkuId();
  916. GoodsDonSku upgradeSku = goodsDonSkuMapper.selectById(upgradeOrderDonSkuId);
  917. if (upgradeSku != null) {
  918. if (upgradeSku.getMonths() > minMonths.get()) {
  919. minMonths.set(upgradeSku.getMonths());
  920. }
  921. }
  922. }
  923. List<RenewUpgradePackageFrontView> renewUpgradePackageFrontViews = beanSearcher.searchAll(RenewUpgradePackageFrontView.class, MapUtils.builder().field(RenewUpgradePackageFrontView::getSkuId, skuId).build());
  924. renewUpgradePackageFrontViews.forEach(renew -> {
  925. try {
  926. List<Long> upgradeSkuIds = Jsons.parseList(renew.getUpgradeSkuIds(), Long.class);
  927. //年付展示
  928. MapBuilder builder = MapUtils.builder();
  929. // if (minMonths.get() == 12) {
  930. // builder.field(RenewUpgradePackageFrontView.RenewSkuView::getMonths, minMonths.get()).op(Operator.GreaterEqual);
  931. // if (renewSkuId != null) {
  932. // upgradeSkuIds.remove(renewSkuId);
  933. // }
  934. // } else {
  935. // builder.field(RenewUpgradePackageFrontView.RenewSkuView::getMonths, minMonths.get()).op(Operator.GreaterEqual);
  936. // }
  937. //GPT镜像2月规格 特殊处理
  938. if (sku.getGoodsId() == 18 && sku.getMonths() == 2) {
  939. } else {
  940. //同续费时间规格
  941. builder.field(RenewUpgradePackageFrontView.RenewSkuView::getMonths, minMonths.get()).op(Operator.GreaterEqual);
  942. }
  943. if (renewSkuId != null) {
  944. upgradeSkuIds.remove(renewSkuId);
  945. }
  946. List<RenewUpgradePackageFrontView.RenewSkuView> renewSkuViews = new ArrayList<>();
  947. if (CollUtil.isNotEmpty(upgradeSkuIds)) {
  948. renewSkuViews = beanSearcher.searchAll(RenewUpgradePackageFrontView.RenewSkuView.class, builder
  949. .field(RenewUpgradePackageFrontView.RenewSkuView::getGptLimitNum, minNum.get()).op(Operator.GreaterEqual)
  950. .field(RenewUpgradePackageFrontView.RenewSkuView::getGptLimitTime, minTime.get()).op(LessEqual.class)
  951. .field(RenewUpgradePackageFrontView.RenewSkuView::getSkuId, upgradeSkuIds).op(Operator.InList)
  952. .build());
  953. }
  954. renew.setRenewSkus(renewSkuViews);
  955. } catch (Exception e) {
  956. }
  957. });
  958. return GatewayResponse.SUCCESS.newBuilder().toResult(renewUpgradePackageFrontViews);
  959. }
  960. /**
  961. * 独立规格续费套餐列表
  962. */
  963. @GetMapping("/get/independent/renew/skus/{skuId}")
  964. public Result<List<RenewUpgradePackageFrontView>> getRenewSkus(@PathVariable Long skuId) {
  965. long userId = StpUserUtil.getLoginIdAsLong();
  966. List<RenewUpgradePackageFrontView> renewUpgradePackageFrontViews = beanSearcher.searchAll(RenewUpgradePackageFrontView.class, MapUtils.builder().field(RenewUpgradePackageFrontView::getSkuId, skuId).build());
  967. renewUpgradePackageFrontViews.forEach(renew -> {
  968. try {
  969. List<Long> upgradeSkuIds = Jsons.parseList(renew.getUpgradeSkuIds(), Long.class);
  970. MapBuilder builder = MapUtils.builder();
  971. List<RenewUpgradePackageFrontView.RenewSkuView> renewSkuViews = beanSearcher.searchAll(RenewUpgradePackageFrontView.RenewSkuView.class, builder
  972. .field(RenewUpgradePackageFrontView.RenewSkuView::getSkuId, upgradeSkuIds).op(Operator.InList)
  973. .build());
  974. renew.setRenewSkus(renewSkuViews);
  975. } catch (Exception e) {
  976. }
  977. });
  978. return GatewayResponse.SUCCESS.newBuilder().toResult(renewUpgradePackageFrontViews);
  979. }
  980. /**
  981. * claude pro续费升级
  982. */
  983. @GetMapping("/get/claude/renew/skus/{relationId}/{skuId}")
  984. public Result<List<RenewUpgradePackageFrontView> > getClaudeRenewSkus(@PathVariable Long relationId, @PathVariable Long skuId) {
  985. long userId = StpUserUtil.getLoginIdAsLong();
  986. ClaudeUser claudeUser = claudeUserMapper.selectOne(Wrappers.lambdaQuery(ClaudeUser.class)
  987. .eq(ClaudeUser::getRelationId, relationId)
  988. .last("limit 1"));
  989. if (claudeUser == null) return GatewayResponse.SUCCESS.newBuilder().toResult();
  990. List<RenewUpgradePackageFrontView> renewUpgradePackageFrontViews = beanSearcher.searchAll(RenewUpgradePackageFrontView.class, MapUtils.builder().field(RenewUpgradePackageFrontView::getSkuId, skuId).build());
  991. renewUpgradePackageFrontViews.forEach(renew -> {
  992. try {
  993. List<Long> upgradeSkuIds = Jsons.parseList(renew.getUpgradeSkuIds(), Long.class);
  994. MapBuilder builder = MapUtils.builder();
  995. List<RenewUpgradePackageFrontView.RenewSkuView> renewSkuViews = beanSearcher.searchAll(RenewUpgradePackageFrontView.RenewSkuView.class, builder
  996. .field(RenewUpgradePackageFrontView.RenewSkuView::getSkuId, upgradeSkuIds).op(Operator.InList)
  997. .field(RenewUpgradePackageFrontView.RenewSkuView::getGptLimitNum, claudeUser.getLimitNum()).op(Operator.GreaterEqual)
  998. .build());
  999. renew.setRenewSkus(renewSkuViews);
  1000. } catch (Exception e) {
  1001. }
  1002. });
  1003. return GatewayResponse.SUCCESS.newBuilder().toResult(renewUpgradePackageFrontViews);
  1004. }
  1005. /**
  1006. * 已配置的续费升级规格ids
  1007. */
  1008. @GetMapping("/get/renew/skus/configured")
  1009. public Result<List<Long> > getClaudeRenewSkus() {
  1010. long userId = StpUserUtil.getLoginIdAsLong();
  1011. List<RenewUpgradePackageFrontView> renewUpgradePackageFrontViews = beanSearcher.searchAll(RenewUpgradePackageFrontView.class, MapUtils.builder().onlySelect(RenewUpgradePackageFrontView::getSkuId).build());
  1012. List<Long> collect = renewUpgradePackageFrontViews.stream().map(RenewUpgradePackageFrontView::getSkuId).collect(Collectors.toList());
  1013. return GatewayResponse.SUCCESS.newBuilder().toResult(collect);
  1014. }
  1015. /**
  1016. * 获取GPT PLUS登录验证码
  1017. */
  1018. @GetMapping("/get/verify/code")
  1019. public Result<String> getVerifyCode(@NotEmpty String account) throws Exception {
  1020. String code = groupRelationFrontService.getVerifyCode(account);
  1021. if (StrUtil.isEmpty(code)) {
  1022. throw BusinessRuntimeException.getInstance("请重新发送验证码");
  1023. }
  1024. return GatewayResponse.SUCCESS.newBuilder().toResult(code);
  1025. }
  1026. /**
  1027. * 独立规格续费减免
  1028. */
  1029. @GetMapping("/get/renew/reduce")
  1030. public Result<UserBenefitsFrontView> getRenewReduce(Long skuId, Long relationId) {
  1031. long userId = StpUserUtil.getLoginIdAsLong();
  1032. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  1033. UserBenefitsFrontView data = beanSearcher.searchFirst(UserBenefitsFrontView.class, MapUtils.builder().field(UserBenefitsFrontView::getSkuId, skuId).field(UserBenefitsFrontView::getType, UserBenefits.Type.RENEW.name()).build());
  1034. if (data == null) {
  1035. return GatewayResponse.SUCCESS.newBuilder().toResult();
  1036. }
  1037. Date startTime = null;
  1038. if (relationId != null) {
  1039. GroupsRelation relation = relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
  1040. .eq(GroupsRelation::getId, relationId)
  1041. .in(GroupsRelation::getUserId, userIdList));
  1042. if (relation == null) {
  1043. throw BusinessRuntimeException.getInstance("车票不存在");
  1044. }
  1045. startTime = relation.getStartTime();
  1046. }
  1047. Integer renewCount = userBenefitsOrderRecordMapper.selectUseComboRecordByUid(userIdList, data.getType(), data.getGoodsId(), data.getSkuId(), Constant.noOrderAllStatus, null, startTime, relationId);
  1048. data.setRenewCount(renewCount);
  1049. return GatewayResponse.SUCCESS.newBuilder().toResult(data);
  1050. }
  1051. /**
  1052. * 申请更换车票
  1053. */
  1054. @PostMapping("/change/ticket")
  1055. public Result<String> changeTicket(@RequestBody ChangeTicketReq changeTicketReq) {
  1056. long userId = StpUserUtil.getLoginIdAsLong();
  1057. List<Long> relationIds = changeTicketReq.getRelationIds();
  1058. if (CollUtil.isEmpty(relationIds)) {
  1059. return GatewayResponse.SUCCESS.newBuilder().toResult();
  1060. }
  1061. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  1062. //奈飞超过3帐车票不给看
  1063. Number number = beanSearcher.searchCount(RenewalView.class, MapUtils.builder()
  1064. .field(RenewalView::getUserId, userIdList).op(Operator.InList)
  1065. .field(RenewalView::getGoodsId, 1)
  1066. .field(RenewalView::getExpiryTime, DateTime.now()).op(Operator.GreaterThan)
  1067. .build());
  1068. if (number.intValue() > 2) {
  1069. return GatewayResponse.SUCCESS.newBuilder().toResult();
  1070. }
  1071. relationIds.forEach(relationId -> {
  1072. try {
  1073. groupRelationFrontService.changeTicket(userId, relationId);
  1074. } catch (Exception e) {
  1075. log.error("更换车票失败:{}", StringUtil.getErrorText(e));
  1076. if (relationIds.size() == 1) {
  1077. throw BusinessRuntimeException.getInstance(e.getMessage());
  1078. }
  1079. }
  1080. });
  1081. return GatewayResponse.SUCCESS.newBuilder().toResult();
  1082. }
  1083. /**
  1084. * 查看临时账号
  1085. */
  1086. @GetMapping("/get/temp/account/{relationId}")
  1087. public Result<AccountView> getTempAccount(@PathVariable Long relationId) {
  1088. long userId = StpUserUtil.getLoginIdAsLong();
  1089. AccountView accountView = groupRelationFrontService.getTempAccount(userId, relationId);
  1090. return GatewayResponse.SUCCESS.newBuilder().toResult(accountView);
  1091. }
  1092. /**
  1093. * 申请提交记录
  1094. */
  1095. @GetMapping("/get/netflix/get/error/submit/record")
  1096. public Result<List<NetflixUserAccountStatusRecord>> getUserNetflixSubmitRecord() {
  1097. long userId = StpUserUtil.getLoginIdAsLong();
  1098. List<NetflixUserAccountStatusRecord> netflixUserAccountStatusRecords = groupRelationFrontService.getUserNetflixSubmitRecord(userId);
  1099. return GatewayResponse.SUCCESS.newBuilder().toResult(netflixUserAccountStatusRecords);
  1100. }
  1101. /**
  1102. * 奈飞账号异常检测提交
  1103. */
  1104. @PostMapping("/netflix/error/account/submit/{relationId}")
  1105. public Result<String> nfErrorAccountSubmit(@PathVariable Long relationId) {
  1106. long userId = StpUserUtil.getLoginIdAsLong();
  1107. groupRelationFrontService.nfErrorAccountSubmit(userId, relationId);
  1108. return GatewayResponse.SUCCESS.newBuilder().toResult();
  1109. }
  1110. /**
  1111. * 奈飞账号检测结果
  1112. */
  1113. @GetMapping("/get/netflix/error/account/status/{relationId}")
  1114. public Result<Integer> getNetflixErrorAccountStatus(@PathVariable Long relationId) {
  1115. long userId = StpUserUtil.getLoginIdAsLong();
  1116. Integer state = groupRelationFrontService.getNetflixErrorAccountStatus(userId, relationId);
  1117. return GatewayResponse.SUCCESS.newBuilder().toResult(state);
  1118. }
  1119. }