CmsOrderController.java 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061
  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.util.IoKit;
  17. import com.cyksj.common.util.Xmls;
  18. import com.cyksj.dto.Result;
  19. import com.cyksj.enums.BusinessType;
  20. import com.cyksj.enums.GatewayApiCode;
  21. import com.cyksj.enums.GatewayResponse;
  22. import com.cyksj.mapper.*;
  23. import com.cyksj.mapper.channel.ChannelPopularizeMapper;
  24. import com.cyksj.mapper.channel.UserPayEquipmentAvailableBenefitsMapper;
  25. import com.cyksj.mapper.channel.UserPayEquipmentReceiveBenefitsRecordMapper;
  26. import com.cyksj.mapper.manage.RealGoodsOrderHandleMapper;
  27. import com.cyksj.mapper.manage.cms.CmsUserMapper;
  28. import com.cyksj.mapper.manage.coupon.CouponMapper;
  29. import com.cyksj.mapper.shop.YhShopMapper;
  30. import com.cyksj.model.entity.*;
  31. import com.cyksj.model.excel.*;
  32. import com.cyksj.model.manage.request.ReqSetLogisticsPost;
  33. import com.cyksj.model.manage.views.AccountView;
  34. import com.cyksj.model.manage.views.OrderDonBackView;
  35. import com.cyksj.model.manage.views.UpgradeOrderDonBackView;
  36. import com.cyksj.model.request.*;
  37. import com.cyksj.model.views.*;
  38. import com.cyksj.service.mange.CmsOrderDonService;
  39. import com.cyksj.service.order.OrderDonCommentService;
  40. import com.cyksj.service.user.UserBindRelationService;
  41. import com.cyksj.service.user.UserService;
  42. import com.cyksj.web.util.EasyExcelUtils;
  43. import com.ejlchina.searcher.BeanSearcher;
  44. import com.ejlchina.searcher.SearchResult;
  45. import com.ejlchina.searcher.param.Operator;
  46. import com.ejlchina.searcher.util.MapBuilder;
  47. import com.ejlchina.searcher.util.MapUtils;
  48. import lombok.RequiredArgsConstructor;
  49. import lombok.extern.slf4j.Slf4j;
  50. import org.apache.commons.lang3.StringUtils;
  51. import org.springframework.dao.DuplicateKeyException;
  52. import org.springframework.validation.annotation.Validated;
  53. import org.springframework.web.bind.annotation.*;
  54. import javax.servlet.http.HttpServletRequest;
  55. import javax.servlet.http.HttpServletResponse;
  56. import java.io.IOException;
  57. import java.io.OutputStream;
  58. import java.math.BigDecimal;
  59. import java.util.*;
  60. import java.util.stream.Collectors;
  61. /**
  62. * @author chan
  63. * @date 2021/10/12 下午11:05
  64. */
  65. @Slf4j
  66. @RequestMapping("/manage/order")
  67. @RestController
  68. @RequiredArgsConstructor
  69. public class CmsOrderController {
  70. private final HttpServletRequest request;
  71. private final CmsOrderDonService cmsOrderDonService;
  72. private final UserService userService;
  73. private final BeanSearcher beanSearcher;
  74. private final RealGoodsInterestUserMapper realGoodsInterestUserMapper;
  75. private final RealGoodsOrderHandleMapper realGoodsOrderHandleMapper;
  76. private final CouponMapper couponMapper;
  77. private final OrderCommentMapper orderCommentMapper;
  78. private final OrderDonCommentService orderDonCommentService;
  79. private final GoodsDonSkuMapper skuMapper;
  80. private final ChannelPopularizeMapper channelPopularizeMapper;
  81. private final GroupsRelationMapper relationMapper;
  82. private final UserPayEquipmentReceiveBenefitsRecordMapper receiveBenefitsRecordMapper;
  83. private final UserPayEquipmentAvailableBenefitsMapper availableBenefitsMapper;
  84. private final YhShopMapper yhShopMapper;
  85. private final CmsUserMapper cmsUserMapper;
  86. private final UserMapper userMapper;
  87. private final OrderDonMapper orderDonMapper;
  88. private final OrderDonCustomerServiceRelateMapper orderDonCustomerServiceRelateMapper;
  89. private final MidjourneyUserConversationMapper midjourneyUserConversationMapper;
  90. private final MidjourneyUserMapper midjourneyUserMapper;
  91. private final UserBindRelationService userBindRelationService;
  92. @GetMapping("/get")
  93. @SaCheckPermission("order:view")
  94. public Result<SearchResult<OrderDonBackView>> get(Long channelId, String account, String showId, Long acId, String nickname, String register, Boolean isGoogle, Boolean isSubsidy) {
  95. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  96. if (channelId != null) {
  97. List<Long> popularizeIds = channelPopularizeMapper.getPopularizeIdByChannelId(channelId);
  98. builder.field(OrderDonBackView::getPopularizeId, popularizeIds).op(Operator.InList);
  99. }
  100. if (StrUtil.isNotBlank(account)) {
  101. GroupsRelation relation = relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
  102. .eq(GroupsRelation::getAccount, account).last("limit 1"));
  103. if (relation != null) {
  104. builder.field(OrderDonBackView::getRelationId, relation.getId());
  105. } else {
  106. builder.field(OrderDonBackView::getRelationId).op(Operator.IsNull);
  107. }
  108. }
  109. if (StrUtil.isNotBlank(showId)) {
  110. builder.field(OrderDonBackView::getUserId, userService.getUserIdByShowId(showId));
  111. }
  112. String conditionSql = StrUtil.EMPTY;
  113. if (acId != null) {
  114. conditionSql += String.format(" o.user_id in (select user_id from corp_user where ac_id = %s)", acId);
  115. }
  116. if (!ObjectUtil.isAllEmpty(nickname, register, isGoogle)) {
  117. if (StrUtil.isNotEmpty(conditionSql)) {
  118. conditionSql += " and ";
  119. }
  120. conditionSql += " exists (select u.id from user u where u.id = o.user_id";
  121. if (StrUtil.isNotEmpty(nickname)) {
  122. conditionSql += String.format(" and u.nickname like '%s%%'", nickname);
  123. }
  124. if (StrUtil.isNotEmpty(register)) {
  125. if ("phone".equals(register)) {
  126. conditionSql += " and u.login_phone != ''";
  127. } else if ("email".equals(register)) {
  128. conditionSql += " and u.email != ''";
  129. } else if ("wechat".equals(register)) {
  130. conditionSql += " and u.unionid != ''";
  131. }
  132. }
  133. if (isGoogle != null && isGoogle) {
  134. conditionSql += String.format(" and u.is_google is %s", isGoogle);
  135. }
  136. conditionSql += " limit 1)";
  137. }
  138. if (isSubsidy != null) {
  139. if (StrUtil.isNotEmpty(conditionSql)) {
  140. conditionSql += " and ";
  141. }
  142. conditionSql += " exists (select 1 from order_don_subsidy_relate ocr where ocr.order_id = o.id limit 1)";
  143. }
  144. if (StrUtil.isNotBlank(conditionSql)) {
  145. builder.put("condition", conditionSql);
  146. }
  147. SearchResult<OrderDonBackView> search = beanSearcher.search(OrderDonBackView.class, builder.build());
  148. search.getDataList().forEach(data -> {
  149. if (data.getPopularizeId() != null) {
  150. Optional.ofNullable(channelPopularizeMapper.selectChannelByPid(data.getPopularizeId()))
  151. .ifPresent(channelName -> data.setChannel(channelName));
  152. }
  153. if (data.getGoodsDonType() != null && Constant.realGoodsType.contains(data.getGoodsDonType())) {
  154. RealGoodsOrderHandle realGoodsOrderHandle = realGoodsOrderHandleMapper.selectOne(Wrappers.lambdaQuery(RealGoodsOrderHandle.class).eq(RealGoodsOrderHandle::getOrderId, data.getId()).last("limit 1"));
  155. if (realGoodsOrderHandle != null) {
  156. data.setBeforeServiceName(realGoodsOrderHandle.getBeforeServiceName());
  157. data.setAfterServiceName(realGoodsOrderHandle.getAfterServiceName());
  158. }
  159. }
  160. if (data.getCouponUserId() != 0) {
  161. data.setCouponName(couponMapper.getCouponNameByCouponUserId(data.getCouponUserId()));
  162. data.setCouponMoney(data.getCouponMoney() == null ? BigDecimal.ZERO : data.getCouponMoney());
  163. }
  164. if (data.getRelationId() != 0) {
  165. Optional.ofNullable(relationMapper.getGroupRelationAccountView(data.getRelationId()))
  166. .ifPresent(e -> {
  167. data.setGtAccount(e.getTripsAccount());
  168. data.setAccount(e.getAccount());
  169. });
  170. }
  171. if (data.getIsBenefits() != null && data.getIsBenefits() && !Constant.noOrderAllStatus.contains(data.getStatus())) {
  172. //是否实物权益已发放
  173. Integer count = receiveBenefitsRecordMapper.selectCount(Wrappers.lambdaQuery(UserPayEquipmentReceiveBenefitsRecord.class)
  174. .eq(UserPayEquipmentReceiveBenefitsRecord::getRealOrderId, data.getId()));
  175. if (count == 0) {
  176. count = availableBenefitsMapper.selectCount(Wrappers.lambdaQuery(UserPayEquipmentAvailableBenefits.class)
  177. .eq(UserPayEquipmentAvailableBenefits::getRealOrderId, data.getId()));
  178. }
  179. data.setIsHasBenefits(count == 0 ? true : false);
  180. }
  181. if (data.getYhsId() != 0) {
  182. Optional.ofNullable(yhShopMapper.selectById(data.getYhsId()))
  183. .ifPresent(e -> {
  184. data.setShopName(e.getName());
  185. data.setCustomId(e.getCustomId());
  186. });
  187. }
  188. User user = userMapper.selectById(data.getUserId());
  189. if (user != null) {
  190. data.setNickname(user.getNickname());
  191. data.setLoginPhone(user.getLoginPhone());
  192. data.setEmail(user.getEmail());
  193. data.setRegister(StrUtil.isNotEmpty(user.getUnionid()) ? "wechat" : StrUtil.isNotEmpty(user.getLoginPhone()) ? "phone" : "email");
  194. }
  195. if (data.getGoodsDonType() != null && data.getGoodsDonType() == 1) {
  196. //获取订单关联客服
  197. Optional.ofNullable(orderDonMapper.selectOrderRelate(data.getId())).ifPresent(e -> {
  198. data.setCmsUserId(e.getCmsUserId());
  199. data.setNickname(e.getNickname());
  200. });
  201. }
  202. });
  203. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  204. }
  205. /**
  206. * 用户退款订单列表
  207. */
  208. @GetMapping("/get/refund/list")
  209. public Result<SearchResult<RefundOrderDonView>> getRefundOrderDonView() {
  210. SearchResult<RefundOrderDonView> search = beanSearcher.search(RefundOrderDonView.class, MapUtils.flatBuilder(request.getParameterMap())
  211. .build());
  212. search.getDataList().forEach(data -> {
  213. Optional.ofNullable(userService.getById(data.getUserId()))
  214. .ifPresent(user -> data.setNickname(user.getNickname()));
  215. });
  216. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  217. }
  218. /**
  219. * 镜像规格使用详情
  220. */
  221. @GetMapping("/get/order/mj/mirror/detail/{orderId}")
  222. public Result<MidjourneyUserDetailView> getMjMirrorOrderDetail(@PathVariable Long orderId) {
  223. OrderDon orderDon = orderDonMapper.selectById(orderId);
  224. //续费订单
  225. Date startTime = null;
  226. Date expiryTime = null;
  227. if (orderDon.getOrderType() == 2) {
  228. GoodsDonSku sku = skuMapper.selectById(orderDon.getSkuId());
  229. GroupsRelation relation = relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
  230. .eq(GroupsRelation::getId, orderDon.getRelationId())
  231. .eq(GroupsRelation::getUserId, orderDon.getUserId()).last("limit 1"));
  232. if (relation == null) {
  233. return GatewayResponse.SUCCESS.newBuilder().toResult();
  234. }
  235. startTime = relation.getStartTime();
  236. startTime = DateUtil.offsetMonth(startTime, sku.getMonths());
  237. expiryTime = relation.getExpiryTime();
  238. }
  239. MidjourneyUserDetailView midjourneyUserDetailView = midjourneyUserConversationMapper.getMjMirrorOrderDetail(orderDon.getRelationId(), startTime, expiryTime);
  240. return GatewayResponse.SUCCESS.newBuilder().toResult(midjourneyUserDetailView);
  241. }
  242. /**
  243. * 订单导出
  244. */
  245. @GetMapping("/export")
  246. @SaCheckPermission("order:export")
  247. @Log(module = "订单管理/导出订单", businessType = BusinessType.EXPORT, isSaveRequestData = true)
  248. public void exportOrders(HttpServletResponse response) {
  249. List<ExcelOrderDonData> list = beanSearcher.searchAll(ExcelOrderDonData.class, MapUtils.flatBuilder(request.getParameterMap()).build());
  250. list.forEach(data -> {
  251. data.setMoney(data.getMoney().divide(BigDecimal.valueOf(100)));
  252. OrderDon.Type type = data.getType();
  253. data.setTypeStr(type != null ? type.getDesc() : "");
  254. OrderDon.Status status = data.getStatus();
  255. data.setStatusStr(status != null ? status.getDesc() : "");
  256. if (data.getChannelId() == null) {
  257. data.setChannel("自然流量渠道");
  258. }
  259. if (data.getGoodsDonType() != null && Constant.realGoodsType.contains(data.getGoodsDonType())) {
  260. OrderDonTransportView transportView = beanSearcher.searchFirst(OrderDonTransportView.class, MapUtils.builder().field(OrderDonTransportView::getOrderId, data.getId()).build());
  261. if (transportView != null) {
  262. data.setTransportStr(String.format("%s%s%s%s", transportView.getProvince(), transportView.getCity(), transportView.getDistrict(), transportView.getAddress()));
  263. data.setPhone(transportView.getPhone());
  264. data.setReceiver(transportView.getReceiver());
  265. data.setCodeCn(transportView.getCodeCn());
  266. data.setTrackingNumber(transportView.getTrackingNumber());
  267. }
  268. RealGoodsOrderHandle realGoodsOrderHandle = realGoodsOrderHandleMapper.selectOne(Wrappers.lambdaQuery(RealGoodsOrderHandle.class).eq(RealGoodsOrderHandle::getOrderId, data.getId()).last("limit 1"));
  269. if (realGoodsOrderHandle != null) {
  270. data.setBeforeServiceName(realGoodsOrderHandle.getBeforeServiceName());
  271. data.setAfterServiceName(realGoodsOrderHandle.getAfterServiceName());
  272. }
  273. }
  274. if (data.getCouponUserId() != 0) {
  275. data.setCouponName(couponMapper.getCouponNameByCouponUserId(data.getCouponUserId()));
  276. data.setCouponMoney(data.getCouponMoney() == null ? BigDecimal.ZERO : data.getCouponMoney().divide(BigDecimal.valueOf(100)));
  277. }
  278. });
  279. EasyExcelUtils.createExcelStreamMutilByEasyExcel(response, ExcelOrderDonData.class, list, "订单列表", "订单列表", ExcelTypeEnum.XLSX, null);
  280. }
  281. /**
  282. * 导出实物模板 订单excel
  283. */
  284. @GetMapping("/export/realGoods")
  285. public void exportRealGoods(HttpServletResponse response) throws IOException {
  286. List<ExcelRealGoodsOrderData> list = beanSearcher.searchAll(ExcelRealGoodsOrderData.class, MapUtils.flatBuilder(request.getParameterMap())
  287. .field(ExcelOrderDonData::getGoodsDonType, Constant.realGoodsType).op(Operator.InList)
  288. .build());
  289. // AtomicInteger index = new AtomicInteger(1);
  290. list.forEach(data -> {
  291. data.setPayType("寄付现结");
  292. if (data.getGoodsDonType() == Constant.realGoodsType.get(0)) {
  293. data.setRealGoodName("路由器");
  294. } else if (data.getGoodsDonType() == Constant.realGoodsType.get(1)) {
  295. data.setRealGoodName("银河潮玩");
  296. }
  297. // data.setIndex(index.getAndIncrement());
  298. });
  299. if (CollUtil.isEmpty(list)) {
  300. throw BusinessRuntimeException.getInstance("导出数据为空");
  301. }
  302. response.setContentType("application/x-download");
  303. response.setContentType("application/vnd.ms-excel");
  304. response.setCharacterEncoding("utf-8");
  305. response.setHeader("Content-disposition",
  306. "attachment;filename=" + new String("实物订单列表".getBytes("utf-8"), "ISO-8859-1") + ExcelTypeEnum.XLS.getValue());
  307. EasyExcel.write(response.getOutputStream())
  308. .head(ExcelRealGoodsOrderData.class)
  309. //设置合并单元格策略
  310. // .registerWriteHandler(new RealGoodsOrderLineStrategy())
  311. .excelType(ExcelTypeEnum.XLS)
  312. .sheet("实物订单列表")
  313. //设置头部标题从那行开始
  314. // .relativeHeadRowIndex(2)
  315. .doWrite(list);
  316. }
  317. @PutMapping("/update/status")
  318. public Result<String> upStatus(@RequestBody OrderDon orderDon){
  319. cmsOrderDonService.update(Wrappers.lambdaUpdate(OrderDon.class).eq(OrderDon::getId,orderDon.getId()).set(OrderDon::getStatus,orderDon.getStatus()));
  320. return GatewayResponse.SUCCESS.newBuilder().toResult();
  321. }
  322. /**
  323. * 编辑自定义订阅节点
  324. */
  325. @PutMapping("/update/subNode")
  326. public Result<String> updateSubNode(@RequestBody OrderDon orderDon) {
  327. OrderDon en = cmsOrderDonService.getById(orderDon.getId());
  328. if (en != null) {
  329. en.setSubNode(orderDon.getSubNode());
  330. cmsOrderDonService.updateById(en);
  331. }
  332. return GatewayResponse.SUCCESS.newBuilder().toResult();
  333. }
  334. @GetMapping("/get/transport/{orderId}")
  335. public Result<OrderDonTransportView> getTransport(@PathVariable Long orderId){
  336. // OrderDonTransport transport = cmsOrderDonService.getTransport(orderId);
  337. OrderDonTransportView transportView = beanSearcher.searchFirst(OrderDonTransportView.class, MapUtils.builder().field(OrderDonTransportView::getOrderId, orderId).build());
  338. return GatewayResponse.SUCCESS.newBuilder().toResult(transportView);
  339. }
  340. @PostMapping("/post/setWaybill")
  341. public Result<OrderDonWaybill> setWaybill(@RequestBody ReqSetLogisticsPost reqSetLogisticsPost){
  342. OrderDonWaybill orderDonWaybill = cmsOrderDonService.setWaybill(reqSetLogisticsPost);
  343. return GatewayResponse.SUCCESS.newBuilder().toResult(orderDonWaybill);
  344. }
  345. /**
  346. * 用户购买实物商品意愿列表
  347. */
  348. @GetMapping("/get/realGooods/interest/users")
  349. @SaCheckPermission("interest:view")
  350. public Result<SearchResult> getInterestUserList(RealGoodsInterestUser.Status interestStatus, HttpServletRequest request) {
  351. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  352. SearchResult<RealGoodsInterestUserView> search;
  353. if (interestStatus == null) {
  354. builder.field(RealGoodsInterestUserView::getInterestStatus, "hasPayment").op(Operator.NotEqual);
  355. search = beanSearcher.search(RealGoodsInterestUserView.class, builder.build());
  356. } else if (interestStatus != RealGoodsInterestUser.Status.hasPayment) {
  357. builder.field(RealGoodsInterestUserView::getInterestStatus, interestStatus.name());
  358. search = beanSearcher.search(RealGoodsInterestUserView.class, builder.build());
  359. } else {
  360. search = new SearchResult<>();
  361. SearchResult<RealGoodsInterestUserHasPaymentView> search2 = beanSearcher.search(RealGoodsInterestUserHasPaymentView.class, builder.build());
  362. search.setTotalCount(search2.getTotalCount());
  363. List<RealGoodsInterestUserView> dataList = search.getDataList();
  364. dataList.addAll(search2.getDataList());
  365. }
  366. search.getDataList().forEach(data -> {
  367. Long goodsId = data.getGoodsId();
  368. 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"));
  369. if (order != null) {
  370. data.setOrderId(order.getId());
  371. data.setSkuId(order.getSkuId());
  372. data.setMoney(order.getMoney());
  373. realGoodsInterestUserMapper.updateData(data.getId(), data.getSkuId(), data.getOrderCreatedTime(), data.getOrderId());
  374. }
  375. });
  376. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  377. }
  378. /**
  379. * 修改订单状态
  380. */
  381. @PutMapping("/put/status/{orderId}")
  382. public Result<String> updateOrderStatus(@PathVariable Long orderId) {
  383. OrderDon orderDon = cmsOrderDonService.getById(orderId);
  384. if (orderDon == null) {
  385. throw BusinessRuntimeException.getInstance("该订单不存在");
  386. }
  387. if (orderDon.getStatus() == OrderDon.Status.complete) {
  388. throw BusinessRuntimeException.getInstance("该订单已是已完成状态");
  389. }
  390. if (orderDon.getStatus() != OrderDon.Status.hasPayment) {
  391. throw BusinessRuntimeException.getInstance("该订单不是未支付状态");
  392. }
  393. orderDon.setStatus(OrderDon.Status.complete);
  394. cmsOrderDonService.updateById(orderDon);
  395. return GatewayResponse.SUCCESS.newBuilder().toResult("修改订单状态成功");
  396. }
  397. /**
  398. * 修改购买意愿记录
  399. */
  400. @PutMapping("/put/interest")
  401. public Result<String> updateInterest(@RequestBody @Validated UserRealGoodsInterestReq req) {
  402. RealGoodsInterestUser realGoodsInterestUser = realGoodsInterestUserMapper.selectById(req.getId());
  403. if (realGoodsInterestUser != null) {
  404. if (req.getStatus() != null) {
  405. realGoodsInterestUser.setInterestStatus(req.getStatus());
  406. }
  407. if (req.getRemark() != null) {
  408. realGoodsInterestUser.setRemark(req.getRemark());
  409. }
  410. realGoodsInterestUserMapper.updateById(realGoodsInterestUser);
  411. }
  412. return GatewayResponse.SUCCESS.newBuilder().toResult("修改成功");
  413. }
  414. /**
  415. * 导出用户意愿列表
  416. */
  417. @GetMapping("/export/interest")
  418. public void exportInterest(RealGoodsInterestUser.Status interestStatus, HttpServletRequest request, HttpServletResponse response) {
  419. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  420. List<ExcelRealGoodsUserInterestData> excelRealGoodsUserInterestData;
  421. if (interestStatus == null) {
  422. builder.field(RealGoodsInterestUserView::getInterestStatus, "hasPayment").op(Operator.NotEqual);
  423. excelRealGoodsUserInterestData = beanSearcher.searchAll(ExcelRealGoodsUserInterestData.class, builder.build());
  424. } else {
  425. List<ExcelRealGoodsUserInterestHasPaymentData> excelRealGoodsUserInterestData2 = beanSearcher.searchAll(ExcelRealGoodsUserInterestHasPaymentData.class, builder.build());
  426. excelRealGoodsUserInterestData = new ArrayList<>(excelRealGoodsUserInterestData2);
  427. }
  428. excelRealGoodsUserInterestData.forEach(data -> {
  429. Long goodsId = data.getGoodsId();
  430. 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"));
  431. if (order != null) {
  432. data.setOrderId(order.getId());
  433. data.setSkuId(order.getSkuId());
  434. data.setMoney(order.getMoney());
  435. realGoodsInterestUserMapper.updateData(data.getId(), data.getSkuId(), data.getOrderCreatedTime(), data.getOrderId());
  436. }
  437. data.setMoney(data.getMoney().divide(BigDecimal.valueOf(100)));
  438. });
  439. EasyExcelUtils.createExcelStreamMutilByEasyExcel(response, ExcelRealGoodsUserInterestHasPaymentData.class, excelRealGoodsUserInterestData, "用户意愿列表", "用户意愿列表", ExcelTypeEnum.XLSX, null);
  440. }
  441. /**
  442. * 实物订单配置售前售后客户
  443. */
  444. @PostMapping("/put/realGoods/service")
  445. @NoSubmit
  446. @Log(module = "订单管理/售前、售后客服", businessType = BusinessType.PUT, isSaveRequestData = true)
  447. public Result<String> putRealGoodsService(@RequestBody @Validated RealGoodsServiceReq request) {
  448. OrderDon orderDon = cmsOrderDonService.getById(request.getOrderId());
  449. if (orderDon == null || orderDon.getRelationId() != 0) {
  450. throw BusinessRuntimeException.getInstance("该订单不是实物订单");
  451. }
  452. Boolean isBefore = false;
  453. Boolean isAfter = false;
  454. RealGoodsOrderHandle realGoodsOrderHandle = Optional.ofNullable(realGoodsOrderHandleMapper.selectOne(Wrappers.lambdaQuery(RealGoodsOrderHandle.class).eq(RealGoodsOrderHandle::getOrderId, request.getOrderId()).last("limit 1"))).orElse(new RealGoodsOrderHandle());
  455. if (StringUtils.isNotBlank(request.getBeforeServiceName())) {
  456. realGoodsOrderHandle.setBeforeServiceName(request.getBeforeServiceName());
  457. isBefore = true;
  458. }
  459. if (StringUtils.isNotBlank(request.getAfterServiceName())) {
  460. realGoodsOrderHandle.setAfterServiceName(request.getAfterServiceName());
  461. isAfter = true;
  462. }
  463. if (realGoodsOrderHandle.getId() == null) {
  464. realGoodsOrderHandle.setOrderId(request.getOrderId());
  465. realGoodsOrderHandleMapper.insert(realGoodsOrderHandle);
  466. } else {
  467. if (realGoodsOrderHandle.getBeforeOpNum() > 2) {
  468. throw BusinessRuntimeException.getInstance("售前客服已两次修改");
  469. }
  470. if (realGoodsOrderHandle.getAfterOpNum() > 2) {
  471. throw BusinessRuntimeException.getInstance("售后客服已两次修改");
  472. }
  473. if (isBefore) {
  474. realGoodsOrderHandle.setBeforeOpNum(realGoodsOrderHandle.getBeforeOpNum() + 1);
  475. }
  476. if (isAfter) {
  477. realGoodsOrderHandle.setAfterOpNum(realGoodsOrderHandle.getAfterOpNum() + 1);
  478. }
  479. realGoodsOrderHandleMapper.updateById(realGoodsOrderHandle);
  480. }
  481. return GatewayResponse.SUCCESS.newBuilder().toResult("操作成功");
  482. }
  483. /**
  484. * 新增平台评论
  485. */
  486. @PostMapping("/post/orderComment")
  487. public Result<String> insertOrderComment(@RequestBody @Validated OrderComment orderComment) {
  488. if (StrUtil.isEmpty(orderComment.getHeadImgUrl())) {
  489. orderComment.setHeadImgUrl(Constant.DEFAULT_HEAD_IMG);
  490. }
  491. if (orderComment.getCommentTime() == null) {
  492. orderComment.setCommentTime(DateTime.now().toDateStr());
  493. }
  494. orderComment.setVerifyStatus(OrderComment.VerifyStatus.success);
  495. orderCommentMapper.insert(orderComment);
  496. return GatewayResponse.SUCCESS.newBuilder().toResult("新增成功");
  497. }
  498. /**
  499. * 编辑平台评论
  500. */
  501. @PutMapping("/put/orderComment")
  502. public Result<String> updateOrderComment(@RequestBody @Validated OrderComment orderComment) {
  503. if (orderComment.getCommentTime() == null) {
  504. orderComment.setCommentTime(DateTime.now().toDateStr());
  505. }
  506. if (orderComment.getVerifyStatus() == null) {
  507. orderComment.setVerifyStatus(OrderComment.VerifyStatus.success);
  508. }
  509. orderCommentMapper.updateById(orderComment);
  510. return GatewayResponse.SUCCESS.newBuilder().toResult("编辑成功");
  511. }
  512. /**
  513. * 删除平台评论
  514. */
  515. @DeleteMapping("/delete/orderComment/{id}")
  516. public Result<String> deleteOrderCommentById(@PathVariable Long id) {
  517. orderCommentMapper.deleteById(id);
  518. return GatewayResponse.SUCCESS.newBuilder().toResult("删除成功");
  519. }
  520. /**
  521. * 平台评论列表
  522. */
  523. @GetMapping("/get/orderComment")
  524. public Result<SearchResult<OrderCommentView>> getOrderCommentView() {
  525. SearchResult<OrderCommentView> search = beanSearcher.search(OrderCommentView.class, MapUtils.flatBuilder(request.getParameterMap()).build());
  526. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  527. }
  528. /**
  529. * 评论审核
  530. */
  531. @PutMapping("/put/orderComment/status")
  532. @NoSubmit
  533. public Result<String> updateOrderCommentStatus(@RequestBody OrderComment orderCommentReq) throws Exception {
  534. orderDonCommentService.verifyCommentStatus(orderCommentReq.getId(), orderCommentReq.getVerifyStatus());
  535. return GatewayResponse.SUCCESS.newBuilder().toResult();
  536. }
  537. /**
  538. * 配置订单平台评价列表
  539. */
  540. @PostMapping("/post/orderComment/reward/config")
  541. public Result<String> saveOrUpdateOrderCommentConfig(@RequestBody List<OrderCommentRewardConfig> configs) {
  542. orderDonCommentService.saveOrUpdateOrderCommentConfig(configs);
  543. return GatewayResponse.SUCCESS.newBuilder().toResult();
  544. }
  545. /**
  546. * 获取配置 订单平台评价
  547. */
  548. @GetMapping("/get/orderComment/reward/config")
  549. public Result<List<OrderCommentRewardConfigView>> getOrderCommentRewardConfig() {
  550. List<OrderCommentRewardConfigView> views = beanSearcher.searchAll(OrderCommentRewardConfigView.class, MapUtils.builder()
  551. .orderBy(OrderCommentRewardConfigView::getGoodsId).desc()
  552. .build());
  553. return GatewayResponse.SUCCESS.newBuilder().toResult(views);
  554. }
  555. /**
  556. * 踢出车队
  557. */
  558. @PutMapping("/kickOut")
  559. @NoSubmit
  560. public Result<String> kickOut(@RequestBody @Validated ClickOutReq req) {
  561. long adminId = StpUtil.getLoginIdAsLong();
  562. cmsOrderDonService.kickOutRelationId(adminId, req);
  563. return GatewayResponse.SUCCESS.newBuilder().toResult();
  564. }
  565. /**
  566. * 踢出车队列表
  567. */
  568. @GetMapping("/get/kickOut/list")
  569. public Result<SearchResult<UserKickOutView>> getKickOutList() {
  570. SearchResult<UserKickOutView> search = beanSearcher.search(UserKickOutView.class, MapUtils.flatBuilder(request.getParameterMap()).build());
  571. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  572. }
  573. /**
  574. * 客服修改订单来源
  575. */
  576. @PutMapping("/update/order/source")
  577. public Result<String> updateOrderSource(@RequestBody OrderDon orderDon) {
  578. Long id = orderDon.getId();
  579. String labelSource = orderDon.getLabelSource();
  580. cmsOrderDonService.update(null, Wrappers.lambdaUpdate(OrderDon.class)
  581. .set(OrderDon::getLabelSource, labelSource)
  582. .eq(OrderDon::getId, id));
  583. realGoodsOrderHandleMapper.update(null, Wrappers.lambdaUpdate(RealGoodsOrderHandle.class)
  584. .set(RealGoodsOrderHandle::getLabelSource, labelSource)
  585. .eq(RealGoodsOrderHandle::getOrderId, id));
  586. return GatewayResponse.SUCCESS.newBuilder().toResult();
  587. }
  588. /**
  589. * 设置实物订单电视机类型
  590. */
  591. @PutMapping("/update/order/tvType")
  592. public Result<String> updateOrderTvType(@RequestBody OrderDon orderDon) {
  593. Integer tvType = orderDon.getTvType();
  594. Long id = orderDon.getId();
  595. cmsOrderDonService.update(null, Wrappers.lambdaUpdate(OrderDon.class)
  596. .set(OrderDon::getTvType, tvType)
  597. .eq(OrderDon::getId, id));
  598. return GatewayResponse.SUCCESS.newBuilder().toResult();
  599. }
  600. /**
  601. * 订单统一退款
  602. */
  603. @PostMapping("/unified/refund")
  604. @Log(module = "订单管理/统一退款", businessType = BusinessType.PUT, isSaveRequestData = true)
  605. public Result<String> unifiedRefund(@RequestBody @Validated OrderRefundReq refundReq) throws Exception {
  606. long adminId = StpUtil.getLoginIdAsLong();
  607. CmsUser cmsUser = cmsUserMapper.selectById(adminId);
  608. if (cmsUser == null) {
  609. throw BusinessRuntimeException.getGatewayApiCode(GatewayApiCode.CMS_TOKEN_VALID);
  610. }
  611. refundReq.setOperator(cmsUser.getNickname());
  612. cmsOrderDonService.unifiedRefund(refundReq);
  613. return GatewayResponse.SUCCESS.newBuilder().toResult("退款成功");
  614. }
  615. /**
  616. * 微信退款回调
  617. */
  618. @PostMapping("/wx/refund/notify")
  619. public void wxRefundNotify(HttpServletRequest request, HttpServletResponse response) throws Exception {
  620. String xml = IoKit.toString(request.getInputStream());
  621. log.info("=== 退款成功的回调: \n {}", xml);
  622. // 解析xml
  623. Map<String, String> map = Xmls.toMap(xml);
  624. // 退款失败
  625. if (!StrUtil.equals("SUCCESS", map.get("return_code"))) {
  626. throw BusinessRuntimeException.getInstance("退款失败.");
  627. }
  628. cmsOrderDonService.wxRefundNotify(map);
  629. String toWechatXmlResponse = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
  630. OutputStream out = null;
  631. try {
  632. out = response.getOutputStream();
  633. IoKit.write(toWechatXmlResponse, out);
  634. } catch (Throwable e) {
  635. throw BusinessRuntimeException.getInstance(e == null ? null : e.getMessage());
  636. } finally {
  637. IoKit.close(out);
  638. }
  639. }
  640. /**
  641. * 更换用户车票
  642. */
  643. @PutMapping("/put/sameSpec/empty/relation")
  644. @Log(module = "更换用户车票", businessType = BusinessType.PUT, isSaveRequestData = true)
  645. public Result<String> changeRelation(@RequestBody @Validated ChangeRelationReq req) throws Exception {
  646. cmsOrderDonService.changeRelation(req);
  647. return GatewayResponse.SUCCESS.newBuilder().toResult();
  648. }
  649. /**
  650. * 多余车位的空账号
  651. */
  652. @GetMapping("/get/sameSpec/empty/relation")
  653. public Result<SearchResult<EmptyGroupsRelationView>> getSameSpecEmptyRelation(Long skuId, Long groupsId, Long relationId, Boolean isNormal) {
  654. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap())
  655. .field(EmptyGroupsRelationView::getStatus, GroupsTrips.Status.down.name()).op(Operator.NotEqual)
  656. .field(EmptyGroupsRelationView::getSkuId, skuId).orderBy(EmptyGroupsRelationView::getAvailableNum)
  657. .desc();
  658. GoodsDonSku sku = skuMapper.selectById(skuId);
  659. Date expiryTime = null;
  660. if (relationId != null) {
  661. GroupsRelation relation = relationMapper.selectById(relationId);
  662. if (relation != null) expiryTime = relation.getExpiryTime();
  663. }
  664. if (groupsId != null) {
  665. builder.field(EmptyGroupsRelationView::getGroupsId, groupsId).op(Operator.NotEqual);
  666. }
  667. String condition = StrUtil.EMPTY;
  668. if (isNormal != null && isNormal) {
  669. 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);
  670. }
  671. if (StrUtil.isNotEmpty(condition)) {
  672. condition += " and ";
  673. }
  674. Integer maxNum = sku.getNum();
  675. Integer extraNum = 5;
  676. //GPT 4人月付
  677. if (sku.getId() == 178l) {
  678. extraNum = 2;
  679. }
  680. maxNum += extraNum;
  681. 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);
  682. if (StrUtil.isNotEmpty(condition)) {
  683. builder.put("condition", condition);
  684. }
  685. if (expiryTime != null) {
  686. builder.field(AccountView::getExpiryTime, expiryTime).op(Operator.GreaterEqual);
  687. builder.orderBy(AccountView::getExpiryTime).asc();
  688. }
  689. if (sku.getNum() == 1 || !Constant.AI_goodsIds.contains(sku.getGoodsId())) {
  690. builder.field(EmptyGroupsRelationView::getAvailableNum, 0).op(Operator.GreaterThan);
  691. }
  692. SearchResult<EmptyGroupsRelationView> search = beanSearcher.search(EmptyGroupsRelationView.class,
  693. builder.build());
  694. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  695. }
  696. /**
  697. * 订单补差价,补差价退款到余额
  698. */
  699. @PutMapping("/refund/price/differ")
  700. @Log(module = "订单管理/订单补差价", businessType = BusinessType.PUT, isSaveRequestData = true)
  701. public Result<String> refundPriceDiffer(@RequestBody OrderRefundReq orderRefundReq) throws Exception {
  702. long adminId = StpUtil.getLoginIdAsLong();
  703. CmsUser cmsUser = cmsUserMapper.selectById(adminId);
  704. if (cmsUser == null) {
  705. throw BusinessRuntimeException.getGatewayApiCode(GatewayApiCode.CMS_TOKEN_VALID);
  706. }
  707. orderRefundReq.setOperator(cmsUser.getNickname());
  708. cmsOrderDonService.refundPriceDiffer(orderRefundReq);
  709. return GatewayResponse.SUCCESS.newBuilder().toResult();
  710. }
  711. /**
  712. * 将余额清零 退款用户支付金额
  713. */
  714. @PutMapping("/clear/balance/refundMoney")
  715. @NoSubmit
  716. public Result<String> clearBalanceToRefundMoney(@RequestBody @Validated OrderBalanceRefundReq refundReq) throws Exception {
  717. cmsOrderDonService.clearBalanceToRefundMoney(refundReq);
  718. return GatewayResponse.SUCCESS.newBuilder().toResult();
  719. }
  720. /**
  721. * 客服退款每月数据
  722. */
  723. @GetMapping("/get/refundOrder/data")
  724. public Result<SearchResult<RefundOrderDonServiceDataView>> getRefundOrderData(String startTime, String endTime, String operator) {
  725. String time = StrUtil.EMPTY;
  726. if (StrUtil.isNotBlank(startTime)) {
  727. time += String.format(" and o.created_time >= '%s'", startTime);
  728. }
  729. if (StrUtil.isNotBlank(endTime)) {
  730. time += String.format(" and o.created_time < '%s'", endTime);
  731. }
  732. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  733. if (StrUtil.isNotBlank(time)) {
  734. builder.put("time", time);
  735. }
  736. if (StrUtil.isEmpty(operator)) {
  737. List<CmsUserVO> userVOS = beanSearcher.searchAll(CmsUserVO.class, MapUtils.builder().field(CmsUserVO::getRoleNames, "客服").op(Operator.Contain).build());
  738. List<String> collect = userVOS.stream().map(CmsUserVO::getNickname).collect(Collectors.toList());
  739. if (CollUtil.isNotEmpty(collect)) {
  740. builder.field(RefundOrderDonServiceDataView::getOperator, collect).op(Operator.InList);
  741. }
  742. }
  743. SearchResult<RefundOrderDonServiceDataView> search = beanSearcher.search(RefundOrderDonServiceDataView.class, builder.build());
  744. search.getDataList().forEach(e->{
  745. String goodsName = orderDonMapper.selectMaxRefundGoodsName(e.getOperator(), startTime, endTime);
  746. e.setGoodsName(goodsName);
  747. });
  748. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  749. }
  750. /**
  751. * 设置订单客服
  752. */
  753. @PutMapping("/set/service")
  754. public Result<String> setOrderCustomerService(@RequestBody OrderDonCustomerServiceRelate relate) {
  755. OrderDonCustomerServiceRelate orderDonCustomerServiceRelate = orderDonCustomerServiceRelateMapper.selectOne(Wrappers.lambdaQuery(OrderDonCustomerServiceRelate.class)
  756. .eq(OrderDonCustomerServiceRelate::getOrderId, relate.getOrderId()).last("limit 1"));
  757. if (orderDonCustomerServiceRelate != null) {
  758. relate.setId(orderDonCustomerServiceRelate.getId());
  759. }
  760. try {
  761. if (relate.getId() == null) {
  762. orderDonCustomerServiceRelateMapper.insert(relate);
  763. } else {
  764. orderDonCustomerServiceRelateMapper.updateById(relate);
  765. }
  766. } catch (DuplicateKeyException e) {
  767. }
  768. return GatewayResponse.SUCCESS.newBuilder().toResult();
  769. }
  770. /**
  771. * 查询套餐订单列表
  772. */
  773. @GetMapping("/upgrade/get")
  774. @SaCheckPermission("upgradeOrder:view")
  775. public Result<SearchResult<UpgradeOrderDonBackView>> getUpgradeOrder(String account, String showId, Long acId, String nickname, String register, Boolean isGoogle) {
  776. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  777. if (StrUtil.isNotBlank(account)) {
  778. GroupsRelation relation = relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
  779. .eq(GroupsRelation::getAccount, account).last("limit 1"));
  780. if (relation != null) {
  781. builder.field(OrderDonBackView::getRelationId, relation.getId());
  782. } else {
  783. builder.field(OrderDonBackView::getRelationId).op(Operator.IsNull);
  784. }
  785. }
  786. if (StrUtil.isNotBlank(showId)) {
  787. builder.field(OrderDonBackView::getUserId, userService.getUserIdByShowId(showId));
  788. }
  789. String conditionSql = StrUtil.EMPTY;
  790. if (acId != null) {
  791. conditionSql += String.format(" o.user_id in (select user_id from corp_user where ac_id = %s)", acId);
  792. }
  793. if (!ObjectUtil.isAllEmpty(nickname, register, isGoogle)) {
  794. if (StrUtil.isNotEmpty(conditionSql)) {
  795. conditionSql += " and ";
  796. }
  797. conditionSql += " exists (select u.id from user u where u.id = o.user_id";
  798. if (StrUtil.isNotEmpty(nickname)) {
  799. conditionSql += String.format(" and u.nickname like '%s%%'", nickname);
  800. }
  801. if (StrUtil.isNotEmpty(register)) {
  802. if ("phone".equals(register)) {
  803. conditionSql += " and u.login_phone != ''";
  804. } else if ("email".equals(register)) {
  805. conditionSql += " and u.email != ''";
  806. } else if ("wechat".equals(register)) {
  807. conditionSql += " and u.unionid != ''";
  808. }
  809. }
  810. if (isGoogle != null && isGoogle) {
  811. conditionSql += String.format(" and u.is_google is %s", isGoogle);
  812. }
  813. conditionSql += " limit 1)";
  814. }
  815. if (StrUtil.isNotBlank(conditionSql)) {
  816. builder.put("condition", conditionSql);
  817. }
  818. SearchResult<UpgradeOrderDonBackView> search = beanSearcher.search(UpgradeOrderDonBackView.class, builder.build());
  819. search.getDataList().forEach(data -> {
  820. User user = userMapper.selectById(data.getUserId());
  821. if (user != null) {
  822. data.setNickname(user.getNickname());
  823. data.setLoginPhone(user.getLoginPhone());
  824. data.setEmail(user.getEmail());
  825. data.setRegister(StrUtil.isNotEmpty(user.getUnionid()) ? "wechat" : StrUtil.isNotEmpty(user.getLoginPhone()) ? "phone" : "email");
  826. }
  827. });
  828. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  829. }
  830. /**
  831. * 套餐退款订单列表
  832. */
  833. @GetMapping("/get/upgrade/refund/list")
  834. public Result<SearchResult<RefundUpdradeOrderDonView>> getRefundUpgradeOrderDonView(String nickname) {
  835. List<Long> userIds = null;
  836. if (StrUtil.isNotBlank(nickname)) {
  837. userIds = userMapper.selectListByNickname(nickname);
  838. if (CollUtil.isEmpty(userIds)) {
  839. userIds.add(0l);
  840. }
  841. }
  842. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  843. if (CollUtil.isNotEmpty(userIds)) {
  844. builder.field(RealGoodsInterestUserView::getUserId, userIds).op(Operator.InList);
  845. }
  846. SearchResult<RefundUpdradeOrderDonView> search = beanSearcher.search(RefundUpdradeOrderDonView.class,
  847. builder.build());
  848. search.getDataList().forEach(data -> {
  849. Optional.ofNullable(userService.getById(data.getUserId()))
  850. .ifPresent(user -> data.setNickname(user.getNickname()));
  851. });
  852. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  853. }
  854. /**
  855. * 套餐订单导出
  856. */
  857. @GetMapping("/upgrade/export")
  858. @SaCheckPermission("upgradeOrder:export")
  859. @Log(module = "套餐订单管理/导出订单", businessType = BusinessType.EXPORT, isSaveRequestData = true)
  860. public void exportUpgradeOrders(HttpServletResponse response) {
  861. List<ExcelUpgradeOrderDonData> list = beanSearcher.searchAll(ExcelUpgradeOrderDonData.class, MapUtils.flatBuilder(request.getParameterMap()).build());
  862. list.forEach(data -> {
  863. data.setMoney(data.getMoney().divide(BigDecimal.valueOf(100)));
  864. UpgradeOrderDon.Type type = data.getType();
  865. data.setTypeStr(type != null ? type.getDesc() : "");
  866. UpgradeOrderDon.Status status = data.getStatus();
  867. data.setStatusStr(status != null ? status.getDesc() : "");
  868. });
  869. EasyExcelUtils.createExcelStreamMutilByEasyExcel(response, ExcelUpgradeOrderDonData.class, list, "订单列表", "订单列表", ExcelTypeEnum.XLSX, null);
  870. }
  871. /**
  872. * 套餐订单统一退款
  873. */
  874. @PostMapping("/unified/upgrade/refund")
  875. @Log(module = "套餐订单管理/统一退款", businessType = BusinessType.PUT, isSaveRequestData = true)
  876. public Result<String> unifiedUpgradeRefund(@RequestBody @Validated OrderRefundReq refundReq) throws Exception {
  877. long adminId = StpUtil.getLoginIdAsLong();
  878. CmsUser cmsUser = cmsUserMapper.selectById(adminId);
  879. if (cmsUser == null) {
  880. throw BusinessRuntimeException.getGatewayApiCode(GatewayApiCode.CMS_TOKEN_VALID);
  881. }
  882. refundReq.setOperator(cmsUser.getNickname());
  883. cmsOrderDonService.unifiedUpgradeRefund(refundReq);
  884. return GatewayResponse.SUCCESS.newBuilder().toResult("退款成功");
  885. }
  886. /**
  887. * midjourney查询订单用户账号剩余次数
  888. */
  889. @GetMapping("/get/midjourney/user")
  890. public Result<MidjourneyUserDetailView> getMidjourneyUser(Long orderId) {
  891. OrderDon orderDon = orderDonMapper.selectById(orderId);
  892. //续费订单
  893. Date startTime = null;
  894. Date expiryTime = null;
  895. if (orderDon.getOrderType() == 2) {
  896. GoodsDonSku sku = skuMapper.selectById(orderDon.getSkuId());
  897. GroupsRelation relation = relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
  898. .eq(GroupsRelation::getId, orderDon.getRelationId())
  899. .eq(GroupsRelation::getUserId, orderDon.getUserId()).last("limit 1"));
  900. if (relation == null) {
  901. return GatewayResponse.SUCCESS.newBuilder().toResult();
  902. }
  903. startTime = relation.getStartTime();
  904. startTime = DateUtil.offsetMonth(startTime, sku.getMonths());
  905. expiryTime = relation.getExpiryTime();
  906. }
  907. MidjourneyUser midjourneyUser = midjourneyUserMapper.selectOne(Wrappers.lambdaQuery(MidjourneyUser.class)
  908. .eq(MidjourneyUser::getRelationId, orderDon.getRelationId())
  909. .last("limit 1"));
  910. if (midjourneyUser == null) {
  911. return GatewayResponse.SUCCESS.newBuilder().toResult();
  912. }
  913. MidjourneyUserDetailView midjourneyUserDetailView = midjourneyUserConversationMapper.getMjMirrorOrderDetail(orderDon.getRelationId(), startTime, expiryTime);
  914. GoodsDonSku sku = skuMapper.selectById(orderDon.getSkuId());
  915. midjourneyUserDetailView.setUserId(orderDon.getUserId());
  916. midjourneyUserDetailView.setExpiryTime(midjourneyUser.getExpireTime());
  917. midjourneyUserDetailView.setMjFastNum(sku.getMjFastNum() - midjourneyUserDetailView.getUseFastNum());
  918. if (sku.getMjRelaxNum() == null) {
  919. midjourneyUserDetailView.setMjRelaxNum(null);
  920. } else {
  921. midjourneyUserDetailView.setMjRelaxNum(sku.getMjRelaxNum() - midjourneyUserDetailView.getUseRelaxNum());
  922. }
  923. return GatewayResponse.SUCCESS.newBuilder().toResult(midjourneyUserDetailView);
  924. }
  925. /**
  926. * 用户退款详情
  927. */
  928. @GetMapping("/get/user/refund/detail")
  929. public Result<OrderDonUserRefundDetailView> getUserRefundDetail(Long userId) {
  930. if (userId == null || userId == 0) {
  931. return GatewayResponse.SUCCESS.newBuilder().toResult();
  932. }
  933. List<Long> userIdList = null;
  934. try {
  935. userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  936. } catch (Exception e) {
  937. }
  938. String userIds = null;
  939. if (CollUtil.isNotEmpty(userIdList)) {
  940. userIds = userIdList.toString().replaceAll("\\[", "").replaceAll("]", "");
  941. }
  942. MapBuilder builder = MapUtils.builder();
  943. if (StrUtil.isNotBlank(userIds)) {
  944. builder.put("uid", String.format(" and user_id in (%s)", userIds));
  945. } else {
  946. builder.put("uid", String.format(" and user_id = %s", userId));
  947. }
  948. OrderDonUserRefundDetailView orderDonUserRefundDetailView = beanSearcher.searchFirst(OrderDonUserRefundDetailView.class, builder.build());
  949. return GatewayResponse.SUCCESS.newBuilder().toResult(orderDonUserRefundDetailView);
  950. }
  951. /**
  952. * 用户订单列表
  953. */
  954. @GetMapping("/get/user/orders")
  955. public Result<SearchResult<OrderDonUserRefundDetailView.OrderDonDetailView>> getUserOrdersDetail(Long userId) {
  956. if (userId == null || userId == 0) {
  957. return GatewayResponse.SUCCESS.newBuilder().toResult();
  958. }
  959. List<Long> userIdList = null;
  960. try {
  961. userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  962. } catch (Exception e) {
  963. }
  964. if (userIdList == null) {
  965. userIdList = new ArrayList<>();
  966. userIdList.add(userId);
  967. }
  968. SearchResult<OrderDonUserRefundDetailView.OrderDonDetailView> search = beanSearcher.search(OrderDonUserRefundDetailView.OrderDonDetailView.class, MapUtils.flatBuilder(request.getParameterMap())
  969. .field(OrderDonUserRefundDetailView.OrderDonDetailView::getUserId, userIdList).op(Operator.InList)
  970. .build());
  971. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  972. }
  973. }