CmsOrderController.java 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504
  1. package com.cyksj.web.controller.manage;
  2. import cn.dev33.satoken.annotation.SaCheckPermission;
  3. import cn.dev33.satoken.stp.StpUtil;
  4. import cn.hutool.core.collection.CollUtil;
  5. import cn.hutool.core.date.DateTime;
  6. import cn.hutool.core.date.DateUtil;
  7. import cn.hutool.core.util.ObjectUtil;
  8. import cn.hutool.core.util.StrUtil;
  9. import com.alibaba.excel.EasyExcel;
  10. import com.alibaba.excel.support.ExcelTypeEnum;
  11. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  12. import com.cyksj.common.annotation.Log;
  13. import com.cyksj.common.annotation.NoSubmit;
  14. import com.cyksj.common.constant.Constant;
  15. import com.cyksj.common.exception.BusinessRuntimeException;
  16. import com.cyksj.common.task.GlobalThreadPoolTaskExecutor;
  17. import com.cyksj.common.util.IoKit;
  18. import com.cyksj.common.util.Jsons;
  19. import com.cyksj.common.util.Xmls;
  20. import com.cyksj.dto.Result;
  21. import com.cyksj.enums.BusinessType;
  22. import com.cyksj.enums.GatewayApiCode;
  23. import com.cyksj.enums.GatewayResponse;
  24. import com.cyksj.mapper.*;
  25. import com.cyksj.mapper.channel.ChannelPopularizeMapper;
  26. import com.cyksj.mapper.channel.UserPayEquipmentAvailableBenefitsMapper;
  27. import com.cyksj.mapper.channel.UserPayEquipmentReceiveBenefitsRecordMapper;
  28. import com.cyksj.mapper.claudecode.ClaudeCodeDeductOrderRelateMapper;
  29. import com.cyksj.mapper.manage.RealGoodsOrderHandleMapper;
  30. import com.cyksj.mapper.manage.cms.CmsUserMapper;
  31. import com.cyksj.mapper.manage.coupon.CouponMapper;
  32. import com.cyksj.mapper.shop.YhShopMapper;
  33. import com.cyksj.model.dto.OriSkuDto;
  34. import com.cyksj.model.dto.RenewOriOrderSkuDto;
  35. import com.cyksj.model.entity.*;
  36. import com.cyksj.model.excel.*;
  37. import com.cyksj.model.manage.request.ReqSetLogisticsPost;
  38. import com.cyksj.model.manage.views.AccountView;
  39. import com.cyksj.model.manage.views.OrderDonBackView;
  40. import com.cyksj.model.manage.views.UpgradeOrderDonBackView;
  41. import com.cyksj.model.request.*;
  42. import com.cyksj.model.views.*;
  43. import com.cyksj.service.chatgpt.GptUserRechargeRecordService;
  44. import com.cyksj.service.mange.CmsOrderDonService;
  45. import com.cyksj.service.order.OrderDonCommentService;
  46. import com.cyksj.service.user.UserBindRelationService;
  47. import com.cyksj.service.user.UserService;
  48. import com.cyksj.web.util.EasyExcelUtils;
  49. import com.ejlchina.searcher.BeanSearcher;
  50. import com.ejlchina.searcher.SearchResult;
  51. import com.ejlchina.searcher.param.Operator;
  52. import com.ejlchina.searcher.util.MapBuilder;
  53. import com.ejlchina.searcher.util.MapUtils;
  54. import com.google.common.collect.Lists;
  55. import lombok.RequiredArgsConstructor;
  56. import lombok.extern.slf4j.Slf4j;
  57. import org.apache.commons.lang3.StringUtils;
  58. import org.springframework.dao.DuplicateKeyException;
  59. import org.springframework.transaction.annotation.Transactional;
  60. import org.springframework.validation.annotation.Validated;
  61. import org.springframework.web.bind.annotation.*;
  62. import javax.servlet.http.HttpServletRequest;
  63. import javax.servlet.http.HttpServletResponse;
  64. import java.io.IOException;
  65. import java.io.OutputStream;
  66. import java.math.BigDecimal;
  67. import java.util.*;
  68. import java.util.concurrent.CountDownLatch;
  69. import java.util.concurrent.TimeUnit;
  70. import java.util.stream.Collectors;
  71. /**
  72. * admin/订单管理/售后操作
  73. * @author chan
  74. * @date 2021/10/12 下午11:05
  75. */
  76. @Slf4j
  77. @RequestMapping("/manage/order")
  78. @RestController
  79. @RequiredArgsConstructor
  80. public class CmsOrderController {
  81. private final HttpServletRequest request;
  82. private final CmsOrderDonService cmsOrderDonService;
  83. private final UserService userService;
  84. private final BeanSearcher beanSearcher;
  85. private final RealGoodsInterestUserMapper realGoodsInterestUserMapper;
  86. private final RealGoodsOrderHandleMapper realGoodsOrderHandleMapper;
  87. private final CouponMapper couponMapper;
  88. private final OrderCommentMapper orderCommentMapper;
  89. private final OrderDonCommentService orderDonCommentService;
  90. private final GoodsDonSkuMapper skuMapper;
  91. private final ChannelPopularizeMapper channelPopularizeMapper;
  92. private final GroupsRelationMapper relationMapper;
  93. private final UserPayEquipmentReceiveBenefitsRecordMapper receiveBenefitsRecordMapper;
  94. private final UserPayEquipmentAvailableBenefitsMapper availableBenefitsMapper;
  95. private final YhShopMapper yhShopMapper;
  96. private final CmsUserMapper cmsUserMapper;
  97. private final UserMapper userMapper;
  98. private final OrderDonMapper orderDonMapper;
  99. private final OrderDonCustomerServiceRelateMapper orderDonCustomerServiceRelateMapper;
  100. private final MidjourneyUserConversationMapper midjourneyUserConversationMapper;
  101. private final MidjourneyUserMapper midjourneyUserMapper;
  102. private final UserBindRelationService userBindRelationService;
  103. private final OrderDonRenewRecordMapper orderDonRenewRecordMapper;
  104. private final ChatgptUserMapper chatgptUserMapper;
  105. private final UserBenefitsOrderRecordMapper userBenefitsOrderRecordMapper;
  106. private final OrderDonDifferRelateMapper orderDonDifferRelateMapper;
  107. private final OrderDonDifferGoodsMapper orderDonDifferGoodsMapper;
  108. private final OrderDiscountPlusPurchaseSkuRelationMapper plusPurchaseSkuRelationMapper;
  109. private final OrderDonGalaxyCoinRecordMapper orderDonGalaxyCoinRecordMapper;
  110. private final GptUserRechargeRecordService gptUserRechargeRecordService;
  111. private final ClaudeCodeDeductOrderRelateMapper claudeCodeDeductOrderRelateMapper;
  112. private final OrderDonAfterSalesRecordMapper orderDonAfterSalesRecordMapper;
  113. private static final GlobalThreadPoolTaskExecutor TASK_EXECUTOR = GlobalThreadPoolTaskExecutor.getInstance();
  114. @GetMapping("/get")
  115. @SaCheckPermission("order:view")
  116. public Result<SearchResult<OrderDonBackView>> get(Long channelId, String account, String showId, Long acId, String nickname, String register, Boolean isGoogle, Boolean isSubsidy, Boolean isRenewPackage, Integer otherOrderType, Long userMirrorShopId, String operator, Long diffGoodsId, Boolean isTp, String phone, String receiver) {
  117. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  118. if (channelId != null) {
  119. List<Long> popularizeIds = channelPopularizeMapper.getPopularizeIdByChannelId(channelId);
  120. builder.field(OrderDonBackView::getPopularizeId, popularizeIds).op(Operator.InList);
  121. }
  122. if (StrUtil.isNotBlank(account)) {
  123. GroupsRelation relation = relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
  124. .eq(GroupsRelation::getAccount, account).last("limit 1"));
  125. if (relation != null) {
  126. builder.field(OrderDonBackView::getRelationId, relation.getId());
  127. } else {
  128. builder.field(OrderDonBackView::getRelationId).op(Operator.IsNull);
  129. }
  130. }
  131. if (StrUtil.isNotBlank(showId)) {
  132. builder.field(OrderDonBackView::getUserId, userService.getUserIdByShowId(showId));
  133. }
  134. String conditionSql = StrUtil.EMPTY;
  135. if (acId != null) {
  136. conditionSql += String.format(" o.user_id in (select user_id from corp_user where ac_id = %s)", acId);
  137. }
  138. if (!ObjectUtil.isAllEmpty(nickname, register, isGoogle)) {
  139. if (StrUtil.isNotEmpty(conditionSql)) {
  140. conditionSql += " and ";
  141. }
  142. conditionSql += " exists (select u.id from user u where u.id = o.user_id";
  143. if (StrUtil.isNotEmpty(nickname)) {
  144. conditionSql += String.format(" and u.nickname like '%s%%'", nickname);
  145. }
  146. if (StrUtil.isNotEmpty(register)) {
  147. if ("phone".equals(register)) {
  148. conditionSql += " and u.login_phone != ''";
  149. } else if ("email".equals(register)) {
  150. conditionSql += " and u.email != ''";
  151. } else if ("wechat".equals(register)) {
  152. conditionSql += " and u.unionid != ''";
  153. }
  154. }
  155. if (isGoogle != null && isGoogle) {
  156. conditionSql += String.format(" and u.is_google is %s", isGoogle);
  157. }
  158. conditionSql += " limit 1)";
  159. }
  160. if (isSubsidy != null) {
  161. if (StrUtil.isNotEmpty(conditionSql)) {
  162. conditionSql += " and ";
  163. }
  164. conditionSql += " exists (select 1 from order_don_subsidy_relate ocr where ocr.order_id = o.id limit 1)";
  165. }
  166. if (isRenewPackage != null) {
  167. if (StrUtil.isNotEmpty(conditionSql)) {
  168. conditionSql += " and ";
  169. }
  170. conditionSql += " exists (select 1 from order_don_renew_record odrr1 where odrr1.order_id = o.id limit 1)";
  171. }
  172. if (otherOrderType != null) {
  173. //3.续费升级订单
  174. if (otherOrderType == 3) {
  175. builder.put("tb", String.format(" inner join order_don_renew_record odcr on odcr.order_id = o.id and odcr.order_type = 2"));
  176. }
  177. if (otherOrderType == 4) {
  178. //4.用户权益订单
  179. builder.put("tb", String.format(" inner join user_benefits_order_record ubor on ubor.order_id = o.id and ubor.type = 'RENEW'"));
  180. }
  181. if (otherOrderType == 6) {
  182. //6.加盟订单
  183. builder.put("tb", String.format(" inner join user_mirror_shop_order_relate umr on umr.order_id = o.id"));
  184. }
  185. }
  186. if (userMirrorShopId != null) {
  187. if (StrUtil.isNotEmpty(conditionSql)) {
  188. conditionSql += " and ";
  189. }
  190. conditionSql += String.format(" exists (select 1 from user_mirror_shop_order_relate umr where mp_id = %s and umr.order_id = o.id limit 1)", userMirrorShopId);
  191. }
  192. if (!StrUtil.isAllEmpty(phone, receiver)) {
  193. List<Long> transportOrderIds = orderDonMapper.selectTransportOids(phone, receiver);
  194. builder.field(OrderDonBackView::getId, transportOrderIds).op(Operator.InList);
  195. }
  196. if (diffGoodsId != null || StrUtil.isNotBlank(operator) || isTp != null) {
  197. if (StrUtil.isNotEmpty(conditionSql)) {
  198. conditionSql += " and ";
  199. }
  200. conditionSql += " exists (select 1 from order_don_differ_relate odr where odr.order_id = o.id";
  201. if (diffGoodsId != null) {
  202. conditionSql += String.format(" and odr.goods_id = %s", diffGoodsId);
  203. }
  204. if (StrUtil.isNotBlank(operator)) {
  205. conditionSql += String.format(" and odr.operator = '%s'", operator);
  206. }
  207. if (isTp != null && isTp) {
  208. conditionSql += String.format(" and odr.is_tp = %s", isTp);
  209. }
  210. conditionSql += ")";
  211. }
  212. if (StrUtil.isNotBlank(conditionSql)) {
  213. builder.put("condition", conditionSql);
  214. }
  215. SearchResult<OrderDonBackView> search = beanSearcher.search(OrderDonBackView.class, builder.build());
  216. search.getDataList().forEach(data -> {
  217. if (data.getPopularizeId() != null) {
  218. Optional.ofNullable(channelPopularizeMapper.selectChannelByPid(data.getPopularizeId()))
  219. .ifPresent(channelName -> data.setChannel(channelName));
  220. }
  221. if (data.getGoodsDonType() != null && Constant.realGoodsType.contains(data.getGoodsDonType())) {
  222. RealGoodsOrderHandle realGoodsOrderHandle = realGoodsOrderHandleMapper.selectOne(Wrappers.lambdaQuery(RealGoodsOrderHandle.class).eq(RealGoodsOrderHandle::getOrderId, data.getId()).last("limit 1"));
  223. if (realGoodsOrderHandle != null) {
  224. data.setBeforeServiceName(realGoodsOrderHandle.getBeforeServiceName());
  225. data.setAfterServiceName(realGoodsOrderHandle.getAfterServiceName());
  226. }
  227. OrderDonTransportView transportView = beanSearcher.searchFirst(OrderDonTransportView.class, MapUtils.builder().field(OrderDonTransportView::getOrderId, data.getId()).build());
  228. if (transportView != null) {
  229. data.setReceiver(transportView.getReceiver());
  230. data.setPhone(transportView.getPhone());
  231. data.setProvince(transportView.getProvince());
  232. data.setCity(transportView.getCity());
  233. data.setDistrict(transportView.getDistrict());
  234. data.setAddress(transportView.getAddress());
  235. }
  236. }
  237. //使用优惠码
  238. if (data.getCouponId() != null) {
  239. Optional.ofNullable(couponMapper.selectById(data.getCouponId())).ifPresent(coupon -> data.setCouponName(coupon.getName()));
  240. data.setCouponMoney(data.getCouponMoney() == null ? BigDecimal.ZERO : data.getCouponMoney());
  241. }
  242. if (data.getCouponUserId() != 0) {
  243. data.setCouponName(couponMapper.getCouponNameByCouponUserId(data.getCouponUserId()));
  244. data.setCouponMoney(data.getCouponMoney() == null ? BigDecimal.ZERO : data.getCouponMoney());
  245. }
  246. if (data.getRelationId() != 0) {
  247. Optional.ofNullable(relationMapper.getGroupRelationAccountView(data.getRelationId()))
  248. .ifPresent(e -> {
  249. data.setGtAccount(e.getTripsAccount());
  250. data.setAccount(e.getAccount());
  251. data.setActCode(e.getActCode());
  252. data.setActCodeUrl(e.getActCodeUrl());
  253. });
  254. }
  255. if (data.getIsBenefits() != null && data.getIsBenefits() && !Constant.noOrderAllStatus.contains(data.getStatus())) {
  256. //是否实物权益已发放
  257. Integer count = receiveBenefitsRecordMapper.selectCount(Wrappers.lambdaQuery(UserPayEquipmentReceiveBenefitsRecord.class)
  258. .eq(UserPayEquipmentReceiveBenefitsRecord::getRealOrderId, data.getId()));
  259. if (count == 0) {
  260. count = availableBenefitsMapper.selectCount(Wrappers.lambdaQuery(UserPayEquipmentAvailableBenefits.class)
  261. .eq(UserPayEquipmentAvailableBenefits::getRealOrderId, data.getId()));
  262. }
  263. data.setIsHasBenefits(count == 0 ? true : false);
  264. //是否是套餐优惠权益订单
  265. if (data.getIsBenefits()) {
  266. Integer selectCount = userBenefitsOrderRecordMapper.selectCount(Wrappers.lambdaQuery(UserBenefitsOrderRecord.class)
  267. .eq(UserBenefitsOrderRecord::getOrderId, data.getId()));
  268. if (selectCount > 0) {
  269. data.setIsHasBenefits(false);
  270. }
  271. }
  272. }
  273. if (data.getYhsId() != 0) {
  274. Optional.ofNullable(yhShopMapper.selectById(data.getYhsId()))
  275. .ifPresent(e -> {
  276. data.setShopName(e.getName());
  277. data.setCustomId(e.getCustomId());
  278. });
  279. }
  280. User user = userMapper.selectById(data.getUserId());
  281. if (user != null) {
  282. data.setNickname(user.getNickname());
  283. data.setLoginPhone(user.getLoginPhone());
  284. data.setEmail(user.getEmail());
  285. data.setRegister(StrUtil.isNotEmpty(user.getUnionid()) ? "wechat" : StrUtil.isNotEmpty(user.getLoginPhone()) ? "phone" : "email");
  286. }
  287. if (data.getGoodsDonType() != null && data.getGoodsDonType() == 1) {
  288. //获取订单关联客服
  289. Optional.ofNullable(orderDonMapper.selectOrderRelate(data.getId())).ifPresent(e -> {
  290. data.setCmsUserId(e.getCmsUserId());
  291. data.setNickname(e.getNickname());
  292. });
  293. }
  294. //补差价订单
  295. if (data.getGoodsDonType() != null && data.getGoodsDonType() == 5) {
  296. OrderDonDifferRelateView donDifferRelateView = beanSearcher.searchFirst(OrderDonDifferRelateView.class, MapUtils.builder().field(OrderDonDifferRelateView::getOrderId, data.getId()).build());
  297. if (donDifferRelateView != null) {
  298. data.setDiffGoodsId(donDifferRelateView.getGoodsId());
  299. data.setDiffTitle(donDifferRelateView.getTitle());
  300. data.setDiffOperator(donDifferRelateView.getOperator());
  301. data.setIsTp(donDifferRelateView.getIsTp());
  302. }
  303. }
  304. OrderDonGalaxyCoinRecord orderDonGalaxyCoinRecord = orderDonGalaxyCoinRecordMapper.selectOne(Wrappers.lambdaQuery(OrderDonGalaxyCoinRecord.class)
  305. .eq(OrderDonGalaxyCoinRecord::getOrderId, data.getId())
  306. .last("limit 1"));
  307. if (orderDonGalaxyCoinRecord != null) {
  308. data.setGalaxyCoin(orderDonGalaxyCoinRecord.getGalaxyCoin());
  309. data.setGalaxyCoinDeductMoney(orderDonGalaxyCoinRecord.getDeductMoney());
  310. }
  311. if (data.getGoodsId() == Constant.CLAUDE_CODE_GOODS_ID) {
  312. ClaudeCodeDeductOrderRelate claudeCodeDeductOrderRelate = claudeCodeDeductOrderRelateMapper.selectOne(Wrappers.lambdaQuery(ClaudeCodeDeductOrderRelate.class).eq(ClaudeCodeDeductOrderRelate::getOrderId, data.getId()).last("limit 1"));
  313. if (claudeCodeDeductOrderRelate != null) {
  314. data.setDeductMoney(claudeCodeDeductOrderRelate.getDeductMoney());
  315. }
  316. }
  317. });
  318. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  319. }
  320. /**
  321. * 用户退款订单列表
  322. */
  323. @GetMapping("/get/refund/list")
  324. public Result<SearchResult<RefundOrderDonView>> getRefundOrderDonView() {
  325. SearchResult<RefundOrderDonView> search = beanSearcher.search(RefundOrderDonView.class, MapUtils.flatBuilder(request.getParameterMap())
  326. .build());
  327. search.getDataList().forEach(data -> {
  328. Optional.ofNullable(userService.getById(data.getUserId()))
  329. .ifPresent(user -> data.setNickname(user.getNickname()));
  330. });
  331. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  332. }
  333. /**
  334. * 镜像规格使用详情
  335. */
  336. @GetMapping("/get/order/mj/mirror/detail/{orderId}")
  337. public Result<MidjourneyUserDetailView> getMjMirrorOrderDetail(@PathVariable Long orderId) {
  338. OrderDon orderDon = orderDonMapper.selectById(orderId);
  339. //续费订单
  340. Date startTime = null;
  341. Date expiryTime = null;
  342. if (orderDon.getOrderType() == 2) {
  343. GoodsDonSku sku = skuMapper.selectById(orderDon.getSkuId());
  344. GroupsRelation relation = relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
  345. .eq(GroupsRelation::getId, orderDon.getRelationId())
  346. .eq(GroupsRelation::getUserId, orderDon.getUserId()).last("limit 1"));
  347. if (relation == null) {
  348. return GatewayResponse.SUCCESS.newBuilder().toResult();
  349. }
  350. startTime = relation.getStartTime();
  351. startTime = DateUtil.offsetMonth(startTime, sku.getMonths());
  352. expiryTime = relation.getExpiryTime();
  353. }
  354. MidjourneyUserDetailView midjourneyUserDetailView = midjourneyUserConversationMapper.getMjMirrorOrderDetail(orderDon.getRelationId(), startTime, expiryTime);
  355. return GatewayResponse.SUCCESS.newBuilder().toResult(midjourneyUserDetailView);
  356. }
  357. /**
  358. * 订单导出
  359. */
  360. @GetMapping("/export")
  361. @SaCheckPermission("order:export")
  362. @Log(module = "订单管理/导出订单", businessType = BusinessType.EXPORT, isSaveRequestData = true)
  363. public void exportOrders(HttpServletResponse response, Long channelId, String account, String showId, Long acId, String nickname, String register, Boolean isGoogle, Boolean isSubsidy, Boolean isRenewPackage, Integer otherOrderType, Long userMirrorShopId, String operator, Long diffGoodsId, Boolean isTp) throws InterruptedException {
  364. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  365. if (channelId != null) {
  366. List<Long> popularizeIds = channelPopularizeMapper.getPopularizeIdByChannelId(channelId);
  367. builder.field(ExcelOrderDonData::getPopularizeId, popularizeIds).op(Operator.InList);
  368. }
  369. if (StrUtil.isNotBlank(account)) {
  370. GroupsRelation relation = relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
  371. .eq(GroupsRelation::getAccount, account).last("limit 1"));
  372. if (relation != null) {
  373. builder.field(ExcelOrderDonData::getRelationId, relation.getId());
  374. } else {
  375. builder.field(ExcelOrderDonData::getRelationId).op(Operator.IsNull);
  376. }
  377. }
  378. if (StrUtil.isNotBlank(showId)) {
  379. builder.field(ExcelOrderDonData::getUserId, userService.getUserIdByShowId(showId));
  380. }
  381. String conditionSql = StrUtil.EMPTY;
  382. if (acId != null) {
  383. conditionSql += String.format(" o.user_id in (select user_id from corp_user where ac_id = %s)", acId);
  384. }
  385. if (!ObjectUtil.isAllEmpty(nickname, register, isGoogle)) {
  386. if (StrUtil.isNotEmpty(conditionSql)) {
  387. conditionSql += " and ";
  388. }
  389. conditionSql += " exists (select u.id from user u where u.id = o.user_id";
  390. if (StrUtil.isNotEmpty(nickname)) {
  391. conditionSql += String.format(" and u.nickname like '%s%%'", nickname);
  392. }
  393. if (StrUtil.isNotEmpty(register)) {
  394. if ("phone".equals(register)) {
  395. conditionSql += " and u.login_phone != ''";
  396. } else if ("email".equals(register)) {
  397. conditionSql += " and u.email != ''";
  398. } else if ("wechat".equals(register)) {
  399. conditionSql += " and u.unionid != ''";
  400. }
  401. }
  402. if (isGoogle != null && isGoogle) {
  403. conditionSql += String.format(" and u.is_google is %s", isGoogle);
  404. }
  405. conditionSql += " limit 1)";
  406. }
  407. if (isSubsidy != null) {
  408. if (StrUtil.isNotEmpty(conditionSql)) {
  409. conditionSql += " and ";
  410. }
  411. conditionSql += " exists (select 1 from order_don_subsidy_relate ocr where ocr.order_id = o.id limit 1)";
  412. }
  413. if (isRenewPackage != null) {
  414. if (StrUtil.isNotEmpty(conditionSql)) {
  415. conditionSql += " and ";
  416. }
  417. conditionSql += " exists (select 1 from order_don_renew_record odrr1 where odrr1.order_id = o.id limit 1)";
  418. }
  419. if (otherOrderType != null) {
  420. //3.续费升级订单
  421. if (otherOrderType == 3) {
  422. builder.put("tb", String.format(" inner join order_don_renew_record odcr on odcr.order_id = o.id and odcr.order_type = 2"));
  423. }
  424. if (otherOrderType == 4) {
  425. //4.用户权益订单
  426. builder.put("tb", String.format(" inner join user_benefits_order_record ubor on ubor.order_id = o.id and ubor.type = 'RENEW'"));
  427. }
  428. if (otherOrderType == 6) {
  429. //6.加盟订单
  430. builder.put("tb", String.format(" inner join user_mirror_shop_order_relate umr on umr.order_id = o.id"));
  431. }
  432. }
  433. if (diffGoodsId != null || StrUtil.isNotBlank(operator) || isTp != null) {
  434. if (StrUtil.isNotEmpty(conditionSql)) {
  435. conditionSql += " and ";
  436. }
  437. conditionSql += " exists (select 1 from order_don_differ_relate odr where odr.order_id = o.id";
  438. if (diffGoodsId != null) {
  439. conditionSql += String.format(" and odr.goods_id = %s", diffGoodsId);
  440. }
  441. if (StrUtil.isNotBlank(operator)) {
  442. conditionSql += String.format(" and odr.operator = '%s'", operator);
  443. }
  444. if (isTp != null && isTp) {
  445. conditionSql += String.format(" and odr.is_tp = %s", isTp);
  446. }
  447. conditionSql += ")";
  448. }
  449. if (userMirrorShopId != null) {
  450. conditionSql += String.format(" exists (select 1 from user_mirror_shop_order_relate umr where mp_id = %s and umr.order_id = o.id limit 1)", userMirrorShopId);
  451. }
  452. if (StrUtil.isNotBlank(conditionSql)) {
  453. builder.put("condition", conditionSql);
  454. }
  455. List<ExcelOrderDonData> list = beanSearcher.searchAll(ExcelOrderDonData.class, builder.build());
  456. List<List<ExcelOrderDonData>> partition = Lists.partition(list, 500);
  457. CountDownLatch countDownLatch = new CountDownLatch(partition.size());
  458. for (List<ExcelOrderDonData> excelOrderDonData : partition) {
  459. TASK_EXECUTOR.execute(() -> setExportOrderInfo(excelOrderDonData, countDownLatch));
  460. }
  461. countDownLatch.await(15, TimeUnit.MINUTES);
  462. EasyExcelUtils.createExcelStreamMutilByEasyExcel(response, ExcelOrderDonData.class, list, "订单列表", "订单列表", ExcelTypeEnum.XLSX, null);
  463. }
  464. /**
  465. * 导出实物模板 订单excel
  466. */
  467. @GetMapping("/export/realGoods")
  468. public void exportRealGoods(HttpServletResponse response) throws IOException {
  469. List<ExcelRealGoodsOrderData> list = beanSearcher.searchAll(ExcelRealGoodsOrderData.class, MapUtils.flatBuilder(request.getParameterMap())
  470. .field(ExcelOrderDonData::getGoodsDonType, Constant.realGoodsType).op(Operator.InList)
  471. .build());
  472. // AtomicInteger index = new AtomicInteger(1);
  473. list.forEach(data -> {
  474. data.setPayType("寄付现结");
  475. if (data.getGoodsDonType() == Constant.realGoodsType.get(0)) {
  476. data.setRealGoodName("路由器");
  477. } else if (data.getGoodsDonType() == Constant.realGoodsType.get(1)) {
  478. data.setRealGoodName("银河潮玩");
  479. }
  480. // data.setIndex(index.getAndIncrement());
  481. });
  482. if (CollUtil.isEmpty(list)) {
  483. throw BusinessRuntimeException.getInstance("导出数据为空");
  484. }
  485. response.setContentType("application/x-download");
  486. response.setContentType("application/vnd.ms-excel");
  487. response.setCharacterEncoding("utf-8");
  488. response.setHeader("Content-disposition",
  489. "attachment;filename=" + new String("实物订单列表".getBytes("utf-8"), "ISO-8859-1") + ExcelTypeEnum.XLS.getValue());
  490. EasyExcel.write(response.getOutputStream())
  491. .head(ExcelRealGoodsOrderData.class)
  492. //设置合并单元格策略
  493. // .registerWriteHandler(new RealGoodsOrderLineStrategy())
  494. .excelType(ExcelTypeEnum.XLS)
  495. .sheet("实物订单列表")
  496. //设置头部标题从那行开始
  497. // .relativeHeadRowIndex(2)
  498. .doWrite(list);
  499. }
  500. @PutMapping("/update/status")
  501. public Result<String> upStatus(@RequestBody OrderDon orderDon){
  502. cmsOrderDonService.update(Wrappers.lambdaUpdate(OrderDon.class).eq(OrderDon::getId,orderDon.getId()).set(OrderDon::getStatus,orderDon.getStatus()));
  503. return GatewayResponse.SUCCESS.newBuilder().toResult();
  504. }
  505. /**
  506. * 编辑自定义订阅节点
  507. */
  508. @PutMapping("/update/subNode")
  509. public Result<String> updateSubNode(@RequestBody OrderDon orderDon) {
  510. OrderDon en = cmsOrderDonService.getById(orderDon.getId());
  511. if (en != null) {
  512. en.setSubNode(orderDon.getSubNode());
  513. cmsOrderDonService.updateById(en);
  514. }
  515. return GatewayResponse.SUCCESS.newBuilder().toResult();
  516. }
  517. @GetMapping("/get/transport/{orderId}")
  518. public Result<OrderDonTransportView> getTransport(@PathVariable Long orderId){
  519. // OrderDonTransport transport = cmsOrderDonService.getTransport(orderId);
  520. OrderDonTransportView transportView = beanSearcher.searchFirst(OrderDonTransportView.class, MapUtils.builder().field(OrderDonTransportView::getOrderId, orderId).build());
  521. return GatewayResponse.SUCCESS.newBuilder().toResult(transportView);
  522. }
  523. @PostMapping("/post/setWaybill")
  524. public Result<OrderDonWaybill> setWaybill(@RequestBody ReqSetLogisticsPost reqSetLogisticsPost){
  525. OrderDonWaybill orderDonWaybill = cmsOrderDonService.setWaybill(reqSetLogisticsPost);
  526. return GatewayResponse.SUCCESS.newBuilder().toResult(orderDonWaybill);
  527. }
  528. /**
  529. * 用户购买实物商品意愿列表
  530. */
  531. @GetMapping("/get/realGooods/interest/users")
  532. @SaCheckPermission("interest:view")
  533. public Result<SearchResult> getInterestUserList(RealGoodsInterestUser.Status interestStatus, HttpServletRequest request) {
  534. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  535. SearchResult<RealGoodsInterestUserView> search;
  536. if (interestStatus == null) {
  537. builder.field(RealGoodsInterestUserView::getInterestStatus, "hasPayment").op(Operator.NotEqual);
  538. search = beanSearcher.search(RealGoodsInterestUserView.class, builder.build());
  539. } else if (interestStatus != RealGoodsInterestUser.Status.hasPayment) {
  540. builder.field(RealGoodsInterestUserView::getInterestStatus, interestStatus.name());
  541. search = beanSearcher.search(RealGoodsInterestUserView.class, builder.build());
  542. } else {
  543. search = new SearchResult<>();
  544. SearchResult<RealGoodsInterestUserHasPaymentView> search2 = beanSearcher.search(RealGoodsInterestUserHasPaymentView.class, builder.build());
  545. search.setTotalCount(search2.getTotalCount());
  546. List<RealGoodsInterestUserView> dataList = search.getDataList();
  547. dataList.addAll(search2.getDataList());
  548. }
  549. search.getDataList().forEach(data -> {
  550. Long goodsId = data.getGoodsId();
  551. OrderDon order = cmsOrderDonService.getOne(Wrappers.lambdaQuery(OrderDon.class).eq(OrderDon::getUserId, data.getUserId()).eq(OrderDon::getGoodsId, goodsId).ne(OrderDon::getId, data.getId()).gt(OrderDon::getMoney, data.getMoney()).eq(OrderDon::getStatus, "close").last("limit 1"));
  552. if (order != null) {
  553. data.setOrderId(order.getId());
  554. data.setSkuId(order.getSkuId());
  555. data.setMoney(order.getMoney());
  556. realGoodsInterestUserMapper.updateData(data.getId(), data.getSkuId(), data.getOrderCreatedTime(), data.getOrderId());
  557. }
  558. });
  559. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  560. }
  561. /**
  562. * 修改订单状态
  563. */
  564. @PutMapping("/put/status/{orderId}")
  565. @Transactional(rollbackFor = Throwable.class)
  566. public Result<String> updateOrderStatus(@PathVariable Long orderId) {
  567. long adminId = StpUtil.getLoginIdAsLong();
  568. CmsUser cmsUser = cmsUserMapper.selectById(adminId);
  569. OrderDon orderDon = cmsOrderDonService.getById(orderId);
  570. if (orderDon == null) {
  571. throw BusinessRuntimeException.getInstance("该订单不存在");
  572. }
  573. if (orderDon.getStatus() == OrderDon.Status.complete) {
  574. throw BusinessRuntimeException.getInstance("该订单已是已完成状态");
  575. }
  576. if (orderDon.getStatus() != OrderDon.Status.hasPayment) {
  577. throw BusinessRuntimeException.getInstance("该订单不是未支付状态");
  578. }
  579. orderDon.setStatus(OrderDon.Status.complete);
  580. cmsOrderDonService.updateById(orderDon);
  581. Long relationId = orderDon.getRelationId();
  582. Optional.ofNullable(relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
  583. .eq(GroupsRelation::getId, relationId)
  584. .eq(GroupsRelation::getUserId, orderDon.getUserId())
  585. .last("limit 1"))).ifPresent(relation->{
  586. GroupsRelation.RechargeStatus rechargeStatus = relation.getRechargeStatus();
  587. if (rechargeStatus != null && (rechargeStatus == GroupsRelation.RechargeStatus.waiting || rechargeStatus == GroupsRelation.RechargeStatus.recharge_error)) {
  588. relation.setRechargeStatus(GroupsRelation.RechargeStatus.complete);
  589. if (cmsUser != null) {
  590. relation.setOperator(cmsUser.getNickname());
  591. }
  592. relation.setSendTime(DateTime.now());
  593. //设置车票时间
  594. if (relation.getStartTime() == null) {
  595. relation.setStartTime(DateTime.now());
  596. GoodsDonSku sku = skuMapper.selectById(orderDon.getSkuId());
  597. DateTime expiryTime;
  598. if (sku.getDays() != null && sku.getDays() > 0) {
  599. expiryTime = DateUtil.offsetDay(relation.getStartTime(), sku.getDays());
  600. } else {
  601. expiryTime = DateUtil.offsetMonth(relation.getStartTime(), sku.getMonths());
  602. }
  603. relation.setExpiryTime(expiryTime);
  604. }
  605. relationMapper.updateById(relation);
  606. //GPT代充
  607. Integer subRechargeNum = 1;
  608. GoodsDonSku goodsDonSku = skuMapper.selectById(orderDon.getSkuId());
  609. if (goodsDonSku.getRechargeType() == 2) {
  610. subRechargeNum = 12;
  611. }
  612. //GPT代充
  613. if (orderDon.getGoodsId() == Constant.GPT_RECHARGE_GOODS_ID) {
  614. //扣除次数
  615. Integer rechargeRemainNum = relation.getRechargeRemainNum();
  616. if (rechargeRemainNum != null && rechargeRemainNum > 0) {
  617. int update = relationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
  618. .set(GroupsRelation::getRechargeRemainNum, rechargeRemainNum - subRechargeNum)
  619. .eq(GroupsRelation::getId, relationId)
  620. .eq(GroupsRelation::getRechargeRemainNum, rechargeRemainNum));
  621. if (update == 0) {
  622. throw BusinessRuntimeException.getInstance("更新用户代充剩余次数失败,请重试");
  623. }
  624. //记录gpt代充记录
  625. gptUserRechargeRecordService.recordGptUserRechargeNum(null, relation.getUserId(), relation.getId(), relation.getAccount(), -subRechargeNum, cmsUser != null ? cmsUser.getNickname() : null, "客服手动充值");
  626. }
  627. }
  628. }
  629. });
  630. return GatewayResponse.SUCCESS.newBuilder().toResult("修改订单状态成功");
  631. }
  632. /**
  633. * 修改购买意愿记录
  634. */
  635. @PutMapping("/put/interest")
  636. public Result<String> updateInterest(@RequestBody @Validated UserRealGoodsInterestReq req) {
  637. RealGoodsInterestUser realGoodsInterestUser = realGoodsInterestUserMapper.selectById(req.getId());
  638. if (realGoodsInterestUser != null) {
  639. if (req.getStatus() != null) {
  640. realGoodsInterestUser.setInterestStatus(req.getStatus());
  641. }
  642. if (req.getRemark() != null) {
  643. realGoodsInterestUser.setRemark(req.getRemark());
  644. }
  645. realGoodsInterestUserMapper.updateById(realGoodsInterestUser);
  646. }
  647. return GatewayResponse.SUCCESS.newBuilder().toResult("修改成功");
  648. }
  649. /**
  650. * 导出用户意愿列表
  651. */
  652. @GetMapping("/export/interest")
  653. public void exportInterest(RealGoodsInterestUser.Status interestStatus, HttpServletRequest request, HttpServletResponse response) {
  654. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  655. List<ExcelRealGoodsUserInterestData> excelRealGoodsUserInterestData;
  656. if (interestStatus == null) {
  657. builder.field(RealGoodsInterestUserView::getInterestStatus, "hasPayment").op(Operator.NotEqual);
  658. excelRealGoodsUserInterestData = beanSearcher.searchAll(ExcelRealGoodsUserInterestData.class, builder.build());
  659. } else {
  660. List<ExcelRealGoodsUserInterestHasPaymentData> excelRealGoodsUserInterestData2 = beanSearcher.searchAll(ExcelRealGoodsUserInterestHasPaymentData.class, builder.build());
  661. excelRealGoodsUserInterestData = new ArrayList<>(excelRealGoodsUserInterestData2);
  662. }
  663. excelRealGoodsUserInterestData.forEach(data -> {
  664. Long goodsId = data.getGoodsId();
  665. OrderDon order = cmsOrderDonService.getOne(Wrappers.lambdaQuery(OrderDon.class).eq(OrderDon::getUserId, data.getUserId()).eq(OrderDon::getGoodsId, goodsId).ne(OrderDon::getId, data.getId()).gt(OrderDon::getMoney, data.getMoney()).eq(OrderDon::getStatus, "close").last("limit 1"));
  666. if (order != null) {
  667. data.setOrderId(order.getId());
  668. data.setSkuId(order.getSkuId());
  669. data.setMoney(order.getMoney());
  670. realGoodsInterestUserMapper.updateData(data.getId(), data.getSkuId(), data.getOrderCreatedTime(), data.getOrderId());
  671. }
  672. data.setMoney(data.getMoney().divide(BigDecimal.valueOf(100)));
  673. });
  674. EasyExcelUtils.createExcelStreamMutilByEasyExcel(response, ExcelRealGoodsUserInterestHasPaymentData.class, excelRealGoodsUserInterestData, "用户意愿列表", "用户意愿列表", ExcelTypeEnum.XLSX, null);
  675. }
  676. /**
  677. * 实物订单配置售前售后客户
  678. */
  679. @PostMapping("/put/realGoods/service")
  680. @NoSubmit
  681. @Log(module = "订单管理/售前、售后客服", businessType = BusinessType.PUT, isSaveRequestData = true)
  682. public Result<String> putRealGoodsService(@RequestBody @Validated RealGoodsServiceReq request) {
  683. OrderDon orderDon = cmsOrderDonService.getById(request.getOrderId());
  684. if (orderDon == null || orderDon.getRelationId() != 0) {
  685. throw BusinessRuntimeException.getInstance("该订单不是实物订单");
  686. }
  687. Boolean isBefore = false;
  688. Boolean isAfter = false;
  689. RealGoodsOrderHandle realGoodsOrderHandle = Optional.ofNullable(realGoodsOrderHandleMapper.selectOne(Wrappers.lambdaQuery(RealGoodsOrderHandle.class).eq(RealGoodsOrderHandle::getOrderId, request.getOrderId()).last("limit 1"))).orElse(new RealGoodsOrderHandle());
  690. if (StringUtils.isNotBlank(request.getBeforeServiceName())) {
  691. realGoodsOrderHandle.setBeforeServiceName(request.getBeforeServiceName());
  692. isBefore = true;
  693. }
  694. if (StringUtils.isNotBlank(request.getAfterServiceName())) {
  695. realGoodsOrderHandle.setAfterServiceName(request.getAfterServiceName());
  696. isAfter = true;
  697. }
  698. if (realGoodsOrderHandle.getId() == null) {
  699. realGoodsOrderHandle.setOrderId(request.getOrderId());
  700. realGoodsOrderHandleMapper.insert(realGoodsOrderHandle);
  701. } else {
  702. if (realGoodsOrderHandle.getBeforeOpNum() > 2) {
  703. throw BusinessRuntimeException.getInstance("售前客服已两次修改");
  704. }
  705. if (realGoodsOrderHandle.getAfterOpNum() > 2) {
  706. throw BusinessRuntimeException.getInstance("售后客服已两次修改");
  707. }
  708. if (isBefore) {
  709. realGoodsOrderHandle.setBeforeOpNum(realGoodsOrderHandle.getBeforeOpNum() + 1);
  710. }
  711. if (isAfter) {
  712. realGoodsOrderHandle.setAfterOpNum(realGoodsOrderHandle.getAfterOpNum() + 1);
  713. }
  714. realGoodsOrderHandleMapper.updateById(realGoodsOrderHandle);
  715. }
  716. return GatewayResponse.SUCCESS.newBuilder().toResult("操作成功");
  717. }
  718. /**
  719. * 新增平台评论
  720. */
  721. @PostMapping("/post/orderComment")
  722. public Result<String> insertOrderComment(@RequestBody @Validated OrderComment orderComment) {
  723. if (StrUtil.isEmpty(orderComment.getHeadImgUrl())) {
  724. orderComment.setHeadImgUrl(Constant.DEFAULT_HEAD_IMG);
  725. }
  726. if (orderComment.getCommentTime() == null) {
  727. orderComment.setCommentTime(DateTime.now().toDateStr());
  728. }
  729. orderComment.setVerifyStatus(OrderComment.VerifyStatus.success);
  730. orderCommentMapper.insert(orderComment);
  731. return GatewayResponse.SUCCESS.newBuilder().toResult("新增成功");
  732. }
  733. /**
  734. * 编辑平台评论
  735. */
  736. @PutMapping("/put/orderComment")
  737. public Result<String> updateOrderComment(@RequestBody @Validated OrderComment orderComment) {
  738. if (orderComment.getCommentTime() == null) {
  739. orderComment.setCommentTime(DateTime.now().toDateStr());
  740. }
  741. if (orderComment.getVerifyStatus() == null) {
  742. orderComment.setVerifyStatus(OrderComment.VerifyStatus.success);
  743. }
  744. orderCommentMapper.updateById(orderComment);
  745. return GatewayResponse.SUCCESS.newBuilder().toResult("编辑成功");
  746. }
  747. /**
  748. * 删除平台评论
  749. */
  750. @DeleteMapping("/delete/orderComment/{id}")
  751. public Result<String> deleteOrderCommentById(@PathVariable Long id) {
  752. orderCommentMapper.deleteById(id);
  753. return GatewayResponse.SUCCESS.newBuilder().toResult("删除成功");
  754. }
  755. /**
  756. * 平台评论列表
  757. */
  758. @GetMapping("/get/orderComment")
  759. public Result<SearchResult<OrderCommentView>> getOrderCommentView() {
  760. SearchResult<OrderCommentView> search = beanSearcher.search(OrderCommentView.class, MapUtils.flatBuilder(request.getParameterMap()).build());
  761. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  762. }
  763. /**
  764. * 评论审核
  765. */
  766. @PutMapping("/put/orderComment/status")
  767. @NoSubmit
  768. public Result<String> updateOrderCommentStatus(@RequestBody OrderComment orderCommentReq) throws Exception {
  769. orderDonCommentService.verifyCommentStatus(orderCommentReq.getId(), orderCommentReq.getVerifyStatus());
  770. return GatewayResponse.SUCCESS.newBuilder().toResult();
  771. }
  772. /**
  773. * 配置订单平台评价列表
  774. */
  775. @PostMapping("/post/orderComment/reward/config")
  776. public Result<String> saveOrUpdateOrderCommentConfig(@RequestBody List<OrderCommentRewardConfig> configs) {
  777. orderDonCommentService.saveOrUpdateOrderCommentConfig(configs);
  778. return GatewayResponse.SUCCESS.newBuilder().toResult();
  779. }
  780. /**
  781. * 获取配置 订单平台评价
  782. */
  783. @GetMapping("/get/orderComment/reward/config")
  784. public Result<List<OrderCommentRewardConfigView>> getOrderCommentRewardConfig() {
  785. List<OrderCommentRewardConfigView> views = beanSearcher.searchAll(OrderCommentRewardConfigView.class, MapUtils.builder()
  786. .orderBy(OrderCommentRewardConfigView::getGoodsId).desc()
  787. .build());
  788. return GatewayResponse.SUCCESS.newBuilder().toResult(views);
  789. }
  790. /**
  791. * 踢出车队
  792. */
  793. @PutMapping("/kickOut")
  794. @NoSubmit
  795. public Result<String> kickOut(@RequestBody @Validated ClickOutReq req) {
  796. long adminId = StpUtil.getLoginIdAsLong();
  797. cmsOrderDonService.kickOutRelationId(adminId, req);
  798. return GatewayResponse.SUCCESS.newBuilder().toResult();
  799. }
  800. /**
  801. * 踢出车队列表
  802. */
  803. @GetMapping("/get/kickOut/list")
  804. public Result<SearchResult<UserKickOutView>> getKickOutList() {
  805. SearchResult<UserKickOutView> search = beanSearcher.search(UserKickOutView.class, MapUtils.flatBuilder(request.getParameterMap()).build());
  806. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  807. }
  808. /**
  809. * 客服修改订单来源
  810. */
  811. @PutMapping("/update/order/source")
  812. public Result<String> updateOrderSource(@RequestBody OrderDon orderDon) {
  813. Long id = orderDon.getId();
  814. String labelSource = orderDon.getLabelSource();
  815. cmsOrderDonService.update(null, Wrappers.lambdaUpdate(OrderDon.class)
  816. .set(OrderDon::getLabelSource, labelSource)
  817. .eq(OrderDon::getId, id));
  818. realGoodsOrderHandleMapper.update(null, Wrappers.lambdaUpdate(RealGoodsOrderHandle.class)
  819. .set(RealGoodsOrderHandle::getLabelSource, labelSource)
  820. .eq(RealGoodsOrderHandle::getOrderId, id));
  821. return GatewayResponse.SUCCESS.newBuilder().toResult();
  822. }
  823. /**
  824. * 设置实物订单电视机类型
  825. */
  826. @PutMapping("/update/order/tvType")
  827. public Result<String> updateOrderTvType(@RequestBody OrderDon orderDon) {
  828. Integer tvType = orderDon.getTvType();
  829. Long id = orderDon.getId();
  830. cmsOrderDonService.update(null, Wrappers.lambdaUpdate(OrderDon.class)
  831. .set(OrderDon::getTvType, tvType)
  832. .eq(OrderDon::getId, id));
  833. return GatewayResponse.SUCCESS.newBuilder().toResult();
  834. }
  835. /**
  836. * 订单统一退款
  837. */
  838. @PostMapping("/unified/refund")
  839. @Log(module = "订单管理/统一退款", businessType = BusinessType.PUT, isSaveRequestData = true)
  840. public Result<String> unifiedRefund(@RequestBody @Validated OrderRefundReq refundReq) throws Exception {
  841. long adminId = StpUtil.getLoginIdAsLong();
  842. CmsUser cmsUser = cmsUserMapper.selectById(adminId);
  843. if (cmsUser == null) {
  844. throw BusinessRuntimeException.getGatewayApiCode(GatewayApiCode.CMS_TOKEN_VALID);
  845. }
  846. refundReq.setOperator(cmsUser.getNickname());
  847. cmsOrderDonService.unifiedRefund(refundReq);
  848. return GatewayResponse.SUCCESS.newBuilder().toResult("退款成功");
  849. }
  850. /**
  851. * 微信退款回调
  852. */
  853. @PostMapping("/wx/refund/notify")
  854. public void wxRefundNotify(HttpServletRequest request, HttpServletResponse response) throws Exception {
  855. String xml = IoKit.toString(request.getInputStream());
  856. log.info("=== 退款成功的回调: \n {}", xml);
  857. // 解析xml
  858. Map<String, String> map = Xmls.toMap(xml);
  859. // 退款失败
  860. if (!StrUtil.equals("SUCCESS", map.get("return_code"))) {
  861. throw BusinessRuntimeException.getInstance("退款失败.");
  862. }
  863. cmsOrderDonService.wxRefundNotify(map);
  864. String toWechatXmlResponse = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
  865. OutputStream out = null;
  866. try {
  867. out = response.getOutputStream();
  868. IoKit.write(toWechatXmlResponse, out);
  869. } catch (Throwable e) {
  870. throw BusinessRuntimeException.getInstance(e == null ? null : e.getMessage());
  871. } finally {
  872. IoKit.close(out);
  873. }
  874. }
  875. /**
  876. * 更换用户车票
  877. */
  878. @PutMapping("/put/sameSpec/empty/relation")
  879. @Log(module = "更换用户车票", businessType = BusinessType.PUT, isSaveRequestData = true)
  880. public Result<String> changeRelation(@RequestBody @Validated ChangeRelationReq req) throws Exception {
  881. cmsOrderDonService.changeRelation(req);
  882. return GatewayResponse.SUCCESS.newBuilder().toResult();
  883. }
  884. /**
  885. * 多余车位的空账号
  886. */
  887. @GetMapping("/get/sameSpec/empty/relation")
  888. public Result<SearchResult<EmptyGroupsRelationView>> getSameSpecEmptyRelation(Long skuId, Long groupsId, Long relationId, Boolean isNormal) {
  889. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap())
  890. .field(EmptyGroupsRelationView::getStatus, GroupsTrips.Status.down.name()).op(Operator.NotEqual).field(EmptyGroupsRelationView::getSkuId, skuId);
  891. GoodsDonSku sku = skuMapper.selectById(skuId);
  892. if (sku.getGoodsId() == Constant.NETFLIX_GID) {
  893. builder.orderBy(EmptyGroupsRelationView::getCreatedTime).desc().orderBy(EmptyGroupsRelationView::getAvailableNum).desc();
  894. } else {
  895. builder.orderBy(EmptyGroupsRelationView::getAvailableNum).desc();
  896. }
  897. Date expiryTime = null;
  898. if (relationId != null) {
  899. GroupsRelation relation = relationMapper.selectById(relationId);
  900. if (relation != null) expiryTime = relation.getExpiryTime();
  901. }
  902. if (groupsId != null) {
  903. builder.field(EmptyGroupsRelationView::getGroupsId, groupsId).op(Operator.NotEqual);
  904. }
  905. String condition = StrUtil.EMPTY;
  906. if (isNormal != null && isNormal) {
  907. condition += String.format("gt.account_id not in (select account_id from work_order where sku_id = %s and account_id is not null)", skuId);
  908. }
  909. if (StrUtil.isNotEmpty(condition)) {
  910. condition += " and ";
  911. }
  912. Integer maxNum = sku.getNum();
  913. Integer extraNum = 5;
  914. //GPT 4人月付
  915. if (sku.getId() == 178l) {
  916. extraNum = 2;
  917. }
  918. maxNum += extraNum;
  919. condition += String.format("(available_parking_num = 0 or available_parking_num > (select count(*) from groups_relation gr where gr.groups_id = gt.id and gr.user_id != 0 and gr.num <= %s))", maxNum);
  920. if (StrUtil.isNotEmpty(condition)) {
  921. builder.put("condition", condition);
  922. }
  923. if (expiryTime != null) {
  924. builder.field(AccountView::getExpiryTime, expiryTime).op(Operator.GreaterEqual);
  925. builder.orderBy(AccountView::getExpiryTime).asc();
  926. }
  927. if (sku.getNum() == 1 || !Constant.AI_goodsIds.contains(sku.getGoodsId())) {
  928. builder.field(EmptyGroupsRelationView::getAvailableNum, 0).op(Operator.GreaterThan);
  929. }
  930. SearchResult<EmptyGroupsRelationView> search = beanSearcher.search(EmptyGroupsRelationView.class,
  931. builder.build());
  932. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  933. }
  934. /**
  935. * 订单补差价,补差价退款到余额
  936. */
  937. @PutMapping("/refund/price/differ")
  938. @Log(module = "订单管理/订单补差价", businessType = BusinessType.PUT, isSaveRequestData = true)
  939. public Result<String> refundPriceDiffer(@RequestBody OrderRefundReq orderRefundReq) throws Exception {
  940. long adminId = StpUtil.getLoginIdAsLong();
  941. CmsUser cmsUser = cmsUserMapper.selectById(adminId);
  942. if (cmsUser == null) {
  943. throw BusinessRuntimeException.getGatewayApiCode(GatewayApiCode.CMS_TOKEN_VALID);
  944. }
  945. orderRefundReq.setOperator(cmsUser.getNickname());
  946. cmsOrderDonService.refundPriceDiffer(orderRefundReq);
  947. return GatewayResponse.SUCCESS.newBuilder().toResult();
  948. }
  949. /**
  950. * 将余额清零 退款用户支付金额
  951. */
  952. @PutMapping("/clear/balance/refundMoney")
  953. @NoSubmit
  954. public Result<String> clearBalanceToRefundMoney(@RequestBody @Validated OrderBalanceRefundReq refundReq) throws Exception {
  955. cmsOrderDonService.clearBalanceToRefundMoney(refundReq);
  956. return GatewayResponse.SUCCESS.newBuilder().toResult();
  957. }
  958. /**
  959. * 客服退款每月数据
  960. */
  961. @GetMapping("/get/refundOrder/data")
  962. public Result<SearchResult<RefundOrderDonServiceDataView>> getRefundOrderData(String startTime, String endTime, String operator) {
  963. String time = StrUtil.EMPTY;
  964. if (StrUtil.isNotBlank(startTime)) {
  965. time += String.format(" and o.created_time >= '%s'", startTime);
  966. }
  967. if (StrUtil.isNotBlank(endTime)) {
  968. time += String.format(" and o.created_time < '%s'", endTime);
  969. }
  970. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  971. if (StrUtil.isNotBlank(time)) {
  972. builder.put("time", time);
  973. }
  974. if (StrUtil.isEmpty(operator)) {
  975. List<CmsUserVO> userVOS = beanSearcher.searchAll(CmsUserVO.class, MapUtils.builder().field(CmsUserVO::getRoleNames, "客服").op(Operator.Contain).build());
  976. List<String> collect = userVOS.stream().map(CmsUserVO::getNickname).collect(Collectors.toList());
  977. if (CollUtil.isNotEmpty(collect)) {
  978. builder.field(RefundOrderDonServiceDataView::getOperator, collect).op(Operator.InList);
  979. }
  980. }
  981. SearchResult<RefundOrderDonServiceDataView> search = beanSearcher.search(RefundOrderDonServiceDataView.class, builder.build());
  982. search.getDataList().forEach(e->{
  983. String goodsName = orderDonMapper.selectMaxRefundGoodsName(e.getOperator(), startTime, endTime);
  984. e.setGoodsName(goodsName);
  985. });
  986. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  987. }
  988. /**
  989. * 设置订单客服
  990. */
  991. @PutMapping("/set/service")
  992. public Result<String> setOrderCustomerService(@RequestBody OrderDonCustomerServiceRelate relate) {
  993. OrderDonCustomerServiceRelate orderDonCustomerServiceRelate = orderDonCustomerServiceRelateMapper.selectOne(Wrappers.lambdaQuery(OrderDonCustomerServiceRelate.class)
  994. .eq(OrderDonCustomerServiceRelate::getOrderId, relate.getOrderId()).last("limit 1"));
  995. if (orderDonCustomerServiceRelate != null) {
  996. relate.setId(orderDonCustomerServiceRelate.getId());
  997. }
  998. try {
  999. if (relate.getId() == null) {
  1000. orderDonCustomerServiceRelateMapper.insert(relate);
  1001. } else {
  1002. orderDonCustomerServiceRelateMapper.updateById(relate);
  1003. }
  1004. } catch (DuplicateKeyException e) {
  1005. }
  1006. return GatewayResponse.SUCCESS.newBuilder().toResult();
  1007. }
  1008. /**
  1009. * 查询套餐订单列表
  1010. */
  1011. @GetMapping("/upgrade/get")
  1012. @SaCheckPermission("upgradeOrder:view")
  1013. public Result<SearchResult<UpgradeOrderDonBackView>> getUpgradeOrder(String account, String showId, Long acId, String nickname, String register, Boolean isGoogle) {
  1014. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  1015. if (StrUtil.isNotBlank(account)) {
  1016. GroupsRelation relation = relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
  1017. .eq(GroupsRelation::getAccount, account).last("limit 1"));
  1018. if (relation != null) {
  1019. builder.field(OrderDonBackView::getRelationId, relation.getId());
  1020. } else {
  1021. builder.field(OrderDonBackView::getRelationId).op(Operator.IsNull);
  1022. }
  1023. }
  1024. if (StrUtil.isNotBlank(showId)) {
  1025. builder.field(OrderDonBackView::getUserId, userService.getUserIdByShowId(showId));
  1026. }
  1027. String conditionSql = StrUtil.EMPTY;
  1028. if (acId != null) {
  1029. conditionSql += String.format(" o.user_id in (select user_id from corp_user where ac_id = %s)", acId);
  1030. }
  1031. if (!ObjectUtil.isAllEmpty(nickname, register, isGoogle)) {
  1032. if (StrUtil.isNotEmpty(conditionSql)) {
  1033. conditionSql += " and ";
  1034. }
  1035. conditionSql += " exists (select u.id from user u where u.id = o.user_id";
  1036. if (StrUtil.isNotEmpty(nickname)) {
  1037. conditionSql += String.format(" and u.nickname like '%s%%'", nickname);
  1038. }
  1039. if (StrUtil.isNotEmpty(register)) {
  1040. if ("phone".equals(register)) {
  1041. conditionSql += " and u.login_phone != ''";
  1042. } else if ("email".equals(register)) {
  1043. conditionSql += " and u.email != ''";
  1044. } else if ("wechat".equals(register)) {
  1045. conditionSql += " and u.unionid != ''";
  1046. }
  1047. }
  1048. if (isGoogle != null && isGoogle) {
  1049. conditionSql += String.format(" and u.is_google is %s", isGoogle);
  1050. }
  1051. conditionSql += " limit 1)";
  1052. }
  1053. if (StrUtil.isNotBlank(conditionSql)) {
  1054. builder.put("condition", conditionSql);
  1055. }
  1056. SearchResult<UpgradeOrderDonBackView> search = beanSearcher.search(UpgradeOrderDonBackView.class, builder.build());
  1057. search.getDataList().forEach(data -> {
  1058. User user = userMapper.selectById(data.getUserId());
  1059. if (user != null) {
  1060. data.setNickname(user.getNickname());
  1061. data.setLoginPhone(user.getLoginPhone());
  1062. data.setEmail(user.getEmail());
  1063. data.setRegister(StrUtil.isNotEmpty(user.getUnionid()) ? "wechat" : StrUtil.isNotEmpty(user.getLoginPhone()) ? "phone" : "email");
  1064. }
  1065. });
  1066. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  1067. }
  1068. /**
  1069. * 套餐退款订单列表
  1070. */
  1071. @GetMapping("/get/upgrade/refund/list")
  1072. public Result<SearchResult<RefundUpdradeOrderDonView>> getRefundUpgradeOrderDonView(String nickname) {
  1073. List<Long> userIds = null;
  1074. if (StrUtil.isNotBlank(nickname)) {
  1075. userIds = userMapper.selectListByNickname(nickname);
  1076. if (CollUtil.isEmpty(userIds)) {
  1077. userIds.add(0l);
  1078. }
  1079. }
  1080. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  1081. if (CollUtil.isNotEmpty(userIds)) {
  1082. builder.field(RealGoodsInterestUserView::getUserId, userIds).op(Operator.InList);
  1083. }
  1084. SearchResult<RefundUpdradeOrderDonView> search = beanSearcher.search(RefundUpdradeOrderDonView.class,
  1085. builder.build());
  1086. search.getDataList().forEach(data -> {
  1087. Optional.ofNullable(userService.getById(data.getUserId()))
  1088. .ifPresent(user -> data.setNickname(user.getNickname()));
  1089. });
  1090. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  1091. }
  1092. /**
  1093. * 套餐订单导出
  1094. */
  1095. @GetMapping("/upgrade/export")
  1096. @SaCheckPermission("upgradeOrder:export")
  1097. @Log(module = "套餐订单管理/导出订单", businessType = BusinessType.EXPORT, isSaveRequestData = true)
  1098. public void exportUpgradeOrders(HttpServletResponse response) {
  1099. List<ExcelUpgradeOrderDonData> list = beanSearcher.searchAll(ExcelUpgradeOrderDonData.class, MapUtils.flatBuilder(request.getParameterMap()).build());
  1100. list.forEach(data -> {
  1101. data.setMoney(data.getMoney().divide(BigDecimal.valueOf(100)));
  1102. UpgradeOrderDon.Type type = data.getType();
  1103. data.setTypeStr(type != null ? type.getDesc() : "");
  1104. UpgradeOrderDon.Status status = data.getStatus();
  1105. data.setStatusStr(status != null ? status.getDesc() : "");
  1106. });
  1107. EasyExcelUtils.createExcelStreamMutilByEasyExcel(response, ExcelUpgradeOrderDonData.class, list, "订单列表", "订单列表", ExcelTypeEnum.XLSX, null);
  1108. }
  1109. /**
  1110. * 套餐订单统一退款
  1111. */
  1112. @PostMapping("/unified/upgrade/refund")
  1113. @Log(module = "套餐订单管理/统一退款", businessType = BusinessType.PUT, isSaveRequestData = true)
  1114. public Result<String> unifiedUpgradeRefund(@RequestBody @Validated OrderRefundReq refundReq) throws Exception {
  1115. long adminId = StpUtil.getLoginIdAsLong();
  1116. CmsUser cmsUser = cmsUserMapper.selectById(adminId);
  1117. if (cmsUser == null) {
  1118. throw BusinessRuntimeException.getGatewayApiCode(GatewayApiCode.CMS_TOKEN_VALID);
  1119. }
  1120. refundReq.setOperator(cmsUser.getNickname());
  1121. cmsOrderDonService.unifiedUpgradeRefund(refundReq);
  1122. return GatewayResponse.SUCCESS.newBuilder().toResult("退款成功");
  1123. }
  1124. /**
  1125. * midjourney查询订单用户账号剩余次数
  1126. */
  1127. @GetMapping("/get/midjourney/user")
  1128. public Result<MidjourneyUserDetailView> getMidjourneyUser(Long orderId) {
  1129. OrderDon orderDon = orderDonMapper.selectById(orderId);
  1130. //续费订单
  1131. Date startTime = null;
  1132. Date expiryTime = null;
  1133. if (orderDon.getOrderType() == 2) {
  1134. GoodsDonSku sku = skuMapper.selectById(orderDon.getSkuId());
  1135. GroupsRelation relation = relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
  1136. .eq(GroupsRelation::getId, orderDon.getRelationId())
  1137. .eq(GroupsRelation::getUserId, orderDon.getUserId()).last("limit 1"));
  1138. if (relation == null) {
  1139. return GatewayResponse.SUCCESS.newBuilder().toResult();
  1140. }
  1141. startTime = relation.getStartTime();
  1142. startTime = DateUtil.offsetMonth(startTime, sku.getMonths());
  1143. expiryTime = relation.getExpiryTime();
  1144. }
  1145. MidjourneyUser midjourneyUser = midjourneyUserMapper.selectOne(Wrappers.lambdaQuery(MidjourneyUser.class)
  1146. .eq(MidjourneyUser::getRelationId, orderDon.getRelationId())
  1147. .last("limit 1"));
  1148. if (midjourneyUser == null) {
  1149. return GatewayResponse.SUCCESS.newBuilder().toResult();
  1150. }
  1151. MidjourneyUserDetailView midjourneyUserDetailView = midjourneyUserConversationMapper.getMjMirrorOrderDetail(orderDon.getRelationId(), startTime, expiryTime);
  1152. GoodsDonSku sku = skuMapper.selectById(orderDon.getSkuId());
  1153. midjourneyUserDetailView.setUserId(orderDon.getUserId());
  1154. midjourneyUserDetailView.setExpiryTime(midjourneyUser.getExpireTime());
  1155. midjourneyUserDetailView.setMjFastNum(sku.getMjFastNum() - midjourneyUserDetailView.getUseFastNum());
  1156. if (sku.getMjRelaxNum() == null) {
  1157. midjourneyUserDetailView.setMjRelaxNum(null);
  1158. } else {
  1159. midjourneyUserDetailView.setMjRelaxNum(sku.getMjRelaxNum() - midjourneyUserDetailView.getUseRelaxNum());
  1160. }
  1161. return GatewayResponse.SUCCESS.newBuilder().toResult(midjourneyUserDetailView);
  1162. }
  1163. /**
  1164. * 用户退款详情
  1165. */
  1166. @GetMapping("/get/user/refund/detail")
  1167. public Result<OrderDonUserRefundDetailView> getUserRefundDetail(Long userId, Long orderId) {
  1168. if (userId == null || userId == 0) {
  1169. return GatewayResponse.SUCCESS.newBuilder().toResult();
  1170. }
  1171. List<Long> userIdList = null;
  1172. try {
  1173. userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  1174. } catch (Exception e) {
  1175. userIdList = List.of(userId);
  1176. }
  1177. String userIds = null;
  1178. if (CollUtil.isNotEmpty(userIdList)) {
  1179. userIds = userIdList.toString().replaceAll("\\[", "").replaceAll("]", "");
  1180. }
  1181. MapBuilder builder = MapUtils.builder();
  1182. if (StrUtil.isNotBlank(userIds)) {
  1183. builder.put("uid", String.format(" and user_id in (%s)", userIds));
  1184. } else {
  1185. builder.put("uid", String.format(" and user_id = %s", userId));
  1186. }
  1187. OrderDonUserRefundDetailView orderDonUserRefundDetailView = beanSearcher.searchFirst(OrderDonUserRefundDetailView.class, builder.build());
  1188. OrderDon orderDon = orderDonMapper.selectById(orderId);
  1189. if (orderDon != null && orderDon.getRelationId() != null && orderDon.getRelationId() > 0) {
  1190. GroupsRelation relation = relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class).eq(GroupsRelation::getId, orderDon.getRelationId()).in(GroupsRelation::getUserId, userIdList));
  1191. if (relation != null && relation.getExpiryTime() != null && relation.getExpiryTime().after(DateTime.now())) {
  1192. Long remainDays = DateUtil.betweenDay(DateTime.now(), relation.getExpiryTime(), false);
  1193. orderDonUserRefundDetailView.setRemainsDays(remainDays.intValue());
  1194. orderDonUserRefundDetailView.setCompensationDays(relation.getCompensationDays());
  1195. }
  1196. //是否是重复续费升级订单
  1197. if (orderDon.getOrderType() == 2) {
  1198. Integer selectCount = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class).eq(OrderDon::getRelationId, relation.getId()).in(OrderDon::getUserId, userIdList).eq(OrderDon::getOrderType, 2).notIn(OrderDon::getStatus, Constant.noOrderStatus));
  1199. orderDonUserRefundDetailView.setIsDupRenew(selectCount > 1);
  1200. }
  1201. }
  1202. return GatewayResponse.SUCCESS.newBuilder().toResult(orderDonUserRefundDetailView);
  1203. }
  1204. /**
  1205. * 用户订单列表
  1206. */
  1207. @GetMapping("/get/user/orders")
  1208. public Result<SearchResult<OrderDonUserRefundDetailView.OrderDonDetailView>> getUserOrdersDetail(Long userId) {
  1209. if (userId == null || userId == 0) {
  1210. return GatewayResponse.SUCCESS.newBuilder().toResult();
  1211. }
  1212. List<Long> userIdList = null;
  1213. try {
  1214. userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  1215. } catch (Exception e) {
  1216. }
  1217. if (userIdList == null) {
  1218. userIdList = new ArrayList<>();
  1219. userIdList.add(userId);
  1220. }
  1221. SearchResult<OrderDonUserRefundDetailView.OrderDonDetailView> search = beanSearcher.search(OrderDonUserRefundDetailView.OrderDonDetailView.class, MapUtils.flatBuilder(request.getParameterMap())
  1222. .field(OrderDonUserRefundDetailView.OrderDonDetailView::getUserId, userIdList).op(Operator.InList)
  1223. .build());
  1224. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  1225. }
  1226. /**
  1227. * 续费升级订单详情
  1228. */
  1229. @GetMapping("/renew/orders/detail")
  1230. public Result<RenewOriOrderSkuDto> getRenewOrdersDetail(Long orderId) {
  1231. OrderDon orderDon = orderDonMapper.selectById(orderId);
  1232. if (orderDon.getOrderType() == 2) {
  1233. OrderDonRenewRecord orderDonRenewRecord = orderDonRenewRecordMapper.selectOne(Wrappers.lambdaQuery(OrderDonRenewRecord.class)
  1234. .eq(OrderDonRenewRecord::getOrderId, orderDon.getId())
  1235. .last("limit 1"));
  1236. if (orderDonRenewRecord != null) {
  1237. GroupsRelation relation = relationMapper.selectById(orderDon.getRelationId());
  1238. if (relation != null) {
  1239. GoodsDonSku sku = skuMapper.selectById(orderDon.getSkuId());
  1240. Date expiryTime = relation.getExpiryTime();
  1241. DateTime lastExpiryTIme = DateUtil.offsetMonth(expiryTime, -sku.getMonths());
  1242. RenewOriOrderSkuDto renewOriOrderSkuDto = new RenewOriOrderSkuDto();
  1243. OriSkuDto oriSku = skuMapper.selectRenewOriSku(orderDonRenewRecord.getOriSkuId());
  1244. renewOriOrderSkuDto.setOriSku(oriSku);
  1245. renewOriOrderSkuDto.setLastExpiryTime(lastExpiryTIme);
  1246. ChatgptUser chatgptUser = chatgptUserMapper.selectOne(Wrappers.lambdaQuery(ChatgptUser.class)
  1247. .eq(ChatgptUser::getRelationId, orderDon.getRelationId())
  1248. .last("limit 1"));
  1249. if (chatgptUser != null) {
  1250. renewOriOrderSkuDto.setOrderId(chatgptUser.getRenewOrderId());
  1251. }
  1252. return GatewayResponse.SUCCESS.newBuilder().toResult(renewOriOrderSkuDto);
  1253. }
  1254. }
  1255. }
  1256. return GatewayResponse.SUCCESS.newBuilder().toResult();
  1257. }
  1258. public void setExportOrderInfo(List<ExcelOrderDonData> datas, CountDownLatch countDownLatch) {
  1259. datas.forEach(data -> {
  1260. data.setMoney(data.getMoney().divide(BigDecimal.valueOf(100)));
  1261. OrderDon.Type type = data.getType();
  1262. data.setTypeStr(type != null ? type.getDesc() : "");
  1263. OrderDon.Status status = data.getStatus();
  1264. data.setStatusStr(status != null ? status.getDesc() : "");
  1265. data.setChannel("自然流量渠道");
  1266. if (data.getPopularizeId() != null) {
  1267. Optional.ofNullable(channelPopularizeMapper.selectChannelByPid(data.getPopularizeId()))
  1268. .ifPresent(channelName -> data.setChannel(channelName));
  1269. }
  1270. User user = userMapper.selectById(data.getUserId());
  1271. if (user != null) {
  1272. data.setNickname(user.getNickname());
  1273. data.setRegister(StrUtil.isNotEmpty(user.getUnionid()) ? "wechat" : StrUtil.isNotEmpty(user.getLoginPhone()) ? "phone" : "email");
  1274. }
  1275. if (data.getGoodsDonType() != null && Constant.realGoodsType.contains(data.getGoodsDonType())) {
  1276. OrderDonTransportView transportView = beanSearcher.searchFirst(OrderDonTransportView.class, MapUtils.builder().field(OrderDonTransportView::getOrderId, data.getId()).build());
  1277. if (transportView != null) {
  1278. data.setTransportStr(String.format("%s%s%s%s", transportView.getProvince(), transportView.getCity(), transportView.getDistrict(), transportView.getAddress()));
  1279. data.setPhone(transportView.getPhone());
  1280. data.setReceiver(transportView.getReceiver());
  1281. data.setCodeCn(transportView.getCodeCn());
  1282. data.setTrackingNumber(transportView.getTrackingNumber());
  1283. }
  1284. RealGoodsOrderHandle realGoodsOrderHandle = realGoodsOrderHandleMapper.selectOne(Wrappers.lambdaQuery(RealGoodsOrderHandle.class).eq(RealGoodsOrderHandle::getOrderId, data.getId()).last("limit 1"));
  1285. if (realGoodsOrderHandle != null) {
  1286. data.setBeforeServiceName(realGoodsOrderHandle.getBeforeServiceName());
  1287. data.setAfterServiceName(realGoodsOrderHandle.getAfterServiceName());
  1288. }
  1289. }
  1290. //使用优惠码
  1291. if (data.getCouponId() != null) {
  1292. Optional.ofNullable(couponMapper.selectById(data.getCouponId())).ifPresent(coupon -> data.setCouponName(coupon.getName()));
  1293. data.setCouponMoney(data.getCouponMoney() == null ? BigDecimal.ZERO : data.getCouponMoney());
  1294. }
  1295. if (data.getCouponUserId() != 0) {
  1296. data.setCouponName(couponMapper.getCouponNameByCouponUserId(data.getCouponUserId()));
  1297. data.setCouponMoney(data.getCouponMoney() == null ? BigDecimal.ZERO : data.getCouponMoney());
  1298. }
  1299. //差价订单
  1300. if (data.getGoodsDonType() != null && data.getGoodsDonType() == 5) {
  1301. OrderDonDifferRelateView orderDonDifferRelateView = beanSearcher.searchFirst(OrderDonDifferRelateView.class, MapUtils.builder().field(OrderDonDifferRelateView::getOrderId, data.getId()).build());
  1302. if (orderDonDifferRelateView != null) {
  1303. data.setDiffInfo(orderDonDifferRelateView.getTitle() + "-" + orderDonDifferRelateView.getOperator());
  1304. }
  1305. }
  1306. });
  1307. countDownLatch.countDown();
  1308. }
  1309. /**
  1310. * 补差价可选平台
  1311. */
  1312. @GetMapping("/get/diff/goods")
  1313. public Result<List<OrderDonDifferGoods>> getDiffGoods() {
  1314. List<OrderDonDifferGoods> orderDonDifferGoods = beanSearcher.searchAll(OrderDonDifferGoods.class, MapUtils.flatBuilder(request.getParameterMap()).orderBy(OrderDonDifferGoods::getGoodsId).build());
  1315. return GatewayResponse.SUCCESS.newBuilder().toResult(orderDonDifferGoods);
  1316. }
  1317. /**
  1318. * 新增补差价平台
  1319. */
  1320. @PostMapping("/post/diff/goods")
  1321. public Result<String> insertDiffGoods(@RequestBody OrderDonDifferGoods orderDonDifferGoods) {
  1322. try {
  1323. orderDonDifferGoodsMapper.insert(orderDonDifferGoods);
  1324. } catch (DuplicateKeyException e) {
  1325. }
  1326. return GatewayResponse.SUCCESS.newBuilder().toResult();
  1327. }
  1328. /**
  1329. * 更新补差价订单关联信息
  1330. */
  1331. @PutMapping("/update/diff/info")
  1332. public Result<String> updateDiffOrderDonInfo(@RequestBody OrderDonDifferRelate relate) {
  1333. OrderDonDifferRelate orderDonDifferRelate = orderDonDifferRelateMapper.selectOne(Wrappers.lambdaQuery(OrderDonDifferRelate.class)
  1334. .eq(OrderDonDifferRelate::getOrderId, relate.getOrderId())
  1335. .last("limit 1"));
  1336. if (orderDonDifferRelate != null) {
  1337. relate.setId(orderDonDifferRelate.getId());
  1338. orderDonDifferRelateMapper.updateById(relate);
  1339. } else orderDonDifferRelateMapper.insert(relate);
  1340. return GatewayResponse.SUCCESS.newBuilder().toResult();
  1341. }
  1342. /**
  1343. * 用户加购订单车票列表
  1344. */
  1345. @GetMapping("/get/dp/relations")
  1346. public Result<List<GroupRelationDetailView>> getDpRelations(Long orderId) throws Exception {
  1347. OrderDon orderDon = orderDonMapper.selectById(orderId);
  1348. List relationIds = new ArrayList<>();
  1349. relationIds.add(orderDon.getRelationId());
  1350. OrderDiscountPlusPurchaseSkuRelation orderDiscountPlusPurchaseSkuRelation = plusPurchaseSkuRelationMapper.selectOne(Wrappers.lambdaQuery(OrderDiscountPlusPurchaseSkuRelation.class)
  1351. .eq(OrderDiscountPlusPurchaseSkuRelation::getOrderId, orderId)
  1352. .last("limit 1"));
  1353. if (orderDiscountPlusPurchaseSkuRelation != null && StrUtil.isNotBlank(orderDiscountPlusPurchaseSkuRelation.getRelationIds())) {
  1354. relationIds.addAll(Jsons.parseList(orderDiscountPlusPurchaseSkuRelation.getRelationIds(), Long.class));
  1355. }
  1356. List<GroupRelationDetailView> groupsRelationViews = beanSearcher.searchAll(GroupRelationDetailView.class, MapUtils.builder().field(GroupRelationDetailView::getUserId, orderDon.getUserId()).field(GroupRelationDetailView::getRelationId, relationIds).op(Operator.InList).build());
  1357. return GatewayResponse.SUCCESS.newBuilder().toResult(groupsRelationViews);
  1358. }
  1359. /**
  1360. * 查看车票账号密码记录
  1361. */
  1362. @GetMapping("/get/pwd/view/record")
  1363. public Result<SearchResult<TicketPwdViewRecord>> getPwdViewRecord(Long userId, Long relationId, String account) {
  1364. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  1365. SearchResult<TicketPwdViewRecord> search = beanSearcher.search(TicketPwdViewRecord.class, MapUtils.flatBuilder(request.getParameterMap())
  1366. .field(TicketPwdViewRecord::getUserId, userIdList).op(Operator.InList)
  1367. .field(TicketPwdViewRecord::getRelationId, relationId)
  1368. .field(TicketPwdViewRecord::getAccount, account)
  1369. .orderBy(TicketPwdViewRecord::getId).desc()
  1370. .build());
  1371. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  1372. }
  1373. /**
  1374. * 添加售后操作
  1375. */
  1376. @PostMapping("/afterSales/record")
  1377. public Result<String> recordAfterSales(@RequestBody OrderDonAfterSalesRecord salesRecord) {
  1378. long adminId = StpUtil.getLoginIdAsLong();
  1379. CmsUser cmsUser = cmsUserMapper.selectById(adminId);
  1380. salesRecord.setOperator(cmsUser.getNickname());
  1381. orderDonAfterSalesRecordMapper.insert(salesRecord);
  1382. return GatewayResponse.SUCCESS.newBuilder().toResult();
  1383. }
  1384. /**
  1385. * 订单售后操作列表
  1386. */
  1387. @GetMapping("/get/afterSales/record")
  1388. public Result<SearchResult<OrderDonAfterSalesRecord>> getRecordAfterSales() {
  1389. SearchResult<OrderDonAfterSalesRecord> search = beanSearcher.search(OrderDonAfterSalesRecord.class, MapUtils.flatBuilder(request.getParameterMap()).build());
  1390. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  1391. }
  1392. }