| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091 |
- package com.cyksj.web.controller.manage;
- import cn.dev33.satoken.annotation.SaCheckPermission;
- import cn.dev33.satoken.stp.StpUtil;
- import cn.hutool.core.collection.CollUtil;
- import cn.hutool.core.date.DateTime;
- import cn.hutool.core.date.DateUtil;
- import cn.hutool.core.util.ObjectUtil;
- import cn.hutool.core.util.StrUtil;
- import com.alibaba.excel.EasyExcel;
- import com.alibaba.excel.support.ExcelTypeEnum;
- import com.baomidou.mybatisplus.core.toolkit.Wrappers;
- import com.cyksj.common.annotation.Log;
- import com.cyksj.common.annotation.NoSubmit;
- import com.cyksj.common.constant.Constant;
- import com.cyksj.common.exception.BusinessRuntimeException;
- import com.cyksj.common.util.IoKit;
- import com.cyksj.common.util.Xmls;
- import com.cyksj.dto.Result;
- import com.cyksj.enums.BusinessType;
- import com.cyksj.enums.GatewayApiCode;
- import com.cyksj.enums.GatewayResponse;
- import com.cyksj.mapper.*;
- import com.cyksj.mapper.channel.ChannelPopularizeMapper;
- import com.cyksj.mapper.channel.UserPayEquipmentAvailableBenefitsMapper;
- import com.cyksj.mapper.channel.UserPayEquipmentReceiveBenefitsRecordMapper;
- import com.cyksj.mapper.manage.RealGoodsOrderHandleMapper;
- import com.cyksj.mapper.manage.cms.CmsUserMapper;
- import com.cyksj.mapper.manage.coupon.CouponMapper;
- import com.cyksj.mapper.shop.YhShopMapper;
- import com.cyksj.model.dto.OriSkuDto;
- import com.cyksj.model.dto.RenewOriOrderSkuDto;
- import com.cyksj.model.entity.*;
- import com.cyksj.model.excel.*;
- import com.cyksj.model.manage.request.ReqSetLogisticsPost;
- import com.cyksj.model.manage.views.AccountView;
- import com.cyksj.model.manage.views.OrderDonBackView;
- import com.cyksj.model.manage.views.UpgradeOrderDonBackView;
- import com.cyksj.model.request.*;
- import com.cyksj.model.views.*;
- import com.cyksj.service.mange.CmsOrderDonService;
- import com.cyksj.service.order.OrderDonCommentService;
- import com.cyksj.service.user.UserBindRelationService;
- import com.cyksj.service.user.UserService;
- import com.cyksj.web.util.EasyExcelUtils;
- import com.ejlchina.searcher.BeanSearcher;
- import com.ejlchina.searcher.SearchResult;
- import com.ejlchina.searcher.param.Operator;
- import com.ejlchina.searcher.util.MapBuilder;
- import com.ejlchina.searcher.util.MapUtils;
- import lombok.RequiredArgsConstructor;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.dao.DuplicateKeyException;
- import org.springframework.validation.annotation.Validated;
- import org.springframework.web.bind.annotation.*;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import java.io.IOException;
- import java.io.OutputStream;
- import java.math.BigDecimal;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * @author chan
- * @date 2021/10/12 下午11:05
- */
- @Slf4j
- @RequestMapping("/manage/order")
- @RestController
- @RequiredArgsConstructor
- public class CmsOrderController {
- private final HttpServletRequest request;
- private final CmsOrderDonService cmsOrderDonService;
- private final UserService userService;
- private final BeanSearcher beanSearcher;
- private final RealGoodsInterestUserMapper realGoodsInterestUserMapper;
- private final RealGoodsOrderHandleMapper realGoodsOrderHandleMapper;
- private final CouponMapper couponMapper;
- private final OrderCommentMapper orderCommentMapper;
- private final OrderDonCommentService orderDonCommentService;
- private final GoodsDonSkuMapper skuMapper;
- private final ChannelPopularizeMapper channelPopularizeMapper;
- private final GroupsRelationMapper relationMapper;
- private final UserPayEquipmentReceiveBenefitsRecordMapper receiveBenefitsRecordMapper;
- private final UserPayEquipmentAvailableBenefitsMapper availableBenefitsMapper;
- private final YhShopMapper yhShopMapper;
- private final CmsUserMapper cmsUserMapper;
- private final UserMapper userMapper;
- private final OrderDonMapper orderDonMapper;
- private final OrderDonCustomerServiceRelateMapper orderDonCustomerServiceRelateMapper;
- private final MidjourneyUserConversationMapper midjourneyUserConversationMapper;
- private final MidjourneyUserMapper midjourneyUserMapper;
- private final UserBindRelationService userBindRelationService;
- private final OrderDonRenewRecordMapper orderDonRenewRecordMapper;
- @GetMapping("/get")
- @SaCheckPermission("order:view")
- public Result<SearchResult<OrderDonBackView>> get(Long channelId, String account, String showId, Long acId, String nickname, String register, Boolean isGoogle, Boolean isSubsidy) {
- MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
- if (channelId != null) {
- List<Long> popularizeIds = channelPopularizeMapper.getPopularizeIdByChannelId(channelId);
- builder.field(OrderDonBackView::getPopularizeId, popularizeIds).op(Operator.InList);
- }
- if (StrUtil.isNotBlank(account)) {
- GroupsRelation relation = relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
- .eq(GroupsRelation::getAccount, account).last("limit 1"));
- if (relation != null) {
- builder.field(OrderDonBackView::getRelationId, relation.getId());
- } else {
- builder.field(OrderDonBackView::getRelationId).op(Operator.IsNull);
- }
- }
- if (StrUtil.isNotBlank(showId)) {
- builder.field(OrderDonBackView::getUserId, userService.getUserIdByShowId(showId));
- }
- String conditionSql = StrUtil.EMPTY;
- if (acId != null) {
- conditionSql += String.format(" o.user_id in (select user_id from corp_user where ac_id = %s)", acId);
- }
- if (!ObjectUtil.isAllEmpty(nickname, register, isGoogle)) {
- if (StrUtil.isNotEmpty(conditionSql)) {
- conditionSql += " and ";
- }
- conditionSql += " exists (select u.id from user u where u.id = o.user_id";
- if (StrUtil.isNotEmpty(nickname)) {
- conditionSql += String.format(" and u.nickname like '%s%%'", nickname);
- }
- if (StrUtil.isNotEmpty(register)) {
- if ("phone".equals(register)) {
- conditionSql += " and u.login_phone != ''";
- } else if ("email".equals(register)) {
- conditionSql += " and u.email != ''";
- } else if ("wechat".equals(register)) {
- conditionSql += " and u.unionid != ''";
- }
- }
- if (isGoogle != null && isGoogle) {
- conditionSql += String.format(" and u.is_google is %s", isGoogle);
- }
- conditionSql += " limit 1)";
- }
- if (isSubsidy != null) {
- if (StrUtil.isNotEmpty(conditionSql)) {
- conditionSql += " and ";
- }
- conditionSql += " exists (select 1 from order_don_subsidy_relate ocr where ocr.order_id = o.id limit 1)";
- }
- if (StrUtil.isNotBlank(conditionSql)) {
- builder.put("condition", conditionSql);
- }
- SearchResult<OrderDonBackView> search = beanSearcher.search(OrderDonBackView.class, builder.build());
- search.getDataList().forEach(data -> {
- if (data.getPopularizeId() != null) {
- Optional.ofNullable(channelPopularizeMapper.selectChannelByPid(data.getPopularizeId()))
- .ifPresent(channelName -> data.setChannel(channelName));
- }
- if (data.getGoodsDonType() != null && Constant.realGoodsType.contains(data.getGoodsDonType())) {
- RealGoodsOrderHandle realGoodsOrderHandle = realGoodsOrderHandleMapper.selectOne(Wrappers.lambdaQuery(RealGoodsOrderHandle.class).eq(RealGoodsOrderHandle::getOrderId, data.getId()).last("limit 1"));
- if (realGoodsOrderHandle != null) {
- data.setBeforeServiceName(realGoodsOrderHandle.getBeforeServiceName());
- data.setAfterServiceName(realGoodsOrderHandle.getAfterServiceName());
- }
- }
- if (data.getCouponUserId() != 0) {
- data.setCouponName(couponMapper.getCouponNameByCouponUserId(data.getCouponUserId()));
- data.setCouponMoney(data.getCouponMoney() == null ? BigDecimal.ZERO : data.getCouponMoney());
- }
- if (data.getRelationId() != 0) {
- Optional.ofNullable(relationMapper.getGroupRelationAccountView(data.getRelationId()))
- .ifPresent(e -> {
- data.setGtAccount(e.getTripsAccount());
- data.setAccount(e.getAccount());
- });
- }
- if (data.getIsBenefits() != null && data.getIsBenefits() && !Constant.noOrderAllStatus.contains(data.getStatus())) {
- //是否实物权益已发放
- Integer count = receiveBenefitsRecordMapper.selectCount(Wrappers.lambdaQuery(UserPayEquipmentReceiveBenefitsRecord.class)
- .eq(UserPayEquipmentReceiveBenefitsRecord::getRealOrderId, data.getId()));
- if (count == 0) {
- count = availableBenefitsMapper.selectCount(Wrappers.lambdaQuery(UserPayEquipmentAvailableBenefits.class)
- .eq(UserPayEquipmentAvailableBenefits::getRealOrderId, data.getId()));
- }
- data.setIsHasBenefits(count == 0 ? true : false);
- }
- if (data.getYhsId() != 0) {
- Optional.ofNullable(yhShopMapper.selectById(data.getYhsId()))
- .ifPresent(e -> {
- data.setShopName(e.getName());
- data.setCustomId(e.getCustomId());
- });
- }
- User user = userMapper.selectById(data.getUserId());
- if (user != null) {
- data.setNickname(user.getNickname());
- data.setLoginPhone(user.getLoginPhone());
- data.setEmail(user.getEmail());
- data.setRegister(StrUtil.isNotEmpty(user.getUnionid()) ? "wechat" : StrUtil.isNotEmpty(user.getLoginPhone()) ? "phone" : "email");
- }
- if (data.getGoodsDonType() != null && data.getGoodsDonType() == 1) {
- //获取订单关联客服
- Optional.ofNullable(orderDonMapper.selectOrderRelate(data.getId())).ifPresent(e -> {
- data.setCmsUserId(e.getCmsUserId());
- data.setNickname(e.getNickname());
- });
- }
- });
- return GatewayResponse.SUCCESS.newBuilder().toResult(search);
- }
- /**
- * 用户退款订单列表
- */
- @GetMapping("/get/refund/list")
- public Result<SearchResult<RefundOrderDonView>> getRefundOrderDonView() {
- SearchResult<RefundOrderDonView> search = beanSearcher.search(RefundOrderDonView.class, MapUtils.flatBuilder(request.getParameterMap())
- .build());
- search.getDataList().forEach(data -> {
- Optional.ofNullable(userService.getById(data.getUserId()))
- .ifPresent(user -> data.setNickname(user.getNickname()));
- });
- return GatewayResponse.SUCCESS.newBuilder().toResult(search);
- }
- /**
- * 镜像规格使用详情
- */
- @GetMapping("/get/order/mj/mirror/detail/{orderId}")
- public Result<MidjourneyUserDetailView> getMjMirrorOrderDetail(@PathVariable Long orderId) {
- OrderDon orderDon = orderDonMapper.selectById(orderId);
- //续费订单
- Date startTime = null;
- Date expiryTime = null;
- if (orderDon.getOrderType() == 2) {
- GoodsDonSku sku = skuMapper.selectById(orderDon.getSkuId());
- GroupsRelation relation = relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
- .eq(GroupsRelation::getId, orderDon.getRelationId())
- .eq(GroupsRelation::getUserId, orderDon.getUserId()).last("limit 1"));
- if (relation == null) {
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- startTime = relation.getStartTime();
- startTime = DateUtil.offsetMonth(startTime, sku.getMonths());
- expiryTime = relation.getExpiryTime();
- }
- MidjourneyUserDetailView midjourneyUserDetailView = midjourneyUserConversationMapper.getMjMirrorOrderDetail(orderDon.getRelationId(), startTime, expiryTime);
- return GatewayResponse.SUCCESS.newBuilder().toResult(midjourneyUserDetailView);
- }
- /**
- * 订单导出
- */
- @GetMapping("/export")
- @SaCheckPermission("order:export")
- @Log(module = "订单管理/导出订单", businessType = BusinessType.EXPORT, isSaveRequestData = true)
- public void exportOrders(HttpServletResponse response) {
- List<ExcelOrderDonData> list = beanSearcher.searchAll(ExcelOrderDonData.class, MapUtils.flatBuilder(request.getParameterMap()).build());
- list.forEach(data -> {
- data.setMoney(data.getMoney().divide(BigDecimal.valueOf(100)));
- OrderDon.Type type = data.getType();
- data.setTypeStr(type != null ? type.getDesc() : "");
- OrderDon.Status status = data.getStatus();
- data.setStatusStr(status != null ? status.getDesc() : "");
- if (data.getChannelId() == null) {
- data.setChannel("自然流量渠道");
- }
- if (data.getGoodsDonType() != null && Constant.realGoodsType.contains(data.getGoodsDonType())) {
- OrderDonTransportView transportView = beanSearcher.searchFirst(OrderDonTransportView.class, MapUtils.builder().field(OrderDonTransportView::getOrderId, data.getId()).build());
- if (transportView != null) {
- data.setTransportStr(String.format("%s%s%s%s", transportView.getProvince(), transportView.getCity(), transportView.getDistrict(), transportView.getAddress()));
- data.setPhone(transportView.getPhone());
- data.setReceiver(transportView.getReceiver());
- data.setCodeCn(transportView.getCodeCn());
- data.setTrackingNumber(transportView.getTrackingNumber());
- }
- RealGoodsOrderHandle realGoodsOrderHandle = realGoodsOrderHandleMapper.selectOne(Wrappers.lambdaQuery(RealGoodsOrderHandle.class).eq(RealGoodsOrderHandle::getOrderId, data.getId()).last("limit 1"));
- if (realGoodsOrderHandle != null) {
- data.setBeforeServiceName(realGoodsOrderHandle.getBeforeServiceName());
- data.setAfterServiceName(realGoodsOrderHandle.getAfterServiceName());
- }
- }
- if (data.getCouponUserId() != 0) {
- data.setCouponName(couponMapper.getCouponNameByCouponUserId(data.getCouponUserId()));
- data.setCouponMoney(data.getCouponMoney() == null ? BigDecimal.ZERO : data.getCouponMoney().divide(BigDecimal.valueOf(100)));
- }
- });
- EasyExcelUtils.createExcelStreamMutilByEasyExcel(response, ExcelOrderDonData.class, list, "订单列表", "订单列表", ExcelTypeEnum.XLSX, null);
- }
- /**
- * 导出实物模板 订单excel
- */
- @GetMapping("/export/realGoods")
- public void exportRealGoods(HttpServletResponse response) throws IOException {
- List<ExcelRealGoodsOrderData> list = beanSearcher.searchAll(ExcelRealGoodsOrderData.class, MapUtils.flatBuilder(request.getParameterMap())
- .field(ExcelOrderDonData::getGoodsDonType, Constant.realGoodsType).op(Operator.InList)
- .build());
- // AtomicInteger index = new AtomicInteger(1);
- list.forEach(data -> {
- data.setPayType("寄付现结");
- if (data.getGoodsDonType() == Constant.realGoodsType.get(0)) {
- data.setRealGoodName("路由器");
- } else if (data.getGoodsDonType() == Constant.realGoodsType.get(1)) {
- data.setRealGoodName("银河潮玩");
- }
- // data.setIndex(index.getAndIncrement());
- });
- if (CollUtil.isEmpty(list)) {
- throw BusinessRuntimeException.getInstance("导出数据为空");
- }
- response.setContentType("application/x-download");
- response.setContentType("application/vnd.ms-excel");
- response.setCharacterEncoding("utf-8");
- response.setHeader("Content-disposition",
- "attachment;filename=" + new String("实物订单列表".getBytes("utf-8"), "ISO-8859-1") + ExcelTypeEnum.XLS.getValue());
- EasyExcel.write(response.getOutputStream())
- .head(ExcelRealGoodsOrderData.class)
- //设置合并单元格策略
- // .registerWriteHandler(new RealGoodsOrderLineStrategy())
- .excelType(ExcelTypeEnum.XLS)
- .sheet("实物订单列表")
- //设置头部标题从那行开始
- // .relativeHeadRowIndex(2)
- .doWrite(list);
- }
- @PutMapping("/update/status")
- public Result<String> upStatus(@RequestBody OrderDon orderDon){
- cmsOrderDonService.update(Wrappers.lambdaUpdate(OrderDon.class).eq(OrderDon::getId,orderDon.getId()).set(OrderDon::getStatus,orderDon.getStatus()));
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- /**
- * 编辑自定义订阅节点
- */
- @PutMapping("/update/subNode")
- public Result<String> updateSubNode(@RequestBody OrderDon orderDon) {
- OrderDon en = cmsOrderDonService.getById(orderDon.getId());
- if (en != null) {
- en.setSubNode(orderDon.getSubNode());
- cmsOrderDonService.updateById(en);
- }
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- @GetMapping("/get/transport/{orderId}")
- public Result<OrderDonTransportView> getTransport(@PathVariable Long orderId){
- // OrderDonTransport transport = cmsOrderDonService.getTransport(orderId);
- OrderDonTransportView transportView = beanSearcher.searchFirst(OrderDonTransportView.class, MapUtils.builder().field(OrderDonTransportView::getOrderId, orderId).build());
- return GatewayResponse.SUCCESS.newBuilder().toResult(transportView);
- }
- @PostMapping("/post/setWaybill")
- public Result<OrderDonWaybill> setWaybill(@RequestBody ReqSetLogisticsPost reqSetLogisticsPost){
- OrderDonWaybill orderDonWaybill = cmsOrderDonService.setWaybill(reqSetLogisticsPost);
- return GatewayResponse.SUCCESS.newBuilder().toResult(orderDonWaybill);
- }
- /**
- * 用户购买实物商品意愿列表
- */
- @GetMapping("/get/realGooods/interest/users")
- @SaCheckPermission("interest:view")
- public Result<SearchResult> getInterestUserList(RealGoodsInterestUser.Status interestStatus, HttpServletRequest request) {
- MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
- SearchResult<RealGoodsInterestUserView> search;
- if (interestStatus == null) {
- builder.field(RealGoodsInterestUserView::getInterestStatus, "hasPayment").op(Operator.NotEqual);
- search = beanSearcher.search(RealGoodsInterestUserView.class, builder.build());
- } else if (interestStatus != RealGoodsInterestUser.Status.hasPayment) {
- builder.field(RealGoodsInterestUserView::getInterestStatus, interestStatus.name());
- search = beanSearcher.search(RealGoodsInterestUserView.class, builder.build());
- } else {
- search = new SearchResult<>();
- SearchResult<RealGoodsInterestUserHasPaymentView> search2 = beanSearcher.search(RealGoodsInterestUserHasPaymentView.class, builder.build());
- search.setTotalCount(search2.getTotalCount());
- List<RealGoodsInterestUserView> dataList = search.getDataList();
- dataList.addAll(search2.getDataList());
- }
- search.getDataList().forEach(data -> {
- Long goodsId = data.getGoodsId();
- 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"));
- if (order != null) {
- data.setOrderId(order.getId());
- data.setSkuId(order.getSkuId());
- data.setMoney(order.getMoney());
- realGoodsInterestUserMapper.updateData(data.getId(), data.getSkuId(), data.getOrderCreatedTime(), data.getOrderId());
- }
- });
- return GatewayResponse.SUCCESS.newBuilder().toResult(search);
- }
- /**
- * 修改订单状态
- */
- @PutMapping("/put/status/{orderId}")
- public Result<String> updateOrderStatus(@PathVariable Long orderId) {
- OrderDon orderDon = cmsOrderDonService.getById(orderId);
- if (orderDon == null) {
- throw BusinessRuntimeException.getInstance("该订单不存在");
- }
- if (orderDon.getStatus() == OrderDon.Status.complete) {
- throw BusinessRuntimeException.getInstance("该订单已是已完成状态");
- }
- if (orderDon.getStatus() != OrderDon.Status.hasPayment) {
- throw BusinessRuntimeException.getInstance("该订单不是未支付状态");
- }
- orderDon.setStatus(OrderDon.Status.complete);
- cmsOrderDonService.updateById(orderDon);
- return GatewayResponse.SUCCESS.newBuilder().toResult("修改订单状态成功");
- }
- /**
- * 修改购买意愿记录
- */
- @PutMapping("/put/interest")
- public Result<String> updateInterest(@RequestBody @Validated UserRealGoodsInterestReq req) {
- RealGoodsInterestUser realGoodsInterestUser = realGoodsInterestUserMapper.selectById(req.getId());
- if (realGoodsInterestUser != null) {
- if (req.getStatus() != null) {
- realGoodsInterestUser.setInterestStatus(req.getStatus());
- }
- if (req.getRemark() != null) {
- realGoodsInterestUser.setRemark(req.getRemark());
- }
- realGoodsInterestUserMapper.updateById(realGoodsInterestUser);
- }
- return GatewayResponse.SUCCESS.newBuilder().toResult("修改成功");
- }
- /**
- * 导出用户意愿列表
- */
- @GetMapping("/export/interest")
- public void exportInterest(RealGoodsInterestUser.Status interestStatus, HttpServletRequest request, HttpServletResponse response) {
- MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
- List<ExcelRealGoodsUserInterestData> excelRealGoodsUserInterestData;
- if (interestStatus == null) {
- builder.field(RealGoodsInterestUserView::getInterestStatus, "hasPayment").op(Operator.NotEqual);
- excelRealGoodsUserInterestData = beanSearcher.searchAll(ExcelRealGoodsUserInterestData.class, builder.build());
- } else {
- List<ExcelRealGoodsUserInterestHasPaymentData> excelRealGoodsUserInterestData2 = beanSearcher.searchAll(ExcelRealGoodsUserInterestHasPaymentData.class, builder.build());
- excelRealGoodsUserInterestData = new ArrayList<>(excelRealGoodsUserInterestData2);
- }
- excelRealGoodsUserInterestData.forEach(data -> {
- Long goodsId = data.getGoodsId();
- 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"));
- if (order != null) {
- data.setOrderId(order.getId());
- data.setSkuId(order.getSkuId());
- data.setMoney(order.getMoney());
- realGoodsInterestUserMapper.updateData(data.getId(), data.getSkuId(), data.getOrderCreatedTime(), data.getOrderId());
- }
- data.setMoney(data.getMoney().divide(BigDecimal.valueOf(100)));
- });
- EasyExcelUtils.createExcelStreamMutilByEasyExcel(response, ExcelRealGoodsUserInterestHasPaymentData.class, excelRealGoodsUserInterestData, "用户意愿列表", "用户意愿列表", ExcelTypeEnum.XLSX, null);
- }
- /**
- * 实物订单配置售前售后客户
- */
- @PostMapping("/put/realGoods/service")
- @NoSubmit
- @Log(module = "订单管理/售前、售后客服", businessType = BusinessType.PUT, isSaveRequestData = true)
- public Result<String> putRealGoodsService(@RequestBody @Validated RealGoodsServiceReq request) {
- OrderDon orderDon = cmsOrderDonService.getById(request.getOrderId());
- if (orderDon == null || orderDon.getRelationId() != 0) {
- throw BusinessRuntimeException.getInstance("该订单不是实物订单");
- }
- Boolean isBefore = false;
- Boolean isAfter = false;
- RealGoodsOrderHandle realGoodsOrderHandle = Optional.ofNullable(realGoodsOrderHandleMapper.selectOne(Wrappers.lambdaQuery(RealGoodsOrderHandle.class).eq(RealGoodsOrderHandle::getOrderId, request.getOrderId()).last("limit 1"))).orElse(new RealGoodsOrderHandle());
- if (StringUtils.isNotBlank(request.getBeforeServiceName())) {
- realGoodsOrderHandle.setBeforeServiceName(request.getBeforeServiceName());
- isBefore = true;
- }
- if (StringUtils.isNotBlank(request.getAfterServiceName())) {
- realGoodsOrderHandle.setAfterServiceName(request.getAfterServiceName());
- isAfter = true;
- }
- if (realGoodsOrderHandle.getId() == null) {
- realGoodsOrderHandle.setOrderId(request.getOrderId());
- realGoodsOrderHandleMapper.insert(realGoodsOrderHandle);
- } else {
- if (realGoodsOrderHandle.getBeforeOpNum() > 2) {
- throw BusinessRuntimeException.getInstance("售前客服已两次修改");
- }
- if (realGoodsOrderHandle.getAfterOpNum() > 2) {
- throw BusinessRuntimeException.getInstance("售后客服已两次修改");
- }
- if (isBefore) {
- realGoodsOrderHandle.setBeforeOpNum(realGoodsOrderHandle.getBeforeOpNum() + 1);
- }
- if (isAfter) {
- realGoodsOrderHandle.setAfterOpNum(realGoodsOrderHandle.getAfterOpNum() + 1);
- }
- realGoodsOrderHandleMapper.updateById(realGoodsOrderHandle);
- }
- return GatewayResponse.SUCCESS.newBuilder().toResult("操作成功");
- }
- /**
- * 新增平台评论
- */
- @PostMapping("/post/orderComment")
- public Result<String> insertOrderComment(@RequestBody @Validated OrderComment orderComment) {
- if (StrUtil.isEmpty(orderComment.getHeadImgUrl())) {
- orderComment.setHeadImgUrl(Constant.DEFAULT_HEAD_IMG);
- }
- if (orderComment.getCommentTime() == null) {
- orderComment.setCommentTime(DateTime.now().toDateStr());
- }
- orderComment.setVerifyStatus(OrderComment.VerifyStatus.success);
- orderCommentMapper.insert(orderComment);
- return GatewayResponse.SUCCESS.newBuilder().toResult("新增成功");
- }
- /**
- * 编辑平台评论
- */
- @PutMapping("/put/orderComment")
- public Result<String> updateOrderComment(@RequestBody @Validated OrderComment orderComment) {
- if (orderComment.getCommentTime() == null) {
- orderComment.setCommentTime(DateTime.now().toDateStr());
- }
- if (orderComment.getVerifyStatus() == null) {
- orderComment.setVerifyStatus(OrderComment.VerifyStatus.success);
- }
- orderCommentMapper.updateById(orderComment);
- return GatewayResponse.SUCCESS.newBuilder().toResult("编辑成功");
- }
- /**
- * 删除平台评论
- */
- @DeleteMapping("/delete/orderComment/{id}")
- public Result<String> deleteOrderCommentById(@PathVariable Long id) {
- orderCommentMapper.deleteById(id);
- return GatewayResponse.SUCCESS.newBuilder().toResult("删除成功");
- }
- /**
- * 平台评论列表
- */
- @GetMapping("/get/orderComment")
- public Result<SearchResult<OrderCommentView>> getOrderCommentView() {
- SearchResult<OrderCommentView> search = beanSearcher.search(OrderCommentView.class, MapUtils.flatBuilder(request.getParameterMap()).build());
- return GatewayResponse.SUCCESS.newBuilder().toResult(search);
- }
- /**
- * 评论审核
- */
- @PutMapping("/put/orderComment/status")
- @NoSubmit
- public Result<String> updateOrderCommentStatus(@RequestBody OrderComment orderCommentReq) throws Exception {
- orderDonCommentService.verifyCommentStatus(orderCommentReq.getId(), orderCommentReq.getVerifyStatus());
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- /**
- * 配置订单平台评价列表
- */
- @PostMapping("/post/orderComment/reward/config")
- public Result<String> saveOrUpdateOrderCommentConfig(@RequestBody List<OrderCommentRewardConfig> configs) {
- orderDonCommentService.saveOrUpdateOrderCommentConfig(configs);
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- /**
- * 获取配置 订单平台评价
- */
- @GetMapping("/get/orderComment/reward/config")
- public Result<List<OrderCommentRewardConfigView>> getOrderCommentRewardConfig() {
- List<OrderCommentRewardConfigView> views = beanSearcher.searchAll(OrderCommentRewardConfigView.class, MapUtils.builder()
- .orderBy(OrderCommentRewardConfigView::getGoodsId).desc()
- .build());
- return GatewayResponse.SUCCESS.newBuilder().toResult(views);
- }
- /**
- * 踢出车队
- */
- @PutMapping("/kickOut")
- @NoSubmit
- public Result<String> kickOut(@RequestBody @Validated ClickOutReq req) {
- long adminId = StpUtil.getLoginIdAsLong();
- cmsOrderDonService.kickOutRelationId(adminId, req);
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- /**
- * 踢出车队列表
- */
- @GetMapping("/get/kickOut/list")
- public Result<SearchResult<UserKickOutView>> getKickOutList() {
- SearchResult<UserKickOutView> search = beanSearcher.search(UserKickOutView.class, MapUtils.flatBuilder(request.getParameterMap()).build());
- return GatewayResponse.SUCCESS.newBuilder().toResult(search);
- }
- /**
- * 客服修改订单来源
- */
- @PutMapping("/update/order/source")
- public Result<String> updateOrderSource(@RequestBody OrderDon orderDon) {
- Long id = orderDon.getId();
- String labelSource = orderDon.getLabelSource();
- cmsOrderDonService.update(null, Wrappers.lambdaUpdate(OrderDon.class)
- .set(OrderDon::getLabelSource, labelSource)
- .eq(OrderDon::getId, id));
- realGoodsOrderHandleMapper.update(null, Wrappers.lambdaUpdate(RealGoodsOrderHandle.class)
- .set(RealGoodsOrderHandle::getLabelSource, labelSource)
- .eq(RealGoodsOrderHandle::getOrderId, id));
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- /**
- * 设置实物订单电视机类型
- */
- @PutMapping("/update/order/tvType")
- public Result<String> updateOrderTvType(@RequestBody OrderDon orderDon) {
- Integer tvType = orderDon.getTvType();
- Long id = orderDon.getId();
- cmsOrderDonService.update(null, Wrappers.lambdaUpdate(OrderDon.class)
- .set(OrderDon::getTvType, tvType)
- .eq(OrderDon::getId, id));
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- /**
- * 订单统一退款
- */
- @PostMapping("/unified/refund")
- @Log(module = "订单管理/统一退款", businessType = BusinessType.PUT, isSaveRequestData = true)
- public Result<String> unifiedRefund(@RequestBody @Validated OrderRefundReq refundReq) throws Exception {
- long adminId = StpUtil.getLoginIdAsLong();
- CmsUser cmsUser = cmsUserMapper.selectById(adminId);
- if (cmsUser == null) {
- throw BusinessRuntimeException.getGatewayApiCode(GatewayApiCode.CMS_TOKEN_VALID);
- }
- refundReq.setOperator(cmsUser.getNickname());
- cmsOrderDonService.unifiedRefund(refundReq);
- return GatewayResponse.SUCCESS.newBuilder().toResult("退款成功");
- }
- /**
- * 微信退款回调
- */
- @PostMapping("/wx/refund/notify")
- public void wxRefundNotify(HttpServletRequest request, HttpServletResponse response) throws Exception {
- String xml = IoKit.toString(request.getInputStream());
- log.info("=== 退款成功的回调: \n {}", xml);
- // 解析xml
- Map<String, String> map = Xmls.toMap(xml);
- // 退款失败
- if (!StrUtil.equals("SUCCESS", map.get("return_code"))) {
- throw BusinessRuntimeException.getInstance("退款失败.");
- }
- cmsOrderDonService.wxRefundNotify(map);
- String toWechatXmlResponse = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
- OutputStream out = null;
- try {
- out = response.getOutputStream();
- IoKit.write(toWechatXmlResponse, out);
- } catch (Throwable e) {
- throw BusinessRuntimeException.getInstance(e == null ? null : e.getMessage());
- } finally {
- IoKit.close(out);
- }
- }
- /**
- * 更换用户车票
- */
- @PutMapping("/put/sameSpec/empty/relation")
- @Log(module = "更换用户车票", businessType = BusinessType.PUT, isSaveRequestData = true)
- public Result<String> changeRelation(@RequestBody @Validated ChangeRelationReq req) throws Exception {
- cmsOrderDonService.changeRelation(req);
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- /**
- * 多余车位的空账号
- */
- @GetMapping("/get/sameSpec/empty/relation")
- public Result<SearchResult<EmptyGroupsRelationView>> getSameSpecEmptyRelation(Long skuId, Long groupsId, Long relationId, Boolean isNormal) {
- MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap())
- .field(EmptyGroupsRelationView::getStatus, GroupsTrips.Status.down.name()).op(Operator.NotEqual)
- .field(EmptyGroupsRelationView::getSkuId, skuId).orderBy(EmptyGroupsRelationView::getAvailableNum)
- .desc();
- GoodsDonSku sku = skuMapper.selectById(skuId);
- Date expiryTime = null;
- if (relationId != null) {
- GroupsRelation relation = relationMapper.selectById(relationId);
- if (relation != null) expiryTime = relation.getExpiryTime();
- }
- if (groupsId != null) {
- builder.field(EmptyGroupsRelationView::getGroupsId, groupsId).op(Operator.NotEqual);
- }
- String condition = StrUtil.EMPTY;
- if (isNormal != null && isNormal) {
- 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);
- }
- if (StrUtil.isNotEmpty(condition)) {
- condition += " and ";
- }
- Integer maxNum = sku.getNum();
- Integer extraNum = 5;
- //GPT 4人月付
- if (sku.getId() == 178l) {
- extraNum = 2;
- }
- maxNum += extraNum;
- 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);
- if (StrUtil.isNotEmpty(condition)) {
- builder.put("condition", condition);
- }
- if (expiryTime != null) {
- builder.field(AccountView::getExpiryTime, expiryTime).op(Operator.GreaterEqual);
- builder.orderBy(AccountView::getExpiryTime).asc();
- }
- if (sku.getNum() == 1 || !Constant.AI_goodsIds.contains(sku.getGoodsId())) {
- builder.field(EmptyGroupsRelationView::getAvailableNum, 0).op(Operator.GreaterThan);
- }
- SearchResult<EmptyGroupsRelationView> search = beanSearcher.search(EmptyGroupsRelationView.class,
- builder.build());
- return GatewayResponse.SUCCESS.newBuilder().toResult(search);
- }
- /**
- * 订单补差价,补差价退款到余额
- */
- @PutMapping("/refund/price/differ")
- @Log(module = "订单管理/订单补差价", businessType = BusinessType.PUT, isSaveRequestData = true)
- public Result<String> refundPriceDiffer(@RequestBody OrderRefundReq orderRefundReq) throws Exception {
- long adminId = StpUtil.getLoginIdAsLong();
- CmsUser cmsUser = cmsUserMapper.selectById(adminId);
- if (cmsUser == null) {
- throw BusinessRuntimeException.getGatewayApiCode(GatewayApiCode.CMS_TOKEN_VALID);
- }
- orderRefundReq.setOperator(cmsUser.getNickname());
- cmsOrderDonService.refundPriceDiffer(orderRefundReq);
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- /**
- * 将余额清零 退款用户支付金额
- */
- @PutMapping("/clear/balance/refundMoney")
- @NoSubmit
- public Result<String> clearBalanceToRefundMoney(@RequestBody @Validated OrderBalanceRefundReq refundReq) throws Exception {
- cmsOrderDonService.clearBalanceToRefundMoney(refundReq);
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- /**
- * 客服退款每月数据
- */
- @GetMapping("/get/refundOrder/data")
- public Result<SearchResult<RefundOrderDonServiceDataView>> getRefundOrderData(String startTime, String endTime, String operator) {
- String time = StrUtil.EMPTY;
- if (StrUtil.isNotBlank(startTime)) {
- time += String.format(" and o.created_time >= '%s'", startTime);
- }
- if (StrUtil.isNotBlank(endTime)) {
- time += String.format(" and o.created_time < '%s'", endTime);
- }
- MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
- if (StrUtil.isNotBlank(time)) {
- builder.put("time", time);
- }
- if (StrUtil.isEmpty(operator)) {
- List<CmsUserVO> userVOS = beanSearcher.searchAll(CmsUserVO.class, MapUtils.builder().field(CmsUserVO::getRoleNames, "客服").op(Operator.Contain).build());
- List<String> collect = userVOS.stream().map(CmsUserVO::getNickname).collect(Collectors.toList());
- if (CollUtil.isNotEmpty(collect)) {
- builder.field(RefundOrderDonServiceDataView::getOperator, collect).op(Operator.InList);
- }
- }
- SearchResult<RefundOrderDonServiceDataView> search = beanSearcher.search(RefundOrderDonServiceDataView.class, builder.build());
- search.getDataList().forEach(e->{
- String goodsName = orderDonMapper.selectMaxRefundGoodsName(e.getOperator(), startTime, endTime);
- e.setGoodsName(goodsName);
- });
- return GatewayResponse.SUCCESS.newBuilder().toResult(search);
- }
- /**
- * 设置订单客服
- */
- @PutMapping("/set/service")
- public Result<String> setOrderCustomerService(@RequestBody OrderDonCustomerServiceRelate relate) {
- OrderDonCustomerServiceRelate orderDonCustomerServiceRelate = orderDonCustomerServiceRelateMapper.selectOne(Wrappers.lambdaQuery(OrderDonCustomerServiceRelate.class)
- .eq(OrderDonCustomerServiceRelate::getOrderId, relate.getOrderId()).last("limit 1"));
- if (orderDonCustomerServiceRelate != null) {
- relate.setId(orderDonCustomerServiceRelate.getId());
- }
- try {
- if (relate.getId() == null) {
- orderDonCustomerServiceRelateMapper.insert(relate);
- } else {
- orderDonCustomerServiceRelateMapper.updateById(relate);
- }
- } catch (DuplicateKeyException e) {
- }
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- /**
- * 查询套餐订单列表
- */
- @GetMapping("/upgrade/get")
- @SaCheckPermission("upgradeOrder:view")
- public Result<SearchResult<UpgradeOrderDonBackView>> getUpgradeOrder(String account, String showId, Long acId, String nickname, String register, Boolean isGoogle) {
- MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
- if (StrUtil.isNotBlank(account)) {
- GroupsRelation relation = relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
- .eq(GroupsRelation::getAccount, account).last("limit 1"));
- if (relation != null) {
- builder.field(OrderDonBackView::getRelationId, relation.getId());
- } else {
- builder.field(OrderDonBackView::getRelationId).op(Operator.IsNull);
- }
- }
- if (StrUtil.isNotBlank(showId)) {
- builder.field(OrderDonBackView::getUserId, userService.getUserIdByShowId(showId));
- }
- String conditionSql = StrUtil.EMPTY;
- if (acId != null) {
- conditionSql += String.format(" o.user_id in (select user_id from corp_user where ac_id = %s)", acId);
- }
- if (!ObjectUtil.isAllEmpty(nickname, register, isGoogle)) {
- if (StrUtil.isNotEmpty(conditionSql)) {
- conditionSql += " and ";
- }
- conditionSql += " exists (select u.id from user u where u.id = o.user_id";
- if (StrUtil.isNotEmpty(nickname)) {
- conditionSql += String.format(" and u.nickname like '%s%%'", nickname);
- }
- if (StrUtil.isNotEmpty(register)) {
- if ("phone".equals(register)) {
- conditionSql += " and u.login_phone != ''";
- } else if ("email".equals(register)) {
- conditionSql += " and u.email != ''";
- } else if ("wechat".equals(register)) {
- conditionSql += " and u.unionid != ''";
- }
- }
- if (isGoogle != null && isGoogle) {
- conditionSql += String.format(" and u.is_google is %s", isGoogle);
- }
- conditionSql += " limit 1)";
- }
- if (StrUtil.isNotBlank(conditionSql)) {
- builder.put("condition", conditionSql);
- }
- SearchResult<UpgradeOrderDonBackView> search = beanSearcher.search(UpgradeOrderDonBackView.class, builder.build());
- search.getDataList().forEach(data -> {
- User user = userMapper.selectById(data.getUserId());
- if (user != null) {
- data.setNickname(user.getNickname());
- data.setLoginPhone(user.getLoginPhone());
- data.setEmail(user.getEmail());
- data.setRegister(StrUtil.isNotEmpty(user.getUnionid()) ? "wechat" : StrUtil.isNotEmpty(user.getLoginPhone()) ? "phone" : "email");
- }
- });
- return GatewayResponse.SUCCESS.newBuilder().toResult(search);
- }
- /**
- * 套餐退款订单列表
- */
- @GetMapping("/get/upgrade/refund/list")
- public Result<SearchResult<RefundUpdradeOrderDonView>> getRefundUpgradeOrderDonView(String nickname) {
- List<Long> userIds = null;
- if (StrUtil.isNotBlank(nickname)) {
- userIds = userMapper.selectListByNickname(nickname);
- if (CollUtil.isEmpty(userIds)) {
- userIds.add(0l);
- }
- }
- MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
- if (CollUtil.isNotEmpty(userIds)) {
- builder.field(RealGoodsInterestUserView::getUserId, userIds).op(Operator.InList);
- }
- SearchResult<RefundUpdradeOrderDonView> search = beanSearcher.search(RefundUpdradeOrderDonView.class,
- builder.build());
- search.getDataList().forEach(data -> {
- Optional.ofNullable(userService.getById(data.getUserId()))
- .ifPresent(user -> data.setNickname(user.getNickname()));
- });
- return GatewayResponse.SUCCESS.newBuilder().toResult(search);
- }
- /**
- * 套餐订单导出
- */
- @GetMapping("/upgrade/export")
- @SaCheckPermission("upgradeOrder:export")
- @Log(module = "套餐订单管理/导出订单", businessType = BusinessType.EXPORT, isSaveRequestData = true)
- public void exportUpgradeOrders(HttpServletResponse response) {
- List<ExcelUpgradeOrderDonData> list = beanSearcher.searchAll(ExcelUpgradeOrderDonData.class, MapUtils.flatBuilder(request.getParameterMap()).build());
- list.forEach(data -> {
- data.setMoney(data.getMoney().divide(BigDecimal.valueOf(100)));
- UpgradeOrderDon.Type type = data.getType();
- data.setTypeStr(type != null ? type.getDesc() : "");
- UpgradeOrderDon.Status status = data.getStatus();
- data.setStatusStr(status != null ? status.getDesc() : "");
- });
- EasyExcelUtils.createExcelStreamMutilByEasyExcel(response, ExcelUpgradeOrderDonData.class, list, "订单列表", "订单列表", ExcelTypeEnum.XLSX, null);
- }
- /**
- * 套餐订单统一退款
- */
- @PostMapping("/unified/upgrade/refund")
- @Log(module = "套餐订单管理/统一退款", businessType = BusinessType.PUT, isSaveRequestData = true)
- public Result<String> unifiedUpgradeRefund(@RequestBody @Validated OrderRefundReq refundReq) throws Exception {
- long adminId = StpUtil.getLoginIdAsLong();
- CmsUser cmsUser = cmsUserMapper.selectById(adminId);
- if (cmsUser == null) {
- throw BusinessRuntimeException.getGatewayApiCode(GatewayApiCode.CMS_TOKEN_VALID);
- }
- refundReq.setOperator(cmsUser.getNickname());
- cmsOrderDonService.unifiedUpgradeRefund(refundReq);
- return GatewayResponse.SUCCESS.newBuilder().toResult("退款成功");
- }
- /**
- * midjourney查询订单用户账号剩余次数
- */
- @GetMapping("/get/midjourney/user")
- public Result<MidjourneyUserDetailView> getMidjourneyUser(Long orderId) {
- OrderDon orderDon = orderDonMapper.selectById(orderId);
- //续费订单
- Date startTime = null;
- Date expiryTime = null;
- if (orderDon.getOrderType() == 2) {
- GoodsDonSku sku = skuMapper.selectById(orderDon.getSkuId());
- GroupsRelation relation = relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
- .eq(GroupsRelation::getId, orderDon.getRelationId())
- .eq(GroupsRelation::getUserId, orderDon.getUserId()).last("limit 1"));
- if (relation == null) {
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- startTime = relation.getStartTime();
- startTime = DateUtil.offsetMonth(startTime, sku.getMonths());
- expiryTime = relation.getExpiryTime();
- }
- MidjourneyUser midjourneyUser = midjourneyUserMapper.selectOne(Wrappers.lambdaQuery(MidjourneyUser.class)
- .eq(MidjourneyUser::getRelationId, orderDon.getRelationId())
- .last("limit 1"));
- if (midjourneyUser == null) {
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- MidjourneyUserDetailView midjourneyUserDetailView = midjourneyUserConversationMapper.getMjMirrorOrderDetail(orderDon.getRelationId(), startTime, expiryTime);
- GoodsDonSku sku = skuMapper.selectById(orderDon.getSkuId());
- midjourneyUserDetailView.setUserId(orderDon.getUserId());
- midjourneyUserDetailView.setExpiryTime(midjourneyUser.getExpireTime());
- midjourneyUserDetailView.setMjFastNum(sku.getMjFastNum() - midjourneyUserDetailView.getUseFastNum());
- if (sku.getMjRelaxNum() == null) {
- midjourneyUserDetailView.setMjRelaxNum(null);
- } else {
- midjourneyUserDetailView.setMjRelaxNum(sku.getMjRelaxNum() - midjourneyUserDetailView.getUseRelaxNum());
- }
- return GatewayResponse.SUCCESS.newBuilder().toResult(midjourneyUserDetailView);
- }
- /**
- * 用户退款详情
- */
- @GetMapping("/get/user/refund/detail")
- public Result<OrderDonUserRefundDetailView> getUserRefundDetail(Long userId) {
- if (userId == null || userId == 0) {
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- List<Long> userIdList = null;
- try {
- userIdList = userBindRelationService.getRelationUserIdList(userId, null);
- } catch (Exception e) {
- }
- String userIds = null;
- if (CollUtil.isNotEmpty(userIdList)) {
- userIds = userIdList.toString().replaceAll("\\[", "").replaceAll("]", "");
- }
- MapBuilder builder = MapUtils.builder();
- if (StrUtil.isNotBlank(userIds)) {
- builder.put("uid", String.format(" and user_id in (%s)", userIds));
- } else {
- builder.put("uid", String.format(" and user_id = %s", userId));
- }
- OrderDonUserRefundDetailView orderDonUserRefundDetailView = beanSearcher.searchFirst(OrderDonUserRefundDetailView.class, builder.build());
- return GatewayResponse.SUCCESS.newBuilder().toResult(orderDonUserRefundDetailView);
- }
- /**
- * 用户订单列表
- */
- @GetMapping("/get/user/orders")
- public Result<SearchResult<OrderDonUserRefundDetailView.OrderDonDetailView>> getUserOrdersDetail(Long userId) {
- if (userId == null || userId == 0) {
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- List<Long> userIdList = null;
- try {
- userIdList = userBindRelationService.getRelationUserIdList(userId, null);
- } catch (Exception e) {
- }
- if (userIdList == null) {
- userIdList = new ArrayList<>();
- userIdList.add(userId);
- }
- SearchResult<OrderDonUserRefundDetailView.OrderDonDetailView> search = beanSearcher.search(OrderDonUserRefundDetailView.OrderDonDetailView.class, MapUtils.flatBuilder(request.getParameterMap())
- .field(OrderDonUserRefundDetailView.OrderDonDetailView::getUserId, userIdList).op(Operator.InList)
- .build());
- return GatewayResponse.SUCCESS.newBuilder().toResult(search);
- }
- /**
- * 续费升级订单详情
- */
- @GetMapping("/renew/orders/detail")
- public Result<RenewOriOrderSkuDto> getRenewOrdersDetail(Long orderId) {
- OrderDon orderDon = orderDonMapper.selectById(orderId);
- if (orderDon.getOrderType() == 2) {
- OrderDonRenewRecord orderDonRenewRecord = orderDonRenewRecordMapper.selectOne(Wrappers.lambdaQuery(OrderDonRenewRecord.class)
- .eq(OrderDonRenewRecord::getOrderId, orderDon.getId())
- .last("limit 1"));
- if (orderDonRenewRecord != null) {
- GroupsRelation relation = relationMapper.selectById(orderDon.getRelationId());
- GoodsDonSku sku = skuMapper.selectById(orderDon.getSkuId());
- Date expiryTime = relation.getExpiryTime();
- DateTime lastExpiryTIme = DateUtil.offsetMonth(expiryTime, -sku.getMonths());
- RenewOriOrderSkuDto renewOriOrderSkuDto = new RenewOriOrderSkuDto();
- OriSkuDto oriSku = skuMapper.selectRenewOriSku(orderDonRenewRecord.getOriSkuId());
- renewOriOrderSkuDto.setOriSku(oriSku);
- renewOriOrderSkuDto.setLastExpiryTime(lastExpiryTIme);
- return GatewayResponse.SUCCESS.newBuilder().toResult(renewOriOrderSkuDto);
- }
- }
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- }
|