package com.xinquan.order.controller.management;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.xinquan.common.core.domain.R;
|
import com.xinquan.common.core.utils.page.CollUtils;
|
import com.xinquan.common.core.utils.page.PageDTO;
|
import com.xinquan.common.security.utils.SecurityUtils;
|
import com.xinquan.course.api.domain.Course;
|
import com.xinquan.course.api.feign.RemoteCourseService;
|
import com.xinquan.meditation.api.domain.Meditation;
|
import com.xinquan.meditation.api.feign.RemoteMeditationService;
|
import com.xinquan.order.api.domain.Order;
|
import com.xinquan.order.api.domain.dto.OrderListDTO;
|
import com.xinquan.order.api.domain.vo.OrderCountVO;
|
import com.xinquan.order.domain.OrderPaymentRecord;
|
import com.xinquan.order.service.OrderPaymentRecordService;
|
import com.xinquan.order.service.OrderService;
|
import com.xinquan.system.api.RemoteUserService;
|
import com.xinquan.system.api.domain.AppUser;
|
import com.xinquan.system.api.domain.SysUser;
|
import com.xinquan.user.api.feign.RemoteAppUserService;
|
import io.swagger.annotations.ApiOperation;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.annotation.Resource;
|
import java.math.BigDecimal;
|
import java.time.LocalDateTime;
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.Objects;
|
import java.util.stream.Collectors;
|
|
/**
|
* <p>
|
* 订单表 前端控制器
|
* </p>
|
*
|
* @author mitao
|
* @since 2024-08-21
|
*/
|
@RestController
|
@RequestMapping("/mgt/order/order")
|
public class MgtOrderController {
|
@Resource
|
private OrderService orderService;
|
@Resource
|
private OrderPaymentRecordService orderPaymentRecordService;
|
@Resource
|
private RemoteAppUserService remoteAppUserService;
|
@Resource
|
private RemoteCourseService remoteCourseService;
|
@Resource
|
private RemoteMeditationService remoteMeditationService;
|
@Resource
|
private RemoteUserService remoteUserService;
|
|
@PostMapping("/orderList")
|
@ApiOperation(value = "订单列表管理列表-分页", tags = {"管理后台-订单列表管理"})
|
public R<PageDTO<Order>> orderList(@RequestBody OrderListDTO courseDTO) {
|
String startTime = null;
|
String endTime = null;
|
if (org.springframework.util.StringUtils.hasLength(courseDTO.getTime())){
|
String[] split = courseDTO.getTime().split(" - ");
|
startTime = split[0]+"00:00:00";
|
endTime = split[1]+"23:59:59";
|
}
|
List<Integer> payType1 = new ArrayList<>();
|
payType1.add(1);
|
payType1.add(5);
|
List<Integer> payType2 = new ArrayList<>();
|
payType2.add(2);
|
payType2.add(6);
|
List<Integer> payType3 = new ArrayList<>();
|
payType3.add(4);
|
payType3.add(7);
|
LambdaQueryWrapper<Order> courseLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
courseLambdaQueryWrapper.between(Order::getCreateTime, startTime, endTime);
|
if (courseDTO.getPayType()!=null){
|
switch (courseDTO.getPayType()){
|
case 1:
|
courseLambdaQueryWrapper.in(Order::getPayType,payType1);
|
break;
|
case 2:
|
courseLambdaQueryWrapper.in(Order::getPayType,payType2);
|
break;
|
case 3:
|
courseLambdaQueryWrapper.eq(Order::getPayType,courseDTO.getPayType());
|
break;
|
case 4:
|
courseLambdaQueryWrapper.in(Order::getPayType,payType3);
|
break;
|
}
|
|
}
|
courseLambdaQueryWrapper.eq(courseDTO.getPaymentStatus()!=null,Order::getPaymentStatus, courseDTO.getPaymentStatus());
|
courseLambdaQueryWrapper.eq(courseDTO.getOrderFrom()!=null,Order::getOrderFrom, courseDTO.getOrderFrom());
|
courseLambdaQueryWrapper.eq(courseDTO.getUid()!=null&&(!courseDTO.getUid().isEmpty()),Order::getAppUserId, courseDTO.getUid());
|
if (org.springframework.util.StringUtils.hasLength(courseDTO.getBuyContent())){
|
// 查询购买内容
|
List<Long> collect1 = orderService.lambdaQuery().like(Order::getVipType, courseDTO.getBuyContent()).list().stream()
|
.map(Order::getId).collect(Collectors.toList());
|
List<Long> collect2 = orderService.lambdaQuery().like(Order::getBizOrderNo, courseDTO.getBuyContent()).list().stream()
|
.map(Order::getId).collect(Collectors.toList());
|
List<Long> data = remoteCourseService.getCourseIdsByName(courseDTO.getBuyContent()).getData();
|
if (!data.isEmpty()){
|
List<Long> collect3 = orderService.lambdaQuery().in(Order::getBusinessId, data)
|
.eq(Order::getOrderFrom, 2)
|
.list().stream()
|
.map(Order::getId).collect(Collectors.toList());
|
if (!collect3.isEmpty()){
|
collect1.addAll(collect3);
|
}
|
}
|
List<Long> data1 = remoteMeditationService.getMeditationIdsByName(courseDTO.getBuyContent()).getData();
|
if (!data1.isEmpty()){
|
List<Long> collect3 = orderService.lambdaQuery().in(Order::getBusinessId, data1)
|
.eq(Order::getOrderFrom, 1)
|
.list().stream()
|
.map(Order::getId).collect(Collectors.toList());
|
if (!collect3.isEmpty()){
|
collect1.addAll(collect3);
|
}
|
}
|
|
collect1.addAll(collect2);
|
List<Long> collect = collect1.stream().distinct().collect(Collectors.toList());
|
if (collect.isEmpty()){
|
collect.add(-1L);
|
}
|
courseLambdaQueryWrapper.in(Order::getId,collect);
|
}
|
|
courseLambdaQueryWrapper.orderByDesc(Order::getCreateTime);
|
if (org.springframework.util.StringUtils.hasLength(courseDTO.getUserNameOrPhone())){
|
List<Long> collect = remoteAppUserService.getAppUserByNameOrPhone(courseDTO.getUserNameOrPhone()).getData();
|
if (collect.isEmpty()){
|
collect.add(-1L);
|
}
|
courseLambdaQueryWrapper.in(Order::getAppUserId, collect);
|
}
|
|
Page<Order> page = orderService.page(new Page<>(courseDTO.getPageCurr(), courseDTO.getPageSize()), courseLambdaQueryWrapper);
|
if (CollUtils.isEmpty(page.getRecords())) {
|
return R.ok(PageDTO.empty(page));
|
}
|
for (Order record : page.getRecords()) {
|
record.setUid(record.getId().toString());
|
AppUser byId1 = remoteAppUserService.getAppUserById(record.getAppUserId()+"").getData();
|
if (Objects.nonNull(byId1)){
|
record.setUserName(byId1.getNickname());
|
record.setCellPhone(byId1.getCellPhone());
|
}
|
if (record.getOrderFrom()!=null){
|
switch (record.getOrderFrom()){
|
case 1:
|
Meditation data = remoteMeditationService.getMeditationById(record.getBusinessId()).getData();
|
if (data!=null){
|
record.setCategoryMeditationName(data.getCategoryName());
|
record.setMeditationTitle(data.getMeditationTitle());
|
record.setIconUrl(data.getIconUrl());
|
record.setDetailDescription(data.getDetailDescription());
|
record.setGeneralPriceMeditation(data.getGeneralPrice());
|
record.setListingStatusMeditation(data.getListingStatus());
|
record.setMeditationUid(data.getId()+"");
|
}
|
break;
|
case 2:
|
Course data1 = remoteCourseService.getCourseById(record.getBusinessId(),"").getData();
|
if (data1!=null){
|
record.setCategoryCourseName(data1.getCategoryName());
|
record.setCourseTitle(data1.getCourseTitle());
|
record.setCoverUrl(data1.getCoverUrl());
|
record.setTutor(data1.getTutor());
|
record.setCourseChapterCount(data1.getCourseChapterCount());
|
record.setGeneralPriceCourse(data1.getGeneralPrice());
|
record.setListingStatusCourse(data1.getListingStatus());
|
record.setCourseUid(data1.getId()+"");
|
}
|
break;
|
case 3:
|
record.setBuyContent(record.getVipType());
|
record.setGeneralPriceVip(record.getRealPayAmount());
|
break;
|
}
|
}
|
}
|
return R.ok(PageDTO.of(page, Order.class));
|
}
|
@PostMapping("/orderCount")
|
@ApiOperation(value = "订单列表管理列表上方合计数据", tags = {"管理后台-订单列表管理"})
|
|
public R<OrderCountVO> orderCount(@RequestBody OrderListDTO courseDTO) {
|
OrderCountVO orderCountVO = new OrderCountVO();
|
String startTime = null;
|
String endTime = null;
|
if (org.springframework.util.StringUtils.hasLength(courseDTO.getTime())){
|
String[] split = courseDTO.getTime().split(" - ");
|
startTime = split[0]+"00:00:00";
|
endTime = split[1]+"23:59:59";
|
}
|
List<Integer> payType1 = new ArrayList<>();
|
payType1.add(1);
|
payType1.add(5);
|
List<Integer> payType2 = new ArrayList<>();
|
payType2.add(2);
|
payType2.add(6);
|
List<Integer> payType3 = new ArrayList<>();
|
payType3.add(4);
|
payType3.add(7);
|
LambdaQueryWrapper<Order> courseLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
courseLambdaQueryWrapper.between(Order::getCreateTime, startTime, endTime);
|
if (courseDTO.getPayType()!=null){
|
switch (courseDTO.getPayType()){
|
case 1:
|
courseLambdaQueryWrapper.in(Order::getPayType,payType1);
|
break;
|
case 2:
|
courseLambdaQueryWrapper.in(Order::getPayType,payType2);
|
break;
|
case 3:
|
courseLambdaQueryWrapper.eq(Order::getPayType,courseDTO.getPayType());
|
break;
|
case 4:
|
courseLambdaQueryWrapper.in(Order::getPayType,payType3);
|
break;
|
}
|
|
}
|
courseLambdaQueryWrapper.eq(courseDTO.getPaymentStatus()!=null,Order::getPaymentStatus, courseDTO.getPaymentStatus());
|
courseLambdaQueryWrapper.eq(courseDTO.getOrderFrom()!=null,Order::getOrderFrom, courseDTO.getOrderFrom());
|
if (org.springframework.util.StringUtils.hasLength(courseDTO.getBuyContent())){
|
// 查询购买内容
|
List<Long> collect1 = orderService.lambdaQuery().like(Order::getVipType, courseDTO.getBuyContent()).list().stream()
|
.map(Order::getId).collect(Collectors.toList());
|
List<Long> collect2 = orderService.lambdaQuery().like(Order::getBizOrderNo, courseDTO.getBuyContent()).list().stream()
|
.map(Order::getId).collect(Collectors.toList());
|
List<Long> data = remoteCourseService.getCourseIdsByName(courseDTO.getBuyContent()).getData();
|
if (!data.isEmpty()){
|
List<Long> collect3 = orderService.lambdaQuery().in(Order::getBusinessId, data)
|
.eq(Order::getOrderFrom, 2)
|
.list().stream()
|
.map(Order::getId).collect(Collectors.toList());
|
if (!collect3.isEmpty()){
|
collect1.addAll(collect3);
|
}
|
}
|
List<Long> data1 = remoteMeditationService.getMeditationIdsByName(courseDTO.getBuyContent()).getData();
|
if (!data1.isEmpty()){
|
List<Long> collect3 = orderService.lambdaQuery().in(Order::getBusinessId, data1)
|
.eq(Order::getOrderFrom, 1)
|
.list().stream()
|
.map(Order::getId).collect(Collectors.toList());
|
if (!collect3.isEmpty()){
|
collect1.addAll(collect3);
|
}
|
}
|
|
collect1.addAll(collect2);
|
List<Long> collect = collect1.stream().distinct().collect(Collectors.toList());
|
if (collect.isEmpty()){
|
collect.add(-1L);
|
}
|
courseLambdaQueryWrapper.in(Order::getId,collect);
|
}
|
courseLambdaQueryWrapper.orderByDesc(Order::getCreateTime);
|
if (org.springframework.util.StringUtils.hasLength(courseDTO.getUserNameOrPhone())){
|
List<Long> collect = remoteAppUserService.getAppUserByNameOrPhone(courseDTO.getUserNameOrPhone()).getData();
|
if (collect.isEmpty()){
|
collect.add(-1L);
|
}
|
courseLambdaQueryWrapper.in(Order::getAppUserId, collect);
|
}
|
List<Order> page = orderService.list(courseLambdaQueryWrapper);
|
Integer payCount = 0;
|
Integer completeCount = 0;
|
Integer cancelCount = 0;
|
BigDecimal totalMoney = new BigDecimal("0");
|
for (Order record : page) {
|
if (record.getPaymentStatus()!=null){
|
switch (record.getPaymentStatus()){
|
case 1:
|
payCount++;
|
break;
|
case 2:
|
completeCount++;
|
break;
|
case 3:
|
cancelCount++;
|
break;
|
}
|
}
|
if (record.getRealPayAmount()!=null && record.getRefundStatus()!=3){
|
totalMoney = totalMoney.add(record.getRealPayAmount());
|
}
|
}
|
orderCountVO.setTotalCount(page.size());
|
orderCountVO.setPayCount(payCount);
|
orderCountVO.setCompleteCount(completeCount);
|
orderCountVO.setCancelCount(cancelCount);
|
orderCountVO.setTotalMoney(totalMoney);
|
return R.ok(orderCountVO);
|
}
|
|
@GetMapping("/detailOrder")
|
@ApiOperation(value = "查看详情订单列表管理", notes = "管理后台-订单列表管理")
|
public R<Order> detailOrder(String uid) {
|
Order record = orderService.getById(uid);
|
if (record.getOrderFrom()!=null){
|
switch (record.getOrderFrom()){
|
case 1:
|
Meditation data = remoteMeditationService.getMeditationById(record.getBusinessId()).getData();
|
if (data!=null){
|
record.setCategoryMeditationName(data.getCategoryName());
|
record.setMeditationTitle(data.getMeditationTitle());
|
record.setIconUrl(data.getIconUrl());
|
record.setDetailDescription(data.getDetailDescription());
|
record.setGeneralPriceMeditation(data.getGeneralPrice());
|
record.setListingStatusMeditation(data.getListingStatus());
|
record.setMeditationUid(data.getId()+"");
|
}
|
break;
|
case 2:
|
Course data1 = remoteCourseService.getCourseById(record.getBusinessId(),"").getData();
|
if (data1!=null){
|
record.setCategoryCourseName(data1.getCategoryName());
|
record.setCourseTitle(data1.getCourseTitle());
|
record.setCoverUrl(data1.getCoverUrl());
|
record.setTutor(data1.getTutor());
|
record.setCourseChapterCount(data1.getCourseChapterCount());
|
record.setGeneralPriceCourse(data1.getGeneralPrice());
|
record.setListingStatusCourse(data1.getListingStatus());
|
record.setCourseUid(data1.getId()+"");
|
}
|
break;
|
case 3:
|
record.setBuyContent(record.getVipType());
|
record.setGeneralPriceVip(record.getRealPayAmount());
|
break;
|
}
|
}
|
record.setUid(record.getId().toString());
|
AppUser byId2 = remoteAppUserService.getAppUserById(record.getAppUserId()+"").getData();
|
AppUser byId3 = remoteAppUserService.getAppUserById(record.getGiveUserId()+"").getData();
|
if (Objects.nonNull(byId2)){
|
record.setUserName(byId2.getNickname());
|
record.setAvatar(byId2.getAvatar());
|
record.setCellPhone(byId2.getCellPhone());
|
}
|
if (Objects.nonNull(byId3)){
|
record.setUserNameGive(byId3.getNickname());
|
record.setAvatarGive(byId3.getAvatar());
|
record.setCellPhoneGive(byId3.getCellPhone());
|
}
|
if (record.getChangePriceOperator()!=null){
|
SysUser data = remoteUserService.getSysUserById(record.getChangePriceOperator() + "").getData();
|
record.setChangePriceOperatorName(data.getNickName()+"("+data.getUserName()+")");
|
}
|
if (record.getPayType()!=null){
|
List<OrderPaymentRecord> list = orderPaymentRecordService.list(new LambdaQueryWrapper<OrderPaymentRecord>()
|
.eq(OrderPaymentRecord::getOrderId, record.getId())
|
.orderByDesc(OrderPaymentRecord::getPaymentType)
|
);
|
if (record.getPayType() ==5 || record.getPayType()==6 || record.getPayType()==7){
|
if(record.getRealPayAmount()!=null){
|
switch (record.getPayType()){
|
case 5:
|
if (!list.isEmpty()){
|
OrderPaymentRecord orderPaymentRecord = list.get(1);
|
OrderPaymentRecord orderPaymentRecord1 = list.get(0);
|
switch (orderPaymentRecord.getPaymentType()){
|
case 1:
|
record.setPaymentType("微信(¥"+(orderPaymentRecord.getPayAmount()==null?"":orderPaymentRecord.getPayAmount())+")"
|
+" + 余额(¥"+orderPaymentRecord1.getPayAmount()+")");
|
break;
|
case 2:
|
record.setPaymentType("支付宝(¥"+(orderPaymentRecord.getPayAmount()==null?"":orderPaymentRecord.getPayAmount())+")"
|
+" + 余额(¥"+orderPaymentRecord1.getPayAmount()+")");
|
|
break;
|
case 3:
|
record.setPaymentType("内购(¥"+(orderPaymentRecord.getPayAmount()==null?"":orderPaymentRecord.getPayAmount())+")"
|
+" + 余额(¥"+orderPaymentRecord1.getPayAmount()+")");
|
break;
|
}
|
}
|
break;
|
case 6:
|
record.setPaymentType("支付宝(¥"+record.getRealPayAmount()+")");
|
break;
|
case 7:
|
record.setPaymentType("内购(¥"+record.getRealPayAmount()+")");
|
break;
|
}
|
}
|
}else{
|
if(record.getRealPayAmount()!=null){
|
switch (record.getPayType()){
|
case 1:
|
record.setPaymentType("微信(¥"+record.getRealPayAmount()+")");
|
break;
|
case 2:
|
record.setPaymentType("支付宝(¥"+record.getRealPayAmount()+")");
|
break;
|
case 3:
|
record.setPaymentType("余额(¥"+record.getRealPayAmount()+")");
|
break;
|
case 4:
|
record.setPaymentType("内购(¥"+record.getRealPayAmount()+")");
|
break;
|
}
|
}
|
}
|
}
|
return R.ok(record);
|
}
|
@GetMapping("/cancel")
|
@ApiOperation(value = "取消订单", notes = "管理后台-订单列表管理")
|
public R updateState(String uid) {
|
Order byId = orderService.getById(uid);
|
byId.setPaymentStatus(3);
|
orderService.updateById(byId);
|
return R.ok();
|
}
|
}
|