|
@@ -0,0 +1,685 @@
|
|
|
+package com.zhongzheng.modules.order.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.lang.Validator;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
+import com.zhongzheng.common.core.redis.RedisCache;
|
|
|
+import com.zhongzheng.common.exception.CustomException;
|
|
|
+import com.zhongzheng.common.utils.DateUtils;
|
|
|
+import com.zhongzheng.common.utils.ServletUtils;
|
|
|
+import com.zhongzheng.modules.course.domain.CourseBusiness;
|
|
|
+import com.zhongzheng.modules.goods.domain.Goods;
|
|
|
+import com.zhongzheng.modules.goods.service.IGoodsService;
|
|
|
+import com.zhongzheng.modules.order.bo.*;
|
|
|
+import com.zhongzheng.modules.order.domain.*;
|
|
|
+import com.zhongzheng.modules.order.mapper.OrderHandleMapper;
|
|
|
+import com.zhongzheng.modules.order.service.*;
|
|
|
+import com.zhongzheng.modules.order.vo.OrderHandleGoodsVo;
|
|
|
+import com.zhongzheng.modules.order.vo.OrderHandleStatisticsVo;
|
|
|
+import com.zhongzheng.modules.order.vo.OrderHandleVo;
|
|
|
+import com.zhongzheng.modules.system.domain.SysTenant;
|
|
|
+import com.zhongzheng.modules.system.service.ISysTenantService;
|
|
|
+import com.zhongzheng.modules.system.vo.SysTenantHandleAccountVo;
|
|
|
+import com.zhongzheng.modules.user.bo.SubjectStudyRecordQueryBo;
|
|
|
+import com.zhongzheng.modules.user.service.IUserService;
|
|
|
+import com.zhongzheng.modules.user.service.IUserStudyRecordService;
|
|
|
+import com.zhongzheng.modules.user.vo.SubjectStudyRecordVo;
|
|
|
+import com.zhongzheng.modules.user.vo.UserVo;
|
|
|
+import com.zhongzheng.modules.wx.service.IWxPayService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.github.pagehelper.Page;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 经办录单Service业务层处理
|
|
|
+ *
|
|
|
+ * @author hjl
|
|
|
+ * @date 2024-01-19
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class OrderHandleServiceImpl extends ServiceImpl<OrderHandleMapper, OrderHandle> implements IOrderHandleService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IUserService iUserService;
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IOrderService iOrderService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IWxPayService iWxPayService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IOrderPayService iOrderPayService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IUserStudyRecordService iUserStudyRecordService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysTenantService sysTenantService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IOrderInvoiceOrderService iOrderInvoiceOrderService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IOrderInvoiceService iOrderInvoiceService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IOrderGoodsRefundService iOrderGoodsRefundService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IOrderGoodsService iOrderGoodsService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IGoodsService iGoodsService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RedisCache redisCache;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public OrderHandleVo queryById(Long id) {
|
|
|
+ OrderHandle db = this.baseMapper.selectById(id);
|
|
|
+ return BeanUtil.toBean(db, OrderHandleVo.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public OrderHandle queryBySn(String handleOrderSn) {
|
|
|
+ return getOne(new LambdaQueryWrapper<OrderHandle>().eq(OrderHandle::getHandleOrderSn, handleOrderSn));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<OrderHandleVo> queryList(OrderHandleQueryBo bo) {
|
|
|
+ LambdaQueryWrapper<OrderHandle> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.eq(StrUtil.isNotBlank(bo.getHandleOrderSn()), OrderHandle::getHandleOrderSn, bo.getHandleOrderSn());
|
|
|
+ lqw.like(StrUtil.isNotBlank(bo.getCreateUsername()), OrderHandle::getCreateUsername, bo.getCreateUsername());
|
|
|
+ lqw.eq(bo.getStatus() != null, OrderHandle::getStatus, bo.getStatus());
|
|
|
+ lqw.eq(bo.getCreateUserId() != null, OrderHandle::getCreateUserId, bo.getCreateUserId());
|
|
|
+ lqw.eq(bo.getEducationTypeId() != null, OrderHandle::getEducationTypeId, bo.getEducationTypeId());
|
|
|
+ lqw.eq(bo.getBusinessId() != null, OrderHandle::getBusinessId, bo.getBusinessId());
|
|
|
+ lqw.eq(bo.getProjectId() != null, OrderHandle::getProjectId, bo.getProjectId());
|
|
|
+ lqw.eq(bo.getInputFrom() != null, OrderHandle::getInputFrom, bo.getInputFrom());
|
|
|
+ lqw.eq(bo.getPayStatus() != null, OrderHandle::getPayStatus, bo.getPayStatus());
|
|
|
+ lqw.eq(bo.getGoodsType() != null, OrderHandle::getGoodsType, bo.getGoodsType());
|
|
|
+ return entity2Vo(this.list(lqw));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<OrderHandleVo> selectList(OrderHandleQueryBo bo) {
|
|
|
+ List<OrderHandleVo> orderHandleVos = baseMapper.selectOrderList(bo);
|
|
|
+ if (CollectionUtils.isEmpty(orderHandleVos)) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ orderHandleVos.forEach(item -> {
|
|
|
+ //实际价格
|
|
|
+ item.setRealPrice(item.getPayPrice().subtract(item.getGoodsRefund()));
|
|
|
+ //发票
|
|
|
+ List<OrderInvoiceOrder> list = iOrderInvoiceOrderService
|
|
|
+ .list(new LambdaQueryWrapper<OrderInvoiceOrder>()
|
|
|
+ .eq(OrderInvoiceOrder::getOrderSn, item.getHandleOrderSn()));
|
|
|
+ if (CollectionUtils.isNotEmpty(list)) {
|
|
|
+ List<OrderInvoice> invoices = iOrderInvoiceService.list(new LambdaQueryWrapper<OrderInvoice>()
|
|
|
+ .in(OrderInvoice::getInvoiceId, list.stream().map(OrderInvoiceOrder::getInvoiceId).collect(Collectors.toList()))
|
|
|
+ .and(x -> x.isNull(OrderInvoice::getWashStatus).or().eq(OrderInvoice::getWashStatus, 1)
|
|
|
+ .eq(OrderInvoice::getStatus, 1))
|
|
|
+ .orderByDesc(OrderInvoice::getCreateTime));
|
|
|
+ if (CollectionUtils.isNotEmpty(invoices)) {
|
|
|
+ OrderInvoice invoice = invoices.get(0);
|
|
|
+ if (invoice.getInvoiceStatus() == 2) {
|
|
|
+ item.setInvoiceStatus(invoice.getInvoiceStatus());
|
|
|
+ } else if (invoice.getPeriodStatus() == 1) {
|
|
|
+ item.setInvoiceStatus(invoice.getPeriodStatus());
|
|
|
+ } else if (invoice.getPeriodStatus() == 2) {
|
|
|
+ item.setInvoiceStatus(3);
|
|
|
+ }else {
|
|
|
+ item.setInvoiceStatus(invoice.getInvoiceStatus());
|
|
|
+ }
|
|
|
+ item.setHandleRemark(invoice.getHandleRemark());
|
|
|
+ item.setInvoiceMode(invoice.getInvoiceMode());
|
|
|
+ item.setInvoiceReason(invoice.getPeriodReason());
|
|
|
+ item.setInvoiceUrl(invoices.stream().filter(x -> StringUtils.isNotBlank(x.getInvoiceImg())).map(OrderInvoice::getInvoiceImg).collect(Collectors.joining(",")));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //退款
|
|
|
+ if (ObjectUtils.isNotNull(item.getRefundStatus()) && item.getRefundStatus() == 0) {
|
|
|
+ List<Order> orders = iOrderService.list(new LambdaQueryWrapper<Order>().eq(Order::getHandleOrderSn, item.getHandleOrderSn()));
|
|
|
+ List<OrderGoodsRefund> list1 = iOrderGoodsRefundService.list(new LambdaQueryWrapper<OrderGoodsRefund>()
|
|
|
+ .in(OrderGoodsRefund::getOrderSn, orders.stream().map(Order::getOrderSn).collect(Collectors.toList()))
|
|
|
+ .eq(OrderGoodsRefund::getStatus, 1)
|
|
|
+ .eq(OrderGoodsRefund::getPeriodStatus, 0));
|
|
|
+ if (CollectionUtils.isNotEmpty(list1)) {
|
|
|
+ OrderGoodsRefund refund = list1.get(0);
|
|
|
+ item.setPayee(refund.getPayee());
|
|
|
+ item.setPayeeBank(refund.getPayeeBank());
|
|
|
+ item.setPayeeBankAccount(refund.getPayeeBankAccount());
|
|
|
+ item.setRefundCheckReason(refund.getPeriodReason());
|
|
|
+ item.setRefundApplyReason(refund.getApplyReason());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return orderHandleVos;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<OrderHandleGoodsVo> selectOrderGoodsList(OrderHandleQueryBo bo) {
|
|
|
+ List<OrderHandleGoodsVo> list = this.baseMapper.selectOrderGoodsList(bo);
|
|
|
+ for (OrderHandleGoodsVo vo : list) {
|
|
|
+ Long secLong = 0L;
|
|
|
+ Long studyLong = 0L;
|
|
|
+
|
|
|
+ if (vo.getPayStatus() == 1) {
|
|
|
+ SubjectStudyRecordQueryBo subjectStudyRecordQueryBo = new SubjectStudyRecordQueryBo();
|
|
|
+ subjectStudyRecordQueryBo.setGoodsId(vo.getGoodsId());
|
|
|
+ subjectStudyRecordQueryBo.setUserId(vo.getUserId());
|
|
|
+ subjectStudyRecordQueryBo.setGradeId(vo.getGradeId());
|
|
|
+ subjectStudyRecordQueryBo.setOrderGoodsId(vo.getOrderGoodsId());
|
|
|
+ List<SubjectStudyRecordVo> subjectStudyRecordVos = iUserStudyRecordService.listSubject(subjectStudyRecordQueryBo);
|
|
|
+ for (SubjectStudyRecordVo subjectStudyRecordVo : subjectStudyRecordVos) {
|
|
|
+ secLong = new BigDecimal(secLong.toString()).add(new BigDecimal(subjectStudyRecordVo.getSectionNum().toString())).longValue();
|
|
|
+ studyLong = new BigDecimal(studyLong.toString()).add(new BigDecimal(subjectStudyRecordVo.getRecordNum().toString())).longValue();
|
|
|
+
|
|
|
+ }
|
|
|
+ vo.setSecAllNum(secLong);
|
|
|
+ vo.setStuAllNum(studyLong);
|
|
|
+ }
|
|
|
+ //退款
|
|
|
+ OrderGoodsRefund refund = iOrderGoodsRefundService
|
|
|
+ .getOne(new LambdaQueryWrapper<OrderGoodsRefund>()
|
|
|
+ .eq(OrderGoodsRefund::getOrderGoodsId, vo.getOrderGoodsId())
|
|
|
+ .eq(OrderGoodsRefund::getStatus, 1)
|
|
|
+ .orderByDesc(OrderGoodsRefund::getCreateTime)
|
|
|
+ .last("limit 1"));
|
|
|
+ if (ObjectUtils.isNotNull(refund)) {
|
|
|
+ vo.setRefundStatus(refund.getPeriodStatus());
|
|
|
+ vo.setRefundReason(refund.getApplyReason());
|
|
|
+ vo.setPeriodReason(refund.getPeriodReason());
|
|
|
+ vo.setRefundCheckReason(refund.getPeriodReason());
|
|
|
+ vo.setRefundApplyReason(refund.getApplyReason());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 实体类转化成视图对象
|
|
|
+ *
|
|
|
+ * @param collection 实体类集合
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<OrderHandleVo> entity2Vo(Collection<OrderHandle> collection) {
|
|
|
+ List<OrderHandleVo> voList = collection.stream()
|
|
|
+ .map(any -> BeanUtil.toBean(any, OrderHandleVo.class))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (collection instanceof Page) {
|
|
|
+ Page<OrderHandle> page = (Page<OrderHandle>) collection;
|
|
|
+ Page<OrderHandleVo> pageVo = new Page<>();
|
|
|
+ BeanUtil.copyProperties(page, pageVo);
|
|
|
+ pageVo.addAll(voList);
|
|
|
+ voList = pageVo;
|
|
|
+ }
|
|
|
+ return voList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String insertByAddBo(OrderHandleAddBo bo) {
|
|
|
+ if (Validator.isEmpty(bo.getBusinessId()) || Validator.isEmpty(bo.getGoodsType()) || Validator.isEmpty(bo.getInputFrom()) || Validator.isEmpty(bo.getPayType())) {
|
|
|
+ throw new CustomException("参数缺失");
|
|
|
+ }
|
|
|
+ OrderHandle add = BeanUtil.toBean(bo, OrderHandle.class);
|
|
|
+ validEntityBeforeSave(add);
|
|
|
+ add.setCreateTime(DateUtils.getNowTime());
|
|
|
+ add.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ add.setHandleOrderSn(DateUtils.getTagOrderSn("HD"));
|
|
|
+ add.setOverTime(DateUtils.getNowTime() + 7 * 24 * 3600);
|
|
|
+ if (Validator.isEmpty(add.getInputFrom())) {
|
|
|
+ add.setInputFrom(1);
|
|
|
+ }
|
|
|
+ String tenantId = ServletUtils.getRequest().getHeader("TenantId");
|
|
|
+ SysTenant tenant = sysTenantService.getById(tenantId);
|
|
|
+ //账号信息
|
|
|
+ String information = tenant.getHandleBank();
|
|
|
+ SysTenantHandleAccountVo accountVo = JSONObject.parseObject(information, SysTenantHandleAccountVo.class);
|
|
|
+ if (Validator.isNotEmpty(accountVo)) {
|
|
|
+ add.setRecCompanyAccount(accountVo.getRecCompanyAccount());
|
|
|
+ add.setRecCompanyBank(accountVo.getRecCompanyBank());
|
|
|
+ add.setRecCompanyName(accountVo.getRecCompanyName());
|
|
|
+ }
|
|
|
+ if (this.save(add)) {
|
|
|
+ return add.getHandleOrderSn();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public String createOrder(OrderHandleAddBo bo) {
|
|
|
+ String key = "SUBMIT_HANDLE:"+bo.getCreateUserId()+"-"+bo.getUserGoodsList().size();
|
|
|
+ Long keyStatus = redisCache.getCacheObject(key);
|
|
|
+ if(Validator.isNotEmpty(keyStatus)&&keyStatus==100L){
|
|
|
+ throw new CustomException("禁止频繁提交",667);
|
|
|
+ }
|
|
|
+ redisCache.setCacheObject(key, 100L,60, TimeUnit.SECONDS);
|
|
|
+
|
|
|
+ String handleOrderSn = insertByAddBo(bo);
|
|
|
+ String importNo = ServletUtils.getEncoded("IMPORT");
|
|
|
+ Map<String,String> telMap = new HashMap<>();
|
|
|
+ Map<String,String> idMap = new HashMap<>();
|
|
|
+ for (OrderHandleItemAddBo itemAddBo : bo.getUserGoodsList()) {
|
|
|
+ if(Validator.isNotEmpty(itemAddBo.getUser().getTelphone())){
|
|
|
+ if(!telMap.containsKey(itemAddBo.getUser().getTelphone())){
|
|
|
+ telMap.put(itemAddBo.getUser().getTelphone(),itemAddBo.getUser().getIdCard());
|
|
|
+ }else{
|
|
|
+ redisCache.deleteObject(key);
|
|
|
+ throw new CustomException("本次名单存在手机号码"+itemAddBo.getUser().getTelphone()+"重复用户");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(Validator.isNotEmpty(itemAddBo.getUser().getIdCard())){
|
|
|
+ if(!idMap.containsKey(itemAddBo.getUser().getIdCard())){
|
|
|
+ idMap.put(itemAddBo.getUser().getIdCard(),itemAddBo.getUser().getTelphone());
|
|
|
+ }else{
|
|
|
+ redisCache.deleteObject(key);
|
|
|
+ throw new CustomException("本次名单存在身份证号码"+itemAddBo.getUser().getIdCard ()+"重复用户");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (OrderHandleItemAddBo itemAddBo : bo.getUserGoodsList()) {
|
|
|
+ if (Validator.isEmpty(itemAddBo.getUser().getUserId())) {
|
|
|
+ if (Validator.isEmpty(itemAddBo.getUser().getEduLevel()) || Validator.isEmpty(itemAddBo.getUser().getCompanyName()) || Validator.isEmpty(itemAddBo.getUser().getSex())) {
|
|
|
+ redisCache.deleteObject(key);
|
|
|
+ throw new CustomException("用户参数缺失");
|
|
|
+ }
|
|
|
+ Long userId = iUserService.importUser(itemAddBo.getUser(), importNo);
|
|
|
+ itemAddBo.getUser().setUserId(userId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (OrderHandleItemAddBo itemAddBo : bo.getUserGoodsList()) {
|
|
|
+ OrderAddBo addBo = new OrderAddBo();
|
|
|
+ addBo.setUserId(itemAddBo.getUser().getUserId());
|
|
|
+ addBo.setGoodsList(itemAddBo.getGoodsList());
|
|
|
+ addBo.setHandleOrderSn(handleOrderSn);
|
|
|
+ iOrderService.placePlatHandleOrder(addBo);
|
|
|
+ }
|
|
|
+ redisCache.deleteObject(key);
|
|
|
+ return handleOrderSn;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, String> resumePayOrder(OrderHandleAddBo bo) {
|
|
|
+ if (Validator.isEmpty(bo.getHandleOrderSn())) {
|
|
|
+ throw new CustomException("录单单号为空");
|
|
|
+ }
|
|
|
+ if (Validator.isEmpty(bo.getPayType())) {
|
|
|
+ throw new CustomException("支付方式缺失");
|
|
|
+ }
|
|
|
+ OrderHandle orderHandle = queryBySn(bo.getHandleOrderSn());
|
|
|
+ if (Validator.isEmpty(orderHandle)) {
|
|
|
+ throw new CustomException("录单单号不存在");
|
|
|
+ }
|
|
|
+ if (orderHandle.getPayStatus() != 0) {
|
|
|
+ throw new CustomException("非支付状态");
|
|
|
+ }
|
|
|
+ if (orderHandle.getOverTime() < DateUtils.getNowTime()) {
|
|
|
+ throw new CustomException("已超时关闭");
|
|
|
+ }
|
|
|
+ UserVo userVo = iUserService.queryById(bo.getCreateUserId());
|
|
|
+ if (bo.getPayType() == 1) {
|
|
|
+ Map<String, String> payResult = new HashMap<>();
|
|
|
+ if (orderHandle.getPayPrice().compareTo(BigDecimal.ZERO) != 0) {
|
|
|
+ OrderPayAddBo payAddBo = new OrderPayAddBo();
|
|
|
+ //生成支付单号
|
|
|
+ String pay_no = DateUtils.getPayOrderSn();
|
|
|
+ payAddBo.setPaySn(pay_no);
|
|
|
+ payAddBo.setOrderSn(orderHandle.getHandleOrderSn());
|
|
|
+ payAddBo.setStatus(0);
|
|
|
+ payAddBo.setPayPrice(orderHandle.getPayPrice());
|
|
|
+ payAddBo.setOrderFrom(2);
|
|
|
+ iOrderPayService.insertByAddBo(payAddBo);
|
|
|
+ String body = "中正云-订单:" + orderHandle.getHandleOrderSn();
|
|
|
+ payResult = iWxPayService.paymentPc(pay_no, userVo.getOpenId(), body, orderHandle.getPayPrice());
|
|
|
+ payResult.put("orderSn", orderHandle.getHandleOrderSn());
|
|
|
+ return payResult;
|
|
|
+ }
|
|
|
+ } else if (bo.getPayType() == 2) {
|
|
|
+ if (Validator.isEmpty(bo.getCompanyName()) || Validator.isEmpty(bo.getCompanyTel()) || Validator.isEmpty(bo.getCompanyPayImg())) {
|
|
|
+ throw new CustomException("对公凭证缺失");
|
|
|
+ }
|
|
|
+ LambdaUpdateWrapper<OrderHandle> objectLambdaUpdateWrapper = Wrappers.lambdaUpdate();
|
|
|
+ objectLambdaUpdateWrapper.eq(OrderHandle::getId, orderHandle.getId());
|
|
|
+ objectLambdaUpdateWrapper.set(OrderHandle::getCompanyName, bo.getCompanyName());
|
|
|
+ objectLambdaUpdateWrapper.set(OrderHandle::getCompanyTel, bo.getCompanyTel());
|
|
|
+ objectLambdaUpdateWrapper.set(OrderHandle::getCompanyRemark, bo.getCompanyRemark());
|
|
|
+ objectLambdaUpdateWrapper.set(OrderHandle::getCompanyPayImg, bo.getCompanyPayImg());
|
|
|
+ objectLambdaUpdateWrapper.set(OrderHandle::getUpdateTime, DateUtils.getNowTime());
|
|
|
+ objectLambdaUpdateWrapper.set(OrderHandle::getPayStatus, 2);
|
|
|
+ objectLambdaUpdateWrapper.set(OrderHandle::getPayType, 2);
|
|
|
+ this.update(null, objectLambdaUpdateWrapper);
|
|
|
+
|
|
|
+ LambdaUpdateWrapper<Order> objectLambdaUpdateWrapper2 = Wrappers.lambdaUpdate();
|
|
|
+ objectLambdaUpdateWrapper2.eq(Order::getHandleOrderSn, orderHandle.getHandleOrderSn());
|
|
|
+ objectLambdaUpdateWrapper2.set(Order::getPayType, 7);
|
|
|
+ objectLambdaUpdateWrapper2.set(Order::getUpdateTime, DateUtils.getNowTime());
|
|
|
+ iOrderService.update(null, objectLambdaUpdateWrapper2);
|
|
|
+
|
|
|
+ Map<String, String> payResult = new HashMap<>();
|
|
|
+ return payResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean closeOrder(OrderHandleAddBo bo) {
|
|
|
+ OrderHandle orderHandle = queryBySn(bo.getHandleOrderSn());
|
|
|
+ if (Validator.isEmpty(orderHandle)) {
|
|
|
+ throw new CustomException("录单单号不存在");
|
|
|
+ }
|
|
|
+ if (orderHandle.getPayStatus() != 0) {
|
|
|
+ throw new CustomException("非待支付状态");
|
|
|
+ }
|
|
|
+ LambdaUpdateWrapper<OrderHandle> objectLambdaUpdateWrapper = Wrappers.lambdaUpdate();
|
|
|
+ objectLambdaUpdateWrapper.eq(OrderHandle::getId, orderHandle.getId());
|
|
|
+ objectLambdaUpdateWrapper.set(OrderHandle::getUpdateTime, DateUtils.getNowTime());
|
|
|
+ objectLambdaUpdateWrapper.set(OrderHandle::getCloseTime, DateUtils.getNowTime());
|
|
|
+ objectLambdaUpdateWrapper.set(OrderHandle::getPayStatus, -1);
|
|
|
+ this.update(null, objectLambdaUpdateWrapper);
|
|
|
+
|
|
|
+ List<Order> list = iOrderService.list(new LambdaQueryWrapper<Order>().eq(Order::getHandleOrderSn, orderHandle.getHandleOrderSn()));
|
|
|
+ for (Order order : list) {
|
|
|
+ OrderEditBo editBo = new OrderEditBo();
|
|
|
+ editBo.setOrderId(order.getOrderId());
|
|
|
+ editBo.setOrderStatus(-1);
|
|
|
+ iOrderService.updateByEditBo(editBo);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean overTimeCloseOrder() {
|
|
|
+ List<OrderHandle> list = this.list(new LambdaQueryWrapper<OrderHandle>().eq(OrderHandle::getPayStatus, 0).lt(OrderHandle::getOverTime,DateUtils.getNowTime()));
|
|
|
+ for(OrderHandle orderHandle : list){
|
|
|
+ OrderHandleAddBo addBo = new OrderHandleAddBo();
|
|
|
+ addBo.setHandleOrderSn(orderHandle.getHandleOrderSn());
|
|
|
+ closeOrder(addBo);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean updateByEditBo(OrderHandleEditBo bo) {
|
|
|
+ OrderHandle update = BeanUtil.toBean(bo, OrderHandle.class);
|
|
|
+ validEntityBeforeSave(update);
|
|
|
+ update.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ return this.updateById(update);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean updateRefuseBo(OrderHandleEditBo bo) {
|
|
|
+ OrderHandle orderHandle = queryBySn(bo.getHandleOrderSn());
|
|
|
+ if (Validator.isEmpty(orderHandle)) {
|
|
|
+ throw new CustomException("录单单号不存在");
|
|
|
+ }
|
|
|
+ if (orderHandle.getPayStatus()!=-2) {
|
|
|
+ throw new CustomException("非拒绝状态");
|
|
|
+ }
|
|
|
+ OrderHandle update = new OrderHandle();
|
|
|
+ update.setId(orderHandle.getId());
|
|
|
+ update.setPayStatus(2);
|
|
|
+ update.setCompanyPayImg(bo.getCompanyPayImg());
|
|
|
+ update.setCompanyName(bo.getCompanyName());
|
|
|
+ update.setCompanyTel(bo.getCompanyTel());
|
|
|
+ update.setCompanyRemark(bo.getCompanyRemark());
|
|
|
+ validEntityBeforeSave(update);
|
|
|
+ update.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ return this.updateById(update);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存前的数据校验
|
|
|
+ *
|
|
|
+ * @param entity 实体类数据
|
|
|
+ */
|
|
|
+ private void validEntityBeforeSave(OrderHandle entity) {
|
|
|
+ //TODO 做一些数据校验,如唯一约束
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
+ if (isValid) {
|
|
|
+ //TODO 做一些业务上的校验,判断是否需要校验
|
|
|
+ }
|
|
|
+ return this.removeByIds(ids);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public boolean refundApply(OrderHandleRefundBo bo) {
|
|
|
+ if (ObjectUtils.isNull(bo.getHandleOrderSn())) {
|
|
|
+ throw new CustomException("请先选择订单");
|
|
|
+ }
|
|
|
+ OrderHandle orderHandle = getOne(new LambdaQueryWrapper<OrderHandle>().eq(OrderHandle::getHandleOrderSn, bo.getHandleOrderSn()));
|
|
|
+ if (ObjectUtils.isNull(orderHandle)) {
|
|
|
+ throw new CustomException("订单信息有误");
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotNull(orderHandle.getRefundStatus()) && orderHandle.getRefundStatus() == 0) {
|
|
|
+ throw new CustomException("当前订单存在退款审核,请先处理");
|
|
|
+ }
|
|
|
+ if (orderHandle.getPayType() == 2) {
|
|
|
+ //对公
|
|
|
+ if (ObjectUtils.isNull(bo.getPayee()) || ObjectUtils.isNull(bo.getPayeeBank()) || ObjectUtils.isNull(bo.getPayeeBankAccount())) {
|
|
|
+ throw new CustomException("请先填写收款信息");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ bo.getOrderGoodsIds().forEach(orderGoodsId -> {
|
|
|
+ OrderGoods orderGoods = iOrderGoodsService.getById(orderGoodsId);
|
|
|
+ orderGoods.setRefundStatus(1);//申请退款
|
|
|
+ iOrderGoodsService.updateById(orderGoods);
|
|
|
+ Order order = iOrderService.getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderSn, orderGoods.getOrderSn()));
|
|
|
+ order.setOrderRefundStatus(0);
|
|
|
+ iOrderService.updateById(order);
|
|
|
+ //创建退款信息
|
|
|
+ OrderGoodsRefund refund = new OrderGoodsRefund();
|
|
|
+ refund.setCreateTime(DateUtils.getNowTime());
|
|
|
+ refund.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ //退款单号
|
|
|
+ String out_trade_no = DateUtils.getDateOrderSn();
|
|
|
+ refund.setRefundSn(out_trade_no);
|
|
|
+ refund.setUserId(order.getUserId());
|
|
|
+ refund.setOrderSn(order.getOrderSn());
|
|
|
+ refund.setGoodsId(orderGoods.getGoodsId());
|
|
|
+ refund.setRefundFee(orderGoods.getGoodsPrice());
|
|
|
+ refund.setRealRefundFee(orderGoods.getGoodsRealPrice());
|
|
|
+ refund.setApplyReason(bo.getRefundReason());
|
|
|
+ refund.setType(3);//企业订单
|
|
|
+ refund.setOrderGoodsId(orderGoods.getOrderGoodsId());
|
|
|
+ refund.setPeriodStatus(0);//待审核
|
|
|
+ refund.setPayee(bo.getPayee());
|
|
|
+ refund.setPayeeBank(bo.getPayeeBank());
|
|
|
+ refund.setPayeeBankAccount(bo.getPayeeBankAccount());
|
|
|
+ iOrderGoodsRefundService.save(refund);
|
|
|
+ });
|
|
|
+ orderHandle.setRefundStatus(0);//待审核
|
|
|
+ orderHandle.setRefundPrice(bo.getRefundPrice());
|
|
|
+ return updateById(orderHandle);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public OrderHandleStatisticsVo statistics(OrderHandleQueryBo bo) {
|
|
|
+ List<OrderHandleVo> orderHandleVos = baseMapper.selectOrderList(bo);
|
|
|
+ BigDecimal payPrice = orderHandleVos.stream().filter(x -> ObjectUtils.isNotNull(x.getOrderPrice())).map(OrderHandleVo::getOrderPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ BigDecimal refundPrice = orderHandleVos.stream().filter(x -> ObjectUtils.isNotNull(x.getGoodsRefund())).map(OrderHandleVo::getGoodsRefund).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ BigDecimal orderPrice = payPrice.subtract(refundPrice);
|
|
|
+ Integer orderNum = orderHandleVos.size();
|
|
|
+ Set<Long> userIds = new HashSet<>();
|
|
|
+ orderHandleVos.forEach(item -> {
|
|
|
+ List<Order> list = iOrderService.list(new LambdaQueryWrapper<Order>().eq(Order::getHandleOrderSn, item.getHandleOrderSn()).eq(Order::getStatus, 1));
|
|
|
+ if (CollectionUtils.isNotEmpty(list)) {
|
|
|
+ list.forEach(x -> userIds.add(x.getUserId()));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ Integer unCheckOrderNum = orderHandleVos.stream().filter(x -> ObjectUtils.isNotNull(x.getPayStatus()) && x.getPayStatus() == 2).collect(Collectors.toList()).size();
|
|
|
+ Integer unRefundNum = orderHandleVos.stream().filter(x -> ObjectUtils.isNotNull(x.getRefundStatus()) && x.getRefundStatus() == 0).collect(Collectors.toList()).size();
|
|
|
+
|
|
|
+ OrderHandleStatisticsVo vo = new OrderHandleStatisticsVo();
|
|
|
+ vo.setOrderPrice(orderPrice);
|
|
|
+ vo.setRefundPrice(refundPrice);
|
|
|
+ vo.setPayPrice(payPrice);
|
|
|
+ vo.setOrderNum(orderNum);
|
|
|
+ vo.setUnCheckOrderNum(unCheckOrderNum);
|
|
|
+ vo.setUnRefundNum(unRefundNum);
|
|
|
+ vo.setOrderUserNum(userIds.size());
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public boolean checkOrderHandle(OrderHandleCheckBo bo) {
|
|
|
+ OrderHandle orderHandle = getOne(new LambdaQueryWrapper<OrderHandle>().eq(OrderHandle::getHandleOrderSn, bo.getOrderHandleSn()));
|
|
|
+ if (ObjectUtils.isNull(orderHandle)) {
|
|
|
+ throw new CustomException("订单不存在,请检查");
|
|
|
+ }
|
|
|
+ if (orderHandle.getPayStatus() != 2) {
|
|
|
+ throw new CustomException("订单不需要审核,请检查");
|
|
|
+ }
|
|
|
+ switch (bo.getCheckResult()) {
|
|
|
+ case 1://通过
|
|
|
+ List<Order> list = iOrderService.list(new LambdaQueryWrapper<Order>().eq(Order::getHandleOrderSn, bo.getOrderHandleSn()));
|
|
|
+ list.forEach(item -> {
|
|
|
+ iWxPayService.dealOrder(item.getOrderSn(), "");
|
|
|
+ });
|
|
|
+ orderHandle.setPayStatus(1);//已通过
|
|
|
+ orderHandle.setPayTime(DateUtils.getNowTime());
|
|
|
+ orderHandle.setCheckTime(DateUtils.getNowTime());
|
|
|
+ orderHandle.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ updateById(orderHandle);
|
|
|
+ break;
|
|
|
+ case 2://不通过
|
|
|
+ orderHandle.setPayStatus(-2);//不通过
|
|
|
+ orderHandle.setCheckReason(bo.getCheckReason());
|
|
|
+ orderHandle.setCheckTime(DateUtils.getNowTime());
|
|
|
+ updateById(orderHandle);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean refundOrderHandle(OrderHandleCheckBo bo) {
|
|
|
+ OrderHandle orderHandle = getOne(new LambdaQueryWrapper<OrderHandle>().eq(OrderHandle::getHandleOrderSn, bo.getOrderHandleSn()));
|
|
|
+ if (ObjectUtils.isNull(orderHandle)) {
|
|
|
+ throw new CustomException("订单不存在,请检查");
|
|
|
+ }
|
|
|
+ if (orderHandle.getRefundStatus() != 0) {
|
|
|
+ throw new CustomException("订单不需要退款审核,请检查");
|
|
|
+ }
|
|
|
+ List<Order> orderList = iOrderService
|
|
|
+ .list(new LambdaQueryWrapper<Order>().eq(Order::getHandleOrderSn, bo.getOrderHandleSn())
|
|
|
+ .eq(Order::getOrderRefundStatus, 0));
|
|
|
+ if (CollectionUtils.isEmpty(orderList)) {
|
|
|
+ throw new CustomException("未找到待审核退款订单,请检查");
|
|
|
+ }
|
|
|
+ List<OrderGoods> orderGoodsList = iOrderGoodsService.list(new LambdaQueryWrapper<OrderGoods>()
|
|
|
+ .in(OrderGoods::getOrderSn, orderList.stream().map(Order::getOrderSn).collect(Collectors.toList()))
|
|
|
+ .eq(OrderGoods::getRefundStatus, 1)
|
|
|
+ .eq(OrderGoods::getStatus, 1));
|
|
|
+
|
|
|
+ List<OrderGoodsRefund> goodsRefundList = iOrderGoodsRefundService.list(new LambdaQueryWrapper<OrderGoodsRefund>()
|
|
|
+ .in(OrderGoodsRefund::getOrderGoodsId, orderGoodsList.stream().map(OrderGoods::getOrderGoodsId).collect(Collectors.toList()))
|
|
|
+ .eq(OrderGoodsRefund::getStatus, 1)
|
|
|
+ .eq(OrderGoodsRefund::getPeriodStatus, 0));
|
|
|
+
|
|
|
+ switch (bo.getCheckResult()) {
|
|
|
+ case 1://通过
|
|
|
+ if (orderHandle.getPayType() == 1) {
|
|
|
+ //微信支付
|
|
|
+ goodsRefundList.forEach(refund -> {
|
|
|
+ Order order = iOrderService.getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderSn, refund.getOrderSn()));
|
|
|
+ Map<String, String> payResult = iWxPayService.refund(refund.getRefundSn(), order.getTransid(), refund.getRealRefundFee(), order.getPayPrice());
|
|
|
+ if ("OK".equals(payResult.get("return_msg")) && Validator.isNotEmpty(payResult.get("refund_id"))) {
|
|
|
+ OrderGoods orderGoods = iOrderGoodsService.getById(refund.getOrderGoodsId());
|
|
|
+ Goods goods = iGoodsService.getById(orderGoods.getGoodsId());
|
|
|
+ iOrderGoodsRefundService.refundCall(payResult.get("refund_id"), refund.getRefundId(), orderGoods.getOrderGoodsId(), order, goods.getGoodsType(), orderGoods.getGradeId(), order.getUserId(), goods.getGoodsId());
|
|
|
+ //关闭C端用户的分销返利
|
|
|
+ iOrderGoodsRefundService.shareClientCancelOldSys(order, orderGoods, refund.getRealRefundFee());
|
|
|
+ } else {
|
|
|
+ throw new CustomException("退款错误" + JSON.toJSONString(payResult));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ //对公转账
|
|
|
+ goodsRefundList.forEach(refund -> {
|
|
|
+ Order order = iOrderService.getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderSn, refund.getOrderSn()));
|
|
|
+ OrderGoods orderGoods = iOrderGoodsService.getById(refund.getOrderGoodsId());
|
|
|
+ Goods goods = iGoodsService.getById(orderGoods.getGoodsId());
|
|
|
+ iOrderGoodsRefundService.refundCall("", refund.getRefundId(), orderGoods.getOrderGoodsId(), order, goods.getGoodsType(), orderGoods.getGradeId(), order.getUserId(), goods.getGoodsId());
|
|
|
+ //关闭C端用户的分销返利
|
|
|
+ iOrderGoodsRefundService.shareClientCancelOldSys(order, orderGoods, refund.getRealRefundFee());
|
|
|
+ });
|
|
|
+ }
|
|
|
+ //退款金额
|
|
|
+ BigDecimal reduce = goodsRefundList.stream().map(OrderGoodsRefund::getRealRefundFee).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ if (ObjectUtils.isNotNull(orderHandle.getRefundedPrice())){
|
|
|
+ orderHandle.setRefundedPrice(orderHandle.getRefundedPrice().add(reduce));
|
|
|
+ }else {
|
|
|
+ orderHandle.setRefundedPrice(reduce);
|
|
|
+ }
|
|
|
+ orderHandle.setRefundStatus(1);//已退款
|
|
|
+ updateById(orderHandle);
|
|
|
+ goodsRefundList.forEach(x -> {
|
|
|
+ x.setPeriodStatus(1);//已退款
|
|
|
+ x.setPeriodTime(DateUtils.getNowTime());
|
|
|
+ });
|
|
|
+ iOrderGoodsRefundService.updateBatchById(goodsRefundList);
|
|
|
+ //是否存在发票
|
|
|
+ List<OrderInvoiceOrder> list = iOrderInvoiceOrderService
|
|
|
+ .list(new LambdaQueryWrapper<OrderInvoiceOrder>().eq(OrderInvoiceOrder::getOrderSn, orderHandle.getHandleOrderSn()));
|
|
|
+ if (CollectionUtils.isNotEmpty(list)){
|
|
|
+ iOrderInvoiceService.update(new LambdaUpdateWrapper<OrderInvoice>()
|
|
|
+ .set(OrderInvoice::getWashStatus,1)//带冲红
|
|
|
+ .set(OrderInvoice::getInvoiceStatus,4)//失效
|
|
|
+ .in(OrderInvoice::getInvoiceId,list.stream().map(OrderInvoiceOrder::getInvoiceId).collect(Collectors.toList())));
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 2://不通过
|
|
|
+ orderHandle.setRefundStatus(2);//不通过
|
|
|
+ orderHandle.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ updateById(orderHandle);
|
|
|
+ goodsRefundList.forEach(x -> {
|
|
|
+ x.setPeriodReason(bo.getCheckReason());
|
|
|
+ x.setPeriodStatus(2);//不通过
|
|
|
+ x.setPeriodTime(DateUtils.getNowTime());
|
|
|
+ });
|
|
|
+ iOrderGoodsRefundService.updateBatchById(goodsRefundList);
|
|
|
+ orderList.forEach(item -> {
|
|
|
+ item.setOrderRefundStatus(4);
|
|
|
+ });
|
|
|
+ iOrderService.updateBatchById(orderList);
|
|
|
+ orderGoodsList.forEach(item -> {
|
|
|
+ item.setRefundStatus(3);
|
|
|
+ });
|
|
|
+ iOrderGoodsService.updateBatchById(orderGoodsList);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+}
|