CmsOrderController.java 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864
  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.date.DateTime;
  5. import cn.hutool.core.util.StrUtil;
  6. import com.alibaba.excel.EasyExcel;
  7. import com.alibaba.excel.support.ExcelTypeEnum;
  8. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  9. import com.cyksj.common.annotation.Log;
  10. import com.cyksj.common.annotation.NoSubmit;
  11. import com.cyksj.common.constant.Constant;
  12. import com.cyksj.common.exception.BusinessRuntimeException;
  13. import com.cyksj.common.util.IoKit;
  14. import com.cyksj.common.util.Jsons;
  15. import com.cyksj.common.util.Xmls;
  16. import com.cyksj.dto.Result;
  17. import com.cyksj.enums.BusinessType;
  18. import com.cyksj.enums.GatewayResponse;
  19. import com.cyksj.mapper.GoodsDonSkuMapper;
  20. import com.cyksj.mapper.GroupsRelationMapper;
  21. import com.cyksj.mapper.OrderCommentMapper;
  22. import com.cyksj.mapper.RealGoodsInterestUserMapper;
  23. import com.cyksj.mapper.channel.ChannelPopularizeMapper;
  24. import com.cyksj.mapper.manage.RealGoodsOrderHandleMapper;
  25. import com.cyksj.mapper.manage.coupon.CouponMapper;
  26. import com.cyksj.model.entity.*;
  27. import com.cyksj.model.excel.*;
  28. import com.cyksj.model.excel.merge.CustomMergeStrategy;
  29. import com.cyksj.model.manage.request.ReqSetLogisticsPost;
  30. import com.cyksj.model.manage.views.AccountView;
  31. import com.cyksj.model.manage.views.OrderDonBackView;
  32. import com.cyksj.model.manage.views.OrderDonSkuBackView;
  33. import com.cyksj.model.manage.views.OrderMasterDonBackView;
  34. import com.cyksj.model.request.*;
  35. import com.cyksj.model.views.*;
  36. import com.cyksj.service.mange.CmsOrderDonService;
  37. import com.cyksj.service.order.OrderDonCommentService;
  38. import com.cyksj.service.user.UserService;
  39. import com.cyksj.web.util.EasyExcelUtils;
  40. import com.ejlchina.searcher.BeanSearcher;
  41. import com.ejlchina.searcher.SearchResult;
  42. import com.ejlchina.searcher.param.Operator;
  43. import com.ejlchina.searcher.util.MapBuilder;
  44. import com.ejlchina.searcher.util.MapUtils;
  45. import lombok.RequiredArgsConstructor;
  46. import lombok.extern.slf4j.Slf4j;
  47. import org.apache.commons.lang3.StringUtils;
  48. import org.springframework.validation.annotation.Validated;
  49. import org.springframework.web.bind.annotation.*;
  50. import javax.servlet.http.HttpServletRequest;
  51. import javax.servlet.http.HttpServletResponse;
  52. import java.io.OutputStream;
  53. import java.math.BigDecimal;
  54. import java.util.*;
  55. import java.util.stream.Collectors;
  56. /**
  57. * @author chan
  58. * @date 2021/10/12 下午11:05
  59. */
  60. @Slf4j
  61. @RequestMapping("/manage/order")
  62. @RestController
  63. @RequiredArgsConstructor
  64. public class CmsOrderController {
  65. private final HttpServletRequest request;
  66. private final CmsOrderDonService cmsOrderDonService;
  67. private final UserService userService;
  68. private final BeanSearcher beanSearcher;
  69. private final RealGoodsInterestUserMapper realGoodsInterestUserMapper;
  70. private final RealGoodsOrderHandleMapper realGoodsOrderHandleMapper;
  71. private final CouponMapper couponMapper;
  72. private final OrderCommentMapper orderCommentMapper;
  73. private final OrderDonCommentService orderDonCommentService;
  74. private final GoodsDonSkuMapper skuMapper;
  75. private final ChannelPopularizeMapper channelPopularizeMapper;
  76. private final GroupsRelationMapper relationMapper;
  77. @GetMapping("/get")
  78. @SaCheckPermission("order:view")
  79. @Deprecated
  80. public Result<SearchResult<OrderDonBackView>> get(Long channelId, String account, String showId) {
  81. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  82. if (channelId != null) {
  83. List<Long> popularizeIds = channelPopularizeMapper.getPopularizeIdByChannelId(channelId);
  84. builder.field(OrderDonBackView::getPopularizeId, popularizeIds).op(Operator.InList);
  85. }
  86. if (StrUtil.isNotBlank(account)) {
  87. GroupsRelation relation = relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
  88. .eq(GroupsRelation::getAccount, account).last("limit 1"));
  89. if (relation != null) {
  90. builder.field(OrderDonBackView::getRelationId, relation.getId());
  91. } else {
  92. builder.field(OrderDonBackView::getRelationId).op(Operator.IsNull);
  93. }
  94. }
  95. if (StrUtil.isNotBlank(showId)) {
  96. builder.field(OrderDonBackView::getUserId, userService.getUserIdByShowId(showId));
  97. }
  98. SearchResult<OrderDonBackView> search = beanSearcher.search(OrderDonBackView.class, builder.build());
  99. search.getDataList().forEach(data -> {
  100. if (data.getPopularizeId() != null) {
  101. Optional.ofNullable(channelPopularizeMapper.selectChannelByPid(data.getPopularizeId()))
  102. .ifPresent(channelName -> data.setChannel(channelName));
  103. }
  104. if (data.getGoodsDonType() != null && Constant.realGoodsType.contains(data.getGoodsDonType())) {
  105. RealGoodsOrderHandle realGoodsOrderHandle = realGoodsOrderHandleMapper.selectOne(Wrappers.lambdaQuery(RealGoodsOrderHandle.class).eq(RealGoodsOrderHandle::getOrderId, data.getId()).last("limit 1"));
  106. if (realGoodsOrderHandle != null) {
  107. data.setBeforeServiceName(realGoodsOrderHandle.getBeforeServiceName());
  108. data.setAfterServiceName(realGoodsOrderHandle.getAfterServiceName());
  109. }
  110. }
  111. if (data.getCouponUserId() != 0) {
  112. data.setCouponName(couponMapper.getCouponNameByCouponUserId(data.getCouponUserId()));
  113. data.setCouponMoney(data.getCouponMoney() == null ? BigDecimal.ZERO : data.getCouponMoney());
  114. }
  115. Optional.ofNullable(relationMapper.selectById(data.getRelationId()))
  116. .ifPresent(relation -> {
  117. data.setAccount(relation.getAccount());
  118. AccountView accountView = beanSearcher.searchFirst(AccountView.class, MapUtils.builder().field(AccountView::getGroupsId, relation.getGroupsId()).onlySelect(AccountView::getAccount).build());
  119. Optional.ofNullable(accountView).ifPresent(view -> data.setGtAccount(view.getAccount()));
  120. });
  121. Optional.ofNullable(skuMapper.selectById(data.getSkuId()))
  122. .ifPresent(sku -> {
  123. data.setSpecVal(sku.getSpecVal());
  124. data.setMonths(sku.getMonths());
  125. data.setDays(sku.getDays());
  126. });
  127. });
  128. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  129. }
  130. /** 主订单查询
  131. * @param channelId 推广渠道id
  132. * @param account 用户邀请制座位账号
  133. * @param showId 用户展示id
  134. * @param goodsDonType 平台类型 1虚拟
  135. * @param goodsId 平台id
  136. * @param skuId 规格id
  137. * @param isNoBind 是否未绑定车票
  138. * @param dsType 优惠类型 1优惠券 2余额 3 银河币
  139. * @return
  140. */
  141. @GetMapping("/get/mOrder")
  142. public Result<SearchResult<OrderMasterDonBackView>> getMOrder(Long channelId, String account, String showId, Long goodsDonType, Long goodsId, Long skuId, Boolean isNoBind, Integer dsType, @RequestParam(value = "orderStatus", required = false) List<String> orderStatus) throws Exception {
  143. StringBuilder conditionSb = new StringBuilder();
  144. if (goodsId != null) {
  145. conditionSb.append(String.format(" and goods_id = %s", goodsId));
  146. }
  147. if (skuId != null) {
  148. conditionSb.append(String.format(" and os.sku_id = %s", skuId));
  149. }
  150. if (goodsDonType != null) {
  151. conditionSb.append(String.format(" and os.goods_id in (select id from goods_don where type = %s)", goodsDonType));
  152. }
  153. if (isNoBind != null) {
  154. String f = isNoBind ? "=" : "!=";
  155. conditionSb.append(String.format(" and os.ex_code != '' and os.user_id %s 0", f));
  156. }
  157. if (dsType != null) {
  158. //默认优惠券
  159. String dsTypeField = "coupon_user_id";
  160. if (dsType == 2) {
  161. dsTypeField = "balance";
  162. } else if (dsType == 3) {
  163. dsTypeField = "galaxycoin";
  164. }
  165. conditionSb.append(String.format(" and os.%s != 0", dsTypeField));
  166. }
  167. if (orderStatus != null) {
  168. conditionSb.append(String.format(" and os.status in %s", Jsons.toJson(orderStatus).replaceAll("\\[", "(").replaceAll("]", ")")));
  169. }
  170. String conditionSql = null;
  171. if (conditionSb.length() > 0) {
  172. conditionSql = String.format(" (select count(*) from order_don os where os.m_oid = o.id %s) > 0", conditionSb.toString());
  173. }
  174. //主订单
  175. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  176. if (channelId != null) {
  177. List<Long> popularizeIds = channelPopularizeMapper.getPopularizeIdByChannelId(channelId);
  178. builder.field(OrderMasterDonBackView::getPopularizeId, popularizeIds).op(Operator.InList);
  179. }
  180. if (StrUtil.isNotBlank(account)) {
  181. GroupsRelation relation = relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
  182. .eq(GroupsRelation::getAccount, account).last("limit 1"));
  183. if (relation != null) {
  184. builder.field(OrderMasterDonBackView::getUserId, relation.getUserId());
  185. } else {
  186. builder.field(OrderMasterDonBackView::getUserId).op(Operator.IsNull);
  187. }
  188. }
  189. if (StrUtil.isNotBlank(showId)) {
  190. builder.field(OrderMasterDonBackView::getUserId, userService.getUserIdByShowId(showId));
  191. }
  192. if (StrUtil.isNotBlank(conditionSql)) {
  193. builder.put("condition", conditionSql);
  194. }
  195. SearchResult<OrderMasterDonBackView> search1 = beanSearcher.search(OrderMasterDonBackView.class, builder.build());
  196. search1.getDataList().forEach(mData -> {
  197. List<OrderDonSkuBackView> orderDonBackViews = beanSearcher.searchAll(OrderDonSkuBackView.class, MapUtils.builder().field(OrderDonSkuBackView::getMOid, mData.getMOid()).build());
  198. mData.setChildren(orderDonBackViews);
  199. mData.setHasChildren(false);
  200. if (mData.getChildren().size() > 1) {
  201. mData.setHasChildren(true);
  202. }
  203. mData.getChildren().forEach(data -> {
  204. if (data.getPopularizeId() != null) {
  205. Optional.ofNullable(channelPopularizeMapper.selectChannelByPid(data.getPopularizeId()))
  206. .ifPresent(channelName -> data.setChannel(channelName));
  207. }
  208. if (data.getGoodsDonType() != null && Constant.realGoodsType.contains(data.getGoodsDonType())) {
  209. RealGoodsOrderHandle realGoodsOrderHandle = realGoodsOrderHandleMapper.selectOne(Wrappers.lambdaQuery(RealGoodsOrderHandle.class).eq(RealGoodsOrderHandle::getOrderId, data.getId()).last("limit 1"));
  210. if (realGoodsOrderHandle != null) {
  211. data.setBeforeServiceName(realGoodsOrderHandle.getBeforeServiceName());
  212. data.setAfterServiceName(realGoodsOrderHandle.getAfterServiceName());
  213. }
  214. }
  215. if (data.getCouponUserId() != 0) {
  216. data.setCouponName(couponMapper.getCouponNameByCouponUserId(data.getCouponUserId()));
  217. data.setCouponMoney(data.getCouponMoney() == null ? BigDecimal.ZERO : data.getCouponMoney());
  218. }
  219. Optional.ofNullable(relationMapper.selectById(data.getRelationId()))
  220. .ifPresent(relation -> {
  221. data.setAccount(relation.getAccount());
  222. AccountView accountView = beanSearcher.searchFirst(AccountView.class, MapUtils.builder().field(AccountView::getGroupsId, relation.getGroupsId()).onlySelect(AccountView::getAccount).build());
  223. Optional.ofNullable(accountView).ifPresent(view -> data.setGtAccount(view.getAccount()));
  224. });
  225. Optional.ofNullable(skuMapper.selectById(data.getSkuId()))
  226. .ifPresent(sku -> {
  227. data.setSpecVal(sku.getSpecVal());
  228. data.setMonths(sku.getMonths());
  229. data.setDays(sku.getDays());
  230. });
  231. });
  232. });
  233. return GatewayResponse.SUCCESS.newBuilder().toResult(search1);
  234. }
  235. /**
  236. * 用户退款订单列表
  237. */
  238. @GetMapping("/get/refund/list")
  239. public Result<SearchResult<RefundOrderDonView>> getRefundOrderDonView() {
  240. SearchResult<RefundOrderDonView> search = beanSearcher.search(RefundOrderDonView.class, MapUtils.flatBuilder(request.getParameterMap())
  241. .build());
  242. search.getDataList().forEach(data -> {
  243. Optional.ofNullable(userService.getById(data.getUserId()))
  244. .ifPresent(user -> data.setNickname(user.getNickname()));
  245. });
  246. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  247. }
  248. /**
  249. * 订单导出
  250. */
  251. @GetMapping("/export")
  252. @SaCheckPermission("order:export")
  253. @Log(module = "订单管理/导出订单", businessType = BusinessType.EXPORT, isSaveRequestData = true)
  254. public void exportOrders(HttpServletResponse response) {
  255. List<ExcelOrderDonData> list = beanSearcher.searchAll(ExcelOrderDonData.class, MapUtils.flatBuilder(request.getParameterMap()).build());
  256. list.forEach(data -> {
  257. data.setMoney(data.getMoney().divide(BigDecimal.valueOf(100)));
  258. OrderDon.Type type = data.getType();
  259. data.setTypeStr(type != null ? type.getDesc() : "");
  260. OrderDon.Status status = data.getStatus();
  261. data.setStatusStr(status != null ? status.getDesc() : "");
  262. if (data.getChannelId() == null) {
  263. data.setChannel("自然流量渠道");
  264. }
  265. if (data.getGoodsDonType() != null && Constant.realGoodsType.contains(data.getGoodsDonType())) {
  266. OrderDonTransportView transportView = beanSearcher.searchFirst(OrderDonTransportView.class, MapUtils.builder().field(OrderDonTransportView::getOrderId, data.getId()).build());
  267. if (transportView != null) {
  268. data.setTransportStr(String.format("%s%s%s%s", transportView.getProvince(), transportView.getCity(), transportView.getDistrict(), transportView.getAddress()));
  269. data.setPhone(transportView.getPhone());
  270. data.setReceiver(transportView.getReceiver());
  271. data.setCodeCn(transportView.getCodeCn());
  272. data.setTrackingNumber(transportView.getTrackingNumber());
  273. }
  274. RealGoodsOrderHandle realGoodsOrderHandle = realGoodsOrderHandleMapper.selectOne(Wrappers.lambdaQuery(RealGoodsOrderHandle.class).eq(RealGoodsOrderHandle::getOrderId, data.getId()).last("limit 1"));
  275. if (realGoodsOrderHandle != null) {
  276. data.setBeforeServiceName(realGoodsOrderHandle.getBeforeServiceName());
  277. data.setAfterServiceName(realGoodsOrderHandle.getAfterServiceName());
  278. }
  279. }
  280. if (data.getCouponUserId() != 0) {
  281. data.setCouponName(couponMapper.getCouponNameByCouponUserId(data.getCouponUserId()));
  282. data.setCouponMoney(data.getCouponMoney() == null ? BigDecimal.ZERO : data.getCouponMoney().divide(BigDecimal.valueOf(100)));
  283. }
  284. });
  285. EasyExcelUtils.createExcelStreamMutilByEasyExcel(response, ExcelOrderDonData.class, list, "订单列表", "订单列表", ExcelTypeEnum.XLSX, null);
  286. }
  287. /**
  288. * 主订单 导出
  289. */
  290. @GetMapping("/mOrder/export")
  291. @Log(module = "订单管理/主订单导出订单", businessType = BusinessType.EXPORT, isSaveRequestData = true)
  292. public void exportMOrders(HttpServletResponse response, Long channelId, String account, String showId, Long goodsDonType, Long goodsId, Long skuId, Boolean isNoBind, Integer dsType, @RequestParam(value = "orderStatus", required = false) List<String> orderStatus) throws Exception {
  293. StringBuilder conditionSb = new StringBuilder();
  294. if (goodsId != null) {
  295. conditionSb.append(String.format(" and goods_id = %s", goodsId));
  296. }
  297. if (skuId != null) {
  298. conditionSb.append(String.format(" and os.sku_id = %s", skuId));
  299. }
  300. if (goodsDonType != null) {
  301. conditionSb.append(String.format(" and os.goods_id in (select id from goods_don where type = %s)", goodsDonType));
  302. }
  303. if (isNoBind != null) {
  304. String f = isNoBind ? "=" : "!=";
  305. conditionSb.append(String.format(" and os.ex_code != '' and os.user_id %s 0", f));
  306. }
  307. if (dsType != null) {
  308. //默认优惠券
  309. String dsTypeField = "coupon_user_id";
  310. if (dsType == 2) {
  311. dsTypeField = "balance";
  312. } else if (dsType == 3) {
  313. dsTypeField = "galaxycoin";
  314. }
  315. conditionSb.append(String.format(" and os.%s != 0", dsTypeField));
  316. }
  317. if (orderStatus != null) {
  318. conditionSb.append(String.format(" and os.status in %s", Jsons.toJson(orderStatus).replaceAll("\\[", "(").replaceAll("]", ")")));
  319. }
  320. String conditionSql = null;
  321. if (conditionSb.length() > 0) {
  322. conditionSql = String.format(" (select count(*) from order_don os where os.m_oid = o.id %s) > 0", conditionSb.toString());
  323. }
  324. //主订单
  325. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  326. if (channelId != null) {
  327. List<Long> popularizeIds = channelPopularizeMapper.getPopularizeIdByChannelId(channelId);
  328. builder.field(ExcelOrderMasterDonData::getPopularizeId, popularizeIds).op(Operator.InList);
  329. }
  330. if (StrUtil.isNotBlank(account)) {
  331. GroupsRelation relation = relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
  332. .eq(GroupsRelation::getAccount, account).last("limit 1"));
  333. if (relation != null) {
  334. builder.field(ExcelOrderMasterDonData::getUserId, relation.getUserId());
  335. } else {
  336. builder.field(ExcelOrderMasterDonData::getUserId).op(Operator.IsNull);
  337. }
  338. }
  339. if (StrUtil.isNotBlank(showId)) {
  340. builder.field(ExcelOrderMasterDonData::getUserId, userService.getUserIdByShowId(showId));
  341. }
  342. if (StrUtil.isNotBlank(conditionSql)) {
  343. builder.put("condition", conditionSql);
  344. }
  345. List<ExcelOrderMasterDonData> mOrderList = beanSearcher.searchAll(ExcelOrderMasterDonData.class, builder.build());
  346. mOrderList = cmsOrderDonService.exportMOrders(mOrderList);
  347. List<ExcelOrderMasterDonData> collect = mOrderList.stream().sorted(Comparator.comparing(ExcelOrderMasterDonData::getOrderId)).collect(Collectors.toList());
  348. response.setContentType("application/x-download");
  349. response.setContentType("application/vnd.ms-excel");
  350. response.setCharacterEncoding("utf-8");
  351. response.setHeader("Content-disposition",
  352. "attachment;filename=" + new String("订单列表".getBytes("utf-8"), "ISO-8859-1") + ExcelTypeEnum.XLS.getValue());
  353. EasyExcel.write(response.getOutputStream())
  354. .head(ExcelOrderMasterDonData.class)
  355. //设置合并单元格策略
  356. .registerWriteHandler(new CustomMergeStrategy(collect.size(), ExcelOrderMasterDonData.class))
  357. .excelType(ExcelTypeEnum.XLS)
  358. .sheet("订单列表")
  359. .doWrite(collect);
  360. }
  361. /**
  362. * 导出实物模板 订单excel
  363. */
  364. @GetMapping("/export/mOrder/realGoods")
  365. public void exportMorderRealGoods(HttpServletResponse response, Long channelId, String account, String showId, Boolean isNoBind, Integer dsType, @RequestParam(value = "orderStatus", required = false) List<String> orderStatus) throws Exception {
  366. StringBuilder conditionSb = new StringBuilder();
  367. if (isNoBind != null) {
  368. String f = isNoBind ? "=" : "!=";
  369. conditionSb.append(String.format(" and os.ex_code != '' and os.user_id %s 0", f));
  370. }
  371. if (dsType != null) {
  372. //默认优惠券
  373. String dsTypeField = "coupon_user_id";
  374. if (dsType == 2) {
  375. dsTypeField = "balance";
  376. } else if (dsType == 3) {
  377. dsTypeField = "galaxycoin";
  378. }
  379. conditionSb.append(String.format(" and os.%s != 0", dsTypeField));
  380. }
  381. if (orderStatus != null) {
  382. conditionSb.append(String.format(" and os.status in %s", Jsons.toJson(orderStatus).replaceAll("\\[", "(").replaceAll("]", ")")));
  383. }
  384. String conditionSql = null;
  385. //主订单
  386. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  387. if (channelId != null) {
  388. List<Long> popularizeIds = channelPopularizeMapper.getPopularizeIdByChannelId(channelId);
  389. builder.field(ExcelRealGoodsMOrderData::getPopularizeId, popularizeIds).op(Operator.InList);
  390. }
  391. if (StrUtil.isNotBlank(account)) {
  392. GroupsRelation relation = relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
  393. .eq(GroupsRelation::getAccount, account).last("limit 1"));
  394. if (relation != null) {
  395. builder.field(ExcelRealGoodsMOrderData::getUserId, relation.getUserId());
  396. } else {
  397. builder.field(ExcelRealGoodsMOrderData::getUserId).op(Operator.IsNull);
  398. }
  399. }
  400. if (StrUtil.isNotBlank(showId)) {
  401. builder.field(ExcelRealGoodsMOrderData::getUserId, userService.getUserIdByShowId(showId));
  402. }
  403. if (StrUtil.isNotBlank(conditionSql)) {
  404. builder.put("condition", conditionSql);
  405. }
  406. List<ExcelRealGoodsMOrderData> list = beanSearcher.searchAll(ExcelRealGoodsMOrderData.class, builder
  407. .field(ExcelRealGoodsMOrderData::getGoodsDonType, Constant.realGoodsType).op(Operator.InList)
  408. .build());
  409. list.forEach(data -> {
  410. data.setPayType("寄付现结");
  411. if (data.getGoodsDonType() == Constant.realGoodsType.get(0)) {
  412. data.setRealGoodName("路由器");
  413. } else if (data.getGoodsDonType() == Constant.realGoodsType.get(1)) {
  414. data.setRealGoodName("银河潮玩");
  415. }
  416. });
  417. EasyExcelUtils.createExcelStreamMutilByEasyExcel(response, ExcelRealGoodsOrderData.class, list, "实物订单列表", "实物订单列表", ExcelTypeEnum.XLSX, null);
  418. }
  419. /**
  420. * 导出实物模板 订单excel
  421. */
  422. @GetMapping("/export/realGoods")
  423. public void exportRealGoods(HttpServletResponse response) {
  424. List<ExcelRealGoodsOrderData> list = beanSearcher.searchAll(ExcelRealGoodsOrderData.class, MapUtils.flatBuilder(request.getParameterMap())
  425. .field(ExcelOrderDonData::getGoodsDonType, Constant.realGoodsType).op(Operator.InList)
  426. .build());
  427. list.forEach(data -> {
  428. data.setPayType("寄付现结");
  429. if (data.getGoodsDonType() == Constant.realGoodsType.get(0)) {
  430. data.setRealGoodName("路由器");
  431. } else if (data.getGoodsDonType() == Constant.realGoodsType.get(1)) {
  432. data.setRealGoodName("银河潮玩");
  433. }
  434. });
  435. EasyExcelUtils.createExcelStreamMutilByEasyExcel(response, ExcelRealGoodsOrderData.class, list, "实物订单列表", "实物订单列表", ExcelTypeEnum.XLSX, null);
  436. }
  437. @PutMapping("/update/status")
  438. public Result<String> upStatus(@RequestBody OrderDon orderDon){
  439. cmsOrderDonService.update(Wrappers.lambdaUpdate(OrderDon.class).eq(OrderDon::getId,orderDon.getId()).set(OrderDon::getStatus,orderDon.getStatus()));
  440. return GatewayResponse.SUCCESS.newBuilder().toResult();
  441. }
  442. /**
  443. * 编辑自定义订阅节点
  444. */
  445. @PutMapping("/update/subNode")
  446. public Result<String> updateSubNode(@RequestBody OrderDon orderDon) {
  447. OrderDon en = cmsOrderDonService.getById(orderDon.getId());
  448. if (en != null) {
  449. en.setSubNode(orderDon.getSubNode());
  450. cmsOrderDonService.updateById(en);
  451. }
  452. return GatewayResponse.SUCCESS.newBuilder().toResult();
  453. }
  454. @GetMapping("/get/transport/{orderId}")
  455. public Result<OrderDonTransportView> getTransport(@PathVariable Long orderId){
  456. // OrderDonTransport transport = cmsOrderDonService.getTransport(orderId);
  457. OrderDonTransportView transportView = beanSearcher.searchFirst(OrderDonTransportView.class, MapUtils.builder().field(OrderDonTransportView::getOrderId, orderId).build());
  458. return GatewayResponse.SUCCESS.newBuilder().toResult(transportView);
  459. }
  460. @PostMapping("/post/setWaybill")
  461. public Result<OrderDonWaybill> setWaybill(@RequestBody ReqSetLogisticsPost reqSetLogisticsPost){
  462. OrderDonWaybill orderDonWaybill = cmsOrderDonService.setWaybill(reqSetLogisticsPost);
  463. return GatewayResponse.SUCCESS.newBuilder().toResult(orderDonWaybill);
  464. }
  465. /**
  466. * 用户购买实物商品意愿列表
  467. */
  468. @GetMapping("/get/realGooods/interest/users")
  469. @SaCheckPermission("interest:view")
  470. public Result<SearchResult> getInterestUserList(RealGoodsInterestUser.Status interestStatus, HttpServletRequest request) {
  471. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  472. SearchResult<RealGoodsInterestUserView> search;
  473. if (interestStatus == null) {
  474. builder.field(RealGoodsInterestUserView::getInterestStatus, "hasPayment").op(Operator.NotEqual);
  475. search = beanSearcher.search(RealGoodsInterestUserView.class, builder.build());
  476. } else if (interestStatus != RealGoodsInterestUser.Status.hasPayment) {
  477. builder.field(RealGoodsInterestUserView::getInterestStatus, interestStatus.name());
  478. search = beanSearcher.search(RealGoodsInterestUserView.class, builder.build());
  479. } else {
  480. search = new SearchResult<>();
  481. SearchResult<RealGoodsInterestUserHasPaymentView> search2 = beanSearcher.search(RealGoodsInterestUserHasPaymentView.class, builder.build());
  482. search.setTotalCount(search2.getTotalCount());
  483. List<RealGoodsInterestUserView> dataList = search.getDataList();
  484. dataList.addAll(search2.getDataList());
  485. }
  486. search.getDataList().forEach(data -> {
  487. Long goodsId = data.getGoodsId();
  488. 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"));
  489. if (order != null) {
  490. data.setOrderId(order.getId());
  491. data.setSkuId(order.getSkuId());
  492. data.setMoney(order.getMoney());
  493. realGoodsInterestUserMapper.updateData(data.getId(), data.getSkuId(), data.getOrderCreatedTime(), data.getOrderId());
  494. }
  495. });
  496. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  497. }
  498. /**
  499. * 修改订单状态
  500. */
  501. @PutMapping("/put/status/{orderId}")
  502. public Result<String> updateOrderStatus(@PathVariable Long orderId) {
  503. OrderDon orderDon = cmsOrderDonService.getById(orderId);
  504. if (orderDon == null) {
  505. throw BusinessRuntimeException.getInstance("该订单不存在");
  506. }
  507. if (orderDon.getStatus() == OrderDon.Status.complete) {
  508. throw BusinessRuntimeException.getInstance("该订单已是已完成状态");
  509. }
  510. if (orderDon.getStatus() != OrderDon.Status.hasPayment) {
  511. throw BusinessRuntimeException.getInstance("该订单不是未支付状态");
  512. }
  513. orderDon.setStatus(OrderDon.Status.complete);
  514. cmsOrderDonService.updateById(orderDon);
  515. return GatewayResponse.SUCCESS.newBuilder().toResult("修改订单状态成功");
  516. }
  517. /**
  518. * 修改购买意愿记录
  519. */
  520. @PutMapping("/put/interest")
  521. public Result<String> updateInterest(@RequestBody @Validated UserRealGoodsInterestReq req) {
  522. RealGoodsInterestUser realGoodsInterestUser = realGoodsInterestUserMapper.selectById(req.getId());
  523. if (realGoodsInterestUser != null) {
  524. if (req.getStatus() != null) {
  525. realGoodsInterestUser.setInterestStatus(req.getStatus());
  526. }
  527. if (req.getRemark() != null) {
  528. realGoodsInterestUser.setRemark(req.getRemark());
  529. }
  530. realGoodsInterestUserMapper.updateById(realGoodsInterestUser);
  531. }
  532. return GatewayResponse.SUCCESS.newBuilder().toResult("修改成功");
  533. }
  534. /**
  535. * 导出用户意愿列表
  536. */
  537. @GetMapping("/export/interest")
  538. public void exportInterest(RealGoodsInterestUser.Status interestStatus, HttpServletRequest request, HttpServletResponse response) {
  539. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  540. List<ExcelRealGoodsUserInterestData> excelRealGoodsUserInterestData;
  541. if (interestStatus == null) {
  542. builder.field(RealGoodsInterestUserView::getInterestStatus, "hasPayment").op(Operator.NotEqual);
  543. excelRealGoodsUserInterestData = beanSearcher.searchAll(ExcelRealGoodsUserInterestData.class, builder.build());
  544. } else {
  545. List<ExcelRealGoodsUserInterestHasPaymentData> excelRealGoodsUserInterestData2 = beanSearcher.searchAll(ExcelRealGoodsUserInterestHasPaymentData.class, builder.build());
  546. excelRealGoodsUserInterestData = new ArrayList<>(excelRealGoodsUserInterestData2);
  547. }
  548. excelRealGoodsUserInterestData.forEach(data -> {
  549. Long goodsId = data.getGoodsId();
  550. 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"));
  551. if (order != null) {
  552. data.setOrderId(order.getId());
  553. data.setSkuId(order.getSkuId());
  554. data.setMoney(order.getMoney());
  555. realGoodsInterestUserMapper.updateData(data.getId(), data.getSkuId(), data.getOrderCreatedTime(), data.getOrderId());
  556. }
  557. data.setMoney(data.getMoney().divide(BigDecimal.valueOf(100)));
  558. });
  559. EasyExcelUtils.createExcelStreamMutilByEasyExcel(response, ExcelRealGoodsUserInterestHasPaymentData.class, excelRealGoodsUserInterestData, "用户意愿列表", "用户意愿列表", ExcelTypeEnum.XLSX, null);
  560. }
  561. /**
  562. * 实物订单配置售前售后客户
  563. */
  564. @PostMapping("/put/realGoods/service")
  565. @NoSubmit
  566. @Log(module = "订单管理/售前、售后客服", businessType = BusinessType.PUT, isSaveRequestData = true)
  567. public Result<String> putRealGoodsService(@RequestBody @Validated RealGoodsServiceReq request) {
  568. OrderDon orderDon = cmsOrderDonService.getById(request.getOrderId());
  569. if (orderDon == null || orderDon.getRelationId() != 0) {
  570. throw BusinessRuntimeException.getInstance("该订单不是实物订单");
  571. }
  572. Boolean isBefore = false;
  573. Boolean isAfter = false;
  574. RealGoodsOrderHandle realGoodsOrderHandle = Optional.ofNullable(realGoodsOrderHandleMapper.selectOne(Wrappers.lambdaQuery(RealGoodsOrderHandle.class).eq(RealGoodsOrderHandle::getOrderId, request.getOrderId()).last("limit 1"))).orElse(new RealGoodsOrderHandle());
  575. if (StringUtils.isNotBlank(request.getBeforeServiceName())) {
  576. realGoodsOrderHandle.setBeforeServiceName(request.getBeforeServiceName());
  577. isBefore = true;
  578. }
  579. if (StringUtils.isNotBlank(request.getAfterServiceName())) {
  580. realGoodsOrderHandle.setAfterServiceName(request.getAfterServiceName());
  581. isAfter = true;
  582. }
  583. if (realGoodsOrderHandle.getId() == null) {
  584. realGoodsOrderHandle.setOrderId(request.getOrderId());
  585. realGoodsOrderHandleMapper.insert(realGoodsOrderHandle);
  586. } else {
  587. if (realGoodsOrderHandle.getBeforeOpNum() > 2) {
  588. throw BusinessRuntimeException.getInstance("售前客服已两次修改");
  589. }
  590. if (realGoodsOrderHandle.getAfterOpNum() > 2) {
  591. throw BusinessRuntimeException.getInstance("售后客服已两次修改");
  592. }
  593. if (isBefore) {
  594. realGoodsOrderHandle.setBeforeOpNum(realGoodsOrderHandle.getBeforeOpNum() + 1);
  595. }
  596. if (isAfter) {
  597. realGoodsOrderHandle.setAfterOpNum(realGoodsOrderHandle.getAfterOpNum() + 1);
  598. }
  599. realGoodsOrderHandleMapper.updateById(realGoodsOrderHandle);
  600. }
  601. return GatewayResponse.SUCCESS.newBuilder().toResult("操作成功");
  602. }
  603. /**
  604. * 新增平台评论
  605. */
  606. @PostMapping("/post/orderComment")
  607. public Result<String> insertOrderComment(@RequestBody @Validated OrderComment orderComment) {
  608. if (StrUtil.isEmpty(orderComment.getHeadImgUrl())) {
  609. orderComment.setHeadImgUrl(Constant.DEFAULT_HEAD_IMG);
  610. }
  611. if (orderComment.getCommentTime() == null) {
  612. orderComment.setCommentTime(DateTime.now().toDateStr());
  613. }
  614. orderComment.setVerifyStatus(OrderComment.VerifyStatus.success);
  615. orderCommentMapper.insert(orderComment);
  616. return GatewayResponse.SUCCESS.newBuilder().toResult("新增成功");
  617. }
  618. /**
  619. * 编辑平台评论
  620. */
  621. @PutMapping("/put/orderComment")
  622. public Result<String> updateOrderComment(@RequestBody @Validated OrderComment orderComment) {
  623. if (orderComment.getCommentTime() == null) {
  624. orderComment.setCommentTime(DateTime.now().toDateStr());
  625. }
  626. if (orderComment.getVerifyStatus() == null) {
  627. orderComment.setVerifyStatus(OrderComment.VerifyStatus.success);
  628. }
  629. orderCommentMapper.updateById(orderComment);
  630. return GatewayResponse.SUCCESS.newBuilder().toResult("编辑成功");
  631. }
  632. /**
  633. * 删除平台评论
  634. */
  635. @DeleteMapping("/delete/orderComment/{id}")
  636. public Result<String> deleteOrderCommentById(@PathVariable Long id) {
  637. orderCommentMapper.deleteById(id);
  638. return GatewayResponse.SUCCESS.newBuilder().toResult("删除成功");
  639. }
  640. /**
  641. * 平台评论列表
  642. */
  643. @GetMapping("/get/orderComment")
  644. public Result<SearchResult<OrderCommentView>> getOrderCommentView() {
  645. SearchResult<OrderCommentView> search = beanSearcher.search(OrderCommentView.class, MapUtils.flatBuilder(request.getParameterMap()).build());
  646. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  647. }
  648. /**
  649. * 评论审核
  650. */
  651. @PutMapping("/put/orderComment/status")
  652. @NoSubmit
  653. public Result<String> updateOrderCommentStatus(@RequestBody OrderComment orderCommentReq) throws Exception {
  654. orderDonCommentService.verifyCommentStatus(orderCommentReq.getId(), orderCommentReq.getVerifyStatus());
  655. return GatewayResponse.SUCCESS.newBuilder().toResult();
  656. }
  657. /**
  658. * 配置订单平台评价列表
  659. */
  660. @PostMapping("/post/orderComment/reward/config")
  661. public Result<String> saveOrUpdateOrderCommentConfig(@RequestBody List<OrderCommentRewardConfig> configs) {
  662. orderDonCommentService.saveOrUpdateOrderCommentConfig(configs);
  663. return GatewayResponse.SUCCESS.newBuilder().toResult();
  664. }
  665. /**
  666. * 获取配置 订单平台评价
  667. */
  668. @GetMapping("/get/orderComment/reward/config")
  669. public Result<List<OrderCommentRewardConfigView>> getOrderCommentRewardConfig() {
  670. List<OrderCommentRewardConfigView> views = beanSearcher.searchAll(OrderCommentRewardConfigView.class, MapUtils.builder()
  671. .orderBy(OrderCommentRewardConfigView::getGoodsId).desc()
  672. .build());
  673. return GatewayResponse.SUCCESS.newBuilder().toResult(views);
  674. }
  675. /**
  676. * 踢出车队
  677. */
  678. @PutMapping("/kickOut")
  679. @NoSubmit
  680. public Result<String> kickOut(@RequestBody @Validated ClickOutReq req) {
  681. long adminId = StpUtil.getLoginIdAsLong();
  682. cmsOrderDonService.kickOutRelationId(adminId, req);
  683. return GatewayResponse.SUCCESS.newBuilder().toResult();
  684. }
  685. /**
  686. * 踢出车队列表
  687. */
  688. @GetMapping("/get/kickOut/list")
  689. public Result<SearchResult<UserKickOutView>> getKickOutList() {
  690. SearchResult<UserKickOutView> search = beanSearcher.search(UserKickOutView.class, MapUtils.flatBuilder(request.getParameterMap()).build());
  691. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  692. }
  693. /**
  694. * 客服修改订单来源
  695. */
  696. @PutMapping("/update/order/source")
  697. public Result<String> updateOrderSource(@RequestBody OrderDon orderDon) {
  698. Long id = orderDon.getId();
  699. String labelSource = orderDon.getLabelSource();
  700. cmsOrderDonService.update(null, Wrappers.lambdaUpdate(OrderDon.class)
  701. .set(OrderDon::getLabelSource, labelSource)
  702. .eq(OrderDon::getId, id));
  703. realGoodsOrderHandleMapper.update(null, Wrappers.lambdaUpdate(RealGoodsOrderHandle.class)
  704. .set(RealGoodsOrderHandle::getLabelSource, labelSource)
  705. .eq(RealGoodsOrderHandle::getOrderId, id));
  706. return GatewayResponse.SUCCESS.newBuilder().toResult();
  707. }
  708. /**
  709. * 设置实物订单电视机类型
  710. */
  711. @PutMapping("/update/order/tvType")
  712. public Result<String> updateOrderTvType(@RequestBody OrderDon orderDon) {
  713. Integer tvType = orderDon.getTvType();
  714. Long id = orderDon.getId();
  715. cmsOrderDonService.update(null, Wrappers.lambdaUpdate(OrderDon.class)
  716. .set(OrderDon::getTvType, tvType)
  717. .eq(OrderDon::getId, id));
  718. return GatewayResponse.SUCCESS.newBuilder().toResult();
  719. }
  720. /**
  721. * 订单统一退款
  722. */
  723. @PostMapping("/unified/refund")
  724. @Log(module = "订单管理/统一退款", businessType = BusinessType.PUT, isSaveRequestData = true)
  725. public Result<String> unifiedRefund(@RequestBody @Validated OrderRefundReq refundReq) throws Exception {
  726. cmsOrderDonService.unifiedRefund(refundReq);
  727. return GatewayResponse.SUCCESS.newBuilder().toResult("退款成功");
  728. }
  729. /**
  730. * 微信退款回调
  731. */
  732. @PostMapping("/wx/refund/notify")
  733. public void wxRefundNotify(HttpServletRequest request, HttpServletResponse response) throws Exception {
  734. String xml = IoKit.toString(request.getInputStream());
  735. log.info("=== 退款成功的回调: \n {}", xml);
  736. // 解析xml
  737. Map<String, String> map = Xmls.toMap(xml);
  738. // 退款失败
  739. if (!StrUtil.equals("SUCCESS", map.get("return_code"))) {
  740. throw BusinessRuntimeException.getInstance("退款失败.");
  741. }
  742. cmsOrderDonService.wxRefundNotify(map);
  743. String toWechatXmlResponse = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
  744. OutputStream out = null;
  745. try {
  746. out = response.getOutputStream();
  747. IoKit.write(toWechatXmlResponse, out);
  748. } catch (Throwable e) {
  749. throw BusinessRuntimeException.getInstance(e == null ? null : e.getMessage());
  750. } finally {
  751. IoKit.close(out);
  752. }
  753. }
  754. /**
  755. * 更换用户车票
  756. */
  757. @PutMapping("/put/sameSpec/empty/relation")
  758. public Result<String> changeRelation(@RequestBody @Validated ChangeRelationReq req) throws Exception {
  759. cmsOrderDonService.changeRelation(req);
  760. return GatewayResponse.SUCCESS.newBuilder().toResult();
  761. }
  762. /**
  763. * 多余车位的空账号
  764. */
  765. @GetMapping("/get/sameSpec/empty/relation")
  766. public Result<SearchResult<EmptyGroupsRelationView>> getSameSpecEmptyRelation(Long skuId, Long groupsId, Long relationId, Boolean isNormal) {
  767. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap())
  768. .field(EmptyGroupsRelationView::getStatus, GroupsTrips.Status.down.name()).op(Operator.NotEqual)
  769. .field(EmptyGroupsRelationView::getSkuId, skuId).orderBy(EmptyGroupsRelationView::getAvailableNum)
  770. .desc();
  771. Date expiryTime = null;
  772. if (relationId != null) {
  773. GroupsRelation relation = relationMapper.selectById(relationId);
  774. if (relation != null) expiryTime = relation.getExpiryTime();
  775. }
  776. if (groupsId != null) {
  777. builder.field(EmptyGroupsRelationView::getGroupsId, groupsId).op(Operator.NotEqual);
  778. }
  779. if (isNormal != null && isNormal) {
  780. builder.put("account_id", String.format("gt.account_id not in (select account_id from work_order where sku_id = %s and account_id is not null)", skuId));
  781. }
  782. if (expiryTime != null) {
  783. builder.field(AccountView::getExpiryTime, expiryTime).op(Operator.GreaterEqual);
  784. builder.orderBy(AccountView::getExpiryTime).asc();
  785. }
  786. GoodsDonSku sku = skuMapper.selectById(skuId);
  787. if (!Constant.AI_goodsIds.contains(sku.getGoodsId())) {
  788. builder.field(EmptyGroupsRelationView::getAvailableNum, 0).op(Operator.GreaterThan);
  789. }
  790. SearchResult<EmptyGroupsRelationView> search = beanSearcher.search(EmptyGroupsRelationView.class,
  791. builder.build());
  792. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  793. }
  794. /**
  795. * 订单补差价,补差价退款到余额
  796. */
  797. @PutMapping("/refund/price/differ")
  798. @Log(module = "订单管理/订单补差价", businessType = BusinessType.PUT, isSaveRequestData = true)
  799. public Result<String> refundPriceDiffer(@RequestBody OrderRefundReq orderRefundReq) {
  800. cmsOrderDonService.refundPriceDiffer(orderRefundReq);
  801. return GatewayResponse.SUCCESS.newBuilder().toResult();
  802. }
  803. }