|
|
@@ -0,0 +1,804 @@
|
|
|
+package com.zhongzheng.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.lang.Validator;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.zhongzheng.bo.*;
|
|
|
+import com.zhongzheng.common.croe.RedisCache;
|
|
|
+import com.zhongzheng.common.filter.CustomException;
|
|
|
+import com.zhongzheng.common.model.TableDataInfo;
|
|
|
+import com.zhongzheng.common.util.DateUtils;
|
|
|
+import com.zhongzheng.common.util.EncryptHandler;
|
|
|
+import com.zhongzheng.common.util.ServletUtils;
|
|
|
+import com.zhongzheng.domian.*;
|
|
|
+import com.zhongzheng.mapper.OrderMapper;
|
|
|
+import com.zhongzheng.mapper.SysUserRoleMapper;
|
|
|
+import com.zhongzheng.service.*;
|
|
|
+import com.zhongzheng.vo.*;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IChannelService iChannelService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RedisCache redisCache;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysPersonService iSysPersonService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IOrderPersonService iOrderPersonService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IOrderRefundService iOrderRefundService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IOrderAttachmentService iOrderAttachmentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IOrderInvoiceService iOrderInvoiceService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IWxPayService iWxPayService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysRoleService iSysRoleService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysUserRoleMapper sysUserRoleMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public OrderSettlementVo orderSettlement(OrderSettlementBo bo) {
|
|
|
+ if (CollectionUtils.isEmpty(bo.getSettlementList())){
|
|
|
+ throw new CustomException("清先添加商品信息");
|
|
|
+ }
|
|
|
+ //渠道信息
|
|
|
+ Channel channel = iChannelService.getById(bo.getChannelId());
|
|
|
+ OrderSettlementVo orderSettlementVo = BeanUtil.toBean(channel, OrderSettlementVo.class);
|
|
|
+ orderSettlementVo.setChannelId(bo.getChannelId());
|
|
|
+ orderSettlementVo.setCompanyId(bo.getCompanyId());
|
|
|
+ List<OrderSettlementDetailBo> detailBos = bo.getSettlementList();
|
|
|
+ //订单人数
|
|
|
+ Set<String> userNum = detailBos.stream().map(OrderSettlementDetailBo::getIdCard).collect(Collectors.toSet());
|
|
|
+ orderSettlementVo.setOrderUserNum(userNum.size());
|
|
|
+ //订单数量
|
|
|
+ orderSettlementVo.setOrderGoodsNum(detailBos.size());
|
|
|
+ BigDecimal priceTotal = detailBos.stream().map(OrderSettlementDetailBo::getOrderPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ orderSettlementVo.setOriginalPrice(priceTotal);
|
|
|
+ switch (channel.getType()){
|
|
|
+ case 1://普通渠道
|
|
|
+ //订单价格
|
|
|
+ orderSettlementVo.setOrderPrice(priceTotal);
|
|
|
+ break;
|
|
|
+ case 2: //满减
|
|
|
+ if (priceTotal.compareTo(channel.getSatisfyPrice()) >= 0 ){
|
|
|
+ //减额
|
|
|
+ BigDecimal reducePrice = channel.getReducePrice();
|
|
|
+ BigDecimal subtract = priceTotal.subtract(reducePrice);
|
|
|
+ orderSettlementVo.setOrderPrice(subtract);
|
|
|
+ }else {
|
|
|
+ orderSettlementVo.setOrderPrice(priceTotal);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 3: //活动特价
|
|
|
+ BigDecimal activityPrice = detailBos.stream().map(OrderSettlementDetailBo::getActivityPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ orderSettlementVo.setOrderPrice(activityPrice);
|
|
|
+ break;
|
|
|
+ default: throw new CustomException("活动渠道类型有误!请检查");
|
|
|
+ }
|
|
|
+ orderSettlementVo.setSettlementList(bo.getSettlementList());
|
|
|
+ return orderSettlementVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Map<String,String> orderSubmit(OrderSubmitBo bo) {
|
|
|
+ String key = "ORDER-" + "-" + bo.getUserId();
|
|
|
+ Long value = redisCache.getCacheObject(key);
|
|
|
+ if (Validator.isNotEmpty(value)) {
|
|
|
+ throw new CustomException("请勿频繁提交订单");
|
|
|
+ }
|
|
|
+ redisCache.setCacheObject(key, 1L, 5, TimeUnit.SECONDS);//5秒
|
|
|
+ if (CollectionUtils.isEmpty(bo.getSettlementList())) {
|
|
|
+ throw new CustomException("订单商品为空,请检查!");
|
|
|
+ }
|
|
|
+ //渠道信息
|
|
|
+ Channel channel = iChannelService.getById(bo.getChannelId());
|
|
|
+ if (ObjectUtils.isNull(channel)) {
|
|
|
+ throw new CustomException("渠道获取有误,请检查!");
|
|
|
+ }
|
|
|
+
|
|
|
+ //创建订单
|
|
|
+ Order order = new Order();
|
|
|
+ //生成订单号
|
|
|
+ String out_trade_no = DateUtils.getDateOrderSn();
|
|
|
+ order.setCreateTime(DateUtils.getNowTime());
|
|
|
+ order.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ order.setChannelId(bo.getChannelId());
|
|
|
+ order.setUserId(bo.getUserId());
|
|
|
+ order.setCompanyId(bo.getCompanyId());
|
|
|
+ order.setOrderFrom(1);
|
|
|
+ order.setOrderSn(out_trade_no);
|
|
|
+ order.setStatus(1);
|
|
|
+ order.setRemark(bo.getOrderRemark());
|
|
|
+
|
|
|
+ //订单员工
|
|
|
+ for (OrderSettlementDetailBo detailBo : bo.getSettlementList()) {
|
|
|
+ OrderPerson orderPerson = new OrderPerson();
|
|
|
+ orderPerson.setOrderSn(out_trade_no);
|
|
|
+ orderPerson.setRefundStatus(0);
|
|
|
+ orderPerson.setPayStatus(1);
|
|
|
+ orderPerson.setEduName(bo.getEduName());
|
|
|
+ orderPerson.setBusinessName(bo.getBusinessName());
|
|
|
+ orderPerson.setSubjectName(detailBo.getSubjectNames());
|
|
|
+ orderPerson.setYear(detailBo.getYear());
|
|
|
+ orderPerson.setCreateTime(DateUtils.getNowTime());
|
|
|
+ orderPerson.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ //获取学员
|
|
|
+ SysPerson person = iSysPersonService.getOne(new LambdaQueryWrapper<SysPerson>()
|
|
|
+ .eq(SysPerson::getIdCard, EncryptHandler.encrypt(detailBo.getIdCard()))
|
|
|
+ .eq(SysPerson::getStatus, 1)
|
|
|
+ .eq(SysPerson::getCompanyId, bo.getCompanyId())
|
|
|
+ .last("limit 1"));
|
|
|
+ if (ObjectUtils.isNull(person)){
|
|
|
+ throw new CustomException(String.format("【%】学员信息获取有误,请检查", detailBo.getIdCard()));
|
|
|
+ }
|
|
|
+ orderPerson.setPersonId(person.getPersonId());
|
|
|
+ orderPerson.setPersonName(detailBo.getRealname());
|
|
|
+ orderPerson.setPersonPhone(detailBo.getTelphone());
|
|
|
+ orderPerson.setPersonCard(detailBo.getIdCard());
|
|
|
+ orderPerson.setStatus(1);
|
|
|
+ orderPerson.setPrice(detailBo.getOrderPrice());
|
|
|
+ //价格
|
|
|
+ if (channel.getType() == 3){
|
|
|
+ //特价活动
|
|
|
+ orderPerson.setRealPrice(detailBo.getActivityPrice());
|
|
|
+ }else {
|
|
|
+ orderPerson.setRealPrice(detailBo.getOrderPrice());
|
|
|
+ }
|
|
|
+
|
|
|
+ iOrderPersonService.save(orderPerson);
|
|
|
+ }
|
|
|
+
|
|
|
+ //订单原价
|
|
|
+ BigDecimal reduce = bo.getSettlementList().stream().map(OrderSettlementDetailBo::getOrderPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ order.setOrderPrice(reduce);
|
|
|
+
|
|
|
+ //订单支付价格
|
|
|
+ BigDecimal payPrice = BigDecimal.ZERO;
|
|
|
+ if (channel.getType() == 2){
|
|
|
+ //满减
|
|
|
+ if (reduce.compareTo(channel.getSatisfyPrice()) >= 0){
|
|
|
+ payPrice = reduce.subtract(channel.getReducePrice());
|
|
|
+ }
|
|
|
+ }else if (channel.getType() == 3){
|
|
|
+ //活动特价
|
|
|
+ payPrice = bo.getSettlementList().stream().map(OrderSettlementDetailBo::getActivityPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ }else {
|
|
|
+ //普通
|
|
|
+ payPrice = reduce;
|
|
|
+ }
|
|
|
+ order.setPayPrice(payPrice);
|
|
|
+ //待支付
|
|
|
+ order.setOrderStatus(0);
|
|
|
+ order.setPayStatus(0);
|
|
|
+ order.setCheckStatus(0);
|
|
|
+ order.setInvoiceStatus(0);
|
|
|
+
|
|
|
+ //订单附件
|
|
|
+ if (CollectionUtils.isNotEmpty(bo.getAttachmentList())){
|
|
|
+ List<OrderAttachment> attachmentList = bo.getAttachmentList().stream().map(x -> {
|
|
|
+ OrderAttachment attachment = new OrderAttachment();
|
|
|
+ attachment.setOrderSn(out_trade_no);
|
|
|
+ attachment.setAttachmentUrl(x.getAttachmentUrl());
|
|
|
+ attachment.setAttachmentType(x.getAttachmentType());
|
|
|
+ attachment.setStatus(1);
|
|
|
+ attachment.setCreateTime(DateUtils.getNowTime());
|
|
|
+ attachment.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ return attachment;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ iOrderAttachmentService.saveBatch(attachmentList);
|
|
|
+ }
|
|
|
+
|
|
|
+ String body = "在线支付";
|
|
|
+ Map<String,String> result = new HashMap<>();
|
|
|
+ //支付方式
|
|
|
+ if (bo.getOrderType() == 1 ){
|
|
|
+ //对公
|
|
|
+ order.setOrderUncollected(payPrice);
|
|
|
+ }else if (bo.getOrderType() == 2){
|
|
|
+ order.setOrderUncollected(payPrice);
|
|
|
+ //微信支付
|
|
|
+ if (payPrice.compareTo(BigDecimal.ZERO) > 0){
|
|
|
+ result = iWxPayService.paymentPc(out_trade_no, body, payPrice);
|
|
|
+ }
|
|
|
+ }else if (bo.getOrderType() == 3){
|
|
|
+ //线下
|
|
|
+ //未付
|
|
|
+ order.setOrderReceived(bo.getOrderReceived());
|
|
|
+ BigDecimal subtract = payPrice.subtract(bo.getOrderReceived());
|
|
|
+ order.setOrderUncollected(subtract);
|
|
|
+ }
|
|
|
+ order.setOrderType(bo.getOrderType());
|
|
|
+ save(order);
|
|
|
+
|
|
|
+ result.put("orderSn", out_trade_no);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TableDataInfo<OrderListVo> getOrderList(OrderQueryBo bo) {
|
|
|
+ IPage<OrderListVo> page = baseMapper.getOrderList(new Page<>(bo.getPageNum(), bo.getPageSize()), bo);
|
|
|
+ if (CollectionUtils.isEmpty(page.getRecords())){
|
|
|
+ return new TableDataInfo<OrderListVo>().setRows(new ArrayList<>());
|
|
|
+ }
|
|
|
+
|
|
|
+ page.getRecords().forEach(x -> {
|
|
|
+ List<OrderPerson> personList = iOrderPersonService.list(new LambdaQueryWrapper<OrderPerson>().eq(OrderPerson::getOrderSn, x.getOrderSn()).eq(OrderPerson::getStatus, 1));
|
|
|
+ //人数和订单数
|
|
|
+ Set<Long> userNum = personList.stream().map(OrderPerson::getPersonId).collect(Collectors.toSet());
|
|
|
+ x.setOrderPersonNum(userNum.size());
|
|
|
+ x.setOrderNum(personList.size());
|
|
|
+ });
|
|
|
+ TableDataInfo<OrderListVo> info = new TableDataInfo<>();
|
|
|
+ info.setTotal(page.getTotal());
|
|
|
+ info.setRows(page.getRecords());
|
|
|
+ return info;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Integer queryByOrderSn(String orderSn) {
|
|
|
+ Order order = getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderSn, orderSn));
|
|
|
+ if (Objects.isNull(order)){
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ return order.getOrderStatus();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public OrderDetailVo getOrderDetail(String orderSn) {
|
|
|
+ OrderDetailVo detailVo = baseMapper.getOrderDetail(orderSn);
|
|
|
+ if (Objects.isNull(detailVo)){
|
|
|
+ throw new CustomException("订单获取有误!");
|
|
|
+ }
|
|
|
+ //订单学员
|
|
|
+ List<OrderPerson> orderPeople = iOrderPersonService
|
|
|
+ .list(new LambdaQueryWrapper<OrderPerson>().eq(OrderPerson::getOrderSn, orderSn));
|
|
|
+ if (CollectionUtils.isNotEmpty(orderPeople)){
|
|
|
+ List<OrderPersonVo> personVos = orderPeople.stream().map(x -> {
|
|
|
+ OrderPersonVo bean = BeanUtil.toBean(x, OrderPersonVo.class);
|
|
|
+ bean.setIdCard(x.getPersonCard());
|
|
|
+ bean.setPhone(x.getPersonPhone());
|
|
|
+ bean.setGender(getUserSex(x.getPersonCard()));
|
|
|
+ return bean;
|
|
|
+ }
|
|
|
+ ).collect(Collectors.toList());
|
|
|
+ detailVo.setOrderPersonList(personVos);
|
|
|
+ //人数和订单数
|
|
|
+ Set<Long> userNum = orderPeople.stream().map(OrderPerson::getPersonId).collect(Collectors.toSet());
|
|
|
+ detailVo.setOrderPersonNum(userNum.size());
|
|
|
+ detailVo.setOrderNum(orderPeople.size());
|
|
|
+ }
|
|
|
+ //订单附件
|
|
|
+ List<OrderAttachment> attachmentList = iOrderAttachmentService
|
|
|
+ .list(new LambdaQueryWrapper<OrderAttachment>().eq(OrderAttachment::getOrderSn, orderSn));
|
|
|
+ if (CollectionUtils.isNotEmpty(attachmentList)){
|
|
|
+ List<OrderAttachmentVo> attachmentVos = attachmentList.stream().map(x -> BeanUtil.toBean(x, OrderAttachmentVo.class)).collect(Collectors.toList());
|
|
|
+ detailVo.setOrderAttachmentVos(attachmentVos);
|
|
|
+ }
|
|
|
+ return detailVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getUserSex(String idNumber){
|
|
|
+ if (idNumber == null || (idNumber.length() != 18 && idNumber.length() != 15)) {
|
|
|
+ return "男";
|
|
|
+ }
|
|
|
+ int index = idNumber.length() == 18 ? 16 : 14;
|
|
|
+ char genderCode = idNumber.charAt(index);
|
|
|
+ return (genderCode % 2 == 0) ? "女" : "男";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean uploadAttachment(OrderUploadAttachBo bo) {
|
|
|
+ Order order = getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderSn, bo.getOrderSn()));
|
|
|
+ if (ObjectUtils.isNull(order)){
|
|
|
+ throw new CustomException("订单号有误!");
|
|
|
+ }
|
|
|
+ //上传附件
|
|
|
+ if (CollectionUtils.isEmpty(bo.getAttachmentList())){
|
|
|
+ throw new CustomException("附件为空");
|
|
|
+ }
|
|
|
+ List<OrderAttachment> attachments = bo.getAttachmentList().stream().map(x -> {
|
|
|
+ OrderAttachment attachment = BeanUtil.toBean(x, OrderAttachment.class);
|
|
|
+ attachment.setOrderSn(bo.getOrderSn());
|
|
|
+ attachment.setStatus(1);
|
|
|
+ attachment.setCreateTime(DateUtils.getNowTime());
|
|
|
+ attachment.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ return attachment;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ return iOrderAttachmentService.saveBatch(attachments);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean invoiceApply(OrderInvoiceCheckBo bo) {
|
|
|
+ Order order = getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderSn, bo.getOrderSn()));
|
|
|
+ if (ObjectUtils.isNull(order)){
|
|
|
+ throw new CustomException("订单号有误!");
|
|
|
+ }
|
|
|
+ if (order.getCheckStatus() != 1){
|
|
|
+ throw new CustomException("订单未审核通过,请检查!");
|
|
|
+ }
|
|
|
+ if (order.getInvoiceStatus() == 2){
|
|
|
+ throw new CustomException("当前订单已申请发票,请等待后台审核");
|
|
|
+ }
|
|
|
+
|
|
|
+ //新增发票信息
|
|
|
+ OrderInvoice invoice = BeanUtil.toBean(bo, OrderInvoice.class);
|
|
|
+ //待审核
|
|
|
+ invoice.setAmount(order.getPayPrice());
|
|
|
+ invoice.setPeriodStatus(1);
|
|
|
+ invoice.setInvoiceStatus(1); //未开票
|
|
|
+ invoice.setApplyTime(DateUtils.getNowTime());
|
|
|
+ invoice.setStatus(1);
|
|
|
+ invoice.setCreateTime(DateUtils.getNowTime());
|
|
|
+ invoice.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ iOrderInvoiceService.save(invoice);
|
|
|
+
|
|
|
+ order.setInvoiceStatus(2);
|
|
|
+ return updateById(order);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean refundApply(RefundApplyBo bo) {
|
|
|
+ Order order = getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderSn, bo.getOrderSn()));
|
|
|
+ if (ObjectUtils.isNull(order)){
|
|
|
+ throw new CustomException("订单号有误!");
|
|
|
+ }
|
|
|
+ if (order.getCheckStatus() != 1){
|
|
|
+ throw new CustomException("订单未审核通过,请检查!");
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotNull(order.getRefundStatus()) && order.getRefundStatus() == 0){
|
|
|
+ throw new CustomException("该订单已有申请退款,请等待审核!");
|
|
|
+ }
|
|
|
+ OrderRefund orderRefund = new OrderRefund();
|
|
|
+ //退款单号
|
|
|
+ String refundSn = DateUtils.getDateOrderSn();
|
|
|
+
|
|
|
+ orderRefund.setRefundSn(refundSn);
|
|
|
+ orderRefund.setOrderSn(order.getOrderSn());
|
|
|
+ orderRefund.setUserId(bo.getUserId());
|
|
|
+ orderRefund.setCompanyId(bo.getCompanyId());
|
|
|
+ orderRefund.setApplyReason(bo.getApplyReason());
|
|
|
+ //待审核
|
|
|
+ orderRefund.setPeriodStatus(0);
|
|
|
+ orderRefund.setPayee(bo.getPayee());
|
|
|
+ orderRefund.setPayeeBank(bo.getPayeeBank());
|
|
|
+ orderRefund.setPayeeBankAccount(bo.getPayeeBankAccount());
|
|
|
+ orderRefund.setStatus(1);
|
|
|
+ orderRefund.setCreateTime(DateUtils.getNowTime());
|
|
|
+ orderRefund.setUpdateTime(DateUtils.getNowTime());
|
|
|
+
|
|
|
+ //退款金额
|
|
|
+ if (StringUtils.isNotEmpty(bo.getOrderPersonIds())){
|
|
|
+ List<Long> personIds = Arrays.stream(bo.getOrderPersonIds().split(",")).map(x -> Long.valueOf(x)).collect(Collectors.toList());
|
|
|
+ List<OrderPerson> orderPeople = iOrderPersonService.list(new LambdaQueryWrapper<OrderPerson>().eq(OrderPerson::getStatus,1).in(OrderPerson::getOrderPersonId,personIds));
|
|
|
+ BigDecimal refundPrice = orderPeople.stream().map(OrderPerson::getRealPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ orderRefund.setRefundFee(refundPrice);
|
|
|
+ orderRefund.setOrderPersonIds(bo.getOrderPersonIds());
|
|
|
+ orderPeople.forEach(x -> x.setRefundStatus(1));
|
|
|
+ iOrderPersonService.updateBatchById(orderPeople);
|
|
|
+ //补充订单退款金额
|
|
|
+ if (ObjectUtils.isNull(order.getOrderRefund())){
|
|
|
+ order.setOrderRefund(refundPrice);
|
|
|
+ }else {
|
|
|
+ order.setOrderRefund(order.getOrderPrice().add(refundPrice));
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ //全部
|
|
|
+ List<OrderPerson> list = iOrderPersonService.list(new LambdaQueryWrapper<OrderPerson>()
|
|
|
+ .eq(OrderPerson::getOrderSn, bo.getOrderSn())
|
|
|
+ .notIn(OrderPerson::getRefundStatus, Arrays.asList(1, 2))
|
|
|
+ .eq(OrderPerson::getStatus, 1));
|
|
|
+ if (CollectionUtils.isEmpty(list)){
|
|
|
+ throw new CustomException("该订单已全部退款,请检查");
|
|
|
+ }
|
|
|
+ BigDecimal refundPrice2 = list.stream().map(OrderPerson::getRealPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ orderRefund.setRefundFee(refundPrice2);
|
|
|
+ list.forEach(x -> x.setRefundStatus(1));
|
|
|
+ iOrderPersonService.updateBatchById(list);
|
|
|
+ //补充订单退款金额
|
|
|
+ if (ObjectUtils.isNull(order.getOrderRefund())){
|
|
|
+ order.setOrderRefund(refundPrice2);
|
|
|
+ }else {
|
|
|
+ order.setOrderRefund(order.getOrderPrice().add(refundPrice2));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //修改订单状态
|
|
|
+ order.setRefundStatus(0);
|
|
|
+ updateById(order);
|
|
|
+ return iOrderRefundService.save(orderRefund);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean edit(OrderEditBo bo) {
|
|
|
+ Order order = getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderSn, bo.getOrderSn()));
|
|
|
+ if (ObjectUtils.isNull(order)){
|
|
|
+ throw new CustomException("订单号有误!");
|
|
|
+ }
|
|
|
+ if (order.getCheckStatus() == 1){
|
|
|
+ throw new CustomException("该订单已审核,请勿修改!");
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isEmpty(bo.getOrderPersonList())){
|
|
|
+ throw new CustomException("订单员工信息未空,请检查!");
|
|
|
+ }
|
|
|
+
|
|
|
+ for (OrderPersonVo personVo : bo.getOrderPersonList()) {
|
|
|
+ OrderPerson orderPerson= iOrderPersonService.getById(personVo.getOrderPersonId());
|
|
|
+ //校验身份证
|
|
|
+ SysPerson person = iSysPersonService.getOne(new LambdaQueryWrapper<SysPerson>()
|
|
|
+ .eq(SysPerson::getIdCard,EncryptHandler.encrypt(personVo.getIdCard()))
|
|
|
+ .eq(SysPerson::getCompanyId,order.getCompanyId()).last("limit 1"));
|
|
|
+
|
|
|
+ if(Validator.isNull(person)){
|
|
|
+ SysPerson sysPerson = new SysPerson();
|
|
|
+ sysPerson.setPersonCode(ServletUtils.getEncoded("YG"));
|
|
|
+ sysPerson.setCompanyId(order.getCompanyId());
|
|
|
+ sysPerson.setPersonName(personVo.getPersonName());
|
|
|
+ sysPerson.setGender(getUserSex(personVo.getIdCard()));
|
|
|
+ sysPerson.setIdCard(personVo.getIdCard());
|
|
|
+ sysPerson.setPhone(personVo.getPhone());
|
|
|
+ sysPerson.setStatus(1);
|
|
|
+ sysPerson.setCreateTime(DateUtils.getNowTime());
|
|
|
+ sysPerson.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ iSysPersonService.save(sysPerson);
|
|
|
+ person = iSysPersonService.getById(sysPerson.getPersonId());
|
|
|
+
|
|
|
+ }
|
|
|
+ orderPerson.setPersonId(person.getPersonId());
|
|
|
+ orderPerson.setPersonName(person.getPersonName());
|
|
|
+ orderPerson.setPersonCard(EncryptHandler.decrypt(person.getIdCard()));
|
|
|
+ orderPerson.setPersonPhone(EncryptHandler.decrypt(person.getPhone()));
|
|
|
+ orderPerson.setYear(personVo.getYear());
|
|
|
+ orderPerson.setSubjectName(personVo.getSubjectName());
|
|
|
+ iOrderPersonService.updateById(orderPerson);
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean revocation(OrderRevocationBo bo) {
|
|
|
+ Order order = getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderSn, bo.getOrderSn()));
|
|
|
+ if (ObjectUtils.isNull(order)){
|
|
|
+ throw new CustomException("订单号有误!");
|
|
|
+ }
|
|
|
+ if (order.getCheckStatus() == 1){
|
|
|
+ throw new CustomException("该订单已审核,请勿修改!");
|
|
|
+ }
|
|
|
+ if (order.getStatus() != 1){
|
|
|
+ throw new CustomException("当前订单已关闭,请勿重复关闭");
|
|
|
+ }
|
|
|
+
|
|
|
+ //订单员工
|
|
|
+ iOrderPersonService.update(new LambdaUpdateWrapper<OrderPerson>()
|
|
|
+ .set(OrderPerson::getStatus,0)
|
|
|
+ .eq(OrderPerson::getOrderSn,bo.getOrderSn()));
|
|
|
+
|
|
|
+ order.setStatus(0);
|
|
|
+ return updateById(order);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TableDataInfo<OrderListVo> getFinanceOrderList(OrderQueryBo bo) {
|
|
|
+ IPage<OrderListVo> page = baseMapper.getFinanceOrderList(new Page<>(bo.getPageNum(), bo.getPageSize()), bo);
|
|
|
+ if (CollectionUtils.isEmpty(page.getRecords())){
|
|
|
+ return new TableDataInfo<OrderListVo>().setRows(new ArrayList<>());
|
|
|
+ }
|
|
|
+
|
|
|
+ page.getRecords().forEach(x -> {
|
|
|
+ List<OrderPerson> personList = iOrderPersonService.listPersonBySn(x.getOrderSn());
|
|
|
+ //人数和订单数
|
|
|
+ Set<Long> userNum = personList.stream().map(OrderPerson::getPersonId).collect(Collectors.toSet());
|
|
|
+ x.setOrderPersonNum(userNum.size());
|
|
|
+ x.setOrderNum(personList.size());
|
|
|
+ });
|
|
|
+ TableDataInfo<OrderListVo> info = new TableDataInfo<>();
|
|
|
+ info.setTotal(page.getTotal());
|
|
|
+ info.setRows(page.getRecords());
|
|
|
+ return info;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public OrderDetailVo getFinanceOrderDetail(String orderSn) {
|
|
|
+ OrderDetailVo detailVo = baseMapper.getFinanceOrderDetail(orderSn);
|
|
|
+ if (Objects.isNull(detailVo)){
|
|
|
+ throw new CustomException("订单获取有误!");
|
|
|
+ }
|
|
|
+ //订单学员
|
|
|
+ List<OrderPerson> orderPeople = iOrderPersonService.listPersonBySn(orderSn);
|
|
|
+ if (CollectionUtils.isNotEmpty(orderPeople)){
|
|
|
+ List<OrderPersonVo> personVos = orderPeople.stream().map(x -> {
|
|
|
+ OrderPersonVo bean = BeanUtil.toBean(x, OrderPersonVo.class);
|
|
|
+ bean.setIdCard(x.getPersonCard());
|
|
|
+ bean.setPhone(x.getPersonPhone());
|
|
|
+ bean.setGender(getUserSex(x.getPersonCard()));
|
|
|
+ return bean;
|
|
|
+ }
|
|
|
+ ).collect(Collectors.toList());
|
|
|
+ detailVo.setOrderPersonList(personVos);
|
|
|
+ //人数和订单数
|
|
|
+ Set<Long> userNum = orderPeople.stream().map(OrderPerson::getPersonId).collect(Collectors.toSet());
|
|
|
+ detailVo.setOrderPersonNum(userNum.size());
|
|
|
+ detailVo.setOrderNum(orderPeople.size());
|
|
|
+ }
|
|
|
+ //订单附件
|
|
|
+ List<OrderAttachment> attachmentList = iOrderAttachmentService.listByOrderSn(orderSn);
|
|
|
+ if (CollectionUtils.isNotEmpty(attachmentList)){
|
|
|
+ List<OrderAttachmentVo> attachmentVos = attachmentList.stream().map(x -> BeanUtil.toBean(x, OrderAttachmentVo.class)).collect(Collectors.toList());
|
|
|
+ detailVo.setOrderAttachmentVos(attachmentVos);
|
|
|
+ }
|
|
|
+ return detailVo;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean checkOrder(OrderCheckBo bo) {
|
|
|
+ if (!bo.getIsAdmin()){
|
|
|
+ //校验审核角色
|
|
|
+ List<SysUserRole> sysUserRoles = sysUserRoleMapper
|
|
|
+ .selectList(new LambdaQueryWrapper<SysUserRole>().eq(SysUserRole::getUserId, bo.getUserId()));
|
|
|
+ if (CollectionUtils.isEmpty(sysUserRoles)){
|
|
|
+ throw new CustomException("当前账号没有审核权限");
|
|
|
+ }
|
|
|
+ List<SysRole> sysRoles = iSysRoleService.listByIds(sysUserRoles.stream().map(SysUserRole::getRoleId).collect(Collectors.toList()));
|
|
|
+ if (!sysRoles.stream().anyMatch(x -> x.getRoleName().contains("审核员"))){
|
|
|
+ throw new CustomException("当前账号没有审核权限");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ OrderDetailVo detailVo = baseMapper.getFinanceOrderDetail(bo.getOrderSn());
|
|
|
+ if (Objects.isNull(detailVo)){
|
|
|
+ throw new CustomException("订单获取有误!");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (detailVo.getCheckStatus() != 0){
|
|
|
+ throw new CustomException("当前订单状态不在待审核,请检查!");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (detailVo.getStatus() == 0){
|
|
|
+ throw new CustomException("当前订单已关闭,请检查!");
|
|
|
+ }
|
|
|
+
|
|
|
+ //机构
|
|
|
+ ServletUtils.getResponse().setHeader("tenantId",detailVo.getTenantId().toString());
|
|
|
+
|
|
|
+ //修改审核状态
|
|
|
+ update(new LambdaUpdateWrapper<Order>().set(Order::getCheckStatus,bo.getCheckStatus()).eq(Order::getOrderSn,bo.getOrderSn()));
|
|
|
+ iOrderPersonService.update(new LambdaUpdateWrapper<OrderPerson>().set(OrderPerson::getPayStatus,3).eq(OrderPerson::getOrderSn,bo.getOrderSn()).eq(OrderPerson::getStatus,1));
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public OrderInvoiceVo getOrderInvoiceApply(String orderSn) {
|
|
|
+ OrderDetailVo detailVo = baseMapper.getFinanceOrderDetail(orderSn);
|
|
|
+ if (Objects.isNull(detailVo)){
|
|
|
+ throw new CustomException("订单获取有误!");
|
|
|
+ }
|
|
|
+ //发票申请信息
|
|
|
+ return baseMapper.getOrderInvoiceApply(orderSn);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean invoiceUpload(InvoiceUploadBo bo) {
|
|
|
+ if (CollectionUtils.isEmpty(bo.getInvoiceUrl())){
|
|
|
+ throw new CustomException("发票地址为空,请检查");
|
|
|
+ }
|
|
|
+ //订单发票信息
|
|
|
+ OrderInvoice invoice = iOrderInvoiceService.getOrderInvoiceById(bo.getInvoiceId());
|
|
|
+ if (Objects.isNull(invoice)){
|
|
|
+ throw new CustomException("发票信息有误");
|
|
|
+ }
|
|
|
+ if (invoice.getPeriodStatus() != 3){
|
|
|
+ throw new CustomException("当前发票审核未通过");
|
|
|
+ }
|
|
|
+ //机构
|
|
|
+ ServletUtils.getResponse().setHeader("tenantId",invoice.getTenantId().toString());
|
|
|
+
|
|
|
+ String url = bo.getInvoiceUrl().stream().collect(Collectors.joining(","));
|
|
|
+ invoice.setInvoiceUrl(url);
|
|
|
+ invoice.setInvoiceStatus(2);
|
|
|
+ iOrderInvoiceService.updateById(invoice);
|
|
|
+
|
|
|
+ //补充发票附件
|
|
|
+ List<OrderAttachment> attachments = bo.getInvoiceUrl().stream().map(x -> {
|
|
|
+ OrderAttachment attachment = new OrderAttachment();
|
|
|
+ attachment.setAttachmentType(3);
|
|
|
+ attachment.setAttachmentUrl(x);
|
|
|
+ attachment.setStatus(1);
|
|
|
+ attachment.setOrderSn(invoice.getOrderSn());
|
|
|
+ attachment.setCreateTime(DateUtils.getNowTime());
|
|
|
+ attachment.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ return attachment;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ iOrderAttachmentService.saveBatch(attachments);
|
|
|
+
|
|
|
+ return update(new LambdaUpdateWrapper<Order>()
|
|
|
+ .set(Order::getInvoiceStatus,1)
|
|
|
+ .eq(Order::getOrderSn,invoice.getOrderSn()));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean invoiceCheckOrder(OrderCheckBo bo) {
|
|
|
+ if (!bo.getIsAdmin()){
|
|
|
+ //校验审核角色
|
|
|
+ List<SysUserRole> sysUserRoles = sysUserRoleMapper
|
|
|
+ .selectList(new LambdaQueryWrapper<SysUserRole>().eq(SysUserRole::getUserId, bo.getUserId()));
|
|
|
+ if (CollectionUtils.isEmpty(sysUserRoles)){
|
|
|
+ throw new CustomException("当前账号没有审核权限");
|
|
|
+ }
|
|
|
+ List<SysRole> sysRoles = iSysRoleService.listByIds(sysUserRoles.stream().map(SysUserRole::getRoleId).collect(Collectors.toList()));
|
|
|
+ if (!sysRoles.stream().anyMatch(x -> x.getRoleName().contains("审核员"))){
|
|
|
+ throw new CustomException("当前账号没有审核权限");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //订单发票信息
|
|
|
+ OrderInvoice invoice = iOrderInvoiceService.getOrderInvoiceById(bo.getInvoiceId());
|
|
|
+ if (Objects.isNull(invoice)){
|
|
|
+ throw new CustomException("发票信息有误");
|
|
|
+ }
|
|
|
+ if (invoice.getPeriodStatus() != 1){
|
|
|
+ throw new CustomException("当前发票审核状态未在待审核,请检查!");
|
|
|
+ }
|
|
|
+
|
|
|
+ OrderDetailVo detailVo = baseMapper.getFinanceOrderDetail(invoice.getOrderSn());
|
|
|
+ if (Objects.isNull(detailVo)){
|
|
|
+ throw new CustomException("订单获取有误!");
|
|
|
+ }
|
|
|
+
|
|
|
+ //机构
|
|
|
+ ServletUtils.getResponse().setHeader("tenantId",invoice.getTenantId().toString());
|
|
|
+ switch (bo.getInvoiceStatus()){
|
|
|
+ case 2: //驳回
|
|
|
+ invoice.setPeriodStatus(2);
|
|
|
+ iOrderInvoiceService.updateById(invoice);
|
|
|
+ update(new LambdaUpdateWrapper<Order>().set(Order::getInvoiceStatus,4).eq(Order::getOrderSn,invoice.getOrderSn()));
|
|
|
+ break;
|
|
|
+ case 3: //通过
|
|
|
+ invoice.setPeriodStatus(3);
|
|
|
+ iOrderInvoiceService.updateById(invoice);
|
|
|
+ update(new LambdaUpdateWrapper<Order>().set(Order::getInvoiceStatus,3).eq(Order::getOrderSn,invoice.getOrderSn()));
|
|
|
+ break;
|
|
|
+ default: throw new CustomException("审核状态不匹配");
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public OrderRefundDetailVo getOrderRefundDetail(String orderSn) {
|
|
|
+ OrderDetailVo detailVo = baseMapper.getFinanceOrderDetail(orderSn);
|
|
|
+ if (Objects.isNull(detailVo)){
|
|
|
+ throw new CustomException("订单获取有误!");
|
|
|
+ }
|
|
|
+ //退款详情
|
|
|
+ OrderRefund refund = iOrderRefundService.getRefundBySn(orderSn);
|
|
|
+ if (ObjectUtils.isNull(refund)){
|
|
|
+ throw new CustomException("退款信息有误");
|
|
|
+ }
|
|
|
+
|
|
|
+ OrderRefundDetailVo refundDetailVo = BeanUtil.toBean(detailVo, OrderRefundDetailVo.class);
|
|
|
+ refundDetailVo.setRefundId(refund.getRefundId());
|
|
|
+ refundDetailVo.setRefundSn(refund.getRefundSn());
|
|
|
+ refundDetailVo.setRefundFee(refund.getRefundFee());
|
|
|
+ refundDetailVo.setApplyReason(refund.getApplyReason());
|
|
|
+ refundDetailVo.setPayee(refund.getPayee());
|
|
|
+ refundDetailVo.setPayeeBank(refund.getPayeeBank());
|
|
|
+ refundDetailVo.setPayeeBankAccount(refund.getPayeeBankAccount());
|
|
|
+ refundDetailVo.setPeriodStatus(refund.getPeriodStatus());
|
|
|
+
|
|
|
+ //退款员工信息
|
|
|
+ if (StringUtils.isNotEmpty(refund.getOrderPersonIds())){
|
|
|
+ //机构
|
|
|
+ ServletUtils.getResponse().setHeader("tenantId",refund.getTenantId().toString());
|
|
|
+
|
|
|
+ List<OrderPerson> orderPeople = iOrderPersonService.listByIds(Arrays.asList(refund.getOrderPersonIds()));
|
|
|
+ if (CollectionUtils.isNotEmpty(orderPeople)){
|
|
|
+ List<OrderPersonVo> collect = orderPeople.stream().map(x -> {
|
|
|
+ OrderPersonVo personVo = BeanUtil.toBean(x, OrderPersonVo.class);
|
|
|
+ personVo.setGender(getUserSex(x.getPersonCard()));
|
|
|
+ return personVo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ refundDetailVo.setOrderPersonList(collect);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return refundDetailVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean refundCheckOrder(OrderCheckBo bo) {
|
|
|
+ if (!bo.getIsAdmin()){
|
|
|
+ //校验审核角色
|
|
|
+ List<SysUserRole> sysUserRoles = sysUserRoleMapper
|
|
|
+ .selectList(new LambdaQueryWrapper<SysUserRole>().eq(SysUserRole::getUserId, bo.getUserId()));
|
|
|
+ if (CollectionUtils.isEmpty(sysUserRoles)){
|
|
|
+ throw new CustomException("当前账号没有审核权限");
|
|
|
+ }
|
|
|
+ List<SysRole> sysRoles = iSysRoleService.listByIds(sysUserRoles.stream().map(SysUserRole::getRoleId).collect(Collectors.toList()));
|
|
|
+ if (!sysRoles.stream().anyMatch(x -> x.getRoleName().contains("审核员"))){
|
|
|
+ throw new CustomException("当前账号没有审核权限");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ OrderDetailVo detailVo = baseMapper.getFinanceOrderDetail(bo.getOrderSn());
|
|
|
+ if (Objects.isNull(detailVo)){
|
|
|
+ throw new CustomException("订单获取有误!");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (detailVo.getRefundStatus() != 0){
|
|
|
+ throw new CustomException("当前订单退款状态未在待审核!");
|
|
|
+ }
|
|
|
+
|
|
|
+ //机构
|
|
|
+ ServletUtils.getResponse().setHeader("tenantId",detailVo.getTenantId().toString());
|
|
|
+ if (bo.getRefundStatus() == 2){
|
|
|
+ //审核不通过
|
|
|
+ OrderRefund orderRefund = iOrderRefundService.getById(bo.getRefundId());
|
|
|
+ orderRefund.setPeriodStatus(2);//未通过
|
|
|
+ orderRefund.setPeriodTime(DateUtils.getNowTime());
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(orderRefund.getOrderPersonIds())){
|
|
|
+ List<OrderPerson> orderPeople = iOrderPersonService.listByIds(Arrays.asList(orderRefund.getOrderPersonIds()));
|
|
|
+ orderPeople.forEach(x -> x.setRefundStatus(3));//拒绝退款
|
|
|
+ iOrderPersonService.updateBatchById(orderPeople);
|
|
|
+ }
|
|
|
+ orderRefund.setPeriodReason(bo.getPeriodReason());
|
|
|
+ iOrderRefundService.updateById(orderRefund);
|
|
|
+
|
|
|
+ Order order = getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderSn, detailVo.getOrderSn()));
|
|
|
+ order.setRefundStatus(1);//未通过
|
|
|
+ //退款金额
|
|
|
+ order.setOrderRefund(order.getOrderRefund().subtract(orderRefund.getRefundFee()));
|
|
|
+ updateById(order);
|
|
|
+ }else if (detailVo.getRefundStatus() == 1){
|
|
|
+ //通过
|
|
|
+
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|