CmsOrderController.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. package com.cyksj.web.controller.manage;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.date.DateTime;
  4. import cn.hutool.core.util.ObjectUtil;
  5. import cn.hutool.core.util.StrUtil;
  6. import com.alibaba.excel.support.ExcelTypeEnum;
  7. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  8. import com.cyksj.common.annotation.Log;
  9. import com.cyksj.common.annotation.NoSubmit;
  10. import com.cyksj.common.constant.Constant;
  11. import com.cyksj.common.exception.BusinessRuntimeException;
  12. import com.cyksj.dto.Result;
  13. import com.cyksj.enums.BusinessType;
  14. import com.cyksj.enums.GatewayApiCode;
  15. import com.cyksj.enums.GatewayResponse;
  16. import com.cyksj.mapper.*;
  17. import com.cyksj.mapper.channel.ChannelPopularizeMapper;
  18. import com.cyksj.mapper.manage.cms.CmsUserMapper;
  19. import com.cyksj.mapper.manage.coupon.CouponMapper;
  20. import com.cyksj.model.entity.*;
  21. import com.cyksj.model.excel.ExcelOrderDonData;
  22. import com.cyksj.model.manage.views.AccountView;
  23. import com.cyksj.model.manage.views.OrderDonBackView;
  24. import com.cyksj.model.request.ChangeRelationReq;
  25. import com.cyksj.model.request.ClickOutReq;
  26. import com.cyksj.model.request.OrderRefundReq;
  27. import com.cyksj.model.views.*;
  28. import com.cyksj.service.mange.CmsOrderDonService;
  29. import com.cyksj.service.order.OrderDonCommentService;
  30. import com.cyksj.service.user.UserBindRelationService;
  31. import com.cyksj.service.user.UserService;
  32. import com.cyksj.web.util.EasyExcelUtils;
  33. import com.cyksj.web.util.StpAbroadUtil;
  34. import com.ejlchina.searcher.BeanSearcher;
  35. import com.ejlchina.searcher.SearchResult;
  36. import com.ejlchina.searcher.param.Operator;
  37. import com.ejlchina.searcher.util.MapBuilder;
  38. import com.ejlchina.searcher.util.MapUtils;
  39. import lombok.RequiredArgsConstructor;
  40. import lombok.extern.slf4j.Slf4j;
  41. import org.springframework.dao.DuplicateKeyException;
  42. import org.springframework.validation.annotation.Validated;
  43. import org.springframework.web.bind.annotation.*;
  44. import javax.servlet.http.HttpServletRequest;
  45. import javax.servlet.http.HttpServletResponse;
  46. import java.math.BigDecimal;
  47. import java.util.ArrayList;
  48. import java.util.Date;
  49. import java.util.List;
  50. import java.util.Optional;
  51. import java.util.stream.Collectors;
  52. /**
  53. * @author chan
  54. * @date 2021/10/12 下午11:05
  55. */
  56. @Slf4j
  57. @RequestMapping("/manage/order")
  58. @RestController
  59. @RequiredArgsConstructor
  60. public class CmsOrderController {
  61. private final HttpServletRequest request;
  62. private final CmsOrderDonService cmsOrderDonService;
  63. private final UserService userService;
  64. private final BeanSearcher beanSearcher;
  65. private final CouponMapper couponMapper;
  66. private final OrderCommentMapper orderCommentMapper;
  67. private final OrderDonCommentService orderDonCommentService;
  68. private final GoodsDonSkuMapper skuMapper;
  69. private final ChannelPopularizeMapper channelPopularizeMapper;
  70. private final GroupsRelationMapper relationMapper;
  71. private final CmsUserMapper cmsUserMapper;
  72. private final UserMapper userMapper;
  73. private final OrderDonMapper orderDonMapper;
  74. private final UserBindRelationService userBindRelationService;
  75. private final OrderDonCustomerServiceRelateMapper orderDonCustomerServiceRelateMapper;
  76. @GetMapping("/get")
  77. public Result<SearchResult<OrderDonBackView>> get(Long channelId, String account, String showId, Long acId, String nickname, String register, Boolean isGoogle, Boolean isSubsidy, Boolean isRenewPackage) {
  78. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  79. if (channelId != null) {
  80. List<Long> popularizeIds = channelPopularizeMapper.getPopularizeIdByChannelId(channelId);
  81. builder.field(OrderDonBackView::getPopularizeId, popularizeIds).op(Operator.InList);
  82. }
  83. if (StrUtil.isNotBlank(account)) {
  84. GroupsRelation relation = relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
  85. .eq(GroupsRelation::getAccount, account).last("limit 1"));
  86. if (relation != null) {
  87. builder.field(OrderDonBackView::getRelationId, relation.getId());
  88. } else {
  89. builder.field(OrderDonBackView::getRelationId).op(Operator.IsNull);
  90. }
  91. }
  92. if (StrUtil.isNotBlank(showId)) {
  93. builder.field(OrderDonBackView::getUserId, userService.getUserIdByShowId(showId));
  94. }
  95. String conditionSql = StrUtil.EMPTY;
  96. if (acId != null) {
  97. conditionSql += String.format(" o.user_id in (select user_id from corp_user where ac_id = %s)", acId);
  98. }
  99. if (!ObjectUtil.isAllEmpty(nickname, register, isGoogle)) {
  100. if (StrUtil.isNotEmpty(conditionSql)) {
  101. conditionSql += " and ";
  102. }
  103. conditionSql += " exists (select u.id from user u where u.id = o.user_id";
  104. if (StrUtil.isNotEmpty(nickname)) {
  105. conditionSql += String.format(" and u.nickname like '%s%%'", nickname);
  106. }
  107. if (StrUtil.isNotEmpty(register)) {
  108. if ("phone".equals(register)) {
  109. conditionSql += " and u.login_phone != ''";
  110. } else if ("email".equals(register)) {
  111. conditionSql += " and u.email != ''";
  112. } else if ("wechat".equals(register)) {
  113. conditionSql += " and u.unionid != ''";
  114. }
  115. }
  116. if (isGoogle != null && isGoogle) {
  117. conditionSql += String.format(" and u.is_google is %s", isGoogle);
  118. }
  119. conditionSql += " limit 1)";
  120. }
  121. if (isSubsidy != null) {
  122. if (StrUtil.isNotEmpty(conditionSql)) {
  123. conditionSql += " and ";
  124. }
  125. conditionSql += " exists (select 1 from order_don_subsidy_relate ocr where ocr.order_id = o.id limit 1)";
  126. }
  127. if (isRenewPackage != null) {
  128. if (StrUtil.isNotEmpty(conditionSql)) {
  129. conditionSql += " and ";
  130. }
  131. conditionSql += " exists (select 1 from order_don_renew_record odrr1 where odrr1.order_id = o.id limit 1)";
  132. }
  133. if (StrUtil.isNotBlank(conditionSql)) {
  134. builder.put("condition", conditionSql);
  135. }
  136. SearchResult<OrderDonBackView> search = beanSearcher.search(OrderDonBackView.class, builder.build());
  137. search.getDataList().forEach(data -> {
  138. if (data.getPopularizeId() != null) {
  139. Optional.ofNullable(channelPopularizeMapper.selectChannelByPid(data.getPopularizeId()))
  140. .ifPresent(channelName -> data.setChannel(channelName));
  141. }
  142. if (data.getCouponId() != null) {
  143. Optional.ofNullable(couponMapper.selectById(data.getCouponId()))
  144. .ifPresent(coupon -> data.setCouponName(coupon.getName()));
  145. data.setCouponMoney(data.getCouponMoney() == null ? BigDecimal.ZERO : data.getCouponMoney());
  146. }
  147. if (data.getCouponUserId() != 0) {
  148. data.setCouponName(couponMapper.getCouponNameByCouponUserId(data.getCouponUserId()));
  149. data.setCouponMoney(data.getCouponMoney() == null ? BigDecimal.ZERO : data.getCouponMoney());
  150. }
  151. if (data.getRelationId() != 0) {
  152. Optional.ofNullable(relationMapper.getGroupRelationAccountView(data.getRelationId()))
  153. .ifPresent(e -> {
  154. data.setGtAccount(e.getTripsAccount());
  155. data.setAccount(e.getAccount());
  156. });
  157. }
  158. User user = userMapper.selectById(data.getUserId());
  159. if (user != null) {
  160. data.setNickname(user.getNickname());
  161. data.setLoginPhone(user.getLoginPhone());
  162. data.setEmail(user.getEmail());
  163. data.setRegister(StrUtil.isNotEmpty(user.getUnionid()) ? "wechat" : StrUtil.isNotEmpty(user.getLoginPhone()) ? "phone" : "email");
  164. }
  165. if (data.getGoodsDonType() != null && data.getGoodsDonType() == 1) {
  166. //获取订单关联客服
  167. Optional.ofNullable(orderDonMapper.selectOrderRelate(data.getId())).ifPresent(e -> {
  168. data.setCmsUserId(e.getCmsUserId());
  169. data.setNickname(e.getNickname());
  170. });
  171. }
  172. });
  173. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  174. }
  175. /**
  176. * 用户退款订单列表
  177. */
  178. @GetMapping("/get/refund/list")
  179. public Result<SearchResult<RefundOrderDonView>> getRefundOrderDonView() {
  180. SearchResult<RefundOrderDonView> search = beanSearcher.search(RefundOrderDonView.class, MapUtils.flatBuilder(request.getParameterMap())
  181. .build());
  182. search.getDataList().forEach(data -> {
  183. Optional.ofNullable(userService.getById(data.getUserId()))
  184. .ifPresent(user -> data.setNickname(user.getNickname()));
  185. });
  186. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  187. }
  188. /**
  189. * 订单导出
  190. */
  191. @GetMapping("/export")
  192. @Log(module = "订单管理/导出订单", businessType = BusinessType.EXPORT, isSaveRequestData = true)
  193. public void exportOrders(HttpServletResponse response) {
  194. List<ExcelOrderDonData> list = beanSearcher.searchAll(ExcelOrderDonData.class, MapUtils.flatBuilder(request.getParameterMap()).build());
  195. list.forEach(data -> {
  196. data.setMoney(data.getMoney().divide(BigDecimal.valueOf(100)));
  197. OrderDon.Type type = data.getType();
  198. data.setTypeStr(type != null ? type.getDesc() : "");
  199. OrderDon.Status status = data.getStatus();
  200. data.setStatusStr(status != null ? status.getDesc() : "");
  201. if (data.getChannelId() == null) {
  202. data.setChannel("自然流量渠道");
  203. }
  204. if (data.getCouponUserId() != 0) {
  205. data.setCouponName(couponMapper.getCouponNameByCouponUserId(data.getCouponUserId()));
  206. data.setCouponMoney(data.getCouponMoney() == null ? BigDecimal.ZERO : data.getCouponMoney().divide(BigDecimal.valueOf(100)));
  207. }
  208. });
  209. EasyExcelUtils.createExcelStreamMutilByEasyExcel(response, ExcelOrderDonData.class, list, "订单列表", "订单列表", ExcelTypeEnum.XLSX, null);
  210. }
  211. @PutMapping("/update/status")
  212. public Result<String> upStatus(@RequestBody OrderDon orderDon){
  213. cmsOrderDonService.update(Wrappers.lambdaUpdate(OrderDon.class).eq(OrderDon::getId,orderDon.getId()).set(OrderDon::getStatus,orderDon.getStatus()));
  214. return GatewayResponse.SUCCESS.newBuilder().toResult();
  215. }
  216. /**
  217. * 修改订单状态
  218. */
  219. @PutMapping("/put/status/{orderId}")
  220. public Result<String> updateOrderStatus(@PathVariable Long orderId) {
  221. OrderDon orderDon = cmsOrderDonService.getById(orderId);
  222. if (orderDon == null) {
  223. throw BusinessRuntimeException.getInstance("该订单不存在");
  224. }
  225. if (orderDon.getStatus() == OrderDon.Status.complete) {
  226. throw BusinessRuntimeException.getInstance("该订单已是已完成状态");
  227. }
  228. if (orderDon.getStatus() != OrderDon.Status.hasPayment) {
  229. throw BusinessRuntimeException.getInstance("该订单不是未支付状态");
  230. }
  231. orderDon.setStatus(OrderDon.Status.complete);
  232. cmsOrderDonService.updateById(orderDon);
  233. return GatewayResponse.SUCCESS.newBuilder().toResult("修改订单状态成功");
  234. }
  235. /**
  236. * 新增平台评论
  237. */
  238. @PostMapping("/post/orderComment")
  239. public Result<String> insertOrderComment(@RequestBody @Validated OrderComment orderComment) {
  240. if (StrUtil.isEmpty(orderComment.getHeadImgUrl())) {
  241. orderComment.setHeadImgUrl(Constant.DEFAULT_HEAD_IMG);
  242. }
  243. if (orderComment.getCommentTime() == null) {
  244. orderComment.setCommentTime(DateTime.now().toDateStr());
  245. }
  246. orderComment.setVerifyStatus(OrderComment.VerifyStatus.success);
  247. orderCommentMapper.insert(orderComment);
  248. return GatewayResponse.SUCCESS.newBuilder().toResult("新增成功");
  249. }
  250. /**
  251. * 编辑平台评论
  252. */
  253. @PutMapping("/put/orderComment")
  254. public Result<String> updateOrderComment(@RequestBody @Validated OrderComment orderComment) {
  255. if (orderComment.getCommentTime() == null) {
  256. orderComment.setCommentTime(DateTime.now().toDateStr());
  257. }
  258. if (orderComment.getVerifyStatus() == null) {
  259. orderComment.setVerifyStatus(OrderComment.VerifyStatus.success);
  260. }
  261. orderCommentMapper.updateById(orderComment);
  262. return GatewayResponse.SUCCESS.newBuilder().toResult("编辑成功");
  263. }
  264. /**
  265. * 删除平台评论
  266. */
  267. @DeleteMapping("/delete/orderComment/{id}")
  268. public Result<String> deleteOrderCommentById(@PathVariable Long id) {
  269. orderCommentMapper.deleteById(id);
  270. return GatewayResponse.SUCCESS.newBuilder().toResult("删除成功");
  271. }
  272. /**
  273. * 平台评论列表
  274. */
  275. @GetMapping("/get/orderComment")
  276. public Result<SearchResult<OrderCommentView>> getOrderCommentView() {
  277. SearchResult<OrderCommentView> search = beanSearcher.search(OrderCommentView.class, MapUtils.flatBuilder(request.getParameterMap()).build());
  278. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  279. }
  280. /**
  281. * 配置订单平台评价列表
  282. */
  283. @PostMapping("/post/orderComment/reward/config")
  284. public Result<String> saveOrUpdateOrderCommentConfig(@RequestBody List<OrderCommentRewardConfig> configs) {
  285. orderDonCommentService.saveOrUpdateOrderCommentConfig(configs);
  286. return GatewayResponse.SUCCESS.newBuilder().toResult();
  287. }
  288. /**
  289. * 获取配置 订单平台评价
  290. */
  291. @GetMapping("/get/orderComment/reward/config")
  292. public Result<List<OrderCommentRewardConfigView>> getOrderCommentRewardConfig() {
  293. List<OrderCommentRewardConfigView> views = beanSearcher.searchAll(OrderCommentRewardConfigView.class, MapUtils.builder()
  294. .orderBy(OrderCommentRewardConfigView::getGoodsId).desc()
  295. .build());
  296. return GatewayResponse.SUCCESS.newBuilder().toResult(views);
  297. }
  298. /**
  299. * 踢出车队
  300. */
  301. @PutMapping("/kickOut")
  302. @NoSubmit
  303. public Result<String> kickOut(@RequestBody @Validated ClickOutReq req) {
  304. long adminId = StpAbroadUtil.getLoginIdAsLong();
  305. cmsOrderDonService.kickOutRelationId(adminId, req);
  306. return GatewayResponse.SUCCESS.newBuilder().toResult();
  307. }
  308. /**
  309. * 踢出车队列表
  310. */
  311. @GetMapping("/get/kickOut/list")
  312. public Result<SearchResult<UserKickOutView>> getKickOutList() {
  313. SearchResult<UserKickOutView> search = beanSearcher.search(UserKickOutView.class, MapUtils.flatBuilder(request.getParameterMap()).build());
  314. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  315. }
  316. /**
  317. * 订单统一退款
  318. */
  319. @PostMapping("/unified/refund")
  320. @Log(module = "订单管理/统一退款", businessType = BusinessType.PUT, isSaveRequestData = true)
  321. public Result<String> unifiedRefund(@RequestBody @Validated OrderRefundReq refundReq) throws Exception {
  322. long adminId = StpAbroadUtil.getLoginIdAsLong();
  323. CmsUser cmsUser = cmsUserMapper.selectById(adminId);
  324. if (cmsUser == null) {
  325. throw BusinessRuntimeException.getGatewayApiCode(GatewayApiCode.CMS_TOKEN_VALID);
  326. }
  327. refundReq.setOperator(cmsUser.getNickname());
  328. cmsOrderDonService.unifiedRefund(refundReq);
  329. return GatewayResponse.SUCCESS.newBuilder().toResult("退款成功");
  330. }
  331. /**
  332. * 更换用户车票
  333. */
  334. @PutMapping("/put/sameSpec/empty/relation")
  335. @Log(module = "更换用户车票", businessType = BusinessType.PUT, isSaveRequestData = true)
  336. public Result<String> changeRelation(@RequestBody @Validated ChangeRelationReq req) throws Exception {
  337. cmsOrderDonService.changeRelation(req);
  338. return GatewayResponse.SUCCESS.newBuilder().toResult();
  339. }
  340. /**
  341. * 多余车位的空账号
  342. */
  343. @GetMapping("/get/sameSpec/empty/relation")
  344. public Result<SearchResult<EmptyGroupsRelationView>> getSameSpecEmptyRelation(Long skuId, Long groupsId, Long relationId, Boolean isNormal) {
  345. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap())
  346. .field(EmptyGroupsRelationView::getStatus, GroupsTrips.Status.down.name()).op(Operator.NotEqual)
  347. .field(EmptyGroupsRelationView::getSkuId, skuId).orderBy(EmptyGroupsRelationView::getAvailableNum)
  348. .desc();
  349. GoodsDonSku sku = skuMapper.selectById(skuId);
  350. Date expiryTime = null;
  351. if (relationId != null) {
  352. GroupsRelation relation = relationMapper.selectById(relationId);
  353. if (relation != null) expiryTime = relation.getExpiryTime();
  354. }
  355. if (groupsId != null) {
  356. builder.field(EmptyGroupsRelationView::getGroupsId, groupsId).op(Operator.NotEqual);
  357. }
  358. String condition = StrUtil.EMPTY;
  359. if (isNormal != null && isNormal) {
  360. 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);
  361. }
  362. if (StrUtil.isNotEmpty(condition)) {
  363. condition += " and ";
  364. }
  365. Integer maxNum = sku.getNum();
  366. Integer extraNum = 5;
  367. //GPT 4人月付
  368. if (sku.getId() == 178l) {
  369. extraNum = 2;
  370. }
  371. maxNum += extraNum;
  372. 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);
  373. if (StrUtil.isNotEmpty(condition)) {
  374. builder.put("condition", condition);
  375. }
  376. if (expiryTime != null) {
  377. builder.field(AccountView::getExpiryTime, expiryTime).op(Operator.GreaterEqual);
  378. builder.orderBy(AccountView::getExpiryTime).asc();
  379. }
  380. if (sku.getNum() == 1 || !Constant.AI_goodsIds.contains(sku.getGoodsId())) {
  381. builder.field(EmptyGroupsRelationView::getAvailableNum, 0).op(Operator.GreaterThan);
  382. }
  383. SearchResult<EmptyGroupsRelationView> search = beanSearcher.search(EmptyGroupsRelationView.class,
  384. builder.build());
  385. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  386. }
  387. /**
  388. * 客服退款每月数据
  389. */
  390. @GetMapping("/get/refundOrder/data")
  391. public Result<SearchResult<RefundOrderDonServiceDataView>> getRefundOrderData(String startTime, String endTime, String operator) {
  392. String time = StrUtil.EMPTY;
  393. if (StrUtil.isNotBlank(startTime)) {
  394. time += String.format(" and o.created_time >= '%s'", startTime);
  395. }
  396. if (StrUtil.isNotBlank(endTime)) {
  397. time += String.format(" and o.created_time < '%s'", endTime);
  398. }
  399. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  400. if (StrUtil.isNotBlank(time)) {
  401. builder.put("time", time);
  402. }
  403. if (StrUtil.isEmpty(operator)) {
  404. List<CmsUserVO> userVOS = beanSearcher.searchAll(CmsUserVO.class, MapUtils.builder().field(CmsUserVO::getRoleNames, "客服").op(Operator.Contain).build());
  405. List<String> collect = userVOS.stream().map(CmsUserVO::getNickname).collect(Collectors.toList());
  406. if (CollUtil.isNotEmpty(collect)) {
  407. builder.field(RefundOrderDonServiceDataView::getOperator, collect).op(Operator.InList);
  408. }
  409. }
  410. SearchResult<RefundOrderDonServiceDataView> search = beanSearcher.search(RefundOrderDonServiceDataView.class, builder.build());
  411. search.getDataList().forEach(e->{
  412. String goodsName = orderDonMapper.selectMaxRefundGoodsName(e.getOperator(), startTime, endTime);
  413. e.setGoodsName(goodsName);
  414. });
  415. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  416. }
  417. /**
  418. * 设置订单客服
  419. */
  420. @PutMapping("/set/service")
  421. public Result<String> setOrderCustomerService(@RequestBody OrderDonCustomerServiceRelate relate) {
  422. OrderDonCustomerServiceRelate orderDonCustomerServiceRelate = orderDonCustomerServiceRelateMapper.selectOne(Wrappers.lambdaQuery(OrderDonCustomerServiceRelate.class)
  423. .eq(OrderDonCustomerServiceRelate::getOrderId, relate.getOrderId()).last("limit 1"));
  424. if (orderDonCustomerServiceRelate != null) {
  425. relate.setId(orderDonCustomerServiceRelate.getId());
  426. }
  427. try {
  428. if (relate.getId() == null) {
  429. orderDonCustomerServiceRelateMapper.insert(relate);
  430. } else {
  431. orderDonCustomerServiceRelateMapper.updateById(relate);
  432. }
  433. } catch (DuplicateKeyException e) {
  434. }
  435. return GatewayResponse.SUCCESS.newBuilder().toResult();
  436. }
  437. /**
  438. * 用户退款详情
  439. */
  440. @GetMapping("/get/user/refund/detail")
  441. public Result<OrderDonUserRefundDetailView> getUserRefundDetail(Long userId) {
  442. if (userId == null || userId == 0) {
  443. return GatewayResponse.SUCCESS.newBuilder().toResult();
  444. }
  445. List<Long> userIdList = null;
  446. try {
  447. userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  448. } catch (Exception e) {
  449. }
  450. String userIds = null;
  451. if (CollUtil.isNotEmpty(userIdList)) {
  452. userIds = userIdList.toString().replaceAll("\\[", "").replaceAll("]", "");
  453. }
  454. MapBuilder builder = MapUtils.builder();
  455. if (StrUtil.isNotBlank(userIds)) {
  456. builder.put("uid", String.format(" and user_id in (%s)", userIds));
  457. } else {
  458. builder.put("uid", String.format(" and user_id = %s", userId));
  459. }
  460. OrderDonUserRefundDetailView orderDonUserRefundDetailView = beanSearcher.searchFirst(OrderDonUserRefundDetailView.class, builder.build());
  461. return GatewayResponse.SUCCESS.newBuilder().toResult(orderDonUserRefundDetailView);
  462. }
  463. /**
  464. * 用户订单列表
  465. */
  466. @GetMapping("/get/user/orders")
  467. public Result<SearchResult<OrderDonUserRefundDetailView.OrderDonDetailView>> getUserOrdersDetail(Long userId) {
  468. if (userId == null || userId == 0) {
  469. return GatewayResponse.SUCCESS.newBuilder().toResult();
  470. }
  471. List<Long> userIdList = null;
  472. try {
  473. userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  474. } catch (Exception e) {
  475. }
  476. if (userIdList == null) {
  477. userIdList = new ArrayList<>();
  478. userIdList.add(userId);
  479. }
  480. SearchResult<OrderDonUserRefundDetailView.OrderDonDetailView> search = beanSearcher.search(OrderDonUserRefundDetailView.OrderDonDetailView.class, MapUtils.flatBuilder(request.getParameterMap())
  481. .field(OrderDonUserRefundDetailView.OrderDonDetailView::getUserId, userIdList).op(Operator.InList)
  482. .build());
  483. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  484. }
  485. }