|
|
@@ -1,14 +1,40 @@
|
|
|
package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Map.Entry;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Isolation;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
-import com.ym.mec.biz.dal.dao.*;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.ym.mec.biz.dal.dao.GoodsDao;
|
|
|
+import com.ym.mec.biz.dal.dao.SellOrderDao;
|
|
|
+import com.ym.mec.biz.dal.dao.StudentPaymentOrderDao;
|
|
|
+import com.ym.mec.biz.dal.dao.StudentPaymentRouteOrderDao;
|
|
|
+import com.ym.mec.biz.dal.dao.SysUserCashAccountDao;
|
|
|
import com.ym.mec.biz.dal.dto.PageInfoOrder;
|
|
|
import com.ym.mec.biz.dal.dto.StudentPaymentRouteOrderDto;
|
|
|
import com.ym.mec.biz.dal.entity.Goods;
|
|
|
import com.ym.mec.biz.dal.entity.SellOrder;
|
|
|
import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
|
|
|
import com.ym.mec.biz.dal.entity.StudentPaymentRouteOrder;
|
|
|
-import com.ym.mec.biz.dal.enums.*;
|
|
|
+import com.ym.mec.biz.dal.enums.AccountType;
|
|
|
+import com.ym.mec.biz.dal.enums.AuditStatusEnum;
|
|
|
+import com.ym.mec.biz.dal.enums.DealStatusEnum;
|
|
|
+import com.ym.mec.biz.dal.enums.GroupType;
|
|
|
+import com.ym.mec.biz.dal.enums.OrderTypeEnum;
|
|
|
+import com.ym.mec.biz.dal.enums.SellTypeEnum;
|
|
|
+import com.ym.mec.biz.dal.enums.SporadicChargeTypeEnum;
|
|
|
import com.ym.mec.biz.dal.page.StudentPaymentOrderQueryInfo;
|
|
|
import com.ym.mec.biz.service.GoodsService;
|
|
|
import com.ym.mec.biz.service.SellOrderService;
|
|
|
@@ -18,15 +44,6 @@ import com.ym.mec.common.exception.BizException;
|
|
|
import com.ym.mec.common.service.IdGeneratorService;
|
|
|
import com.ym.mec.common.service.impl.BaseServiceImpl;
|
|
|
import com.ym.mec.util.collection.MapUtil;
|
|
|
-import org.apache.ibatis.javassist.expr.NewArray;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Isolation;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
-
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.util.*;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, StudentPaymentRouteOrder> implements StudentPaymentRouteOrderService {
|
|
|
@@ -88,107 +105,163 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
|
|
|
- public StudentPaymentRouteOrderDto addOutOrder(StudentPaymentRouteOrderDto studentPaymentRouteOrderDto) {
|
|
|
+ public StudentPaymentRouteOrder addOutOrder(StudentPaymentRouteOrder studentPaymentRouteOrder) {
|
|
|
Date nowDate = new Date();
|
|
|
String orderNo = idGeneratorService.generatorId("payment") + "";
|
|
|
- studentPaymentRouteOrderDto.setType(OrderTypeEnum.OUTORDER);
|
|
|
- studentPaymentRouteOrderDto.setMerNos(studentPaymentRouteOrderDto.getMerNo());
|
|
|
- studentPaymentRouteOrderDto.setOrderNo(orderNo);
|
|
|
- studentPaymentRouteOrderDto.setGroupType(GroupType.OUTORDER);
|
|
|
- studentPaymentRouteOrderDto.setRouteOrganId(studentPaymentRouteOrderDto.getOrganId());
|
|
|
- studentPaymentRouteOrderDto.setExpectAmount(studentPaymentRouteOrderDto.getActualAmount());
|
|
|
- studentPaymentRouteOrderDto.setStatus(DealStatusEnum.SUCCESS);
|
|
|
- studentPaymentRouteOrderDto.setCreateTime(studentPaymentRouteOrderDto.getPayTime());
|
|
|
- studentPaymentRouteOrderDto.setUpdateTime(nowDate);
|
|
|
- studentPaymentRouteOrderDao.insertOrder(studentPaymentRouteOrderDto);
|
|
|
-
|
|
|
- StudentPaymentRouteOrder studentPaymentRouteOrder = new StudentPaymentRouteOrder();
|
|
|
studentPaymentRouteOrder.setOrderNo(orderNo);
|
|
|
- studentPaymentRouteOrder.setMerNo(studentPaymentRouteOrderDto.getMerNo());
|
|
|
- studentPaymentRouteOrder.setRouteOrganId(studentPaymentRouteOrderDto.getOrganId());
|
|
|
- studentPaymentRouteOrder.setRouteAmount(studentPaymentRouteOrderDto.getActualAmount());
|
|
|
+ studentPaymentRouteOrder.setAuditStatus(AuditStatusEnum.ING);
|
|
|
+ studentPaymentRouteOrder.setCreateTime(nowDate);
|
|
|
+ studentPaymentRouteOrder.setUpdateTime(nowDate);
|
|
|
+ studentPaymentRouteOrder.setRouteAmount(studentPaymentRouteOrder.getSaleAmount().add(studentPaymentRouteOrder.getServiceAmount()));
|
|
|
studentPaymentRouteOrder.setRouteBalanceAmount(BigDecimal.ZERO);
|
|
|
studentPaymentRouteOrder.setFeeFlag("N");
|
|
|
+
|
|
|
studentPaymentRouteOrderDao.insert(studentPaymentRouteOrder);
|
|
|
-
|
|
|
- if (studentPaymentRouteOrderDto.getGoodies() != null && studentPaymentRouteOrderDto.getGoodies().size() > 0) {
|
|
|
- BigDecimal hasRouteAmount = BigDecimal.ZERO;
|
|
|
- BigDecimal goodsTotalPrice = BigDecimal.ZERO;
|
|
|
-
|
|
|
- List<Integer> goodsIdList = new ArrayList<>();
|
|
|
- for (Map.Entry<Integer, Integer> goodsMap : studentPaymentRouteOrderDto.getGoodies().entrySet()) {
|
|
|
- Goods goods = goodsDao.get(goodsMap.getKey());
|
|
|
- goodsTotalPrice = goodsTotalPrice.add(goods.getGroupPurchasePrice().multiply(new BigDecimal(goodsMap.getValue())));
|
|
|
- for (int i = 0; i < goodsMap.getValue(); i++) {
|
|
|
- goodsIdList.add(goodsMap.getKey());
|
|
|
- }
|
|
|
- }
|
|
|
- List<SellOrder> sellOrderList = goodsService.subtractStock(goodsIdList, AccountType.INTERNAL);
|
|
|
-
|
|
|
- int i = 1;
|
|
|
- for (Map.Entry<Integer, Integer> goodsMap : studentPaymentRouteOrderDto.getGoodies().entrySet()) {
|
|
|
- Goods goods = goodsDao.get(goodsMap.getKey());
|
|
|
-
|
|
|
- BigDecimal actualAmount = BigDecimal.ZERO;
|
|
|
- if (goodsTotalPrice.compareTo(BigDecimal.ZERO) != 0) {
|
|
|
- actualAmount = studentPaymentRouteOrderDto.getGoodsAmount().multiply(goods.getGroupPurchasePrice().multiply(new BigDecimal(goodsMap.getValue()))).divide(goodsTotalPrice, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
- }
|
|
|
- if (i == studentPaymentRouteOrderDto.getGoodies().size()) {
|
|
|
- actualAmount = studentPaymentRouteOrderDto.getGoodsAmount().subtract(hasRouteAmount);
|
|
|
- }
|
|
|
- hasRouteAmount = hasRouteAmount.add(actualAmount);
|
|
|
- i++;
|
|
|
-
|
|
|
- int complementNum = goods.getComplementGoodsIdList() == null ? 1 : goods.getComplementGoodsIdList().split(",").length;
|
|
|
- int goodsNum = goodsMap.getValue() * complementNum;
|
|
|
- BigDecimal complementPrice = goods.getGroupPurchasePrice().multiply(new BigDecimal(goodsMap.getValue()));
|
|
|
- Map<Integer, BigDecimal> complementGoodsPrice = new HashMap<>();
|
|
|
- complementGoodsPrice.put(goods.getId(), goods.getGroupPurchasePrice());
|
|
|
- if (goods.getComplementGoodsIdList() != null) {
|
|
|
- List<Goods> complementGoodies = goodsDao.findGoodsByIds(goods.getComplementGoodsIdList());
|
|
|
- complementGoodsPrice = complementGoodies.stream().collect(Collectors.toMap(Goods::getId, Goods::getGroupPurchasePrice));
|
|
|
- complementPrice = complementGoodies.stream().map(Goods::getGroupPurchasePrice).reduce(BigDecimal.ZERO, BigDecimal::add).multiply(new BigDecimal(goodsMap.getValue()));
|
|
|
- }
|
|
|
-
|
|
|
- BigDecimal hasRouteSellOrderActualAmount = BigDecimal.ZERO;
|
|
|
- for (SellOrder sellOrder : sellOrderList) {
|
|
|
- if (!goodsMap.getKey().equals(sellOrder.getParentGoodsId()) && !goodsMap.getKey().equals(sellOrder.getGoodsId())) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- BigDecimal sellOrderActualAmount = BigDecimal.ZERO;
|
|
|
- if (complementPrice.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
- sellOrderActualAmount = complementGoodsPrice.get(sellOrder.getGoodsId()).multiply(new BigDecimal(sellOrder.getNum())).multiply(actualAmount).divide(complementPrice, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
- }
|
|
|
- goodsNum = goodsNum - sellOrder.getNum();
|
|
|
- if (goodsNum <= 0) {
|
|
|
- sellOrderActualAmount = actualAmount.subtract(hasRouteSellOrderActualAmount);
|
|
|
- }
|
|
|
- hasRouteSellOrderActualAmount = hasRouteSellOrderActualAmount.add(sellOrderActualAmount);
|
|
|
-
|
|
|
- sellOrder.setSellTime(studentPaymentRouteOrderDto.getPayTime());
|
|
|
- sellOrder.setOrganId(studentPaymentRouteOrderDto.getOrganId());
|
|
|
- sellOrder.setCooperationOrganId(studentPaymentRouteOrderDto.getSchoolId());
|
|
|
- sellOrder.setTransNo(studentPaymentRouteOrderDto.getTransNo());
|
|
|
- sellOrder.setOrderId(studentPaymentRouteOrderDto.getId());
|
|
|
- sellOrder.setOrderNo(orderNo);
|
|
|
- sellOrder.setActualAmount(sellOrderActualAmount);
|
|
|
- sellOrder.setBalanceAmount(BigDecimal.ZERO);
|
|
|
- sellOrder.setExpectAmount(sellOrderActualAmount);
|
|
|
- sellOrder.setUserId(studentPaymentRouteOrderDto.getUserId());
|
|
|
- sellOrder.setPaymentChannel(studentPaymentRouteOrderDto.getPaymentChannel());
|
|
|
- sellOrder.setMerNo(studentPaymentRouteOrderDto.getMerNos());
|
|
|
- sellOrder.setSellTime(studentPaymentRouteOrderDto.getCreateTime());
|
|
|
- sellOrder.setCreateIme(nowDate);
|
|
|
- sellOrder.setUpdateTime(nowDate);
|
|
|
- sellOrder.setType(SellTypeEnum.SCHOOL_BUY);
|
|
|
- }
|
|
|
- }
|
|
|
- sellOrderDao.batchInsert(sellOrderList);
|
|
|
- }
|
|
|
- return studentPaymentRouteOrderDto;
|
|
|
+
|
|
|
+ return studentPaymentRouteOrder;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public StudentPaymentRouteOrder updateOutOrder(StudentPaymentRouteOrder studentPaymentRouteOrder) {
|
|
|
+ Date nowDate = new Date();
|
|
|
+ studentPaymentRouteOrder.setAuditStatus(AuditStatusEnum.ING);
|
|
|
+ studentPaymentRouteOrder.setUpdateTime(nowDate);
|
|
|
+ studentPaymentRouteOrder.setRouteAmount(studentPaymentRouteOrder.getSaleAmount().add(studentPaymentRouteOrder.getServiceAmount()));
|
|
|
+ studentPaymentRouteOrder.setRouteBalanceAmount(BigDecimal.ZERO);
|
|
|
+ studentPaymentRouteOrder.setFeeFlag("N");
|
|
|
+
|
|
|
+ studentPaymentRouteOrderDao.update(studentPaymentRouteOrder);
|
|
|
+
|
|
|
+ return studentPaymentRouteOrder;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
|
|
|
+ public boolean auditOutOrder(Long studentPaymentRouteOrderId, AuditStatusEnum auditStatus, String memo, Integer operatorId) {
|
|
|
+ StudentPaymentRouteOrder studentPaymentRouteOrder = studentPaymentRouteOrderDao.get(studentPaymentRouteOrderId);
|
|
|
+ if(studentPaymentRouteOrder == null){
|
|
|
+ throw new BizException("查询订单信息失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(studentPaymentRouteOrder.getAuditStatus() != AuditStatusEnum.ING){
|
|
|
+ throw new BizException("只有“审核中”的订单才能审核");
|
|
|
+ }
|
|
|
+
|
|
|
+ Date nowDate = new Date();
|
|
|
+
|
|
|
+ studentPaymentRouteOrder.setUpdateBy(operatorId);
|
|
|
+ studentPaymentRouteOrder.setUpdateTime(nowDate);
|
|
|
+ studentPaymentRouteOrder.setMemo(memo);
|
|
|
+ studentPaymentRouteOrder.setAuditStatus(auditStatus);
|
|
|
+
|
|
|
+ studentPaymentRouteOrderDao.update(studentPaymentRouteOrder);
|
|
|
+
|
|
|
+ if(auditStatus == AuditStatusEnum.PASS){
|
|
|
+ StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
|
|
|
+ studentPaymentOrder.setActualAmount(studentPaymentRouteOrder.getRouteAmount());
|
|
|
+ studentPaymentOrder.setMusicGroupId(studentPaymentRouteOrder.getSchoolId()+ "");
|
|
|
+ studentPaymentOrder.setType(OrderTypeEnum.OUTORDER);
|
|
|
+ studentPaymentOrder.setMerNos(studentPaymentRouteOrder.getMerNo());
|
|
|
+ studentPaymentOrder.setOrderNo(studentPaymentRouteOrder.getOrderNo());
|
|
|
+ studentPaymentOrder.setGroupType(GroupType.OUTORDER);
|
|
|
+ studentPaymentOrder.setOrganId(studentPaymentRouteOrder.getRouteOrganId());
|
|
|
+ studentPaymentOrder.setExpectAmount(studentPaymentRouteOrder.getRouteAmount());
|
|
|
+ studentPaymentOrder.setStatus(DealStatusEnum.SUCCESS);
|
|
|
+ studentPaymentOrder.setCreateTime(studentPaymentRouteOrder.getPayTime());
|
|
|
+ studentPaymentOrder.setUpdateTime(nowDate);
|
|
|
+ studentPaymentOrder.setMemo(studentPaymentRouteOrder.getMemo());
|
|
|
+ studentPaymentOrder.setUserId(studentPaymentRouteOrder.getUserId());
|
|
|
+ studentPaymentOrder.setPayTime(studentPaymentRouteOrder.getPayTime());
|
|
|
+
|
|
|
+ studentPaymentRouteOrderDao.insertOrder(studentPaymentOrder);
|
|
|
+
|
|
|
+ if (StringUtils.isNoneBlank(studentPaymentRouteOrder.getGoodsJson())) {
|
|
|
+ BigDecimal hasRouteAmount = BigDecimal.ZERO;
|
|
|
+ BigDecimal goodsTotalPrice = BigDecimal.ZERO;
|
|
|
+
|
|
|
+ List<Integer> goodsIdList = new ArrayList<>();
|
|
|
+ JSONObject jsonObj = JSON.parseObject(studentPaymentRouteOrder.getGoodsJson());
|
|
|
+ for (Entry<String, Object> goodsMap : jsonObj.entrySet()) {
|
|
|
+ Integer goodsId = Integer.parseInt(goodsMap.getKey());
|
|
|
+ Integer nums = Integer.parseInt(goodsMap.getValue().toString());
|
|
|
+ Goods goods = goodsDao.get(goodsId);
|
|
|
+ goodsTotalPrice = goodsTotalPrice.add(goods.getGroupPurchasePrice().multiply(new BigDecimal(nums)));
|
|
|
+ for (int i = 0; i < nums; i++) {
|
|
|
+ goodsIdList.add(goodsId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<SellOrder> sellOrderList = goodsService.subtractStock(goodsIdList, AccountType.INTERNAL);
|
|
|
+
|
|
|
+ int i = 1;
|
|
|
+ for (Entry<String, Object> goodsMap : jsonObj.entrySet()) {
|
|
|
+ Integer goodsId = Integer.parseInt(goodsMap.getKey());
|
|
|
+ Integer nums = Integer.parseInt(goodsMap.getValue().toString());
|
|
|
+ Goods goods = goodsDao.get(goodsId);
|
|
|
+
|
|
|
+ BigDecimal actualAmount = BigDecimal.ZERO;
|
|
|
+ if (goodsTotalPrice.compareTo(BigDecimal.ZERO) != 0) {
|
|
|
+ actualAmount = studentPaymentRouteOrder.getSaleAmount().multiply(goods.getGroupPurchasePrice().multiply(new BigDecimal(nums))).divide(goodsTotalPrice, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ }
|
|
|
+ if (i == jsonObj.entrySet().size()) {
|
|
|
+ actualAmount = studentPaymentRouteOrder.getSaleAmount().subtract(hasRouteAmount);
|
|
|
+ }
|
|
|
+ hasRouteAmount = hasRouteAmount.add(actualAmount);
|
|
|
+ i++;
|
|
|
+
|
|
|
+ int complementNum = goods.getComplementGoodsIdList() == null ? 1 : goods.getComplementGoodsIdList().split(",").length;
|
|
|
+ int goodsNum = nums * complementNum;
|
|
|
+ BigDecimal complementPrice = goods.getGroupPurchasePrice().multiply(new BigDecimal(nums));
|
|
|
+ Map<Integer, BigDecimal> complementGoodsPrice = new HashMap<>();
|
|
|
+ complementGoodsPrice.put(goods.getId(), goods.getGroupPurchasePrice());
|
|
|
+ if (goods.getComplementGoodsIdList() != null) {
|
|
|
+ List<Goods> complementGoodies = goodsDao.findGoodsByIds(goods.getComplementGoodsIdList());
|
|
|
+ complementGoodsPrice = complementGoodies.stream().collect(Collectors.toMap(Goods::getId, Goods::getGroupPurchasePrice));
|
|
|
+ complementPrice = complementGoodies.stream().map(Goods::getGroupPurchasePrice).reduce(BigDecimal.ZERO, BigDecimal::add).multiply(new BigDecimal(nums));
|
|
|
+ }
|
|
|
+
|
|
|
+ BigDecimal hasRouteSellOrderActualAmount = BigDecimal.ZERO;
|
|
|
+ for (SellOrder sellOrder : sellOrderList) {
|
|
|
+ if (!goodsMap.getKey().equals(sellOrder.getParentGoodsId()) && !goodsMap.getKey().equals(sellOrder.getGoodsId())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ BigDecimal sellOrderActualAmount = BigDecimal.ZERO;
|
|
|
+ if (complementPrice.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ sellOrderActualAmount = complementGoodsPrice.get(sellOrder.getGoodsId()).multiply(new BigDecimal(sellOrder.getNum())).multiply(actualAmount).divide(complementPrice, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ }
|
|
|
+ goodsNum = goodsNum - sellOrder.getNum();
|
|
|
+ if (goodsNum <= 0) {
|
|
|
+ sellOrderActualAmount = actualAmount.subtract(hasRouteSellOrderActualAmount);
|
|
|
+ }
|
|
|
+ hasRouteSellOrderActualAmount = hasRouteSellOrderActualAmount.add(sellOrderActualAmount);
|
|
|
+
|
|
|
+ sellOrder.setSellTime(studentPaymentRouteOrder.getPayTime());
|
|
|
+ sellOrder.setOrganId(studentPaymentRouteOrder.getRouteOrganId());
|
|
|
+ sellOrder.setCooperationOrganId(studentPaymentRouteOrder.getSchoolId());
|
|
|
+ sellOrder.setTransNo(studentPaymentRouteOrder.getTransNo());
|
|
|
+ sellOrder.setOrderId(studentPaymentOrder.getId());
|
|
|
+ sellOrder.setOrderNo(studentPaymentRouteOrder.getOrderNo());
|
|
|
+ sellOrder.setActualAmount(sellOrderActualAmount);
|
|
|
+ sellOrder.setBalanceAmount(BigDecimal.ZERO);
|
|
|
+ sellOrder.setExpectAmount(sellOrderActualAmount);
|
|
|
+ sellOrder.setUserId(studentPaymentRouteOrder.getUserId());
|
|
|
+ sellOrder.setPaymentChannel(studentPaymentOrder.getPaymentChannel());
|
|
|
+ sellOrder.setMerNo(studentPaymentRouteOrder.getMerNo());
|
|
|
+ sellOrder.setSellTime(studentPaymentRouteOrder.getCreateTime());
|
|
|
+ sellOrder.setCreateIme(nowDate);
|
|
|
+ sellOrder.setUpdateTime(nowDate);
|
|
|
+ sellOrder.setType(SellTypeEnum.SCHOOL_BUY);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sellOrderDao.batchInsert(sellOrderList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public StudentPaymentRouteOrder addRouteOrder(String orderNo, Integer routeOrganId, BigDecimal routeBalanceAmount) {
|
|
|
StudentPaymentRouteOrder studentPaymentRouteOrder = new StudentPaymentRouteOrder();
|
|
|
studentPaymentRouteOrder.setOrderNo(orderNo);
|